pre lunch commit
[oweals/gnunet.git] / src / ats / test_ats_api_performance_monitor.c
1 /*
2      This file is part of GNUnet.
3      (C) 2010,2011 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  * @file ats/test_ats_api_performance_monitor.c
22  * @brief test performance monitoring
23  * @author Christian Grothoff
24  * @author Matthias Wachs
25  */
26 #include "platform.h"
27 #include "gnunet_ats_service.h"
28 #include "gnunet_testing_lib.h"
29 #include "ats.h"
30
31 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
32
33
34 static GNUNET_SCHEDULER_TaskIdentifier die_task;
35
36 struct GNUNET_CONFIGURATION_Handle *cfg;
37
38 static struct GNUNET_ATS_PerformanceHandle *ph;
39
40 static struct GNUNET_ATS_PerformanceMonitorHandle *phm;
41
42 static int ret;
43
44
45 static void
46 end_now (int res)
47 {
48         if (GNUNET_SCHEDULER_NO_TASK != die_task)
49         {
50                         GNUNET_SCHEDULER_cancel (die_task);
51                         die_task = GNUNET_SCHEDULER_NO_TASK;
52         }
53
54         if (NULL != phm)
55         {
56                 GNUNET_ATS_performance_monitor_stop (phm);
57                 phm = NULL;
58         }
59
60         if (NULL != ph)
61         {
62                 GNUNET_ATS_performance_done (ph);
63                 ph = NULL;
64         }
65         ret = res;
66 }
67
68 static void
69 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
70 {
71   die_task = GNUNET_SCHEDULER_NO_TASK;
72   GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout\n");
73   end_now (1);
74 }
75
76
77 static void
78 perf_mon_cb (void *cls,
79                                                 struct GNUNET_PeerIdentity *peer,
80                                                 struct GNUNET_ATS_Information *ats,
81                                                 uint32_t ats_count)
82 {
83
84 }
85
86
87 static void
88 run (void *cls, 
89      const struct GNUNET_CONFIGURATION_Handle *mycfg,
90      struct GNUNET_TESTING_Peer *peer)
91 {
92   ret = 1;
93   cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg;
94   die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
95
96   ph = GNUNET_ATS_performance_init (cfg, NULL, NULL);
97   GNUNET_assert (NULL != ph);
98
99   phm = GNUNET_ATS_performance_monitor_start (ph, &perf_mon_cb, &ret);
100   GNUNET_assert (NULL != phm);
101
102 //  GNUNET_ATS_performance_monitor_stop (phm);
103
104         //GNUNET_ATS_performance_done (ph);
105 //      ph = NULL;
106   //end_now (0);
107 }
108
109
110 int
111 main (int argc, char *argv[])
112 {
113   if (0 != GNUNET_TESTING_peer_run ("test_ats_api_performance_monitor",
114                                     "test_ats_api.conf",
115                                     &run, NULL))
116     return 1;
117   return ret;
118 }
119
120 /* end of file test_ats_api_performance_monitor.c */