aboutsummaryrefslogtreecommitdiff
path: root/src/testing/test_testing_sharedservices.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/test_testing_sharedservices.c')
-rw-r--r--src/testing/test_testing_sharedservices.c89
1 files changed, 45 insertions, 44 deletions
diff --git a/src/testing/test_testing_sharedservices.c b/src/testing/test_testing_sharedservices.c
index 86e9f017c..13219bf5d 100644
--- a/src/testing/test_testing_sharedservices.c
+++ b/src/testing/test_testing_sharedservices.c
@@ -29,7 +29,7 @@
29#include "gnunet_testing_lib.h" 29#include "gnunet_testing_lib.h"
30 30
31#define LOG(kind, ...) \ 31#define LOG(kind, ...) \
32 GNUNET_log(kind, __VA_ARGS__) 32 GNUNET_log (kind, __VA_ARGS__)
33 33
34#define NUM_PEERS 4 34#define NUM_PEERS 4
35 35
@@ -41,7 +41,8 @@ int status;
41/** 41/**
42 * The testing context 42 * The testing context
43 */ 43 */
44struct TestingContext { 44struct TestingContext
45{
45 /** 46 /**
46 * The testing system 47 * The testing system
47 */ 48 */
@@ -65,26 +66,26 @@ struct TestingContext {
65 * @param cls the testing context 66 * @param cls the testing context
66 */ 67 */
67static void 68static void
68do_shutdown(void *cls) 69do_shutdown (void *cls)
69{ 70{
70 struct TestingContext *test_ctx = cls; 71 struct TestingContext *test_ctx = cls;
71 struct GNUNET_TESTING_Peer *peer; 72 struct GNUNET_TESTING_Peer *peer;
72 unsigned int cnt; 73 unsigned int cnt;
73 74
74 GNUNET_assert(NULL != test_ctx); 75 GNUNET_assert (NULL != test_ctx);
75 for (cnt = 0; cnt < NUM_PEERS; cnt++) 76 for (cnt = 0; cnt < NUM_PEERS; cnt++)
76 { 77 {
77 peer = test_ctx->peers[cnt]; 78 peer = test_ctx->peers[cnt];
78 if (NULL == peer) 79 if (NULL == peer)
79 continue; 80 continue;
80 (void)GNUNET_TESTING_peer_stop(peer); 81 (void) GNUNET_TESTING_peer_stop (peer);
81 GNUNET_TESTING_peer_destroy(peer); 82 GNUNET_TESTING_peer_destroy (peer);
82 } 83 }
83 if (NULL != test_ctx->cfg) 84 if (NULL != test_ctx->cfg)
84 GNUNET_CONFIGURATION_destroy(test_ctx->cfg); 85 GNUNET_CONFIGURATION_destroy (test_ctx->cfg);
85 if (NULL != test_ctx->system) 86 if (NULL != test_ctx->system)
86 GNUNET_TESTING_system_destroy(test_ctx->system, GNUNET_YES); 87 GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES);
87 GNUNET_free(test_ctx); 88 GNUNET_free (test_ctx);
88} 89}
89 90
90 91
@@ -92,8 +93,8 @@ do_shutdown(void *cls)
92 * Main point of test execution 93 * Main point of test execution
93 */ 94 */
94static void 95static void
95run(void *cls, char *const *args, const char *cfgfile, 96run (void *cls, char *const *args, const char *cfgfile,
96 const struct GNUNET_CONFIGURATION_Handle *cfg) 97 const struct GNUNET_CONFIGURATION_Handle *cfg)
97{ 98{
98 struct TestingContext *test_ctx; 99 struct TestingContext *test_ctx;
99 char *emsg; 100 char *emsg;
@@ -105,44 +106,44 @@ run(void *cls, char *const *args, const char *cfgfile,
105 struct GNUNET_TESTING_Peer *peer; 106 struct GNUNET_TESTING_Peer *peer;
106 unsigned int cnt; 107 unsigned int cnt;
107 108
108 test_ctx = GNUNET_new(struct TestingContext); 109 test_ctx = GNUNET_new (struct TestingContext);
109 test_ctx->system = 110 test_ctx->system =
110 GNUNET_TESTING_system_create("test-gnunet-testing", 111 GNUNET_TESTING_system_create ("test-gnunet-testing",
111 "127.0.0.1", NULL, ss); 112 "127.0.0.1", NULL, ss);
112 emsg = NULL; 113 emsg = NULL;
113 if (NULL == test_ctx->system) 114 if (NULL == test_ctx->system)
114 goto end; 115 goto end;
115 test_ctx->cfg = GNUNET_CONFIGURATION_dup(cfg); 116 test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg);
116 for (cnt = 0; cnt < NUM_PEERS; cnt++) 117 for (cnt = 0; cnt < NUM_PEERS; cnt++)
118 {
119 peer = GNUNET_TESTING_peer_configure (test_ctx->system,
120 test_ctx->cfg,
121 0, &id, &emsg);
122 if (NULL == peer)
123 {
124 if (NULL != emsg)
125 printf ("Test failed upon error: %s", emsg);
126 goto end;
127 }
128 if (GNUNET_OK != GNUNET_TESTING_peer_start (peer))
117 { 129 {
118 peer = GNUNET_TESTING_peer_configure(test_ctx->system, 130 GNUNET_TESTING_peer_destroy (peer);
119 test_ctx->cfg, 131 goto end;
120 0, &id, &emsg);
121 if (NULL == peer)
122 {
123 if (NULL != emsg)
124 printf("Test failed upon error: %s", emsg);
125 goto end;
126 }
127 if (GNUNET_OK != GNUNET_TESTING_peer_start(peer))
128 {
129 GNUNET_TESTING_peer_destroy(peer);
130 goto end;
131 }
132 test_ctx->peers[cnt] = peer;
133 } 132 }
133 test_ctx->peers[cnt] = peer;
134 }
134 status = GNUNET_OK; 135 status = GNUNET_OK;
135 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, 136 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
136 &do_shutdown, test_ctx); 137 &do_shutdown, test_ctx);
137 return; 138 return;
138 139
139end: 140end:
140 GNUNET_SCHEDULER_add_now(&do_shutdown, test_ctx); 141 GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx);
141 GNUNET_free_non_null(emsg); 142 GNUNET_free_non_null (emsg);
142} 143}
143 144
144 145
145int main(int argc, char *argv[]) 146int main (int argc, char *argv[])
146{ 147{
147 struct GNUNET_GETOPT_CommandLineOption options[] = { 148 struct GNUNET_GETOPT_CommandLineOption options[] = {
148 GNUNET_GETOPT_OPTION_END 149 GNUNET_GETOPT_OPTION_END
@@ -153,10 +154,10 @@ int main(int argc, char *argv[])
153 154
154 status = GNUNET_SYSERR; 155 status = GNUNET_SYSERR;
155 if (GNUNET_OK != 156 if (GNUNET_OK !=
156 GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2, 157 GNUNET_PROGRAM_run ((sizeof(argv2) / sizeof(char *)) - 1, argv2,
157 "test_testing_sharedservices", 158 "test_testing_sharedservices",
158 "test case for testing service sharing among peers started by testing", 159 "test case for testing service sharing among peers started by testing",
159 options, &run, NULL)) 160 options, &run, NULL))
160 return 1; 161 return 1;
161 return (GNUNET_OK == status) ? 0 : 3; 162 return (GNUNET_OK == status) ? 0 : 3;
162} 163}