aboutsummaryrefslogtreecommitdiff
path: root/src/testbed
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-03-13 11:48:21 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-03-13 11:48:21 +0000
commit4a3aedc380b10a1f517ece3188b094ff4279c891 (patch)
tree96b469d7c81deb4f3c97fd6924160572af81d4a5 /src/testbed
parent0043aada3f5172d461f89eecc9138b6a1754ca14 (diff)
downloadgnunet-4a3aedc380b10a1f517ece3188b094ff4279c891.tar.gz
gnunet-4a3aedc380b10a1f517ece3188b094ff4279c891.zip
- adding the testbed_api_statistics testcase source
Diffstat (limited to 'src/testbed')
-rw-r--r--src/testbed/test_testbed_api_statistics.c186
1 files changed, 186 insertions, 0 deletions
diff --git a/src/testbed/test_testbed_api_statistics.c b/src/testbed/test_testbed_api_statistics.c
new file mode 100644
index 000000000..7d8761532
--- /dev/null
+++ b/src/testbed/test_testbed_api_statistics.c
@@ -0,0 +1,186 @@
1/*
2 This file is part of GNUnet
3 (C) 2008--2013 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_statistics.c
23 * @brief testcase for testing GNUNET_TESTBED_get_statistics() implementation
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 5
35
36/**
37 * The array of peers; we get them from the testbed
38 */
39static struct GNUNET_TESTBED_Peer **peers;
40
41/**
42 * Operation handle
43 */
44static struct GNUNET_TESTBED_Operation *op;
45
46/**
47 * dummy pointer
48 */
49static void *dummy_cls = (void *) 0xDEAD0001;
50
51/**
52 * Abort task identifier
53 */
54static GNUNET_SCHEDULER_TaskIdentifier abort_task;
55
56/**
57 * Global testing result
58 */
59static int result;
60
61/**
62 * Fail testcase
63 */
64#define FAIL_TEST(cond, ret) do { \
65 if (!(cond)) { \
66 GNUNET_break(0); \
67 if (GNUNET_SCHEDULER_NO_TASK != abort_task) \
68 GNUNET_SCHEDULER_cancel (abort_task); \
69 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); \
70 ret; \
71 } \
72 } while (0)
73
74
75/**
76 * Abort task
77 *
78 * @param cls NULL
79 * @param tc scheduler task context
80 */
81static void
82do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
83{
84 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test timed out -- Aborting\n");
85 abort_task = GNUNET_SCHEDULER_NO_TASK;
86 if (NULL != op)
87 {
88 GNUNET_TESTBED_operation_done (op);
89 op = NULL;
90 }
91 result = GNUNET_SYSERR;
92}
93
94
95/**
96 * Callback function to process statistic values from all peers.
97 *
98 * @param cls closure
99 * @param peer the peer the statistic belong to
100 * @param subsystem name of subsystem that created the statistic
101 * @param name the name of the datum
102 * @param value the current value
103 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
104 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
105 */
106static int
107stats_iterator (void *cls,
108 const struct GNUNET_TESTBED_Peer *peer,
109 const char *subsystem, const char *name, uint64_t value,
110 int is_persistent)
111{
112 static struct GNUNET_TESTBED_Peer **seen_peers;
113 static unsigned int num_seen_peers;
114 unsigned int cnt;
115
116 FAIL_TEST (cls == dummy_cls, return GNUNET_SYSERR);
117 for (cnt = 0; cnt < num_seen_peers; cnt++)
118 FAIL_TEST (peer != seen_peers[cnt], return GNUNET_SYSERR);
119 FAIL_TEST (NULL != subsystem, return GNUNET_SYSERR);
120 FAIL_TEST (NULL != name, return GNUNET_SYSERR);
121 GNUNET_array_append (seen_peers, num_seen_peers,
122 (struct GNUNET_TESTBED_Peer *) peer);
123 return GNUNET_SYSERR;
124}
125
126
127/**
128 * Callback to be called when an operation is completed
129 *
130 * @param cls the callback closure from functions generating an operation
131 * @param op the operation that has been finished
132 * @param emsg error message in case the operation has failed; will be NULL if
133 * operation has executed successfully.
134 */
135static void
136op_comp_cb (void *cls,
137 struct GNUNET_TESTBED_Operation *op,
138 const char *emsg)
139{
140 FAIL_TEST (cls == dummy_cls, return);
141 result = GNUNET_OK;
142 GNUNET_TESTBED_operation_done (op);
143 op = NULL;
144 GNUNET_SCHEDULER_cancel (abort_task);
145 GNUNET_SCHEDULER_shutdown ();
146}
147
148
149/**
150 * Signature of a main function for a testcase.
151 *
152 * @param cls closure
153 * @param num_peers number of peers in 'peers'
154 * @param peers handle to peers run in the testbed
155 */
156static void
157test_master (void *cls, unsigned int num_peers,
158 struct GNUNET_TESTBED_Peer **peers_)
159{
160 FAIL_TEST (NUM_PEERS == num_peers, return);
161 peers = peers_;
162 op = GNUNET_TESTBED_get_statistics (num_peers, peers,
163 &stats_iterator,
164 &op_comp_cb,
165 dummy_cls);
166 abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
167 (GNUNET_TIME_UNIT_MINUTES, 1),
168 &do_abort, NULL);
169}
170
171
172/**
173 * Main function
174 */
175int
176main (int argc, char **argv)
177{
178 (void) GNUNET_TESTBED_test_run ("test_testbed_api_statistics",
179 "test_testbed_api_statistics.conf",
180 NUM_PEERS,
181 1LL, NULL, NULL,
182 &test_master, NULL);
183 if (GNUNET_OK != result)
184 return 1;
185 return 0;
186}