diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-03-09 01:23:14 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-03-09 01:23:14 +0100 |
commit | b3c485774524f2c4799a46278305070b3a710277 (patch) | |
tree | 99230d0c5ba055fff626f0d7576140fa7176f77d | |
parent | a58204836147e7093e5b741513584772b47fc3ea (diff) | |
download | gnunet-gtk-b3c485774524f2c4799a46278305070b3a710277.tar.gz gnunet-gtk-b3c485774524f2c4799a46278305070b3a710277.zip |
automatically launch required services during transport tests
-rw-r--r-- | src/setup/gnunet-setup-transport-test.c | 120 | ||||
-rw-r--r-- | src/setup/gnunet-setup.c | 5 | ||||
-rw-r--r-- | src/setup/gnunet-setup.h | 6 |
3 files changed, 128 insertions, 3 deletions
diff --git a/src/setup/gnunet-setup-transport-test.c b/src/setup/gnunet-setup-transport-test.c index 66f5e80e..a62c4d8e 100644 --- a/src/setup/gnunet-setup-transport-test.c +++ b/src/setup/gnunet-setup-transport-test.c | |||
@@ -69,6 +69,116 @@ struct TestContext | |||
69 | 69 | ||
70 | 70 | ||
71 | /** | 71 | /** |
72 | * Number of active tests. | ||
73 | */ | ||
74 | static unsigned int num_tests; | ||
75 | |||
76 | /** | ||
77 | * Handle for NAT service. | ||
78 | */ | ||
79 | static struct GNUNET_OS_Process *nat; | ||
80 | |||
81 | /** | ||
82 | * Handle for NAT-AUTO service. | ||
83 | */ | ||
84 | static struct GNUNET_OS_Process *nat_auto; | ||
85 | |||
86 | /** | ||
87 | * Handle for RESOLVER service. | ||
88 | */ | ||
89 | static struct GNUNET_OS_Process *resolver; | ||
90 | |||
91 | |||
92 | /** | ||
93 | * Stop the given process, nicely. | ||
94 | * | ||
95 | * @param proc process to stop. | ||
96 | */ | ||
97 | static void | ||
98 | stop_service (struct GNUNET_OS_Process *proc) | ||
99 | { | ||
100 | if (NULL == proc) | ||
101 | return; | ||
102 | GNUNET_break (0 == | ||
103 | GNUNET_OS_process_kill (proc, | ||
104 | SIGTERM)); | ||
105 | GNUNET_break (GNUNET_OK == | ||
106 | GNUNET_OS_process_wait (proc)); | ||
107 | GNUNET_OS_process_destroy (proc); | ||
108 | } | ||
109 | |||
110 | |||
111 | /** | ||
112 | * Start the given service process. | ||
113 | * | ||
114 | * @param name name of the service to run | ||
115 | * @return handle to the service | ||
116 | */ | ||
117 | static struct GNUNET_OS_Process * | ||
118 | start_service (const char *name) | ||
119 | { | ||
120 | struct GNUNET_OS_Process *proc; | ||
121 | char *binary; | ||
122 | char *filename; | ||
123 | char *path; | ||
124 | |||
125 | GNUNET_asprintf (&binary, | ||
126 | "gnunet-service-%s", | ||
127 | name); | ||
128 | path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBEXECDIR); | ||
129 | GNUNET_asprintf (&filename, | ||
130 | "%s/%s", | ||
131 | path, | ||
132 | binary); | ||
133 | GNUNET_free (path); | ||
134 | proc = GNUNET_OS_start_process (GNUNET_NO, | ||
135 | GNUNET_OS_INHERIT_STD_ERR, | ||
136 | NULL, | ||
137 | NULL, | ||
138 | NULL, | ||
139 | filename, | ||
140 | binary, | ||
141 | "-c", | ||
142 | option_cfg_name, | ||
143 | NULL); | ||
144 | if (NULL == proc) | ||
145 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | ||
146 | "exec", | ||
147 | filename); | ||
148 | GNUNET_free (binary); | ||
149 | GNUNET_free (filename); | ||
150 | return proc; | ||
151 | } | ||
152 | |||
153 | |||
154 | /** | ||
155 | * Stop the helper services. | ||
156 | */ | ||
157 | static void | ||
158 | stop_services () | ||
159 | { | ||
160 | stop_service (nat_auto); | ||
161 | nat_auto = NULL; | ||
162 | stop_service (nat); | ||
163 | nat = NULL; | ||
164 | stop_service (resolver); | ||
165 | resolver = NULL; | ||
166 | } | ||
167 | |||
168 | |||
169 | /** | ||
170 | * Start the helper services. | ||
171 | */ | ||
172 | static void | ||
173 | start_services () | ||
174 | { | ||
175 | resolver = start_service ("resolver"); | ||
176 | nat = start_service ("nat"); | ||
177 | nat_auto = start_service ("nat-auto"); | ||
178 | } | ||
179 | |||
180 | |||
181 | /** | ||
72 | * Display the result of the test. | 182 | * Display the result of the test. |
73 | * | 183 | * |
74 | * @param tc test context | 184 | * @param tc test context |
@@ -103,7 +213,10 @@ display_test_result (struct TestContext *tc, | |||
103 | GNUNET_NAT_AUTO_test_stop (tc->tst); | 213 | GNUNET_NAT_AUTO_test_stop (tc->tst); |
104 | tc->tst = NULL; | 214 | tc->tst = NULL; |
105 | } | 215 | } |
216 | num_tests--; | ||
106 | GNUNET_free (tc); | 217 | GNUNET_free (tc); |
218 | if (0 == num_tests) | ||
219 | stop_services (); | ||
107 | } | 220 | } |
108 | 221 | ||
109 | 222 | ||
@@ -138,7 +251,10 @@ shutdown_task (void *cls) | |||
138 | tc->st = NULL; | 251 | tc->st = NULL; |
139 | GNUNET_SCHEDULER_cancel (tc->tt); | 252 | GNUNET_SCHEDULER_cancel (tc->tt); |
140 | GNUNET_NAT_AUTO_test_stop (tc->tst); | 253 | GNUNET_NAT_AUTO_test_stop (tc->tst); |
254 | num_tests--; | ||
141 | GNUNET_free (tc); | 255 | GNUNET_free (tc); |
256 | if (0 == num_tests) | ||
257 | stop_services (); | ||
142 | } | 258 | } |
143 | 259 | ||
144 | 260 | ||
@@ -184,8 +300,10 @@ GNUNET_setup_transport_test (const char *section_name, | |||
184 | struct TestContext *tc; | 300 | struct TestContext *tc; |
185 | GtkWidget *w; | 301 | GtkWidget *w; |
186 | 302 | ||
187 | GNUNET_break (0); // FIXME: launch NAT and RESOLVER service at least first! | 303 | if (0 == num_tests) |
304 | start_services (); | ||
188 | tc = GNUNET_new (struct TestContext); | 305 | tc = GNUNET_new (struct TestContext); |
306 | num_tests++; | ||
189 | tc->success_image = success_image; | 307 | tc->success_image = success_image; |
190 | tc->failure_image = failure_image; | 308 | tc->failure_image = failure_image; |
191 | w = GTK_WIDGET (GNUNET_SETUP_get_object (success_image)); | 309 | w = GTK_WIDGET (GNUNET_SETUP_get_object (success_image)); |
diff --git a/src/setup/gnunet-setup.c b/src/setup/gnunet-setup.c index a2dd6a27..ac37a972 100644 --- a/src/setup/gnunet-setup.c +++ b/src/setup/gnunet-setup.c | |||
@@ -40,7 +40,7 @@ static struct GNUNET_GTK_MainLoop *ml; | |||
40 | /** | 40 | /** |
41 | * Name of the configuration file. | 41 | * Name of the configuration file. |
42 | */ | 42 | */ |
43 | static const char *option_cfg_name; | 43 | const char *option_cfg_name; |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * Our configuration. | 46 | * Our configuration. |
@@ -332,7 +332,8 @@ write_configuration () | |||
332 | 332 | ||
333 | cfgDefault = GNUNET_CONFIGURATION_create (); | 333 | cfgDefault = GNUNET_CONFIGURATION_create (); |
334 | (void) GNUNET_CONFIGURATION_load (cfgDefault, NULL); /* load defaults only */ | 334 | (void) GNUNET_CONFIGURATION_load (cfgDefault, NULL); /* load defaults only */ |
335 | ret = GNUNET_CONFIGURATION_write_diffs (cfgDefault, cfg, | 335 | ret = GNUNET_CONFIGURATION_write_diffs (cfgDefault, |
336 | cfg, | ||
336 | option_cfg_name); | 337 | option_cfg_name); |
337 | GNUNET_CONFIGURATION_destroy (cfgDefault); | 338 | GNUNET_CONFIGURATION_destroy (cfgDefault); |
338 | return ret; | 339 | return ret; |
diff --git a/src/setup/gnunet-setup.h b/src/setup/gnunet-setup.h index fde0b27a..59682fc0 100644 --- a/src/setup/gnunet-setup.h +++ b/src/setup/gnunet-setup.h | |||
@@ -33,6 +33,12 @@ | |||
33 | 33 | ||
34 | 34 | ||
35 | /** | 35 | /** |
36 | * Name of the configuration file. | ||
37 | */ | ||
38 | extern const char *option_cfg_name; | ||
39 | |||
40 | |||
41 | /** | ||
36 | * Columns in the gns setup model. | 42 | * Columns in the gns setup model. |
37 | */ | 43 | */ |
38 | enum GNUNET_GTK_SETUP_HostlistUrlModelColumns | 44 | enum GNUNET_GTK_SETUP_HostlistUrlModelColumns |