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
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.
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.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
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>
28 #include "gnunet_util_lib.h"
29 #include "gnunet_testing_lib.h"
31 #define LOG(kind,...) \
32 GNUNET_log (kind, __VA_ARGS__)
37 * The status of the test
49 struct GNUNET_TESTING_System *system;
52 * The peer which has been started by the testing system
54 struct GNUNET_TESTING_Peer *peers[NUM_PEERS];
57 * The running configuration of the peer
59 struct GNUNET_CONFIGURATION_Handle *cfg;
66 * @param cls the testing context
69 do_shutdown (void *cls)
71 struct TestingContext *test_ctx = cls;
72 struct GNUNET_TESTING_Peer *peer;
75 GNUNET_assert (NULL != test_ctx);
76 for (cnt = 0; cnt < NUM_PEERS; cnt++)
78 peer = test_ctx->peers[cnt];
81 (void) GNUNET_TESTING_peer_stop (peer);
82 GNUNET_TESTING_peer_destroy (peer);
84 if (NULL != test_ctx->cfg)
85 GNUNET_CONFIGURATION_destroy (test_ctx->cfg);
86 if (NULL != test_ctx->system)
87 GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES);
88 GNUNET_free (test_ctx);
93 * Main point of test execution
96 run (void *cls, char *const *args, const char *cfgfile,
97 const struct GNUNET_CONFIGURATION_Handle *cfg)
99 struct TestingContext *test_ctx;
101 struct GNUNET_PeerIdentity id;
102 struct GNUNET_TESTING_SharedService ss[] = {
103 {"peerinfo", cfg, 2},
106 struct GNUNET_TESTING_Peer *peer;
109 test_ctx = GNUNET_new (struct TestingContext);
111 GNUNET_TESTING_system_create ("test-gnunet-testing",
112 "127.0.0.1", NULL, ss);
114 if (NULL == test_ctx->system)
116 test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg);
117 for (cnt = 0; cnt < NUM_PEERS; cnt++)
119 peer = GNUNET_TESTING_peer_configure (test_ctx->system,
125 printf ("Test failed upon error: %s", emsg);
128 if (GNUNET_OK != GNUNET_TESTING_peer_start (peer))
130 GNUNET_TESTING_peer_destroy (peer);
133 test_ctx->peers[cnt] = peer;
136 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
137 &do_shutdown, test_ctx);
141 GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx);
142 GNUNET_free_non_null (emsg);
146 int main (int argc, char *argv[])
148 struct GNUNET_GETOPT_CommandLineOption options[] = {
149 GNUNET_GETOPT_OPTION_END
151 char *const argv2[] = { "test_testing_sharedservices",
152 "-c", "test_testing_sharedservices.conf",
156 status = GNUNET_SYSERR;
158 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
159 "test_testing_sharedservices",
160 "test case for testing service sharing among peers started by testing",
161 options, &run, NULL))
163 return (GNUNET_OK == status) ? 0 : 3;
166 /* end of test_testing_sharedservices.c */