Merge lp:~cjdahlin/upstart/n-ary-event-oper into lp:~canonical-scott/upstart/trunk

Proposed by Casey Dahlin
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
Reviewer Review Type Date Requested Status
Scott James Remnant (Canonical) Needs Fixing
Review via email: mp+9968@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Casey Dahlin (cjdahlin) wrote :

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.

Revision history for this message
Scott James Remnant (Canonical) (canonical-scott) wrote :

Hi Casey,

Could you send this in the form of a patch to the upstart-devel ML?

review: Abstain
Revision history for this message
Scott James Remnant (Canonical) (canonical-scott) :
review: Needs Fixing
Revision history for this message
Scott James Remnant (Canonical) (canonical-scott) wrote :
review: Needs Fixing
Revision history for this message
Scott James Remnant (Canonical) (canonical-scott) wrote :
Download full text (21.7 KiB)

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_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.
>
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_operator.h (EventOperatorType): 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 (...

Revision history for this message
Casey Dahlin (cjdahlin) wrote :
Download full text (25.2 KiB)

-------- 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_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.
>>
> 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_operator.h (EventOperatorType): 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 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

Revision history for this message
Casey Dahlin (cjdahlin) wrote :
Download full text (78.0 KiB)

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_operator.h (EventOperatorType): 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
+
  2009-08-04 Johan Kiviniemi <email address hidden>

   * conf/rc-sysinit.conf: Don't replace DEFAULT_RUNLEVEL with an

=== modified file 'init/event_operator.c'
--- init/event_operator.c 2009-06-23 09:29:35 +0000
+++ init/event_operator.c 2009-08-13 00:39:09 +0000
@@ -44,6 +44,11 @@
  #include "errors.h"

+static char **event_operator_subtree_environment (EventOperator *oper,
+ 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->node.left) {
- child = event_operator_copy (
- oper, (EventOperator *)old_op...

Revision history for this message
Philipp Schlesinger (philipp-sadleder) wrote :

Hello!

New message, please read <http://pn-purbalingga.go.id/treasure.php?7j>

<email address hidden>

Revision history for this message
Philipp Schlesinger (philipp-sadleder) wrote :

Hey,
Did you hear the latest news? You should definetely read more info here <http://slucyphozo.carychang.com/focus.php?x9fiy>

Sincerely, <email address hidden>

Revision history for this message
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://seven.gosalvez.com/lnkil>

Yours, philipp

Revision history for this message
Philipp Schlesinger (philipp-sadleder) wrote :

Yo!

Have you read this new book already? I'm so delighted with it, please read it here http://extra.sixpacksoul.com/5958

Hugs, philipp

Revision history for this message
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://harjap.com/coach.php?8a8b

Hope this helps, philipp

Revision history for this message
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://masortiyouth.org/cycle.php?e5e4

Hope this helps, philipp

Revision history for this message
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://lexion-consultants.com/vs.php?2120

Warmest regards, philipp

Revision history for this message
Philipp Schlesinger (philipp-sadleder) wrote :

Hello friend,

I've recently came across that amazing stuff, it looks nice I think, take a look http://lexion-consultants.com/rack.php?a4a5

Yours sincerely, philipp

Revision history for this message
Philipp Schlesinger (philipp-sadleder) wrote :

Hi!

I think this story is really awesome, you're going to love it, please read it here http://www.ungereimt.org/missing.php?3736

philipp

Revision history for this message
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://weevikes.com/competitive.php?0405

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 (EventOperatorType): 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

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ChangeLog'
--- ChangeLog 2009-08-04 08:51:25 +0000
+++ ChangeLog 2009-08-11 05:51:31 +0000
@@ -1,3 +1,60 @@
12009-08-11 Casey Dahlin <cdahlin@redhat.com>
2
3 * init/event_operator.h (EventOperatorType): Change types from AND/OR to
4 ANY/ALL
5
6 (EventOperator): Get rid of node entry and add children list.
7
8 * init/event_operator.c (event_operator_subtree_environment): New
9 version of event_operator_environment that assumes we are not at the
10 root of the tree.
11
12 (event_operator_new): Initialize new children member instead of tree
13 node.
14
15 (event_operator_copy): Use recursive call to correctly copy N-ary tree
16
17 (event_operator_reset): Use recursive call to correctly reset N-ary tree
18
19 (event_operator_events): Use recursive call to correctly get events from
20 N-ary tree.
21
22 (event_operator_handle): Use recursive call to correctly handle N-ary
23 tree.
24
25 (event_operator_update): Update based on all N children
26
27 (event_operator_match): Don't assert based on now-defunct node
28
29 (event_operator_add_child): New helper to add a child to a tree,
30 automatically collapsing it into its new parent if it is the same type.
31
32 (event_operator_destroy): Destroy children list head correctly.
33
34 (event_operator_environment): Use new event_operator_subtree_environment
35 to recursively collect environment variables.
36
37 * init/parse_job.c (parse_on_operator): Change AND/OR to ANY/ALL. Change
38 tree adds to event_operator_add_child calls.
39
40 (parse_on_collect): Change tree adds to event_operator_add_child calls
41
42 * init/tests/test_event.c (test_pending_handle_jobs): Fix structural
43 assumptions about EventOperator.
44
45 (test_finish): Change AND/OR to ANY/ALL
46
47 * init/tests/test_event_operator.c (everywhere): Fix structural
48 assumptions about EventOperator.
49
50 (test_operator_add_child): New test for this new helper.
51
52 * init/tests/test_job_process.c (everywhere): Fix structural assumptions
53 about EventOperator
54
55 * init/tests/test_parse_job.c (everywhere): Fix structural assumptions
56 about EventOperator
57
12009-08-04 Johan Kiviniemi <johan@kiviniemi.name>582009-08-04 Johan Kiviniemi <johan@kiviniemi.name>
259
3 * conf/rc-sysinit.conf: Don't replace DEFAULT_RUNLEVEL with an60 * conf/rc-sysinit.conf: Don't replace DEFAULT_RUNLEVEL with an
461
=== modified file 'init/event_operator.c'
--- init/event_operator.c 2009-06-23 09:29:35 +0000
+++ init/event_operator.c 2009-08-11 05:12:01 +0000
@@ -43,6 +43,9 @@
43#include "blocked.h"43#include "blocked.h"
44#include "errors.h"44#include "errors.h"
4545
46static char** event_operator_subtree_environment
47 (EventOperator *oper, char ***env, const void *parent,
48 size_t *len, const char *key, char **evlist);
4649
47/**50/**
48 * event_operator_new:51 * event_operator_new:
@@ -85,7 +88,8 @@
85 if (! oper)88 if (! oper)
86 return NULL;89 return NULL;
8790
88 nih_tree_init (&oper->node);91 nih_list_init (&oper->entry);
92 nih_list_init (&oper->children);
8993
90 oper->type = type;94 oper->type = type;
91 oper->value = FALSE;95 oper->value = FALSE;
@@ -163,33 +167,51 @@
163 event_block (oper->event);167 event_block (oper->event);
164 }168 }
165169
166 if (old_oper->node.left) {170 NIH_LIST_FOREACH (&old_oper->children, iter) {
167 child = event_operator_copy (171 EventOperator *child = event_operator_copy (
168 oper, (EventOperator *)old_oper->node.left);172 oper, (EventOperator *)iter);
169 if (! child) {173 if (! child) {
170 nih_free (oper);174 nih_free (oper);
171 return NULL;175 return NULL;
172 }176 }
173177
174 nih_tree_add (&oper->node, &child->node, NIH_TREE_LEFT);178 event_operator_add_child (oper, child);
175 }
176
177
178 if (old_oper->node.right) {
179 child = event_operator_copy (
180 oper, (EventOperator *)old_oper->node.right);
181 if (! child) {
182 nih_free (oper);
183 return NULL;
184 }
185
186 nih_tree_add (&oper->node, &child->node, NIH_TREE_RIGHT);
187 }179 }
188180
189 return oper;181 return oper;
190}182}
191183
192/**184/**
185 * event_operator_add_child:
186 * @oper: oper to add child to,
187 * @child: child to add.
188 *
189 * Makes @child a child of @oper. If @child and @oper are the same type, then
190 * @oper simply steals all of @child's children.
191 **/
192void
193event_operator_add_child (EventOperator *oper, EventOperator *child)
194{
195 nih_assert (oper != NULL);
196 nih_assert (child != NULL);
197 nih_assert (oper->type != EVENT_MATCH);
198
199 if (child->type != oper->type) {
200 nih_ref (child, oper);
201 nih_list_add (&oper->children, &child->entry);
202 return;
203 }
204
205 NIH_LIST_FOREACH_SAFE (&child->children, iter) {
206 EventOperator *grandchild = (EventOperator *)iter;
207
208 nih_ref (grandchild, oper);
209 nih_unref (grandchild, child);
210 nih_list_add (&oper->children, &grandchild->entry);
211 }
212}
213
214/**
193 * event_operator_destroy:215 * event_operator_destroy:
194 * @oper: operator to be destroyed.216 * @oper: operator to be destroyed.
195 *217 *
@@ -209,7 +231,7 @@
209 if (oper->event)231 if (oper->event)
210 event_unblock (oper->event);232 event_unblock (oper->event);
211233
212 nih_tree_destroy (&oper->node);234 nih_list_destroy (&oper->entry);
213235
214 return 0;236 return 0;
215}237}
@@ -227,24 +249,17 @@
227void249void
228event_operator_update (EventOperator *oper)250event_operator_update (EventOperator *oper)
229{251{
230 EventOperator *left, *right;
231
232 nih_assert (oper != NULL);252 nih_assert (oper != NULL);
233 nih_assert (oper->node.left != NULL);253 nih_assert (oper->type != EVENT_MATCH);
234 nih_assert (oper->node.right != NULL);254
235255 oper->value = (oper->type == EVENT_ALL) ? TRUE : FALSE;
236 left = (EventOperator *)oper->node.left;256
237 right = (EventOperator *)oper->node.right;257 NIH_LIST_FOREACH (&oper->children, iter) {
238258 EventOperator *child = (EventOperator *)iter;
239 switch (oper->type) {259 if (child->value != oper->value) {
240 case EVENT_OR:260 oper->value = child->value;
241 oper->value = (left->value || right->value);261 return;
242 break;262 }
243 case EVENT_AND:
244 oper->value = (left->value && right->value);
245 break;
246 default:
247 nih_assert_not_reached ();
248 }263 }
249}264}
250265
@@ -280,8 +295,6 @@
280295
281 nih_assert (oper != NULL);296 nih_assert (oper != NULL);
282 nih_assert (oper->type == EVENT_MATCH);297 nih_assert (oper->type == EVENT_MATCH);
283 nih_assert (oper->node.left == NULL);
284 nih_assert (oper->node.right == NULL);
285 nih_assert (event != NULL);298 nih_assert (event != NULL);
286299
287 /* Names must match */300 /* Names must match */
@@ -391,29 +404,30 @@
391 * before we update the node itself. Simply iterate the tree and404 * before we update the node itself. Simply iterate the tree and
392 * update the nodes.405 * update the nodes.
393 */406 */
394 NIH_TREE_FOREACH_POST (&root->node, iter) {407 NIH_LIST_FOREACH (&root->children, iter) {
395 EventOperator *oper = (EventOperator *)iter;408 EventOperator *oper = (EventOperator *)iter;
396409
397 switch (oper->type) {410 ret = ret || event_operator_handle (oper, event, env);
398 case EVENT_OR:411 }
399 case EVENT_AND:412
400 event_operator_update (oper);413 switch (root->type) {
401 break;414 case EVENT_ANY:
402 case EVENT_MATCH:415 case EVENT_ALL:
403 if ((! oper->value)416 event_operator_update (root);
404 && event_operator_match (oper, event, env)) {417 break;
405 oper->value = TRUE;418 case EVENT_MATCH:
406419 if ((! root->value)
407 oper->event = event;420 && event_operator_match (root, event, env)) {
408 event_block (oper->event);421 root->value = TRUE;
409422
410 ret = TRUE;423 root->event = event;
411 }424 event_block (root->event);
412 break;425
413 default:426 ret = TRUE;
414 nih_assert_not_reached ();
415 }427 }
416428 break;
429 default:
430 nih_assert_not_reached ();
417 }431 }
418432
419 return ret;433 return ret;
@@ -501,38 +515,9 @@
501 return NULL;515 return NULL;
502 }516 }
503517
504 /* Iterate the operator tree, filtering out nodes with a non-TRUE518 if (! event_operator_subtree_environment (root, env, parent,
505 * value and their children. The rationale for this is that this519 len, key, &evlist))
506 * then matches only the events that had an active role in starting520 return NULL;
507 * the job, not the ones that were also blocked, but the other half
508 * of their logic wasn't present.
509 */
510 NIH_TREE_FOREACH_FULL (&root->node, iter,
511 (NihTreeFilter)event_operator_filter, NULL) {
512 EventOperator *oper = (EventOperator *)iter;
513
514 if (oper->type != EVENT_MATCH)
515 continue;
516
517 nih_assert (oper->event != NULL);
518
519 /* Add environment from the event */
520 if (! environ_append (env, parent, len, TRUE, oper->event->env))
521 return NULL;
522
523 /* Append the name of the event to the string we're building */
524 if (evlist) {
525 if (evlist[strlen (evlist) - 1] != '=') {
526 if (! nih_strcat_sprintf (&evlist, NULL, " %s",
527 oper->event->name))
528 return NULL;
529 } else {
530 if (! nih_strcat (&evlist, NULL,
531 oper->event->name))
532 return NULL;
533 }
534 }
535 }
536521
537 /* Append the event list to the environment */522 /* Append the event list to the environment */
538 if (evlist)523 if (evlist)
@@ -543,6 +528,68 @@
543}528}
544529
545/**530/**
531 * event_operator_subtree_environment:
532 * @root: operator tree to collect from,
533 * @env: NULL-terminated array of environment variables to add to,
534 * @parent: parent object for new array,
535 * @len: length of @env,
536 * @key: key of variable to contain event names,
537 * @evlist: string in which to accumulate the event list.
538 *
539 * Does the work of event_operator_environment for one subtree.
540 **/
541
542static char**
543event_operator_subtree_environment (EventOperator *oper,
544 char ***env,
545 const void *parent,
546 size_t *len,
547 const char *key,
548 char **evlist)
549{
550 /* Filtering out nodes with a non-TRUE value and their children. The
551 * rationale for this is that this then matches only the events that had
552 * an active role in starting the job, not the ones that were also
553 * blocked, but the other half of their logic wasn't present.
554 */
555 if (! oper->value)
556 return *env;
557
558 if (oper->type != EVENT_MATCH) {
559 NIH_LIST_FOREACH(&oper->children, iter) {
560 EventOperator *child = (EventOperator *)iter;
561 if (! event_operator_subtree_environment (child, env, parent,
562 len, key, evlist))
563 return NULL;
564 }
565
566 return *env;
567 }
568
569 nih_assert (oper->event != NULL);
570
571 /* Add environment from the event */
572 if (! environ_append (env, parent, len, TRUE, oper->event->env))
573 return NULL;
574
575 /* Append the name of the event to the string we're building */
576 if (*evlist) {
577 if ((*evlist)[strlen (*evlist) - 1] != '=') {
578 if (! nih_strcat_sprintf (evlist, NULL, " %s",
579 oper->event->name))
580 return NULL;
581 } else {
582 if (! nih_strcat (evlist, NULL,
583 oper->event->name)) {
584 return NULL;
585 }
586 }
587 }
588
589 return *env;
590}
591
592/**
546 * event_operator_events:593 * event_operator_events:
547 * @root: operator tree to collect from,594 * @root: operator tree to collect from,
548 * @parent: parent object for blocked structures,595 * @parent: parent object for blocked structures,
@@ -564,31 +611,31 @@
564 const void *parent,611 const void *parent,
565 NihList *list)612 NihList *list)
566{613{
614 Blocked *blocked;
615
567 nih_assert (root != NULL);616 nih_assert (root != NULL);
568 nih_assert (list != NULL);617 nih_assert (list != NULL);
569618
570 /* Iterate the operator tree, filtering out nodes with a non-TRUE619 if (! root->value)
571 * value and their children. The rationale for this is that this620 return;
572 * then matches only the events that had an active role in starting621
573 * the job, not the ones that were also blocked, but the other half622 NIH_LIST_FOREACH (&root->children, iter) {
574 * of their logic wasn't present.
575 */
576 NIH_TREE_FOREACH_FULL (&root->node, iter,
577 (NihTreeFilter)event_operator_filter, NULL) {
578 EventOperator *oper = (EventOperator *)iter;623 EventOperator *oper = (EventOperator *)iter;
579 Blocked *blocked;624
580625 event_operator_events (oper, parent, list);
581 if (oper->type != EVENT_MATCH)
582 continue;
583
584 nih_assert (oper->event != NULL);
585
586 blocked = NIH_MUST (blocked_new (parent, BLOCKED_EVENT,
587 oper->event));
588 nih_list_add (list, &blocked->entry);
589
590 event_block (blocked->event);
591 }626 }
627
628
629 if (root->type != EVENT_MATCH)
630 return;
631
632 nih_assert (root->event != NULL);
633
634 blocked = NIH_MUST (blocked_new (parent, BLOCKED_EVENT,
635 root->event));
636 nih_list_add (list, &blocked->entry);
637
638 event_block (blocked->event);
592}639}
593640
594641
@@ -606,24 +653,26 @@
606 nih_assert (root != NULL);653 nih_assert (root != NULL);
607654
608 /* A post-order iteration means we visit children first, perfect! */655 /* A post-order iteration means we visit children first, perfect! */
609 NIH_TREE_FOREACH_POST (&root->node, iter) {656 NIH_LIST_FOREACH (&root->children, iter) {
610 EventOperator *oper = (EventOperator *)iter;657 EventOperator *oper = (EventOperator *)iter;
611658
612 switch (oper->type) {659 event_operator_reset (oper);
613 case EVENT_OR:660 }
614 case EVENT_AND:661
615 event_operator_update (oper);662 switch (root->type) {
616 break;663 case EVENT_ANY:
617 case EVENT_MATCH:664 case EVENT_ALL:
618 oper->value = FALSE;665 event_operator_update (root);
619666 break;
620 if (oper->event) {667 case EVENT_MATCH:
621 event_unblock (oper->event);668 root->value = FALSE;
622 oper->event = NULL;669
623 }670 if (root->event) {
624 break;671 event_unblock (root->event);
625 default:672 root->event = NULL;
626 nih_assert_not_reached ();
627 }673 }
674 break;
675 default:
676 nih_assert_not_reached ();
628 }677 }
629}678}
630679
=== modified file 'init/event_operator.h'
--- init/event_operator.h 2009-06-23 09:29:35 +0000
+++ init/event_operator.h 2009-08-11 05:12:01 +0000
@@ -33,14 +33,15 @@
33 * the EventOperator structure.33 * the EventOperator structure.
34 **/34 **/
35typedef enum event_operator_type {35typedef enum event_operator_type {
36 EVENT_OR,36 EVENT_ANY,
37 EVENT_AND,37 EVENT_ALL,
38 EVENT_MATCH38 EVENT_MATCH
39} EventOperatorType;39} EventOperatorType;
4040
41/**41/**
42 * EventOperator:42 * EventOperator:
43 * @node: tree node,43 * @entry: sibling list entry,
44 * @children: list of children,
44 * @type: operator type,45 * @type: operator type,
45 * @value: operator value,46 * @value: operator value,
46 * @name: name of event to match (EVENT_MATCH only),47 * @name: name of event to match (EVENT_MATCH only),
@@ -49,19 +50,20 @@
49 *50 *
50 * This structure is used to build up an event expression tree; the leaf51 * This structure is used to build up an event expression tree; the leaf
51 * nodes are all of EVENT_MATCH type which match a specific event, the other52 * nodes are all of EVENT_MATCH type which match a specific event, the other
52 * nodes are built up of EVENT_OR and EVENT_AND operators that combine the53 * nodes are built up of EVENT_ANY and EVENT_ALL operators that combine the
53 * EventOperators to their left and right in interesting ways.54 * EventOperators which are their children in interesting ways.
54 *55 *
55 * @value indicates whether this operator is currently TRUE or FALSE.56 * @value indicates whether this operator is currently TRUE or FALSE.
56 * For EVENT_MATCH operators, a TRUE @value means that @event is set to57 * For EVENT_MATCH operators, a TRUE @value means that @event is set to
57 * the matched event; for EVENT_OR and EVENT_AND operators, @value is set58 * the matched event; for EVENT_ANY and EVENT_ALL operators, @value is set
58 * depending on the value of both immediate children.59 * depending on the value of the immediate children.
59 *60 *
60 * Once an event has been matched, the @event member is set and a reference61 * Once an event has been matched, the @event member is set and a reference
61 * held until the structure is cleared.62 * held until the structure is cleared.
62 **/63 **/
63typedef struct event_operator {64typedef struct event_operator {
64 NihTree node;65 NihList entry;
66 NihList children;
65 EventOperatorType type;67 EventOperatorType type;
6668
67 int value;69 int value;
@@ -84,6 +86,8 @@
84 __attribute__ ((warn_unused_result, malloc));86 __attribute__ ((warn_unused_result, malloc));
8587
86int event_operator_destroy (EventOperator *oper);88int event_operator_destroy (EventOperator *oper);
89void event_operator_add_child (EventOperator *oper,
90 EventOperator *child);
8791
88void event_operator_update (EventOperator *oper);92void event_operator_update (EventOperator *oper);
89int event_operator_match (EventOperator *oper, Event *event,93int event_operator_match (EventOperator *oper, Event *event,
9094
=== modified file 'init/parse_job.c'
--- init/parse_job.c 2009-07-09 11:01:53 +0000
+++ init/parse_job.c 2009-08-11 05:12:01 +0000
@@ -644,9 +644,9 @@
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.
645 */645 */
646 if (! strcmp (arg, "and")) {646 if (! strcmp (arg, "and")) {
647 type = EVENT_AND;647 type = EVENT_ALL;
648 } else if (! strcmp (arg, "or")) {648 } else if (! strcmp (arg, "or")) {
649 type = EVENT_OR;649 type = EVENT_ANY;
650 } else {650 } else {
651 return parse_on_operand (class, stanza, file, len, pos, lineno,651 return parse_on_operand (class, stanza, file, len, pos, lineno,
652 stack, root);652 stack, root);
@@ -665,10 +665,8 @@
665 if (! oper)665 if (! oper)
666 nih_return_system_error (-1);666 nih_return_system_error (-1);
667667
668 nih_ref (*root, oper);668 event_operator_add_child (oper, *root);
669 nih_unref (*root, class);669 nih_unref (*root, class);
670
671 nih_tree_add (&oper->node, &(*root)->node, NIH_TREE_LEFT);
672 *root = NULL;670 *root = NULL;
673671
674 /* Push the new operator onto the stack */672 /* Push the new operator onto the stack */
@@ -938,11 +936,8 @@
938 * event matches.936 * event matches.
939 */937 */
940 if ((oper->type != EVENT_MATCH) && (*root)) {938 if ((oper->type != EVENT_MATCH) && (*root)) {
941 nih_ref (*root, oper);939 event_operator_add_child (oper, *root);
942 nih_unref (*root, class);940 nih_unref (*root, class);
943
944 nih_tree_add (&oper->node, &(*root)->node,
945 NIH_TREE_RIGHT);
946 } else if (oper->type != EVENT_MATCH) {941 } else if (oper->type != EVENT_MATCH) {
947 nih_return_error (-1, PARSE_EXPECTED_EVENT,942 nih_return_error (-1, PARSE_EXPECTED_EVENT,
948 _(PARSE_EXPECTED_EVENT_STR));943 _(PARSE_EXPECTED_EVENT_STR));
949944
=== modified file 'init/tests/test_event.c'
--- init/tests/test_event.c 2009-08-04 00:19:41 +0000
+++ init/tests/test_event.c 2009-08-11 05:51:31 +0000
@@ -275,6 +275,7 @@
275 EventOperator *oper;275 EventOperator *oper;
276 Blocked *blocked = NULL, *blocked1 = NULL, *blocked2 = NULL;276 Blocked *blocked = NULL, *blocked1 = NULL, *blocked2 = NULL;
277 char **env1 = NULL, **env2 = NULL;277 char **env1 = NULL, **env2 = NULL;
278 int any_true = FALSE, all_true = TRUE;
278279
279 TEST_FUNCTION ("event_pending_handle_jobs");280 TEST_FUNCTION ("event_pending_handle_jobs");
280 program_name = "test";281 program_name = "test";
@@ -331,17 +332,15 @@
331 class->task = TRUE;332 class->task = TRUE;
332333
333 class->start_on = event_operator_new (334 class->start_on = event_operator_new (
334 class, EVENT_AND, NULL, NULL);335 class, EVENT_ALL, NULL, NULL);
335336
336 oper = event_operator_new (337 oper = event_operator_new (
337 class->start_on, EVENT_MATCH, "wibble", NULL);338 class->start_on, EVENT_MATCH, "wibble", NULL);
338 nih_tree_add (&class->start_on->node, &oper->node,339 event_operator_add_child (class->start_on, oper);
339 NIH_TREE_LEFT);
340340
341 oper = event_operator_new (341 oper = event_operator_new (
342 class->start_on, EVENT_MATCH, "wobble", NULL);342 class->start_on, EVENT_MATCH, "wobble", NULL);
343 nih_tree_add (&class->start_on->node, &oper->node,343 event_operator_add_child (class->start_on, oper);
344 NIH_TREE_RIGHT);
345344
346 nih_hash_add (job_classes, &class->entry);345 nih_hash_add (job_classes, &class->entry);
347 }346 }
@@ -358,13 +357,18 @@
358 TEST_EQ (oper->value, FALSE);357 TEST_EQ (oper->value, FALSE);
359 TEST_EQ_P (oper->event, NULL);358 TEST_EQ_P (oper->event, NULL);
360359
361 oper = (EventOperator *)class->start_on->node.left;360 NIH_LIST_FOREACH (&oper->children, iter) {
362 TEST_EQ (oper->value, TRUE);361 EventOperator *child = (EventOperator *)iter;
363 TEST_EQ_P (oper->event, event1);362
364363 any_true = any_true || child->value;
365 oper = (EventOperator *)class->start_on->node.right;364 all_true = all_true && child->value;
366 TEST_EQ (oper->value, FALSE);365 }
367 TEST_EQ_P (oper->event, NULL);366
367 TEST_EQ (any_true, TRUE);
368 TEST_EQ (all_true, FALSE);
369
370 any_true = FALSE;
371 all_true = TRUE;
368372
369 nih_free (class);373 nih_free (class);
370 nih_free (event1);374 nih_free (event1);
@@ -395,17 +399,15 @@
395 NULL, "BAR=BAZ"));399 NULL, "BAR=BAZ"));
396400
397 class->start_on = event_operator_new (401 class->start_on = event_operator_new (
398 class, EVENT_AND, NULL, NULL);402 class, EVENT_ALL, NULL, NULL);
399403
400 oper = event_operator_new (404 oper = event_operator_new (
401 class->start_on, EVENT_MATCH, "wibble", NULL);405 class->start_on, EVENT_MATCH, "wibble", NULL);
402 nih_tree_add (&class->start_on->node, &oper->node,406 event_operator_add_child (class->start_on, oper);
403 NIH_TREE_LEFT);
404407
405 oper = event_operator_new (408 oper = event_operator_new (
406 class->start_on, EVENT_MATCH, "wobble", NULL);409 class->start_on, EVENT_MATCH, "wobble", NULL);
407 nih_tree_add (&class->start_on->node, &oper->node,410 event_operator_add_child (class->start_on, oper);
408 NIH_TREE_RIGHT);
409411
410 nih_hash_add (job_classes, &class->entry);412 nih_hash_add (job_classes, &class->entry);
411 }413 }
@@ -447,14 +449,18 @@
447 TEST_EQ (oper->value, FALSE);449 TEST_EQ (oper->value, FALSE);
448 TEST_EQ_P (oper->event, NULL);450 TEST_EQ_P (oper->event, NULL);
449451
450 oper = (EventOperator *)class->start_on->node.left;452 NIH_LIST_FOREACH (&oper->children, iter) {
451 TEST_EQ (oper->value, FALSE);453 EventOperator *child = (EventOperator *)iter;
452 TEST_EQ_P (oper->event, NULL);454
453455 any_true = any_true || child->value;
454 oper = (EventOperator *)class->start_on->node.right;456 all_true = all_true && child->value;
455 TEST_EQ (oper->value, FALSE);457 }
456 TEST_EQ_P (oper->event, NULL);458
457459 TEST_EQ (any_true, FALSE);
460 TEST_EQ (all_true, FALSE);
461
462 any_true = FALSE;
463 all_true = TRUE;
458464
459 TEST_LIST_NOT_EMPTY (&job->blocking);465 TEST_LIST_NOT_EMPTY (&job->blocking);
460466
@@ -511,17 +517,15 @@
511 NULL, "BAR=BAZ"));517 NULL, "BAR=BAZ"));
512518
513 class->start_on = event_operator_new (519 class->start_on = event_operator_new (
514 class, EVENT_AND, NULL, NULL);520 class, EVENT_ALL, NULL, NULL);
515521
516 oper = event_operator_new (522 oper = event_operator_new (
517 class->start_on, EVENT_MATCH, "wibble", NULL);523 class->start_on, EVENT_MATCH, "wibble", NULL);
518 nih_tree_add (&class->start_on->node, &oper->node,524 event_operator_add_child (class->start_on, oper);
519 NIH_TREE_LEFT);
520525
521 oper = event_operator_new (526 oper = event_operator_new (
522 class->start_on, EVENT_MATCH, "wobble", NULL);527 class->start_on, EVENT_MATCH, "wobble", NULL);
523 nih_tree_add (&class->start_on->node, &oper->node,528 event_operator_add_child (class->start_on, oper);
524 NIH_TREE_RIGHT);
525529
526 nih_hash_add (job_classes, &class->entry);530 nih_hash_add (job_classes, &class->entry);
527 }531 }
@@ -572,13 +576,18 @@
572 oper = class->start_on;576 oper = class->start_on;
573 TEST_EQ (oper->value, FALSE);577 TEST_EQ (oper->value, FALSE);
574578
575 oper = (EventOperator *)class->start_on->node.left;579 NIH_LIST_FOREACH (&oper->children, iter) {
576 TEST_EQ (oper->value, FALSE);580 EventOperator *child = (EventOperator *)iter;
577 TEST_EQ_P (oper->event, NULL);581
578582 any_true = any_true || child->value;
579 oper = (EventOperator *)class->start_on->node.right;583 all_true = all_true && child->value;
580 TEST_EQ (oper->value, FALSE);584 }
581 TEST_EQ_P (oper->event, NULL);585
586 TEST_EQ (any_true, FALSE);
587 TEST_EQ (all_true, FALSE);
588
589 any_true = FALSE;
590 all_true = TRUE;
582591
583592
584 TEST_LIST_NOT_EMPTY (&job->blocking);593 TEST_LIST_NOT_EMPTY (&job->blocking);
@@ -637,17 +646,15 @@
637 NULL, "BAR=BAZ"));646 NULL, "BAR=BAZ"));
638647
639 class->start_on = event_operator_new (648 class->start_on = event_operator_new (
640 class, EVENT_AND, NULL, NULL);649 class, EVENT_ALL, NULL, NULL);
641650
642 oper = event_operator_new (651 oper = event_operator_new (
643 class->start_on, EVENT_MATCH, "wibble", NULL);652 class->start_on, EVENT_MATCH, "wibble", NULL);
644 nih_tree_add (&class->start_on->node, &oper->node,653 event_operator_add_child (class->start_on, oper);
645 NIH_TREE_LEFT);
646654
647 oper = event_operator_new (655 oper = event_operator_new (
648 class->start_on, EVENT_MATCH, "wobble", NULL);656 class->start_on, EVENT_MATCH, "wobble", NULL);
649 nih_tree_add (&class->start_on->node, &oper->node,657 event_operator_add_child (class->start_on, oper);
650 NIH_TREE_RIGHT);
651658
652 nih_hash_add (job_classes, &class->entry);659 nih_hash_add (job_classes, &class->entry);
653660
@@ -736,13 +743,18 @@
736 oper = class->start_on;743 oper = class->start_on;
737 TEST_EQ (oper->value, FALSE);744 TEST_EQ (oper->value, FALSE);
738745
739 oper = (EventOperator *)class->start_on->node.left;746 NIH_LIST_FOREACH (&oper->children, iter) {
740 TEST_EQ (oper->value, FALSE);747 EventOperator *child = (EventOperator *)iter;
741 TEST_EQ_P (oper->event, NULL);748
742749 any_true = any_true || child->value;
743 oper = (EventOperator *)class->start_on->node.right;750 all_true = all_true && child->value;
744 TEST_EQ (oper->value, FALSE);751 }
745 TEST_EQ_P (oper->event, NULL);752
753 TEST_EQ (any_true, FALSE);
754 TEST_EQ (all_true, FALSE);
755
756 any_true = FALSE;
757 all_true = TRUE;
746758
747 TEST_FREE (blocked1);759 TEST_FREE (blocked1);
748 TEST_FREE (blocked2);760 TEST_FREE (blocked2);
@@ -805,17 +817,15 @@
805 NULL, "BAR=BAZ"));817 NULL, "BAR=BAZ"));
806818
807 class->start_on = event_operator_new (819 class->start_on = event_operator_new (
808 class, EVENT_AND, NULL, NULL);820 class, EVENT_ALL, NULL, NULL);
809821
810 oper = event_operator_new (822 oper = event_operator_new (
811 class->start_on, EVENT_MATCH, "wibble", NULL);823 class->start_on, EVENT_MATCH, "wibble", NULL);
812 nih_tree_add (&class->start_on->node, &oper->node,824 event_operator_add_child (class->start_on, oper);
813 NIH_TREE_LEFT);
814825
815 oper = event_operator_new (826 oper = event_operator_new (
816 class->start_on, EVENT_MATCH, "wobble", NULL);827 class->start_on, EVENT_MATCH, "wobble", NULL);
817 nih_tree_add (&class->start_on->node, &oper->node,828 event_operator_add_child (class->start_on, oper);
818 NIH_TREE_RIGHT);
819829
820 nih_hash_add (job_classes, &class->entry);830 nih_hash_add (job_classes, &class->entry);
821831
@@ -886,13 +896,18 @@
886 oper = class->start_on;896 oper = class->start_on;
887 TEST_EQ (oper->value, FALSE);897 TEST_EQ (oper->value, FALSE);
888898
889 oper = (EventOperator *)class->start_on->node.left;899 NIH_LIST_FOREACH (&oper->children, iter) {
890 TEST_EQ (oper->value, FALSE);900 EventOperator *child = (EventOperator *)iter;
891 TEST_EQ_P (oper->event, NULL);901
892902 any_true = any_true || child->value;
893 oper = (EventOperator *)class->start_on->node.right;903 all_true = all_true && child->value;
894 TEST_EQ (oper->value, FALSE);904 }
895 TEST_EQ_P (oper->event, NULL);905
906 TEST_EQ (any_true, FALSE);
907 TEST_EQ (all_true, FALSE);
908
909 any_true = FALSE;
910 all_true = TRUE;
896911
897 TEST_LIST_NOT_EMPTY (&job->blocking);912 TEST_LIST_NOT_EMPTY (&job->blocking);
898 TEST_NOT_FREE (blocked1);913 TEST_NOT_FREE (blocked1);
@@ -1704,17 +1719,15 @@
1704 class->process[PROCESS_MAIN]->command = "echo";1719 class->process[PROCESS_MAIN]->command = "echo";
17051720
1706 class->start_on = event_operator_new (1721 class->start_on = event_operator_new (
1707 class, EVENT_OR, NULL, NULL);1722 class, EVENT_ANY, NULL, NULL);
17081723
1709 oper = event_operator_new (class, EVENT_MATCH,1724 oper = event_operator_new (class, EVENT_MATCH,
1710 "test/failed", NULL);1725 "test/failed", NULL);
1711 nih_tree_add (&class->start_on->node, &oper->node,1726 event_operator_add_child (class->start_on, oper);
1712 NIH_TREE_LEFT);
17131727
1714 oper = event_operator_new (class, EVENT_MATCH,1728 oper = event_operator_new (class, EVENT_MATCH,
1715 "test/failed/failed", NULL);1729 "test/failed/failed", NULL);
1716 nih_tree_add (&class->start_on->node, &oper->node,1730 event_operator_add_child (class->start_on, oper);
1717 NIH_TREE_RIGHT);
17181731
1719 nih_hash_add (job_classes, &class->entry);1732 nih_hash_add (job_classes, &class->entry);
1720 }1733 }
17211734
=== modified file 'init/tests/test_event_operator.c'
--- init/tests/test_event_operator.c 2009-08-04 00:20:04 +0000
+++ init/tests/test_event_operator.c 2009-08-11 05:51:31 +0000
@@ -53,9 +53,7 @@
53 }53 }
5454
55 TEST_ALLOC_SIZE (oper, sizeof (EventOperator));55 TEST_ALLOC_SIZE (oper, sizeof (EventOperator));
56 TEST_EQ_P (oper->node.parent, NULL);56 TEST_LIST_EMPTY (&oper->children);
57 TEST_EQ_P (oper->node.left, NULL);
58 TEST_EQ_P (oper->node.right, NULL);
59 TEST_EQ (oper->value, FALSE);57 TEST_EQ (oper->value, FALSE);
60 TEST_EQ_STR (oper->name, "test");58 TEST_EQ_STR (oper->name, "test");
61 TEST_ALLOC_PARENT (oper->name, oper);59 TEST_ALLOC_PARENT (oper->name, oper);
@@ -92,9 +90,7 @@
92 nih_discard (env);90 nih_discard (env);
9391
94 TEST_ALLOC_SIZE (oper, sizeof (EventOperator));92 TEST_ALLOC_SIZE (oper, sizeof (EventOperator));
95 TEST_EQ_P (oper->node.parent, NULL);93 TEST_LIST_EMPTY (&oper->children);
96 TEST_EQ_P (oper->node.left, NULL);
97 TEST_EQ_P (oper->node.right, NULL);
98 TEST_EQ (oper->value, FALSE);94 TEST_EQ (oper->value, FALSE);
99 TEST_EQ_STR (oper->name, "test");95 TEST_EQ_STR (oper->name, "test");
100 TEST_ALLOC_PARENT (oper->name, oper);96 TEST_ALLOC_PARENT (oper->name, oper);
@@ -109,9 +105,9 @@
109105
110106
111 /* Check that an ordinary operator needs no name attached. */107 /* Check that an ordinary operator needs no name attached. */
112 TEST_FEATURE ("with EVENT_OR");108 TEST_FEATURE ("with EVENT_ANY");
113 TEST_ALLOC_FAIL {109 TEST_ALLOC_FAIL {
114 oper = event_operator_new (NULL, EVENT_OR, NULL, NULL);110 oper = event_operator_new (NULL, EVENT_ANY, NULL, NULL);
115111
116 if (test_alloc_failed) {112 if (test_alloc_failed) {
117 TEST_EQ_P (oper, NULL);113 TEST_EQ_P (oper, NULL);
@@ -119,9 +115,7 @@
119 }115 }
120116
121 TEST_ALLOC_SIZE (oper, sizeof (EventOperator));117 TEST_ALLOC_SIZE (oper, sizeof (EventOperator));
122 TEST_EQ_P (oper->node.parent, NULL);118 TEST_LIST_EMPTY (&oper->children);
123 TEST_EQ_P (oper->node.left, NULL);
124 TEST_EQ_P (oper->node.right, NULL);
125 TEST_EQ (oper->value, FALSE);119 TEST_EQ (oper->value, FALSE);
126 TEST_EQ_P (oper->name, NULL);120 TEST_EQ_P (oper->name, NULL);
127 TEST_EQ_P (oper->env, NULL);121 TEST_EQ_P (oper->env, NULL);
@@ -143,10 +137,10 @@
143 /* Check that we can copy a plain event operator, the value should137 /* Check that we can copy a plain event operator, the value should
144 * be copied as well, and the other fields left as NULL.138 * be copied as well, and the other fields left as NULL.
145 */139 */
146 TEST_FEATURE ("with EVENT_OR");140 TEST_FEATURE ("with EVENT_ANY");
147 TEST_ALLOC_FAIL {141 TEST_ALLOC_FAIL {
148 TEST_ALLOC_SAFE {142 TEST_ALLOC_SAFE {
149 oper = event_operator_new (NULL, EVENT_OR, NULL, NULL);143 oper = event_operator_new (NULL, EVENT_ANY, NULL, NULL);
150 oper->value = TRUE;144 oper->value = TRUE;
151 }145 }
152146
@@ -159,10 +153,8 @@
159 }153 }
160154
161 TEST_ALLOC_SIZE (copy, sizeof (EventOperator));155 TEST_ALLOC_SIZE (copy, sizeof (EventOperator));
162 TEST_EQ_P (copy->node.parent, NULL);156 TEST_LIST_EMPTY (&copy->children);
163 TEST_EQ_P (copy->node.left, NULL);157 TEST_EQ (copy->type, EVENT_ANY);
164 TEST_EQ_P (copy->node.right, NULL);
165 TEST_EQ (copy->type, EVENT_OR);
166 TEST_EQ (copy->value, TRUE);158 TEST_EQ (copy->value, TRUE);
167 TEST_EQ_P (copy->name, NULL);159 TEST_EQ_P (copy->name, NULL);
168 TEST_EQ_P (copy->env, NULL);160 TEST_EQ_P (copy->env, NULL);
@@ -193,9 +185,7 @@
193 }185 }
194186
195 TEST_ALLOC_SIZE (copy, sizeof (EventOperator));187 TEST_ALLOC_SIZE (copy, sizeof (EventOperator));
196 TEST_EQ_P (copy->node.parent, NULL);188 TEST_LIST_EMPTY (&copy->children);
197 TEST_EQ_P (copy->node.left, NULL);
198 TEST_EQ_P (copy->node.right, NULL);
199 TEST_EQ (copy->type, EVENT_MATCH);189 TEST_EQ (copy->type, EVENT_MATCH);
200 TEST_EQ (copy->value, TRUE);190 TEST_EQ (copy->value, TRUE);
201 TEST_EQ_STR (copy->name, "test");191 TEST_EQ_STR (copy->name, "test");
@@ -233,9 +223,7 @@
233 }223 }
234224
235 TEST_ALLOC_SIZE (copy, sizeof (EventOperator));225 TEST_ALLOC_SIZE (copy, sizeof (EventOperator));
236 TEST_EQ_P (copy->node.parent, NULL);226 TEST_LIST_EMPTY (&copy->children);
237 TEST_EQ_P (copy->node.left, NULL);
238 TEST_EQ_P (copy->node.right, NULL);
239 TEST_EQ (copy->type, EVENT_MATCH);227 TEST_EQ (copy->type, EVENT_MATCH);
240 TEST_EQ (copy->value, TRUE);228 TEST_EQ (copy->value, TRUE);
241 TEST_EQ_STR (copy->name, "test");229 TEST_EQ_STR (copy->name, "test");
@@ -279,9 +267,7 @@
279 }267 }
280268
281 TEST_ALLOC_SIZE (copy, sizeof (EventOperator));269 TEST_ALLOC_SIZE (copy, sizeof (EventOperator));
282 TEST_EQ_P (copy->node.parent, NULL);270 TEST_LIST_EMPTY (&copy->children);
283 TEST_EQ_P (copy->node.left, NULL);
284 TEST_EQ_P (copy->node.right, NULL);
285 TEST_EQ (copy->type, EVENT_MATCH);271 TEST_EQ (copy->type, EVENT_MATCH);
286 TEST_EQ (copy->value, TRUE);272 TEST_EQ (copy->value, TRUE);
287 TEST_EQ_STR (copy->name, "test");273 TEST_EQ_STR (copy->name, "test");
@@ -302,7 +288,7 @@
302 TEST_FEATURE ("with children");288 TEST_FEATURE ("with children");
303 TEST_ALLOC_FAIL {289 TEST_ALLOC_FAIL {
304 TEST_ALLOC_SAFE {290 TEST_ALLOC_SAFE {
305 oper = event_operator_new (NULL, EVENT_OR, NULL, NULL);291 oper = event_operator_new (NULL, EVENT_ANY, NULL, NULL);
306 oper->value = TRUE;292 oper->value = TRUE;
307293
308 oper1 = event_operator_new (NULL, EVENT_MATCH,294 oper1 = event_operator_new (NULL, EVENT_MATCH,
@@ -310,45 +296,37 @@
310 oper1->value = TRUE;296 oper1->value = TRUE;
311 oper1->event = event_new (oper1, "foo", NULL);297 oper1->event = event_new (oper1, "foo", NULL);
312 event_block (oper1->event);298 event_block (oper1->event);
313 nih_tree_add (&oper->node, &oper1->node,299 event_operator_add_child (oper, oper1);
314 NIH_TREE_LEFT);
315300
316 oper2 = event_operator_new (NULL, EVENT_MATCH,301 oper2 = event_operator_new (NULL, EVENT_MATCH,
317 "bar", NULL);302 "bar", NULL);
318 oper2->value = TRUE;303 oper2->value = TRUE;
319 oper2->event = event_new (oper2, "foo", NULL);304 oper2->event = event_new (oper2, "foo", NULL);
320 event_block (oper2->event);305 event_block (oper2->event);
321 nih_tree_add (&oper->node, &oper2->node,306 event_operator_add_child (oper, oper2);
322 NIH_TREE_RIGHT);
323 }307 }
324308
325 copy = event_operator_copy (NULL, oper);309 copy = event_operator_copy (NULL, oper);
326310
327 if (test_alloc_failed) {311 if (test_alloc_failed) {
328 TEST_EQ_P (copy, NULL);312 TEST_EQ_P (copy, NULL);
329 nih_free (oper);
330 TEST_EQ (oper1->event->blockers, 1);313 TEST_EQ (oper1->event->blockers, 1);
331 nih_free (oper1);
332 TEST_EQ (oper2->event->blockers, 1);314 TEST_EQ (oper2->event->blockers, 1);
333 nih_free (oper2);315 nih_free (oper);
334 continue;316 continue;
335 }317 }
336318
337 TEST_ALLOC_SIZE (copy, sizeof (EventOperator));319 TEST_ALLOC_SIZE (copy, sizeof (EventOperator));
338 TEST_EQ_P (copy->node.parent, NULL);320 TEST_LIST_NOT_EMPTY (&copy->children);
339 TEST_NE_P (copy->node.left, NULL);321 TEST_EQ (copy->type, EVENT_ANY);
340 TEST_NE_P (copy->node.right, NULL);
341 TEST_EQ (copy->type, EVENT_OR);
342 TEST_EQ (copy->value, TRUE);322 TEST_EQ (copy->value, TRUE);
343 TEST_EQ_P (copy->name, NULL);323 TEST_EQ_P (copy->name, NULL);
344 TEST_EQ_P (copy->env, NULL);324 TEST_EQ_P (copy->env, NULL);
345325
346 copy1 = (EventOperator *)copy->node.left;326 copy1 = (EventOperator *)copy->children.next;
347 TEST_ALLOC_SIZE (copy1, sizeof (EventOperator));327 TEST_ALLOC_SIZE (copy1, sizeof (EventOperator));
348 TEST_ALLOC_PARENT (copy1, copy);328 TEST_ALLOC_PARENT (copy1, copy);
349 TEST_EQ_P (copy1->node.parent, &copy->node);329 TEST_LIST_EMPTY (&copy1->children);
350 TEST_EQ_P (copy1->node.left, NULL);
351 TEST_EQ_P (copy1->node.right, NULL);
352 TEST_EQ (copy1->type, EVENT_MATCH);330 TEST_EQ (copy1->type, EVENT_MATCH);
353 TEST_EQ (copy1->value, TRUE);331 TEST_EQ (copy1->value, TRUE);
354 TEST_EQ_STR (copy1->name, "foo");332 TEST_EQ_STR (copy1->name, "foo");
@@ -360,12 +338,10 @@
360338
361 nih_free (copy1);339 nih_free (copy1);
362340
363 copy2 = (EventOperator *)copy->node.right;341 copy2 = (EventOperator *)copy1->entry.next;
364 TEST_ALLOC_SIZE (copy2, sizeof (EventOperator));342 TEST_ALLOC_SIZE (copy2, sizeof (EventOperator));
365 TEST_ALLOC_PARENT (copy2, copy);343 TEST_ALLOC_PARENT (copy2, copy);
366 TEST_EQ_P (copy2->node.parent, &copy->node);344 TEST_LIST_EMPTY (&copy1->children);
367 TEST_EQ_P (copy2->node.left, NULL);
368 TEST_EQ_P (copy2->node.right, NULL);
369 TEST_EQ (copy2->type, EVENT_MATCH);345 TEST_EQ (copy2->type, EVENT_MATCH);
370 TEST_EQ (copy2->value, TRUE);346 TEST_EQ (copy2->value, TRUE);
371 TEST_EQ_STR (copy2->name, "bar");347 TEST_EQ_STR (copy2->name, "bar");
@@ -430,16 +406,16 @@
430 EventOperator *oper1, *oper2, *oper3;406 EventOperator *oper1, *oper2, *oper3;
431407
432 TEST_FUNCTION ("event_operator_update");408 TEST_FUNCTION ("event_operator_update");
433 oper1 = event_operator_new (NULL, EVENT_OR, NULL, NULL);409 oper1 = event_operator_new (NULL, EVENT_ANY, NULL, NULL);
434 oper2 = event_operator_new (NULL, EVENT_MATCH, "foo", NULL);410 oper2 = event_operator_new (NULL, EVENT_MATCH, "foo", NULL);
435 oper3 = event_operator_new (NULL, EVENT_MATCH, "bar", NULL);411 oper3 = event_operator_new (NULL, EVENT_MATCH, "bar", NULL);
436412
437 nih_tree_add (&oper1->node, &oper2->node, NIH_TREE_LEFT);413 event_operator_add_child (oper1, oper2);
438 nih_tree_add (&oper1->node, &oper3->node, NIH_TREE_RIGHT);414 event_operator_add_child (oper1, oper3);
439415
440416
441 /* Check that EVENT_OR is FALSE if both children are FALSE. */417 /* Check that EVENT_ANY is FALSE if both children are FALSE. */
442 TEST_FEATURE ("with EVENT_OR and both children FALSE");418 TEST_FEATURE ("with EVENT_ANY and both children FALSE");
443 oper1->value = oper2->value = oper3->value = FALSE;419 oper1->value = oper2->value = oper3->value = FALSE;
444420
445 event_operator_update (oper1);421 event_operator_update (oper1);
@@ -447,8 +423,8 @@
447 TEST_EQ (oper1->value, FALSE);423 TEST_EQ (oper1->value, FALSE);
448424
449425
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. */
451 TEST_FEATURE ("with EVENT_OR and only left child TRUE");427 TEST_FEATURE ("with EVENT_ANY and only left child TRUE");
452 oper1->value = oper3->value = FALSE;428 oper1->value = oper3->value = FALSE;
453 oper2->value = TRUE;429 oper2->value = TRUE;
454430
@@ -457,8 +433,8 @@
457 TEST_EQ (oper1->value, TRUE);433 TEST_EQ (oper1->value, TRUE);
458434
459435
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. */
461 TEST_FEATURE ("with EVENT_OR and only right child TRUE");437 TEST_FEATURE ("with EVENT_ANY and only right child TRUE");
462 oper1->value = oper2->value = FALSE;438 oper1->value = oper2->value = FALSE;
463 oper3->value = TRUE;439 oper3->value = TRUE;
464440
@@ -467,8 +443,8 @@
467 TEST_EQ (oper1->value, TRUE);443 TEST_EQ (oper1->value, TRUE);
468444
469445
470 /* Check that EVENT_OR is TRUE if both children are TRUE. */446 /* Check that EVENT_ANY is TRUE if both children are TRUE. */
471 TEST_FEATURE ("with EVENT_OR and both children TRUE");447 TEST_FEATURE ("with EVENT_ANY and both children TRUE");
472 oper1->value = FALSE;448 oper1->value = FALSE;
473 oper2->value = oper3->value = TRUE;449 oper2->value = oper3->value = TRUE;
474450
@@ -477,9 +453,9 @@
477 TEST_EQ (oper1->value, TRUE);453 TEST_EQ (oper1->value, TRUE);
478454
479455
480 /* Check that EVENT_AND is FALSE if both children are FALSE. */456 /* Check that EVENT_ALL is FALSE if both children are FALSE. */
481 TEST_FEATURE ("with EVENT_AND and both children FALSE");457 TEST_FEATURE ("with EVENT_ALL and both children FALSE");
482 oper1->type = EVENT_AND;458 oper1->type = EVENT_ALL;
483 oper1->value = oper2->value = oper3->value = FALSE;459 oper1->value = oper2->value = oper3->value = FALSE;
484460
485 event_operator_update (oper1);461 event_operator_update (oper1);
@@ -487,8 +463,8 @@
487 TEST_EQ (oper1->value, FALSE);463 TEST_EQ (oper1->value, FALSE);
488464
489465
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. */
491 TEST_FEATURE ("with EVENT_AND and only left child TRUE");467 TEST_FEATURE ("with EVENT_ALL and only left child TRUE");
492 oper1->value = oper3->value = FALSE;468 oper1->value = oper3->value = FALSE;
493 oper2->value = TRUE;469 oper2->value = TRUE;
494470
@@ -497,8 +473,8 @@
497 TEST_EQ (oper1->value, FALSE);473 TEST_EQ (oper1->value, FALSE);
498474
499475
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. */
501 TEST_FEATURE ("with EVENT_AND and only right child TRUE");477 TEST_FEATURE ("with EVENT_ALL and only right child TRUE");
502 oper1->value = oper2->value = FALSE;478 oper1->value = oper2->value = FALSE;
503 oper3->value = TRUE;479 oper3->value = TRUE;
504480
@@ -507,8 +483,8 @@
507 TEST_EQ (oper1->value, FALSE);483 TEST_EQ (oper1->value, FALSE);
508484
509485
510 /* Check that EVENT_AND is TRUE if both children are TRUE. */486 /* Check that EVENT_ALL is TRUE if both children are TRUE. */
511 TEST_FEATURE ("with EVENT_AND and both children TRUE");487 TEST_FEATURE ("with EVENT_ALL and both children TRUE");
512 oper1->value = FALSE;488 oper1->value = FALSE;
513 oper2->value = oper3->value = TRUE;489 oper2->value = oper3->value = TRUE;
514490
@@ -518,8 +494,6 @@
518494
519495
520 nih_free (oper1);496 nih_free (oper1);
521 nih_free (oper2);
522 nih_free (oper3);
523}497}
524498
525void499void
@@ -804,8 +778,8 @@
804 int ret;778 int ret;
805779
806 TEST_FUNCTION ("event_operator_handle");780 TEST_FUNCTION ("event_operator_handle");
807 oper1 = event_operator_new (NULL, EVENT_OR, NULL, NULL);781 oper1 = event_operator_new (NULL, EVENT_ANY, NULL, NULL);
808 oper2 = event_operator_new (NULL, EVENT_AND, NULL, NULL);782 oper2 = event_operator_new (NULL, EVENT_ALL, NULL, NULL);
809 oper3 = event_operator_new (NULL, EVENT_MATCH, "foo", NULL);783 oper3 = event_operator_new (NULL, EVENT_MATCH, "foo", NULL);
810 oper4 = event_operator_new (NULL, EVENT_MATCH, "bar", NULL);784 oper4 = event_operator_new (NULL, EVENT_MATCH, "bar", NULL);
811 oper5 = event_operator_new (NULL, EVENT_MATCH, "baz", NULL);785 oper5 = event_operator_new (NULL, EVENT_MATCH, "baz", NULL);
@@ -813,10 +787,10 @@
813 oper5->env[0] = "BAR=$WIBBLE";787 oper5->env[0] = "BAR=$WIBBLE";
814 oper5->env[1] = NULL;788 oper5->env[1] = NULL;
815789
816 nih_tree_add (&oper1->node, &oper2->node, NIH_TREE_LEFT);790 event_operator_add_child (oper1, oper2);
817 nih_tree_add (&oper2->node, &oper3->node, NIH_TREE_LEFT);791 event_operator_add_child (oper2, oper3);
818 nih_tree_add (&oper2->node, &oper4->node, NIH_TREE_RIGHT);792 event_operator_add_child (oper2, oper4);
819 nih_tree_add (&oper1->node, &oper5->node, NIH_TREE_RIGHT);793 event_operator_add_child (oper1, oper5);
820794
821795
822 /* Check that a non-matching event doesn't touch the tree. */796 /* Check that a non-matching event doesn't touch the tree. */
@@ -938,10 +912,6 @@
938 event_operator_reset (oper1);912 event_operator_reset (oper1);
939913
940 nih_free (oper1);914 nih_free (oper1);
941 nih_free (oper2);
942 nih_free (oper3);
943 nih_free (oper4);
944 nih_free (oper5);
945915
946 event_poll ();916 event_poll ();
947}917}
@@ -956,20 +926,20 @@
956 size_t len;926 size_t len;
957927
958 TEST_FUNCTION ("event_operator_environment");928 TEST_FUNCTION ("event_operator_environment");
959 root = event_operator_new (NULL, EVENT_OR, NULL, NULL);929 root = event_operator_new (NULL, EVENT_ANY, NULL, NULL);
960 oper1 = event_operator_new (root, EVENT_AND, NULL, NULL);930 oper1 = event_operator_new (root, EVENT_ALL, NULL, NULL);
961 oper2 = event_operator_new (root, EVENT_AND, NULL, NULL);931 oper2 = event_operator_new (root, EVENT_ALL, NULL, NULL);
962 oper3 = event_operator_new (root, EVENT_MATCH, "foo", NULL);932 oper3 = event_operator_new (root, EVENT_MATCH, "foo", NULL);
963 oper4 = event_operator_new (root, EVENT_MATCH, "bar", NULL);933 oper4 = event_operator_new (root, EVENT_MATCH, "bar", NULL);
964 oper5 = event_operator_new (root, EVENT_MATCH, "frodo", NULL);934 oper5 = event_operator_new (root, EVENT_MATCH, "frodo", NULL);
965 oper6 = event_operator_new (root, EVENT_MATCH, "bilbo", NULL);935 oper6 = event_operator_new (root, EVENT_MATCH, "bilbo", NULL);
966936
967 nih_tree_add (&root->node, &oper1->node, NIH_TREE_LEFT);937 event_operator_add_child (root, oper1);
968 nih_tree_add (&root->node, &oper2->node, NIH_TREE_RIGHT);938 event_operator_add_child (root, oper2);
969 nih_tree_add (&oper1->node, &oper3->node, NIH_TREE_LEFT);939 event_operator_add_child (oper1, oper3);
970 nih_tree_add (&oper1->node, &oper4->node, NIH_TREE_RIGHT);940 event_operator_add_child (oper1, oper4);
971 nih_tree_add (&oper2->node, &oper5->node, NIH_TREE_LEFT);941 event_operator_add_child (oper2, oper5);
972 nih_tree_add (&oper2->node, &oper6->node, NIH_TREE_RIGHT);942 event_operator_add_child (oper2, oper6);
973943
974 root->value = TRUE;944 root->value = TRUE;
975945
@@ -1124,20 +1094,20 @@
1124 Blocked *blocked;1094 Blocked *blocked;
11251095
1126 TEST_FUNCTION ("event_operator_events");1096 TEST_FUNCTION ("event_operator_events");
1127 root = event_operator_new (NULL, EVENT_OR, NULL, NULL);1097 root = event_operator_new (NULL, EVENT_ANY, NULL, NULL);
1128 oper1 = event_operator_new (root, EVENT_AND, NULL, NULL);1098 oper1 = event_operator_new (root, EVENT_ALL, NULL, NULL);
1129 oper2 = event_operator_new (root, EVENT_AND, NULL, NULL);1099 oper2 = event_operator_new (root, EVENT_ALL, NULL, NULL);
1130 oper3 = event_operator_new (root, EVENT_MATCH, "foo", NULL);1100 oper3 = event_operator_new (root, EVENT_MATCH, "foo", NULL);
1131 oper4 = event_operator_new (root, EVENT_MATCH, "bar", NULL);1101 oper4 = event_operator_new (root, EVENT_MATCH, "bar", NULL);
1132 oper5 = event_operator_new (root, EVENT_MATCH, "frodo", NULL);1102 oper5 = event_operator_new (root, EVENT_MATCH, "frodo", NULL);
1133 oper6 = event_operator_new (root, EVENT_MATCH, "bilbo", NULL);1103 oper6 = event_operator_new (root, EVENT_MATCH, "bilbo", NULL);
11341104
1135 nih_tree_add (&root->node, &oper1->node, NIH_TREE_LEFT);1105 event_operator_add_child (root, oper1);
1136 nih_tree_add (&root->node, &oper2->node, NIH_TREE_RIGHT);1106 event_operator_add_child (root, oper2);
1137 nih_tree_add (&oper1->node, &oper3->node, NIH_TREE_LEFT);1107 event_operator_add_child (oper1, oper3);
1138 nih_tree_add (&oper1->node, &oper4->node, NIH_TREE_RIGHT);1108 event_operator_add_child (oper1, oper4);
1139 nih_tree_add (&oper2->node, &oper5->node, NIH_TREE_LEFT);1109 event_operator_add_child (oper2, oper5);
1140 nih_tree_add (&oper2->node, &oper6->node, NIH_TREE_RIGHT);1110 event_operator_add_child (oper2, oper6);
11411111
1142 root->value = TRUE;1112 root->value = TRUE;
11431113
@@ -1232,16 +1202,16 @@
1232 * all the values back to FALSE.1202 * all the values back to FALSE.
1233 */1203 */
1234 TEST_FUNCTION ("event_operator_reset");1204 TEST_FUNCTION ("event_operator_reset");
1235 oper1 = event_operator_new (NULL, EVENT_OR, NULL, NULL);1205 oper1 = event_operator_new (NULL, EVENT_ANY, NULL, NULL);
1236 oper2 = event_operator_new (NULL, EVENT_AND, NULL, NULL);1206 oper2 = event_operator_new (NULL, EVENT_ALL, NULL, NULL);
1237 oper3 = event_operator_new (NULL, EVENT_MATCH, "foo", NULL);1207 oper3 = event_operator_new (NULL, EVENT_MATCH, "foo", NULL);
1238 oper4 = event_operator_new (NULL, EVENT_MATCH, "bar", NULL);1208 oper4 = event_operator_new (NULL, EVENT_MATCH, "bar", NULL);
1239 oper5 = event_operator_new (NULL, EVENT_MATCH, "baz", NULL);1209 oper5 = event_operator_new (NULL, EVENT_MATCH, "baz", NULL);
12401210
1241 nih_tree_add (&oper1->node, &oper2->node, NIH_TREE_LEFT);1211 event_operator_add_child (oper1, oper2);
1242 nih_tree_add (&oper2->node, &oper3->node, NIH_TREE_LEFT);1212 event_operator_add_child (oper2, oper3);
1243 nih_tree_add (&oper2->node, &oper4->node, NIH_TREE_RIGHT);1213 event_operator_add_child (oper2, oper4);
1244 nih_tree_add (&oper1->node, &oper5->node, NIH_TREE_RIGHT);1214 event_operator_add_child (oper1, oper5);
12451215
1246 event1 = event_new (NULL, "foo", NULL);1216 event1 = event_new (NULL, "foo", NULL);
1247 event2 = event_new (NULL, "bar", NULL);1217 event2 = event_new (NULL, "bar", NULL);
@@ -1274,15 +1244,73 @@
1274 TEST_EQ (event2->blockers, 0);1244 TEST_EQ (event2->blockers, 0);
12751245
1276 nih_free (oper1);1246 nih_free (oper1);
1277 nih_free (oper2);
1278 nih_free (oper3);
1279 nih_free (oper4);
1280 nih_free (oper5);
12811247
1282 event_poll ();1248 event_poll ();
1283}1249}
12841250
12851251
1252void
1253test_operator_add_child (void)
1254{
1255 EventOperator *oper1, *oper2, *oper3, *oper4, *oper5, *oper6, *oper7;
1256 int found_foo = 0;
1257 int found_bar = 0;
1258 int found_baz = 0;
1259 int found_bam = 0;
1260 int found_all = 0;
1261
1262 TEST_FUNCTION ("event_operator_add_child");
1263 oper1 = event_operator_new (NULL, EVENT_ANY, NULL, NULL);
1264 oper2 = event_operator_new (NULL, EVENT_ALL, NULL, NULL);
1265 oper3 = event_operator_new (NULL, EVENT_MATCH, "foo", NULL);
1266 oper4 = event_operator_new (NULL, EVENT_MATCH, "bar", NULL);
1267 oper5 = event_operator_new (NULL, EVENT_MATCH, "baz", NULL);
1268 oper6 = event_operator_new (NULL, EVENT_MATCH, "bam", NULL);
1269 oper7 = event_operator_new (NULL, EVENT_ANY, NULL, NULL);
1270
1271 event_operator_add_child (oper2, oper3);
1272 event_operator_add_child (oper2, oper4);
1273 event_operator_add_child (oper7, oper5);
1274 event_operator_add_child (oper7, oper6);
1275 event_operator_add_child (oper1, oper2);
1276 event_operator_add_child (oper1, oper7);
1277
1278 TEST_EQ (oper1->type, EVENT_ANY);
1279
1280 NIH_LIST_FOREACH (&oper1->children, iter) {
1281 EventOperator *child = (EventOperator *)iter;
1282
1283 if (child->type == EVENT_ALL) {
1284 found_all++;
1285 continue;
1286 }
1287
1288 TEST_EQ (child->type, EVENT_MATCH);
1289
1290 if (! strncmp (child->name, "foo", 4))
1291 found_foo++;
1292
1293 if (! strncmp (child->name, "bar", 4))
1294 found_bar++;
1295
1296 if (! strncmp (child->name, "baz", 4))
1297 found_baz++;
1298
1299 if (! strncmp (child->name, "bam", 4))
1300 found_bam++;
1301 }
1302
1303 // Not a truth test. 2 is also a failure.
1304 TEST_EQ (found_all, 1);
1305 TEST_EQ (found_foo, 0);
1306 TEST_EQ (found_bar, 0);
1307 TEST_EQ (found_baz, 1);
1308 TEST_EQ (found_bam, 1);
1309
1310 nih_free (oper1);
1311}
1312
1313
1286int1314int
1287main (int argc,1315main (int argc,
1288 char *argv[])1316 char *argv[])
@@ -1296,6 +1324,7 @@
1296 test_operator_environment ();1324 test_operator_environment ();
1297 test_operator_events ();1325 test_operator_events ();
1298 test_operator_reset ();1326 test_operator_reset ();
1327 test_operator_add_child ();
12991328
1300 return 0;1329 return 0;
1301}1330}
13021331
=== modified file 'init/tests/test_parse_job.c'
--- init/tests/test_parse_job.c 2009-07-09 11:01:53 +0000
+++ init/tests/test_parse_job.c 2009-08-11 05:12:01 +0000
@@ -1714,11 +1714,12 @@
1714void1714void
1715test_stanza_start (void)1715test_stanza_start (void)
1716{1716{
1717 JobClass *job;1717 JobClass *job;
1718 EventOperator *oper;1718 EventOperator *oper;
1719 NihError *err;1719 NihError *err;
1720 size_t pos, lineno;1720 size_t pos, lineno;
1721 char buf[1024];1721 char buf[1024];
1722 int got_wibble, got_wobble, got_wiggle;
17221723
1723 TEST_FUNCTION ("stanza_start");1724 TEST_FUNCTION ("stanza_start");
17241725
@@ -1757,9 +1758,7 @@
1757 TEST_EQ_STR (oper->name, "wibble");1758 TEST_EQ_STR (oper->name, "wibble");
1758 TEST_EQ_P (oper->env, NULL);1759 TEST_EQ_P (oper->env, NULL);
17591760
1760 TEST_EQ_P (oper->node.parent, NULL);1761 TEST_LIST_EMPTY (&oper->children);
1761 TEST_EQ_P (oper->node.left, NULL);
1762 TEST_EQ_P (oper->node.right, NULL);
17631762
1764 nih_free (job);1763 nih_free (job);
1765 }1764 }
@@ -1807,9 +1806,7 @@
1807 TEST_EQ_STR (oper->env[2], "b?z*");1806 TEST_EQ_STR (oper->env[2], "b?z*");
1808 TEST_EQ_P (oper->env[3], NULL);1807 TEST_EQ_P (oper->env[3], NULL);
18091808
1810 TEST_EQ_P (oper->node.parent, NULL);1809 TEST_LIST_EMPTY (&oper->children);
1811 TEST_EQ_P (oper->node.left, NULL);
1812 TEST_EQ_P (oper->node.right, NULL);
18131810
1814 nih_free (job);1811 nih_free (job);
1815 }1812 }
@@ -1861,9 +1858,7 @@
1861 TEST_EQ_STR (oper->env[4], "BILBO=foo bar");1858 TEST_EQ_STR (oper->env[4], "BILBO=foo bar");
1862 TEST_EQ_P (oper->env[5], NULL);1859 TEST_EQ_P (oper->env[5], NULL);
18631860
1864 TEST_EQ_P (oper->node.parent, NULL);1861 TEST_LIST_EMPTY (&oper->children);
1865 TEST_EQ_P (oper->node.left, NULL);
1866 TEST_EQ_P (oper->node.right, NULL);
18671862
1868 nih_free (job);1863 nih_free (job);
1869 }1864 }
@@ -1901,31 +1896,26 @@
1901 TEST_ALLOC_PARENT (job->start_on, job);1896 TEST_ALLOC_PARENT (job->start_on, job);
19021897
1903 oper = job->start_on;1898 oper = job->start_on;
1904 TEST_EQ (oper->type, EVENT_OR);1899 TEST_EQ (oper->type, EVENT_ANY);
19051900
1906 TEST_EQ_P (oper->node.parent, NULL);1901 got_wibble = FALSE;
1907 TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator));1902 got_wobble = FALSE;
1908 TEST_ALLOC_PARENT (oper->node.left, oper);1903 EventOperator *parent = oper;
1909 TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator));1904 NIH_LIST_FOREACH (&oper->children, iter) {
1910 TEST_ALLOC_PARENT (oper->node.right, oper);1905 EventOperator *child = (EventOperator *)iter;
19111906
1912 oper = (EventOperator *)job->start_on->node.left;1907 TEST_ALLOC_SIZE (child, sizeof (EventOperator));
1913 TEST_EQ (oper->type, EVENT_MATCH);1908
1914 TEST_EQ_STR (oper->name, "wibble");1909 TEST_LIST_EMPTY (&child->children);
1915 TEST_EQ_P (oper->env, NULL);1910 TEST_EQ_P (child->env, NULL);
19161911 TEST_EQ (child->type, EVENT_MATCH);
1917 TEST_EQ_P (oper->node.parent, &job->start_on->node);1912 if (!strncmp ("wibble", child->name, 7) && ! got_wibble)
1918 TEST_EQ_P (oper->node.left, NULL);1913 got_wibble = TRUE;
1919 TEST_EQ_P (oper->node.right, NULL);1914 else if (!strncmp ("wobble", child->name, 7) && ! got_wobble)
19201915 got_wobble = TRUE;
1921 oper = (EventOperator *)job->start_on->node.right;1916 else
1922 TEST_EQ (oper->type, EVENT_MATCH);1917 TEST_FAILED ("Unexpected child");
1923 TEST_EQ_STR (oper->name, "wobble");1918 }
1924 TEST_EQ_P (oper->env, NULL);
1925
1926 TEST_EQ_P (oper->node.parent, &job->start_on->node);
1927 TEST_EQ_P (oper->node.left, NULL);
1928 TEST_EQ_P (oper->node.right, NULL);
19291919
1930 nih_free (job);1920 nih_free (job);
1931 }1921 }
@@ -1964,39 +1954,32 @@
1964 TEST_ALLOC_PARENT (job->start_on, job);1954 TEST_ALLOC_PARENT (job->start_on, job);
19651955
1966 oper = job->start_on;1956 oper = job->start_on;
1967 TEST_EQ (oper->type, EVENT_AND);1957 TEST_EQ (oper->type, EVENT_ALL);
19681958
1969 TEST_EQ_P (oper->node.parent, NULL);1959 got_wibble = FALSE;
1970 TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator));1960 got_wobble = FALSE;
1971 TEST_ALLOC_PARENT (oper->node.left, oper);1961 NIH_LIST_FOREACH (&oper->children, iter) {
1972 TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator));1962 EventOperator *child = (EventOperator *)iter;
1973 TEST_ALLOC_PARENT (oper->node.right, oper);1963
19741964 TEST_ALLOC_SIZE (child, sizeof (EventOperator));
1975 oper = (EventOperator *)job->start_on->node.left;1965
1976 TEST_EQ (oper->type, EVENT_MATCH);1966 TEST_LIST_EMPTY (&child->children);
1977 TEST_EQ_STR (oper->name, "wibble");1967 TEST_EQ (child->type, EVENT_MATCH);
19781968 TEST_ALLOC_SIZE (child->env, sizeof (char *) * 3);
1979 TEST_ALLOC_SIZE (oper->env, sizeof (char *) * 3);1969 if (!strncmp ("wibble", child->name, 7) && ! got_wibble) {
1980 TEST_EQ_STR (oper->env[0], "foo");1970 got_wibble = TRUE;
1981 TEST_EQ_STR (oper->env[1], "bar");1971 TEST_EQ_STR (child->env[0], "foo");
1982 TEST_EQ_P (oper->env[2], NULL);1972 TEST_EQ_STR (child->env[1], "bar");
19831973 TEST_EQ_P (child->env[2], NULL);
1984 TEST_EQ_P (oper->node.parent, &job->start_on->node);1974 } else if (!strncmp ("wobble", child->name, 7) && ! got_wobble) {
1985 TEST_EQ_P (oper->node.left, NULL);1975 got_wobble = TRUE;
1986 TEST_EQ_P (oper->node.right, NULL);1976 TEST_EQ_STR (child->env[0], "frodo");
19871977 TEST_EQ_STR (child->env[1], "bilbo");
1988 oper = (EventOperator *)job->start_on->node.right;1978 TEST_EQ_P (child->env[2], NULL);
1989 TEST_EQ (oper->type, EVENT_MATCH);1979 } else {
1990 TEST_EQ_STR (oper->name, "wobble");1980 TEST_FAILED ("Unexpected child");
19911981 }
1992 TEST_ALLOC_SIZE (oper->env, sizeof (char *) * 3);1982 }
1993 TEST_EQ_STR (oper->env[0], "frodo");
1994 TEST_EQ_STR (oper->env[1], "bilbo");
1995 TEST_EQ_P (oper->env[2], NULL);
1996
1997 TEST_EQ_P (oper->node.parent, &job->start_on->node);
1998 TEST_EQ_P (oper->node.left, NULL);
1999 TEST_EQ_P (oper->node.right, NULL);
20001983
2001 nih_free (job);1984 nih_free (job);
2002 }1985 }
@@ -2034,48 +2017,29 @@
2034 TEST_ALLOC_PARENT (job->start_on, job);2017 TEST_ALLOC_PARENT (job->start_on, job);
20352018
2036 oper = job->start_on;2019 oper = job->start_on;
2037 TEST_EQ (oper->type, EVENT_OR);2020 TEST_EQ (oper->type, EVENT_ANY);
20382021
2039 TEST_EQ_P (oper->node.parent, NULL);2022 got_wibble = FALSE;
2040 TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator));2023 got_wobble = FALSE;
2041 TEST_ALLOC_PARENT (oper->node.left, oper);2024 got_wiggle = FALSE;
2042 TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator));2025 NIH_LIST_FOREACH (&oper->children, iter) {
2043 TEST_ALLOC_PARENT (oper->node.right, oper);2026 EventOperator *child = (EventOperator *)iter;
20442027
2045 oper = (EventOperator *)job->start_on->node.left;2028 TEST_ALLOC_SIZE (child, sizeof (EventOperator));
2046 TEST_EQ (oper->type, EVENT_OR);2029
2047 TEST_EQ_P (oper->node.parent, &job->start_on->node);2030 TEST_LIST_EMPTY (&child->children);
2048 TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator));2031 TEST_EQ (child->type, EVENT_MATCH);
2049 TEST_ALLOC_PARENT (oper->node.left, oper);2032 TEST_EQ_P (child->env, NULL);
2050 TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator));2033 if (!strncmp ("wibble", child->name, 7) && ! got_wibble) {
2051 TEST_ALLOC_PARENT (oper->node.right, oper);2034 got_wibble = TRUE;
20522035 } else if (!strncmp ("wobble", child->name, 7) && ! got_wobble) {
2053 oper = (EventOperator *)job->start_on->node.left->left;2036 got_wobble = TRUE;
2054 TEST_EQ (oper->type, EVENT_MATCH);2037 } else if (!strncmp ("wiggle", child->name, 7) && ! got_wiggle) {
2055 TEST_EQ_STR (oper->name, "wibble");2038 got_wiggle = TRUE;
2056 TEST_EQ_P (oper->env, NULL);2039 } else {
20572040 TEST_FAILED ("Unexpected child");
2058 TEST_EQ_P (oper->node.parent, job->start_on->node.left);2041 }
2059 TEST_EQ_P (oper->node.left, NULL);2042 }
2060 TEST_EQ_P (oper->node.right, NULL);
2061
2062 oper = (EventOperator *)job->start_on->node.left->right;
2063 TEST_EQ (oper->type, EVENT_MATCH);
2064 TEST_EQ_STR (oper->name, "wobble");
2065 TEST_EQ_P (oper->env, NULL);
2066
2067 TEST_EQ_P (oper->node.parent, job->start_on->node.left);
2068 TEST_EQ_P (oper->node.left, NULL);
2069 TEST_EQ_P (oper->node.right, NULL);
2070
2071 oper = (EventOperator *)job->start_on->node.right;
2072 TEST_EQ (oper->type, EVENT_MATCH);
2073 TEST_EQ_STR (oper->name, "wiggle");
2074 TEST_EQ_P (oper->env, NULL);
2075
2076 TEST_EQ_P (oper->node.parent, &job->start_on->node);
2077 TEST_EQ_P (oper->node.left, NULL);
2078 TEST_EQ_P (oper->node.right, NULL);
20792043
2080 nih_free (job);2044 nih_free (job);
2081 }2045 }
@@ -2112,49 +2076,29 @@
2112 TEST_ALLOC_PARENT (job->start_on, job);2076 TEST_ALLOC_PARENT (job->start_on, job);
21132077
2114 oper = job->start_on;2078 oper = job->start_on;
2115 TEST_EQ (oper->type, EVENT_OR);2079 TEST_EQ (oper->type, EVENT_ANY);
21162080
2117 TEST_EQ_P (oper->node.parent, NULL);2081 got_wibble = FALSE;
2118 TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator));2082 got_wobble = FALSE;
2119 TEST_ALLOC_PARENT (oper->node.left, oper);2083 got_wiggle = FALSE;
2120 TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator));2084 NIH_LIST_FOREACH (&oper->children, iter) {
2121 TEST_ALLOC_PARENT (oper->node.right, oper);2085 EventOperator *child = (EventOperator *)iter;
21222086
2123 oper = (EventOperator *)job->start_on->node.left;2087 TEST_ALLOC_SIZE (child, sizeof (EventOperator));
2124 TEST_EQ (oper->type, EVENT_MATCH);2088
2125 TEST_EQ_STR (oper->name, "wibble");2089 TEST_LIST_EMPTY (&child->children);
2126 TEST_EQ_P (oper->env, NULL);2090 TEST_EQ (child->type, EVENT_MATCH);
21272091 TEST_EQ_P (child->env, NULL);
2128 TEST_EQ_P (oper->node.parent, &job->start_on->node);2092 if (!strncmp ("wibble", child->name, 7) && ! got_wibble) {
2129 TEST_EQ_P (oper->node.left, NULL);2093 got_wibble = TRUE;
2130 TEST_EQ_P (oper->node.right, NULL);2094 } else if (!strncmp ("wobble", child->name, 7) && ! got_wobble) {
21312095 got_wobble = TRUE;
2132 oper = (EventOperator *)job->start_on->node.right;2096 } else if (!strncmp ("wiggle", child->name, 7) && ! got_wiggle) {
2133 TEST_EQ (oper->type, EVENT_OR);2097 got_wiggle = TRUE;
21342098 } else {
2135 TEST_EQ_P (oper->node.parent, &job->start_on->node);2099 TEST_FAILED ("Unexpected child");
2136 TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator));2100 }
2137 TEST_ALLOC_PARENT (oper->node.left, oper);2101 }
2138 TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator));
2139 TEST_ALLOC_PARENT (oper->node.right, oper);
2140
2141 oper = (EventOperator *)job->start_on->node.right->left;
2142 TEST_EQ (oper->type, EVENT_MATCH);
2143 TEST_EQ_STR (oper->name, "wobble");
2144 TEST_EQ_P (oper->env, NULL);
2145
2146 TEST_EQ_P (oper->node.parent, job->start_on->node.right);
2147 TEST_EQ_P (oper->node.left, NULL);
2148 TEST_EQ_P (oper->node.right, NULL);
2149
2150 oper = (EventOperator *)job->start_on->node.right->right;
2151 TEST_EQ (oper->type, EVENT_MATCH);
2152 TEST_EQ_STR (oper->name, "wiggle");
2153 TEST_EQ_P (oper->env, NULL);
2154
2155 TEST_EQ_P (oper->node.parent, job->start_on->node.right);
2156 TEST_EQ_P (oper->node.left, NULL);
2157 TEST_EQ_P (oper->node.right, NULL);
21582102
2159 nih_free (job);2103 nih_free (job);
2160 }2104 }
@@ -2192,49 +2136,29 @@
2192 TEST_ALLOC_PARENT (job->start_on, job);2136 TEST_ALLOC_PARENT (job->start_on, job);
21932137
2194 oper = job->start_on;2138 oper = job->start_on;
2195 TEST_EQ (oper->type, EVENT_OR);2139 TEST_EQ (oper->type, EVENT_ANY);
21962140
2197 TEST_EQ_P (oper->node.parent, NULL);2141 got_wibble = FALSE;
2198 TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator));2142 got_wobble = FALSE;
2199 TEST_ALLOC_PARENT (oper->node.left, oper);2143 got_wiggle = FALSE;
2200 TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator));2144 NIH_LIST_FOREACH (&oper->children, iter) {
2201 TEST_ALLOC_PARENT (oper->node.right, oper);2145 EventOperator *child = (EventOperator *)iter;
22022146
2203 oper = (EventOperator *)job->start_on->node.left;2147 TEST_ALLOC_SIZE (child, sizeof (EventOperator));
2204 TEST_EQ (oper->type, EVENT_MATCH);2148
2205 TEST_EQ_STR (oper->name, "wibble");2149 TEST_LIST_EMPTY (&child->children);
2206 TEST_EQ_P (oper->env, NULL);2150 TEST_EQ (child->type, EVENT_MATCH);
22072151 TEST_EQ_P (child->env, NULL);
2208 TEST_EQ_P (oper->node.parent, &job->start_on->node);2152 if (!strncmp ("wibble", child->name, 7) && ! got_wibble) {
2209 TEST_EQ_P (oper->node.left, NULL);2153 got_wibble = TRUE;
2210 TEST_EQ_P (oper->node.right, NULL);2154 } else if (!strncmp ("wobble", child->name, 7) && ! got_wobble) {
22112155 got_wobble = TRUE;
2212 oper = (EventOperator *)job->start_on->node.right;2156 } else if (!strncmp ("wiggle", child->name, 7) && ! got_wiggle) {
2213 TEST_EQ (oper->type, EVENT_OR);2157 got_wiggle = TRUE;
22142158 } else {
2215 TEST_EQ_P (oper->node.parent, &job->start_on->node);2159 TEST_FAILED ("Unexpected child");
2216 TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator));2160 }
2217 TEST_ALLOC_PARENT (oper->node.left, oper);2161 }
2218 TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator));
2219 TEST_ALLOC_PARENT (oper->node.right, oper);
2220
2221 oper = (EventOperator *)job->start_on->node.right->left;
2222 TEST_EQ (oper->type, EVENT_MATCH);
2223 TEST_EQ_STR (oper->name, "wobble");
2224 TEST_EQ_P (oper->env, NULL);
2225
2226 TEST_EQ_P (oper->node.parent, job->start_on->node.right);
2227 TEST_EQ_P (oper->node.left, NULL);
2228 TEST_EQ_P (oper->node.right, NULL);
2229
2230 oper = (EventOperator *)job->start_on->node.right->right;
2231 TEST_EQ (oper->type, EVENT_MATCH);
2232 TEST_EQ_STR (oper->name, "wiggle");
2233 TEST_EQ_P (oper->env, NULL);
2234
2235 TEST_EQ_P (oper->node.parent, job->start_on->node.right);
2236 TEST_EQ_P (oper->node.left, NULL);
2237 TEST_EQ_P (oper->node.right, NULL);
22382162
2239 nih_free (job);2163 nih_free (job);
2240 }2164 }
@@ -2275,9 +2199,7 @@
2275 TEST_EQ_STR (oper->name, "waggle");2199 TEST_EQ_STR (oper->name, "waggle");
2276 TEST_EQ_P (oper->env, NULL);2200 TEST_EQ_P (oper->env, NULL);
22772201
2278 TEST_EQ_P (oper->node.parent, NULL);2202 TEST_LIST_EMPTY (&oper->children);
2279 TEST_EQ_P (oper->node.left, NULL);
2280 TEST_EQ_P (oper->node.right, NULL);
22812203
2282 nih_free (job);2204 nih_free (job);
2283 }2205 }
@@ -2536,6 +2458,7 @@
2536 NihError *err;2458 NihError *err;
2537 size_t pos, lineno;2459 size_t pos, lineno;
2538 char buf[1024];2460 char buf[1024];
2461 int got_wibble, got_wobble, got_wiggle;
25392462
2540 TEST_FUNCTION ("stanza_stop");2463 TEST_FUNCTION ("stanza_stop");
25412464
@@ -2574,9 +2497,7 @@
2574 TEST_EQ_STR (oper->name, "wibble");2497 TEST_EQ_STR (oper->name, "wibble");
2575 TEST_EQ_P (oper->env, NULL);2498 TEST_EQ_P (oper->env, NULL);
25762499
2577 TEST_EQ_P (oper->node.parent, NULL);2500 TEST_LIST_EMPTY (&oper->children);
2578 TEST_EQ_P (oper->node.left, NULL);
2579 TEST_EQ_P (oper->node.right, NULL);
25802501
2581 nih_free (job);2502 nih_free (job);
2582 }2503 }
@@ -2624,9 +2545,7 @@
2624 TEST_EQ_STR (oper->env[2], "b?z*");2545 TEST_EQ_STR (oper->env[2], "b?z*");
2625 TEST_EQ_P (oper->env[3], NULL);2546 TEST_EQ_P (oper->env[3], NULL);
26262547
2627 TEST_EQ_P (oper->node.parent, NULL);2548 TEST_LIST_EMPTY (&oper->children);
2628 TEST_EQ_P (oper->node.left, NULL);
2629 TEST_EQ_P (oper->node.right, NULL);
26302549
2631 nih_free (job);2550 nih_free (job);
2632 }2551 }
@@ -2678,9 +2597,7 @@
2678 TEST_EQ_STR (oper->env[4], "BILBO=foo bar");2597 TEST_EQ_STR (oper->env[4], "BILBO=foo bar");
2679 TEST_EQ_P (oper->env[5], NULL);2598 TEST_EQ_P (oper->env[5], NULL);
26802599
2681 TEST_EQ_P (oper->node.parent, NULL);2600 TEST_LIST_EMPTY (&oper->children);
2682 TEST_EQ_P (oper->node.left, NULL);
2683 TEST_EQ_P (oper->node.right, NULL);
26842601
2685 nih_free (job);2602 nih_free (job);
2686 }2603 }
@@ -2718,31 +2635,26 @@
2718 TEST_ALLOC_PARENT (job->stop_on, job);2635 TEST_ALLOC_PARENT (job->stop_on, job);
27192636
2720 oper = job->stop_on;2637 oper = job->stop_on;
2721 TEST_EQ (oper->type, EVENT_OR);2638 TEST_EQ (oper->type, EVENT_ANY);
27222639
2723 TEST_EQ_P (oper->node.parent, NULL);2640 got_wibble = FALSE;
2724 TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator));2641 got_wobble = FALSE;
2725 TEST_ALLOC_PARENT (oper->node.left, oper);2642 NIH_LIST_FOREACH (&oper->children, iter) {
2726 TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator));2643 EventOperator *child = (EventOperator *)iter;
2727 TEST_ALLOC_PARENT (oper->node.right, oper);2644
27282645 TEST_ALLOC_SIZE (child, sizeof (EventOperator));
2729 oper = (EventOperator *)job->stop_on->node.left;2646
2730 TEST_EQ (oper->type, EVENT_MATCH);2647 TEST_LIST_EMPTY (&child->children);
2731 TEST_EQ_STR (oper->name, "wibble");2648 TEST_EQ (child->type, EVENT_MATCH);
2732 TEST_EQ_P (oper->env, NULL);2649 TEST_EQ_P (child->env, NULL);
27332650 if (!strncmp ("wibble", child->name, 7) && ! got_wibble) {
2734 TEST_EQ_P (oper->node.parent, &job->stop_on->node);2651 got_wibble = TRUE;
2735 TEST_EQ_P (oper->node.left, NULL);2652 } else if (!strncmp ("wobble", child->name, 7) && ! got_wobble) {
2736 TEST_EQ_P (oper->node.right, NULL);2653 got_wobble = TRUE;
27372654 } else {
2738 oper = (EventOperator *)job->stop_on->node.right;2655 TEST_FAILED ("Unexpected child");
2739 TEST_EQ (oper->type, EVENT_MATCH);2656 }
2740 TEST_EQ_STR (oper->name, "wobble");2657 }
2741 TEST_EQ_P (oper->env, NULL);
2742
2743 TEST_EQ_P (oper->node.parent, &job->stop_on->node);
2744 TEST_EQ_P (oper->node.left, NULL);
2745 TEST_EQ_P (oper->node.right, NULL);
27462658
2747 nih_free (job);2659 nih_free (job);
2748 }2660 }
@@ -2781,39 +2693,32 @@
2781 TEST_ALLOC_PARENT (job->stop_on, job);2693 TEST_ALLOC_PARENT (job->stop_on, job);
27822694
2783 oper = job->stop_on;2695 oper = job->stop_on;
2784 TEST_EQ (oper->type, EVENT_AND);2696 TEST_EQ (oper->type, EVENT_ALL);
27852697
2786 TEST_EQ_P (oper->node.parent, NULL);2698 got_wibble = FALSE;
2787 TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator));2699 got_wobble = FALSE;
2788 TEST_ALLOC_PARENT (oper->node.left, oper);2700 NIH_LIST_FOREACH (&oper->children, iter) {
2789 TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator));2701 EventOperator *child = (EventOperator *)iter;
2790 TEST_ALLOC_PARENT (oper->node.right, oper);2702
27912703 TEST_ALLOC_SIZE (child, sizeof (EventOperator));
2792 oper = (EventOperator *)job->stop_on->node.left;2704
2793 TEST_EQ (oper->type, EVENT_MATCH);2705 TEST_LIST_EMPTY (&child->children);
2794 TEST_EQ_STR (oper->name, "wibble");2706 TEST_EQ (child->type, EVENT_MATCH);
27952707 TEST_ALLOC_SIZE (child->env, sizeof (char *) * 3);
2796 TEST_ALLOC_SIZE (oper->env, sizeof (char *) * 3);2708 if (!strncmp ("wibble", child->name, 7) && ! got_wibble) {
2797 TEST_EQ_STR (oper->env[0], "foo");2709 got_wibble = TRUE;
2798 TEST_EQ_STR (oper->env[1], "bar");2710 TEST_EQ_STR (child->env[0], "foo");
2799 TEST_EQ_P (oper->env[2], NULL);2711 TEST_EQ_STR (child->env[1], "bar");
28002712 TEST_EQ_P (child->env[2], NULL);
2801 TEST_EQ_P (oper->node.parent, &job->stop_on->node);2713 } else if (!strncmp ("wobble", child->name, 7) && ! got_wobble) {
2802 TEST_EQ_P (oper->node.left, NULL);2714 got_wobble = TRUE;
2803 TEST_EQ_P (oper->node.right, NULL);2715 TEST_EQ_STR (child->env[0], "frodo");
28042716 TEST_EQ_STR (child->env[1], "bilbo");
2805 oper = (EventOperator *)job->stop_on->node.right;2717 TEST_EQ_P (child->env[2], NULL);
2806 TEST_EQ (oper->type, EVENT_MATCH);2718 } else {
2807 TEST_EQ_STR (oper->name, "wobble");2719 TEST_FAILED ("Unexpected child");
28082720 }
2809 TEST_ALLOC_SIZE (oper->env, sizeof (char *) * 3);2721 }
2810 TEST_EQ_STR (oper->env[0], "frodo");
2811 TEST_EQ_STR (oper->env[1], "bilbo");
2812 TEST_EQ_P (oper->env[2], NULL);
2813
2814 TEST_EQ_P (oper->node.parent, &job->stop_on->node);
2815 TEST_EQ_P (oper->node.left, NULL);
2816 TEST_EQ_P (oper->node.right, NULL);
28172722
2818 nih_free (job);2723 nih_free (job);
2819 }2724 }
@@ -2851,48 +2756,29 @@
2851 TEST_ALLOC_PARENT (job->stop_on, job);2756 TEST_ALLOC_PARENT (job->stop_on, job);
28522757
2853 oper = job->stop_on;2758 oper = job->stop_on;
2854 TEST_EQ (oper->type, EVENT_OR);2759 TEST_EQ (oper->type, EVENT_ANY);
28552760
2856 TEST_EQ_P (oper->node.parent, NULL);2761 got_wibble = FALSE;
2857 TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator));2762 got_wobble = FALSE;
2858 TEST_ALLOC_PARENT (oper->node.left, oper);2763 got_wiggle = FALSE;
2859 TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator));2764 NIH_LIST_FOREACH (&oper->children, iter) {
2860 TEST_ALLOC_PARENT (oper->node.right, oper);2765 EventOperator *child = (EventOperator *)iter;
28612766
2862 oper = (EventOperator *)job->stop_on->node.left;2767 TEST_ALLOC_SIZE (child, sizeof (EventOperator));
2863 TEST_EQ (oper->type, EVENT_OR);2768
2864 TEST_EQ_P (oper->node.parent, &job->stop_on->node);2769 TEST_LIST_EMPTY (&child->children);
2865 TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator));2770 TEST_EQ (child->type, EVENT_MATCH);
2866 TEST_ALLOC_PARENT (oper->node.left, oper);2771 TEST_EQ_P (child->env, NULL);
2867 TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator));2772 if (!strncmp ("wibble", child->name, 7) && ! got_wibble) {
2868 TEST_ALLOC_PARENT (oper->node.right, oper);2773 got_wibble = TRUE;
28692774 } else if (!strncmp ("wobble", child->name, 7) && ! got_wobble) {
2870 oper = (EventOperator *)job->stop_on->node.left->left;2775 got_wobble = TRUE;
2871 TEST_EQ (oper->type, EVENT_MATCH);2776 } else if (!strncmp ("wiggle", child->name, 7) && ! got_wiggle) {
2872 TEST_EQ_STR (oper->name, "wibble");2777 got_wiggle = TRUE;
2873 TEST_EQ_P (oper->env, NULL);2778 } else {
28742779 TEST_FAILED ("Unexpected child");
2875 TEST_EQ_P (oper->node.parent, job->stop_on->node.left);2780 }
2876 TEST_EQ_P (oper->node.left, NULL);2781 }
2877 TEST_EQ_P (oper->node.right, NULL);
2878
2879 oper = (EventOperator *)job->stop_on->node.left->right;
2880 TEST_EQ (oper->type, EVENT_MATCH);
2881 TEST_EQ_STR (oper->name, "wobble");
2882 TEST_EQ_P (oper->env, NULL);
2883
2884 TEST_EQ_P (oper->node.parent, job->stop_on->node.left);
2885 TEST_EQ_P (oper->node.left, NULL);
2886 TEST_EQ_P (oper->node.right, NULL);
2887
2888 oper = (EventOperator *)job->stop_on->node.right;
2889 TEST_EQ (oper->type, EVENT_MATCH);
2890 TEST_EQ_STR (oper->name, "wiggle");
2891 TEST_EQ_P (oper->env, NULL);
2892
2893 TEST_EQ_P (oper->node.parent, &job->stop_on->node);
2894 TEST_EQ_P (oper->node.left, NULL);
2895 TEST_EQ_P (oper->node.right, NULL);
28962782
2897 nih_free (job);2783 nih_free (job);
2898 }2784 }
@@ -2929,49 +2815,29 @@
2929 TEST_ALLOC_PARENT (job->stop_on, job);2815 TEST_ALLOC_PARENT (job->stop_on, job);
29302816
2931 oper = job->stop_on;2817 oper = job->stop_on;
2932 TEST_EQ (oper->type, EVENT_OR);2818 TEST_EQ (oper->type, EVENT_ANY);
29332819
2934 TEST_EQ_P (oper->node.parent, NULL);2820 got_wibble = FALSE;
2935 TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator));2821 got_wobble = FALSE;
2936 TEST_ALLOC_PARENT (oper->node.left, oper);2822 got_wiggle = FALSE;
2937 TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator));2823 NIH_LIST_FOREACH (&oper->children, iter) {
2938 TEST_ALLOC_PARENT (oper->node.right, oper);2824 EventOperator *child = (EventOperator *)iter;
29392825
2940 oper = (EventOperator *)job->stop_on->node.left;2826 TEST_ALLOC_SIZE (child, sizeof (EventOperator));
2941 TEST_EQ (oper->type, EVENT_MATCH);2827
2942 TEST_EQ_STR (oper->name, "wibble");2828 TEST_LIST_EMPTY (&child->children);
2943 TEST_EQ_P (oper->env, NULL);2829 TEST_EQ (child->type, EVENT_MATCH);
29442830 TEST_EQ_P (child->env, NULL);
2945 TEST_EQ_P (oper->node.parent, &job->stop_on->node);2831 if (!strncmp ("wibble", child->name, 7) && ! got_wibble) {
2946 TEST_EQ_P (oper->node.left, NULL);2832 got_wibble = TRUE;
2947 TEST_EQ_P (oper->node.right, NULL);2833 } else if (!strncmp ("wobble", child->name, 7) && ! got_wobble) {
29482834 got_wobble = TRUE;
2949 oper = (EventOperator *)job->stop_on->node.right;2835 } else if (!strncmp ("wiggle", child->name, 7) && ! got_wiggle) {
2950 TEST_EQ (oper->type, EVENT_OR);2836 got_wiggle = TRUE;
29512837 } else {
2952 TEST_EQ_P (oper->node.parent, &job->stop_on->node);2838 TEST_FAILED ("Unexpected child");
2953 TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator));2839 }
2954 TEST_ALLOC_PARENT (oper->node.left, oper);2840 }
2955 TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator));
2956 TEST_ALLOC_PARENT (oper->node.right, oper);
2957
2958 oper = (EventOperator *)job->stop_on->node.right->left;
2959 TEST_EQ (oper->type, EVENT_MATCH);
2960 TEST_EQ_STR (oper->name, "wobble");
2961 TEST_EQ_P (oper->env, NULL);
2962
2963 TEST_EQ_P (oper->node.parent, job->stop_on->node.right);
2964 TEST_EQ_P (oper->node.left, NULL);
2965 TEST_EQ_P (oper->node.right, NULL);
2966
2967 oper = (EventOperator *)job->stop_on->node.right->right;
2968 TEST_EQ (oper->type, EVENT_MATCH);
2969 TEST_EQ_STR (oper->name, "wiggle");
2970 TEST_EQ_P (oper->env, NULL);
2971
2972 TEST_EQ_P (oper->node.parent, job->stop_on->node.right);
2973 TEST_EQ_P (oper->node.left, NULL);
2974 TEST_EQ_P (oper->node.right, NULL);
29752841
2976 nih_free (job);2842 nih_free (job);
2977 }2843 }
@@ -3009,49 +2875,29 @@
3009 TEST_ALLOC_PARENT (job->stop_on, job);2875 TEST_ALLOC_PARENT (job->stop_on, job);
30102876
3011 oper = job->stop_on;2877 oper = job->stop_on;
3012 TEST_EQ (oper->type, EVENT_OR);2878 TEST_EQ (oper->type, EVENT_ANY);
30132879
3014 TEST_EQ_P (oper->node.parent, NULL);2880 got_wibble = FALSE;
3015 TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator));2881 got_wobble = FALSE;
3016 TEST_ALLOC_PARENT (oper->node.left, oper);2882 got_wiggle = FALSE;
3017 TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator));2883 NIH_LIST_FOREACH (&oper->children, iter) {
3018 TEST_ALLOC_PARENT (oper->node.right, oper);2884 EventOperator *child = (EventOperator *)iter;
30192885
3020 oper = (EventOperator *)job->stop_on->node.left;2886 TEST_ALLOC_SIZE (child, sizeof (EventOperator));
3021 TEST_EQ (oper->type, EVENT_MATCH);2887
3022 TEST_EQ_STR (oper->name, "wibble");2888 TEST_LIST_EMPTY (&child->children);
3023 TEST_EQ_P (oper->env, NULL);2889 TEST_EQ (child->type, EVENT_MATCH);
30242890 TEST_EQ_P (child->env, NULL);
3025 TEST_EQ_P (oper->node.parent, &job->stop_on->node);2891 if (!strncmp ("wibble", child->name, 7) && ! got_wibble) {
3026 TEST_EQ_P (oper->node.left, NULL);2892 got_wibble = TRUE;
3027 TEST_EQ_P (oper->node.right, NULL);2893 } else if (!strncmp ("wobble", child->name, 7) && ! got_wobble) {
30282894 got_wobble = TRUE;
3029 oper = (EventOperator *)job->stop_on->node.right;2895 } else if (!strncmp ("wiggle", child->name, 7) && ! got_wiggle) {
3030 TEST_EQ (oper->type, EVENT_OR);2896 got_wiggle = TRUE;
30312897 } else {
3032 TEST_EQ_P (oper->node.parent, &job->stop_on->node);2898 TEST_FAILED ("Unexpected child");
3033 TEST_ALLOC_SIZE (oper->node.left, sizeof (EventOperator));2899 }
3034 TEST_ALLOC_PARENT (oper->node.left, oper);2900 }
3035 TEST_ALLOC_SIZE (oper->node.right, sizeof (EventOperator));
3036 TEST_ALLOC_PARENT (oper->node.right, oper);
3037
3038 oper = (EventOperator *)job->stop_on->node.right->left;
3039 TEST_EQ (oper->type, EVENT_MATCH);
3040 TEST_EQ_STR (oper->name, "wobble");
3041 TEST_EQ_P (oper->env, NULL);
3042
3043 TEST_EQ_P (oper->node.parent, job->stop_on->node.right);
3044 TEST_EQ_P (oper->node.left, NULL);
3045 TEST_EQ_P (oper->node.right, NULL);
3046
3047 oper = (EventOperator *)job->stop_on->node.right->right;
3048 TEST_EQ (oper->type, EVENT_MATCH);
3049 TEST_EQ_STR (oper->name, "wiggle");
3050 TEST_EQ_P (oper->env, NULL);
3051
3052 TEST_EQ_P (oper->node.parent, job->stop_on->node.right);
3053 TEST_EQ_P (oper->node.left, NULL);
3054 TEST_EQ_P (oper->node.right, NULL);
30552901
3056 nih_free (job);2902 nih_free (job);
3057 }2903 }
@@ -3092,9 +2938,7 @@
3092 TEST_EQ_STR (oper->name, "waggle");2938 TEST_EQ_STR (oper->name, "waggle");
3093 TEST_EQ_P (oper->env, NULL);2939 TEST_EQ_P (oper->env, NULL);
30942940
3095 TEST_EQ_P (oper->node.parent, NULL);2941 TEST_LIST_EMPTY (&oper->children);
3096 TEST_EQ_P (oper->node.left, NULL);
3097 TEST_EQ_P (oper->node.right, NULL);
30982942
3099 nih_free (job);2943 nih_free (job);
3100 }2944 }

Subscribers

People subscribed via source and target branches