2 This file is part of GNUnet
3 (C) 2008--2013 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_testbed_api_hosts.c
23 * @brief tests cases for testbed_api_hosts.c
24 * @author Sree Harsha Totakura
28 #include "gnunet_util_lib.h"
29 #include "gnunet_testbed_service.h"
30 #include "testbed_api_hosts.h"
33 #define TIME_REL_SECS(sec) \
34 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec)
37 * configuration handle to use as template configuration while creating hosts
39 static struct GNUNET_CONFIGURATION_Handle *cfg;
42 * Host we are creating and using
44 static struct GNUNET_TESTBED_Host *host;
47 * An array of hosts which are loaded from a file
49 static struct GNUNET_TESTBED_Host **hosts;
52 * Number of hosts in the above list
54 static unsigned int num_hosts;
62 * Shutdown task identifier
64 struct GNUNET_SCHEDULER_Task * shutdown_id;
70 * @param tc the task context
73 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
75 GNUNET_TESTBED_host_destroy (host);
76 while (0 != num_hosts)
78 GNUNET_TESTBED_host_destroy (hosts[num_hosts - 1]);
84 GNUNET_CONFIGURATION_destroy (cfg);
94 * @param args arguments passed to GNUNET_PROGRAM_run
95 * @param cfgfile the path to configuration file
96 * @param cfg the configuration file handle
99 run (void *cls, char *const *args, const char *cfgfile,
100 const struct GNUNET_CONFIGURATION_Handle *config)
104 cfg = GNUNET_CONFIGURATION_dup (config);
105 host = GNUNET_TESTBED_host_create ("localhost", NULL, cfg, 0);
106 GNUNET_assert (NULL != host);
107 GNUNET_assert (0 != GNUNET_TESTBED_host_get_id_ (host));
108 GNUNET_TESTBED_host_destroy (host);
109 host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0);
110 GNUNET_assert (NULL != host);
111 GNUNET_assert (0 == GNUNET_TESTBED_host_get_id_ (host));
112 GNUNET_assert (host == GNUNET_TESTBED_host_lookup_by_id_ (0));
114 num_hosts = GNUNET_TESTBED_hosts_load_from_file ("sample_hosts.txt", cfg, &hosts);
115 GNUNET_assert (7 == num_hosts);
116 GNUNET_assert (NULL != hosts);
117 for (cnt = 0; cnt < num_hosts; cnt++)
121 GNUNET_assert (0 == strcmp ("totakura",
122 GNUNET_TESTBED_host_get_username_
124 GNUNET_assert (NULL != GNUNET_TESTBED_host_get_hostname (hosts[cnt]));
125 GNUNET_assert (22 == GNUNET_TESTBED_host_get_ssh_port_ (hosts[cnt]));
129 GNUNET_assert (0 == strcmp ("totakura",
130 GNUNET_TESTBED_host_get_username_
132 GNUNET_assert (NULL != GNUNET_TESTBED_host_get_hostname (hosts[cnt]));
133 GNUNET_assert (2022 == GNUNET_TESTBED_host_get_ssh_port_ (hosts[cnt]));
137 GNUNET_assert (0 == strcmp ("totakura",
138 GNUNET_TESTBED_host_get_username_
140 GNUNET_assert (0 == strcmp ("asgard.realm",
141 GNUNET_TESTBED_host_get_hostname
143 GNUNET_assert (22 == GNUNET_TESTBED_host_get_ssh_port_ (hosts[cnt]));
147 GNUNET_assert (NULL == GNUNET_TESTBED_host_get_username_ (hosts[cnt]));
148 GNUNET_assert (0 == strcmp ("rivendal",
149 GNUNET_TESTBED_host_get_hostname
151 GNUNET_assert (22 == GNUNET_TESTBED_host_get_ssh_port_ (hosts[cnt]));
155 GNUNET_assert (NULL == GNUNET_TESTBED_host_get_username_ (hosts[cnt]));
156 GNUNET_assert (0 == strcmp ("rohan",
157 GNUNET_TESTBED_host_get_hostname
159 GNUNET_assert (561 == GNUNET_TESTBED_host_get_ssh_port_ (hosts[cnt]));
164 GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (0), &do_shutdown, NULL);
169 main (int argc, char **argv)
171 char *const argv2[] = { "test_testbed_api_hosts",
172 "-c", "test_testbed_api.conf",
175 struct GNUNET_GETOPT_CommandLineOption options[] = {
176 GNUNET_GETOPT_OPTION_END
179 status = GNUNET_SYSERR;
181 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
182 "test_testbed_api_hosts", "nohelp", options, &run,
185 return (GNUNET_OK == status) ? 0 : 1;
188 /* end of test_testbed_api_hosts.c */