diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-09-01 15:42:42 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-09-01 15:42:42 +0000 |
commit | 768cf4d37944fceb336ceb09aa85e2ae87e7a612 (patch) | |
tree | cf680d1b5306c3a066ec2f269f51c5754f3898e8 | |
parent | 427cbfbb202128ea8017c8da75f1a22b376ab2b0 (diff) | |
download | gnunet-768cf4d37944fceb336ceb09aa85e2ae87e7a612.tar.gz gnunet-768cf4d37944fceb336ceb09aa85e2ae87e7a612.zip |
tests for testbed_test_run and some fixes
-rw-r--r-- | src/testbed/Makefile.am | 7 | ||||
-rw-r--r-- | src/testbed/test_testbed_api_test.c | 93 | ||||
-rw-r--r-- | src/testbed/test_testbed_api_testbed_run.c | 38 | ||||
-rw-r--r-- | src/testbed/testbed_api_test.c | 18 | ||||
-rw-r--r-- | src/testbed/testbed_api_testbed.c | 2 |
5 files changed, 130 insertions, 28 deletions
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am index 2e07afee7..a865e468f 100644 --- a/src/testbed/Makefile.am +++ b/src/testbed/Makefile.am | |||
@@ -74,6 +74,7 @@ check_PROGRAMS = \ | |||
74 | test_testbed_api \ | 74 | test_testbed_api \ |
75 | test_testbed_api_operations \ | 75 | test_testbed_api_operations \ |
76 | test_testbed_api_testbed_run \ | 76 | test_testbed_api_testbed_run \ |
77 | test_testbed_api_test \ | ||
77 | test_gnunet_helper_testbed | 78 | test_gnunet_helper_testbed |
78 | 79 | ||
79 | if ENABLE_TEST_RUN | 80 | if ENABLE_TEST_RUN |
@@ -126,6 +127,12 @@ test_testbed_api_testbed_run_LDADD = \ | |||
126 | $(top_builddir)/src/util/libgnunetutil.la \ | 127 | $(top_builddir)/src/util/libgnunetutil.la \ |
127 | libgnunettestbed.la | 128 | libgnunettestbed.la |
128 | 129 | ||
130 | test_testbed_api_test_SOURCES = \ | ||
131 | test_testbed_api_test.c | ||
132 | test_testbed_api_test_LDADD = \ | ||
133 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
134 | libgnunettestbed.la | ||
135 | |||
129 | test_gnunet_helper_testbed_SOURCES = \ | 136 | test_gnunet_helper_testbed_SOURCES = \ |
130 | test_gnunet_helper_testbed.c | 137 | test_gnunet_helper_testbed.c |
131 | test_gnunet_helper_testbed_LDADD = \ | 138 | test_gnunet_helper_testbed_LDADD = \ |
diff --git a/src/testbed/test_testbed_api_test.c b/src/testbed/test_testbed_api_test.c new file mode 100644 index 000000000..83d18ce0c --- /dev/null +++ b/src/testbed/test_testbed_api_test.c | |||
@@ -0,0 +1,93 @@ | |||
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 src/testbed/test_testbed_api_test.c | ||
23 | * @brief testing cases for testing high level testbed api helper functions | ||
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 | * Number of peers we want to start | ||
33 | */ | ||
34 | #define NUM_PEERS 25 | ||
35 | |||
36 | /** | ||
37 | * Testing result | ||
38 | */ | ||
39 | static int result; | ||
40 | |||
41 | |||
42 | /** | ||
43 | * Shutdown nicely | ||
44 | * | ||
45 | * @param cls NULL | ||
46 | * @param tc the task context | ||
47 | */ | ||
48 | static void | ||
49 | do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
50 | { | ||
51 | GNUNET_SCHEDULER_shutdown (); | ||
52 | } | ||
53 | |||
54 | |||
55 | /** | ||
56 | * Signature of a main function for a testcase. | ||
57 | * | ||
58 | * @param cls closure | ||
59 | * @param num_peers number of peers in 'peers' | ||
60 | * @param peers handle to peers run in the testbed | ||
61 | */ | ||
62 | static void | ||
63 | test_master (void *cls, unsigned int num_peers, | ||
64 | struct GNUNET_TESTBED_Peer **peers) | ||
65 | { | ||
66 | unsigned int peer; | ||
67 | |||
68 | GNUNET_assert (NULL == cls); | ||
69 | GNUNET_assert (NUM_PEERS == num_peers); | ||
70 | GNUNET_assert (NULL != peers); | ||
71 | for (peer = 0; peer < num_peers; peer++) | ||
72 | GNUNET_assert (NULL != peers[peer]); | ||
73 | result = GNUNET_OK; | ||
74 | /* Artificial delay for shutdown */ | ||
75 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_shutdown, NULL); | ||
76 | } | ||
77 | |||
78 | |||
79 | /** | ||
80 | * Main function | ||
81 | */ | ||
82 | int | ||
83 | main (int argc, char **argv) | ||
84 | { | ||
85 | result = GNUNET_SYSERR; | ||
86 | GNUNET_TESTBED_test_run ("test_testbed_api_test", "test_testbed_api.conf", | ||
87 | NUM_PEERS, &test_master, NULL); | ||
88 | if (GNUNET_OK != result) | ||
89 | return 1; | ||
90 | return 0; | ||
91 | } | ||
92 | |||
93 | /* end of test_testbed_api_test.c */ | ||
diff --git a/src/testbed/test_testbed_api_testbed_run.c b/src/testbed/test_testbed_api_testbed_run.c index 2a7c77af0..8aee8d6cc 100644 --- a/src/testbed/test_testbed_api_testbed_run.c +++ b/src/testbed/test_testbed_api_testbed_run.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | (C) 2008--2012 Christian Grothoff (and other contributing authors) | 3 | (C) 2008--2012 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 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 | 7 | by the Free Software Foundation; either version 3, or (at your |
8 | option) any later version. | 8 | option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 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 | 16 | along with GNUnet; see the file COPYING. If not, write to the |
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file testbed/test_testbed_api_testbed_run.c | 22 | * @file testbed/test_testbed_api_testbed_run.c |
@@ -191,3 +191,5 @@ main (int argc, char **argv) | |||
191 | return 1; | 191 | return 1; |
192 | return 0; | 192 | return 0; |
193 | } | 193 | } |
194 | |||
195 | /* end of test_testbed_api_testbed_run.c */ | ||
diff --git a/src/testbed/testbed_api_test.c b/src/testbed/testbed_api_test.c index 0b3844011..1d49e706d 100644 --- a/src/testbed/testbed_api_test.c +++ b/src/testbed/testbed_api_test.c | |||
@@ -42,7 +42,7 @@ struct TestRunContext | |||
42 | * Closure for test master | 42 | * Closure for test master |
43 | */ | 43 | */ |
44 | void *test_master_cls; | 44 | void *test_master_cls; |
45 | 45 | ||
46 | /** | 46 | /** |
47 | * Number of peers to start | 47 | * Number of peers to start |
48 | */ | 48 | */ |
@@ -76,7 +76,7 @@ controller_event_cb (void *cls, | |||
76 | return; | 76 | return; |
77 | GNUNET_assert (GNUNET_TESTBED_ET_PEER_START == event->type); | 77 | GNUNET_assert (GNUNET_TESTBED_ET_PEER_START == event->type); |
78 | GNUNET_assert (NULL == rc->peers[rc->peer_cnt]); | 78 | GNUNET_assert (NULL == rc->peers[rc->peer_cnt]); |
79 | GNUNET_assert (NULL != event->details.peer_start.peer); | 79 | GNUNET_assert (NULL != event->details.peer_start.peer); |
80 | rc->peers[rc->peer_cnt++] = event->details.peer_start.peer; | 80 | rc->peers[rc->peer_cnt++] = event->details.peer_start.peer; |
81 | } | 81 | } |
82 | 82 | ||
@@ -91,7 +91,7 @@ static void | |||
91 | master_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 91 | master_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
92 | { | 92 | { |
93 | struct TestRunContext *rc = cls; | 93 | struct TestRunContext *rc = cls; |
94 | 94 | ||
95 | GNUNET_assert (rc->peer_cnt == rc->num_peers); | 95 | GNUNET_assert (rc->peer_cnt == rc->num_peers); |
96 | rc->test_master (rc->test_master_cls, rc->num_peers, rc->peers); | 96 | rc->test_master (rc->test_master_cls, rc->num_peers, rc->peers); |
97 | } | 97 | } |
@@ -111,8 +111,8 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
111 | { | 111 | { |
112 | struct TestRunContext *rc = cls; | 112 | struct TestRunContext *rc = cls; |
113 | 113 | ||
114 | GNUNET_TESTBED_run (NULL, config, rc->num_peers, 0, &controller_event_cb, | 114 | GNUNET_TESTBED_run (NULL, config, rc->num_peers, 0, &controller_event_cb, rc, |
115 | rc, &master_task, rc); | 115 | &master_task, rc); |
116 | } | 116 | } |
117 | 117 | ||
118 | 118 | ||
@@ -155,7 +155,7 @@ GNUNET_TESTBED_test_run (const char *testname, const char *cfg_filename, | |||
155 | GNUNET_GETOPT_OPTION_END | 155 | GNUNET_GETOPT_OPTION_END |
156 | }; | 156 | }; |
157 | struct TestRunContext *rc; | 157 | struct TestRunContext *rc; |
158 | 158 | ||
159 | argv2[0] = GNUNET_strdup (testname); | 159 | argv2[0] = GNUNET_strdup (testname); |
160 | argv2[2] = GNUNET_strdup (cfg_filename); | 160 | argv2[2] = GNUNET_strdup (cfg_filename); |
161 | GNUNET_assert (NULL != test_master); | 161 | GNUNET_assert (NULL != test_master); |
@@ -163,14 +163,12 @@ GNUNET_TESTBED_test_run (const char *testname, const char *cfg_filename, | |||
163 | (num_peers * sizeof (struct GNUNET_TESTBED_Peer *))); | 163 | (num_peers * sizeof (struct GNUNET_TESTBED_Peer *))); |
164 | rc->test_master = test_master; | 164 | rc->test_master = test_master; |
165 | rc->test_master_cls = test_master_cls; | 165 | rc->test_master_cls = test_master_cls; |
166 | rc->num_peers = rc->num_peers; | 166 | rc->num_peers = num_peers; |
167 | (void) GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | 167 | (void) GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, |
168 | "testname", "nohelp", options, &run, rc); | 168 | testname, "nohelp", options, &run, rc); |
169 | GNUNET_free (rc); | 169 | GNUNET_free (rc); |
170 | GNUNET_free (argv2[0]); | 170 | GNUNET_free (argv2[0]); |
171 | GNUNET_free (argv2[2]); | 171 | GNUNET_free (argv2[2]); |
172 | } | 172 | } |
173 | 173 | ||
174 | |||
175 | |||
176 | /* end of testbed_api_test.c */ | 174 | /* end of testbed_api_test.c */ |
diff --git a/src/testbed/testbed_api_testbed.c b/src/testbed/testbed_api_testbed.c index d841caab3..06cba2850 100644 --- a/src/testbed/testbed_api_testbed.c +++ b/src/testbed/testbed_api_testbed.c | |||
@@ -481,6 +481,8 @@ GNUNET_TESTBED_run (const char *host_filename, | |||
481 | struct RunContext *rc; | 481 | struct RunContext *rc; |
482 | 482 | ||
483 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); | 483 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); |
484 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); | ||
485 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); | ||
484 | rc = GNUNET_malloc (sizeof (struct RunContext)); | 486 | rc = GNUNET_malloc (sizeof (struct RunContext)); |
485 | GNUNET_break (NULL == host_filename); /* Currently we do not support host | 487 | GNUNET_break (NULL == host_filename); /* Currently we do not support host |
486 | * files */ | 488 | * files */ |