diff options
Diffstat (limited to 'src/arm')
-rw-r--r-- | src/arm/Makefile.am | 24 | ||||
-rw-r--r-- | src/arm/mockup-service.c | 54 | ||||
-rw-r--r-- | src/arm/test_arm_api_data.conf | 11 | ||||
-rw-r--r-- | src/arm/test_exponential_backoff.c | 229 |
4 files changed, 313 insertions, 5 deletions
diff --git a/src/arm/Makefile.am b/src/arm/Makefile.am index 4bfda1756..36161e8a0 100644 --- a/src/arm/Makefile.am +++ b/src/arm/Makefile.am | |||
@@ -23,7 +23,8 @@ libgnunetarm_la_LDFLAGS = \ | |||
23 | 23 | ||
24 | bin_PROGRAMS = \ | 24 | bin_PROGRAMS = \ |
25 | gnunet-arm \ | 25 | gnunet-arm \ |
26 | gnunet-service-arm | 26 | gnunet-service-arm \ |
27 | mockup-service | ||
27 | 28 | ||
28 | gnunet_arm_SOURCES = \ | 29 | gnunet_arm_SOURCES = \ |
29 | gnunet-arm.c | 30 | gnunet-arm.c |
@@ -39,13 +40,20 @@ gnunet_service_arm_LDADD = \ | |||
39 | $(GN_LIBINTL) | 40 | $(GN_LIBINTL) |
40 | 41 | ||
41 | 42 | ||
42 | check_PROGRAMS = \ | 43 | mockup_service_SOURCES = \ |
43 | test_arm_api | 44 | mockup-service.c |
45 | mockup_service_LDADD = \ | ||
46 | $(top_builddir)/src/util/libgnunetutil.la | ||
47 | |||
44 | 48 | ||
49 | check_PROGRAMS = \ | ||
50 | test_arm_api \ | ||
51 | test_exponential_backoff | ||
52 | |||
45 | check_SCRIPTS = \ | 53 | check_SCRIPTS = \ |
46 | test_gnunet_arm.sh | 54 | test_gnunet_arm.sh |
47 | 55 | ||
48 | TESTS = $(check_PROGRAMS) $(check_SCRIPTS) | 56 | TESTS = test_arm_api $(check_SCRIPTS) |
49 | 57 | ||
50 | test_arm_api_SOURCES = \ | 58 | test_arm_api_SOURCES = \ |
51 | test_arm_api.c | 59 | test_arm_api.c |
@@ -53,6 +61,12 @@ test_arm_api_LDADD = \ | |||
53 | $(top_builddir)/src/arm/libgnunetarm.la \ | 61 | $(top_builddir)/src/arm/libgnunetarm.la \ |
54 | $(top_builddir)/src/util/libgnunetutil.la | 62 | $(top_builddir)/src/util/libgnunetutil.la |
55 | 63 | ||
56 | 64 | test_exponential_backoff_SOURCES = \ | |
65 | test_exponential_backoff.c | ||
66 | test_exponential_backoff_LDADD = \ | ||
67 | $(top_builddir)/src/arm/libgnunetarm.la \ | ||
68 | $(top_builddir)/src/util/libgnunetutil.la | ||
69 | |||
70 | |||
57 | EXTRA_DIST = \ | 71 | EXTRA_DIST = \ |
58 | test_arm_api_data.conf | 72 | test_arm_api_data.conf |
diff --git a/src/arm/mockup-service.c b/src/arm/mockup-service.c new file mode 100644 index 000000000..026138fab --- /dev/null +++ b/src/arm/mockup-service.c | |||
@@ -0,0 +1,54 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2007, 2008, 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 | #include <stdlib.h> | ||
22 | #include "platform.h" | ||
23 | #include "gnunet_disk_lib.h" | ||
24 | #include "gnunet_getopt_lib.h" | ||
25 | #include "gnunet_protocols.h" | ||
26 | #include "gnunet_service_lib.h" | ||
27 | #include "gnunet_statistics_service.h" | ||
28 | #include "gnunet_strings_lib.h" | ||
29 | #include "gnunet_time_lib.h" | ||
30 | |||
31 | |||
32 | static void | ||
33 | run (void *cls, | ||
34 | struct GNUNET_SCHEDULER_Handle *sched, | ||
35 | struct GNUNET_SERVER_Handle *server, | ||
36 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
37 | { | ||
38 | /* Does nothing */ | ||
39 | int x = 0; | ||
40 | } | ||
41 | |||
42 | |||
43 | int main(int argc, char *const *argv) | ||
44 | { | ||
45 | int ret; | ||
46 | |||
47 | ret = (GNUNET_OK == | ||
48 | GNUNET_SERVICE_run (argc, | ||
49 | argv, | ||
50 | "do-nothing", GNUNET_SERVICE_OPTION_NONE, | ||
51 | &run, NULL)) ? 0 : 1; | ||
52 | |||
53 | return ret; | ||
54 | } \ No newline at end of file | ||
diff --git a/src/arm/test_arm_api_data.conf b/src/arm/test_arm_api_data.conf index cbfb30534..92f7efb45 100644 --- a/src/arm/test_arm_api_data.conf +++ b/src/arm/test_arm_api_data.conf | |||
@@ -9,3 +9,14 @@ DEFAULTSERVICES = | |||
9 | 9 | ||
10 | [resolver] | 10 | [resolver] |
11 | #DEBUG = YES | 11 | #DEBUG = YES |
12 | |||
13 | [do-nothing] | ||
14 | #DEBUG = YES | ||
15 | PORT = 2223 | ||
16 | HOSTNAME = localhost | ||
17 | HOME = $SERVICEHOME | ||
18 | CONFIG = $DEFAULTCONFIG | ||
19 | BINARY = mockup-service | ||
20 | ACCEPT_FROM = 127.0.0.1; | ||
21 | ACCEPT_FROM6 = ::1; | ||
22 | ALLOW_SHUTDOWN = YES | ||
diff --git a/src/arm/test_exponential_backoff.c b/src/arm/test_exponential_backoff.c new file mode 100644 index 000000000..bbd0f2000 --- /dev/null +++ b/src/arm/test_exponential_backoff.c | |||
@@ -0,0 +1,229 @@ | |||
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 arm/test_exponential_backoff.c | ||
22 | * @brief testcase for gnunet-service-arm.c | ||
23 | */ | ||
24 | #include "platform.h" | ||
25 | #include "gnunet_arm_service.h" | ||
26 | #include "gnunet_client_lib.h" | ||
27 | #include "gnunet_configuration_lib.h" | ||
28 | #include "gnunet_program_lib.h" | ||
29 | |||
30 | #define START_ARM GNUNET_YES | ||
31 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | ||
32 | |||
33 | static struct GNUNET_SCHEDULER_Handle *sched; | ||
34 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
35 | static struct GNUNET_ARM_Handle *arm; | ||
36 | static int ok = 1; | ||
37 | static int kill_ok = GNUNET_OK; | ||
38 | static FILE *killLogFilePtr; | ||
39 | static char *killLogFileName; | ||
40 | |||
41 | static void | ||
42 | arm_notify_stop (void *cls, int success) | ||
43 | { | ||
44 | GNUNET_assert (success == GNUNET_NO); | ||
45 | #if START_ARM | ||
46 | GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, NULL, NULL); | ||
47 | #endif | ||
48 | } | ||
49 | |||
50 | |||
51 | static void | ||
52 | do_nothing_notify_stop (void *cls, int success) | ||
53 | { | ||
54 | GNUNET_assert (success == GNUNET_NO); | ||
55 | } | ||
56 | |||
57 | |||
58 | static void | ||
59 | do_nothing_notify (void *cls, int success) | ||
60 | { | ||
61 | GNUNET_assert (success == GNUNET_YES); | ||
62 | ok = 1; | ||
63 | } | ||
64 | |||
65 | |||
66 | static void | ||
67 | arm_notify (void *cls, int success) | ||
68 | { | ||
69 | GNUNET_assert (success == GNUNET_YES); | ||
70 | GNUNET_ARM_start_service (arm, "do-nothing", TIMEOUT, &do_nothing_notify, NULL); | ||
71 | } | ||
72 | |||
73 | |||
74 | static void | ||
75 | kill_task (void *cbData, | ||
76 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
77 | static void | ||
78 | do_nothing_restarted_notify_task (void *unused, | ||
79 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
80 | { | ||
81 | static char a; | ||
82 | static int trialCount = 0; | ||
83 | |||
84 | trialCount++; | ||
85 | if (trialCount >= 11) { | ||
86 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | ||
87 | fprintf(killLogFilePtr, "Reason is shutdown!\n"); | ||
88 | else if ((tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0) | ||
89 | fprintf(killLogFilePtr, "%d.Reason is timeout!\n", trialCount); | ||
90 | else if ((tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE) != 0) | ||
91 | fprintf(killLogFilePtr, "%d.Service is running!\n", trialCount); | ||
92 | } | ||
93 | |||
94 | GNUNET_SCHEDULER_add_now (sched, &kill_task, &a); // checks if this was too fast | ||
95 | } | ||
96 | |||
97 | |||
98 | static void | ||
99 | kill_task (void *cbData, | ||
100 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
101 | { | ||
102 | int* reason; | ||
103 | struct GNUNET_CLIENT_Connection * doNothingConnection = NULL; | ||
104 | static struct GNUNET_TIME_Absolute startedWaitingAt; | ||
105 | struct GNUNET_TIME_Relative waitedFor; | ||
106 | static int trialCount = 0; | ||
107 | |||
108 | reason = cbData; | ||
109 | if (NULL != reason) { | ||
110 | waitedFor = GNUNET_TIME_absolute_get_duration(startedWaitingAt); | ||
111 | trialCount++; | ||
112 | if (trialCount >= 11) | ||
113 | fprintf(killLogFilePtr, "Trial no.%d, Started waiting at:%lld. Waited for: %lld\n", trialCount, startedWaitingAt.value, waitedFor.value); | ||
114 | } | ||
115 | |||
116 | /* Connect to the doNothing task */ | ||
117 | doNothingConnection = GNUNET_CLIENT_connect (sched, "do-nothing", cfg); | ||
118 | if (NULL == doNothingConnection) | ||
119 | fprintf(killLogFilePtr, "Unable to connect to do-nothing process!\n"); | ||
120 | else if (trialCount == 20) { | ||
121 | GNUNET_ARM_stop_service (arm, "do-nothing", TIMEOUT, &arm_notify_stop, NULL); | ||
122 | return; | ||
123 | } | ||
124 | |||
125 | /* Use the created connection to kill the doNothingTask */ | ||
126 | GNUNET_CLIENT_service_shutdown(doNothingConnection); | ||
127 | sleep(0.005); | ||
128 | startedWaitingAt = GNUNET_TIME_absolute_get(); | ||
129 | /* | ||
130 | * There is something wrong here! | ||
131 | * TIMEOUT value is set to 10 seconds (a drastically large value) | ||
132 | * debugging is showing that the reason for which | ||
133 | * do_nothing_restarted_notify_task is called is "always" | ||
134 | * TIMEOUT which means that the "do-nothing" service is not running | ||
135 | * however the overall execution time doesn't exceed 2 seconds | ||
136 | * which means there is something tricky about the TIMOUT passed | ||
137 | * to function GNUNET_CLIENT_service_test() | ||
138 | */ | ||
139 | GNUNET_CLIENT_service_test(sched, "do-nothing", cfg, TIMEOUT, &do_nothing_restarted_notify_task, NULL); | ||
140 | } | ||
141 | |||
142 | static void | ||
143 | task (void *cls, | ||
144 | struct GNUNET_SCHEDULER_Handle *s, | ||
145 | char *const *args, | ||
146 | const char *cfgfile, | ||
147 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
148 | { | ||
149 | cfg = c; | ||
150 | sched = s; | ||
151 | |||
152 | arm = GNUNET_ARM_connect (cfg, sched, NULL); | ||
153 | #if START_ARM | ||
154 | GNUNET_ARM_start_service (arm, "arm", TIMEOUT, &arm_notify, NULL); | ||
155 | #else | ||
156 | arm_do_nothing (NULL, GNUNET_YES); | ||
157 | #endif | ||
158 | GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_UNIT_SECONDS, &kill_task, NULL); | ||
159 | } | ||
160 | |||
161 | static int | ||
162 | check () | ||
163 | { | ||
164 | char *const argv[] = { | ||
165 | "test-arm-api", | ||
166 | "-c", "test_arm_api_data.conf", | ||
167 | #if VERBOSE | ||
168 | "-L", "DEBUG", | ||
169 | #endif | ||
170 | NULL | ||
171 | }; | ||
172 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
173 | GNUNET_GETOPT_OPTION_END | ||
174 | }; | ||
175 | |||
176 | /* Running ARM and running the do_nothing task */ | ||
177 | GNUNET_assert (GNUNET_OK == | ||
178 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | ||
179 | argv, | ||
180 | "test-exponential-backoff", | ||
181 | "nohelp", options, &task, NULL)); | ||
182 | |||
183 | |||
184 | return ok; | ||
185 | } | ||
186 | |||
187 | static int | ||
188 | init() | ||
189 | { | ||
190 | killLogFileName = GNUNET_DISK_mktemp("exponential-backoff-waiting.log"); | ||
191 | if (NULL == (killLogFilePtr = FOPEN(killLogFileName, "w"))) { | ||
192 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fopen", killLogFileName); | ||
193 | GNUNET_free (killLogFileName); | ||
194 | return GNUNET_SYSERR; | ||
195 | } | ||
196 | |||
197 | return GNUNET_OK; | ||
198 | } | ||
199 | |||
200 | |||
201 | static void | ||
202 | houseKeep() | ||
203 | { | ||
204 | GNUNET_assert (0 == fclose (killLogFilePtr)); | ||
205 | GNUNET_free(killLogFileName); | ||
206 | } | ||
207 | |||
208 | |||
209 | int | ||
210 | main (int argc, char *argv[]) | ||
211 | { | ||
212 | int ret; | ||
213 | |||
214 | |||
215 | GNUNET_log_setup ("test-exponential-backoff", | ||
216 | #if VERBOSE | ||
217 | "DEBUG", | ||
218 | #else | ||
219 | "WARNING", | ||
220 | #endif | ||
221 | NULL); | ||
222 | |||
223 | init(); | ||
224 | ret = check (); | ||
225 | houseKeep(); | ||
226 | return ret; | ||
227 | } | ||
228 | |||
229 | /* end of test_exponential_backoff.c */ | ||