diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-03-09 11:57:32 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-03-09 11:57:32 +0000 |
commit | bc3e4df88fd50cfc0f4808201d5b6aedb6e4d55a (patch) | |
tree | 76dd8b97b5285d3d8d7c78e4e1830d6f8a7d3baa /src | |
parent | e7674a12b370168daa102ed69cb24e96b8ed251b (diff) | |
download | gnunet-bc3e4df88fd50cfc0f4808201d5b6aedb6e4d55a.tar.gz gnunet-bc3e4df88fd50cfc0f4808201d5b6aedb6e4d55a.zip |
-additional tests for process starts
Diffstat (limited to 'src')
-rw-r--r-- | src/util/os_priority.c | 2 | ||||
-rw-r--r-- | src/util/test_os_start_process.c | 73 |
2 files changed, 67 insertions, 8 deletions
diff --git a/src/util/os_priority.c b/src/util/os_priority.c index 7003abf02..641afa6d3 100644 --- a/src/util/os_priority.c +++ b/src/util/os_priority.c | |||
@@ -299,7 +299,7 @@ npipe_open (const char *fn, | |||
299 | } | 299 | } |
300 | if (-1 == fd) | 300 | if (-1 == fd) |
301 | { | 301 | { |
302 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 302 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
303 | (flags == GNUNET_DISK_OPEN_READ) | 303 | (flags == GNUNET_DISK_OPEN_READ) |
304 | ? _("Failed to open named pipe `%s' for reading: %s\n") | 304 | ? _("Failed to open named pipe `%s' for reading: %s\n") |
305 | : _("Failed to open named pipe `%s' for writing: %s\n"), | 305 | : _("Failed to open named pipe `%s' for writing: %s\n"), |
diff --git a/src/util/test_os_start_process.c b/src/util/test_os_start_process.c index 54638c12f..3bcd636d3 100644 --- a/src/util/test_os_start_process.c +++ b/src/util/test_os_start_process.c | |||
@@ -51,12 +51,11 @@ static GNUNET_SCHEDULER_TaskIdentifier die_task; | |||
51 | static void | 51 | static void |
52 | end_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 52 | end_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
53 | { | 53 | { |
54 | |||
55 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) | 54 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) |
56 | { | 55 | { |
57 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 56 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
58 | } | 57 | } |
59 | GNUNET_OS_process_wait (proc); | 58 | GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (proc)); |
60 | GNUNET_OS_process_close (proc); | 59 | GNUNET_OS_process_close (proc); |
61 | proc = NULL; | 60 | proc = NULL; |
62 | GNUNET_DISK_pipe_close (hello_pipe_stdout); | 61 | GNUNET_DISK_pipe_close (hello_pipe_stdout); |
@@ -106,7 +105,7 @@ read_call (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
106 | 105 | ||
107 | 106 | ||
108 | static void | 107 | static void |
109 | task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 108 | run_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
110 | { | 109 | { |
111 | char *fn; | 110 | char *fn; |
112 | const struct GNUNET_DISK_FileHandle *stdout_read_handle; | 111 | const struct GNUNET_DISK_FileHandle *stdout_read_handle; |
@@ -160,22 +159,79 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
160 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 159 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
161 | stdout_read_handle, &read_call, | 160 | stdout_read_handle, &read_call, |
162 | (void *) stdout_read_handle); | 161 | (void *) stdout_read_handle); |
163 | |||
164 | } | 162 | } |
165 | 163 | ||
164 | |||
166 | /** | 165 | /** |
167 | * Main method, starts scheduler with task1, | 166 | * Main method, starts scheduler with task1, |
168 | * checks that "ok" is correct at the end. | 167 | * checks that "ok" is correct at the end. |
169 | */ | 168 | */ |
170 | static int | 169 | static int |
171 | check () | 170 | check_run () |
172 | { | 171 | { |
173 | ok = 1; | 172 | ok = 1; |
174 | GNUNET_SCHEDULER_run (&task, &ok); | 173 | GNUNET_SCHEDULER_run (&run_task, &ok); |
175 | return ok; | 174 | return ok; |
176 | } | 175 | } |
177 | 176 | ||
178 | 177 | ||
178 | /** | ||
179 | * Test killing via pipe. | ||
180 | */ | ||
181 | static int | ||
182 | check_kill () | ||
183 | { | ||
184 | hello_pipe_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO); | ||
185 | hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES); | ||
186 | if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL)) | ||
187 | { | ||
188 | return 1; | ||
189 | } | ||
190 | proc = | ||
191 | GNUNET_OS_start_process (GNUNET_YES, hello_pipe_stdin, hello_pipe_stdout, "cat", | ||
192 | "gnunet-service-resolver", "-", NULL); | ||
193 | sleep (1); /* give process time to start and open pipe */ | ||
194 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) | ||
195 | { | ||
196 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
197 | } | ||
198 | GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (proc)); | ||
199 | GNUNET_OS_process_close (proc); | ||
200 | proc = NULL; | ||
201 | GNUNET_DISK_pipe_close (hello_pipe_stdout); | ||
202 | GNUNET_DISK_pipe_close (hello_pipe_stdin); | ||
203 | return 0; | ||
204 | } | ||
205 | |||
206 | |||
207 | /** | ||
208 | * Test killing via pipe. | ||
209 | */ | ||
210 | static int | ||
211 | check_instant_kill () | ||
212 | { | ||
213 | hello_pipe_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO); | ||
214 | hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES); | ||
215 | if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL)) | ||
216 | { | ||
217 | return 1; | ||
218 | } | ||
219 | proc = | ||
220 | GNUNET_OS_start_process (GNUNET_YES, hello_pipe_stdin, hello_pipe_stdout, "cat", | ||
221 | "gnunet-service-resolver", "-", NULL); | ||
222 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) | ||
223 | { | ||
224 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
225 | } | ||
226 | GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (proc)); | ||
227 | GNUNET_OS_process_close (proc); | ||
228 | proc = NULL; | ||
229 | GNUNET_DISK_pipe_close (hello_pipe_stdout); | ||
230 | GNUNET_DISK_pipe_close (hello_pipe_stdin); | ||
231 | return 0; | ||
232 | } | ||
233 | |||
234 | |||
179 | int | 235 | int |
180 | main (int argc, char *argv[]) | 236 | main (int argc, char *argv[]) |
181 | { | 237 | { |
@@ -188,7 +244,10 @@ main (int argc, char *argv[]) | |||
188 | "WARNING", | 244 | "WARNING", |
189 | #endif | 245 | #endif |
190 | NULL); | 246 | NULL); |
191 | ret = check (); | 247 | ret = 0; |
248 | ret |= check_run (); | ||
249 | ret |= check_kill (); | ||
250 | ret |= check_instant_kill (); | ||
192 | 251 | ||
193 | return ret; | 252 | return ret; |
194 | } | 253 | } |