2 This file is part of GNUnet
3 Copyright (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_statistics.c
23 * @brief testcase for testing GNUNET_TESTBED_get_statistics() implementation
24 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
28 #include "gnunet_util_lib.h"
29 #include "gnunet_testbed_service.h"
32 * Number of peers we want to start
37 * The array of peers; we get them from the testbed
39 static struct GNUNET_TESTBED_Peer **peers;
44 static struct GNUNET_TESTBED_Operation *op;
49 static void *dummy_cls = (void *) 0xDEAD0001;
52 * Abort task identifier
54 static struct GNUNET_SCHEDULER_Task * abort_task;
57 * Global testing result
62 * The peers we have seen in the statistics iterator
64 static struct GNUNET_TESTBED_Peer **seen_peers;
67 * Number of peers in the above array
69 static unsigned int num_seen_peers;
75 #define FAIL_TEST(cond, ret) do { \
78 if (NULL != abort_task) \
79 GNUNET_SCHEDULER_cancel (abort_task); \
80 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); \
90 * @param tc scheduler task context
93 do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
95 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test timed out -- Aborting\n");
99 GNUNET_TESTBED_operation_done (op);
102 result = GNUNET_SYSERR;
107 * Callback function to process statistic values from all peers.
110 * @param peer the peer the statistic belong to
111 * @param subsystem name of subsystem that created the statistic
112 * @param name the name of the datum
113 * @param value the current value
114 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
115 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
118 stats_iterator (void *cls,
119 const struct GNUNET_TESTBED_Peer *peer,
120 const char *subsystem, const char *name, uint64_t value,
125 FAIL_TEST (cls == dummy_cls, return GNUNET_SYSERR);
126 for (cnt = 0; cnt < num_seen_peers; cnt++)
127 FAIL_TEST (peer != seen_peers[cnt], return GNUNET_SYSERR);
128 FAIL_TEST (NULL != subsystem, return GNUNET_SYSERR);
129 FAIL_TEST (NULL != name, return GNUNET_SYSERR);
130 GNUNET_array_append (seen_peers, num_seen_peers,
131 (struct GNUNET_TESTBED_Peer *) peer);
132 return GNUNET_SYSERR;
137 * Callback to be called when an operation is completed
139 * @param cls the callback closure from functions generating an operation
140 * @param op the operation that has been finished
141 * @param emsg error message in case the operation has failed; will be NULL if
142 * operation has executed successfully.
145 op_comp_cb (void *cls,
146 struct GNUNET_TESTBED_Operation *op,
149 FAIL_TEST (cls == dummy_cls, return);
151 GNUNET_TESTBED_operation_done (op);
153 GNUNET_SCHEDULER_cancel (abort_task);
154 GNUNET_SCHEDULER_shutdown ();
159 * Signature of a main function for a testcase.
162 * @param h the run handle
163 * @param num_peers number of peers in 'peers'
164 * @param peers_ handle to peers run in the testbed
165 * @param links_succeeded the number of overlay link connection attempts that
167 * @param links_failed the number of overlay link connection attempts that
171 test_master (void *cls,
172 struct GNUNET_TESTBED_RunHandle *h,
173 unsigned int num_peers,
174 struct GNUNET_TESTBED_Peer **peers_,
175 unsigned int links_succeeded,
176 unsigned int links_failed)
178 FAIL_TEST (NUM_PEERS == num_peers, return);
180 op = GNUNET_TESTBED_get_statistics (num_peers, peers,
185 abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
186 (GNUNET_TIME_UNIT_MINUTES, 1),
195 main (int argc, char **argv)
197 (void) GNUNET_TESTBED_test_run ("test_testbed_api_statistics",
198 "test_testbed_api_statistics.conf",
202 GNUNET_free_non_null (seen_peers);
203 if (GNUNET_OK != result)