aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/structure.dot2
-rw-r--r--po/POTFILES.in4
-rw-r--r--src/testing/gnunet-testing-run-service.c166
3 files changed, 98 insertions, 74 deletions
diff --git a/doc/structure.dot b/doc/structure.dot
index d3b2c0cc9..f7f0ac451 100644
--- a/doc/structure.dot
+++ b/doc/structure.dot
@@ -36,7 +36,7 @@ splines = true;
36// psycd -> mesh [style=dashed]; 36// psycd -> mesh [style=dashed];
37 stream [shape=diamond]; 37 stream [shape=diamond];
38 stream -> mesh; 38 stream -> mesh;
39 stream -> lockmanager; 39 stream -> lockmanager [style=dashed];
40 dht -> core; 40 dht -> core;
41 dht -> nse; 41 dht -> nse;
42 dht -> block; 42 dht -> block;
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 9c02b90fc..4b22465b8 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -105,7 +105,6 @@ src/gns/gnocksy/gns_glue.c
105src/gns/gns_api.c 105src/gns/gns_api.c
106src/gns/gnunet-gns.c 106src/gns/gnunet-gns.c
107src/gns/gnunet-gns-fcfsd.c 107src/gns/gnunet-gns-fcfsd.c
108src/gns/gnunet-gns-lookup.c
109src/gns/gnunet-gns-proxy.c 108src/gns/gnunet-gns-proxy.c
110src/gns/gnunet-service-gns.c 109src/gns/gnunet-service-gns.c
111src/gns/gnunet-service-gns_interceptor.c 110src/gns/gnunet-service-gns_interceptor.c
@@ -131,6 +130,7 @@ src/namestore/gnunet-namestore.c
131src/namestore/gnunet-service-namestore.c 130src/namestore/gnunet-service-namestore.c
132src/namestore/namestore_api.c 131src/namestore/namestore_api.c
133src/namestore/namestore_common.c 132src/namestore/namestore_common.c
133src/namestore/plugin_namestore_postgres.c
134src/namestore/plugin_namestore_sqlite.c 134src/namestore/plugin_namestore_sqlite.c
135src/nat/gnunet-helper-nat-client.c 135src/nat/gnunet-helper-nat-client.c
136src/nat/gnunet-helper-nat-client-windows.c 136src/nat/gnunet-helper-nat-client-windows.c
@@ -157,6 +157,7 @@ src/statistics/statistics_api.c
157src/stream/stream_api.c 157src/stream/stream_api.c
158src/template/gnunet-service-template.c 158src/template/gnunet-service-template.c
159src/template/gnunet-template.c 159src/template/gnunet-template.c
160src/testbed/gnunet-service-testbed.c
160src/testbed/testbed_api.c 161src/testbed/testbed_api.c
161src/testbed/testbed_api_hosts.c 162src/testbed/testbed_api_hosts.c
162src/testbed/testbed_api_operations.c 163src/testbed/testbed_api_operations.c
@@ -165,6 +166,7 @@ src/testbed/testbed_api_services.c
165src/testbed/testbed_api_testbed.c 166src/testbed/testbed_api_testbed.c
166src/testbed/testbed_api_test.c 167src/testbed/testbed_api_test.c
167src/testbed/testbed_api_topology.c 168src/testbed/testbed_api_topology.c
169src/testing/gnunet-testing-run-service.c
168src/testing_old/gnunet-testing.c 170src/testing_old/gnunet-testing.c
169src/testing_old/helper.c 171src/testing_old/helper.c
170src/testing_old/testing.c 172src/testing_old/testing.c
diff --git a/src/testing/gnunet-testing-run-service.c b/src/testing/gnunet-testing-run-service.c
index c9e115260..fa98e1a6c 100644
--- a/src/testing/gnunet-testing-run-service.c
+++ b/src/testing/gnunet-testing-run-service.c
@@ -44,109 +44,134 @@
44#include "gnunet_os_lib.h" 44#include "gnunet_os_lib.h"
45 45
46 46
47static struct GNUNET_DISK_FileHandle fh; 47#define LOG(kind,...) \
48static char *tmpfilename = NULL; 48 GNUNET_log_from (kind, "gnunet-testing", __VA_ARGS__)
49static GNUNET_SCHEDULER_TaskIdentifier tid = GNUNET_SCHEDULER_NO_TASK; 49
50static struct GNUNET_TESTING_Peer *my_peer = NULL; 50
51/**
52 * FIXME
53 */
54static struct GNUNET_DISK_FileHandle *fh;
55
56/**
57 * FIXME
58 */
59static char *tmpfilename;
60
61/**
62 * FIXME
63 */
64static GNUNET_SCHEDULER_TaskIdentifier tid;
65
66/**
67 * FIXME
68 */
69static struct GNUNET_TESTING_Peer *my_peer;
51 70
52 71
53#define LOG(kind,...) \
54 GNUNET_log_from (kind, "gnunettestingnew", __VA_ARGS__)
55 72
56 73
57/** 74/**
58 * Cleanup called by signal handlers and when stdin is closed. 75 * Cleanup called by signal handlers and when stdin is closed.
59 * Removes the temporary file with the configuration and shuts down the scheduler. 76 * Removes the temporary file.
77 *
78 * @param cls unused
79 * @param tc scheduler context
60 */ 80 */
61void 81static void
62cleanup (void) 82cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
63{ 83{
64 if (NULL != tmpfilename) 84 if (NULL != tmpfilename)
65 { 85 {
66 remove (tmpfilename); 86 if (0 != UNLINK (tmpfilename))
87 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", tmpfilename);
88 }
89 if (GNUNET_SCHEDULER_NO_TASK != tid)
90 {
91 GNUNET_SCHEDULER_cancel (tid);
92 tid = GNUNET_SCHEDULER_NO_TASK;
93 }
94 if (NULL != fh)
95 {
96 GNUNET_DISK_file_close (fh);
97 fh = NULL;
67 } 98 }
68 GNUNET_SCHEDULER_shutdown ();
69} 99}
70 100
101
71/** 102/**
72 * Called whenever we can read stdin non-blocking 103 * Called whenever we can read stdin non-blocking
104 *
105 * @param cls unused
106 * @param tc scheduler context
73 */ 107 */
74void 108static void
75stdin_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 109stdin_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
76{ 110{
77 int c; 111 int c;
78 112
79 if (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) 113 tid = GNUNET_SCHEDULER_NO_TASK;
80 { 114 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
81 return; 115 return;
82 } 116 GNUNET_assert (0 != (GNUNET_SCHEDULER_REASON_READ_READY & tc->reason));
83 if (GNUNET_SCHEDULER_REASON_READ_READY & tc->reason) 117 c = getchar ();
118 switch (c)
84 { 119 {
85 c = getchar (); 120 case EOF:
86 if (EOF == c || 'q' == c) 121 case 'q':
87 { 122 GNUNET_SCHEDULER_shutdown ();
88 tid = GNUNET_SCHEDULER_NO_TASK;
89 cleanup ();
90 }
91 else
92 {
93 if ('r' == c)
94 {
95 GNUNET_TESTING_peer_stop(my_peer);
96 GNUNET_TESTING_peer_start(my_peer);
97 printf("restarted\n");
98 fflush(stdout);
99 }
100 tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, &fh, &stdin_cb, NULL);
101 }
102 return; 123 return;
124 case 'r':
125 GNUNET_TESTING_peer_stop (my_peer);
126 GNUNET_TESTING_peer_start (my_peer);
127 printf ("restarted\n");
128 fflush (stdout);
129 break;
130 case '\n':
131 case '\r':
132 /* ignore whitespace */
133 break;
134 default:
135 fprintf (stderr, _("Unknown command, use 'q' to quit or 'r' to restart peer\n"));
136 break;
103 } 137 }
104 GNUNET_break (0); 138 tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, &fh, &stdin_cb, NULL);
105} 139}
106 140
141
107/** 142/**
108 * Main function called by the testing library. 143 * Main function called by the testing library.
109 * Executed inside a running scheduler. 144 * Executed inside a running scheduler.
145 *
146 * @param cls unused
147 * @param cfg configuration of the peer that was started
148 * @param peer handle to the peer
110 */ 149 */
111void 150static void
112testing_main (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, 151testing_main (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
113 const struct GNUNET_TESTING_Peer *peer) 152 const struct GNUNET_TESTING_Peer *peer)
114{ 153{
115 my_peer = (struct GNUNET_TESTING_Peer *) peer; 154 my_peer = (struct GNUNET_TESTING_Peer *) peer;
116 tmpfilename = tmpnam (NULL); 155 if (NULL == (tmpfilename = GNUNET_DISK_mktemp ("gnunet-testing")))
117 if (NULL == tmpfilename)
118 { 156 {
119 GNUNET_break (0); 157 GNUNET_break (0);
120 cleanup (); 158 cleanup ();
121 return; 159 return;
122 } 160 }
123
124 if (GNUNET_SYSERR == 161 if (GNUNET_SYSERR ==
125 GNUNET_CONFIGURATION_write((struct GNUNET_CONFIGURATION_Handle *) cfg, tmpfilename)) 162 GNUNET_CONFIGURATION_write ((struct GNUNET_CONFIGURATION_Handle *) cfg, tmpfilename))
126 { 163 {
127 GNUNET_break (0); 164 GNUNET_break (0);
128 return; 165 return;
129 } 166 }
130 167 printf("%s\n", tmpfilename);
131 printf("started\n%s\n", tmpfilename);
132 fflush(stdout); 168 fflush(stdout);
133 169 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREFER_REL, &cleanup);
134 GNUNET_break(NULL != GNUNET_SIGNAL_handler_install(SIGTERM, &cleanup)); 170 fh = GNUNET_DISK_get_handle_from_native (stdin);
135 GNUNET_break(NULL != GNUNET_SIGNAL_handler_install(SIGINT, &cleanup));
136
137#if !WINDOWS
138 fh.fd = 0; /* 0=stdin */
139#else
140 /* FIXME: box GetStdHandle(STD_INPUT_HANDLE) somehow.
141 * Note that it will only work if parent process spawns
142 * gnunet-testing-run-service with custom-created asynchronous standard input
143 */
144#endif
145 tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, &fh, &stdin_cb, NULL); 171 tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, &fh, &stdin_cb, NULL);
146} 172}
147 173
148 174
149
150/** 175/**
151 * The main function. 176 * The main function.
152 * 177 *
@@ -157,29 +182,26 @@ testing_main (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
157int 182int
158main (int argc, char *const *argv) 183main (int argc, char *const *argv)
159{ 184{
185 static char *cfg_name;
186 static char *srv_name;
160 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 187 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
161 GNUNET_GETOPT_OPTION_HELP("tool to start a service for testing"), 188 {'c', "config", "FILENAME",
189 gettext_noop ("name of the configuration file to use"), 1,
190 &GNUNET_GETOPT_set_string, &cfg_name},
191 {'s', "service", "SERVICE",
192 gettext_noop ("name of the service to run"), 1,
193 &GNUNET_GETOPT_set_string, &srv_name},
194 GNUNET_GETOPT_OPTION_HELP ("tool to start a service for testing"),
162 GNUNET_GETOPT_OPTION_END 195 GNUNET_GETOPT_OPTION_END
163 }; 196 };
164 int arg_start;
165 int ret; 197 int ret;
166 198
167 arg_start = GNUNET_GETOPT_run("gnunet-testing-run-service", options, argc, argv); 199 if (GNUNET_SYSERR ==
168 200 GNUNET_GETOPT_run("gnunet-testing-run-service", options, argc, argv))
169 if (arg_start == GNUNET_SYSERR)
170 {
171 return 1; 201 return 1;
172 } 202 ret = GNUNET_TESTING_service_run_restartable ("gnunet_service_test", srv_name,
173 203 cfg_name, &testing_main, NULL);
174 if (arg_start != 1 || argc != 2) 204 if (0 != ret)
175 {
176 fprintf (stderr, "Invalid number of arguments\n");
177 return 1;
178 }
179
180 ret = GNUNET_TESTING_service_run_restartable ("gnunet_service_test", argv[1],
181 NULL, &testing_main, NULL);
182 if (ret)
183 { 205 {
184 printf ("error\n"); 206 printf ("error\n");
185 } 207 }