2 This file is part of GNUnet
3 Copyright (C) 2008, 2009, 2012 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
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 Affero General Public License for more details.
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/>.
20 * @file testing/test_testing_sharedservices.c
21 * @brief test case for testing service sharing among peers started by testing
22 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
26 #include "gnunet_util_lib.h"
27 #include "gnunet_testing_lib.h"
29 #define LOG(kind,...) \
30 GNUNET_log (kind, __VA_ARGS__)
35 * The status of the test
47 struct GNUNET_TESTING_System *system;
50 * The peer which has been started by the testing system
52 struct GNUNET_TESTING_Peer *peers[NUM_PEERS];
55 * The running configuration of the peer
57 struct GNUNET_CONFIGURATION_Handle *cfg;
64 * @param cls the testing context
67 do_shutdown (void *cls)
69 struct TestingContext *test_ctx = cls;
70 struct GNUNET_TESTING_Peer *peer;
73 GNUNET_assert (NULL != test_ctx);
74 for (cnt = 0; cnt < NUM_PEERS; cnt++)
76 peer = test_ctx->peers[cnt];
79 (void) GNUNET_TESTING_peer_stop (peer);
80 GNUNET_TESTING_peer_destroy (peer);
82 if (NULL != test_ctx->cfg)
83 GNUNET_CONFIGURATION_destroy (test_ctx->cfg);
84 if (NULL != test_ctx->system)
85 GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES);
86 GNUNET_free (test_ctx);
91 * Main point of test execution
94 run (void *cls, char *const *args, const char *cfgfile,
95 const struct GNUNET_CONFIGURATION_Handle *cfg)
97 struct TestingContext *test_ctx;
99 struct GNUNET_PeerIdentity id;
100 struct GNUNET_TESTING_SharedService ss[] = {
101 {"peerinfo", cfg, 2},
104 struct GNUNET_TESTING_Peer *peer;
107 test_ctx = GNUNET_new (struct TestingContext);
109 GNUNET_TESTING_system_create ("test-gnunet-testing",
110 "127.0.0.1", NULL, ss);
112 if (NULL == test_ctx->system)
114 test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg);
115 for (cnt = 0; cnt < NUM_PEERS; cnt++)
117 peer = GNUNET_TESTING_peer_configure (test_ctx->system,
123 printf ("Test failed upon error: %s", emsg);
126 if (GNUNET_OK != GNUNET_TESTING_peer_start (peer))
128 GNUNET_TESTING_peer_destroy (peer);
131 test_ctx->peers[cnt] = peer;
134 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
135 &do_shutdown, test_ctx);
139 GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx);
140 GNUNET_free_non_null (emsg);
144 int main (int argc, char *argv[])
146 struct GNUNET_GETOPT_CommandLineOption options[] = {
147 GNUNET_GETOPT_OPTION_END
149 char *const argv2[] = { "test_testing_sharedservices",
150 "-c", "test_testing_sharedservices.conf",
154 status = GNUNET_SYSERR;
156 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
157 "test_testing_sharedservices",
158 "test case for testing service sharing among peers started by testing",
159 options, &run, NULL))
161 return (GNUNET_OK == status) ? 0 : 3;
164 /* end of test_testing_sharedservices.c */