diff options
Diffstat (limited to 'src/service/testing/test_testing_peerstartup.c')
-rw-r--r-- | src/service/testing/test_testing_peerstartup.c | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/src/service/testing/test_testing_peerstartup.c b/src/service/testing/test_testing_peerstartup.c new file mode 100644 index 000000000..25cbb2a9f --- /dev/null +++ b/src/service/testing/test_testing_peerstartup.c | |||
@@ -0,0 +1,143 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2008, 2009, 2012 GNUnet e.V. | ||
4 | |||
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. | ||
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 | Affero General Public License for more details. | ||
14 | |||
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/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file testing/test_testing_new_peerstartup.c | ||
23 | * @brief test case for testing peer startup and shutdown using new testing | ||
24 | * library | ||
25 | * @author Sree Harsha Totakura | ||
26 | */ | ||
27 | |||
28 | #include "platform.h" | ||
29 | #include "gnunet_util_lib.h" | ||
30 | #include "gnunet_testing_lib.h" | ||
31 | |||
32 | #define LOG(kind, ...) \ | ||
33 | GNUNET_log (kind, __VA_ARGS__) | ||
34 | |||
35 | /** | ||
36 | * The status of the test | ||
37 | */ | ||
38 | int status; | ||
39 | |||
40 | /** | ||
41 | * The testing context | ||
42 | */ | ||
43 | struct TestingContext | ||
44 | { | ||
45 | /** | ||
46 | * The testing system | ||
47 | */ | ||
48 | struct GNUNET_TESTING_System *system; | ||
49 | |||
50 | /** | ||
51 | * The peer which has been started by the testing system | ||
52 | */ | ||
53 | struct GNUNET_TESTING_Peer *peer; | ||
54 | |||
55 | /** | ||
56 | * The running configuration of the peer | ||
57 | */ | ||
58 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
59 | }; | ||
60 | |||
61 | |||
62 | /** | ||
63 | * Task for shutdown | ||
64 | * | ||
65 | * @param cls the testing context | ||
66 | */ | ||
67 | static void | ||
68 | do_shutdown (void *cls) | ||
69 | { | ||
70 | struct TestingContext *test_ctx = cls; | ||
71 | |||
72 | GNUNET_assert (NULL != test_ctx); | ||
73 | if (NULL != test_ctx->peer) | ||
74 | { | ||
75 | (void) GNUNET_TESTING_peer_stop (test_ctx->peer); | ||
76 | GNUNET_TESTING_peer_destroy (test_ctx->peer); | ||
77 | } | ||
78 | if (NULL != test_ctx->cfg) | ||
79 | GNUNET_CONFIGURATION_destroy (test_ctx->cfg); | ||
80 | if (NULL != test_ctx->system) | ||
81 | GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES); | ||
82 | GNUNET_free (test_ctx); | ||
83 | } | ||
84 | |||
85 | |||
86 | /** | ||
87 | * Main point of test execution | ||
88 | */ | ||
89 | static void | ||
90 | run (void *cls, char *const *args, const char *cfgfile, | ||
91 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
92 | { | ||
93 | struct TestingContext *test_ctx; | ||
94 | char *emsg; | ||
95 | struct GNUNET_PeerIdentity id; | ||
96 | |||
97 | test_ctx = GNUNET_new (struct TestingContext); | ||
98 | test_ctx->system = | ||
99 | GNUNET_TESTING_system_create ("test-gnunet-testing", | ||
100 | "127.0.0.1", NULL, NULL); | ||
101 | emsg = NULL; | ||
102 | if (NULL == test_ctx->system) | ||
103 | goto end; | ||
104 | test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg); | ||
105 | test_ctx->peer = | ||
106 | GNUNET_TESTING_peer_configure (test_ctx->system, | ||
107 | test_ctx->cfg, | ||
108 | 0, &id, &emsg); | ||
109 | if (NULL == test_ctx->peer) | ||
110 | { | ||
111 | if (NULL != emsg) | ||
112 | printf ("Test failed upon error: %s", emsg); | ||
113 | goto end; | ||
114 | } | ||
115 | if (GNUNET_OK != GNUNET_TESTING_peer_start (test_ctx->peer)) | ||
116 | goto end; | ||
117 | status = GNUNET_OK; | ||
118 | |||
119 | end: | ||
120 | GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx); | ||
121 | GNUNET_free (emsg); | ||
122 | } | ||
123 | |||
124 | |||
125 | int | ||
126 | main (int argc, char *argv[]) | ||
127 | { | ||
128 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
129 | GNUNET_GETOPT_OPTION_END | ||
130 | }; | ||
131 | |||
132 | status = GNUNET_SYSERR; | ||
133 | if (GNUNET_OK != | ||
134 | GNUNET_PROGRAM_run (argc, argv, | ||
135 | "test_testing_peerstartup", | ||
136 | "test case for peerstartup using new testing library", | ||
137 | options, &run, NULL)) | ||
138 | return 1; | ||
139 | return (GNUNET_OK == status) ? 0 : 1; | ||
140 | } | ||
141 | |||
142 | |||
143 | /* end of test_testing_peerstartup.c */ | ||