2 This file is part of GNUnet.
3 (C) 2010,2011 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.
21 * @file ats/test_ats_api_performance_monitor.c
22 * @brief test performance monitoring
23 * @author Christian Grothoff
24 * @author Matthias Wachs
27 #include "gnunet_ats_service.h"
28 #include "gnunet_testing_lib.h"
31 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20)
32 #define SHUTDOWN_CORRECT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
34 static GNUNET_SCHEDULER_TaskIdentifier die_task;
35 static GNUNET_SCHEDULER_TaskIdentifier stage_task;
37 struct GNUNET_CONFIGURATION_Handle *cfg;
39 static struct GNUNET_ATS_PerformanceHandle *ph;
41 static struct GNUNET_ATS_PerformanceMonitorHandle *phm;
49 if (GNUNET_SCHEDULER_NO_TASK != stage_task)
51 GNUNET_SCHEDULER_cancel (stage_task);
52 stage_task = GNUNET_SCHEDULER_NO_TASK;
54 if (GNUNET_SCHEDULER_NO_TASK != die_task)
56 GNUNET_SCHEDULER_cancel (die_task);
57 die_task = GNUNET_SCHEDULER_NO_TASK;
62 GNUNET_ATS_performance_monitor_stop (phm);
68 GNUNET_ATS_performance_done (ph);
75 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
77 die_task = GNUNET_SCHEDULER_NO_TASK;
78 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout\n");
83 next_stage (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
85 static int stage_counter = 0;
87 stage_task = GNUNET_SCHEDULER_NO_TASK;
88 if (0 == stage_counter)
90 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stop performance monitoring\n");
92 GNUNET_ATS_performance_monitor_stop (phm);
95 stage_task = GNUNET_SCHEDULER_add_delayed (SHUTDOWN_CORRECT, &next_stage, NULL);
109 perf_mon_cb (void *cls,
110 struct GNUNET_PeerIdentity *peer,
111 struct GNUNET_ATS_Information *ats,
120 const struct GNUNET_CONFIGURATION_Handle *mycfg,
121 struct GNUNET_TESTING_Peer *peer)
124 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg;
125 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
127 ph = GNUNET_ATS_performance_init (cfg, NULL, NULL);
128 GNUNET_assert (NULL != ph);
130 phm = GNUNET_ATS_performance_monitor_start (ph, &perf_mon_cb, &ret);
131 GNUNET_assert (NULL != phm);
133 stage_task = GNUNET_SCHEDULER_add_delayed (SHUTDOWN_CORRECT, &next_stage, NULL);
138 main (int argc, char *argv[])
140 if (0 != GNUNET_TESTING_peer_run ("test_ats_api_performance_monitor",
147 /* end of file test_ats_api_performance_monitor.c */