2 This file is part of GNUnet
3 Copyright (C) 2008--2013 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
17 * @file testbed/test_testbed_api_statistics.c
18 * @brief testcase for testing GNUNET_TESTBED_get_statistics() implementation
19 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
23 #include "gnunet_util_lib.h"
24 #include "gnunet_testbed_service.h"
27 * Number of peers we want to start
32 * The array of peers; we get them from the testbed
34 static struct GNUNET_TESTBED_Peer **peers;
39 static struct GNUNET_TESTBED_Operation *op;
44 static void *dummy_cls = (void *) 0xDEAD0001;
47 * Abort task identifier
49 static struct GNUNET_SCHEDULER_Task * abort_task;
52 * Global testing result
57 * The peers we have seen in the statistics iterator
59 static struct GNUNET_TESTBED_Peer **seen_peers;
62 * Number of peers in the above array
64 static unsigned int num_seen_peers;
70 #define FAIL_TEST(cond, ret) do { \
73 if (NULL != abort_task) \
74 GNUNET_SCHEDULER_cancel (abort_task); \
75 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); \
89 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test timed out -- Aborting\n");
93 GNUNET_TESTBED_operation_done (op);
96 result = GNUNET_SYSERR;
101 * Callback function to process statistic values from all peers.
104 * @param peer the peer the statistic belong to
105 * @param subsystem name of subsystem that created the statistic
106 * @param name the name of the datum
107 * @param value the current value
108 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
109 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
112 stats_iterator (void *cls,
113 const struct GNUNET_TESTBED_Peer *peer,
114 const char *subsystem, const char *name, uint64_t value,
119 FAIL_TEST (cls == dummy_cls, return GNUNET_SYSERR);
120 for (cnt = 0; cnt < num_seen_peers; cnt++)
121 FAIL_TEST (peer != seen_peers[cnt], return GNUNET_SYSERR);
122 FAIL_TEST (NULL != subsystem, return GNUNET_SYSERR);
123 FAIL_TEST (NULL != name, return GNUNET_SYSERR);
124 GNUNET_array_append (seen_peers, num_seen_peers,
125 (struct GNUNET_TESTBED_Peer *) peer);
126 return GNUNET_SYSERR;
131 * Callback to be called when an operation is completed
133 * @param cls the callback closure from functions generating an operation
134 * @param op the operation that has been finished
135 * @param emsg error message in case the operation has failed; will be NULL if
136 * operation has executed successfully.
139 op_comp_cb (void *cls,
140 struct GNUNET_TESTBED_Operation *op,
143 FAIL_TEST (cls == dummy_cls, return);
145 GNUNET_TESTBED_operation_done (op);
147 GNUNET_SCHEDULER_cancel (abort_task);
148 GNUNET_SCHEDULER_shutdown ();
153 * Signature of a main function for a testcase.
156 * @param h the run handle
157 * @param num_peers number of peers in 'peers'
158 * @param peers_ handle to peers run in the testbed
159 * @param links_succeeded the number of overlay link connection attempts that
161 * @param links_failed the number of overlay link connection attempts that
165 test_master (void *cls,
166 struct GNUNET_TESTBED_RunHandle *h,
167 unsigned int num_peers,
168 struct GNUNET_TESTBED_Peer **peers_,
169 unsigned int links_succeeded,
170 unsigned int links_failed)
172 FAIL_TEST (NUM_PEERS == num_peers, return);
174 op = GNUNET_TESTBED_get_statistics (num_peers, peers,
179 abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
180 (GNUNET_TIME_UNIT_MINUTES, 1),
189 main (int argc, char **argv)
191 (void) GNUNET_TESTBED_test_run ("test_testbed_api_statistics",
192 "test_testbed_api_statistics.conf",
196 GNUNET_free_non_null (seen_peers);
197 if (GNUNET_OK != result)