Merge lp:~jamesodhunt/upstart/fix-test_state-test into lp:upstart

Proposed by James Hunt
Status: Rejected
Rejected by: James Hunt
Proposed branch: lp:~jamesodhunt/upstart/fix-test_state-test
Merge into: lp:upstart
Diff against target: 144 lines (+66/-4)
4 files modified
ChangeLog (+8/-0)
init/tests/test_state.c (+21/-4)
test/test_util_common.c (+34/-0)
test/test_util_common.h (+3/-0)
To merge this branch: bzr merge lp:~jamesodhunt/upstart/fix-test_state-test
Reviewer Review Type Date Requested Status
Dimitri John Ledkov Needs Fixing
Review via email: mp+195031@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

timed_check() is essentially exec once in a lifetime, this is because: start_time & secs_to_wait are local static variables, which are set first time timed_check() is called & are never reset to 0, once the timing is complete.

Thus this is better to be done as a preprocessor macro.

So instead of timed_check(), would it be possible to use TEST_WATCH_UPDATE_TIMEOUT_SECS(secs) where TEST_FORCE_WATCH_UPDATE() was currently used?

Additional nih_io_watches asserts & init are all good.

ps. it looks like TEST_FORCE_WATCH_UPDATE_TIMEOUT_SECS & TEST_FORCE_WATCH_UPDATE_TIMEOUT are the same as TEST_FORCE_WATCH_UPDATE, since all three call _TEST_WATCH_UPDATE(1, timeout) and timeout is not used when force is 1.

pss. please note that select in _TEST_WATCH_UPDATE is rounded up, and in some cases ( when !have_timed_waitpid() ) it's rounded up to a hallarious value of 1 600 seconds or some such. (virtualised PPAs with acient XEN kernel / hyper visor)

review: Needs Fixing
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

Unmerged revisions

1570. By James Hunt

* init/tests/test_state.c: test_log_serialise():
  - Added extra checks on nih_io_watches.
  - Need to wait for logfile to be written to handle case where NIH
    encounters EAGAIN.
* test/test_util_common.c: Added timed_check() utility function.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2013-11-12 12:17:30 +0000
3+++ ChangeLog 2013-11-13 11:07:42 +0000
4@@ -1,3 +1,11 @@
5+2013-11-13 James Hunt <james.hunt@ubuntu.com>
6+
7+ * init/tests/test_state.c: test_log_serialise():
8+ - Added extra checks on nih_io_watches.
9+ - Need to wait for logfile to be written to handle case where NIH
10+ encounters EAGAIN.
11+ * test/test_util_common.c: Added timed_check() utility function.
12+
13 2013-11-12 James Hunt <james.hunt@ubuntu.com>
14
15 * extra/man/socket-event.7: PATH => SOCKET_PATH.
16
17=== modified file 'init/tests/test_state.c'
18--- init/tests/test_state.c 2013-10-24 12:35:33 +0000
19+++ init/tests/test_state.c 2013-11-13 11:07:42 +0000
20@@ -2048,12 +2048,15 @@
21 struct stat statbuf;
22 mode_t old_perms;
23 int status;
24+ int got;
25
26 conf_init ();
27+ nih_io_init ();
28 log_unflushed_init ();
29
30 TEST_TRUE (NIH_LIST_EMPTY (conf_sources));
31 TEST_TRUE (NIH_LIST_EMPTY (log_unflushed_files));
32+ TEST_TRUE (NIH_LIST_EMPTY (nih_io_watches));
33
34 TEST_GROUP ("Log serialisation and deserialisation");
35
36@@ -2067,6 +2070,7 @@
37
38 log = log_new (NULL, "/foo", pty_master, 0);
39 TEST_NE_P (log, NULL);
40+ TEST_FALSE (NIH_LIST_EMPTY (nih_io_watches));
41
42 json = log_serialise (log);
43 TEST_NE_P (json, NULL);
44@@ -2086,11 +2090,14 @@
45
46 TEST_FILENAME (filename);
47
48+ TEST_TRUE (NIH_LIST_EMPTY (nih_io_watches));
49+
50 TEST_EQ (openpty (&pty_master, &pty_slave, NULL, NULL, NULL), 0);
51
52 /* Provide a log file which is accessible initially */
53 log = log_new (NULL, filename, pty_master, 0);
54 TEST_NE_P (log, NULL);
55+ TEST_FALSE (NIH_LIST_EMPTY (nih_io_watches));
56
57 assert0 (pipe (fds));
58
59@@ -2131,10 +2138,19 @@
60 close (pty_slave);
61 close (fds[0]);
62
63- /* Slurp the childs initial output */
64- TEST_FORCE_WATCH_UPDATE ();
65-
66- TEST_EQ (stat (filename, &statbuf), 0);
67+ TEST_FALSE (NIH_LIST_EMPTY (nih_io_watches));
68+
69+ got = FALSE;
70+ while (timed_check (5)) {
71+ TEST_FORCE_WATCH_UPDATE ();
72+ if (! stat (filename, &statbuf)) {
73+ got = TRUE;
74+ break;
75+ }
76+ sleep (1);
77+ }
78+
79+ TEST_EQ (got, TRUE);
80
81 /* save */
82 old_perms = statbuf.st_mode;
83@@ -2181,6 +2197,7 @@
84
85 nih_free (log);
86 nih_free (new_log);
87+ TEST_TRUE (NIH_LIST_EMPTY (nih_io_watches));
88 TEST_EQ (unlink (filename), 0);
89
90 /*******************************/
91
92=== modified file 'test/test_util_common.c'
93--- test/test_util_common.c 2013-11-12 12:17:30 +0000
94+++ test/test_util_common.c 2013-11-13 11:07:42 +0000
95@@ -1002,3 +1002,37 @@
96
97 }
98 }
99+
100+/**
101+ * timed_check:
102+ * @secs: Seconds to run for.
103+ *
104+ * Return TRUE for @secs seconds. Place in a while loop to call a block
105+ * of code repeatedly for that duration (have the loop call sleep(3) to
106+ * avoid a busy wait!).
107+ *
108+ * Returns: TRUE whilst @secs timeout has not been reached, else FALSE.
109+ **/
110+int
111+timed_check (int secs)
112+{
113+ static time_t start_time = 0;
114+ static int secs_to_wait = 0;
115+ time_t now;
116+
117+ if (! secs)
118+ return FALSE;
119+
120+ if (! start_time)
121+ start_time = time (NULL);
122+
123+ if (! secs_to_wait)
124+ secs_to_wait = secs;
125+
126+ now = time (NULL);
127+
128+ if (now > (start_time + secs_to_wait))
129+ return FALSE;
130+
131+ return TRUE;
132+}
133
134=== modified file 'test/test_util_common.h'
135--- test/test_util_common.h 2013-11-12 12:17:30 +0000
136+++ test/test_util_common.h 2013-11-13 11:07:42 +0000
137@@ -756,4 +756,7 @@
138
139 void test_common_cleanup (void);
140
141+int timed_check (int secs)
142+ __attribute__ ((warn_unused_result));
143+
144 #endif /* TEST_UTIL_COMMON_H */

Subscribers

People subscribed via source and target branches