2 This file is part of GNUnet
3 (C) 2012 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file testbed/test_gnunet_testbed_helper.c
23 * @brief Testcase for testing gnunet-testbed-helper.c
24 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
28 #include "gnunet_util_lib.h"
29 #include "testbed_helper.h"
32 * Generic logging shortcut
34 #define LOG(kind,...) \
35 GNUNET_log (kind, __VA_ARGS__)
39 * Handle to the helper process
41 static struct GNUNET_HELPER_Handle *helper;
46 static struct GNUNET_TESTBED_HelperInit msg;
52 static struct GNUNET_HELPER_SendHandle *shandle;
55 * Abort task identifier
57 static GNUNET_SCHEDULER_TaskIdentifier abort_task;
60 * Shutdown task identifier
62 static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
69 * @param tc the task context
72 do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
74 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
75 GNUNET_SCHEDULER_cancel (abort_task);
76 GNUNET_HELPER_stop (helper);
81 * abort task to run on test timed out
84 * @param tc the task context
87 do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
89 LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
90 abort_task = GNUNET_SCHEDULER_NO_TASK;
91 GNUNET_HELPER_send_cancel (shandle);
92 if (GNUNET_SCHEDULER_NO_TASK == shutdown_task)
93 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
98 * Continuation function.
101 * @param result GNUNET_OK on success,
102 * GNUNET_NO if helper process died
103 * GNUNET_SYSERR during GNUNET_HELPER_stop
106 cont_cb (void *cls, int result)
109 LOG (GNUNET_ERROR_TYPE_DEBUG, "Message sent\n");
110 GNUNET_assert (GNUNET_OK == result);
111 if (GNUNET_SCHEDULER_NO_TASK == shutdown_task)
112 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
118 * Main function that will be run.
121 * @param args remaining command-line arguments
122 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
123 * @param cfg configuration
126 run (void *cls, char *const *args, const char *cfgfile,
127 const struct GNUNET_CONFIGURATION_Handle * cfg)
129 char * const binary_argv[] = {
130 "gnunet-testbed-helper",
134 helper = GNUNET_HELPER_start ("gnunet-testbed-helper", binary_argv,
136 GNUNET_assert (NULL != helper);
137 msg.header.size = htons (sizeof (struct GNUNET_TESTBED_HelperInit));
138 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT);
139 msg.cname_size = htons (0);
140 msg.config_size = htons (0);
141 shandle = GNUNET_HELPER_send (helper,
142 (const struct GNUNET_MessageHeader *) &msg,
143 GNUNET_NO, cont_cb, NULL);
144 GNUNET_assert (NULL != shandle);
145 abort_task = GNUNET_SCHEDULER_add_delayed
146 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1), &do_abort, NULL);
153 * @param argc the number of command line arguments
154 * @param argv command line arg array
155 * @return return code
157 int main (int argc, char **argv)
159 struct GNUNET_GETOPT_CommandLineOption options[] = {
160 GNUNET_GETOPT_OPTION_END
164 GNUNET_PROGRAM_run (argc, argv, "test_gnunet_testbed_helper",
165 "Testcase for testing gnunet-testbed-helper.c",
166 options, &run, NULL))