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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
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 * The status of the test
43 struct TestingContext {
47 struct GNUNET_TESTING_System *system;
50 * The peer which has been started by the testing system
52 struct GNUNET_TESTING_Peer *peer;
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;
71 GNUNET_assert(NULL != test_ctx);
72 if (NULL != test_ctx->peer)
74 (void)GNUNET_TESTING_peer_stop(test_ctx->peer);
75 GNUNET_TESTING_peer_destroy(test_ctx->peer);
77 if (NULL != test_ctx->cfg)
78 GNUNET_CONFIGURATION_destroy(test_ctx->cfg);
79 if (NULL != test_ctx->system)
80 GNUNET_TESTING_system_destroy(test_ctx->system, GNUNET_YES);
81 GNUNET_free(test_ctx);
86 * Main point of test execution
89 run(void *cls, char *const *args, const char *cfgfile,
90 const struct GNUNET_CONFIGURATION_Handle *cfg)
92 struct TestingContext *test_ctx;
94 struct GNUNET_PeerIdentity id;
96 test_ctx = GNUNET_new(struct TestingContext);
98 GNUNET_TESTING_system_create("test-gnunet-testing",
99 "127.0.0.1", NULL, NULL);
101 if (NULL == test_ctx->system)
103 test_ctx->cfg = GNUNET_CONFIGURATION_dup(cfg);
105 GNUNET_TESTING_peer_configure(test_ctx->system,
108 if (NULL == test_ctx->peer)
111 printf("Test failed upon error: %s", emsg);
114 if (GNUNET_OK != GNUNET_TESTING_peer_start(test_ctx->peer))
119 GNUNET_SCHEDULER_add_now(&do_shutdown, test_ctx);
120 GNUNET_free_non_null(emsg);
124 int main(int argc, char *argv[])
126 struct GNUNET_GETOPT_CommandLineOption options[] = {
127 GNUNET_GETOPT_OPTION_END
130 status = GNUNET_SYSERR;
132 GNUNET_PROGRAM_run(argc, argv,
133 "test_testing_peerstartup",
134 "test case for peerstartup using new testing library",
135 options, &run, NULL))
137 return (GNUNET_OK == status) ? 0 : 1;
140 /* end of test_testing_peerstartup.c */