summaryrefslogtreecommitdiff
path: root/src/util/test_os_start_process.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-06-13 15:18:35 +0000
committerChristian Grothoff <christian@grothoff.org>2012-06-13 15:18:35 +0000
commit2742cca3d2180b4f615c40609fccf10a806f05c8 (patch)
tree7a59d0d43951cec4f0edd903f02ead3dbe037a2f /src/util/test_os_start_process.c
parent832d12049add37805697104b9f8eaae420eef406 (diff)
downloadgnunet-2742cca3d2180b4f615c40609fccf10a806f05c8.tar.gz
gnunet-2742cca3d2180b4f615c40609fccf10a806f05c8.zip
-cleaning up VERBOSE and check nonsense in util tests
Diffstat (limited to 'src/util/test_os_start_process.c')
-rw-r--r--src/util/test_os_start_process.c35
1 files changed, 16 insertions, 19 deletions
diff --git a/src/util/test_os_start_process.c b/src/util/test_os_start_process.c
index 0d1481857..5b9973250 100644
--- a/src/util/test_os_start_process.c
+++ b/src/util/test_os_start_process.c
@@ -33,21 +33,26 @@
33#include "gnunet_scheduler_lib.h" 33#include "gnunet_scheduler_lib.h"
34#include "disk.h" 34#include "disk.h"
35 35
36#define VERBOSE GNUNET_NO
37 36
38static char *test_phrase = "HELLO WORLD"; 37static const char *test_phrase = "HELLO WORLD";
38
39static int ok; 39static int ok;
40 40
41static struct GNUNET_OS_Process *proc; 41static struct GNUNET_OS_Process *proc;
42 42
43/* Pipe to write to started processes stdin (on write end) */ 43/**
44 * Pipe to write to started processes stdin (on write end)
45 */
44static struct GNUNET_DISK_PipeHandle *hello_pipe_stdin; 46static struct GNUNET_DISK_PipeHandle *hello_pipe_stdin;
45 47
46/* Pipe to read from started processes stdout (on read end) */ 48/**
49 * Pipe to read from started processes stdout (on read end)
50 */
47static struct GNUNET_DISK_PipeHandle *hello_pipe_stdout; 51static struct GNUNET_DISK_PipeHandle *hello_pipe_stdout;
48 52
49static GNUNET_SCHEDULER_TaskIdentifier die_task; 53static GNUNET_SCHEDULER_TaskIdentifier die_task;
50 54
55
51static void 56static void
52end_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 57end_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
53{ 58{
@@ -62,6 +67,7 @@ end_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
62 GNUNET_DISK_pipe_close (hello_pipe_stdin); 67 GNUNET_DISK_pipe_close (hello_pipe_stdin);
63} 68}
64 69
70
65static void 71static void
66read_call (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 72read_call (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
67{ 73{
@@ -73,9 +79,7 @@ read_call (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
73 79
74 bytes = GNUNET_DISK_file_read (stdout_read_handle, &buf, sizeof (buf)); 80 bytes = GNUNET_DISK_file_read (stdout_read_handle, &buf, sizeof (buf));
75 81
76#if VERBOSE 82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "bytes is %d\n", bytes);
77 FPRINTF (stderr, "bytes is %d\n", bytes);
78#endif
79 83
80 if (bytes < 1) 84 if (bytes < 1)
81 { 85 {
@@ -87,10 +91,8 @@ read_call (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
87 } 91 }
88 92
89 ok = strncmp (&buf[0], test_phrase, strlen (test_phrase)); 93 ok = strncmp (&buf[0], test_phrase, strlen (test_phrase));
90#if VERBOSE 94 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "read %s\n", &buf[0]);
91 FPRINTF (stderr, "read %s\n", &buf[0]); 95 if (0 == ok)
92#endif
93 if (ok == 0)
94 { 96 {
95 GNUNET_SCHEDULER_cancel (die_task); 97 GNUNET_SCHEDULER_cancel (die_task);
96 GNUNET_SCHEDULER_add_now (&end_task, NULL); 98 GNUNET_SCHEDULER_add_now (&end_task, NULL);
@@ -190,11 +192,9 @@ check_kill ()
190 proc = 192 proc =
191 GNUNET_OS_start_process (GNUNET_YES, hello_pipe_stdin, hello_pipe_stdout, "cat", 193 GNUNET_OS_start_process (GNUNET_YES, hello_pipe_stdin, hello_pipe_stdout, "cat",
192 "gnunet-service-resolver", "-", NULL); 194 "gnunet-service-resolver", "-", NULL);
193 sleep (1); /* give process time to start and open pipe */ 195 sleep (1); /* give process time to start, so we actually use the pipe-kill mechanism! */
194 if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) 196 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
195 {
196 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 197 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
197 }
198 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (proc)); 198 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (proc));
199 GNUNET_OS_process_destroy (proc); 199 GNUNET_OS_process_destroy (proc);
200 proc = NULL; 200 proc = NULL;
@@ -238,16 +238,13 @@ main (int argc, char *argv[])
238 int ret; 238 int ret;
239 239
240 GNUNET_log_setup ("test-os-start-process", 240 GNUNET_log_setup ("test-os-start-process",
241#if VERBOSE
242 "DEBUG",
243#else
244 "WARNING", 241 "WARNING",
245#endif
246 NULL); 242 NULL);
247 ret = 0; 243 ret = 0;
248 ret |= check_run (); 244 ret |= check_run ();
249 ret |= check_kill (); 245 ret |= check_kill ();
250 ret |= check_instant_kill (); 246 ret |= check_instant_kill ();
251
252 return ret; 247 return ret;
253} 248}
249
250/* end of test_os_start_process.c */