aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-04-19 14:59:43 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-04-19 14:59:43 +0000
commit87c2411c30758a5a6f39b433b8012c030ecd5963 (patch)
tree368ac889496cef47d5136b860c3c7688e0314a1e /src
parent1079f746c943b2efffa28970fe03f679334c3bb3 (diff)
downloadgnunet-87c2411c30758a5a6f39b433b8012c030ecd5963.tar.gz
gnunet-87c2411c30758a5a6f39b433b8012c030ecd5963.zip
- simple test case for service sharing in testing deployments
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_testing_lib.h6
-rw-r--r--src/testbed/testbed.conf.in2
-rw-r--r--src/testing/Makefile.am11
-rw-r--r--src/testing/test_testing_peerstartup.c2
-rw-r--r--src/testing/test_testing_sharedservices.c167
-rw-r--r--src/testing/test_testing_sharedservices.conf84
-rw-r--r--src/testing/testing.c27
7 files changed, 281 insertions, 18 deletions
diff --git a/src/include/gnunet_testing_lib.h b/src/include/gnunet_testing_lib.h
index d4c5b5b37..bf5e9e522 100644
--- a/src/include/gnunet_testing_lib.h
+++ b/src/include/gnunet_testing_lib.h
@@ -111,7 +111,7 @@ struct GNUNET_TESTING_System *
111GNUNET_TESTING_system_create (const char *testdir, 111GNUNET_TESTING_system_create (const char *testdir,
112 const char *trusted_ip, 112 const char *trusted_ip,
113 const char *hostname, 113 const char *hostname,
114 const struct GNUNET_TESTING_SharedService ** 114 const struct GNUNET_TESTING_SharedService *
115 shared_services); 115 shared_services);
116 116
117 117
@@ -141,8 +141,8 @@ struct GNUNET_TESTING_System *
141GNUNET_TESTING_system_create_with_portrange (const char *testdir, 141GNUNET_TESTING_system_create_with_portrange (const char *testdir,
142 const char *trusted_ip, 142 const char *trusted_ip,
143 const char *hostname, 143 const char *hostname,
144 const struct 144 const struct
145 GNUNET_TESTING_SharedService ** 145 GNUNET_TESTING_SharedService *
146 shared_services, 146 shared_services,
147 uint16_t lowport, 147 uint16_t lowport,
148 uint16_t highport); 148 uint16_t highport);
diff --git a/src/testbed/testbed.conf.in b/src/testbed/testbed.conf.in
index cf724409a..b5687aa5b 100644
--- a/src/testbed/testbed.conf.in
+++ b/src/testbed/testbed.conf.in
@@ -54,7 +54,7 @@ AUTOSTART = NO
54@UNIXONLY@ PORT = 2102 54@UNIXONLY@ PORT = 2102
55HOSTNAME = localhost 55HOSTNAME = localhost
56BINARY = gnunet-service-testbed-logger 56BINARY = gnunet-service-testbed-logger
57UNIXPaTH = /tmp/gnunet-gnunet-testbed-logger.sock 57UNIXPATH = /tmp/gnunet-gnunet-testbed-logger.sock
58DIR = /tmp 58DIR = /tmp
59UNIX_MATCH_UID = YES 59UNIX_MATCH_UID = YES
60UNIX_MATCH_GID = YES 60UNIX_MATCH_GID = YES
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 02a62e57f..b028e1ab1 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -56,7 +56,8 @@ check_PROGRAMS = \
56 test_testing_portreservation \ 56 test_testing_portreservation \
57 test_testing_servicestartup \ 57 test_testing_servicestartup \
58 test_testing_peerstartup \ 58 test_testing_peerstartup \
59 test_testing_peerstartup2 59 test_testing_peerstartup2 \
60 test_testing_sharedservices
60 61
61if ENABLE_TEST_RUN 62if ENABLE_TEST_RUN
62TESTS = \ 63TESTS = \
@@ -64,7 +65,6 @@ TESTS = \
64 test_testing_peerstartup \ 65 test_testing_peerstartup \
65 test_testing_peerstartup2 \ 66 test_testing_peerstartup2 \
66 test_testing_servicestartup 67 test_testing_servicestartup
67
68endif 68endif
69 69
70test_testing_portreservation_SOURCES = \ 70test_testing_portreservation_SOURCES = \
@@ -91,6 +91,13 @@ test_testing_servicestartup_LDADD = \
91 $(top_builddir)/src/testing/libgnunettesting.la \ 91 $(top_builddir)/src/testing/libgnunettesting.la \
92 $(top_builddir)/src/util/libgnunetutil.la 92 $(top_builddir)/src/util/libgnunetutil.la
93 93
94test_testing_sharedservices_SOURCES = \
95 test_testing_sharedservices.c
96test_testing_sharedservices_LDADD = \
97 $(top_builddir)/src/testing/libgnunettesting.la \
98 $(top_builddir)/src/util/libgnunetutil.la
99
100
94 101
95EXTRA_DIST = \ 102EXTRA_DIST = \
96 test_testing_defaults.conf 103 test_testing_defaults.conf
diff --git a/src/testing/test_testing_peerstartup.c b/src/testing/test_testing_peerstartup.c
index d32a341b5..41a99a75d 100644
--- a/src/testing/test_testing_peerstartup.c
+++ b/src/testing/test_testing_peerstartup.c
@@ -133,7 +133,7 @@ int main (int argc, char *argv[])
133 status = GNUNET_SYSERR; 133 status = GNUNET_SYSERR;
134 if (GNUNET_OK != 134 if (GNUNET_OK !=
135 GNUNET_PROGRAM_run (argc, argv, 135 GNUNET_PROGRAM_run (argc, argv,
136 "test_testing_new_peerstartup", 136 "test_testing_peerstartup",
137 "test case for peerstartup using new testing library", 137 "test case for peerstartup using new testing library",
138 options, &run, NULL)) 138 options, &run, NULL))
139 return 1; 139 return 1;
diff --git a/src/testing/test_testing_sharedservices.c b/src/testing/test_testing_sharedservices.c
new file mode 100644
index 000000000..305b2b21b
--- /dev/null
+++ b/src/testing/test_testing_sharedservices.c
@@ -0,0 +1,167 @@
1/*
2 This file is part of GNUnet
3 (C) 2008, 2009, 2012 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 */
20
21/**
22 * @file testing/test_testing_sharedservices.c
23 * @brief test case for testing service sharing among peers started by testing
24 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
25 */
26
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_testing_lib.h"
30
31#define LOG(kind,...) \
32 GNUNET_log (kind, __VA_ARGS__)
33
34#define NUM_PEERS 4
35
36/**
37 * The status of the test
38 */
39int status;
40
41/**
42 * The testing context
43 */
44struct TestingContext
45{
46 /**
47 * The testing system
48 */
49 struct GNUNET_TESTING_System *system;
50
51 /**
52 * The peer which has been started by the testing system
53 */
54 struct GNUNET_TESTING_Peer *peers[NUM_PEERS];
55
56 /**
57 * The running configuration of the peer
58 */
59 struct GNUNET_CONFIGURATION_Handle *cfg;
60};
61
62
63/**
64 * Task for shutdown
65 *
66 * @param cls the testing context
67 * @param tc the tast context
68 */
69static void
70do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
71{
72 struct TestingContext *test_ctx = cls;
73 struct GNUNET_TESTING_Peer *peer;
74 unsigned int cnt;
75
76 GNUNET_assert (NULL != test_ctx);
77 for (cnt = 0; cnt < NUM_PEERS; cnt++)
78 {
79 peer = test_ctx->peers[cnt];
80 if (NULL == peer)
81 continue;
82 (void) GNUNET_TESTING_peer_stop (peer);
83 GNUNET_TESTING_peer_destroy (peer);
84 }
85 if (NULL != test_ctx->cfg)
86 GNUNET_CONFIGURATION_destroy (test_ctx->cfg);
87 if (NULL != test_ctx->system)
88 GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES);
89 GNUNET_free (test_ctx);
90}
91
92
93/**
94 * Main point of test execution
95 */
96static void
97run (void *cls, char *const *args, const char *cfgfile,
98 const struct GNUNET_CONFIGURATION_Handle *cfg)
99{
100 struct TestingContext *test_ctx;
101 char *emsg;
102 struct GNUNET_PeerIdentity id;
103 struct GNUNET_TESTING_SharedService ss[] = {
104 {"peerinfo", cfg, 2},
105 {NULL, NULL, 0}
106 };
107 struct GNUNET_TESTING_Peer *peer;
108 unsigned int cnt;
109
110 test_ctx = GNUNET_malloc (sizeof (struct TestingContext));
111 test_ctx->system =
112 GNUNET_TESTING_system_create ("test-gnunet-testing",
113 "127.0.0.1", NULL, ss);
114 emsg = NULL;
115 if (NULL == test_ctx->system)
116 goto end;
117 test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg);
118 for (cnt = 0; cnt < NUM_PEERS; cnt++)
119 {
120 peer = GNUNET_TESTING_peer_configure (test_ctx->system,
121 test_ctx->cfg,
122 0, &id, &emsg);
123 if (NULL == peer)
124 {
125 if (NULL != emsg)
126 printf ("Test failed upon error: %s", emsg);
127 goto end;
128 }
129 if (GNUNET_OK != GNUNET_TESTING_peer_start (peer))
130 {
131 GNUNET_TESTING_peer_destroy (peer);
132 goto end;
133 }
134 test_ctx->peers[cnt] = peer;
135 }
136 status = GNUNET_OK;
137 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
138 &do_shutdown, test_ctx);
139 return;
140
141 end:
142 GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx);
143 GNUNET_free_non_null (emsg);
144}
145
146
147int main (int argc, char *argv[])
148{
149 struct GNUNET_GETOPT_CommandLineOption options[] = {
150 GNUNET_GETOPT_OPTION_END
151 };
152 char *const argv2[] = { "test_testing_sharedservices",
153 "-c", "test_testing_sharedservices.conf",
154 NULL
155 };
156
157 status = GNUNET_SYSERR;
158 if (GNUNET_OK !=
159 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
160 "test_testing_sharedservices",
161 "test case for testing service sharing among peers started by testing",
162 options, &run, NULL))
163 return 1;
164 return (GNUNET_OK == status) ? 0 : 3;
165}
166
167/* end of test_testing_sharedservices.c */
diff --git a/src/testing/test_testing_sharedservices.conf b/src/testing/test_testing_sharedservices.conf
new file mode 100644
index 000000000..393b1e518
--- /dev/null
+++ b/src/testing/test_testing_sharedservices.conf
@@ -0,0 +1,84 @@
1[PATHS]
2SERVICEHOME = /tmp/test-gnunet-testing/
3
4[testbed-logger]
5PORT = 15000
6UNIXPATH = /tmp/testbed-logger.sock
7DIR = /tmp/testbed-logger
8
9[resolver]
10PORT = 2564
11
12[transport]
13PORT = 2565
14PLUGINS = tcp
15
16[transport-tcp]
17TESTING_IGNORE_KEYS = SOMETHING;KEY1;ACCEPT_FROM;
18
19[arm]
20PORT = 2566
21DEFAULTSERVICES =
22
23[statistics]
24PORT = 2567
25
26[transport-tcp]
27PORT = 2568
28BINDTO = 127.0.0.1
29
30[peerinfo]
31PORT = 2569
32AUTOSTART = NO
33
34[core]
35PORT = 2570
36
37[dht]
38AUTOSTART = NO
39
40[nat]
41DISABLEV6 = YES
42ENABLE_UPNP = NO
43BEHIND_NAT = NO
44ALLOW_NAT = NO
45INTERNAL_ADDRESS = 127.0.0.1
46EXTERNAL_ADDRESS = 127.0.0.1
47USE_LOCALADDR = NO
48
49[dns]
50AUTOSTART = NO
51
52[nse]
53AUTOSTART = NO
54
55[mesh]
56AUTOSTART = NO
57
58[datastore]
59AUTOSTART = NO
60
61[fs]
62AUTOSTART = NO
63
64[dv]
65AUTOSTART = NO
66
67[chat]
68AUTOSTART = NO
69
70[vpn]
71AUTOSTART = NO
72
73[gns]
74AUTOSTART = NO
75
76[namestore]
77AUTOSTART = NO
78
79[lockmanager]
80AUTOSTART = NO
81
82[consensus]
83AUTOSTART = NO
84
diff --git a/src/testing/testing.c b/src/testing/testing.c
index 23cd7ddc7..1b2448ffc 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -385,13 +385,13 @@ GNUNET_TESTING_system_create_with_portrange (const char *testdir,
385 const char *trusted_ip, 385 const char *trusted_ip,
386 const char *hostname, 386 const char *hostname,
387 const struct 387 const struct
388 GNUNET_TESTING_SharedService ** 388 GNUNET_TESTING_SharedService *
389 shared_services, 389 shared_services,
390 uint16_t lowport, 390 uint16_t lowport,
391 uint16_t highport) 391 uint16_t highport)
392{ 392{
393 struct GNUNET_TESTING_System *system; 393 struct GNUNET_TESTING_System *system;
394 const struct GNUNET_TESTING_SharedService *tss; 394 struct GNUNET_TESTING_SharedService tss;
395 struct SharedService *ss; 395 struct SharedService *ss;
396 unsigned int cnt; 396 unsigned int cnt;
397 397
@@ -416,17 +416,17 @@ GNUNET_TESTING_system_create_with_portrange (const char *testdir,
416 } 416 }
417 if (NULL == shared_services) 417 if (NULL == shared_services)
418 return system; 418 return system;
419 for (cnt = 0; NULL != (tss = shared_services[cnt]); cnt++) 419 for (cnt = 0; NULL != shared_services[cnt].service; cnt++)
420 { 420 {
421 tss = shared_services[cnt];
421 ss = GNUNET_malloc (sizeof (struct SharedService)); 422 ss = GNUNET_malloc (sizeof (struct SharedService));
422 ss->sname = GNUNET_strdup (tss->service); 423 ss->sname = GNUNET_strdup (tss.service);
423 ss->cfg = GNUNET_CONFIGURATION_dup (tss->cfg);
424 ss->cfg = GNUNET_CONFIGURATION_create (); 424 ss->cfg = GNUNET_CONFIGURATION_create ();
425 GNUNET_CONFIGURATION_iterate_section_values (tss->cfg, ss->sname, 425 GNUNET_CONFIGURATION_iterate_section_values (tss.cfg, ss->sname,
426 &cfg_copy_iterator, ss->cfg); 426 &cfg_copy_iterator, ss->cfg);
427 GNUNET_CONFIGURATION_iterate_section_values (tss->cfg, "TESTING", 427 GNUNET_CONFIGURATION_iterate_section_values (tss.cfg, "TESTING",
428 &cfg_copy_iterator, ss->cfg); 428 &cfg_copy_iterator, ss->cfg);
429 ss->share = tss->share; 429 ss->share = tss.share;
430 GNUNET_array_append (system->shared_services, system->n_shared_services, 430 GNUNET_array_append (system->shared_services, system->n_shared_services,
431 ss); 431 ss);
432 } 432 }
@@ -456,7 +456,7 @@ struct GNUNET_TESTING_System *
456GNUNET_TESTING_system_create (const char *testdir, 456GNUNET_TESTING_system_create (const char *testdir,
457 const char *trusted_ip, 457 const char *trusted_ip,
458 const char *hostname, 458 const char *hostname,
459 const struct GNUNET_TESTING_SharedService ** 459 const struct GNUNET_TESTING_SharedService *
460 shared_services) 460 shared_services)
461{ 461{
462 return GNUNET_TESTING_system_create_with_portrange (testdir, 462 return GNUNET_TESTING_system_create_with_portrange (testdir,
@@ -486,18 +486,22 @@ static int
486start_shared_service_instance (struct SharedServiceInstance *i) 486start_shared_service_instance (struct SharedServiceInstance *i)
487{ 487{
488 char *binary; 488 char *binary;
489 char *libexec_binary;
489 490
490 GNUNET_assert (NULL == i->proc); 491 GNUNET_assert (NULL == i->proc);
491 GNUNET_assert (NULL != i->cfg_fn); 492 GNUNET_assert (NULL != i->cfg_fn);
492 (void) GNUNET_asprintf (&binary, "gnunet-service-%s", i->ss->sname); 493 (void) GNUNET_asprintf (&binary, "gnunet-service-%s", i->ss->sname);
494 libexec_binary = GNUNET_OS_get_libexec_binary_path (binary);
495 GNUNET_free (binary);
493 i->proc = GNUNET_OS_start_process (PIPE_CONTROL, 496 i->proc = GNUNET_OS_start_process (PIPE_CONTROL,
494 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 497 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
495 NULL, NULL, 498 NULL, NULL,
496 binary, 499 libexec_binary,
497 binary, 500 libexec_binary,
498 "-c", 501 "-c",
499 i->cfg_fn, 502 i->cfg_fn,
500 NULL); 503 NULL);
504 GNUNET_free (libexec_binary);
501 if (NULL == i->proc) 505 if (NULL == i->proc)
502 return GNUNET_SYSERR; 506 return GNUNET_SYSERR;
503 return GNUNET_OK; 507 return GNUNET_OK;
@@ -1004,6 +1008,7 @@ associate_shared_service (struct GNUNET_TESTING_System *system,
1004 (void) GNUNET_asprintf (&i->cfg_fn, "%s/config", service_home); 1008 (void) GNUNET_asprintf (&i->cfg_fn, "%s/config", service_home);
1005 GNUNET_CONFIGURATION_set_value_string (temp, "PATHS", "SERVICEHOME", 1009 GNUNET_CONFIGURATION_set_value_string (temp, "PATHS", "SERVICEHOME",
1006 service_home); 1010 service_home);
1011 GNUNET_free (service_home);
1007 GNUNET_CONFIGURATION_set_value_string (temp, ss->sname, "UNIXPATH", 1012 GNUNET_CONFIGURATION_set_value_string (temp, ss->sname, "UNIXPATH",
1008 i->unix_sock); 1013 i->unix_sock);
1009 GNUNET_CONFIGURATION_set_value_string (temp, ss->sname, "PORT", 1014 GNUNET_CONFIGURATION_set_value_string (temp, ss->sname, "PORT",