aboutsummaryrefslogtreecommitdiff
path: root/src/statistics/test_statistics_api_watch.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/statistics/test_statistics_api_watch.c')
-rw-r--r--src/statistics/test_statistics_api_watch.c74
1 files changed, 32 insertions, 42 deletions
diff --git a/src/statistics/test_statistics_api_watch.c b/src/statistics/test_statistics_api_watch.c
index 4c44bd0ba..72cb27ecf 100644
--- a/src/statistics/test_statistics_api_watch.c
+++ b/src/statistics/test_statistics_api_watch.c
@@ -45,8 +45,7 @@ static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
45 45
46 46
47static void 47static void
48force_shutdown (void *cls, 48force_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
49 const struct GNUNET_SCHEDULER_TaskContext *tc)
50{ 49{
51 fprintf (stderr, "Timeout, failed to receive notifications: %d\n", ok); 50 fprintf (stderr, "Timeout, failed to receive notifications: %d\n", ok);
52 GNUNET_STATISTICS_destroy (h, GNUNET_NO); 51 GNUNET_STATISTICS_destroy (h, GNUNET_NO);
@@ -56,8 +55,7 @@ force_shutdown (void *cls,
56 55
57 56
58static void 57static void
59normal_shutdown (void *cls, 58normal_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
60 const struct GNUNET_SCHEDULER_TaskContext *tc)
61{ 59{
62 GNUNET_STATISTICS_destroy (h, GNUNET_NO); 60 GNUNET_STATISTICS_destroy (h, GNUNET_NO);
63 GNUNET_STATISTICS_destroy (h2, GNUNET_NO); 61 GNUNET_STATISTICS_destroy (h2, GNUNET_NO);
@@ -65,39 +63,35 @@ normal_shutdown (void *cls,
65 63
66 64
67static int 65static int
68watch_1 (void *cls, 66watch_1 (void *cls,
69 const char *subsystem, 67 const char *subsystem,
70 const char *name, 68 const char *name, uint64_t value, int is_persistent)
71 uint64_t value,
72 int is_persistent)
73{ 69{
74 GNUNET_assert (value == 42); 70 GNUNET_assert (value == 42);
75 GNUNET_assert (0 == strcmp (name, "test-1")); 71 GNUNET_assert (0 == strcmp (name, "test-1"));
76 ok &= ~1; 72 ok &= ~1;
77 if (0 == ok) 73 if (0 == ok)
78 { 74 {
79 GNUNET_SCHEDULER_cancel (shutdown_task); 75 GNUNET_SCHEDULER_cancel (shutdown_task);
80 GNUNET_SCHEDULER_add_now (&normal_shutdown, NULL); 76 GNUNET_SCHEDULER_add_now (&normal_shutdown, NULL);
81 } 77 }
82 return GNUNET_OK; 78 return GNUNET_OK;
83} 79}
84 80
85 81
86static int 82static int
87watch_2 (void *cls, 83watch_2 (void *cls,
88 const char *subsystem, 84 const char *subsystem,
89 const char *name, 85 const char *name, uint64_t value, int is_persistent)
90 uint64_t value,
91 int is_persistent)
92{ 86{
93 GNUNET_assert (value == 43); 87 GNUNET_assert (value == 43);
94 GNUNET_assert (0 == strcmp (name, "test-2")); 88 GNUNET_assert (0 == strcmp (name, "test-2"));
95 ok &= ~2; 89 ok &= ~2;
96 if (0 == ok) 90 if (0 == ok)
97 { 91 {
98 GNUNET_SCHEDULER_cancel (shutdown_task); 92 GNUNET_SCHEDULER_cancel (shutdown_task);
99 GNUNET_SCHEDULER_add_now (&normal_shutdown, NULL); 93 GNUNET_SCHEDULER_add_now (&normal_shutdown, NULL);
100 } 94 }
101 return GNUNET_OK; 95 return GNUNET_OK;
102} 96}
103 97
@@ -105,27 +99,22 @@ watch_2 (void *cls,
105static void 99static void
106run (void *cls, 100run (void *cls,
107 char *const *args, 101 char *const *args,
108 const char *cfgfile, 102 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
109 const struct GNUNET_CONFIGURATION_Handle *cfg)
110{ 103{
111 h = GNUNET_STATISTICS_create ("dummy", cfg); 104 h = GNUNET_STATISTICS_create ("dummy", cfg);
112 GNUNET_assert (GNUNET_OK == 105 GNUNET_assert (GNUNET_OK ==
113 GNUNET_STATISTICS_watch (h, 106 GNUNET_STATISTICS_watch (h,
114 "test-statistics-api-watch", 107 "test-statistics-api-watch",
115 "test-1", 108 "test-1", &watch_1, NULL));
116 &watch_1,
117 NULL));
118 GNUNET_assert (GNUNET_OK == 109 GNUNET_assert (GNUNET_OK ==
119 GNUNET_STATISTICS_watch (h, 110 GNUNET_STATISTICS_watch (h,
120 "test-statistics-api-watch", 111 "test-statistics-api-watch",
121 "test-2", 112 "test-2", &watch_2, NULL));
122 &watch_2,
123 NULL));
124 h2 = GNUNET_STATISTICS_create ("test-statistics-api-watch", cfg); 113 h2 = GNUNET_STATISTICS_create ("test-statistics-api-watch", cfg);
125 GNUNET_STATISTICS_set (h2, "test-1", 42, GNUNET_NO); 114 GNUNET_STATISTICS_set (h2, "test-1", 42, GNUNET_NO);
126 GNUNET_STATISTICS_set (h2, "test-2", 43, GNUNET_NO); 115 GNUNET_STATISTICS_set (h2, "test-2", 43, GNUNET_NO);
127 shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 116 shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
128 &force_shutdown, NULL); 117 &force_shutdown, NULL);
129} 118}
130 119
131 120
@@ -142,12 +131,13 @@ check ()
142 }; 131 };
143#if START_SERVICE 132#if START_SERVICE
144 struct GNUNET_OS_Process *proc; 133 struct GNUNET_OS_Process *proc;
134
145 proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics", 135 proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics",
146 "gnunet-service-statistics", 136 "gnunet-service-statistics",
147#if VERBOSE 137#if VERBOSE
148 "-L", "DEBUG", 138 "-L", "DEBUG",
149#endif 139#endif
150 "-c", "test_statistics_api_data.conf", NULL); 140 "-c", "test_statistics_api_data.conf", NULL);
151#endif 141#endif
152 GNUNET_assert (NULL != proc); 142 GNUNET_assert (NULL != proc);
153 ok = 3; 143 ok = 3;
@@ -155,10 +145,10 @@ check ()
155 options, &run, NULL); 145 options, &run, NULL);
156#if START_SERVICE 146#if START_SERVICE
157 if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) 147 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
158 { 148 {
159 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 149 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
160 ok = 1; 150 ok = 1;
161 } 151 }
162 GNUNET_OS_process_wait (proc); 152 GNUNET_OS_process_wait (proc);
163 GNUNET_OS_process_close (proc); 153 GNUNET_OS_process_close (proc);
164 proc = NULL; 154 proc = NULL;