aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing.c')
-rw-r--r--src/testing/testing.c40
1 files changed, 27 insertions, 13 deletions
diff --git a/src/testing/testing.c b/src/testing/testing.c
index ecef4f266..8a5ff6679 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -74,6 +74,11 @@ struct GNUNET_TESTING_System
74 char *controller; 74 char *controller;
75 75
76 /** 76 /**
77 * our hostname
78 */
79 char *hostname;
80
81 /**
77 * Hostkeys data, contains "HOSTKEYFILESIZE * total_hostkeys" bytes. 82 * Hostkeys data, contains "HOSTKEYFILESIZE * total_hostkeys" bytes.
78 */ 83 */
79 char *hostkeys_data; 84 char *hostkeys_data;
@@ -262,6 +267,8 @@ hostkeys_unload (struct GNUNET_TESTING_System *system)
262 * @param controller hostname of the controlling host, 267 * @param controller hostname of the controlling host,
263 * service configurations are modified to allow 268 * service configurations are modified to allow
264 * control connections from this host; can be NULL 269 * control connections from this host; can be NULL
270 * @param hostname the hostname of the system we are using for testing; NULL for
271 * localhost
265 * @param lowport lowest port number this system is allowed to allocate (inclusive) 272 * @param lowport lowest port number this system is allowed to allocate (inclusive)
266 * @param highport highest port number this system is allowed to allocate (exclusive) 273 * @param highport highest port number this system is allowed to allocate (exclusive)
267 * @return handle to this system, NULL on error 274 * @return handle to this system, NULL on error
@@ -269,6 +276,7 @@ hostkeys_unload (struct GNUNET_TESTING_System *system)
269struct GNUNET_TESTING_System * 276struct GNUNET_TESTING_System *
270GNUNET_TESTING_system_create_with_portrange (const char *testdir, 277GNUNET_TESTING_system_create_with_portrange (const char *testdir,
271 const char *controller, 278 const char *controller,
279 const char *hostname,
272 uint16_t lowport, 280 uint16_t lowport,
273 uint16_t highport) 281 uint16_t highport)
274{ 282{
@@ -286,6 +294,8 @@ GNUNET_TESTING_system_create_with_portrange (const char *testdir,
286 } 294 }
287 if (NULL != controller) 295 if (NULL != controller)
288 system->controller = GNUNET_strdup (controller); 296 system->controller = GNUNET_strdup (controller);
297 if (NULL != hostname)
298 system->hostname = GNUNET_strdup (hostname);
289 if (GNUNET_OK != hostkeys_load (system)) 299 if (GNUNET_OK != hostkeys_load (system))
290 { 300 {
291 GNUNET_TESTING_system_destroy (system, GNUNET_YES); 301 GNUNET_TESTING_system_destroy (system, GNUNET_YES);
@@ -296,24 +306,27 @@ GNUNET_TESTING_system_create_with_portrange (const char *testdir,
296 306
297 307
298/** 308/**
299 * Create a system handle. There must only be one system 309 * Create a system handle. There must only be one system handle per operating
300 * handle per operating system. 310 * system. Uses a default range for allowed ports. Ports are still tested for
301 * 311 * availability.
302 * @param testdir only the directory name without any path. This is used for
303 * all service homes; the directory will be created in a temporary
304 * location depending on the underlying OS
305 * 312 *
306 * @param controller hostname of the controlling host, 313 * @param testdir only the directory name without any path. This is used for all
307 * service configurations are modified to allow 314 * service homes; the directory will be created in a temporary location
308 * control connections from this host; can be NULL 315 * depending on the underlying OS
316 * @param controller hostname of the controlling host, service configurations
317 * are modified to allow control connections from this host; can be NULL
318 * @param hostname the hostname of the system we are using for testing; NULL for
319 * localhost
309 * @return handle to this system, NULL on error 320 * @return handle to this system, NULL on error
310 */ 321 */
311struct GNUNET_TESTING_System * 322struct GNUNET_TESTING_System *
312GNUNET_TESTING_system_create (const char *testdir, 323GNUNET_TESTING_system_create (const char *testdir,
313 const char *controller) 324 const char *controller,
325 const char *hostname)
314{ 326{
315 return GNUNET_TESTING_system_create_with_portrange (testdir, 327 return GNUNET_TESTING_system_create_with_portrange (testdir,
316 controller, 328 controller,
329 hostname,
317 LOW_PORT, 330 LOW_PORT,
318 HIGH_PORT); 331 HIGH_PORT);
319} 332}
@@ -336,6 +349,7 @@ GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system,
336 GNUNET_DISK_directory_remove (system->tmppath); 349 GNUNET_DISK_directory_remove (system->tmppath);
337 GNUNET_free (system->tmppath); 350 GNUNET_free (system->tmppath);
338 GNUNET_free_non_null (system->controller); 351 GNUNET_free_non_null (system->controller);
352 GNUNET_free_non_null (system->hostname);
339 GNUNET_free (system); 353 GNUNET_free (system);
340} 354}
341 355
@@ -635,9 +649,9 @@ update_config (void *cls, const char *section, const char *option,
635 GNUNET_break(0); /* FIXME */ 649 GNUNET_break(0); /* FIXME */
636 } 650 }
637 } 651 }
638 if ((0 == strcmp (option, "HOSTNAME")) && (NULL != uc->system->controller)) 652 if (0 == strcmp (option, "HOSTNAME"))
639 { 653 {
640 value = uc->system->controller; 654 value = (NULL == uc->system->hostname) ? "localhost" : uc->system->hostname;
641 } 655 }
642 GNUNET_free (single_variable); 656 GNUNET_free (single_variable);
643 GNUNET_free (per_host_variable); 657 GNUNET_free (per_host_variable);
@@ -1119,7 +1133,7 @@ GNUNET_TESTING_service_run (const char *testdir,
1119 struct GNUNET_CONFIGURATION_Handle *cfg; 1133 struct GNUNET_CONFIGURATION_Handle *cfg;
1120 1134
1121 GNUNET_log_setup (testdir, "WARNING", NULL); 1135 GNUNET_log_setup (testdir, "WARNING", NULL);
1122 system = GNUNET_TESTING_system_create (testdir, "127.0.0.1"); 1136 system = GNUNET_TESTING_system_create (testdir, "127.0.0.1", NULL);
1123 if (NULL == system) 1137 if (NULL == system)
1124 return 1; 1138 return 1;
1125 cfg = GNUNET_CONFIGURATION_create (); 1139 cfg = GNUNET_CONFIGURATION_create ();