diff options
Diffstat (limited to 'src/testbed/testbed_api_test.c')
-rw-r--r-- | src/testbed/testbed_api_test.c | 175 |
1 files changed, 0 insertions, 175 deletions
diff --git a/src/testbed/testbed_api_test.c b/src/testbed/testbed_api_test.c deleted file mode 100644 index d9eb384ba..000000000 --- a/src/testbed/testbed_api_test.c +++ /dev/null | |||
@@ -1,175 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2008--2013 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 testbed/testbed_api_test.c | ||
23 | * @brief high-level test function | ||
24 | * @author Christian Grothoff | ||
25 | * @author Sree Harsha Totakura | ||
26 | * @author Tobias Frisch | ||
27 | */ | ||
28 | #include "platform.h" | ||
29 | #include "gnunet_testbed_service.h" | ||
30 | #include "testbed.h" | ||
31 | |||
32 | |||
33 | /** | ||
34 | * Context information for test run | ||
35 | */ | ||
36 | struct TestRunContext | ||
37 | { | ||
38 | /** | ||
39 | * Test master callback | ||
40 | */ | ||
41 | GNUNET_TESTBED_TestMaster test_master; | ||
42 | |||
43 | /** | ||
44 | * Closure for test master | ||
45 | */ | ||
46 | void *test_master_cls; | ||
47 | |||
48 | /** | ||
49 | * The controller event callback | ||
50 | */ | ||
51 | GNUNET_TESTBED_ControllerCallback cc; | ||
52 | |||
53 | /** | ||
54 | * Closure for the above callback | ||
55 | */ | ||
56 | void *cc_cls; | ||
57 | |||
58 | /** | ||
59 | * event mask for the controller callback | ||
60 | */ | ||
61 | uint64_t event_mask; | ||
62 | |||
63 | /** | ||
64 | * Number of peers to start | ||
65 | */ | ||
66 | unsigned int num_peers; | ||
67 | }; | ||
68 | |||
69 | |||
70 | /** | ||
71 | * Main run function. | ||
72 | * | ||
73 | * @param cls NULL | ||
74 | * @param args arguments passed to GNUNET_PROGRAM_run | ||
75 | * @param cfgfile the path to configuration file | ||
76 | * @param config the configuration file handle | ||
77 | */ | ||
78 | static void | ||
79 | run (void *cls, char *const *args, const char *cfgfile, | ||
80 | const struct GNUNET_CONFIGURATION_Handle *config) | ||
81 | { | ||
82 | struct TestRunContext *rc = cls; | ||
83 | |||
84 | GNUNET_TESTBED_run (NULL, config, rc->num_peers, rc->event_mask, rc->cc, | ||
85 | rc->cc_cls, rc->test_master, rc->test_master_cls); | ||
86 | } | ||
87 | |||
88 | |||
89 | /** | ||
90 | * Convenience method for running a "simple" test on the local system | ||
91 | * with a single call from 'main'. Underlay and overlay topology are | ||
92 | * configured using the "UNDERLAY" and "OVERLAY" options in the | ||
93 | * "[testbed]" section of the configuration (with possible options | ||
94 | * given in "UNDERLAY_XXX" and/or "OVERLAY_XXX"). | ||
95 | * | ||
96 | * The test is to be terminated using a call to | ||
97 | * "GNUNET_SCHEDULER_shutdown". If starting the test fails, | ||
98 | * the program is stopped without 'master' ever being run. | ||
99 | * | ||
100 | * NOTE: this function should be called from 'main', NOT from | ||
101 | * within a GNUNET_SCHEDULER-loop. This function will initialize | ||
102 | * the scheduler loop, the testbed and then pass control to | ||
103 | * 'master'. | ||
104 | * | ||
105 | * @param testname name of the testcase (to configure logging, etc.) | ||
106 | * @param cfg_filename configuration filename to use | ||
107 | * (for testbed, controller and peers) | ||
108 | * @param num_peers number of peers to start | ||
109 | * @param event_mask bit mask with set of events to call 'cc' for; | ||
110 | * or-ed values of "1LL" shifted by the | ||
111 | * respective 'enum GNUNET_TESTBED_EventType' | ||
112 | * (e.g. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...") | ||
113 | * @param cc controller callback to invoke on events; This callback is called | ||
114 | * for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't | ||
115 | * set in the event_mask as this is the only way get access to the | ||
116 | * handle of each peer | ||
117 | * @param cc_cls closure for cc | ||
118 | * @param test_master task to run once the test is ready | ||
119 | * @param test_master_cls closure for @a test_master | ||
120 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success | ||
121 | */ | ||
122 | int | ||
123 | GNUNET_TESTBED_test_run (const char *testname, | ||
124 | const char *cfg_filename, | ||
125 | unsigned int num_peers, | ||
126 | uint64_t event_mask, | ||
127 | GNUNET_TESTBED_ControllerCallback cc, | ||
128 | void *cc_cls, | ||
129 | GNUNET_TESTBED_TestMaster test_master, | ||
130 | void *test_master_cls) | ||
131 | { | ||
132 | char *argv2[] = { | ||
133 | NULL, | ||
134 | "-c", | ||
135 | NULL, | ||
136 | NULL | ||
137 | }; | ||
138 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
139 | GNUNET_GETOPT_OPTION_END | ||
140 | }; | ||
141 | struct TestRunContext *rc; | ||
142 | int ret; | ||
143 | |||
144 | argv2[0] = GNUNET_strdup (testname); | ||
145 | argv2[2] = GNUNET_strdup (cfg_filename); | ||
146 | GNUNET_assert (NULL != test_master); | ||
147 | GNUNET_assert (num_peers > 0); | ||
148 | |||
149 | char* envcfg = getenv(ENV_TESTBED_CONFIG); | ||
150 | setenv(ENV_TESTBED_CONFIG, cfg_filename, 1); | ||
151 | |||
152 | rc = GNUNET_malloc (sizeof(struct TestRunContext) | ||
153 | + (num_peers * sizeof(struct GNUNET_TESTBED_Peer *))); | ||
154 | rc->test_master = test_master; | ||
155 | rc->test_master_cls = test_master_cls; | ||
156 | rc->num_peers = num_peers; | ||
157 | rc->event_mask = event_mask; | ||
158 | rc->cc = cc; | ||
159 | rc->cc_cls = cc_cls; | ||
160 | ret = GNUNET_PROGRAM_run ((sizeof(argv2) / sizeof(char *)) - 1, argv2, | ||
161 | testname, "nohelp", options, &run, rc); | ||
162 | |||
163 | if (envcfg) | ||
164 | setenv(ENV_TESTBED_CONFIG, envcfg, 1); | ||
165 | else | ||
166 | unsetenv(ENV_TESTBED_CONFIG); | ||
167 | |||
168 | GNUNET_free (rc); | ||
169 | GNUNET_free (argv2[0]); | ||
170 | GNUNET_free (argv2[2]); | ||
171 | return ret; | ||
172 | } | ||
173 | |||
174 | |||
175 | /* end of testbed_api_test.c */ | ||