Merge lp:~cjdahlin/upstart/n-ary-event-oper into lp:~canonical-scott/upstart/trunk
- n-ary-event-oper
- Merge into trunk
Status: | Needs review |
---|---|
Proposed branch: | lp:~cjdahlin/upstart/n-ary-event-oper |
Merge into: | lp:~canonical-scott/upstart/trunk |
Diff against target: | None lines |
To merge this branch: | bzr merge lp:~cjdahlin/upstart/n-ary-event-oper |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Scott James Remnant (Canonical) | Needs Fixing | ||
Review via email: mp+9968@code.launchpad.net |
Commit message
Description of the change
Scott James Remnant (Canonical) (canonical-scott) wrote : | # |
Hi Casey,
Could you send this in the form of a patch to the upstart-devel ML?
Scott James Remnant (Canonical) (canonical-scott) : | # |
Scott James Remnant (Canonical) (canonical-scott) wrote : | # |
Review comments on ML
https:/
Scott James Remnant (Canonical) (canonical-scott) wrote : | # |
On Tue, 2009-08-11 at 17:33 -0400, Casey Dahlin wrote:
> This makes EventOperators N-ary rather than binary trees. It
> auto-optimizes them with a new event_operator_
> simply gifts all of the new child's children to the new parent rather
> than attaching it when the new parent and child are of the same type.
>
> This makes it a bit easier to make qualitative statements about trees,
> particularly "this tree only contains OR operators," which should become
> useful as AND operators become deprecated in future state models.
>
Thanks Casey.
Could you explain a little bit more about the rationale behind these
changes? Right now this just looks like a different way of constructing
the operator trees, and unless I'm mistaken, it's more expensive to
build them this way, they use more memory per node and they're more
difficult to iterate than the btrees we currently use.
Are you working on something else that requires this? Perhaps it'd help
to outline that work as well to the ML.
One thing I'd like to ask about - I don't have any plans to deprecate
AND operators; could you tell us a little bit about your plans in this
regard?
>
> === modified file 'ChangeLog'
> --- ChangeLog 2009-08-04 08:51:25 +0000
> +++ ChangeLog 2009-08-11 05:51:31 +0000
> @@ -1,3 +1,60 @@
> +2009-08-11 Casey Dahlin <email address hidden>
> +
> + * init/event_
> + ANY/ALL
> +
> + (EventOperator): Get rid of node entry and add children list.
> +
> + * init/event_
> + version of event_operator_
> + root of the tree.
> +
> + (event_
> + node.
> +
> + (event_
> +
> + (event_
> +
> + (event_
> + N-ary tree.
> +
> + (event_
> + tree.
> +
> + (event_
> +
> + (event_
> +
> + (event_
> + automatically collapsing it into its new parent if it is the same type.
> +
> + (event_
> +
> + (event_
> + to recursively collect environment variables.
> +
> + * init/parse_job.c (parse_
> + tree adds to event_operator_
> +
> + (parse_on_collect): Change tree adds to event_operator_
> +
> + * init/tests/
> + assumptions about EventOperator.
> +
> + (test_finish): Change AND/OR to ANY/ALL
> +
> + * init/tests/
> + assumptions about EventOperator.
> +
> + (test_operator_
> +
> + * init/tests/
Casey Dahlin (cjdahlin) wrote : | # |
-------- Original Message --------
Subject: Re: [PATCH] N-ary event operators
Date: Wed, 12 Aug 2009 10:06:39 -0400
From: Casey Dahlin <email address hidden>
To: Scott James Remnant <email address hidden>
CC: Upstart Dev List <email address hidden>
On 08/12/2009 06:12 AM, Scott James Remnant wrote:
> On Tue, 2009-08-11 at 17:33 -0400, Casey Dahlin wrote:
>
>> This makes EventOperators N-ary rather than binary trees. It
>> auto-optimizes them with a new event_operator_
>> simply gifts all of the new child's children to the new parent rather
>> than attaching it when the new parent and child are of the same type.
>>
>> This makes it a bit easier to make qualitative statements about trees,
>> particularly "this tree only contains OR operators," which should become
>> useful as AND operators become deprecated in future state models.
>>
> Thanks Casey.
>
> Could you explain a little bit more about the rationale behind these
> changes? Right now this just looks like a different way of constructing
> the operator trees, and unless I'm mistaken, it's more expensive to
> build them this way, they use more memory per node and they're more
> difficult to iterate than the btrees we currently use.
>
Building them might be a bit more expensive, but they do take up less memory by virtue of simply having fewer nodes.
> Are you working on something else that requires this? Perhaps it'd help
> to outline that work as well to the ML.
>
I am. I'll do that.
> One thing I'd like to ask about - I don't have any plans to deprecate
> AND operators; could you tell us a little bit about your plans in this
> regard?
>
When we switch from start on to on, I see no reason to keep them. We'll have much better ways to retain state (frankly I'd rather just allow multiple "on" stanzas and do away with operators altogether, in which case our commitment to compatibility with 0.6 is the only reason any of this code needs to be around).
>
>
>> === modified file 'ChangeLog'
>> --- ChangeLog 2009-08-04 08:51:25 +0000
>> +++ ChangeLog 2009-08-11 05:51:31 +0000
>> @@ -1,3 +1,60 @@
>> +2009-08-11 Casey Dahlin <email address hidden>
>> +
>> + * init/event_
>> + ANY/ALL
>> +
>> + (EventOperator): Get rid of node entry and add children list.
>> +
>> + * init/event_
>> + version of event_operator_
>> + root of the tree.
>> +
>> + (event_
>> + node.
>> +
>> + (event_
>> +
>> + (event_
>> +
>> + (event_
>> + N-ary tree.
>> +
>> + (event_
>> + tree.
>> +
>> + (event_
>> +
>> + (event_
>> +
>> + (event_
>> + automatically colla...
- 1187. By Casey Dahlin
-
* ChangeLog: Format fix
- 1188. By Casey Dahlin
-
* ChangeLog: More format fixes
- 1189. By Casey Dahlin
-
* init/event_
operator. c: Fix static prototypes, rename ALL/ANY to AND/OR again
(event_operator_ copy): Style fix
(event_operator_ add_child, event_operator_ update) : Improve docstring
* init/event_operator. h, init/parse_job.c: Rename ALL/ANY back to AND/OR
* init/tests/test_event. c: Style fixes
* init/tests/test_event_ operator. c: Style fixes
* init/tests/test_parse_ job.c: Style fixes
Casey Dahlin (cjdahlin) wrote : | # |
This should address most of the issues. I might have missed some, and
theres a few I'll need clarified. Go ahead and look though. (Also note
that the ChangeLog update is no longer complete).
=== modified file 'ChangeLog'
--- ChangeLog 2009-08-04 08:51:25 +0000
+++ ChangeLog 2009-08-13 00:01:12 +0000
@@ -1,3 +1,42 @@
+2009-08-11 Casey Dahlin <email address hidden>
+
+ * init/event_
+ to ANY/ALL
+ (EventOperator): Get rid of node entry and add children list.
+ * init/event_
+ version of event_operator_
+ root of the tree.
+ (event_
+ node.
+ (event_
+ (event_
+ tree
+ (event_
+ from N-ary tree.
+ (event_
+ tree.
+ (event_
+ (event_
+ (event_
+ automatically collapsing it into its new parent if it is the same type.
+ (event_
+ (event_
+ event_operator_
+ variables.
+ * init/parse_job.c (parse_
+ Change tree adds to event_operator_
+ (parse_on_collect): Change tree adds to event_operator_
+ * init/tests/
+ assumptions about EventOperator.
+ (test_finish): Change AND/OR to ANY/ALL
+ * init/tests/
+ assumptions about EventOperator.
+ (test_operator_
+ * init/tests/
+ assumptions about EventOperator
+ * init/tests/
+ about EventOperator
+
2009-08-04 Johan Kiviniemi <email address hidden>
* conf/rc-
=== modified file 'init/event_
--- init/event_
+++ init/event_
@@ -44,6 +44,11 @@
#include "errors.h"
+static char **event_
+ char ***env, const void *parent, size_t *len, const char *key,
+ char **evlist);
+
+
/**
* event_operator_new:
* @parent: parent object for new operator,
@@ -85,7 +90,8 @@ event_operator_new (const void *
if (! oper)
return NULL;
- nih_tree_init (&oper->node);
+ nih_list_init (&oper->entry);
+ nih_list_init (&oper->children);
oper->type = type;
oper->value = FALSE;
@@ -163,30 +169,54 @@ event_operator_copy (const void
event_block (oper->event);
}
- if (old_oper-
- child = event_operator_copy (
- oper, (EventOperator *)old_op...
Philipp Schlesinger (philipp-sadleder) wrote : | # |
Hello!
New message, please read <http://
<email address hidden>
Philipp Schlesinger (philipp-sadleder) wrote : | # |
Hey,
Did you hear the latest news? You should definetely read more info here <http://
Sincerely, <email address hidden>
Philipp Schlesinger (philipp-sadleder) wrote : | # |
Hello,
I met my old friend yesterday, he is now so famous and talked by a lot of people. You can find more about him here <http://
Yours, philipp
Philipp Schlesinger (philipp-sadleder) wrote : | # |
Yo!
Have you read this new book already? I'm so delighted with it, please read it here http://
Hugs, philipp
Philipp Schlesinger (philipp-sadleder) wrote : | # |
Hey,
I'd like to show you a nice gift a friend of mine gave me recently, it's something really cool)) Please take a look http://
Hope this helps, philipp
Philipp Schlesinger (philipp-sadleder) wrote : | # |
Hello,
I know you're interested in stuff like that, that is something really cool, just take a look http://
Hope this helps, philipp
Philipp Schlesinger (philipp-sadleder) wrote : | # |
Dear,
I was amazed by that shocking article I've recently read, please read it and tell me your opinion http://
Warmest regards, philipp
Philipp Schlesinger (philipp-sadleder) wrote : | # |
Hello friend,
I've recently came across that amazing stuff, it looks nice I think, take a look http://
Yours sincerely, philipp
Philipp Schlesinger (philipp-sadleder) wrote : | # |
Hi!
I think this story is really awesome, you're going to love it, please read it here http://
philipp
Philipp Schlesinger (philipp-sadleder) wrote : | # |
Hey!
I've found an article where it's written about increasing tax on goods and services, you may find more information here http://
My best to you, philipp
Unmerged revisions
- 1189. By Casey Dahlin
-
* init/event_
operator. c: Fix static prototypes, rename ALL/ANY to AND/OR again
(event_operator_ copy): Style fix
(event_operator_ add_child, event_operator_ update) : Improve docstring
* init/event_operator. h, init/parse_job.c: Rename ALL/ANY back to AND/OR
* init/tests/test_event. c: Style fixes
* init/tests/test_event_ operator. c: Style fixes
* init/tests/test_parse_ job.c: Style fixes - 1188. By Casey Dahlin
-
* ChangeLog: More format fixes
- 1187. By Casey Dahlin
-
* ChangeLog: Format fix
- 1186. By Casey Dahlin
-
Johan Kiviniemi 2009-08-04 * conf/rc-
sysinit. conf: Don't replace DEFAULT_RUNLEVEL with an
Scott James Remnant 2009-08-04 * init/tests/test_event_ operator. c (test_operator_ new): Replace
Scott James Remnant 2009-08-04 * init/tests/test_event. c (test_new): Replace TEST_ALLOC_ ORPHAN( env)
Scott James Remnant 2009-08-04 * init/tests/test_control. c (test_emit_event): Discard event
Scott James Remnant 2009-08-04 * init/init.supp: Add nih_alloc_ref_new() to init functions
Scott James Remnant 2009-08-02 * configure.ac: Bump version to 0.7.0
Scott James Remnant 2009-08-02 * NEWS: Release 0.6.3
Scott James Remnant 2009-08-01 Update NEWS from libnih
Scott James Remnant 2009-08-01 * init/tests/test_job_ process. c (test_handler): Add a missing test
Scott James Remnant 2009-07-31 * dbus/upstart.h: Allow the service name and address to be overriden
Michael Biebl 2009-07-29 * init/tests/test_job_ process. c: Add missing sys/ptrace.h include
Scott James Remnant 2009-07-21 * configure.ac: Bump version to 0.6.3
Scott James Remnant 2009-07-21 * NEWS: Release 0.6.2
Scott James Remnant 2009-07-21 * init/main.c (crash_handler): Restore missing chdir ("/") call.
Scott James Remnant 2009-07-21 * init/tests/test_job_ process. c (test_handler): We should allow
Scott James Remnant 2009-07-21 * init/job.c (job_change_state): Obvious bug fix; the set of states
Scott James Remnant 2009-07-16 * configure.ac: Bump version to 0.6.2
Scott James Remnant 2009-07-16 * NEWS: Release 0.6.1
Scott James Remnant 2009-07-16 * util/runlevel.c: Output the path before the error message,
Scott James Remnant 2009-07-16 * util/runlevel.c: If there is no current runlevel because the
Scott James Remnant 2009-07-15 * README: Now that D-Bus 1.2.16 proper has been released, update
Scott James Remnant 2009-07-14 * TODO: Update
Scott James Remnant 2009-07-14 * init/tests/test_job_ process. c (test_handler): Rework the existing
Scott James Remnant 2009-07-14 * util/Makefile.am (EXTRA_DIST): Distribute the valgrind suppressions
Scott James Remnant 2009-07-14 * util/tests/test_utmp. c (test_write_ shutdown) : Additional instance
Scott James Remnant 2009-07-14 * util/tests/test_utmp. c (test_write_ runlevel) : Looks like glibc ChangeLog: Update
- 1185. By Casey Dahlin
-
* init/event_
operator. h (EventOperatorT ype): Change types from AND/OR to ANY/ALL
(EventOperator): Get rid of node entry and add children list.
* init/event_operator. c (event_ operator_ subtree_ environment) : New version of
event_operator_environment that assumes we are not at the root of the tree.
(event_operator_ new): Initialize new children member instead of tree node
(event_operator_ copy): Use recursive call to correctly copy N-ary tree
(event_operator_ reset): Use recursive call to correctly reset N-ary tree
(event_operator_ events) : Use recursive call to correctly get events from N-ary
tree
(event_operator_ handle) : Use recursive call to correctly handle N-ary tree
(event_operator_ update) : Update based on all N children
(event_operator_ match): Don't assert based on now-defunct node
(event_operator_ add_child) : New helper to add a child to a tree, automatically
collapsing it into its new parent if it is the same type.
(event_operator_ destroy) : Destroy children list head correctly.
(event_operator_ environment) : Use new event_operator_ subtree_ environment to
recursively collect environment variables.
* init/parse_job.c (parse_on_operator) : Change AND/OR to ANY/ALL. Change tree
adds to event_operator_add_child calls
(parse_on_collect): Change tree adds to event_operator_add_child calls
* init/tests/test_event. c (test_pending_ handle_ jobs): Fix structural assumptions
about EventOperator
(test_finish): Change AND/OR to ANY/ALL
* init/tests/test_event_ operator. c (everywhere): Fix structural assumptions
about EventOperator
(test_operator_add_child) : New test for this new helper
* init/tests/test_job_ process. c (everywhere): Fix structural assumptions
about EventOperator
* init/tests/test_parse_ job.c (everywhere): Fix structural assumptions
about EventOperator
Preview Diff
1 | === modified file 'ChangeLog' | |||
2 | --- ChangeLog 2009-08-04 08:51:25 +0000 | |||
3 | +++ ChangeLog 2009-08-11 05:51:31 +0000 | |||
4 | @@ -1,3 +1,60 @@ | |||
5 | 1 | 2009-08-11 Casey Dahlin <cdahlin@redhat.com> | ||
6 | 2 | |||
7 | 3 | * init/event_operator.h (EventOperatorType): Change types from AND/OR to | ||
8 | 4 | ANY/ALL | ||
9 | 5 | |||
10 | 6 | (EventOperator): Get rid of node entry and add children list. | ||
11 | 7 | |||
12 | 8 | * init/event_operator.c (event_operator_subtree_environment): New | ||
13 | 9 | version of event_operator_environment that assumes we are not at the | ||
14 | 10 | root of the tree. | ||
15 | 11 | |||
16 | 12 | (event_operator_new): Initialize new children member instead of tree | ||
17 | 13 | node. | ||
18 | 14 | |||
19 | 15 | (event_operator_copy): Use recursive call to correctly copy N-ary tree | ||
20 | 16 | |||
21 | 17 | (event_operator_reset): Use recursive call to correctly reset N-ary tree | ||
22 | 18 | |||
23 | 19 | (event_operator_events): Use recursive call to correctly get events from | ||
24 | 20 | N-ary tree. | ||
25 | 21 | |||
26 | 22 | (event_operator_handle): Use recursive call to correctly handle N-ary | ||
27 | 23 | tree. | ||
28 | 24 | |||
29 | 25 | (event_operator_update): Update based on all N children | ||
30 | 26 | |||
31 | 27 | (event_operator_match): Don't assert based on now-defunct node | ||
32 | 28 | |||
33 | 29 | (event_operator_add_child): New helper to add a child to a tree, | ||
34 | 30 | automatically collapsing it into its new parent if it is the same type. | ||
35 | 31 | |||
36 | 32 | (event_operator_destroy): Destroy children list head correctly. | ||
37 | 33 | |||
38 | 34 | (event_operator_environment): Use new event_operator_subtree_environment | ||
39 | 35 | to recursively collect environment variables. | ||
40 | 36 | |||
41 | 37 | * init/parse_job.c (parse_on_operator): Change AND/OR to ANY/ALL. Change | ||
42 | 38 | tree adds to event_operator_add_child calls. | ||
43 | 39 | |||
44 | 40 | (parse_on_collect): Change tree adds to event_operator_add_child calls | ||
45 | 41 | |||
46 | 42 | * init/tests/test_event.c (test_pending_handle_jobs): Fix structural | ||
47 | 43 | assumptions about EventOperator. | ||
48 | 44 | |||
49 | 45 | (test_finish): Change AND/OR to ANY/ALL | ||
50 | 46 | |||
51 | 47 | * init/tests/test_event_operator.c (everywhere): Fix structural | ||
52 | 48 | assumptions about EventOperator. | ||
53 | 49 | |||
54 | 50 | (test_operator_add_child): New test for this new helper. | ||
55 | 51 | |||
56 | 52 | * init/tests/test_job_process.c (everywhere): Fix structural assumptions | ||
57 | 53 | about EventOperator | ||
58 | 54 | |||
59 | 55 | * init/tests/test_parse_job.c (everywhere): Fix structural assumptions | ||
60 | 56 | about EventOperator | ||
61 | 57 | |||
62 | 1 | 2009-08-04 Johan Kiviniemi <johan@kiviniemi.name> | 58 | 2009-08-04 Johan Kiviniemi <johan@kiviniemi.name> |
63 | 2 | 59 | ||
64 | 3 | * conf/rc-sysinit.conf: Don't replace DEFAULT_RUNLEVEL with an | 60 | * conf/rc-sysinit.conf: Don't replace DEFAULT_RUNLEVEL with an |
65 | 4 | 61 | ||
66 | === modified file 'init/event_operator.c' | |||
67 | --- init/event_operator.c 2009-06-23 09:29:35 +0000 | |||
68 | +++ init/event_operator.c 2009-08-11 05:12:01 +0000 | |||
69 | @@ -43,6 +43,9 @@ | |||
70 | 43 | #include "blocked.h" | 43 | #include "blocked.h" |
71 | 44 | #include "errors.h" | 44 | #include "errors.h" |
72 | 45 | 45 | ||
73 | 46 | static char** event_operator_subtree_environment | ||
74 | 47 | (EventOperator *oper, char ***env, const void *parent, | ||
75 | 48 | size_t *len, const char *key, char **evlist); | ||
76 | 46 | 49 | ||
77 | 47 | /** | 50 | /** |
78 | 48 | * event_operator_new: | 51 | * event_operator_new: |
79 | @@ -85,7 +88,8 @@ | |||
80 | 85 | if (! oper) | 88 | if (! oper) |
81 | 86 | return NULL; | 89 | return NULL; |
82 | 87 | 90 | ||
84 | 88 | nih_tree_init (&oper->node); | 91 | nih_list_init (&oper->entry); |
85 | 92 | nih_list_init (&oper->children); | ||
86 | 89 | 93 | ||
87 | 90 | oper->type = type; | 94 | oper->type = type; |
88 | 91 | oper->value = FALSE; | 95 | oper->value = FALSE; |
89 | @@ -163,33 +167,51 @@ | |||
90 | 163 | event_block (oper->event); | 167 | event_block (oper->event); |
91 | 164 | } | 168 | } |
92 | 165 | 169 | ||
114 | 166 | if (old_oper->node.left) { | 170 | NIH_LIST_FOREACH (&old_oper->children, iter) { |
115 | 167 | child = event_operator_copy ( | 171 | EventOperator *child = event_operator_copy ( |
116 | 168 | oper, (EventOperator *)old_oper->node.left); | 172 | oper, (EventOperator *)iter); |
117 | 169 | if (! child) { | 173 | if (! child) { |
118 | 170 | nih_free (oper); | 174 | nih_free (oper); |
119 | 171 | return NULL; | 175 | return NULL; |
120 | 172 | } | 176 | } |
121 | 173 | 177 | ||
122 | 174 | nih_tree_add (&oper->node, &child->node, NIH_TREE_LEFT); | 178 | event_operator_add_child (oper, child); |
102 | 175 | } | ||
103 | 176 | |||
104 | 177 | |||
105 | 178 | if (old_oper->node.right) { | ||
106 | 179 | child = event_operator_copy ( | ||
107 | 180 | oper, (EventOperator *)old_oper->node.right); | ||
108 | 181 | if (! child) { | ||
109 | 182 | nih_free (oper); | ||
110 | 183 | return NULL; | ||
111 | 184 | } | ||
112 | 185 | |||
113 | 186 | nih_tree_add (&oper->node, &child->node, NIH_TREE_RIGHT); | ||
123 | 187 | } | 179 | } |
124 | 188 | 180 | ||
125 | 189 | return oper; | 181 | return oper; |
126 | 190 | } | 182 | } |
127 | 191 | 183 | ||
128 | 192 | /** | 184 | /** |
129 | 185 | * event_operator_add_child: | ||
130 | 186 | * @oper: oper to add child to, | ||
131 | 187 | * @child: child to add. | ||
132 | 188 | * | ||
133 | 189 | * Makes @child a child of @oper. If @child and @oper are the same type, then | ||
134 | 190 | * @oper simply steals all of @child's children. | ||
135 | 191 | **/ | ||
136 | 192 | void | ||
137 | 193 | event_operator_add_child (EventOperator *oper, EventOperator *child) | ||
138 | 194 | { | ||
139 | 195 | nih_assert (oper != NULL); | ||
140 | 196 | nih_assert (child != NULL); | ||
141 | 197 | nih_assert (oper->type != EVENT_MATCH); | ||
142 | 198 | |||
143 | 199 | if (child->type != oper->type) { | ||
144 | 200 | nih_ref (child, oper); | ||
145 | 201 | nih_list_add (&oper->children, &child->entry); | ||
146 | 202 | return; | ||
147 | 203 | } | ||
148 | 204 | |||
149 | 205 | NIH_LIST_FOREACH_SAFE (&child->children, iter) { | ||
150 | 206 | EventOperator *grandchild = (EventOperator *)iter; | ||
151 | 207 | |||
152 | 208 | nih_ref (grandchild, oper); | ||
153 | 209 | nih_unref (grandchild, child); | ||
154 | 210 | nih_list_add (&oper->children, &grandchild->entry); | ||
155 | 211 | } | ||
156 | 212 | } | ||
157 | 213 | |||
158 | 214 | /** | ||
159 | 193 | * event_operator_destroy: | 215 | * event_operator_destroy: |
160 | 194 | * @oper: operator to be destroyed. | 216 | * @oper: operator to be destroyed. |
161 | 195 | * | 217 | * |
162 | @@ -209,7 +231,7 @@ | |||
163 | 209 | if (oper->event) | 231 | if (oper->event) |
164 | 210 | event_unblock (oper->event); | 232 | event_unblock (oper->event); |
165 | 211 | 233 | ||
167 | 212 | nih_tree_destroy (&oper->node); | 234 | nih_list_destroy (&oper->entry); |
168 | 213 | 235 | ||
169 | 214 | return 0; | 236 | return 0; |
170 | 215 | } | 237 | } |
171 | @@ -227,24 +249,17 @@ | |||
172 | 227 | void | 249 | void |
173 | 228 | event_operator_update (EventOperator *oper) | 250 | event_operator_update (EventOperator *oper) |
174 | 229 | { | 251 | { |
175 | 230 | EventOperator *left, *right; | ||
176 | 231 | |||
177 | 232 | nih_assert (oper != NULL); | 252 | nih_assert (oper != NULL); |
193 | 233 | nih_assert (oper->node.left != NULL); | 253 | nih_assert (oper->type != EVENT_MATCH); |
194 | 234 | nih_assert (oper->node.right != NULL); | 254 | |
195 | 235 | 255 | oper->value = (oper->type == EVENT_ALL) ? TRUE : FALSE; | |
196 | 236 | left = (EventOperator *)oper->node.left; | 256 | |
197 | 237 | right = (EventOperator *)oper->node.right; | 257 | NIH_LIST_FOREACH (&oper->children, iter) { |
198 | 238 | 258 | EventOperator *child = (EventOperator *)iter; | |
199 | 239 | switch (oper->type) { | 259 | if (child->value != oper->value) { |
200 | 240 | case EVENT_OR: | 260 | oper->value = child->value; |
201 | 241 | oper->value = (left->value || right->value); | 261 | return; |
202 | 242 | break; | 262 | } |
188 | 243 | case EVENT_AND: | ||
189 | 244 | oper->value = (left->value && right->value); | ||
190 | 245 | break; | ||
191 | 246 | default: | ||
192 | 247 | nih_assert_not_reached (); | ||
203 | 248 | } | 263 | } |
204 | 249 | } | 264 | } |
205 | 250 | 265 | ||
206 | @@ -280,8 +295,6 @@ | |||
207 | 280 | 295 | ||
208 | 281 | nih_assert (oper != NULL); | 296 | nih_assert (oper != NULL); |
209 | 282 | nih_assert (oper->type == EVENT_MATCH); | 297 | nih_assert (oper->type == EVENT_MATCH); |
210 | 283 | nih_assert (oper->node.left == NULL); | ||
211 | 284 | nih_assert (oper->node.right == NULL); | ||
212 | 285 | nih_assert (event != NULL); | 298 | nih_assert (event != NULL); |
213 | 286 | 299 | ||
214 | 287 | /* Names must match */ | 300 | /* Names must match */ |
215 | @@ -391,29 +404,30 @@ | |||
216 | 391 | * before we update the node itself. Simply iterate the tree and | 404 | * before we update the node itself. Simply iterate the tree and |
217 | 392 | * update the nodes. | 405 | * update the nodes. |
218 | 393 | */ | 406 | */ |
220 | 394 | NIH_TREE_FOREACH_POST (&root->node, iter) { | 407 | NIH_LIST_FOREACH (&root->children, iter) { |
221 | 395 | EventOperator *oper = (EventOperator *)iter; | 408 | EventOperator *oper = (EventOperator *)iter; |
222 | 396 | 409 | ||
241 | 397 | switch (oper->type) { | 410 | ret = ret || event_operator_handle (oper, event, env); |
242 | 398 | case EVENT_OR: | 411 | } |
243 | 399 | case EVENT_AND: | 412 | |
244 | 400 | event_operator_update (oper); | 413 | switch (root->type) { |
245 | 401 | break; | 414 | case EVENT_ANY: |
246 | 402 | case EVENT_MATCH: | 415 | case EVENT_ALL: |
247 | 403 | if ((! oper->value) | 416 | event_operator_update (root); |
248 | 404 | && event_operator_match (oper, event, env)) { | 417 | break; |
249 | 405 | oper->value = TRUE; | 418 | case EVENT_MATCH: |
250 | 406 | 419 | if ((! root->value) | |
251 | 407 | oper->event = event; | 420 | && event_operator_match (root, event, env)) { |
252 | 408 | event_block (oper->event); | 421 | root->value = TRUE; |
253 | 409 | 422 | ||
254 | 410 | ret = TRUE; | 423 | root->event = event; |
255 | 411 | } | 424 | event_block (root->event); |
256 | 412 | break; | 425 | |
257 | 413 | default: | 426 | ret = TRUE; |
240 | 414 | nih_assert_not_reached (); | ||
258 | 415 | } | 427 | } |
260 | 416 | 428 | break; | |
261 | 429 | default: | ||
262 | 430 | nih_assert_not_reached (); | ||
263 | 417 | } | 431 | } |
264 | 418 | 432 | ||
265 | 419 | return ret; | 433 | return ret; |
266 | @@ -501,38 +515,9 @@ | |||
267 | 501 | return NULL; | 515 | return NULL; |
268 | 502 | } | 516 | } |
269 | 503 | 517 | ||
302 | 504 | /* Iterate the operator tree, filtering out nodes with a non-TRUE | 518 | if (! event_operator_subtree_environment (root, env, parent, |
303 | 505 | * value and their children. The rationale for this is that this | 519 | len, key, &evlist)) |
304 | 506 | * then matches only the events that had an active role in starting | 520 | return NULL; |
273 | 507 | * the job, not the ones that were also blocked, but the other half | ||
274 | 508 | * of their logic wasn't present. | ||
275 | 509 | */ | ||
276 | 510 | NIH_TREE_FOREACH_FULL (&root->node, iter, | ||
277 | 511 | (NihTreeFilter)event_operator_filter, NULL) { | ||
278 | 512 | EventOperator *oper = (EventOperator *)iter; | ||
279 | 513 | |||
280 | 514 | if (oper->type != EVENT_MATCH) | ||
281 | 515 | continue; | ||
282 | 516 | |||
283 | 517 | nih_assert (oper->event != NULL); | ||
284 | 518 | |||
285 | 519 | /* Add environment from the event */ | ||
286 | 520 | if (! environ_append (env, parent, len, TRUE, oper->event->env)) | ||
287 | 521 | return NULL; | ||
288 | 522 | |||
289 | 523 | /* Append the name of the event to the string we're building */ | ||
290 | 524 | if (evlist) { | ||
291 | 525 | if (evlist[strlen (evlist) - 1] != '=') { | ||
292 | 526 | if (! nih_strcat_sprintf (&evlist, NULL, " %s", | ||
293 | 527 | oper->event->name)) | ||
294 | 528 | return NULL; | ||
295 | 529 | } else { | ||
296 | 530 | if (! nih_strcat (&evlist, NULL, | ||
297 | 531 | oper->event->name)) | ||
298 | 532 | return NULL; | ||
299 | 533 | } | ||
300 | 534 | } | ||
301 | 535 | } | ||
305 | 536 | 521 | ||
306 | 537 | /* Append the event list to the environment */ | 522 | /* Append the event list to the environment */ |
307 | 538 | if (evlist) | 523 | if (evlist) |
308 | @@ -543,6 +528,68 @@ | |||
309 | 543 | } | 528 | } |
310 | 544 | 529 | ||
311 | 545 | /** | 530 | /** |
312 | 531 | * event_operator_subtree_environment: | ||
313 | 532 | * @root: operator tree to collect from, | ||
314 | 533 | * @env: NULL-terminated array of environment variables to add to, | ||
315 | 534 | * @parent: parent object for new array, | ||
316 | 535 | * @len: length of @env, | ||
317 | 536 | * @key: key of variable to contain event names, | ||
318 | 537 | * @evlist: string in which to accumulate the event list. | ||
319 | 538 | * | ||
320 | 539 | * Does the work of event_operator_environment for one subtree. | ||
321 | 540 | **/ | ||
322 | 541 | |||
323 | 542 | static char** | ||
324 | 543 | event_operator_subtree_environment (EventOperator *oper, | ||
325 | 544 | char ***env, | ||
326 | 545 | const void *parent, | ||
327 | 546 | size_t *len, | ||
328 | 547 | const char *key, | ||
329 | 548 | char **evlist) | ||
330 | 549 | { | ||
331 | 550 | /* Filtering out nodes with a non-TRUE value and their children. The | ||
332 | 551 | * rationale for this is that this then matches only the events that had | ||
333 | 552 | * an active role in starting the job, not the ones that were also | ||
334 | 553 | * blocked, but the other half of their logic wasn't present. | ||
335 | 554 | */ | ||
336 | 555 | if (! oper->value) | ||
337 | 556 | return *env; | ||
338 | 557 | |||
339 | 558 | if (oper->type != EVENT_MATCH) { | ||
340 | 559 | NIH_LIST_FOREACH(&oper->children, iter) { | ||
341 | 560 | EventOperator *child = (EventOperator *)iter; | ||
342 | 561 | if (! event_operator_subtree_environment (child, env, parent, | ||
343 | 562 | len, key, evlist)) | ||
344 | 563 | return NULL; | ||
345 | 564 | } | ||
346 | 565 | |||
347 | 566 | return *env; | ||
348 | 567 | } | ||
349 | 568 | |||
350 | 569 | nih_assert (oper->event != NULL); | ||
351 | 570 | |||
352 | 571 | /* Add environment from the event */ | ||
353 | 572 | if (! environ_append (env, parent, len, TRUE, oper->event->env)) | ||
354 | 573 | return NULL; | ||
355 | 574 | |||
356 | 575 | /* Append the name of the event to the string we're building */ | ||
357 | 576 | if (*evlist) { | ||
358 | 577 | if ((*evlist)[strlen (*evlist) - 1] != '=') { | ||
359 | 578 | if (! nih_strcat_sprintf (evlist, NULL, " %s", | ||
360 | 579 | oper->event->name)) | ||
361 | 580 | return NULL; | ||
362 | 581 | } else { | ||
363 | 582 | if (! nih_strcat (evlist, NULL, | ||
364 | 583 | oper->event->name)) { | ||
365 | 584 | return NULL; | ||
366 | 585 | } | ||
367 | 586 | } | ||
368 | 587 | } | ||
369 | 588 | |||
370 | 589 | return *env; | ||
371 | 590 | } | ||
372 | 591 | |||
373 | 592 | /** | ||
374 | 546 | * event_operator_events: | 593 | * event_operator_events: |
375 | 547 | * @root: operator tree to collect from, | 594 | * @root: operator tree to collect from, |
376 | 548 | * @parent: parent object for blocked structures, | 595 | * @parent: parent object for blocked structures, |
377 | @@ -564,31 +611,31 @@ | |||
378 | 564 | const void *parent, | 611 | const void *parent, |
379 | 565 | NihList *list) | 612 | NihList *list) |
380 | 566 | { | 613 | { |
381 | 614 | Blocked *blocked; | ||
382 | 615 | |||
383 | 567 | nih_assert (root != NULL); | 616 | nih_assert (root != NULL); |
384 | 568 | nih_assert (list != NULL); | 617 | nih_assert (list != NULL); |
385 | 569 | 618 | ||
394 | 570 | /* Iterate the operator tree, filtering out nodes with a non-TRUE | 619 | if (! root->value) |
395 | 571 | * value and their children. The rationale for this is that this | 620 | return; |
396 | 572 | * then matches only the events that had an active role in starting | 621 | |
397 | 573 | * the job, not the ones that were also blocked, but the other half | 622 | NIH_LIST_FOREACH (&root->children, iter) { |
390 | 574 | * of their logic wasn't present. | ||
391 | 575 | */ | ||
392 | 576 | NIH_TREE_FOREACH_FULL (&root->node, iter, | ||
393 | 577 | (NihTreeFilter)event_operator_filter, NULL) { | ||
398 | 578 | EventOperator *oper = (EventOperator *)iter; | 623 | EventOperator *oper = (EventOperator *)iter; |
411 | 579 | Blocked *blocked; | 624 | |
412 | 580 | 625 | event_operator_events (oper, parent, list); | |
401 | 581 | if (oper->type != EVENT_MATCH) | ||
402 | 582 | continue; | ||
403 | 583 | |||
404 | 584 | nih_assert (oper->event != NULL); | ||
405 | 585 | |||
406 | 586 | blocked = NIH_MUST (blocked_new (parent, BLOCKED_EVENT, | ||
407 | 587 | oper->event)); | ||
408 | 588 | nih_list_add (list, &blocked->entry); | ||
409 | 589 | |||
410 | 590 | event_block (blocked->event); | ||
413 | 591 | } | 626 | } |
414 | 627 | |||
415 | 628 | |||
416 | 629 | if (root->type != EVENT_MATCH) | ||
417 | 630 | return; | ||
418 | 631 | |||
419 | 632 | nih_assert (root->event != NULL); | ||
420 | 633 | |||
421 | 634 | blocked = NIH_MUST (blocked_new (parent, BLOCKED_EVENT, | ||
422 | 635 | root->event)); | ||
423 | 636 | nih_list_add (list, &blocked->entry); | ||
424 | 637 | |||
425 | 638 | event_block (blocked->event); | ||
426 | 592 | } | 639 | } |
427 | 593 | 640 | ||
428 | 594 | 641 | ||
429 | @@ -606,24 +653,26 @@ | |||
430 | 606 | nih_assert (root != NULL); | 653 | nih_assert (root != NULL); |
431 | 607 | 654 | ||
432 | 608 | /* A post-order iteration means we visit children first, perfect! */ | 655 | /* A post-order iteration means we visit children first, perfect! */ |
434 | 609 | NIH_TREE_FOREACH_POST (&root->node, iter) { | 656 | NIH_LIST_FOREACH (&root->children, iter) { |
435 | 610 | EventOperator *oper = (EventOperator *)iter; | 657 | EventOperator *oper = (EventOperator *)iter; |
436 | 611 | 658 | ||
452 | 612 | switch (oper->type) { | 659 | event_operator_reset (oper); |
453 | 613 | case EVENT_OR: | 660 | } |
454 | 614 | case EVENT_AND: | 661 | |
455 | 615 | event_operator_update (oper); | 662 | switch (root->type) { |
456 | 616 | break; | 663 | case EVENT_ANY: |
457 | 617 | case EVENT_MATCH: | 664 | case EVENT_ALL: |
458 | 618 | oper->value = FALSE; | 665 | event_operator_update (root); |
459 | 619 | 666 | break; | |
460 | 620 | if (oper->event) { | 667 | case EVENT_MATCH: |
461 | 621 | event_unblock (oper->event); | 668 | root->value = FALSE; |
462 | 622 | oper->event = NULL; | 669 | |
463 | 623 | } | 670 | if (root->event) { |
464 | 624 | break; | 671 | event_unblock (root->event); |
465 | 625 | default: | 672 | root->event = NULL; |
451 | 626 | nih_assert_not_reached (); | ||
466 | 627 | } | 673 | } |
467 | 674 | break; | ||
468 | 675 | default: | ||
469 | 676 | nih_assert_not_reached (); | ||
470 | 628 | } | 677 | } |
471 | 629 | } | 678 | } |
472 | 630 | 679 | ||
473 | === modified file 'init/event_operator.h' | |||
474 | --- init/event_operator.h 2009-06-23 09:29:35 +0000 | |||
475 | +++ init/event_operator.h 2009-08-11 05:12:01 +0000 | |||
476 | @@ -33,14 +33,15 @@ | |||
477 | 33 | * the EventOperator structure. | 33 | * the EventOperator structure. |
478 | 34 | **/ | 34 | **/ |
479 | 35 | typedef enum event_operator_type { | 35 | typedef enum event_operator_type { |
482 | 36 | EVENT_OR, | 36 | EVENT_ANY, |
483 | 37 | EVENT_AND, | 37 | EVENT_ALL, |
484 | 38 | EVENT_MATCH | 38 | EVENT_MATCH |
485 | 39 | } EventOperatorType; | 39 | } EventOperatorType; |
486 | 40 | 40 | ||
487 | 41 | /** | 41 | /** |
488 | 42 | * EventOperator: | 42 | * EventOperator: |
490 | 43 | * @node: tree node, | 43 | * @entry: sibling list entry, |
491 | 44 | * @children: list of children, | ||
492 | 44 | * @type: operator type, | 45 | * @type: operator type, |
493 | 45 | * @value: operator value, | 46 | * @value: operator value, |
494 | 46 | * @name: name of event to match (EVENT_MATCH only), | 47 | * @name: name of event to match (EVENT_MATCH only), |
495 | @@ -49,19 +50,20 @@ | |||
496 | 49 | * | 50 | * |
497 | 50 | * This structure is used to build up an event expression tree; the leaf | 51 | * This structure is used to build up an event expression tree; the leaf |
498 | 51 | * nodes are all of EVENT_MATCH type which match a specific event, the other | 52 | * nodes are all of EVENT_MATCH type which match a specific event, the other |
501 | 52 | * nodes are built up of EVENT_OR and EVENT_AND operators that combine the | 53 | * nodes are built up of EVENT_ANY and EVENT_ALL operators that combine the |
502 | 53 | * EventOperators to their left and right in interesting ways. | 54 | * EventOperators which are their children in interesting ways. |
503 | 54 | * | 55 | * |
504 | 55 | * @value indicates whether this operator is currently TRUE or FALSE. | 56 | * @value indicates whether this operator is currently TRUE or FALSE. |
505 | 56 | * For EVENT_MATCH operators, a TRUE @value means that @event is set to | 57 | * For EVENT_MATCH operators, a TRUE @value means that @event is set to |
508 | 57 | * the matched event; for EVENT_OR and EVENT_AND operators, @value is set | 58 | * the matched event; for EVENT_ANY and EVENT_ALL operators, @value is set |
509 | 58 | * depending on the value of both immediate children. | 59 | * depending on the value of the immediate children. |
510 | 59 | * | 60 | * |
511 | 60 | * Once an event has been matched, the @event member is set and a reference | 61 | * Once an event has been matched, the @event member is set and a reference |
512 | 61 | * held until the structure is cleared. | 62 | * held until the structure is cleared. |
513 | 62 | **/ | 63 | **/ |
514 | 63 | typedef struct event_operator { | 64 | typedef struct event_operator { |
516 | 64 | NihTree node; | 65 | NihList entry; |
517 | 66 | NihList children; | ||
518 | 65 | EventOperatorType type; | 67 | EventOperatorType type; |
519 | 66 | 68 | ||
520 | 67 | int value; | 69 | int value; |
521 | @@ -84,6 +86,8 @@ | |||
522 | 84 | __attribute__ ((warn_unused_result, malloc)); | 86 | __attribute__ ((warn_unused_result, malloc)); |
523 | 85 | 87 | ||
524 | 86 | int event_operator_destroy (EventOperator *oper); | 88 | int event_operator_destroy (EventOperator *oper); |
525 | 89 | void event_operator_add_child (EventOperator *oper, | ||
526 | 90 | EventOperator *child); | ||
527 | 87 | 91 | ||
528 | 88 | void event_operator_update (EventOperator *oper); | 92 | void event_operator_update (EventOperator *oper); |
529 | 89 | int event_operator_match (EventOperator *oper, Event *event, | 93 | int event_operator_match (EventOperator *oper, Event *event, |
530 | 90 | 94 | ||
531 | === modified file 'init/parse_job.c' | |||
532 | --- init/parse_job.c 2009-07-09 11:01:53 +0000 | |||
533 | +++ init/parse_job.c 2009-08-11 05:12:01 +0000 | |||
534 | @@ -644,9 +644,9 @@ | |||
535 | 644 | * back to the starting position and deal with it as an operand. | 644 | * back to the starting position and deal with it as an operand. |
536 | 645 | */ | 645 | */ |
537 | 646 | if (! strcmp (arg, "and")) { | 646 | if (! strcmp (arg, "and")) { |
539 | 647 | type = EVENT_AND; | 647 | type = EVENT_ALL; |
540 | 648 | } else if (! strcmp (arg, "or")) { | 648 | } else if (! strcmp (arg, "or")) { |
542 | 649 | type = EVENT_OR; | 649 | type = EVENT_ANY; |
543 | 650 | } else { | 650 | } else { |
544 | 651 | return parse_on_operand (class, stanza, file, len, pos, lineno, | 651 | return parse_on_operand (class, stanza, file, len, pos, lineno, |
545 | 652 | stack, root); | 652 | stack, root); |
546 | @@ -665,10 +665,8 @@ | |||
547 | 665 | if (! oper) | 665 | if (! oper) |
548 | 666 | nih_return_system_error (-1); | 666 | nih_return_system_error (-1); |
549 | 667 | 667 | ||
551 | 668 | nih_ref (*root, oper); | 668 | event_operator_add_child (oper, *root); |
552 | 669 | nih_unref (*root, class); | 669 | nih_unref (*root, class); |
553 | 670 | |||
554 | 671 | nih_tree_add (&oper->node, &(*root)->node, NIH_TREE_LEFT); | ||
555 | 672 | *root = NULL; | 670 | *root = NULL; |
556 | 673 | 671 | ||
557 | 674 | /* Push the new operator onto the stack */ | 672 | /* Push the new operator onto the stack */ |
558 | @@ -938,11 +936,8 @@ | |||
559 | 938 | * event matches. | 936 | * event matches. |
560 | 939 | */ | 937 | */ |
561 | 940 | if ((oper->type != EVENT_MATCH) && (*root)) { | 938 | if ((oper->type != EVENT_MATCH) && (*root)) { |
563 | 941 | nih_ref (*root, oper); | 939 | event_operator_add_child (oper, *root); |
564 | 942 | nih_unref (*root, class); | 940 | nih_unref (*root, class); |
565 | 943 | |||
566 | 944 | nih_tree_add (&oper->node, &(*root)->node, | ||
567 | 945 | NIH_TREE_RIGHT); | ||
568 | 946 | } else if (oper->type != EVENT_MATCH) { | 941 | } else if (oper->type != EVENT_MATCH) { |
569 | 947 | nih_return_error (-1, PARSE_EXPECTED_EVENT, | 942 | nih_return_error (-1, PARSE_EXPECTED_EVENT, |
570 | 948 | _(PARSE_EXPECTED_EVENT_STR)); | 943 | _(PARSE_EXPECTED_EVENT_STR)); |
571 | 949 | 944 | ||
572 | === modified file 'init/tests/test_event.c' | |||
573 | --- init/tests/test_event.c 2009-08-04 00:19:41 +0000 | |||
574 | +++ init/tests/test_event.c 2009-08-11 05:51:31 +0000 | |||
575 | @@ -275,6 +275,7 @@ | |||
576 | 275 | EventOperator *oper; | 275 | EventOperator *oper; |
577 | 276 | Blocked *blocked = NULL, *blocked1 = NULL, *blocked2 = NULL; | 276 | Blocked *blocked = NULL, *blocked1 = NULL, *blocked2 = NULL; |
578 | 277 | char **env1 = NULL, **env2 = NULL; | 277 | char **env1 = NULL, **env2 = NULL; |
579 | 278 | int any_true = FALSE, all_true = TRUE; | ||
580 | 278 | 279 | ||
581 | 279 | TEST_FUNCTION ("event_pending_handle_jobs"); | 280 | TEST_FUNCTION ("event_pending_handle_jobs"); |
582 | 280 | program_name = "test"; | 281 | program_name = "test"; |
583 | @@ -331,17 +332,15 @@ | |||
584 | 331 | class->task = TRUE; | 332 | class->task = TRUE; |
585 | 332 | 333 | ||
586 | 333 | class->start_on = event_operator_new ( | 334 | class->start_on = event_operator_new ( |
588 | 334 | class, EVENT_AND, NULL, NULL); | 335 | class, EVENT_ALL, NULL, NULL); |
589 | 335 | 336 | ||
590 | 336 | oper = event_operator_new ( | 337 | oper = event_operator_new ( |
591 | 337 | class->start_on, EVENT_MATCH, "wibble", NULL); | 338 | class->start_on, EVENT_MATCH, "wibble", NULL); |
594 | 338 | nih_tree_add (&class->start_on->node, &oper->node, | 339 | event_operator_add_child (class->start_on, oper); |
593 | 339 | NIH_TREE_LEFT); | ||
595 | 340 | 340 | ||
596 | 341 | oper = event_operator_new ( | 341 | oper = event_operator_new ( |
597 | 342 | class->start_on, EVENT_MATCH, "wobble", NULL); | 342 | class->start_on, EVENT_MATCH, "wobble", NULL); |
600 | 343 | nih_tree_add (&class->start_on->node, &oper->node, | 343 | event_operator_add_child (class->start_on, oper); |
599 | 344 | NIH_TREE_RIGHT); | ||
601 | 345 | 344 | ||
602 | 346 | nih_hash_add (job_classes, &class->entry); | 345 | nih_hash_add (job_classes, &class->entry); |
603 | 347 | } | 346 | } |
604 | @@ -358,13 +357,18 @@ | |||
605 | 358 | TEST_EQ (oper->value, FALSE); | 357 | TEST_EQ (oper->value, FALSE); |
606 | 359 | TEST_EQ_P (oper->event, NULL); | 358 | TEST_EQ_P (oper->event, NULL); |
607 | 360 | 359 | ||
615 | 361 | oper = (EventOperator *)class->start_on->node.left; | 360 | NIH_LIST_FOREACH (&oper->children, iter) { |
616 | 362 | TEST_EQ (oper->value, TRUE); | 361 | EventOperator *child = (EventOperator *)iter; |
617 | 363 | TEST_EQ_P (oper->event, event1); | 362 | |
618 | 364 | 363 | any_true = any_true || child->value; | |
619 | 365 | oper = (EventOperator *)class->start_on->node.right; | 364 | all_true = all_true && child->value; |
620 | 366 | TEST_EQ (oper->value, FALSE); | 365 | } |
621 | 367 | TEST_EQ_P (oper->event, NULL); | 366 | |
622 | 367 | TEST_EQ (any_true, TRUE); | ||
623 | 368 | TEST_EQ (all_true, FALSE); | ||
624 | 369 | |||
625 | 370 | any_true = FALSE; | ||
626 | 371 | all_true = TRUE; | ||
627 | 368 | 372 | ||
628 | 369 | nih_free (class); | 373 | nih_free (class); |
629 | 370 | nih_free (event1); | 374 | nih_free (event1); |
630 | @@ -395,17 +399,15 @@ | |||
631 | 395 | NULL, "BAR=BAZ")); | 399 | NULL, "BAR=BAZ")); |
632 | 396 | 400 | ||
633 | 397 | class->start_on = event_operator_new ( | 401 | class->start_on = event_operator_new ( |
635 | 398 | class, EVENT_AND, NULL, NULL); | 402 | class, EVENT_ALL, NULL, NULL); |
636 | 399 | 403 | ||
637 | 400 | oper = event_operator_new ( | 404 | oper = event_operator_new ( |
638 | 401 | class->start_on, EVENT_MATCH, "wibble", NULL); | 405 | class->start_on, EVENT_MATCH, "wibble", NULL); |
641 | 402 | nih_tree_add (&class->start_on->node, &oper->node, | 406 | event_operator_add_child (class->start_on, oper); |
640 | 403 | NIH_TREE_LEFT); | ||
642 | 404 | 407 | ||
643 | 405 | oper = event_operator_new ( | 408 | oper = event_operator_new ( |
644 | 406 | class->start_on, EVENT_MATCH, "wobble", NULL); | 409 | class->start_on, EVENT_MATCH, "wobble", NULL); |
647 | 407 | nih_tree_add (&class->start_on->node, &oper->node, | 410 | event_operator_add_child (class->start_on, oper); |
646 | 408 | NIH_TREE_RIGHT); | ||
648 | 409 | 411 | ||
649 | 410 | nih_hash_add (job_classes, &class->entry); | 412 | nih_hash_add (job_classes, &class->entry); |
650 | 411 | } | 413 | } |
651 | @@ -447,14 +449,18 @@ | |||
652 | 447 | TEST_EQ (oper->value, FALSE); | 449 | TEST_EQ (oper->value, FALSE); |
653 | 448 | TEST_EQ_P (oper->event, NULL); | 450 | TEST_EQ_P (oper->event, NULL); |
654 | 449 | 451 | ||
663 | 450 | oper = (EventOperator *)class->start_on->node.left; | 452 | NIH_LIST_FOREACH (&oper->children, iter) { |
664 | 451 | TEST_EQ (oper->value, FALSE); | 453 | EventOperator *child = (EventOperator *)iter; |
665 | 452 | TEST_EQ_P (oper->event, NULL); | 454 | |
666 | 453 | 455 | any_true = any_true || child->value; | |
667 | 454 | oper = (EventOperator *)class->start_on->node.right; | 456 | all_true = all_true && child->value; |
668 | 455 | TEST_EQ (oper->value, FALSE); | 457 | } |
669 | 456 | TEST_EQ_P (oper->event, NULL); | 458 | |
670 | 457 | 459 | TEST_EQ (any_true, FALSE); | |
671 | 460 | TEST_EQ (all_true, FALSE); | ||
672 | 461 | |||
673 | 462 | any_true = FALSE; | ||
674 | 463 | all_true = TRUE; | ||
675 | 458 | 464 | ||
676 | 459 | TEST_LIST_NOT_EMPTY (&job->blocking); | 465 | TEST_LIST_NOT_EMPTY (&job->blocking); |
677 | 460 | 466 | ||
678 | @@ -511,17 +517,15 @@ | |||
679 | 511 | NULL, "BAR=BAZ")); | 517 | NULL, "BAR=BAZ")); |
680 | 512 | 518 | ||
681 | 513 | class->start_on = event_operator_new ( | 519 | class->start_on = event_operator_new ( |
683 | 514 | class, EVENT_AND, NULL, NULL); | 520 | class, EVENT_ALL, NULL, NULL); |
684 | 515 | 521 | ||
685 | 516 | oper = event_operator_new ( | 522 | oper = event_operator_new ( |
686 | 517 | class->start_on, EVENT_MATCH, "wibble", NULL); | 523 | class->start_on, EVENT_MATCH, "wibble", NULL); |
689 | 518 | nih_tree_add (&class->start_on->node, &oper->node, | 524 | event_operator_add_child (class->start_on, oper); |
688 | 519 | NIH_TREE_LEFT); | ||
690 | 520 | 525 | ||
691 | 521 | oper = event_operator_new ( | 526 | oper = event_operator_new ( |
692 | 522 | class->start_on, EVENT_MATCH, "wobble", NULL); | 527 | class->start_on, EVENT_MATCH, "wobble", NULL); |
695 | 523 | nih_tree_add (&class->start_on->node, &oper->node, | 528 | event_operator_add_child (class->start_on, oper); |
694 | 524 | NIH_TREE_RIGHT); | ||
696 | 525 | 529 | ||
697 | 526 | nih_hash_add (job_classes, &class->entry); | 530 | nih_hash_add (job_classes, &class->entry); |
698 | 527 | } | 531 | } |
699 | @@ -572,13 +576,18 @@ | |||
700 | 572 | oper = class->start_on; | 576 | oper = class->start_on; |
701 | 573 | TEST_EQ (oper->value, FALSE); | 577 | TEST_EQ (oper->value, FALSE); |
702 | 574 | 578 | ||
710 | 575 | oper = (EventOperator *)class->start_on->node.left; | 579 | NIH_LIST_FOREACH (&oper->children, iter) { |
711 | 576 | TEST_EQ (oper->value, FALSE); | 580 | EventOperator *child = (EventOperator *)iter; |
712 | 577 | TEST_EQ_P (oper->event, NULL); | 581 | |
713 | 578 | 582 | any_true = any_true || child->value; | |
714 | 579 | oper = (EventOperator *)class->start_on->node.right; | 583 | all_true = all_true && child->value; |
715 | 580 | TEST_EQ (oper->value, FALSE); | 584 | } |
716 | 581 | TEST_EQ_P (oper->event, NULL); | 585 | |
717 | 586 | TEST_EQ (any_true, FALSE); | ||
718 | 587 | TEST_EQ (all_true, FALSE); | ||
719 | 588 | |||
720 | 589 | any_true = FALSE; | ||
721 | 590 | all_true = TRUE; | ||
722 | 582 | 591 | ||
723 | 583 | 592 | ||
724 | 584 | TEST_LIST_NOT_EMPTY (&job->blocking); | 593 | TEST_LIST_NOT_EMPTY (&job->blocking); |
725 | @@ -637,17 +646,15 @@ | |||
726 | 637 | NULL, "BAR=BAZ")); | 646 | NULL, "BAR=BAZ")); |
727 | 638 | 647 | ||
728 | 639 | class->start_on = event_operator_new ( | 648 | class->start_on = event_operator_new ( |
730 | 640 | class, EVENT_AND, NULL, NULL); | 649 | class, EVENT_ALL, NULL, NULL); |
731 | 641 | 650 | ||
732 | 642 | oper = event_operator_new ( | 651 | oper = event_operator_new ( |
733 | 643 | class->start_on, EVENT_MATCH, "wibble", NULL); | 652 | class->start_on, EVENT_MATCH, "wibble", NULL); |
736 | 644 | nih_tree_add (&class->start_on->node, &oper->node, | 653 | event_operator_add_child (class->start_on, oper); |
735 | 645 | NIH_TREE_LEFT); | ||
737 | 646 | 654 | ||
738 | 647 | oper = event_operator_new ( | 655 | oper = event_operator_new ( |
739 | 648 | class->start_on, EVENT_MATCH, "wobble", NULL); | 656 | class->start_on, EVENT_MATCH, "wobble", NULL); |
742 | 649 | nih_tree_add (&class->start_on->node, &oper->node, | 657 | event_operator_add_child (class->start_on, oper); |
741 | 650 | NIH_TREE_RIGHT); | ||
743 | 651 | 658 | ||
744 | 652 | nih_hash_add (job_classes, &class->entry); | 659 | nih_hash_add (job_classes, &class->entry); |
745 | 653 | 660 | ||
746 | @@ -736,13 +743,18 @@ | |||
747 | 736 | oper = class->start_on; | 743 | oper = class->start_on; |
748 | 737 | TEST_EQ (oper->value, FALSE); | 744 | TEST_EQ (oper->value, FALSE); |
749 | 738 | 745 | ||
757 | 739 | oper = (EventOperator *)class->start_on->node.left; | 746 | NIH_LIST_FOREACH (&oper->children, iter) { |
758 | 740 | TEST_EQ (oper->value, FALSE); | 747 | EventOperator *child = (EventOperator *)iter; |
759 | 741 | TEST_EQ_P (oper->event, NULL); | 748 | |
760 | 742 | 749 | any_true = any_true || child->value; | |
761 | 743 | oper = (EventOperator *)class->start_on->node.right; | 750 | all_true = all_true && child->value; |
762 | 744 | TEST_EQ (oper->value, FALSE); | 751 | } |
763 | 745 | TEST_EQ_P (oper->event, NULL); | 752 | |
764 | 753 | TEST_EQ (any_true, FALSE); | ||
765 | 754 | TEST_EQ (all_true, FALSE); | ||
766 | 755 | |||
767 | 756 | any_true = FALSE; | ||
768 | 757 | all_true = TRUE; | ||
769 | 746 | 758 | ||
770 | 747 | TEST_FREE (blocked1); | 759 | TEST_FREE (blocked1); |
771 | 748 | TEST_FREE (blocked2); | 760 | TEST_FREE (blocked2); |
772 | @@ -805,17 +817,15 @@ | |||
773 | 805 | NULL, "BAR=BAZ")); | 817 | NULL, "BAR=BAZ")); |
774 | 806 | 818 | ||
775 | 807 | class->start_on = event_operator_new ( | 819 | class->start_on = event_operator_new ( |
777 | 808 | class, EVENT_AND, NULL, NULL); | 820 | class, EVENT_ALL, NULL, NULL); |
778 | 809 | 821 | ||
779 | 810 | oper = event_operator_new ( | 822 | oper = event_operator_new ( |
780 | 811 | class->start_on, EVENT_MATCH, "wibble", NULL); | 823 | class->start_on, EVENT_MATCH, "wibble", NULL); |
783 | 812 | nih_tree_add (&class->start_on->node, &oper->node, | 824 | event_operator_add_child (class->start_on, oper); |
782 | 813 | NIH_TREE_LEFT); | ||
784 | 814 | 825 | ||
785 | 815 | oper = event_operator_new ( | 826 | oper = event_operator_new ( |
786 | 816 | class->start_on, EVENT_MATCH, "wobble", NULL); | 827 | class->start_on, EVENT_MATCH, "wobble", NULL); |
789 | 817 | nih_tree_add (&class->start_on->node, &oper->node, | 828 | event_operator_add_child (class->start_on, oper); |
788 | 818 | NIH_TREE_RIGHT); | ||
790 | 819 | 829 | ||
791 | 820 | nih_hash_add (job_classes, &class->entry); | 830 | nih_hash_add (job_classes, &class->entry); |
792 | 821 | 831 | ||
793 | @@ -886,13 +896,18 @@ | |||
794 | 886 | oper = class->start_on; | 896 | oper = class->start_on; |
795 | 887 | TEST_EQ (oper->value, FALSE); | 897 | TEST_EQ (oper->value, FALSE); |
796 | 888 | 898 | ||
804 | 889 | oper = (EventOperator *)class->start_on->node.left; | 899 | NIH_LIST_FOREACH (&oper->children, iter) { |
805 | 890 | TEST_EQ (oper->value, FALSE); | 900 | EventOperator *child = (EventOperator *)iter; |
806 | 891 | TEST_EQ_P (oper->event, NULL); | 901 | |
807 | 892 | 902 | any_true = any_true || child->value; | |
808 | 893 | oper = (EventOperator *)class->start_on->node.right; | 903 | all_true = all_true && child->value; |
809 | 894 | TEST_EQ (oper->value, FALSE); | 904 | } |
810 | 895 | TEST_EQ_P (oper->event, NULL); | 905 | |
811 | 906 | TEST_EQ (any_true, FALSE); | ||
812 | 907 | TEST_EQ (all_true, FALSE); | ||
813 | 908 | |||
814 | 909 | any_true = FALSE; | ||
815 | 910 | all_true = TRUE; | ||
816 | 896 | 911 | ||
817 | 897 | TEST_LIST_NOT_EMPTY (&job->blocking); | 912 | TEST_LIST_NOT_EMPTY (&job->blocking); |
818 | 898 | TEST_NOT_FREE (blocked1); | 913 | TEST_NOT_FREE (blocked1); |
819 | @@ -1704,17 +1719,15 @@ | |||
820 | 1704 | class->process[PROCESS_MAIN]->command = "echo"; | 1719 | class->process[PROCESS_MAIN]->command = "echo"; |
821 | 1705 | 1720 | ||
822 | 1706 | class->start_on = event_operator_new ( | 1721 | class->start_on = event_operator_new ( |
824 | 1707 | class, EVENT_OR, NULL, NULL); | 1722 | class, EVENT_ANY, NULL, NULL); |
825 | 1708 | 1723 | ||
826 | 1709 | oper = event_operator_new (class, EVENT_MATCH, | 1724 | oper = event_operator_new (class, EVENT_MATCH, |
827 | 1710 | "test/failed", NULL); | 1725 | "test/failed", NULL); |
830 | 1711 | nih_tree_add (&class->start_on->node, &oper->node, | 1726 | event_operator_add_child (class->start_on, oper); |
829 | 1712 | NIH_TREE_LEFT); | ||
831 | 1713 | 1727 | ||
832 | 1714 | oper = event_operator_new (class, EVENT_MATCH, | 1728 | oper = event_operator_new (class, EVENT_MATCH, |
833 | 1715 | "test/failed/failed", NULL); | 1729 | "test/failed/failed", NULL); |
836 | 1716 | nih_tree_add (&class->start_on->node, &oper->node, | 1730 | event_operator_add_child (class->start_on, oper); |
835 | 1717 | NIH_TREE_RIGHT); | ||
837 | 1718 | 1731 | ||
838 | 1719 | nih_hash_add (job_classes, &class->entry); | 1732 | nih_hash_add (job_classes, &class->entry); |
839 | 1720 | } | 1733 | } |
840 | 1721 | 1734 | ||
841 | === modified file 'init/tests/test_event_operator.c' | |||
842 | --- init/tests/test_event_operator.c 2009-08-04 00:20:04 +0000 | |||
843 | +++ init/tests/test_event_operator.c 2009-08-11 05:51:31 +0000 | |||
844 | @@ -53,9 +53,7 @@ | |||
845 | 53 | } | 53 | } |
846 | 54 | 54 | ||
847 | 55 | TEST_ALLOC_SIZE (oper, sizeof (EventOperator)); | 55 | TEST_ALLOC_SIZE (oper, sizeof (EventOperator)); |
851 | 56 | TEST_EQ_P (oper->node.parent, NULL); | 56 | TEST_LIST_EMPTY (&oper->children); |
849 | 57 | TEST_EQ_P (oper->node.left, NULL); | ||
850 | 58 | TEST_EQ_P (oper->node.right, NULL); | ||
852 | 59 | TEST_EQ (oper->value, FALSE); | 57 | TEST_EQ (oper->value, FALSE); |
853 | 60 | TEST_EQ_STR (oper->name, "test"); | 58 | TEST_EQ_STR (oper->name, "test"); |
854 | 61 | TEST_ALLOC_PARENT (oper->name, oper); | 59 | TEST_ALLOC_PARENT (oper->name, oper); |
855 | @@ -92,9 +90,7 @@ | |||
856 | 92 | nih_discard (env); | 90 | nih_discard (env); |
857 | 93 | 91 | ||
858 | 94 | TEST_ALLOC_SIZE (oper, sizeof (EventOperator)); | 92 | TEST_ALLOC_SIZE (oper, sizeof (EventOperator)); |
862 | 95 | TEST_EQ_P (oper->node.parent, NULL); | 93 | TEST_LIST_EMPTY (&oper->children); |
860 | 96 | TEST_EQ_P (oper->node.left, NULL); | ||
861 | 97 | TEST_EQ_P (oper->node.right, NULL); | ||
863 | 98 | TEST_EQ (oper->value, FALSE); | 94 | TEST_EQ (oper->value, FALSE); |
864 | 99 | TEST_EQ_STR (oper->name, "test"); | 95 | TEST_EQ_STR (oper->name, "test"); |
865 | 100 | TEST_ALLOC_PARENT (oper->name, oper); | 96 | TEST_ALLOC_PARENT (oper->name, oper); |
866 | @@ -109,9 +105,9 @@ | |||
867 | 109 | 105 | ||
868 | 110 | 106 | ||
869 | 111 | /* Check that an ordinary operator needs no name attached. */ | 107 | /* Check that an ordinary operator needs no name attached. */ |
871 | 112 | TEST_FEATURE ("with EVENT_OR"); | 108 | TEST_FEATURE ("with EVENT_ANY"); |
872 | 113 | TEST_ALLOC_FAIL { | 109 | TEST_ALLOC_FAIL { |
874 | 114 | oper = event_operator_new (NULL, EVENT_OR, NULL, NULL); | 110 | oper = event_operator_new (NULL, EVENT_ANY, NULL, NULL); |
875 | 115 | 111 | ||
876 | 116 | if (test_alloc_failed) { | 112 | if (test_alloc_failed) { |
877 | 117 | TEST_EQ_P (oper, NULL); | 113 | TEST_EQ_P (oper, NULL); |
878 | @@ -119,9 +115,7 @@ | |||
879 | 119 | } | 115 | } |
880 | 120 | 116 | ||
881 | 121 | TEST_ALLOC_SIZE (oper, sizeof (EventOperator)); | 117 | TEST_ALLOC_SIZE (oper, sizeof (EventOperator)); |
885 | 122 | TEST_EQ_P (oper->node.parent, NULL); | 118 | TEST_LIST_EMPTY (&oper->children); |
883 | 123 | TEST_EQ_P (oper->node.left, NULL); | ||
884 | 124 | TEST_EQ_P (oper->node.right, NULL); | ||
886 | 125 | TEST_EQ (oper->value, FALSE); | 119 | TEST_EQ (oper->value, FALSE); |
887 | 126 | TEST_EQ_P (oper->name, NULL); | 120 | TEST_EQ_P (oper->name, NULL); |
888 | 127 | TEST_EQ_P (oper->env, NULL); | 121 | TEST_EQ_P (oper->env, NULL); |
889 | @@ -143,10 +137,10 @@ | |||
890 | 143 | /* Check that we can copy a plain event operator, the value should | 137 | /* Check that we can copy a plain event operator, the value should |
891 | 144 | * be copied as well, and the other fields left as NULL. | 138 | * be copied as well, and the other fields left as NULL. |
892 | 145 | */ | 139 | */ |
894 | 146 | TEST_FEATURE ("with EVENT_OR"); | 140 | TEST_FEATURE ("with EVENT_ANY"); |
895 | 147 | TEST_ALLOC_FAIL { | 141 | TEST_ALLOC_FAIL { |
896 | 148 | TEST_ALLOC_SAFE { | 142 | TEST_ALLOC_SAFE { |
898 | 149 | oper = event_operator_new (NULL, EVENT_OR, NULL, NULL); | 143 | oper = event_operator_new (NULL, EVENT_ANY, NULL, NULL); |
899 | 150 | oper->value = TRUE; | 144 | oper->value = TRUE; |
900 | 151 | } | 145 | } |
901 | 152 | 146 | ||
902 | @@ -159,10 +153,8 @@ | |||
903 | 159 | } | 153 | } |
904 | 160 | 154 | ||
905 | 161 | TEST_ALLOC_SIZE (copy, sizeof (EventOperator)); | 155 | TEST_ALLOC_SIZE (copy, sizeof (EventOperator)); |
910 | 162 | TEST_EQ_P (copy->node.parent, NULL); | 156 | TEST_LIST_EMPTY (©->children); |
911 | 163 | TEST_EQ_P (copy->node.left, NULL); | 157 | TEST_EQ (copy->type, EVENT_ANY); |
908 | 164 | TEST_EQ_P (copy->node.right, NULL); | ||
909 | 165 | TEST_EQ (copy->type, EVENT_OR); | ||
912 | 166 | TEST_EQ (copy->value, TRUE); | 158 | TEST_EQ (copy->value, TRUE); |
913 | 167 | TEST_EQ_P (copy->name, NULL); | 159 | TEST_EQ_P (copy->name, NULL); |
914 | 168 | TEST_EQ_P (copy->env, NULL); | 160 | TEST_EQ_P (copy->env, NULL); |
915 | @@ -193,9 +185,7 @@ | |||
916 | 193 | } | 185 | } |
917 | 194 | 186 | ||
918 | 195 | TEST_ALLOC_SIZE (copy, sizeof (EventOperator)); | 187 | TEST_ALLOC_SIZE (copy, sizeof (EventOperator)); |
922 | 196 | TEST_EQ_P (copy->node.parent, NULL); | 188 | TEST_LIST_EMPTY (©->children); |
920 | 197 | TEST_EQ_P (copy->node.left, NULL); | ||
921 | 198 | TEST_EQ_P (copy->node.right, NULL); | ||
923 | 199 | TEST_EQ (copy->type, EVENT_MATCH); | 189 | TEST_EQ (copy->type, EVENT_MATCH); |
924 | 200 | TEST_EQ (copy->value, TRUE); | 190 | TEST_EQ (copy->value, TRUE); |
925 | 201 | TEST_EQ_STR (copy->name, "test"); | 191 | TEST_EQ_STR (copy->name, "test"); |
926 | @@ -233,9 +223,7 @@ | |||
927 | 233 | } | 223 | } |
928 | 234 | 224 | ||
929 | 235 | TEST_ALLOC_SIZE (copy, sizeof (EventOperator)); | 225 | TEST_ALLOC_SIZE (copy, sizeof (EventOperator)); |
933 | 236 | TEST_EQ_P (copy->node.parent, NULL); | 226 | TEST_LIST_EMPTY (©->children); |
931 | 237 | TEST_EQ_P (copy->node.left, NULL); | ||
932 | 238 | TEST_EQ_P (copy->node.right, NULL); | ||
934 | 239 | TEST_EQ (copy->type, EVENT_MATCH); | 227 | TEST_EQ (copy->type, EVENT_MATCH); |
935 | 240 | TEST_EQ (copy->value, TRUE); | 228 | TEST_EQ (copy->value, TRUE); |
936 | 241 | TEST_EQ_STR (copy->name, "test"); | 229 | TEST_EQ_STR (copy->name, "test"); |
937 | @@ -279,9 +267,7 @@ | |||
938 | 279 | } | 267 | } |
939 | 280 | 268 | ||
940 | 281 | TEST_ALLOC_SIZE (copy, sizeof (EventOperator)); | 269 | TEST_ALLOC_SIZE (copy, sizeof (EventOperator)); |
944 | 282 | TEST_EQ_P (copy->node.parent, NULL); | 270 | TEST_LIST_EMPTY (©->children); |
942 | 283 | TEST_EQ_P (copy->node.left, NULL); | ||
943 | 284 | TEST_EQ_P (copy->node.right, NULL); | ||
945 | 285 | TEST_EQ (copy->type, EVENT_MATCH); | 271 | TEST_EQ (copy->type, EVENT_MATCH); |
946 | 286 | TEST_EQ (copy->value, TRUE); | 272 | TEST_EQ (copy->value, TRUE); |
947 | 287 | TEST_EQ_STR (copy->name, "test"); | 273 | TEST_EQ_STR (copy->name, "test"); |
948 | @@ -302,7 +288,7 @@ | |||
949 | 302 | TEST_FEATURE ("with children"); | 288 | TEST_FEATURE ("with children"); |
950 | 303 | TEST_ALLOC_FAIL { | 289 | TEST_ALLOC_FAIL { |
951 | 304 | TEST_ALLOC_SAFE { | 290 | TEST_ALLOC_SAFE { |
953 | 305 | oper = event_operator_new (NULL, EVENT_OR, NULL, NULL); | 291 | oper = event_operator_new (NULL, EVENT_ANY, NULL, NULL); |
954 | 306 | oper->value = TRUE; | 292 | oper->value = TRUE; |
955 | 307 | 293 | ||
956 | 308 | oper1 = event_operator_new (NULL, EVENT_MATCH, | 294 | oper1 = event_operator_new (NULL, EVENT_MATCH, |
957 | @@ -310,45 +296,37 @@ | |||
958 | 310 | oper1->value = TRUE; | 296 | oper1->value = TRUE; |
959 | 311 | oper1->event = event_new (oper1, "foo", NULL); | 297 | oper1->event = event_new (oper1, "foo", NULL); |
960 | 312 | event_block (oper1->event); | 298 | event_block (oper1->event); |
963 | 313 | nih_tree_add (&oper->node, &oper1->node, | 299 | event_operator_add_child (oper, oper1); |
962 | 314 | NIH_TREE_LEFT); | ||
964 | 315 | 300 | ||
965 | 316 | oper2 = event_operator_new (NULL, EVENT_MATCH, | 301 | oper2 = event_operator_new (NULL, EVENT_MATCH, |
966 | 317 | "bar", NULL); | 302 | "bar", NULL); |
967 | 318 | oper2->value = TRUE; | 303 | oper2->value = TRUE; |
968 | 319 | oper2->event = event_new (oper2, "foo", NULL); | 304 | oper2->event = event_new (oper2, "foo", NULL); |
969 | 320 | event_block (oper2->event); | 305 | event_block (oper2->event); |
972 | 321 | nih_tree_add (&oper->node, &oper2->node, | 306 | event_operator_add_child (oper, oper2); |
971 | 322 | NIH_TREE_RIGHT); | ||
973 | 323 | } | 307 | } |
974 | 324 | 308 | ||
975 | 325 | copy = event_operator_copy (NULL, oper); | 309 | copy = event_operator_copy (NULL, oper); |
976 | 326 | 310 | ||
977 | 327 | if (test_alloc_failed) { | 311 | if (test_alloc_failed) { |
978 | 328 | TEST_EQ_P (copy, NULL); | 312 | TEST_EQ_P (copy, NULL); |
979 | 329 | nih_free (oper); | ||
980 | 330 | TEST_EQ (oper1->event->blockers, 1); | 313 | TEST_EQ (oper1->event->blockers, 1); |
981 | 331 | nih_free (oper1); | ||
982 | 332 | TEST_EQ (oper2->event->blockers, 1); | 314 | TEST_EQ (oper2->event->blockers, 1); |
984 | 333 | nih_free (oper2); | 315 | nih_free (oper); |
985 | 334 | continue; | 316 | continue; |
986 | 335 | } | 317 | } |
987 | 336 | 318 | ||
988 | 337 | TEST_ALLOC_SIZE (copy, sizeof (EventOperator)); | 319 | TEST_ALLOC_SIZE (copy, sizeof (EventOperator)); |
993 | 338 | TEST_EQ_P (copy->node.parent, NULL); | 320 | TEST_LIST_NOT_EMPTY (©->children); |
994 | 339 | TEST_NE_P (copy->node.left, NULL); | 321 | TEST_EQ (copy->type, EVENT_ANY); |
991 | 340 | TEST_NE_P (copy->node.right, NULL); | ||
992 | 341 | TEST_EQ (copy->type, EVENT_OR); | ||
995 | 342 | TEST_EQ (copy->value, TRUE); | 322 | TEST_EQ (copy->value, TRUE); |
996 | 343 | TEST_EQ_P (copy->name, NULL); | 323 | TEST_EQ_P (copy->name, NULL); |
997 | 344 | TEST_EQ_P (copy->env, NULL); | 324 | TEST_EQ_P (copy->env, NULL); |
998 | 345 | 325 | ||
1000 | 346 | copy1 = (EventOperator *)copy->node.left; | 326 | copy1 = (EventOperator *)copy->children.next; |
1001 | 347 | TEST_ALLOC_SIZE (copy1, sizeof (EventOperator)); | 327 | TEST_ALLOC_SIZE (copy1, sizeof (EventOperator)); |
1002 | 348 | TEST_ALLOC_PARENT (copy1, copy); | 328 | TEST_ALLOC_PARENT (copy1, copy); |
1006 | 349 | TEST_EQ_P (copy1->node.parent, ©->node); | 329 | TEST_LIST_EMPTY (©1->children); |
1004 | 350 | TEST_EQ_P (copy1->node.left, NULL); | ||
1005 | 351 | TEST_EQ_P (copy1->node.right, NULL); | ||
1007 | 352 | TEST_EQ (copy1->type, EVENT_MATCH); | 330 | TEST_EQ (copy1->type, EVENT_MATCH); |
1008 | 353 | TEST_EQ (copy1->value, TRUE); | 331 | TEST_EQ (copy1->value, TRUE); |
1009 | 354 | TEST_EQ_STR (copy1->name, "foo"); | 332 | TEST_EQ_STR (copy1->name, "foo"); |
1010 | @@ -360,12 +338,10 @@ | |||
1011 | 360 | 338 | ||
1012 | 361 | nih_free (copy1); | 339 | nih_free (copy1); |
1013 | 362 | 340 | ||
1015 | 363 | copy2 = (EventOperator *)copy->node.right; | 341 | copy2 = (EventOperator *)copy1->entry.next; |
1016 | 364 | TEST_ALLOC_SIZE (copy2, sizeof (EventOperator)); | 342 | TEST_ALLOC_SIZE (copy2, sizeof (EventOperator)); |
1017 | 365 | TEST_ALLOC_PARENT (copy2, copy); | 343 | TEST_ALLOC_PARENT (copy2, copy); |
1021 | 366 | TEST_EQ_P (copy2->node.parent, ©->node); | 344 | TEST_LIST_EMPTY (©1->children); |
1019 | 367 | TEST_EQ_P (copy2->node.left, NULL); | ||
1020 | 368 | TEST_EQ_P (copy2->node.right, NULL); | ||
1022 | 369 | TEST_EQ (copy2->type, EVENT_MATCH); | 345 | TEST_EQ (copy2->type, EVENT_MATCH); |
1023 | 370 | TEST_EQ (copy2->value, TRUE); | 346 | TEST_EQ (copy2->value, TRUE); |
1024 | 371 | TEST_EQ_STR (copy2->name, "bar"); | 347 | TEST_EQ_STR (copy2->name, "bar"); |
1025 | @@ -430,16 +406,16 @@ | |||
1026 | 430 | EventOperator *oper1, *oper2, *oper3; | 406 | EventOperator *oper1, *oper2, *oper3; |
1027 | 431 | 407 | ||
1028 | 432 | TEST_FUNCTION ("event_operator_update"); | 408 | TEST_FUNCTION ("event_operator_update"); |
1030 | 433 | oper1 = event_operator_new (NULL, EVENT_OR, NULL, NULL); | 409 | oper1 = event_operator_new (NULL, EVENT_ANY, NULL, NULL); |
1031 | 434 | oper2 = event_operator_new (NULL, EVENT_MATCH, "foo", NULL); | 410 | oper2 = event_operator_new (NULL, EVENT_MATCH, "foo", NULL); |
1032 | 435 | oper3 = event_operator_new (NULL, EVENT_MATCH, "bar", NULL); | 411 | oper3 = event_operator_new (NULL, EVENT_MATCH, "bar", NULL); |
1033 | 436 | 412 | ||
1040 | 437 | nih_tree_add (&oper1->node, &oper2->node, NIH_TREE_LEFT); | 413 | event_operator_add_child (oper1, oper2); |
1041 | 438 | nih_tree_add (&oper1->node, &oper3->node, NIH_TREE_RIGHT); | 414 | event_operator_add_child (oper1, oper3); |
1042 | 439 | 415 | ||
1043 | 440 | 416 | ||
1044 | 441 | /* Check that EVENT_OR is FALSE if both children are FALSE. */ | 417 | /* Check that EVENT_ANY is FALSE if both children are FALSE. */ |
1045 | 442 | TEST_FEATURE ("with EVENT_OR and both children FALSE"); | 418 | TEST_FEATURE ("with EVENT_ANY and both children FALSE"); |
1046 | 443 | oper1->value = oper2->value = oper3->value = FALSE; | 419 | oper1->value = oper2->value = oper3->value = FALSE; |
1047 | 444 | 420 | ||
1048 | 445 | event_operator_update (oper1); | 421 | event_operator_update (oper1); |
1049 | @@ -447,8 +423,8 @@ | |||
1050 | 447 | TEST_EQ (oper1->value, FALSE); | 423 | TEST_EQ (oper1->value, FALSE); |
1051 | 448 | 424 | ||
1052 | 449 | 425 | ||
1055 | 450 | /* Check that EVENT_OR is TRUE if only the left child is TRUE. */ | 426 | /* Check that EVENT_ANY is TRUE if only the left child is TRUE. */ |
1056 | 451 | TEST_FEATURE ("with EVENT_OR and only left child TRUE"); | 427 | TEST_FEATURE ("with EVENT_ANY and only left child TRUE"); |
1057 | 452 | oper1->value = oper3->value = FALSE; | 428 | oper1->value = oper3->value = FALSE; |
1058 | 453 | oper2->value = TRUE; | 429 | oper2->value = TRUE; |
1059 | 454 | 430 | ||
1060 | @@ -457,8 +433,8 @@ | |||
1061 | 457 | TEST_EQ (oper1->value, TRUE); | 433 | TEST_EQ (oper1->value, TRUE); |
1062 | 458 | 434 | ||
1063 | 459 | 435 | ||
1066 | 460 | /* Check that EVENT_OR is TRUE if only the right child is TRUE. */ | 436 | /* Check that EVENT_ANY is TRUE if only the right child is TRUE. */ |
1067 | 461 | TEST_FEATURE ("with EVENT_OR and only right child TRUE"); | 437 | TEST_FEATURE ("with EVENT_ANY and only right child TRUE"); |
1068 | 462 | oper1->value = oper2->value = FALSE; | 438 | oper1->value = oper2->value = FALSE; |
1069 | 463 | oper3->value = TRUE; | 439 | oper3->value = TRUE; |
1070 | 464 | 440 | ||
1071 | @@ -467,8 +443,8 @@ | |||
1072 | 467 | TEST_EQ (oper1->value, TRUE); | 443 | TEST_EQ (oper1->value, TRUE); |
1073 | 468 | 444 | ||
1074 | 469 | 445 | ||
1077 | 470 | /* Check that EVENT_OR is TRUE if both children are TRUE. */ | 446 | /* Check that EVENT_ANY is TRUE if both children are TRUE. */ |
1078 | 471 | TEST_FEATURE ("with EVENT_OR and both children TRUE"); | 447 | TEST_FEATURE ("with EVENT_ANY and both children TRUE"); |
1079 | 472 | oper1->value = FALSE; | 448 | oper1->value = FALSE; |
1080 | 473 | oper2->value = oper3->value = TRUE; | 449 | oper2->value = oper3->value = TRUE; |
1081 | 474 | 450 | ||
1082 | @@ -477,9 +453,9 @@ | |||
1083 | 477 | TEST_EQ (oper1->value, TRUE); | 453 | TEST_EQ (oper1->value, TRUE); |
1084 | 478 | 454 | ||
1085 | 479 | 455 | ||
1089 | 480 | /* Check that EVENT_AND is FALSE if both children are FALSE. */ | 456 | /* Check that EVENT_ALL is FALSE if both children are FALSE. */ |
1090 | 481 | TEST_FEATURE ("with EVENT_AND and both children FALSE"); | 457 | TEST_FEATURE ("with EVENT_ALL and both children FALSE"); |
1091 | 482 | oper1->type = EVENT_AND; | 458 | oper1->type = EVENT_ALL; |
1092 | 483 | oper1->value = oper2->value = oper3->value = FALSE; | 459 | oper1->value = oper2->value = oper3->value = FALSE; |
1093 | 484 | 460 | ||
1094 | 485 | event_operator_update (oper1); | 461 | event_operator_update (oper1); |
1095 | @@ -487,8 +463,8 @@ | |||
1096 | 487 | TEST_EQ (oper1->value, FALSE); | 463 | TEST_EQ (oper1->value, FALSE); |
1097 | 488 | 464 | ||
1098 | 489 | 465 | ||
1101 | 490 | /* Check that EVENT_AND is FALSE if only the left child is TRUE. */ | 466 | /* Check that EVENT_ALL is FALSE if only the left child is TRUE. */ |
1102 | 491 | TEST_FEATURE ("with EVENT_AND and only left child TRUE"); | 467 | TEST_FEATURE ("with EVENT_ALL and only left child TRUE"); |
1103 | 492 | oper1->value = oper3->value = FALSE; | 468 | oper1->value = oper3->value = FALSE; |
1104 | 493 | oper2->value = TRUE; | 469 | oper2->value = TRUE; |
1105 | 494 | 470 | ||
1106 | @@ -497,8 +473,8 @@ | |||
1107 | 497 | TEST_EQ (oper1->value, FALSE); | 473 | TEST_EQ (oper1->value, FALSE); |
1108 | 498 | 474 | ||
1109 | 499 | 475 | ||
1112 | 500 | /* Check that EVENT_AND is FALSE if only the right child is TRUE. */ | 476 | /* Check that EVENT_ALL is FALSE if only the right child is TRUE. */ |
1113 | 501 | TEST_FEATURE ("with EVENT_AND and only right child TRUE"); | 477 | TEST_FEATURE ("with EVENT_ALL and only right child TRUE"); |
1114 | 502 | oper1->value = oper2->value = FALSE; | 478 | oper1->value = oper2->value = FALSE; |
1115 | 503 | oper3->value = TRUE; | 479 | oper3->value = TRUE; |
1116 | 504 | 480 | ||
1117 | @@ -507,8 +483,8 @@ | |||
1118 | 507 | TEST_EQ (oper1->value, FALSE); | 483 | TEST_EQ (oper1->value, FALSE); |
1119 | 508 | 484 | ||
1120 | 509 | 485 | ||
1123 | 510 | /* Check that EVENT_AND is TRUE if both children are TRUE. */ | 486 | /* Check that EVENT_ALL is TRUE if both children are TRUE. */ |
1124 | 511 | TEST_FEATURE ("with EVENT_AND and both children TRUE"); | 487 | TEST_FEATURE ("with EVENT_ALL and both children TRUE"); |
1125 | 512 | oper1->value = FALSE; | 488 | oper1->value = FALSE; |
1126 | 513 | oper2->value = oper3->value = TRUE; | 489 | oper2->value = oper3->value = TRUE; |
1127 | 514 | 490 | ||
1128 | @@ -518,8 +494,6 @@ | |||
1129 | 518 | 494 | ||
1130 | 519 | 495 | ||
1131 | 520 | nih_free (oper1); | 496 | nih_free (oper1); |
1132 | 521 | nih_free (oper2); | ||
1133 | 522 | nih_free (oper3); | ||
1134 | 523 | } | 497 | } |
1135 | 524 | 498 | ||
1136 | 525 | void | 499 | void |
1137 | @@ -804,8 +778,8 @@ | |||
1138 | 804 | int ret; | 778 | int ret; |
1139 | 805 | 779 | ||
1140 | 806 | TEST_FUNCTION ("event_operator_handle"); | 780 | TEST_FUNCTION ("event_operator_handle"); |
1143 | 807 | oper1 = event_operator_new (NULL, EVENT_OR, NULL, NULL); | 781 | oper1 = event_operator_new (NULL, EVENT_ANY, NULL, NULL); |
1144 | 808 | oper2 = event_operator_new (NULL, EVENT_AND, NULL, NULL); | 782 | oper2 = event_operator_new (NULL, EVENT_ALL, NULL, NULL); |
1145 | 809 | oper3 = event_operator_new (NULL, EVENT_MATCH, "foo", NULL); | 783 | oper3 = event_operator_new (NULL, EVENT_MATCH, "foo", NULL); |
1146 | 810 | oper4 = event_operator_new (NULL, EVENT_MATCH, "bar", NULL); | 784 | oper4 = event_operator_new (NULL, EVENT_MATCH, "bar", NULL); |
1147 | 811 | oper5 = event_operator_new (NULL, EVENT_MATCH, "baz", NULL); | 785 | oper5 = event_operator_new (NULL, EVENT_MATCH, "baz", NULL); |
1148 | @@ -813,10 +787,10 @@ | |||
1149 | 813 | oper5->env[0] = "BAR=$WIBBLE"; | 787 | oper5->env[0] = "BAR=$WIBBLE"; |
1150 | 814 | oper5->env[1] = NULL; | 788 | oper5->env[1] = NULL; |
1151 | 815 | 789 | ||
1156 | 816 | nih_tree_add (&oper1->node, &oper2->node, NIH_TREE_LEFT); | 790 | event_operator_add_child (oper1, oper2); |
1157 | 817 | nih_tree_add (&oper2->node, &oper3->node, NIH_TREE_LEFT); | 791 | event_operator_add_child (oper2, oper3); |
1158 | 818 | nih_tree_add (&oper2->node, &oper4->node, NIH_TREE_RIGHT); | 792 | event_operator_add_child (oper2, oper4); |
1159 | 819 | nih_tree_add (&oper1->node, &oper5->node, NIH_TREE_RIGHT); | 793 | event_operator_add_child (oper1, oper5); |
1160 | 820 | 794 | ||
1161 | 821 | 795 | ||
1162 | 822 | /* Check that a non-matching event doesn't touch the tree. */ | 796 | /* Check that a non-matching event doesn't touch the tree. */ |
1163 | @@ -938,10 +912,6 @@ | |||
1164 | 938 | event_operator_reset (oper1); | 912 | event_operator_reset (oper1); |
1165 | 939 | 913 | ||
1166 | 940 | nih_free (oper1); | 914 | nih_free (oper1); |
1167 | 941 | nih_free (oper2); | ||
1168 | 942 | nih_free (oper3); | ||
1169 | 943 | nih_free (oper4); | ||
1170 | 944 | nih_free (oper5); | ||
1171 | 945 | 915 | ||
1172 | 946 | event_poll (); | 916 | event_poll (); |
1173 | 947 | } | 917 | } |
1174 | @@ -956,20 +926,20 @@ | |||
1175 | 956 | size_t len; | 926 | size_t len; |
1176 | 957 | 927 | ||
1177 | 958 | TEST_FUNCTION ("event_operator_environment"); | 928 | TEST_FUNCTION ("event_operator_environment"); |
1181 | 959 | root = event_operator_new (NULL, EVENT_OR, NULL, NULL); | 929 | root = event_operator_new (NULL, EVENT_ANY, NULL, NULL); |
1182 | 960 | oper1 = event_operator_new (root, EVENT_AND, NULL, NULL); | 930 | oper1 = event_operator_new (root, EVENT_ALL, NULL, NULL); |
1183 | 961 | oper2 = event_operator_new (root, EVENT_AND, NULL, NULL); | 931 | oper2 = event_operator_new (root, EVENT_ALL, NULL, NULL); |
1184 | 962 | oper3 = event_operator_new (root, EVENT_MATCH, "foo", NULL); | 932 | oper3 = event_operator_new (root, EVENT_MATCH, "foo", NULL); |
1185 | 963 | oper4 = event_operator_new (root, EVENT_MATCH, "bar", NULL); | 933 | oper4 = event_operator_new (root, EVENT_MATCH, "bar", NULL); |
1186 | 964 | oper5 = event_operator_new (root, EVENT_MATCH, "frodo", NULL); | 934 | oper5 = event_operator_new (root, EVENT_MATCH, "frodo", NULL); |
1187 | 965 | oper6 = event_operator_new (root, EVENT_MATCH, "bilbo", NULL); | 935 | oper6 = event_operator_new (root, EVENT_MATCH, "bilbo", NULL); |
1188 | 966 | 936 | ||
1195 | 967 | nih_tree_add (&root->node, &oper1->node, NIH_TREE_LEFT); | 937 | event_operator_add_child (root, oper1); |
1196 | 968 | nih_tree_add (&root->node, &oper2->node, NIH_TREE_RIGHT); | 938 | event_operator_add_child (root, oper2); |
1197 | 969 | nih_tree_add (&oper1->node, &oper3->node, NIH_TREE_LEFT); | 939 | event_operator_add_child (oper1, oper3); |
1198 | 970 | nih_tree_add (&oper1->node, &oper4->node, NIH_TREE_RIGHT); | 940 | event_operator_add_child (oper1, oper4); |
1199 | 971 | nih_tree_add (&oper2->node, &oper5->node, NIH_TREE_LEFT); | 941 | event_operator_add_child (oper2, oper5); |
1200 | 972 | nih_tree_add (&oper2->node, &oper6->node, NIH_TREE_RIGHT); | 942 | event_operator_add_child (oper2, oper6); |
1201 | 973 | 943 | ||
1202 | 974 | root->value = TRUE; | 944 | root->value = TRUE; |
1203 | 975 | 945 | ||
1204 | @@ -1124,20 +1094,20 @@ | |||
1205 | 1124 | Blocked *blocked; | 1094 | Blocked *blocked; |
1206 | 1125 | 1095 | ||
1207 | 1126 | TEST_FUNCTION ("event_operator_events"); | 1096 | TEST_FUNCTION ("event_operator_events"); |
1211 | 1127 | root = event_operator_new (NULL, EVENT_OR, NULL, NULL); | 1097 | root = event_operator_new (NULL, EVENT_ANY, NULL, NULL); |
1212 | 1128 | oper1 = event_operator_new (root, EVENT_AND, NULL, NULL); | 1098 | oper1 = event_operator_new (root, EVENT_ALL, NULL, NULL); |
1213 | 1129 | oper2 = event_operator_new (root, EVENT_AND, NULL, NULL); | 1099 | oper2 = event_operator_new (root, EVENT_ALL, NULL, NULL); |
1214 | 1130 | oper3 = event_operator_new (root, EVENT_MATCH, "foo", NULL); | 1100 | oper3 = event_operator_new (root, EVENT_MATCH, "foo", NULL); |
1215 | 1131 | oper4 = event_operator_new (root, EVENT_MATCH, "bar", NULL); | 1101 | oper4 = event_operator_new (root, EVENT_MATCH, "bar", NULL); |
1216 | 1132 | oper5 = event_operator_new (root, EVENT_MATCH, "frodo", NULL); | 1102 | oper5 = event_operator_new (root, EVENT_MATCH, "frodo", NULL); |
1217 | 1133 | oper6 = event_operator_new (root, EVENT_MATCH, "bilbo", NULL); | 1103 | oper6 = event_operator_new (root, EVENT_MATCH, "bilbo", NULL); |
1218 | 1134 | 1104 | ||
1225 | 1135 | nih_tree_add (&root->node, &oper1->node, NIH_TREE_LEFT); | 1105 | event_operator_add_child (root, oper1); |
1226 | 1136 | nih_tree_add (&root->node, &oper2->node, NIH_TREE_RIGHT); | 1106 | event_operator_add_child (root, oper2); |
1227 | 1137 | nih_tree_add (&oper1->node, &oper3->node, NIH_TREE_LEFT); | 1107 | event_operator_add_child (oper1, oper3); |
1228 | 1138 | nih_tree_add (&oper1->node, &oper4->node, NIH_TREE_RIGHT); | 1108 | event_operator_add_child (oper1, oper4); |
1229 | 1139 | nih_tree_add (&oper2->node, &oper5->node, NIH_TREE_LEFT); | 1109 | event_operator_add_child (oper2, oper5); |
1230 | 1140 | nih_tree_add (&oper2->node, &oper6->node, NIH_TREE_RIGHT); | 1110 | event_operator_add_child (oper2, oper6); |
1231 | 1141 | 1111 | ||
1232 | 1142 | root->value = TRUE; | 1112 | root->value = TRUE; |
1233 | 1143 | 1113 | ||
1234 | @@ -1232,16 +1202,16 @@ | |||
1235 | 1232 | * all the values back to FALSE. | 1202 | * all the values back to FALSE. |
1236 | 1233 | */ | 1203 | */ |
1237 | 1234 | TEST_FUNCTION ("event_operator_reset"); | 1204 | TEST_FUNCTION ("event_operator_reset"); |
1240 | 1235 | oper1 = event_operator_new (NULL, EVENT_OR, NULL, NULL); | 1205 | oper1 = event_operator_new (NULL, EVENT_ANY, NULL, NULL); |
1241 | 1236 | oper2 = event_operator_new (NULL, EVENT_AND, NULL, NULL); | 1206 | oper2 = event_operator_new (NULL, EVENT_ALL, NULL, NULL); |
1242 | 1237 | oper3 = event_operator_new (NULL, EVENT_MATCH, "foo", NULL); | 1207 | oper3 = event_operator_new (NULL, EVENT_MATCH, "foo", NULL); |
1243 | 1238 | oper4 = event_operator_new (NULL, EVENT_MATCH, "bar", NULL); | 1208 | oper4 = event_operator_new (NULL, EVENT_MATCH, "bar", NULL); |
1244 | 1239 | oper5 = event_operator_new (NULL, EVENT_MATCH, "baz", NULL); | 1209 | oper5 = event_operator_new (NULL, EVENT_MATCH, "baz", NULL); |
1245 | 1240 | 1210 | ||
1250 | 1241 | nih_tree_add (&oper1->node, &oper2->node, NIH_TREE_LEFT); | 1211 | event_operator_add_child (oper1, oper2); |
1251 | 1242 | nih_tree_add (&oper2->node, &oper3->node, NIH_TREE_LEFT); | 1212 | event_operator_add_child (oper2, oper3); |
1252 | 1243 | nih_tree_add (&oper2->node, &oper4->node, NIH_TREE_RIGHT); | 1213 | event_operator_add_child (oper2, oper4); |
1253 | 1244 | nih_tree_add (&oper1->node, &oper5->node, NIH_TREE_RIGHT); | 1214 | event_operator_add_child (oper1, oper5); |
1254 | 1245 | 1215 | ||
1255 | 1246 | event1 = event_new (NULL, "foo", NULL); | 1216 | event1 = event_new (NULL, "foo", NULL); |
1256 | 1247 | event2 = event_new (NULL, "bar", NULL); | 1217 | event2 = event_new (NULL, "bar", NULL); |
1257 | @@ -1274,15 +1244,73 @@ | |||
1258 | 1274 | TEST_EQ (event2->blockers, 0); | 1244 | TEST_EQ (event2->blockers, 0); |
1259 | 1275 | 1245 | ||
1260 | 1276 | nih_free (oper1); | 1246 | nih_free (oper1); |
1261 | 1277 | nih_free (oper2); | ||
1262 | 1278 | nih_free (oper3); | ||
1263 | 1279 | nih_free (oper4); | ||
1264 | 1280 | nih_free (oper5); | ||
1265 | 1281 | 1247 | ||
1266 | 1282 | event_poll (); | 1248 | event_poll (); |
1267 | 1283 | } | 1249 | } |
1268 | 1284 | 1250 | ||
1269 | 1285 | 1251 | ||
1270 | 1252 | void | ||
1271 | 1253 | test_operator_add_child (void) | ||
1272 | 1254 | { | ||
1273 | 1255 | EventOperator *oper1, *oper2, *oper3, *oper4, *oper5, *oper6, *oper7; | ||
1274 | 1256 | int found_foo = 0; | ||
1275 | 1257 | int found_bar = 0; | ||
1276 | 1258 | int found_baz = 0; | ||
1277 | 1259 | int found_bam = 0; | ||
1278 | 1260 | int found_all = 0; | ||
1279 | 1261 | |||
1280 | 1262 | TEST_FUNCTION ("event_operator_add_child"); | ||
1281 | 1263 | oper1 = event_operator_new (NULL, EVENT_ANY, NULL, NULL); | ||
1282 | 1264 | oper2 = event_operator_new (NULL, EVENT_ALL, NULL, NULL); | ||
1283 | 1265 | oper3 = event_operator_new (NULL, EVENT_MATCH, "foo", NULL); | ||
1284 | 1266 | oper4 = event_operator_new (NULL, EVENT_MATCH, "bar", NULL); | ||
1285 | 1267 | oper5 = event_operator_new (NULL, EVENT_MATCH, "baz", NULL); | ||
1286 | 1268 | oper6 = event_operator_new (NULL, EVENT_MATCH, "bam", NULL); | ||
1287 | 1269 | oper7 = event_operator_new (NULL, EVENT_ANY, NULL, NULL); | ||
1288 | 1270 | |||
1289 | 1271 | event_operator_add_child (oper2, oper3); | ||
1290 | 1272 | event_operator_add_child (oper2, oper4); | ||
1291 | 1273 | event_operator_add_child (oper7, oper5); | ||
1292 | 1274 | event_operator_add_child (oper7, oper6); | ||
1293 | 1275 | event_operator_add_child (oper1, oper2); | ||
1294 | 1276 | event_operator_add_child (oper1, oper7); | ||
1295 | 1277 | |||
1296 | 1278 | TEST_EQ (oper1->type, EVENT_ANY); | ||
1297 | 1279 | |||
1298 | 1280 | NIH_LIST_FOREACH (&oper1->children, iter) { | ||
1299 | 1281 | EventOperator *child = (EventOperator *)iter; | ||
1300 | 1282 | |||
1301 | 1283 | if (child->type == EVENT_ALL) { | ||
1302 | 1284 | found_all++; | ||
1303 | 1285 | continue; | ||
1304 | 1286 | } | ||
1305 | 1287 | |||
1306 | 1288 | TEST_EQ (child->type, EVENT_MATCH); | ||
1307 | 1289 | |||
1308 | 1290 | if (! strncmp (child->name, "foo", 4)) | ||
1309 | 1291 | found_foo++; | ||
1310 | 1292 | |||
1311 | 1293 | if (! strncmp (child->name, "bar", 4)) | ||
1312 | 1294 | found_bar++; | ||
1313 | 1295 | |||
1314 | 1296 | if (! strncmp (child->name, "baz", 4)) | ||
1315 | 1297 | found_baz++; | ||
1316 | 1298 | |||
1317 | 1299 | if (! strncmp (child->name, "bam", 4)) | ||
1318 | 1300 | found_bam++; | ||
1319 | 1301 | } | ||
1320 | 1302 | |||
1321 | 1303 | // Not a truth test. 2 is also a failure. | ||
1322 | 1304 | TEST_EQ (found_all, 1); | ||
1323 | 1305 | TEST_EQ (found_foo, 0); | ||
1324 | 1306 | TEST_EQ (found_bar, 0); | ||
1325 | 1307 | TEST_EQ (found_baz, 1); | ||
1326 | 1308 | TEST_EQ (found_bam, 1); | ||
1327 | 1309 | |||
1328 | 1310 | nih_free (oper1); | ||
1329 | 1311 | } | ||
1330 | 1312 | |||
1331 | 1313 | |||
1332 | 1286 | int | 1314 | int |
1333 | 1287 | main (int argc, | 1315 | main (int argc, |
1334 | 1288 | char *argv[]) | 1316 | char *argv[]) |
1335 | @@ -1296,6 +1324,7 @@ | |||
1336 | 1296 | test_operator_environment (); | 1324 | test_operator_environment (); |
1337 | 1297 | test_operator_events (); | 1325 | test_operator_events (); |
1338 | 1298 | test_operator_reset (); | 1326 | test_operator_reset (); |
1339 | 1327 | test_operator_add_child (); | ||
1340 | 1299 | 1328 | ||
1341 | 1300 | return 0; | 1329 | return 0; |
1342 | 1301 | } | 1330 | } |
1343 | 1302 | 1331 | ||
1344 | === modified file 'init/tests/test_parse_job.c' | |||
1345 | --- init/tests/test_parse_job.c 2009-07-09 11:01:53 +0000 | |||
1346 | +++ init/tests/test_parse_job.c 2009-08-11 05:12:01 +0000 | |||
1347 | @@ -1714,11 +1714,12 @@ | |||
1348 | 1714 | void | 1714 | void |
1349 | 1715 | test_stanza_start (void) | 1715 | test_stanza_start (void) |
1350 | 1716 | { | 1716 | { |
1352 | 1717 | JobClass *job; | 1717 | JobClass *job; |
1353 | 1718 | EventOperator *oper; | 1718 | EventOperator *oper; |
1354 | 1719 | NihError *err; | 1719 | NihError *err; |
1355 | 1720 | size_t pos, lineno; | 1720 | size_t pos, lineno; |
1356 | 1721 | char buf[1024]; | 1721 | char buf[1024]; |
1357 | 1722 | int got_wibble, got_wobble, got_wiggle; | ||
1358 | 1722 | 1723 | ||
1359 | 1723 | TEST_FUNCTION ("stanza_start"); | 1724 | TEST_FUNCTION ("stanza_start"); |
1360 | 1724 | 1725 | ||
1361 | @@ -1757,9 +1758,7 @@ | |||
1362 | 1757 | TEST_EQ_STR (oper->name, "wibble"); | 1758 | TEST_EQ_STR (oper->name, "wibble"); |
1363 | 1758 | TEST_EQ_P (oper->env, NULL); | 1759 | TEST_EQ_P (oper->env, NULL); |
1364 | 1759 | 1760 | ||
1368 | 1760 | TEST_EQ_P (oper->node.parent, NULL); | 1761 | TEST_LIST_EMPTY (&oper->children); |
1366 | 1761 | TEST_EQ_P (oper->node.left, NULL); | ||
1367 | 1762 | TEST_EQ_P (oper->node.right, NULL); | ||
1369 | 1763 | 1762 | ||
1370 | 1764 | nih_free (job); | 1763 | nih_free (job); |
1371 | 1765 | } | 1764 | } |
1372 | @@ -1807,9 +1806,7 @@ | |||
1373 | 1807 | TEST_EQ_STR (oper->env[2], "b?z*"); | 1806 | TEST_EQ_STR (oper->env[2], "b?z*"); |
1374 | 1808 | TEST_EQ_P (oper->env[3], NULL); | 1807 | TEST_EQ_P (oper->env[3], NULL); |
1375 | 1809 | 1808 | ||
1379 | 1810 | TEST_EQ_P (oper->node.parent, NULL); | 1809 | TEST_LIST_EMPTY (&oper->children); |
1377 | 1811 | TEST_EQ_P (oper->node.left, NULL); | ||
1378 | 1812 | TEST_EQ_P (oper->node.right, NULL); | ||
1380 | 1813 | 1810 | ||
1381 | 1814 | nih_free (job); | 1811 | nih_free (job); |
1382 | 1815 | } | 1812 | } |
1383 | @@ -1861,9 +1858,7 @@ | |||
1384 | 1861 | TEST_EQ_STR (oper->env[4], "BILBO=foo bar"); | 1858 | TEST_EQ_STR (oper->env[4], "BILBO=foo bar"); |
1385 | 1862 | TEST_EQ_P (oper->env[5], NULL); | 1859 | TEST_EQ_P (oper->env[5], NULL); |
1386 | 1863 | 1860 | ||
1390 | 1864 | TEST_EQ_P (oper->node.parent, NULL); | 1861 | TEST_LIST_EMPTY (&oper->children); |
1388 | 1865 | TEST_EQ_P (oper->node.left, NULL); | ||
1389 | 1866 | TEST_EQ_P (oper->node.right, NULL); | ||
1391 | 1867 | 1862 | ||
1392 | 1868 | nih_free (job); | 1863 | nih_free (job); |
1393 | 1869 | } | 1864 | } |
1394 | @@ -1901,31 +1896,26 @@ | |||
1395 | 1901 | TEST_ALLOC_PARENT (job->start_on, job); | 1896 | TEST_ALLOC_PARENT (job->start_on, job); |
1396 | 1902 | 1897 | ||
1397 | 1903 | oper = job->start_on; | 1898 | oper = job->start_on; |
1423 | 1904 | TEST_EQ (oper->type, EVENT_OR); | 1899 | TEST_EQ (oper->type, EVENT_ANY); |
1424 | 1905 | 1900 | ||
1425 | 1906 | TEST_EQ_P (oper->node.parent, NULL); | 1901 | got_wibble = FALSE; |
1426 | 1907 | TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator)); | 1902 | got_wobble = FALSE; |
1427 | 1908 | TEST_ALLOC_PARENT (oper->node.left, oper); | 1903 | EventOperator *parent = oper; |
1428 | 1909 | TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator)); | 1904 | NIH_LIST_FOREACH (&oper->children, iter) { |
1429 | 1910 | TEST_ALLOC_PARENT (oper->node.right, oper); | 1905 | EventOperator *child = (EventOperator *)iter; |
1430 | 1911 | 1906 | ||
1431 | 1912 | oper = (EventOperator *)job->start_on->node.left; | 1907 | TEST_ALLOC_SIZE (child, sizeof (EventOperator)); |
1432 | 1913 | TEST_EQ (oper->type, EVENT_MATCH); | 1908 | |
1433 | 1914 | TEST_EQ_STR (oper->name, "wibble"); | 1909 | TEST_LIST_EMPTY (&child->children); |
1434 | 1915 | TEST_EQ_P (oper->env, NULL); | 1910 | TEST_EQ_P (child->env, NULL); |
1435 | 1916 | 1911 | TEST_EQ (child->type, EVENT_MATCH); | |
1436 | 1917 | TEST_EQ_P (oper->node.parent, &job->start_on->node); | 1912 | if (!strncmp ("wibble", child->name, 7) && ! got_wibble) |
1437 | 1918 | TEST_EQ_P (oper->node.left, NULL); | 1913 | got_wibble = TRUE; |
1438 | 1919 | TEST_EQ_P (oper->node.right, NULL); | 1914 | else if (!strncmp ("wobble", child->name, 7) && ! got_wobble) |
1439 | 1920 | 1915 | got_wobble = TRUE; | |
1440 | 1921 | oper = (EventOperator *)job->start_on->node.right; | 1916 | else |
1441 | 1922 | TEST_EQ (oper->type, EVENT_MATCH); | 1917 | TEST_FAILED ("Unexpected child"); |
1442 | 1923 | TEST_EQ_STR (oper->name, "wobble"); | 1918 | } |
1418 | 1924 | TEST_EQ_P (oper->env, NULL); | ||
1419 | 1925 | |||
1420 | 1926 | TEST_EQ_P (oper->node.parent, &job->start_on->node); | ||
1421 | 1927 | TEST_EQ_P (oper->node.left, NULL); | ||
1422 | 1928 | TEST_EQ_P (oper->node.right, NULL); | ||
1443 | 1929 | 1919 | ||
1444 | 1930 | nih_free (job); | 1920 | nih_free (job); |
1445 | 1931 | } | 1921 | } |
1446 | @@ -1964,39 +1954,32 @@ | |||
1447 | 1964 | TEST_ALLOC_PARENT (job->start_on, job); | 1954 | TEST_ALLOC_PARENT (job->start_on, job); |
1448 | 1965 | 1955 | ||
1449 | 1966 | oper = job->start_on; | 1956 | oper = job->start_on; |
1483 | 1967 | TEST_EQ (oper->type, EVENT_AND); | 1957 | TEST_EQ (oper->type, EVENT_ALL); |
1484 | 1968 | 1958 | ||
1485 | 1969 | TEST_EQ_P (oper->node.parent, NULL); | 1959 | got_wibble = FALSE; |
1486 | 1970 | TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator)); | 1960 | got_wobble = FALSE; |
1487 | 1971 | TEST_ALLOC_PARENT (oper->node.left, oper); | 1961 | NIH_LIST_FOREACH (&oper->children, iter) { |
1488 | 1972 | TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator)); | 1962 | EventOperator *child = (EventOperator *)iter; |
1489 | 1973 | TEST_ALLOC_PARENT (oper->node.right, oper); | 1963 | |
1490 | 1974 | 1964 | TEST_ALLOC_SIZE (child, sizeof (EventOperator)); | |
1491 | 1975 | oper = (EventOperator *)job->start_on->node.left; | 1965 | |
1492 | 1976 | TEST_EQ (oper->type, EVENT_MATCH); | 1966 | TEST_LIST_EMPTY (&child->children); |
1493 | 1977 | TEST_EQ_STR (oper->name, "wibble"); | 1967 | TEST_EQ (child->type, EVENT_MATCH); |
1494 | 1978 | 1968 | TEST_ALLOC_SIZE (child->env, sizeof (char *) * 3); | |
1495 | 1979 | TEST_ALLOC_SIZE (oper->env, sizeof (char *) * 3); | 1969 | if (!strncmp ("wibble", child->name, 7) && ! got_wibble) { |
1496 | 1980 | TEST_EQ_STR (oper->env[0], "foo"); | 1970 | got_wibble = TRUE; |
1497 | 1981 | TEST_EQ_STR (oper->env[1], "bar"); | 1971 | TEST_EQ_STR (child->env[0], "foo"); |
1498 | 1982 | TEST_EQ_P (oper->env[2], NULL); | 1972 | TEST_EQ_STR (child->env[1], "bar"); |
1499 | 1983 | 1973 | TEST_EQ_P (child->env[2], NULL); | |
1500 | 1984 | TEST_EQ_P (oper->node.parent, &job->start_on->node); | 1974 | } else if (!strncmp ("wobble", child->name, 7) && ! got_wobble) { |
1501 | 1985 | TEST_EQ_P (oper->node.left, NULL); | 1975 | got_wobble = TRUE; |
1502 | 1986 | TEST_EQ_P (oper->node.right, NULL); | 1976 | TEST_EQ_STR (child->env[0], "frodo"); |
1503 | 1987 | 1977 | TEST_EQ_STR (child->env[1], "bilbo"); | |
1504 | 1988 | oper = (EventOperator *)job->start_on->node.right; | 1978 | TEST_EQ_P (child->env[2], NULL); |
1505 | 1989 | TEST_EQ (oper->type, EVENT_MATCH); | 1979 | } else { |
1506 | 1990 | TEST_EQ_STR (oper->name, "wobble"); | 1980 | TEST_FAILED ("Unexpected child"); |
1507 | 1991 | 1981 | } | |
1508 | 1992 | TEST_ALLOC_SIZE (oper->env, sizeof (char *) * 3); | 1982 | } |
1476 | 1993 | TEST_EQ_STR (oper->env[0], "frodo"); | ||
1477 | 1994 | TEST_EQ_STR (oper->env[1], "bilbo"); | ||
1478 | 1995 | TEST_EQ_P (oper->env[2], NULL); | ||
1479 | 1996 | |||
1480 | 1997 | TEST_EQ_P (oper->node.parent, &job->start_on->node); | ||
1481 | 1998 | TEST_EQ_P (oper->node.left, NULL); | ||
1482 | 1999 | TEST_EQ_P (oper->node.right, NULL); | ||
1509 | 2000 | 1983 | ||
1510 | 2001 | nih_free (job); | 1984 | nih_free (job); |
1511 | 2002 | } | 1985 | } |
1512 | @@ -2034,48 +2017,29 @@ | |||
1513 | 2034 | TEST_ALLOC_PARENT (job->start_on, job); | 2017 | TEST_ALLOC_PARENT (job->start_on, job); |
1514 | 2035 | 2018 | ||
1515 | 2036 | oper = job->start_on; | 2019 | oper = job->start_on; |
1558 | 2037 | TEST_EQ (oper->type, EVENT_OR); | 2020 | TEST_EQ (oper->type, EVENT_ANY); |
1559 | 2038 | 2021 | ||
1560 | 2039 | TEST_EQ_P (oper->node.parent, NULL); | 2022 | got_wibble = FALSE; |
1561 | 2040 | TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator)); | 2023 | got_wobble = FALSE; |
1562 | 2041 | TEST_ALLOC_PARENT (oper->node.left, oper); | 2024 | got_wiggle = FALSE; |
1563 | 2042 | TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator)); | 2025 | NIH_LIST_FOREACH (&oper->children, iter) { |
1564 | 2043 | TEST_ALLOC_PARENT (oper->node.right, oper); | 2026 | EventOperator *child = (EventOperator *)iter; |
1565 | 2044 | 2027 | ||
1566 | 2045 | oper = (EventOperator *)job->start_on->node.left; | 2028 | TEST_ALLOC_SIZE (child, sizeof (EventOperator)); |
1567 | 2046 | TEST_EQ (oper->type, EVENT_OR); | 2029 | |
1568 | 2047 | TEST_EQ_P (oper->node.parent, &job->start_on->node); | 2030 | TEST_LIST_EMPTY (&child->children); |
1569 | 2048 | TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator)); | 2031 | TEST_EQ (child->type, EVENT_MATCH); |
1570 | 2049 | TEST_ALLOC_PARENT (oper->node.left, oper); | 2032 | TEST_EQ_P (child->env, NULL); |
1571 | 2050 | TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator)); | 2033 | if (!strncmp ("wibble", child->name, 7) && ! got_wibble) { |
1572 | 2051 | TEST_ALLOC_PARENT (oper->node.right, oper); | 2034 | got_wibble = TRUE; |
1573 | 2052 | 2035 | } else if (!strncmp ("wobble", child->name, 7) && ! got_wobble) { | |
1574 | 2053 | oper = (EventOperator *)job->start_on->node.left->left; | 2036 | got_wobble = TRUE; |
1575 | 2054 | TEST_EQ (oper->type, EVENT_MATCH); | 2037 | } else if (!strncmp ("wiggle", child->name, 7) && ! got_wiggle) { |
1576 | 2055 | TEST_EQ_STR (oper->name, "wibble"); | 2038 | got_wiggle = TRUE; |
1577 | 2056 | TEST_EQ_P (oper->env, NULL); | 2039 | } else { |
1578 | 2057 | 2040 | TEST_FAILED ("Unexpected child"); | |
1579 | 2058 | TEST_EQ_P (oper->node.parent, job->start_on->node.left); | 2041 | } |
1580 | 2059 | TEST_EQ_P (oper->node.left, NULL); | 2042 | } |
1539 | 2060 | TEST_EQ_P (oper->node.right, NULL); | ||
1540 | 2061 | |||
1541 | 2062 | oper = (EventOperator *)job->start_on->node.left->right; | ||
1542 | 2063 | TEST_EQ (oper->type, EVENT_MATCH); | ||
1543 | 2064 | TEST_EQ_STR (oper->name, "wobble"); | ||
1544 | 2065 | TEST_EQ_P (oper->env, NULL); | ||
1545 | 2066 | |||
1546 | 2067 | TEST_EQ_P (oper->node.parent, job->start_on->node.left); | ||
1547 | 2068 | TEST_EQ_P (oper->node.left, NULL); | ||
1548 | 2069 | TEST_EQ_P (oper->node.right, NULL); | ||
1549 | 2070 | |||
1550 | 2071 | oper = (EventOperator *)job->start_on->node.right; | ||
1551 | 2072 | TEST_EQ (oper->type, EVENT_MATCH); | ||
1552 | 2073 | TEST_EQ_STR (oper->name, "wiggle"); | ||
1553 | 2074 | TEST_EQ_P (oper->env, NULL); | ||
1554 | 2075 | |||
1555 | 2076 | TEST_EQ_P (oper->node.parent, &job->start_on->node); | ||
1556 | 2077 | TEST_EQ_P (oper->node.left, NULL); | ||
1557 | 2078 | TEST_EQ_P (oper->node.right, NULL); | ||
1581 | 2079 | 2043 | ||
1582 | 2080 | nih_free (job); | 2044 | nih_free (job); |
1583 | 2081 | } | 2045 | } |
1584 | @@ -2112,49 +2076,29 @@ | |||
1585 | 2112 | TEST_ALLOC_PARENT (job->start_on, job); | 2076 | TEST_ALLOC_PARENT (job->start_on, job); |
1586 | 2113 | 2077 | ||
1587 | 2114 | oper = job->start_on; | 2078 | oper = job->start_on; |
1631 | 2115 | TEST_EQ (oper->type, EVENT_OR); | 2079 | TEST_EQ (oper->type, EVENT_ANY); |
1632 | 2116 | 2080 | ||
1633 | 2117 | TEST_EQ_P (oper->node.parent, NULL); | 2081 | got_wibble = FALSE; |
1634 | 2118 | TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator)); | 2082 | got_wobble = FALSE; |
1635 | 2119 | TEST_ALLOC_PARENT (oper->node.left, oper); | 2083 | got_wiggle = FALSE; |
1636 | 2120 | TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator)); | 2084 | NIH_LIST_FOREACH (&oper->children, iter) { |
1637 | 2121 | TEST_ALLOC_PARENT (oper->node.right, oper); | 2085 | EventOperator *child = (EventOperator *)iter; |
1638 | 2122 | 2086 | ||
1639 | 2123 | oper = (EventOperator *)job->start_on->node.left; | 2087 | TEST_ALLOC_SIZE (child, sizeof (EventOperator)); |
1640 | 2124 | TEST_EQ (oper->type, EVENT_MATCH); | 2088 | |
1641 | 2125 | TEST_EQ_STR (oper->name, "wibble"); | 2089 | TEST_LIST_EMPTY (&child->children); |
1642 | 2126 | TEST_EQ_P (oper->env, NULL); | 2090 | TEST_EQ (child->type, EVENT_MATCH); |
1643 | 2127 | 2091 | TEST_EQ_P (child->env, NULL); | |
1644 | 2128 | TEST_EQ_P (oper->node.parent, &job->start_on->node); | 2092 | if (!strncmp ("wibble", child->name, 7) && ! got_wibble) { |
1645 | 2129 | TEST_EQ_P (oper->node.left, NULL); | 2093 | got_wibble = TRUE; |
1646 | 2130 | TEST_EQ_P (oper->node.right, NULL); | 2094 | } else if (!strncmp ("wobble", child->name, 7) && ! got_wobble) { |
1647 | 2131 | 2095 | got_wobble = TRUE; | |
1648 | 2132 | oper = (EventOperator *)job->start_on->node.right; | 2096 | } else if (!strncmp ("wiggle", child->name, 7) && ! got_wiggle) { |
1649 | 2133 | TEST_EQ (oper->type, EVENT_OR); | 2097 | got_wiggle = TRUE; |
1650 | 2134 | 2098 | } else { | |
1651 | 2135 | TEST_EQ_P (oper->node.parent, &job->start_on->node); | 2099 | TEST_FAILED ("Unexpected child"); |
1652 | 2136 | TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator)); | 2100 | } |
1653 | 2137 | TEST_ALLOC_PARENT (oper->node.left, oper); | 2101 | } |
1611 | 2138 | TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator)); | ||
1612 | 2139 | TEST_ALLOC_PARENT (oper->node.right, oper); | ||
1613 | 2140 | |||
1614 | 2141 | oper = (EventOperator *)job->start_on->node.right->left; | ||
1615 | 2142 | TEST_EQ (oper->type, EVENT_MATCH); | ||
1616 | 2143 | TEST_EQ_STR (oper->name, "wobble"); | ||
1617 | 2144 | TEST_EQ_P (oper->env, NULL); | ||
1618 | 2145 | |||
1619 | 2146 | TEST_EQ_P (oper->node.parent, job->start_on->node.right); | ||
1620 | 2147 | TEST_EQ_P (oper->node.left, NULL); | ||
1621 | 2148 | TEST_EQ_P (oper->node.right, NULL); | ||
1622 | 2149 | |||
1623 | 2150 | oper = (EventOperator *)job->start_on->node.right->right; | ||
1624 | 2151 | TEST_EQ (oper->type, EVENT_MATCH); | ||
1625 | 2152 | TEST_EQ_STR (oper->name, "wiggle"); | ||
1626 | 2153 | TEST_EQ_P (oper->env, NULL); | ||
1627 | 2154 | |||
1628 | 2155 | TEST_EQ_P (oper->node.parent, job->start_on->node.right); | ||
1629 | 2156 | TEST_EQ_P (oper->node.left, NULL); | ||
1630 | 2157 | TEST_EQ_P (oper->node.right, NULL); | ||
1654 | 2158 | 2102 | ||
1655 | 2159 | nih_free (job); | 2103 | nih_free (job); |
1656 | 2160 | } | 2104 | } |
1657 | @@ -2192,49 +2136,29 @@ | |||
1658 | 2192 | TEST_ALLOC_PARENT (job->start_on, job); | 2136 | TEST_ALLOC_PARENT (job->start_on, job); |
1659 | 2193 | 2137 | ||
1660 | 2194 | oper = job->start_on; | 2138 | oper = job->start_on; |
1704 | 2195 | TEST_EQ (oper->type, EVENT_OR); | 2139 | TEST_EQ (oper->type, EVENT_ANY); |
1705 | 2196 | 2140 | ||
1706 | 2197 | TEST_EQ_P (oper->node.parent, NULL); | 2141 | got_wibble = FALSE; |
1707 | 2198 | TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator)); | 2142 | got_wobble = FALSE; |
1708 | 2199 | TEST_ALLOC_PARENT (oper->node.left, oper); | 2143 | got_wiggle = FALSE; |
1709 | 2200 | TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator)); | 2144 | NIH_LIST_FOREACH (&oper->children, iter) { |
1710 | 2201 | TEST_ALLOC_PARENT (oper->node.right, oper); | 2145 | EventOperator *child = (EventOperator *)iter; |
1711 | 2202 | 2146 | ||
1712 | 2203 | oper = (EventOperator *)job->start_on->node.left; | 2147 | TEST_ALLOC_SIZE (child, sizeof (EventOperator)); |
1713 | 2204 | TEST_EQ (oper->type, EVENT_MATCH); | 2148 | |
1714 | 2205 | TEST_EQ_STR (oper->name, "wibble"); | 2149 | TEST_LIST_EMPTY (&child->children); |
1715 | 2206 | TEST_EQ_P (oper->env, NULL); | 2150 | TEST_EQ (child->type, EVENT_MATCH); |
1716 | 2207 | 2151 | TEST_EQ_P (child->env, NULL); | |
1717 | 2208 | TEST_EQ_P (oper->node.parent, &job->start_on->node); | 2152 | if (!strncmp ("wibble", child->name, 7) && ! got_wibble) { |
1718 | 2209 | TEST_EQ_P (oper->node.left, NULL); | 2153 | got_wibble = TRUE; |
1719 | 2210 | TEST_EQ_P (oper->node.right, NULL); | 2154 | } else if (!strncmp ("wobble", child->name, 7) && ! got_wobble) { |
1720 | 2211 | 2155 | got_wobble = TRUE; | |
1721 | 2212 | oper = (EventOperator *)job->start_on->node.right; | 2156 | } else if (!strncmp ("wiggle", child->name, 7) && ! got_wiggle) { |
1722 | 2213 | TEST_EQ (oper->type, EVENT_OR); | 2157 | got_wiggle = TRUE; |
1723 | 2214 | 2158 | } else { | |
1724 | 2215 | TEST_EQ_P (oper->node.parent, &job->start_on->node); | 2159 | TEST_FAILED ("Unexpected child"); |
1725 | 2216 | TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator)); | 2160 | } |
1726 | 2217 | TEST_ALLOC_PARENT (oper->node.left, oper); | 2161 | } |
1684 | 2218 | TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator)); | ||
1685 | 2219 | TEST_ALLOC_PARENT (oper->node.right, oper); | ||
1686 | 2220 | |||
1687 | 2221 | oper = (EventOperator *)job->start_on->node.right->left; | ||
1688 | 2222 | TEST_EQ (oper->type, EVENT_MATCH); | ||
1689 | 2223 | TEST_EQ_STR (oper->name, "wobble"); | ||
1690 | 2224 | TEST_EQ_P (oper->env, NULL); | ||
1691 | 2225 | |||
1692 | 2226 | TEST_EQ_P (oper->node.parent, job->start_on->node.right); | ||
1693 | 2227 | TEST_EQ_P (oper->node.left, NULL); | ||
1694 | 2228 | TEST_EQ_P (oper->node.right, NULL); | ||
1695 | 2229 | |||
1696 | 2230 | oper = (EventOperator *)job->start_on->node.right->right; | ||
1697 | 2231 | TEST_EQ (oper->type, EVENT_MATCH); | ||
1698 | 2232 | TEST_EQ_STR (oper->name, "wiggle"); | ||
1699 | 2233 | TEST_EQ_P (oper->env, NULL); | ||
1700 | 2234 | |||
1701 | 2235 | TEST_EQ_P (oper->node.parent, job->start_on->node.right); | ||
1702 | 2236 | TEST_EQ_P (oper->node.left, NULL); | ||
1703 | 2237 | TEST_EQ_P (oper->node.right, NULL); | ||
1727 | 2238 | 2162 | ||
1728 | 2239 | nih_free (job); | 2163 | nih_free (job); |
1729 | 2240 | } | 2164 | } |
1730 | @@ -2275,9 +2199,7 @@ | |||
1731 | 2275 | TEST_EQ_STR (oper->name, "waggle"); | 2199 | TEST_EQ_STR (oper->name, "waggle"); |
1732 | 2276 | TEST_EQ_P (oper->env, NULL); | 2200 | TEST_EQ_P (oper->env, NULL); |
1733 | 2277 | 2201 | ||
1737 | 2278 | TEST_EQ_P (oper->node.parent, NULL); | 2202 | TEST_LIST_EMPTY (&oper->children); |
1735 | 2279 | TEST_EQ_P (oper->node.left, NULL); | ||
1736 | 2280 | TEST_EQ_P (oper->node.right, NULL); | ||
1738 | 2281 | 2203 | ||
1739 | 2282 | nih_free (job); | 2204 | nih_free (job); |
1740 | 2283 | } | 2205 | } |
1741 | @@ -2536,6 +2458,7 @@ | |||
1742 | 2536 | NihError *err; | 2458 | NihError *err; |
1743 | 2537 | size_t pos, lineno; | 2459 | size_t pos, lineno; |
1744 | 2538 | char buf[1024]; | 2460 | char buf[1024]; |
1745 | 2461 | int got_wibble, got_wobble, got_wiggle; | ||
1746 | 2539 | 2462 | ||
1747 | 2540 | TEST_FUNCTION ("stanza_stop"); | 2463 | TEST_FUNCTION ("stanza_stop"); |
1748 | 2541 | 2464 | ||
1749 | @@ -2574,9 +2497,7 @@ | |||
1750 | 2574 | TEST_EQ_STR (oper->name, "wibble"); | 2497 | TEST_EQ_STR (oper->name, "wibble"); |
1751 | 2575 | TEST_EQ_P (oper->env, NULL); | 2498 | TEST_EQ_P (oper->env, NULL); |
1752 | 2576 | 2499 | ||
1756 | 2577 | TEST_EQ_P (oper->node.parent, NULL); | 2500 | TEST_LIST_EMPTY (&oper->children); |
1754 | 2578 | TEST_EQ_P (oper->node.left, NULL); | ||
1755 | 2579 | TEST_EQ_P (oper->node.right, NULL); | ||
1757 | 2580 | 2501 | ||
1758 | 2581 | nih_free (job); | 2502 | nih_free (job); |
1759 | 2582 | } | 2503 | } |
1760 | @@ -2624,9 +2545,7 @@ | |||
1761 | 2624 | TEST_EQ_STR (oper->env[2], "b?z*"); | 2545 | TEST_EQ_STR (oper->env[2], "b?z*"); |
1762 | 2625 | TEST_EQ_P (oper->env[3], NULL); | 2546 | TEST_EQ_P (oper->env[3], NULL); |
1763 | 2626 | 2547 | ||
1767 | 2627 | TEST_EQ_P (oper->node.parent, NULL); | 2548 | TEST_LIST_EMPTY (&oper->children); |
1765 | 2628 | TEST_EQ_P (oper->node.left, NULL); | ||
1766 | 2629 | TEST_EQ_P (oper->node.right, NULL); | ||
1768 | 2630 | 2549 | ||
1769 | 2631 | nih_free (job); | 2550 | nih_free (job); |
1770 | 2632 | } | 2551 | } |
1771 | @@ -2678,9 +2597,7 @@ | |||
1772 | 2678 | TEST_EQ_STR (oper->env[4], "BILBO=foo bar"); | 2597 | TEST_EQ_STR (oper->env[4], "BILBO=foo bar"); |
1773 | 2679 | TEST_EQ_P (oper->env[5], NULL); | 2598 | TEST_EQ_P (oper->env[5], NULL); |
1774 | 2680 | 2599 | ||
1778 | 2681 | TEST_EQ_P (oper->node.parent, NULL); | 2600 | TEST_LIST_EMPTY (&oper->children); |
1776 | 2682 | TEST_EQ_P (oper->node.left, NULL); | ||
1777 | 2683 | TEST_EQ_P (oper->node.right, NULL); | ||
1779 | 2684 | 2601 | ||
1780 | 2685 | nih_free (job); | 2602 | nih_free (job); |
1781 | 2686 | } | 2603 | } |
1782 | @@ -2718,31 +2635,26 @@ | |||
1783 | 2718 | TEST_ALLOC_PARENT (job->stop_on, job); | 2635 | TEST_ALLOC_PARENT (job->stop_on, job); |
1784 | 2719 | 2636 | ||
1785 | 2720 | oper = job->stop_on; | 2637 | oper = job->stop_on; |
1811 | 2721 | TEST_EQ (oper->type, EVENT_OR); | 2638 | TEST_EQ (oper->type, EVENT_ANY); |
1812 | 2722 | 2639 | ||
1813 | 2723 | TEST_EQ_P (oper->node.parent, NULL); | 2640 | got_wibble = FALSE; |
1814 | 2724 | TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator)); | 2641 | got_wobble = FALSE; |
1815 | 2725 | TEST_ALLOC_PARENT (oper->node.left, oper); | 2642 | NIH_LIST_FOREACH (&oper->children, iter) { |
1816 | 2726 | TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator)); | 2643 | EventOperator *child = (EventOperator *)iter; |
1817 | 2727 | TEST_ALLOC_PARENT (oper->node.right, oper); | 2644 | |
1818 | 2728 | 2645 | TEST_ALLOC_SIZE (child, sizeof (EventOperator)); | |
1819 | 2729 | oper = (EventOperator *)job->stop_on->node.left; | 2646 | |
1820 | 2730 | TEST_EQ (oper->type, EVENT_MATCH); | 2647 | TEST_LIST_EMPTY (&child->children); |
1821 | 2731 | TEST_EQ_STR (oper->name, "wibble"); | 2648 | TEST_EQ (child->type, EVENT_MATCH); |
1822 | 2732 | TEST_EQ_P (oper->env, NULL); | 2649 | TEST_EQ_P (child->env, NULL); |
1823 | 2733 | 2650 | if (!strncmp ("wibble", child->name, 7) && ! got_wibble) { | |
1824 | 2734 | TEST_EQ_P (oper->node.parent, &job->stop_on->node); | 2651 | got_wibble = TRUE; |
1825 | 2735 | TEST_EQ_P (oper->node.left, NULL); | 2652 | } else if (!strncmp ("wobble", child->name, 7) && ! got_wobble) { |
1826 | 2736 | TEST_EQ_P (oper->node.right, NULL); | 2653 | got_wobble = TRUE; |
1827 | 2737 | 2654 | } else { | |
1828 | 2738 | oper = (EventOperator *)job->stop_on->node.right; | 2655 | TEST_FAILED ("Unexpected child"); |
1829 | 2739 | TEST_EQ (oper->type, EVENT_MATCH); | 2656 | } |
1830 | 2740 | TEST_EQ_STR (oper->name, "wobble"); | 2657 | } |
1806 | 2741 | TEST_EQ_P (oper->env, NULL); | ||
1807 | 2742 | |||
1808 | 2743 | TEST_EQ_P (oper->node.parent, &job->stop_on->node); | ||
1809 | 2744 | TEST_EQ_P (oper->node.left, NULL); | ||
1810 | 2745 | TEST_EQ_P (oper->node.right, NULL); | ||
1831 | 2746 | 2658 | ||
1832 | 2747 | nih_free (job); | 2659 | nih_free (job); |
1833 | 2748 | } | 2660 | } |
1834 | @@ -2781,39 +2693,32 @@ | |||
1835 | 2781 | TEST_ALLOC_PARENT (job->stop_on, job); | 2693 | TEST_ALLOC_PARENT (job->stop_on, job); |
1836 | 2782 | 2694 | ||
1837 | 2783 | oper = job->stop_on; | 2695 | oper = job->stop_on; |
1871 | 2784 | TEST_EQ (oper->type, EVENT_AND); | 2696 | TEST_EQ (oper->type, EVENT_ALL); |
1872 | 2785 | 2697 | ||
1873 | 2786 | TEST_EQ_P (oper->node.parent, NULL); | 2698 | got_wibble = FALSE; |
1874 | 2787 | TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator)); | 2699 | got_wobble = FALSE; |
1875 | 2788 | TEST_ALLOC_PARENT (oper->node.left, oper); | 2700 | NIH_LIST_FOREACH (&oper->children, iter) { |
1876 | 2789 | TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator)); | 2701 | EventOperator *child = (EventOperator *)iter; |
1877 | 2790 | TEST_ALLOC_PARENT (oper->node.right, oper); | 2702 | |
1878 | 2791 | 2703 | TEST_ALLOC_SIZE (child, sizeof (EventOperator)); | |
1879 | 2792 | oper = (EventOperator *)job->stop_on->node.left; | 2704 | |
1880 | 2793 | TEST_EQ (oper->type, EVENT_MATCH); | 2705 | TEST_LIST_EMPTY (&child->children); |
1881 | 2794 | TEST_EQ_STR (oper->name, "wibble"); | 2706 | TEST_EQ (child->type, EVENT_MATCH); |
1882 | 2795 | 2707 | TEST_ALLOC_SIZE (child->env, sizeof (char *) * 3); | |
1883 | 2796 | TEST_ALLOC_SIZE (oper->env, sizeof (char *) * 3); | 2708 | if (!strncmp ("wibble", child->name, 7) && ! got_wibble) { |
1884 | 2797 | TEST_EQ_STR (oper->env[0], "foo"); | 2709 | got_wibble = TRUE; |
1885 | 2798 | TEST_EQ_STR (oper->env[1], "bar"); | 2710 | TEST_EQ_STR (child->env[0], "foo"); |
1886 | 2799 | TEST_EQ_P (oper->env[2], NULL); | 2711 | TEST_EQ_STR (child->env[1], "bar"); |
1887 | 2800 | 2712 | TEST_EQ_P (child->env[2], NULL); | |
1888 | 2801 | TEST_EQ_P (oper->node.parent, &job->stop_on->node); | 2713 | } else if (!strncmp ("wobble", child->name, 7) && ! got_wobble) { |
1889 | 2802 | TEST_EQ_P (oper->node.left, NULL); | 2714 | got_wobble = TRUE; |
1890 | 2803 | TEST_EQ_P (oper->node.right, NULL); | 2715 | TEST_EQ_STR (child->env[0], "frodo"); |
1891 | 2804 | 2716 | TEST_EQ_STR (child->env[1], "bilbo"); | |
1892 | 2805 | oper = (EventOperator *)job->stop_on->node.right; | 2717 | TEST_EQ_P (child->env[2], NULL); |
1893 | 2806 | TEST_EQ (oper->type, EVENT_MATCH); | 2718 | } else { |
1894 | 2807 | TEST_EQ_STR (oper->name, "wobble"); | 2719 | TEST_FAILED ("Unexpected child"); |
1895 | 2808 | 2720 | } | |
1896 | 2809 | TEST_ALLOC_SIZE (oper->env, sizeof (char *) * 3); | 2721 | } |
1864 | 2810 | TEST_EQ_STR (oper->env[0], "frodo"); | ||
1865 | 2811 | TEST_EQ_STR (oper->env[1], "bilbo"); | ||
1866 | 2812 | TEST_EQ_P (oper->env[2], NULL); | ||
1867 | 2813 | |||
1868 | 2814 | TEST_EQ_P (oper->node.parent, &job->stop_on->node); | ||
1869 | 2815 | TEST_EQ_P (oper->node.left, NULL); | ||
1870 | 2816 | TEST_EQ_P (oper->node.right, NULL); | ||
1897 | 2817 | 2722 | ||
1898 | 2818 | nih_free (job); | 2723 | nih_free (job); |
1899 | 2819 | } | 2724 | } |
1900 | @@ -2851,48 +2756,29 @@ | |||
1901 | 2851 | TEST_ALLOC_PARENT (job->stop_on, job); | 2756 | TEST_ALLOC_PARENT (job->stop_on, job); |
1902 | 2852 | 2757 | ||
1903 | 2853 | oper = job->stop_on; | 2758 | oper = job->stop_on; |
1946 | 2854 | TEST_EQ (oper->type, EVENT_OR); | 2759 | TEST_EQ (oper->type, EVENT_ANY); |
1947 | 2855 | 2760 | ||
1948 | 2856 | TEST_EQ_P (oper->node.parent, NULL); | 2761 | got_wibble = FALSE; |
1949 | 2857 | TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator)); | 2762 | got_wobble = FALSE; |
1950 | 2858 | TEST_ALLOC_PARENT (oper->node.left, oper); | 2763 | got_wiggle = FALSE; |
1951 | 2859 | TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator)); | 2764 | NIH_LIST_FOREACH (&oper->children, iter) { |
1952 | 2860 | TEST_ALLOC_PARENT (oper->node.right, oper); | 2765 | EventOperator *child = (EventOperator *)iter; |
1953 | 2861 | 2766 | ||
1954 | 2862 | oper = (EventOperator *)job->stop_on->node.left; | 2767 | TEST_ALLOC_SIZE (child, sizeof (EventOperator)); |
1955 | 2863 | TEST_EQ (oper->type, EVENT_OR); | 2768 | |
1956 | 2864 | TEST_EQ_P (oper->node.parent, &job->stop_on->node); | 2769 | TEST_LIST_EMPTY (&child->children); |
1957 | 2865 | TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator)); | 2770 | TEST_EQ (child->type, EVENT_MATCH); |
1958 | 2866 | TEST_ALLOC_PARENT (oper->node.left, oper); | 2771 | TEST_EQ_P (child->env, NULL); |
1959 | 2867 | TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator)); | 2772 | if (!strncmp ("wibble", child->name, 7) && ! got_wibble) { |
1960 | 2868 | TEST_ALLOC_PARENT (oper->node.right, oper); | 2773 | got_wibble = TRUE; |
1961 | 2869 | 2774 | } else if (!strncmp ("wobble", child->name, 7) && ! got_wobble) { | |
1962 | 2870 | oper = (EventOperator *)job->stop_on->node.left->left; | 2775 | got_wobble = TRUE; |
1963 | 2871 | TEST_EQ (oper->type, EVENT_MATCH); | 2776 | } else if (!strncmp ("wiggle", child->name, 7) && ! got_wiggle) { |
1964 | 2872 | TEST_EQ_STR (oper->name, "wibble"); | 2777 | got_wiggle = TRUE; |
1965 | 2873 | TEST_EQ_P (oper->env, NULL); | 2778 | } else { |
1966 | 2874 | 2779 | TEST_FAILED ("Unexpected child"); | |
1967 | 2875 | TEST_EQ_P (oper->node.parent, job->stop_on->node.left); | 2780 | } |
1968 | 2876 | TEST_EQ_P (oper->node.left, NULL); | 2781 | } |
1927 | 2877 | TEST_EQ_P (oper->node.right, NULL); | ||
1928 | 2878 | |||
1929 | 2879 | oper = (EventOperator *)job->stop_on->node.left->right; | ||
1930 | 2880 | TEST_EQ (oper->type, EVENT_MATCH); | ||
1931 | 2881 | TEST_EQ_STR (oper->name, "wobble"); | ||
1932 | 2882 | TEST_EQ_P (oper->env, NULL); | ||
1933 | 2883 | |||
1934 | 2884 | TEST_EQ_P (oper->node.parent, job->stop_on->node.left); | ||
1935 | 2885 | TEST_EQ_P (oper->node.left, NULL); | ||
1936 | 2886 | TEST_EQ_P (oper->node.right, NULL); | ||
1937 | 2887 | |||
1938 | 2888 | oper = (EventOperator *)job->stop_on->node.right; | ||
1939 | 2889 | TEST_EQ (oper->type, EVENT_MATCH); | ||
1940 | 2890 | TEST_EQ_STR (oper->name, "wiggle"); | ||
1941 | 2891 | TEST_EQ_P (oper->env, NULL); | ||
1942 | 2892 | |||
1943 | 2893 | TEST_EQ_P (oper->node.parent, &job->stop_on->node); | ||
1944 | 2894 | TEST_EQ_P (oper->node.left, NULL); | ||
1945 | 2895 | TEST_EQ_P (oper->node.right, NULL); | ||
1969 | 2896 | 2782 | ||
1970 | 2897 | nih_free (job); | 2783 | nih_free (job); |
1971 | 2898 | } | 2784 | } |
1972 | @@ -2929,49 +2815,29 @@ | |||
1973 | 2929 | TEST_ALLOC_PARENT (job->stop_on, job); | 2815 | TEST_ALLOC_PARENT (job->stop_on, job); |
1974 | 2930 | 2816 | ||
1975 | 2931 | oper = job->stop_on; | 2817 | oper = job->stop_on; |
2019 | 2932 | TEST_EQ (oper->type, EVENT_OR); | 2818 | TEST_EQ (oper->type, EVENT_ANY); |
2020 | 2933 | 2819 | ||
2021 | 2934 | TEST_EQ_P (oper->node.parent, NULL); | 2820 | got_wibble = FALSE; |
2022 | 2935 | TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator)); | 2821 | got_wobble = FALSE; |
2023 | 2936 | TEST_ALLOC_PARENT (oper->node.left, oper); | 2822 | got_wiggle = FALSE; |
2024 | 2937 | TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator)); | 2823 | NIH_LIST_FOREACH (&oper->children, iter) { |
2025 | 2938 | TEST_ALLOC_PARENT (oper->node.right, oper); | 2824 | EventOperator *child = (EventOperator *)iter; |
2026 | 2939 | 2825 | ||
2027 | 2940 | oper = (EventOperator *)job->stop_on->node.left; | 2826 | TEST_ALLOC_SIZE (child, sizeof (EventOperator)); |
2028 | 2941 | TEST_EQ (oper->type, EVENT_MATCH); | 2827 | |
2029 | 2942 | TEST_EQ_STR (oper->name, "wibble"); | 2828 | TEST_LIST_EMPTY (&child->children); |
2030 | 2943 | TEST_EQ_P (oper->env, NULL); | 2829 | TEST_EQ (child->type, EVENT_MATCH); |
2031 | 2944 | 2830 | TEST_EQ_P (child->env, NULL); | |
2032 | 2945 | TEST_EQ_P (oper->node.parent, &job->stop_on->node); | 2831 | if (!strncmp ("wibble", child->name, 7) && ! got_wibble) { |
2033 | 2946 | TEST_EQ_P (oper->node.left, NULL); | 2832 | got_wibble = TRUE; |
2034 | 2947 | TEST_EQ_P (oper->node.right, NULL); | 2833 | } else if (!strncmp ("wobble", child->name, 7) && ! got_wobble) { |
2035 | 2948 | 2834 | got_wobble = TRUE; | |
2036 | 2949 | oper = (EventOperator *)job->stop_on->node.right; | 2835 | } else if (!strncmp ("wiggle", child->name, 7) && ! got_wiggle) { |
2037 | 2950 | TEST_EQ (oper->type, EVENT_OR); | 2836 | got_wiggle = TRUE; |
2038 | 2951 | 2837 | } else { | |
2039 | 2952 | TEST_EQ_P (oper->node.parent, &job->stop_on->node); | 2838 | TEST_FAILED ("Unexpected child"); |
2040 | 2953 | TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator)); | 2839 | } |
2041 | 2954 | TEST_ALLOC_PARENT (oper->node.left, oper); | 2840 | } |
1999 | 2955 | TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator)); | ||
2000 | 2956 | TEST_ALLOC_PARENT (oper->node.right, oper); | ||
2001 | 2957 | |||
2002 | 2958 | oper = (EventOperator *)job->stop_on->node.right->left; | ||
2003 | 2959 | TEST_EQ (oper->type, EVENT_MATCH); | ||
2004 | 2960 | TEST_EQ_STR (oper->name, "wobble"); | ||
2005 | 2961 | TEST_EQ_P (oper->env, NULL); | ||
2006 | 2962 | |||
2007 | 2963 | TEST_EQ_P (oper->node.parent, job->stop_on->node.right); | ||
2008 | 2964 | TEST_EQ_P (oper->node.left, NULL); | ||
2009 | 2965 | TEST_EQ_P (oper->node.right, NULL); | ||
2010 | 2966 | |||
2011 | 2967 | oper = (EventOperator *)job->stop_on->node.right->right; | ||
2012 | 2968 | TEST_EQ (oper->type, EVENT_MATCH); | ||
2013 | 2969 | TEST_EQ_STR (oper->name, "wiggle"); | ||
2014 | 2970 | TEST_EQ_P (oper->env, NULL); | ||
2015 | 2971 | |||
2016 | 2972 | TEST_EQ_P (oper->node.parent, job->stop_on->node.right); | ||
2017 | 2973 | TEST_EQ_P (oper->node.left, NULL); | ||
2018 | 2974 | TEST_EQ_P (oper->node.right, NULL); | ||
2042 | 2975 | 2841 | ||
2043 | 2976 | nih_free (job); | 2842 | nih_free (job); |
2044 | 2977 | } | 2843 | } |
2045 | @@ -3009,49 +2875,29 @@ | |||
2046 | 3009 | TEST_ALLOC_PARENT (job->stop_on, job); | 2875 | TEST_ALLOC_PARENT (job->stop_on, job); |
2047 | 3010 | 2876 | ||
2048 | 3011 | oper = job->stop_on; | 2877 | oper = job->stop_on; |
2092 | 3012 | TEST_EQ (oper->type, EVENT_OR); | 2878 | TEST_EQ (oper->type, EVENT_ANY); |
2093 | 3013 | 2879 | ||
2094 | 3014 | TEST_EQ_P (oper->node.parent, NULL); | 2880 | got_wibble = FALSE; |
2095 | 3015 | TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator)); | 2881 | got_wobble = FALSE; |
2096 | 3016 | TEST_ALLOC_PARENT (oper->node.left, oper); | 2882 | got_wiggle = FALSE; |
2097 | 3017 | TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator)); | 2883 | NIH_LIST_FOREACH (&oper->children, iter) { |
2098 | 3018 | TEST_ALLOC_PARENT (oper->node.right, oper); | 2884 | EventOperator *child = (EventOperator *)iter; |
2099 | 3019 | 2885 | ||
2100 | 3020 | oper = (EventOperator *)job->stop_on->node.left; | 2886 | TEST_ALLOC_SIZE (child, sizeof (EventOperator)); |
2101 | 3021 | TEST_EQ (oper->type, EVENT_MATCH); | 2887 | |
2102 | 3022 | TEST_EQ_STR (oper->name, "wibble"); | 2888 | TEST_LIST_EMPTY (&child->children); |
2103 | 3023 | TEST_EQ_P (oper->env, NULL); | 2889 | TEST_EQ (child->type, EVENT_MATCH); |
2104 | 3024 | 2890 | TEST_EQ_P (child->env, NULL); | |
2105 | 3025 | TEST_EQ_P (oper->node.parent, &job->stop_on->node); | 2891 | if (!strncmp ("wibble", child->name, 7) && ! got_wibble) { |
2106 | 3026 | TEST_EQ_P (oper->node.left, NULL); | 2892 | got_wibble = TRUE; |
2107 | 3027 | TEST_EQ_P (oper->node.right, NULL); | 2893 | } else if (!strncmp ("wobble", child->name, 7) && ! got_wobble) { |
2108 | 3028 | 2894 | got_wobble = TRUE; | |
2109 | 3029 | oper = (EventOperator *)job->stop_on->node.right; | 2895 | } else if (!strncmp ("wiggle", child->name, 7) && ! got_wiggle) { |
2110 | 3030 | TEST_EQ (oper->type, EVENT_OR); | 2896 | got_wiggle = TRUE; |
2111 | 3031 | 2897 | } else { | |
2112 | 3032 | TEST_EQ_P (oper->node.parent, &job->stop_on->node); | 2898 | TEST_FAILED ("Unexpected child"); |
2113 | 3033 | TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator)); | 2899 | } |
2114 | 3034 | TEST_ALLOC_PARENT (oper->node.left, oper); | 2900 | } |
2072 | 3035 | TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator)); | ||
2073 | 3036 | TEST_ALLOC_PARENT (oper->node.right, oper); | ||
2074 | 3037 | |||
2075 | 3038 | oper = (EventOperator *)job->stop_on->node.right->left; | ||
2076 | 3039 | TEST_EQ (oper->type, EVENT_MATCH); | ||
2077 | 3040 | TEST_EQ_STR (oper->name, "wobble"); | ||
2078 | 3041 | TEST_EQ_P (oper->env, NULL); | ||
2079 | 3042 | |||
2080 | 3043 | TEST_EQ_P (oper->node.parent, job->stop_on->node.right); | ||
2081 | 3044 | TEST_EQ_P (oper->node.left, NULL); | ||
2082 | 3045 | TEST_EQ_P (oper->node.right, NULL); | ||
2083 | 3046 | |||
2084 | 3047 | oper = (EventOperator *)job->stop_on->node.right->right; | ||
2085 | 3048 | TEST_EQ (oper->type, EVENT_MATCH); | ||
2086 | 3049 | TEST_EQ_STR (oper->name, "wiggle"); | ||
2087 | 3050 | TEST_EQ_P (oper->env, NULL); | ||
2088 | 3051 | |||
2089 | 3052 | TEST_EQ_P (oper->node.parent, job->stop_on->node.right); | ||
2090 | 3053 | TEST_EQ_P (oper->node.left, NULL); | ||
2091 | 3054 | TEST_EQ_P (oper->node.right, NULL); | ||
2115 | 3055 | 2901 | ||
2116 | 3056 | nih_free (job); | 2902 | nih_free (job); |
2117 | 3057 | } | 2903 | } |
2118 | @@ -3092,9 +2938,7 @@ | |||
2119 | 3092 | TEST_EQ_STR (oper->name, "waggle"); | 2938 | TEST_EQ_STR (oper->name, "waggle"); |
2120 | 3093 | TEST_EQ_P (oper->env, NULL); | 2939 | TEST_EQ_P (oper->env, NULL); |
2121 | 3094 | 2940 | ||
2125 | 3095 | TEST_EQ_P (oper->node.parent, NULL); | 2941 | TEST_LIST_EMPTY (&oper->children); |
2123 | 3096 | TEST_EQ_P (oper->node.left, NULL); | ||
2124 | 3097 | TEST_EQ_P (oper->node.right, NULL); | ||
2126 | 3098 | 2942 | ||
2127 | 3099 | nih_free (job); | 2943 | nih_free (job); |
2128 | 3100 | } | 2944 | } |
This makes EventOperators N-ary rather than binary trees. It auto-optimizes them with a new event_operator_ add_child helper that simply gifts all of the new child's children to the new parent rather than attaching it when the new parent and child are of the same type.
This makes it a bit easier to make qualitative statements about trees, particularly "this tree only contains OR operators," which should become useful as AND operators become deprecated in future state models.