aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_netjail_start.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing_api_cmd_netjail_start.c')
-rw-r--r--src/testing/testing_api_cmd_netjail_start.c148
1 files changed, 64 insertions, 84 deletions
diff --git a/src/testing/testing_api_cmd_netjail_start.c b/src/testing/testing_api_cmd_netjail_start.c
index 536b356a6..35fb90f3c 100644
--- a/src/testing/testing_api_cmd_netjail_start.c
+++ b/src/testing/testing_api_cmd_netjail_start.c
@@ -19,7 +19,7 @@
19 */ 19 */
20 20
21/** 21/**
22 * @file testing/testing_api_cmd_hello_world.c 22 * @file testing/testing_api_cmd_netjail_start.c
23 * @brief Command to start the netjail script. 23 * @brief Command to start the netjail script.
24 * @author t3sserakt 24 * @author t3sserakt
25 */ 25 */
@@ -35,22 +35,24 @@
35 */ 35 */
36struct NetJailState 36struct NetJailState
37{ 37{
38 /**
39 * Context for our asynchronous completion.
40 */
41 struct GNUNET_TESTING_AsyncContext ac;
42
38 // Child Wait handle 43 // Child Wait handle
39 struct GNUNET_ChildWaitHandle *cwh; 44 struct GNUNET_ChildWaitHandle *cwh;
40 45
41 // Number of local nodes in each namespace.
42 char *local_m;
43
44 // The number of namespaces.
45 char *global_n;
46
47 /** 46 /**
48 * The process id of the start script. 47 * The process id of the start script.
49 */ 48 */
50 struct GNUNET_OS_Process *start_proc; 49 struct GNUNET_OS_Process *start_proc;
51 50
52 // Flag indication if the script finished. 51 /**
53 unsigned int finished; 52 * Configuration file for the test topology.
53 */
54 char *topology_config;
55
54}; 56};
55 57
56 58
@@ -59,8 +61,7 @@ struct NetJailState
59 * 61 *
60 */ 62 */
61static void 63static void
62netjail_start_cleanup (void *cls, 64netjail_start_cleanup (void *cls)
63 const struct GNUNET_TESTING_Command *cmd)
64{ 65{
65 struct NetJailState *ns = cls; 66 struct NetJailState *ns = cls;
66 67
@@ -87,20 +88,6 @@ netjail_start_cleanup (void *cls,
87 88
88 89
89/** 90/**
90 * Trait function of this cmd does nothing.
91 *
92 */
93static int
94netjail_start_traits (void *cls,
95 const void **ret,
96 const char *trait,
97 unsigned int index)
98{
99 return GNUNET_OK;
100}
101
102
103/**
104 * Callback which will be called if the setup script finished. 91 * Callback which will be called if the setup script finished.
105 * 92 *
106 */ 93 */
@@ -111,40 +98,40 @@ child_completed_callback (void *cls,
111{ 98{
112 struct NetJailState *ns = cls; 99 struct NetJailState *ns = cls;
113 100
101 GNUNET_OS_process_destroy (ns->start_proc);
102 ns->start_proc = NULL;
114 if (0 == exit_code) 103 if (0 == exit_code)
115 { 104 {
116 ns->finished = GNUNET_YES; 105 GNUNET_TESTING_async_finish (&ns->ac);
117 } 106 }
118 else 107 else
119 { 108 {
120 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 109 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
121 "Child completed with an error!\n"); 110 "Child failed with error %lu!\n",
122 ns->finished = GNUNET_SYSERR; 111 exit_code);
112 GNUNET_TESTING_async_fail (&ns->ac);
123 } 113 }
124 GNUNET_OS_process_destroy (ns->start_proc);
125 ns->start_proc = NULL;
126} 114}
127 115
128 116
129
130/** 117/**
131* The run method starts the script which setup the network namespaces. 118* The run method starts the script which setup the network namespaces.
132* 119*
133* @param cls closure. 120* @param cls closure.
134* @param cmd CMD being run.
135* @param is interpreter state. 121* @param is interpreter state.
136*/ 122*/
137static void 123static void
138netjail_start_run (void *cls, 124netjail_start_run (void *cls,
139 const struct GNUNET_TESTING_Command *cmd,
140 struct GNUNET_TESTING_Interpreter *is) 125 struct GNUNET_TESTING_Interpreter *is)
141{ 126{
142 struct NetJailState *ns = cls; 127 struct NetJailState *ns = cls;
143 char *const script_argv[] = {NETJAIL_START_SCRIPT, 128 char pid[15];
144 ns->local_m, 129 enum GNUNET_GenericReturnValue helper_check;
145 ns->global_n, 130
146 NULL}; 131 // FIXME: NETJAIL_START_SCRIPT like this is bad,
147 unsigned int helper_check = GNUNET_OS_check_helper_binary ( 132 // use location from share/gnunet/ of installed
133 // binary in case libgnunettesting is used as a lib!
134 helper_check = GNUNET_OS_check_helper_binary (
148 NETJAIL_START_SCRIPT, 135 NETJAIL_START_SCRIPT,
149 GNUNET_YES, 136 GNUNET_YES,
150 NULL); 137 NULL);
@@ -154,23 +141,38 @@ netjail_start_run (void *cls,
154 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 141 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
155 "No SUID for %s!\n", 142 "No SUID for %s!\n",
156 NETJAIL_START_SCRIPT); 143 NETJAIL_START_SCRIPT);
157 GNUNET_TESTING_interpreter_fail (); 144 GNUNET_TESTING_interpreter_fail (is);
145 return;
158 } 146 }
159 else if (GNUNET_NO == helper_check) 147 if (GNUNET_SYSERR == helper_check)
160 { 148 {
161 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 149 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
162 "%s not found!\n", 150 "%s not found!\n",
163 NETJAIL_START_SCRIPT); 151 NETJAIL_START_SCRIPT);
164 GNUNET_TESTING_interpreter_fail (); 152 GNUNET_TESTING_interpreter_fail (is);
153 return;
165 } 154 }
166 155
167 ns->start_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR, 156 GNUNET_snprintf (pid,
168 NULL, 157 sizeof (pid),
169 NULL, 158 "%u",
170 NULL, 159 getpid ());
171 NETJAIL_START_SCRIPT, 160 {
172 script_argv); 161 char *const script_argv[] = {
173 162 NETJAIL_START_SCRIPT,
163 ns->topology_config,
164 pid,
165 NULL
166 };
167
168 ns->start_proc
169 = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
170 NULL,
171 NULL,
172 NULL,
173 NETJAIL_START_SCRIPT,
174 script_argv);
175 }
174 ns->cwh = GNUNET_wait_child (ns->start_proc, 176 ns->cwh = GNUNET_wait_child (ns->start_proc,
175 &child_completed_callback, 177 &child_completed_callback,
176 ns); 178 ns);
@@ -179,51 +181,29 @@ netjail_start_run (void *cls,
179 181
180 182
181/** 183/**
182 * This function checks the flag NetJailState#finished, if this cmd finished.
183 *
184 */
185static int
186netjail_start_finish (void *cls,
187 GNUNET_SCHEDULER_TaskCallback cont,
188 void *cont_cls)
189{
190 struct NetJailState *ns = cls;
191
192 if (ns->finished)
193 {
194 cont (cont_cls);
195 }
196 return ns->finished;
197}
198
199/**
200 * Create command. 184 * Create command.
201 * 185 *
202 * @param label name for command. 186 * @param label name for command.
203 * @param local_m Number of local nodes in each namespace. 187 * @param topology_config Configuration file for the test topology.
204 * @param global_n The number of namespaces.
205 * @return command. 188 * @return command.
206 */ 189 */
207struct GNUNET_TESTING_Command 190struct GNUNET_TESTING_Command
208GNUNET_TESTING_cmd_netjail_start (const char *label, 191GNUNET_TESTING_cmd_netjail_start (const char *label,
209 char *local_m, 192 char *topology_config)
210 char *global_n)
211{ 193{
212 struct NetJailState *ns; 194 struct NetJailState *ns;
213 195
214 ns = GNUNET_new (struct NetJailState); 196 ns = GNUNET_new (struct NetJailState);
215 ns->local_m = local_m; 197 ns->topology_config = topology_config;
216 ns->global_n = global_n; 198 {
217 ns->finished = GNUNET_NO; 199 struct GNUNET_TESTING_Command cmd = {
218 200 .cls = ns,
219 struct GNUNET_TESTING_Command cmd = { 201 .label = label,
220 .cls = ns, 202 .run = &netjail_start_run,
221 .label = label, 203 .ac = &ns->ac,
222 .run = &netjail_start_run, 204 .cleanup = &netjail_start_cleanup
223 .finish = &netjail_start_finish, 205 };
224 .cleanup = &netjail_start_cleanup, 206
225 .traits = &netjail_start_traits 207 return cmd;
226 }; 208 }
227
228 return cmd;
229} 209}