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_new_peerstartup.c
23 * @brief test case for testing peer startup and shutdown using new testing
25 * @author Sree Harsha Totakura
29 #include "gnunet_util_lib.h"
30 #include "gnunet_testing_lib.h"
32 #define LOG(kind,...) \
33 GNUNET_log (kind, __VA_ARGS__)
36 #define FAIL_TEST(cond) \
40 if (GNUNET_OK == status) { \
41 status = GNUNET_SYSERR; \
48 * The status of the test
60 struct GNUNET_TESTING_System *system;
63 * The peer which has been started by the testing system
65 struct GNUNET_TESTING_Peer *peer;
68 * The running configuration of the peer
70 struct GNUNET_CONFIGURATION_Handle *cfg;
86 do_shutdown2 (void *cls)
88 struct TestingContext *test_ctx = cls;
90 if (NULL != test_ctx->peer)
91 GNUNET_TESTING_peer_destroy (test_ctx->peer);
92 if (NULL != test_ctx->cfg)
93 GNUNET_CONFIGURATION_destroy (test_ctx->cfg);
94 if (NULL != test_ctx->system)
95 GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES);
96 GNUNET_free (test_ctx);
104 * @param cls the testing context
107 do_shutdown (void *cls);
111 peer_status_cb (void *cls, struct GNUNET_TESTING_Peer *peer, int success)
113 struct TestingContext *test_ctx = cls;
115 switch (test_ctx->state)
121 FAIL_TEST (GNUNET_YES == success);
122 test_ctx->state = PEER_STOPPED;
123 GNUNET_SCHEDULER_add_now (&do_shutdown2, cls);
134 * @param cls the testing context
137 do_shutdown (void *cls)
139 struct TestingContext *test_ctx = cls;
141 GNUNET_assert (NULL != test_ctx);
142 if (NULL != test_ctx->peer)
144 FAIL_TEST (GNUNET_OK ==
145 GNUNET_TESTING_peer_stop_async (test_ctx->peer,
150 do_shutdown2 (test_ctx);
155 * Main point of test execution
158 run (void *cls, char *const *args, const char *cfgfile,
159 const struct GNUNET_CONFIGURATION_Handle *cfg)
161 struct TestingContext *test_ctx;
163 struct GNUNET_PeerIdentity id;
165 test_ctx = GNUNET_new (struct TestingContext);
167 GNUNET_TESTING_system_create ("test-gnunet-testing",
168 "127.0.0.1", NULL, NULL);
170 if (NULL == test_ctx->system)
172 test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg);
174 GNUNET_TESTING_peer_configure (test_ctx->system,
177 if (NULL == test_ctx->peer)
180 printf ("Test failed upon error: %s", emsg);
183 if (GNUNET_OK != GNUNET_TESTING_peer_start (test_ctx->peer))
185 test_ctx->state = PEER_STARTED;
186 FAIL_TEST (GNUNET_OK ==
187 GNUNET_TESTING_peer_stop_async (test_ctx->peer,
190 GNUNET_TESTING_peer_stop_async_cancel (test_ctx->peer);
191 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
192 &do_shutdown, test_ctx);
197 GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx);
198 GNUNET_free_non_null (emsg);
202 int main (int argc, char *argv[])
204 struct GNUNET_GETOPT_CommandLineOption options[] = {
205 GNUNET_GETOPT_OPTION_END
210 GNUNET_PROGRAM_run (argc, argv,
211 "test_testing_new_peerstartup",
212 "test case for peerstartup using new testing library",
213 options, &run, NULL))
215 return (GNUNET_OK == status) ? 0 : 1;
218 /* end of test_testing_peerstartup.c */