diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-07-01 07:50:28 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-07-01 07:50:28 +0000 |
commit | 7f892499d0af649861c9a4c06ffc778eba00635c (patch) | |
tree | dd1e7d458f10942faba7cf33b5cffe9954ee4cac | |
parent | 0e05ed7a140a74d0c015cda8b43b77a822bfe4ff (diff) | |
download | gnunet-7f892499d0af649861c9a4c06ffc778eba00635c.tar.gz gnunet-7f892499d0af649861c9a4c06ffc778eba00635c.zip |
new tst
-rw-r--r-- | src/statistics/Makefile.am | 9 | ||||
-rw-r--r-- | src/statistics/test_statistics_api_loop.c | 130 |
2 files changed, 138 insertions, 1 deletions
diff --git a/src/statistics/Makefile.am b/src/statistics/Makefile.am index 4a924c5b5..0e2e4d727 100644 --- a/src/statistics/Makefile.am +++ b/src/statistics/Makefile.am | |||
@@ -42,7 +42,8 @@ gnunet_service_statistics_LDADD = \ | |||
42 | 42 | ||
43 | 43 | ||
44 | check_PROGRAMS = \ | 44 | check_PROGRAMS = \ |
45 | test_statistics_api | 45 | test_statistics_api \ |
46 | test_statistics_api_loop | ||
46 | 47 | ||
47 | TESTS = $(check_PROGRAMS) $(check_SCRIPTS) | 48 | TESTS = $(check_PROGRAMS) $(check_SCRIPTS) |
48 | 49 | ||
@@ -52,6 +53,12 @@ test_statistics_api_LDADD = \ | |||
52 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 53 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
53 | $(top_builddir)/src/util/libgnunetutil.la | 54 | $(top_builddir)/src/util/libgnunetutil.la |
54 | 55 | ||
56 | test_statistics_api_loop_SOURCES = \ | ||
57 | test_statistics_api_loop.c | ||
58 | test_statistics_api_loop_LDADD = \ | ||
59 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | ||
60 | $(top_builddir)/src/util/libgnunetutil.la | ||
61 | |||
55 | check_SCRIPTS = \ | 62 | check_SCRIPTS = \ |
56 | test_gnunet_statistics.sh | 63 | test_gnunet_statistics.sh |
57 | 64 | ||
diff --git a/src/statistics/test_statistics_api_loop.c b/src/statistics/test_statistics_api_loop.c new file mode 100644 index 000000000..b70e92bdc --- /dev/null +++ b/src/statistics/test_statistics_api_loop.c | |||
@@ -0,0 +1,130 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2009 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 2, 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 statistics/test_statistics_api_loop.c | ||
22 | * @brief testcase for statistics_api.c | ||
23 | */ | ||
24 | #include "platform.h" | ||
25 | #include "gnunet_common.h" | ||
26 | #include "gnunet_getopt_lib.h" | ||
27 | #include "gnunet_os_lib.h" | ||
28 | #include "gnunet_program_lib.h" | ||
29 | #include "gnunet_scheduler_lib.h" | ||
30 | #include "gnunet_statistics_service.h" | ||
31 | |||
32 | #define VERBOSE GNUNET_NO | ||
33 | |||
34 | #define START_SERVICE GNUNET_YES | ||
35 | |||
36 | #define ROUNDS (1024 * 1024) | ||
37 | |||
38 | static int | ||
39 | check_1 (void *cls, | ||
40 | const char *subsystem, | ||
41 | const char *name, uint64_t value, int is_persistent) | ||
42 | { | ||
43 | GNUNET_assert (0 == strcmp (name, "test-0")); | ||
44 | GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api-loop")); | ||
45 | GNUNET_assert (is_persistent == GNUNET_NO); | ||
46 | return GNUNET_OK; | ||
47 | } | ||
48 | |||
49 | static struct GNUNET_STATISTICS_Handle *h; | ||
50 | |||
51 | static void | ||
52 | next (void *cls, int success) | ||
53 | { | ||
54 | int *ok = cls; | ||
55 | |||
56 | GNUNET_STATISTICS_destroy (h, GNUNET_NO); | ||
57 | GNUNET_assert (success == GNUNET_OK); | ||
58 | *ok = 0; | ||
59 | } | ||
60 | |||
61 | static void | ||
62 | run (void *cls, | ||
63 | struct GNUNET_SCHEDULER_Handle *sched, | ||
64 | char *const *args, | ||
65 | const char *cfgfile, | ||
66 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
67 | { | ||
68 | int i; | ||
69 | char name[128]; | ||
70 | |||
71 | h = GNUNET_STATISTICS_create (sched, "test-statistics-api-loop", cfg); | ||
72 | for (i=0;i<ROUNDS;i++) | ||
73 | { | ||
74 | GNUNET_snprintf (name, sizeof (name), "test-%d", i % 256); | ||
75 | GNUNET_STATISTICS_set (h, name, i, GNUNET_NO); | ||
76 | GNUNET_snprintf (name, sizeof (name), "test-%d", i % 128); | ||
77 | GNUNET_STATISTICS_update (h, name, 1, GNUNET_NO); | ||
78 | } | ||
79 | i = 0; | ||
80 | GNUNET_break (NULL != | ||
81 | GNUNET_STATISTICS_get (h, NULL, "test-0", | ||
82 | GNUNET_TIME_UNIT_SECONDS, &next, &check_1, cls)); | ||
83 | } | ||
84 | |||
85 | |||
86 | static int | ||
87 | check () | ||
88 | { | ||
89 | int ok = 1; | ||
90 | char *const argv[] = { "test-statistics-api", | ||
91 | "-c", | ||
92 | "test_statistics_api_data.conf", | ||
93 | NULL | ||
94 | }; | ||
95 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
96 | GNUNET_GETOPT_OPTION_END | ||
97 | }; | ||
98 | #if START_SERVICE | ||
99 | pid_t pid; | ||
100 | pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics", | ||
101 | "gnunet-service-statistics", | ||
102 | #if DEBUG_STATISTICS | ||
103 | "-L", "DEBUG", | ||
104 | #endif | ||
105 | "-c", "test_statistics_api_data.conf", NULL); | ||
106 | #endif | ||
107 | GNUNET_PROGRAM_run (3, argv, "test-statistics-api", "nohelp", | ||
108 | options, &run, &ok); | ||
109 | #if START_SERVICE | ||
110 | if (0 != PLIBC_KILL (pid, SIGTERM)) | ||
111 | { | ||
112 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
113 | ok = 1; | ||
114 | } | ||
115 | GNUNET_OS_process_wait(pid); | ||
116 | #endif | ||
117 | return ok; | ||
118 | } | ||
119 | |||
120 | int | ||
121 | main (int argc, char *argv[]) | ||
122 | { | ||
123 | int ret; | ||
124 | |||
125 | ret = check (); | ||
126 | |||
127 | return ret; | ||
128 | } | ||
129 | |||
130 | /* end of test_statistics_api_loop.c */ | ||