Merge branch 'maint-0.2.9' into maint-0.3.3
[tor.git] / src / test / test-child.c
blobf78a829107f1e80b0f5848adfa464caf8734df71
1 /* Copyright (c) 2011-2017, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
4 #include "orconfig.h"
5 #include <stdio.h>
6 #ifdef _WIN32
7 #define WINDOWS_LEAN_AND_MEAN
8 #include <windows.h>
9 #else
10 #include <unistd.h>
11 #endif /* defined(_WIN32) */
12 #include <string.h>
14 #ifdef _WIN32
15 #define SLEEP(sec) Sleep((sec)*1000)
16 #else
17 #define SLEEP(sec) sleep(sec)
18 #endif
20 /** Trivial test program which prints out its command line arguments so we can
21 * check if tor_spawn_background() works */
22 int
23 main(int argc, char **argv)
25 int i;
26 int delay = 1;
27 int fast = 0;
29 if (argc > 1) {
30 if (!strcmp(argv[1], "--hang")) {
31 delay = 60;
32 } else if (!strcmp(argv[1], "--fast")) {
33 fast = 1;
34 delay = 0;
38 fprintf(stdout, "OUT\n");
39 fprintf(stderr, "ERR\n");
40 for (i = 1; i < argc; i++)
41 fprintf(stdout, "%s\n", argv[i]);
42 if (!fast)
43 fprintf(stdout, "SLEEPING\n");
44 /* We need to flush stdout so that test_util_spawn_background_partial_read()
45 succeed. Otherwise ReadFile() will get the entire output in one */
46 // XXX: Can we make stdio flush on newline?
47 fflush(stdout);
48 if (!fast)
49 SLEEP(1);
50 fprintf(stdout, "DONE\n");
51 fflush(stdout);
52 if (fast)
53 return 0;
55 while (--delay) {
56 SLEEP(1);
59 return 0;