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.c104
1 files changed, 51 insertions, 53 deletions
diff --git a/src/testing/test_testing_sharedservices.c b/src/testing/test_testing_sharedservices.c
index e7d285bb9..86e9f017c 100644
--- a/src/testing/test_testing_sharedservices.c
+++ b/src/testing/test_testing_sharedservices.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -28,8 +28,8 @@
28#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
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,8 +41,7 @@ int status;
41/** 41/**
42 * The testing context 42 * The testing context
43 */ 43 */
44struct TestingContext 44struct TestingContext {
45{
46 /** 45 /**
47 * The testing system 46 * The testing system
48 */ 47 */
@@ -66,26 +65,26 @@ struct TestingContext
66 * @param cls the testing context 65 * @param cls the testing context
67 */ 66 */
68static void 67static void
69do_shutdown (void *cls) 68do_shutdown(void *cls)
70{ 69{
71 struct TestingContext *test_ctx = cls; 70 struct TestingContext *test_ctx = cls;
72 struct GNUNET_TESTING_Peer *peer; 71 struct GNUNET_TESTING_Peer *peer;
73 unsigned int cnt; 72 unsigned int cnt;
74 73
75 GNUNET_assert (NULL != test_ctx); 74 GNUNET_assert(NULL != test_ctx);
76 for (cnt = 0; cnt < NUM_PEERS; cnt++) 75 for (cnt = 0; cnt < NUM_PEERS; cnt++)
77 { 76 {
78 peer = test_ctx->peers[cnt]; 77 peer = test_ctx->peers[cnt];
79 if (NULL == peer) 78 if (NULL == peer)
80 continue; 79 continue;
81 (void) GNUNET_TESTING_peer_stop (peer); 80 (void)GNUNET_TESTING_peer_stop(peer);
82 GNUNET_TESTING_peer_destroy (peer); 81 GNUNET_TESTING_peer_destroy(peer);
83 } 82 }
84 if (NULL != test_ctx->cfg) 83 if (NULL != test_ctx->cfg)
85 GNUNET_CONFIGURATION_destroy (test_ctx->cfg); 84 GNUNET_CONFIGURATION_destroy(test_ctx->cfg);
86 if (NULL != test_ctx->system) 85 if (NULL != test_ctx->system)
87 GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES); 86 GNUNET_TESTING_system_destroy(test_ctx->system, GNUNET_YES);
88 GNUNET_free (test_ctx); 87 GNUNET_free(test_ctx);
89} 88}
90 89
91 90
@@ -93,72 +92,71 @@ do_shutdown (void *cls)
93 * Main point of test execution 92 * Main point of test execution
94 */ 93 */
95static void 94static void
96run (void *cls, char *const *args, const char *cfgfile, 95run(void *cls, char *const *args, const char *cfgfile,
97 const struct GNUNET_CONFIGURATION_Handle *cfg) 96 const struct GNUNET_CONFIGURATION_Handle *cfg)
98{ 97{
99 struct TestingContext *test_ctx; 98 struct TestingContext *test_ctx;
100 char *emsg; 99 char *emsg;
101 struct GNUNET_PeerIdentity id; 100 struct GNUNET_PeerIdentity id;
102 struct GNUNET_TESTING_SharedService ss[] = { 101 struct GNUNET_TESTING_SharedService ss[] = {
103 {"peerinfo", cfg, 2}, 102 { "peerinfo", cfg, 2 },
104 {NULL, NULL, 0} 103 { NULL, NULL, 0 }
105 }; 104 };
106 struct GNUNET_TESTING_Peer *peer; 105 struct GNUNET_TESTING_Peer *peer;
107 unsigned int cnt; 106 unsigned int cnt;
108 107
109 test_ctx = GNUNET_new (struct TestingContext); 108 test_ctx = GNUNET_new(struct TestingContext);
110 test_ctx->system = 109 test_ctx->system =
111 GNUNET_TESTING_system_create ("test-gnunet-testing", 110 GNUNET_TESTING_system_create("test-gnunet-testing",
112 "127.0.0.1", NULL, ss); 111 "127.0.0.1", NULL, ss);
113 emsg = NULL; 112 emsg = NULL;
114 if (NULL == test_ctx->system) 113 if (NULL == test_ctx->system)
115 goto end; 114 goto end;
116 test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg); 115 test_ctx->cfg = GNUNET_CONFIGURATION_dup(cfg);
117 for (cnt = 0; cnt < NUM_PEERS; cnt++) 116 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 { 117 {
124 if (NULL != emsg) 118 peer = GNUNET_TESTING_peer_configure(test_ctx->system,
125 printf ("Test failed upon error: %s", emsg); 119 test_ctx->cfg,
126 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;
127 } 133 }
128 if (GNUNET_OK != GNUNET_TESTING_peer_start (peer))
129 {
130 GNUNET_TESTING_peer_destroy (peer);
131 goto end;
132 }
133 test_ctx->peers[cnt] = peer;
134 }
135 status = GNUNET_OK; 134 status = GNUNET_OK;
136 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 135 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
137 &do_shutdown, test_ctx); 136 &do_shutdown, test_ctx);
138 return; 137 return;
139 138
140 end: 139end:
141 GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx); 140 GNUNET_SCHEDULER_add_now(&do_shutdown, test_ctx);
142 GNUNET_free_non_null (emsg); 141 GNUNET_free_non_null(emsg);
143} 142}
144 143
145 144
146int main (int argc, char *argv[]) 145int main(int argc, char *argv[])
147{ 146{
148 struct GNUNET_GETOPT_CommandLineOption options[] = { 147 struct GNUNET_GETOPT_CommandLineOption options[] = {
149 GNUNET_GETOPT_OPTION_END 148 GNUNET_GETOPT_OPTION_END
150 }; 149 };
151 char *const argv2[] = { "test_testing_sharedservices", 150 char *const argv2[] = { "test_testing_sharedservices",
152 "-c", "test_testing_sharedservices.conf", 151 "-c", "test_testing_sharedservices.conf",
153 NULL 152 NULL };
154 };
155 153
156 status = GNUNET_SYSERR; 154 status = GNUNET_SYSERR;
157 if (GNUNET_OK != 155 if (GNUNET_OK !=
158 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, 156 GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2,
159 "test_testing_sharedservices", 157 "test_testing_sharedservices",
160 "test case for testing service sharing among peers started by testing", 158 "test case for testing service sharing among peers started by testing",
161 options, &run, NULL)) 159 options, &run, NULL))
162 return 1; 160 return 1;
163 return (GNUNET_OK == status) ? 0 : 3; 161 return (GNUNET_OK == status) ? 0 : 3;
164} 162}