diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-29 22:23:39 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-29 22:23:39 +0000 |
commit | 25a2663e80f137f1f1eb5452f896acfb918c414a (patch) | |
tree | 1ceecf80f7f7d7e8317208df110b0f68b3bf06f2 /src/testbed/test_testbed_api_testbed_run.c | |
parent | 7252393613f08dea54b5838691e6e608818901c3 (diff) | |
download | gnunet-25a2663e80f137f1f1eb5452f896acfb918c414a.tar.gz gnunet-25a2663e80f137f1f1eb5452f896acfb918c414a.zip |
added the forgotten test case
Diffstat (limited to 'src/testbed/test_testbed_api_testbed_run.c')
-rw-r--r-- | src/testbed/test_testbed_api_testbed_run.c | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/src/testbed/test_testbed_api_testbed_run.c b/src/testbed/test_testbed_api_testbed_run.c new file mode 100644 index 000000000..dc6bd1ea6 --- /dev/null +++ b/src/testbed/test_testbed_api_testbed_run.c | |||
@@ -0,0 +1,159 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2008--2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
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. | ||
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 | General Public License for more details. | ||
14 | |||
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. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file testbed/test_testbed_api_testbed_run.c | ||
23 | * @brief Test cases for testing high-level testbed management | ||
24 | * @author Sree Harsha Totakura <sreeharsha@totakura.in> | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_common.h" | ||
29 | #include "gnunet_testbed_service.h" | ||
30 | |||
31 | /** | ||
32 | * Testbed run handle | ||
33 | */ | ||
34 | static struct GNUNET_TESTBED_RunHandle *rh; | ||
35 | |||
36 | /** | ||
37 | * Abort task identifier | ||
38 | */ | ||
39 | static GNUNET_SCHEDULER_TaskIdentifier abort_task; | ||
40 | |||
41 | /** | ||
42 | * Testing result | ||
43 | */ | ||
44 | static int result; | ||
45 | |||
46 | |||
47 | /** | ||
48 | * Shutdown nicely | ||
49 | * | ||
50 | * @param cls NULL | ||
51 | * @param tc the task context | ||
52 | */ | ||
53 | static void | ||
54 | do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
55 | { | ||
56 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) | ||
57 | GNUNET_SCHEDULER_cancel (abort_task); | ||
58 | if (NULL != rh) | ||
59 | GNUNET_TESTBED_shutdown_run (rh); | ||
60 | } | ||
61 | |||
62 | |||
63 | /** | ||
64 | * abort task to run on test timed out | ||
65 | * | ||
66 | * @param cls NULL | ||
67 | * @param tc the task context | ||
68 | */ | ||
69 | static void | ||
70 | do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
71 | { | ||
72 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); | ||
73 | abort_task = GNUNET_SCHEDULER_NO_TASK; | ||
74 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
75 | GNUNET_SCHEDULER_shutdown (); /* Stop the scheduler */ | ||
76 | } | ||
77 | |||
78 | |||
79 | /** | ||
80 | * Task to be executed when peers are ready | ||
81 | * | ||
82 | * @param cls NULL | ||
83 | * @param tc the task context | ||
84 | */ | ||
85 | static void | ||
86 | master_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
87 | { | ||
88 | result = GNUNET_OK; | ||
89 | /* Artificial delay */ | ||
90 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_shutdown, NULL); | ||
91 | } | ||
92 | |||
93 | |||
94 | /** | ||
95 | * Controller event callback | ||
96 | * | ||
97 | * @param cls NULL | ||
98 | * @param event the controller event | ||
99 | */ | ||
100 | static void | ||
101 | controller_event_cb (void *cls, | ||
102 | const struct GNUNET_TESTBED_EventInformation *event) | ||
103 | { | ||
104 | if (GNUNET_TESTBED_ET_PEER_START == event->type) | ||
105 | return; | ||
106 | GNUNET_break (0); | ||
107 | } | ||
108 | |||
109 | |||
110 | /** | ||
111 | * Main run function. | ||
112 | * | ||
113 | * @param cls NULL | ||
114 | * @param args arguments passed to GNUNET_PROGRAM_run | ||
115 | * @param cfgfile the path to configuration file | ||
116 | * @param cfg the configuration file handle | ||
117 | */ | ||
118 | static void | ||
119 | run (void *cls, char *const *args, const char *cfgfile, | ||
120 | const struct GNUNET_CONFIGURATION_Handle *config) | ||
121 | { | ||
122 | uint64_t event_mask; | ||
123 | |||
124 | event_mask = 0; | ||
125 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); | ||
126 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); | ||
127 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); | ||
128 | event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT); | ||
129 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); | ||
130 | rh = GNUNET_TESTBED_run (NULL, config, 2, event_mask, &controller_event_cb, | ||
131 | NULL, &master_task, NULL); | ||
132 | abort_task = GNUNET_SCHEDULER_add_delayed | ||
133 | (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), &do_abort, NULL); | ||
134 | } | ||
135 | |||
136 | |||
137 | /** | ||
138 | * Main function | ||
139 | */ | ||
140 | int main (int argc, char **argv) | ||
141 | { | ||
142 | int ret; | ||
143 | char *const argv2[] = { | ||
144 | "test_testbed_api_testbed_run", | ||
145 | "-c", "test_testbed_api.conf", | ||
146 | NULL | ||
147 | }; | ||
148 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
149 | GNUNET_GETOPT_OPTION_END | ||
150 | }; | ||
151 | |||
152 | result = GNUNET_SYSERR; | ||
153 | ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | ||
154 | "test_testbed_api_testbed_run", "nohelp", options, | ||
155 | &run, NULL); | ||
156 | if ((GNUNET_OK != ret) || (GNUNET_OK != result)) | ||
157 | return 1; | ||
158 | return 0; | ||
159 | } | ||