diff options
Diffstat (limited to 'src/testing/test_testing_sharedservices.c')
-rw-r--r-- | src/testing/test_testing_sharedservices.c | 167 |
1 files changed, 167 insertions, 0 deletions
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 | */ | ||
39 | int status; | ||
40 | |||
41 | /** | ||
42 | * The testing context | ||
43 | */ | ||
44 | struct 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 | */ | ||
69 | static void | ||
70 | do_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 | */ | ||
96 | static void | ||
97 | run (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 | |||
147 | int 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 */ | ||