Merge lp:~jamesodhunt/upstart/cleanup-test-xdg-dirs into lp:upstart
- cleanup-test-xdg-dirs
- Merge into trunk
Proposed by
James Hunt
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 1568 | ||||
Proposed branch: | lp:~jamesodhunt/upstart/cleanup-test-xdg-dirs | ||||
Merge into: | lp:upstart | ||||
Diff against target: |
776 lines (+249/-161) 9 files modified
ChangeLog (+23/-0) extra/man/socket-event.7 (+2/-2) init/Makefile.am (+8/-0) init/tests/test_main.c (+16/-48) init/tests/test_xdg.c (+18/-3) test/test_util_common.c (+153/-0) test/test_util_common.h (+11/-0) util/Makefile.am (+4/-0) util/tests/test_initctl.c (+14/-108) |
||||
To merge this branch: | bzr merge lp:~jamesodhunt/upstart/cleanup-test-xdg-dirs | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Upstart Reviewers | Pending | ||
Review via email: mp+194848@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Dimitri John Ledkov (xnox) wrote : | # |
Revision history for this message
Dimitri John Ledkov (xnox) wrote : | # |
previously we didn't unset DBUS_SYSTEM_
Revision history for this message
James Hunt (jamesodhunt) wrote : | # |
Actually, we do unset DBUS_SYSTEM_
Revision history for this message
James Hunt (jamesodhunt) wrote : | # |
Well, we reset it :)
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-07 03:35:14 +0000 |
3 | +++ ChangeLog 2013-11-12 12:19:03 +0000 |
4 | @@ -1,3 +1,26 @@ |
5 | +2013-11-12 James Hunt <james.hunt@ubuntu.com> |
6 | + |
7 | + * extra/man/socket-event.7: PATH => SOCKET_PATH. |
8 | + * init/Makefile.am: |
9 | + - Unset DBUS_SYSTEM_BUS_ADDRESS |
10 | + - Explain unsetting vars. |
11 | + - test_xdg: link to libtest_util_common. |
12 | + * init/tests/test_main.c: |
13 | + - Include config.h to avoid local NIH test run failure. |
14 | + - Remove test-specific XDG_CONFIG_HOME/XDG_RUNTIME_DIR handling and |
15 | + call test_common_setup() and test_common_cleanup() instead. |
16 | + * init/tests/test_xdg.c: Remove test-specific |
17 | + XDG_CONFIG_HOME/XDG_RUNTIME_DIR handling and call test_common_setup() |
18 | + and test_common_cleanup() instead. |
19 | + * test/test_util_common.c: Added test_common_setup() and |
20 | + test_common_cleanup(). |
21 | + * util/Makefile.am: |
22 | + - Unset DBUS_SYSTEM_BUS_ADDRESS |
23 | + - Explain unsetting vars. |
24 | + * util/tests/test_initctl.c: Remove test-specific |
25 | + XDG_CONFIG_HOME/XDG_RUNTIME_DIR handling and call test_common_setup() |
26 | + and test_common_cleanup() instead. |
27 | + |
28 | 2013-11-04 James Hunt <james.hunt@ubuntu.com> |
29 | |
30 | * test/test_util_common.h: WAIT_FOR_FILE(): Check @path not |
31 | |
32 | === modified file 'extra/man/socket-event.7' |
33 | --- extra/man/socket-event.7 2013-10-23 16:33:09 +0000 |
34 | +++ extra/man/socket-event.7 2013-11-12 12:19:03 +0000 |
35 | @@ -52,7 +52,7 @@ |
36 | .P |
37 | .RS |
38 | .nf |
39 | -start on socket PROTO=unix PATH=/var/run/.s.pgsql.1234 |
40 | +start on socket PROTO=unix SOCKET_PATH=/var/run/.s.pgsql.1234 |
41 | .fi |
42 | .RE |
43 | .\" |
44 | @@ -60,7 +60,7 @@ |
45 | .P |
46 | .RS |
47 | .nf |
48 | -start on socket PROTO=unix PATH=@/at/upstart/example |
49 | +start on socket PROTO=unix SOCKET_PATH=@/at/upstart/example |
50 | .fi |
51 | .RE |
52 | .\" |
53 | |
54 | === modified file 'init/Makefile.am' |
55 | --- init/Makefile.am 2013-11-11 16:15:52 +0000 |
56 | +++ init/Makefile.am 2013-11-12 12:19:03 +0000 |
57 | @@ -172,10 +172,14 @@ |
58 | LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver |
59 | endif |
60 | |
61 | +# Ensure a clean test environment (that will not touch the running users |
62 | +# one). Tests that need the variables listed below are expected to set |
63 | +# them to appropriate temporary values as needed. |
64 | AM_TESTS_ENVIRONMENT= \ |
65 | unset -v \ |
66 | XDG_RUNTIME_DIR \ |
67 | DBUS_SESSION_BUS_ADDRESS \ |
68 | + DBUS_SYSTEM_BUS_ADDRESS \ |
69 | UPSTART_SESSION \ |
70 | UPSTART_INSTANCE \ |
71 | UPSTART_EVENTS \ |
72 | @@ -408,6 +412,10 @@ |
73 | xdg.o \ |
74 | environ.o \ |
75 | $(NIH_LIBS) \ |
76 | + $(top_builddir)/test/libtest_util_common.a \ |
77 | + $(NIH_LIBS) \ |
78 | + $(NIH_DBUS_LIBS) \ |
79 | + $(DBUS_LIBS) \ |
80 | -lrt |
81 | |
82 | test_control_SOURCES = tests/test_control.c |
83 | |
84 | === modified file 'init/tests/test_main.c' |
85 | --- init/tests/test_main.c 2013-10-18 09:13:36 +0000 |
86 | +++ init/tests/test_main.c 2013-11-12 12:19:03 +0000 |
87 | @@ -19,6 +19,10 @@ |
88 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
89 | */ |
90 | |
91 | +#ifdef HAVE_CONFIG_H |
92 | +# include <config.h> |
93 | +#endif /* HAVE_CONFIG_H */ |
94 | + |
95 | #include <nih/string.h> |
96 | #include <nih/main.h> |
97 | #include <nih/test.h> |
98 | @@ -42,16 +46,14 @@ |
99 | { |
100 | char confdir_a[PATH_MAX]; |
101 | char confdir_b[PATH_MAX]; |
102 | - char xdg_config_home[PATH_MAX]; |
103 | - char xdg_runtime_dir[PATH_MAX]; |
104 | + char *xdg_config_home; |
105 | + char *xdg_runtime_dir; |
106 | char logdir[PATH_MAX]; |
107 | pid_t upstart_pid = 0; |
108 | pid_t dbus_pid = 0; |
109 | char **output; |
110 | size_t lines; |
111 | nih_local char *cmd = NULL; |
112 | - nih_local char *orig_xdg_config_home = NULL; |
113 | - nih_local char *orig_xdg_runtime_dir = NULL; |
114 | nih_local char *xdg_conf_dir = NULL; |
115 | nih_local char *session_file = NULL; |
116 | nih_local char *path = NULL; |
117 | @@ -59,6 +61,12 @@ |
118 | /* space for 2 sets of confdir options and a terminator */ |
119 | char *extra[5]; |
120 | |
121 | + xdg_config_home = getenv ("XDG_CONFIG_HOME"); |
122 | + TEST_NE_P (xdg_config_home, NULL); |
123 | + |
124 | + xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR"); |
125 | + TEST_NE_P (xdg_runtime_dir, NULL); |
126 | + |
127 | TEST_GROUP ("--confdir command-line option handling"); |
128 | |
129 | TEST_FILENAME (confdir_a); |
130 | @@ -67,12 +75,6 @@ |
131 | TEST_FILENAME (confdir_b); |
132 | assert0 (mkdir (confdir_b, 0755)); |
133 | |
134 | - TEST_FILENAME (xdg_config_home); |
135 | - assert0 (mkdir (xdg_config_home, 0755)); |
136 | - |
137 | - TEST_FILENAME (xdg_runtime_dir); |
138 | - assert0 (mkdir (xdg_runtime_dir, 0755)); |
139 | - |
140 | xdg_conf_dir = nih_sprintf (NULL, "%s/%s", xdg_config_home, "upstart"); |
141 | TEST_NE_P (xdg_conf_dir, NULL); |
142 | assert0 (mkdir (xdg_conf_dir, 0755)); |
143 | @@ -80,21 +82,6 @@ |
144 | TEST_FILENAME (logdir); |
145 | assert0 (mkdir (logdir, 0755)); |
146 | |
147 | - /* Take care to avoid disrupting users environment by saving and |
148 | - * restoring these variable (assuming the tests all pass...). |
149 | - */ |
150 | - orig_xdg_config_home = getenv ("XDG_CONFIG_HOME"); |
151 | - if (orig_xdg_config_home) |
152 | - orig_xdg_config_home = NIH_MUST (nih_strdup (NULL, orig_xdg_config_home)); |
153 | - |
154 | - assert0 (setenv ("XDG_CONFIG_HOME", xdg_config_home, 1)); |
155 | - |
156 | - orig_xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR"); |
157 | - if (orig_xdg_runtime_dir) |
158 | - orig_xdg_runtime_dir = NIH_MUST (nih_strdup (NULL, orig_xdg_runtime_dir)); |
159 | - |
160 | - assert0 (setenv ("XDG_RUNTIME_DIR", xdg_runtime_dir, 1)); |
161 | - |
162 | /* disable system default job dir */ |
163 | assert0 (setenv ("UPSTART_NO_SYSTEM_USERCONFDIR", "1", 1)); |
164 | |
165 | @@ -412,32 +399,9 @@ |
166 | |
167 | TEST_DBUS_END (dbus_pid); |
168 | |
169 | - if (orig_xdg_config_home) { |
170 | - /* restore */ |
171 | - setenv ("XDG_CONFIG_HOME", orig_xdg_config_home, 1); |
172 | - } else { |
173 | - assert0 (unsetenv ("XDG_CONFIG_HOME")); |
174 | - } |
175 | - |
176 | - if (orig_xdg_runtime_dir) { |
177 | - /* restore */ |
178 | - setenv ("XDG_RUNTIME_DIR", orig_xdg_runtime_dir, 1); |
179 | - } else { |
180 | - assert0 (unsetenv ("XDG_RUNTIME_DIR")); |
181 | - } |
182 | - |
183 | assert0 (rmdir (confdir_a)); |
184 | assert0 (rmdir (confdir_b)); |
185 | assert0 (rmdir (xdg_conf_dir)); |
186 | - assert0 (rmdir (xdg_config_home)); |
187 | - |
188 | - /* Remove the directory tree the first Session Init created */ |
189 | - path = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions", xdg_runtime_dir)); |
190 | - TEST_EQ (rmdir (path), 0); |
191 | - path = NIH_MUST (nih_sprintf (NULL, "%s/upstart", xdg_runtime_dir)); |
192 | - TEST_EQ (rmdir (path), 0); |
193 | - assert0 (rmdir (xdg_runtime_dir)); |
194 | - |
195 | assert0 (rmdir (logdir)); |
196 | assert0 (unsetenv ("UPSTART_CONFDIR")); |
197 | } |
198 | @@ -446,7 +410,11 @@ |
199 | main (int argc, |
200 | char *argv[]) |
201 | { |
202 | + test_common_setup (); |
203 | + |
204 | test_confdir (); |
205 | |
206 | + test_common_cleanup (); |
207 | + |
208 | return 0; |
209 | } |
210 | |
211 | === modified file 'init/tests/test_xdg.c' |
212 | --- init/tests/test_xdg.c 2013-01-25 09:59:44 +0000 |
213 | +++ init/tests/test_xdg.c 2013-11-12 12:19:03 +0000 |
214 | @@ -30,6 +30,8 @@ |
215 | |
216 | #include "xdg.h" |
217 | |
218 | +#include "test_util_common.h" |
219 | + |
220 | void |
221 | _test_dir_created (char * dirname) { |
222 | struct stat statbuf; |
223 | @@ -438,9 +440,12 @@ |
224 | void |
225 | test_get_session_dir (void) |
226 | { |
227 | - char dirname[PATH_MAX]; |
228 | - char *expected; |
229 | - char *path; |
230 | + char dirname[PATH_MAX]; |
231 | + char *expected; |
232 | + char *path; |
233 | + char *orig_xdg_runtime_dir; |
234 | + |
235 | + orig_xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR"); |
236 | |
237 | TEST_FUNCTION ("get_session_dir"); |
238 | |
239 | @@ -463,6 +468,9 @@ |
240 | } |
241 | } |
242 | |
243 | + if (orig_xdg_runtime_dir) |
244 | + setenv ("XDG_RUNTIME_DIR", orig_xdg_runtime_dir, 1); |
245 | + |
246 | TEST_FEATURE ("with XDG_RUNTIME_DIR unset"); |
247 | assert0 (unsetenv ("XDG_RUNTIME_DIR")); |
248 | |
249 | @@ -476,12 +484,17 @@ |
250 | rmdir (path); |
251 | nih_free (path); |
252 | rmdir (dirname); |
253 | + |
254 | + if (orig_xdg_runtime_dir) |
255 | + setenv ("XDG_RUNTIME_DIR", orig_xdg_runtime_dir, 1); |
256 | } |
257 | |
258 | int |
259 | main (int argc, |
260 | char *argv[]) |
261 | { |
262 | + test_common_setup (); |
263 | + |
264 | test_get_home_subdir (); |
265 | test_get_config_home (); |
266 | test_get_config_dirs (); |
267 | @@ -490,5 +503,7 @@ |
268 | test_get_user_log_dir (); |
269 | test_get_session_dir (); |
270 | |
271 | + test_common_cleanup (); |
272 | + |
273 | return 0; |
274 | } |
275 | |
276 | === modified file 'test/test_util_common.c' |
277 | --- test/test_util_common.c 2013-11-07 03:35:14 +0000 |
278 | +++ test/test_util_common.c 2013-11-12 12:19:03 +0000 |
279 | @@ -58,6 +58,18 @@ |
280 | #error unable to find initctl binary as INITCTL_BINARY not defined |
281 | #endif /* INITCTL_BINARY */ |
282 | |
283 | +static char *saved_xdg_config_home = NULL; |
284 | +static char *saved_xdg_runtime_dir = NULL; |
285 | +static char test_xdg_config_home[PATH_MAX]; |
286 | +static char test_xdg_runtime_dir[PATH_MAX]; |
287 | + |
288 | +/** |
289 | + * test_setup_called: |
290 | + * |
291 | + * Set to TRUE if test_setup() called. |
292 | + **/ |
293 | +static int test_setup_called = FALSE; |
294 | + |
295 | static void selfpipe_write (int n); |
296 | static void selfpipe_setup (void); |
297 | |
298 | @@ -849,3 +861,144 @@ |
299 | |
300 | return ! stat (path, &st); |
301 | } |
302 | + |
303 | +/** |
304 | + * test_common_setup: |
305 | + * |
306 | + * Perform test setup. |
307 | + * |
308 | + * Currently, only needed for those tests which require unique xdg |
309 | + * directories. |
310 | + * |
311 | + * If called, test must call test_common_cleanup() to cleanup. |
312 | + **/ |
313 | +void |
314 | +test_common_setup (void) |
315 | +{ |
316 | + char *xdg_config_home; |
317 | + char *xdg_runtime_dir; |
318 | + |
319 | + /* Take care to avoid disrupting users environment by saving and |
320 | + * restoring these variable (assuming the tests all pass...). |
321 | + */ |
322 | + |
323 | + xdg_config_home = getenv ("XDG_CONFIG_HOME"); |
324 | + if (xdg_config_home) { |
325 | + nih_info ("Existing XDG_CONFIG_HOME found ('%s') - " |
326 | + "saving for later restore", |
327 | + xdg_config_home); |
328 | + |
329 | + saved_xdg_config_home = NIH_MUST (nih_strdup (NULL, xdg_config_home)); |
330 | + } |
331 | + |
332 | + TEST_FILENAME (test_xdg_config_home); |
333 | + assert0 (mkdir (test_xdg_config_home, TEST_DIR_MODE)); |
334 | + assert0 (setenv ("XDG_CONFIG_HOME", test_xdg_config_home, 1)); |
335 | + |
336 | + nih_info ("Using test XDG_CONFIG_HOME='%s'", test_xdg_config_home); |
337 | + |
338 | + xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR"); |
339 | + if (xdg_runtime_dir) { |
340 | + nih_info ("Existing XDG_RUNTIME_DIR found ('%s') - " |
341 | + "saving for later restore", |
342 | + xdg_runtime_dir); |
343 | + |
344 | + saved_xdg_runtime_dir = NIH_MUST (nih_strdup (NULL, xdg_runtime_dir)); |
345 | + } |
346 | + |
347 | + TEST_FILENAME (test_xdg_runtime_dir); |
348 | + assert0 (mkdir (test_xdg_runtime_dir, TEST_DIR_MODE)); |
349 | + assert0 (setenv ("XDG_RUNTIME_DIR", test_xdg_runtime_dir, 1)); |
350 | + |
351 | + nih_info ("Using test XDG_RUNTIME_DIR='%s'", test_xdg_runtime_dir); |
352 | + |
353 | + test_setup_called = TRUE; |
354 | +} |
355 | + |
356 | +/** |
357 | + * test_common_cleanup: |
358 | + * |
359 | + * Perform cleanup of test setup. |
360 | + * |
361 | + * Currently, only needed for those tests which require unique xdg |
362 | + * directories. |
363 | + * |
364 | + * If called, test must already have called test_common_setup(). |
365 | + **/ |
366 | +void |
367 | +test_common_cleanup (void) |
368 | +{ |
369 | + nih_local char *path = NULL; |
370 | + char *xdg_config_home; |
371 | + char *xdg_runtime_dir; |
372 | + struct stat statbuf; |
373 | + |
374 | + if (! test_setup_called) { |
375 | + nih_error ("BUG: Called %s without first calling %s", |
376 | + __func__, "test_common_setup()"); |
377 | + abort (); |
378 | + } |
379 | + |
380 | + xdg_config_home = getenv ("XDG_CONFIG_HOME"); |
381 | + xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR"); |
382 | + |
383 | + if (saved_xdg_config_home) { |
384 | + nih_assert (test_xdg_config_home[0]); |
385 | + TEST_EQ_STR (test_xdg_config_home, xdg_config_home); |
386 | + |
387 | + if (stat (test_xdg_config_home, &statbuf)) { |
388 | + nih_error ("A test has removed XDG_CONFIG_HOME '%s'", test_xdg_config_home); |
389 | + abort (); |
390 | + } |
391 | + |
392 | + if (! S_ISDIR (statbuf.st_mode)) { |
393 | + nih_error ("XDG_CONFIG_HOME '%s' no longer a directory", test_xdg_config_home); |
394 | + abort (); |
395 | + } |
396 | + |
397 | + assert0 (rmdir (test_xdg_config_home)); |
398 | + |
399 | + assert0 (setenv ("XDG_CONFIG_HOME", saved_xdg_config_home, 1)); |
400 | + nih_info ("Restoring XDG_RUNTIME_DIR='%s'", saved_xdg_config_home); |
401 | + nih_free (saved_xdg_config_home); |
402 | + saved_xdg_config_home = NULL; |
403 | + } |
404 | + |
405 | + if (saved_xdg_runtime_dir) { |
406 | + nih_assert (test_xdg_runtime_dir[0]); |
407 | + TEST_EQ_STR (test_xdg_runtime_dir, xdg_runtime_dir); |
408 | + |
409 | + if (stat (test_xdg_runtime_dir, &statbuf)) { |
410 | + nih_error ("A test has removed XDG_RUNTIME_DIR '%s'", test_xdg_runtime_dir); |
411 | + abort (); |
412 | + } |
413 | + |
414 | + if (! S_ISDIR (statbuf.st_mode)) { |
415 | + nih_error ("XDG_RUNTIME_DIR '%s' no longer a directory", test_xdg_runtime_dir); |
416 | + abort (); |
417 | + } |
418 | + |
419 | + path = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions", xdg_runtime_dir)); |
420 | + |
421 | + if (! stat (path, &statbuf)) { |
422 | + nih_local char *cmd = NULL; |
423 | + |
424 | + /* Clean up if tests forgot to */ |
425 | + cmd = NIH_MUST (nih_sprintf (NULL, "rm %s/*.session 2>/dev/null", path)); |
426 | + system (cmd); |
427 | + |
428 | + /* Remove the directory tree the first Session Init created */ |
429 | + assert0 (rmdir (path)); |
430 | + path = NIH_MUST (nih_sprintf (NULL, "%s/upstart", xdg_runtime_dir)); |
431 | + assert0 (rmdir (path)); |
432 | + } |
433 | + |
434 | + assert0 (rmdir (test_xdg_runtime_dir)); |
435 | + |
436 | + assert0 (setenv ("XDG_RUNTIME_DIR", saved_xdg_runtime_dir, 1)); |
437 | + nih_info ("Restoring XDG_RUNTIME_DIR='%s'", saved_xdg_config_home); |
438 | + nih_free (saved_xdg_runtime_dir); |
439 | + saved_xdg_runtime_dir = NULL; |
440 | + |
441 | + } |
442 | +} |
443 | |
444 | === modified file 'test/test_util_common.h' |
445 | --- test/test_util_common.h 2013-11-07 03:35:14 +0000 |
446 | +++ test/test_util_common.h 2013-11-12 12:19:03 +0000 |
447 | @@ -7,6 +7,13 @@ |
448 | |
449 | #include <nih-dbus/test_dbus.h> |
450 | |
451 | +/** |
452 | + * TEST_DIR_MODE: |
453 | + * |
454 | + * Mode to use when creating test directories. |
455 | + **/ |
456 | +#define TEST_DIR_MODE 0750 |
457 | + |
458 | #define BUFFER_SIZE 1024 |
459 | |
460 | /** |
461 | @@ -745,4 +752,8 @@ |
462 | int file_exists (const char *path) |
463 | __attribute__ ((warn_unused_result)); |
464 | |
465 | +void test_common_setup (void); |
466 | + |
467 | +void test_common_cleanup (void); |
468 | + |
469 | #endif /* TEST_UTIL_COMMON_H */ |
470 | |
471 | === modified file 'util/Makefile.am' |
472 | --- util/Makefile.am 2013-11-11 16:15:52 +0000 |
473 | +++ util/Makefile.am 2013-11-12 12:19:03 +0000 |
474 | @@ -182,10 +182,14 @@ |
475 | rm -f "$(DESTDIR)$(sbindir)/$$file"; \ |
476 | done |
477 | |
478 | +# Ensure a clean test environment (that will not touch the running users |
479 | +# one). Tests that need the variables listed below are expected to set |
480 | +# them to appropriate temporary values as needed. |
481 | AM_TESTS_ENVIRONMENT= \ |
482 | unset -v \ |
483 | XDG_RUNTIME_DIR \ |
484 | DBUS_SESSION_BUS_ADDRESS \ |
485 | + DBUS_SYSTEM_BUS_ADDRESS \ |
486 | UPSTART_SESSION \ |
487 | UPSTART_INSTANCE \ |
488 | UPSTART_EVENTS \ |
489 | |
490 | === modified file 'util/tests/test_initctl.c' |
491 | --- util/tests/test_initctl.c 2013-11-11 10:13:08 +0000 |
492 | +++ util/tests/test_initctl.c 2013-11-12 12:19:03 +0000 |
493 | @@ -10988,16 +10988,11 @@ |
494 | TEST_EQ (unsetenv ("UPSTART_CONFDIR"), 0); |
495 | TEST_EQ (unsetenv ("UPSTART_LOGDIR"), 0); |
496 | |
497 | - |
498 | - if (! getenv ("XDG_RUNTIME_DIR")) { |
499 | - TEST_GROUP ("set-env rexec # TODO fails without XDG_RUNTIME_DIR set"); |
500 | - TEST_FAILED (); |
501 | - return; |
502 | - } else { |
503 | - |
504 | /*******************************************************************/ |
505 | TEST_FEATURE ("ensure 'set-env' persists across session-init re-exec"); |
506 | |
507 | + TEST_TRUE (getenv ("XDG_RUNTIME_DIR")); |
508 | + |
509 | contents = nih_sprintf (NULL, |
510 | "start on startup\n" |
511 | "\n" |
512 | @@ -11056,8 +11051,6 @@ |
513 | assert0 (unlink (logfile)); |
514 | DELETE_FILE (confdir, "foo.conf"); |
515 | |
516 | - } |
517 | - |
518 | /*******************************************************************/ |
519 | TEST_FEATURE ("ensure 'set-env --global' persists across session-init re-exec"); |
520 | |
521 | @@ -11114,7 +11107,6 @@ |
522 | nih_local char *session_file = NULL; |
523 | nih_local char *path = NULL; |
524 | nih_local char *expected = NULL; |
525 | - nih_local char *orig_xdg_runtime_dir = NULL; |
526 | size_t len; |
527 | char *value; |
528 | |
529 | @@ -11126,13 +11118,6 @@ |
530 | TEST_FILENAME (confdir); |
531 | TEST_EQ (mkdir (confdir, 0755), 0); |
532 | |
533 | - /* Take care to avoid disrupting users environment by saving and |
534 | - * restoring this variable (assuming the tests all pass...). |
535 | - */ |
536 | - orig_xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR"); |
537 | - if (orig_xdg_runtime_dir) |
538 | - orig_xdg_runtime_dir = NIH_MUST (nih_strdup (NULL, orig_xdg_runtime_dir)); |
539 | - |
540 | /*******************************************************************/ |
541 | TEST_FEATURE ("with no instances and XDG_RUNTIME_DIR unset"); |
542 | |
543 | @@ -11210,13 +11195,6 @@ |
544 | |
545 | /*******************************************************************/ |
546 | |
547 | - if (orig_xdg_runtime_dir) { |
548 | - /* restore */ |
549 | - setenv ("XDG_RUNTIME_DIR", orig_xdg_runtime_dir, 1); |
550 | - } else { |
551 | - assert0 (unsetenv ("XDG_RUNTIME_DIR")); |
552 | - } |
553 | - |
554 | assert0 (unsetenv ("UPSTART_CONFDIR")); |
555 | |
556 | TEST_EQ (rmdir (dirname), 0); |
557 | @@ -11302,7 +11280,6 @@ |
558 | char **output; |
559 | size_t lines; |
560 | nih_local NihDBusProxy *upstart = NULL; |
561 | - nih_local char *orig_xdg_runtime_dir = NULL; |
562 | nih_local char *session_file = NULL; |
563 | nih_local char *job = NULL; |
564 | pid_t job_pid; |
565 | @@ -11318,13 +11295,6 @@ |
566 | TEST_FILENAME (sessiondir); |
567 | TEST_EQ (mkdir (sessiondir, 0755), 0); |
568 | |
569 | - /* Take care to avoid disrupting users environment by saving and |
570 | - * restoring this variable (assuming the tests all pass...). |
571 | - */ |
572 | - orig_xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR"); |
573 | - if (orig_xdg_runtime_dir) |
574 | - orig_xdg_runtime_dir = NIH_MUST (nih_strdup (NULL, orig_xdg_runtime_dir)); |
575 | - |
576 | /* Use the "secret" interface */ |
577 | TEST_EQ (setenv ("UPSTART_CONFDIR", confdir, 1), 0); |
578 | TEST_EQ (setenv ("UPSTART_LOGDIR", logdir, 1), 0); |
579 | @@ -12054,13 +12024,6 @@ |
580 | assert0 (unsetenv ("UPSTART_CONFDIR")); |
581 | assert0 (unsetenv ("UPSTART_LOGDIR")); |
582 | |
583 | - if (orig_xdg_runtime_dir) { |
584 | - /* restore */ |
585 | - setenv ("XDG_RUNTIME_DIR", orig_xdg_runtime_dir, 1); |
586 | - } else { |
587 | - assert0 (unsetenv ("XDG_RUNTIME_DIR")); |
588 | - } |
589 | - |
590 | TEST_EQ (rmdir (logdir), 0); |
591 | TEST_EQ (rmdir (confdir), 0); |
592 | |
593 | @@ -12078,7 +12041,6 @@ |
594 | { |
595 | char confdir[PATH_MAX]; |
596 | char dirname[PATH_MAX]; |
597 | - nih_local char *orig_xdg_runtime_dir = NULL; |
598 | char logdir[PATH_MAX]; |
599 | pid_t upstart_pid = 0; |
600 | nih_local char *logfile = NULL; |
601 | @@ -12090,14 +12052,6 @@ |
602 | mode_t test_umask = 0077; |
603 | mode_t default_umask = 022; |
604 | |
605 | - |
606 | - /* Take care to avoid disrupting users environment by saving and |
607 | - * restoring this variable (assuming the tests all pass...). |
608 | - */ |
609 | - orig_xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR"); |
610 | - if (orig_xdg_runtime_dir) |
611 | - orig_xdg_runtime_dir = NIH_MUST (nih_strdup (NULL, orig_xdg_runtime_dir)); |
612 | - |
613 | TEST_FILENAME (dirname); |
614 | TEST_EQ (mkdir (dirname, 0755), 0); |
615 | TEST_EQ (setenv ("XDG_RUNTIME_DIR", dirname, 1), 0); |
616 | @@ -12176,13 +12130,6 @@ |
617 | /* Restore */ |
618 | (void)umask (original_umask); |
619 | |
620 | - if (orig_xdg_runtime_dir) { |
621 | - /* restore */ |
622 | - setenv ("XDG_RUNTIME_DIR", orig_xdg_runtime_dir, 1); |
623 | - } else { |
624 | - assert0 (unsetenv ("XDG_RUNTIME_DIR")); |
625 | - } |
626 | - |
627 | assert0 (rmdir (confdir)); |
628 | assert0 (rmdir (logdir)); |
629 | } |
630 | @@ -15794,11 +15741,7 @@ |
631 | char *args[2]; |
632 | int ret = 0; |
633 | |
634 | - if (! getenv ("XDG_RUNTIME_DIR")) { |
635 | - TEST_GROUP ("usage # TODO fails without XDG_RUNTIME_DIR set"); |
636 | - TEST_FAILED (); |
637 | - return; |
638 | - } |
639 | + TEST_TRUE (getenv ("XDG_RUNTIME_DIR")); |
640 | |
641 | TEST_GROUP ("usage"); |
642 | |
643 | @@ -16870,15 +16813,17 @@ |
644 | { |
645 | char confdir[PATH_MAX]; |
646 | char logdir[PATH_MAX]; |
647 | - char runtimedir[PATH_MAX]; |
648 | size_t lines; |
649 | pid_t dbus_pid = 0; |
650 | pid_t upstart_pid = 0; |
651 | char *value; |
652 | - nih_local char *orig_xdg_runtime_dir = NULL; |
653 | nih_local char *cmd = NULL; |
654 | char **output; |
655 | nih_local char *session_file = NULL; |
656 | + char *xdg_runtime_dir; |
657 | + |
658 | + xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR"); |
659 | + TEST_TRUE (xdg_runtime_dir); |
660 | |
661 | TEST_GROUP ("job process table commands"); |
662 | |
663 | @@ -16888,22 +16833,10 @@ |
664 | TEST_FILENAME (logdir); |
665 | TEST_EQ (mkdir (logdir, 0755), 0); |
666 | |
667 | - TEST_FILENAME (runtimedir); |
668 | - TEST_EQ (mkdir (runtimedir, 0755), 0); |
669 | - |
670 | /* Use the "secret" interface */ |
671 | TEST_EQ (setenv ("UPSTART_CONFDIR", confdir, 1), 0); |
672 | TEST_EQ (setenv ("UPSTART_LOGDIR", logdir, 1), 0); |
673 | |
674 | - /* Take care to avoid disrupting users environment by saving and |
675 | - * restoring this variable (assuming the tests all pass...). |
676 | - */ |
677 | - orig_xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR"); |
678 | - if (orig_xdg_runtime_dir) |
679 | - orig_xdg_runtime_dir = NIH_MUST (nih_strdup (NULL, orig_xdg_runtime_dir)); |
680 | - |
681 | - TEST_EQ (setenv ("XDG_RUNTIME_DIR", runtimedir, 1), 0); |
682 | - |
683 | /*******************************************************************/ |
684 | /* Ensure basic variables are set in the current environment */ |
685 | |
686 | @@ -16954,12 +16887,12 @@ |
687 | |
688 | STOP_UPSTART (upstart_pid); |
689 | session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions/%d.session", |
690 | - runtimedir, (int)upstart_pid)); |
691 | + xdg_runtime_dir, (int)upstart_pid)); |
692 | unlink (session_file); |
693 | |
694 | /*******************************************************************/ |
695 | |
696 | - test_no_inherit_job_env (runtimedir, confdir, logdir); |
697 | + test_no_inherit_job_env (xdg_runtime_dir, confdir, logdir); |
698 | |
699 | /*******************************************************************/ |
700 | |
701 | @@ -16968,19 +16901,6 @@ |
702 | assert0 (unsetenv ("UPSTART_LOGDIR")); |
703 | assert0 (unsetenv ("UPSTART_SESSION")); |
704 | |
705 | - session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions", runtimedir)); |
706 | - TEST_EQ (rmdir (session_file), 0); |
707 | - session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart", runtimedir)); |
708 | - TEST_EQ (rmdir (session_file), 0); |
709 | - TEST_EQ (rmdir (runtimedir), 0); |
710 | - |
711 | - if (orig_xdg_runtime_dir) { |
712 | - /* restore */ |
713 | - setenv ("XDG_RUNTIME_DIR", orig_xdg_runtime_dir, 1); |
714 | - } else { |
715 | - assert0 (unsetenv ("XDG_RUNTIME_DIR")); |
716 | - } |
717 | - |
718 | TEST_EQ (rmdir (confdir), 0); |
719 | TEST_EQ (rmdir (logdir), 0); |
720 | } |
721 | @@ -16994,22 +16914,12 @@ |
722 | pid_t upstart_pid = 0; |
723 | nih_local char *cmd = NULL; |
724 | char **output; |
725 | - nih_local char *orig_xdg_runtime_dir = NULL; |
726 | nih_local char *dbus_session_address = NULL; |
727 | nih_local char *dbus_session_address2 = NULL; |
728 | nih_local char *upstart_session = NULL; |
729 | char *address; |
730 | - char dirname[PATH_MAX]; |
731 | |
732 | - /* Take care to avoid disrupting users environment by saving and |
733 | - * restoring this variable (assuming the tests all pass...). |
734 | - */ |
735 | - orig_xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR"); |
736 | - if (orig_xdg_runtime_dir) |
737 | - orig_xdg_runtime_dir = NIH_MUST (nih_strdup (NULL, orig_xdg_runtime_dir)); |
738 | - TEST_FILENAME (dirname); |
739 | - TEST_EQ (mkdir (dirname, 0755), 0); |
740 | - TEST_EQ (setenv ("XDG_RUNTIME_DIR", dirname, 1), 0); |
741 | + TEST_TRUE (getenv ("XDG_RUNTIME_DIR")); |
742 | |
743 | TEST_GROUP ("D-Bus connection"); |
744 | |
745 | @@ -17204,14 +17114,6 @@ |
746 | |
747 | /* Stop the 2nd daemon */ |
748 | TEST_DBUS_END (dbus_pid2); |
749 | - |
750 | - /* Restore */ |
751 | - if (orig_xdg_runtime_dir) { |
752 | - /* restore */ |
753 | - setenv ("XDG_RUNTIME_DIR", orig_xdg_runtime_dir, 1); |
754 | - } else { |
755 | - assert0 (unsetenv ("XDG_RUNTIME_DIR")); |
756 | - } |
757 | } |
758 | |
759 | int |
760 | @@ -17225,6 +17127,8 @@ |
761 | nih_main_loop_init (); |
762 | program_name = "test"; |
763 | |
764 | + test_common_setup (); |
765 | + |
766 | test_upstart_open (); |
767 | test_job_status (); |
768 | |
769 | @@ -17269,5 +17173,7 @@ |
770 | |
771 | test_dbus_connection (); |
772 | |
773 | + test_common_cleanup (); |
774 | + |
775 | return 0; |
776 | } |
test_util_common.c: In function ‘test_common_ cleanup’ : common. c:988:11: warning: ignoring return value of ‘system’, declared with attribute warn_unused_result [-Wunused-result]
test_util_
system (cmd);