diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-04-01 17:54:06 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-04-01 17:54:06 +0000 |
commit | 4e3864ec2681a43fb13f5d6af6093ebed5a68196 (patch) | |
tree | 62fe35f676784c78e7f7db8bbe3f1506611d11fe /src/testing/test_testing_peerstartup2.c | |
parent | e1de3162b194d2c72ad66aafcf803477caa41730 (diff) | |
download | gnunet-4e3864ec2681a43fb13f5d6af6093ebed5a68196.tar.gz gnunet-4e3864ec2681a43fb13f5d6af6093ebed5a68196.zip |
- only have asynchronous peer stop
Diffstat (limited to 'src/testing/test_testing_peerstartup2.c')
-rw-r--r-- | src/testing/test_testing_peerstartup2.c | 71 |
1 files changed, 42 insertions, 29 deletions
diff --git a/src/testing/test_testing_peerstartup2.c b/src/testing/test_testing_peerstartup2.c index 25b9ba2ea..d290aff16 100644 --- a/src/testing/test_testing_peerstartup2.c +++ b/src/testing/test_testing_peerstartup2.c | |||
@@ -36,11 +36,14 @@ | |||
36 | 36 | ||
37 | #define FAIL_TEST(cond) \ | 37 | #define FAIL_TEST(cond) \ |
38 | do { \ | 38 | do { \ |
39 | if ((!(cond)) && (GNUNET_OK == status)) { \ | 39 | if (!(cond)) { \ |
40 | status = GNUNET_SYSERR; \ | 40 | GNUNET_break (0); \ |
41 | if (GNUNET_OK == status) { \ | ||
42 | status = GNUNET_SYSERR; \ | ||
43 | } \ | ||
41 | } \ | 44 | } \ |
42 | } while (0) \ | 45 | } while (0) \ |
43 | 46 | ||
44 | 47 | ||
45 | /** | 48 | /** |
46 | * The status of the test | 49 | * The status of the test |
@@ -103,20 +106,7 @@ do_shutdown2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
103 | * @param tc the tast context | 106 | * @param tc the tast context |
104 | */ | 107 | */ |
105 | static void | 108 | static void |
106 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 109 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
107 | { | ||
108 | struct TestingContext *test_ctx = cls; | ||
109 | |||
110 | GNUNET_assert (NULL != test_ctx); | ||
111 | if (NULL != test_ctx->peer) | ||
112 | { | ||
113 | FAIL_TEST (GNUNET_OK == GNUNET_TESTING_peer_stop2 (test_ctx->peer, | ||
114 | GNUNET_TIME_UNIT_MINUTES)); | ||
115 | |||
116 | } | ||
117 | else | ||
118 | do_shutdown (test_ctx, tc); | ||
119 | } | ||
120 | 110 | ||
121 | 111 | ||
122 | static void | 112 | static void |
@@ -127,13 +117,11 @@ peer_status_cb (void *cls, struct GNUNET_TESTING_Peer *peer, int success) | |||
127 | switch (test_ctx->state) | 117 | switch (test_ctx->state) |
128 | { | 118 | { |
129 | case PEER_INIT: | 119 | case PEER_INIT: |
130 | FAIL_TEST (GNUNET_YES == success); | 120 | FAIL_TEST (0); |
131 | test_ctx->state = PEER_STARTED; | ||
132 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
133 | &do_shutdown, test_ctx); | ||
134 | break; | 121 | break; |
135 | case PEER_STARTED: | 122 | case PEER_STARTED: |
136 | FAIL_TEST (GNUNET_NO == success); | 123 | FAIL_TEST (GNUNET_YES == success); |
124 | test_ctx->state = PEER_STOPPED; | ||
137 | GNUNET_SCHEDULER_add_now (&do_shutdown2, cls); | 125 | GNUNET_SCHEDULER_add_now (&do_shutdown2, cls); |
138 | break; | 126 | break; |
139 | case PEER_STOPPED: | 127 | case PEER_STOPPED: |
@@ -143,6 +131,31 @@ peer_status_cb (void *cls, struct GNUNET_TESTING_Peer *peer, int success) | |||
143 | 131 | ||
144 | 132 | ||
145 | /** | 133 | /** |
134 | * Task for shutdown | ||
135 | * | ||
136 | * @param cls the testing context | ||
137 | * @param tc the tast context | ||
138 | */ | ||
139 | static void | ||
140 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
141 | { | ||
142 | struct TestingContext *test_ctx = cls; | ||
143 | |||
144 | GNUNET_assert (NULL != test_ctx); | ||
145 | if (NULL != test_ctx->peer) | ||
146 | { | ||
147 | FAIL_TEST (GNUNET_OK == | ||
148 | GNUNET_TESTING_peer_stop_async (test_ctx->peer, | ||
149 | &peer_status_cb, | ||
150 | test_ctx)); | ||
151 | |||
152 | } | ||
153 | else | ||
154 | do_shutdown (test_ctx, tc); | ||
155 | } | ||
156 | |||
157 | |||
158 | /** | ||
146 | * Main point of test execution | 159 | * Main point of test execution |
147 | */ | 160 | */ |
148 | static void | 161 | static void |
@@ -162,20 +175,20 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
162 | goto end; | 175 | goto end; |
163 | test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg); | 176 | test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg); |
164 | test_ctx->peer = | 177 | test_ctx->peer = |
165 | GNUNET_TESTING_peer_configure2 (test_ctx->system, | 178 | GNUNET_TESTING_peer_configure (test_ctx->system, |
166 | test_ctx->cfg, | 179 | test_ctx->cfg, |
167 | 0, &id, &emsg, | 180 | 0, &id, &emsg); |
168 | &peer_status_cb, | ||
169 | test_ctx); | ||
170 | if (NULL == test_ctx->peer) | 181 | if (NULL == test_ctx->peer) |
171 | { | 182 | { |
172 | if (NULL != emsg) | 183 | if (NULL != emsg) |
173 | printf ("Test failed upon error: %s", emsg); | 184 | printf ("Test failed upon error: %s", emsg); |
174 | goto end; | 185 | goto end; |
175 | } | 186 | } |
176 | if (GNUNET_OK != GNUNET_TESTING_peer_start2 (test_ctx->peer, | 187 | if (GNUNET_OK != GNUNET_TESTING_peer_start (test_ctx->peer)) |
177 | GNUNET_TIME_UNIT_MINUTES)) | ||
178 | goto end; | 188 | goto end; |
189 | test_ctx->state = PEER_STARTED; | ||
190 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
191 | &do_shutdown, test_ctx); | ||
179 | return; | 192 | return; |
180 | 193 | ||
181 | end: | 194 | end: |