diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-05-13 01:05:22 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-05-13 01:05:22 +0000 |
commit | d8c0c8836e4c00318f48ef71b0d1647851f51b9c (patch) | |
tree | a625503495ae2754d51b59b80e768845aaa226e0 /src/mesh/test_mesh_api.c | |
parent | bb0f1a9c37476ebe08b2de7b6fb7f8b2ed0514b5 (diff) | |
download | gnunet-d8c0c8836e4c00318f48ef71b0d1647851f51b9c.tar.gz gnunet-d8c0c8836e4c00318f48ef71b0d1647851f51b9c.zip |
Finished basic connect/disconnect test
Diffstat (limited to 'src/mesh/test_mesh_api.c')
-rw-r--r-- | src/mesh/test_mesh_api.c | 120 |
1 files changed, 85 insertions, 35 deletions
diff --git a/src/mesh/test_mesh_api.c b/src/mesh/test_mesh_api.c index 6c3bd60a9..4c4bf9c4c 100644 --- a/src/mesh/test_mesh_api.c +++ b/src/mesh/test_mesh_api.c | |||
@@ -1,20 +1,47 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 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 | /** | ||
22 | * @file mesh/test_mesh_api.c | ||
23 | * @brief test mesh api: dummy test of callbacks | ||
24 | * @author Bartlomiej Polot | ||
25 | */ | ||
26 | |||
1 | #include "platform.h" | 27 | #include "platform.h" |
2 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
3 | #include "gnunet_dht_service.h" | 29 | #include "gnunet_dht_service.h" |
4 | #include "gnunet_mesh_service_new.h" | 30 | #include "gnunet_mesh_service_new.h" |
5 | 31 | ||
6 | static struct GNUNET_MESH_MessageHandler handlers[] = { | 32 | static struct GNUNET_MESH_MessageHandler handlers[] = {{NULL, 0, 0}}; |
7 | {NULL, 0, 0} | 33 | static struct GNUNET_OS_Process *arm_pid; |
8 | }; | 34 | static struct GNUNET_MESH_Handle *mesh; |
9 | 35 | static int result; | |
10 | static struct GNUNET_OS_Process *arm_pid; | 36 | GNUNET_SCHEDULER_TaskIdentifier abort_task; |
11 | 37 | GNUNET_SCHEDULER_TaskIdentifier test_task; | |
12 | static struct GNUNET_MESH_Handle *mesh; | ||
13 | 38 | ||
14 | static void | 39 | static void |
15 | do_shutdown (void *cls, | 40 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
16 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
17 | { | 41 | { |
42 | if (0 != abort_task) { | ||
43 | GNUNET_SCHEDULER_cancel(abort_task); | ||
44 | } | ||
18 | if (NULL != mesh) { | 45 | if (NULL != mesh) { |
19 | GNUNET_MESH_disconnect (mesh); | 46 | GNUNET_MESH_disconnect (mesh); |
20 | } | 47 | } |
@@ -25,50 +52,67 @@ do_shutdown (void *cls, | |||
25 | GNUNET_OS_process_close (arm_pid); | 52 | GNUNET_OS_process_close (arm_pid); |
26 | } | 53 | } |
27 | 54 | ||
28 | |||
29 | static void | 55 | static void |
30 | error_shutdown (void *cls, | 56 | do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
31 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
32 | { | 57 | { |
33 | if (NULL != mesh) { | 58 | if (0 != test_task) { |
34 | GNUNET_MESH_disconnect (mesh); | 59 | GNUNET_SCHEDULER_cancel(test_task); |
35 | } | 60 | } |
36 | if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) { | 61 | result = GNUNET_SYSERR; |
37 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 62 | abort_task = 0; |
38 | } | 63 | do_shutdown(cls, tc); |
39 | GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid)); | ||
40 | GNUNET_OS_process_close (arm_pid); | ||
41 | } | 64 | } |
42 | 65 | ||
43 | static void | 66 | static void |
44 | run (void *cls, | 67 | test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
45 | char *const *args, | 68 | { |
46 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { | 69 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
47 | GNUNET_MESH_ApplicationType app; | 70 | GNUNET_MESH_ApplicationType app; |
48 | 71 | ||
49 | arm_pid = GNUNET_OS_start_process (NULL, NULL, | 72 | test_task = 0; |
50 | "gnunet-service-arm", | ||
51 | "gnunet-service-arm", | ||
52 | "-L", "DEBUG", | ||
53 | "-c", "test_mesh.conf", | ||
54 | NULL); | ||
55 | app = 0; | 73 | app = 0; |
56 | mesh = GNUNET_MESH_connect(cfg, NULL, NULL, handlers, &app); | 74 | mesh = GNUNET_MESH_connect(cfg, NULL, NULL, handlers, &app); |
57 | if(NULL == mesh) { | 75 | if(NULL == mesh) { |
58 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to mesh :(\n"); | 76 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to mesh :(\n"); |
77 | return; | ||
59 | } else { | 78 | } else { |
60 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO MESH :D\n"); | 79 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO MESH :D\n"); |
61 | } | 80 | } |
62 | 81 | ||
63 | /* do real test work here */ | ||
64 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply( | 82 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply( |
65 | GNUNET_TIME_UNIT_SECONDS, 5), | 83 | GNUNET_TIME_UNIT_SECONDS, 1), |
66 | &do_shutdown, | 84 | &do_shutdown, |
67 | NULL); | 85 | NULL); |
86 | } | ||
87 | |||
88 | |||
89 | static void | ||
90 | run (void *cls, | ||
91 | char *const *args, | ||
92 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
93 | { | ||
94 | arm_pid = GNUNET_OS_start_process (NULL, NULL, | ||
95 | "gnunet-service-arm", | ||
96 | "gnunet-service-arm", | ||
97 | "-L", "DEBUG", | ||
98 | "-c", "test_mesh.conf", | ||
99 | NULL); | ||
100 | |||
101 | abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply( | ||
102 | GNUNET_TIME_UNIT_SECONDS, 5), | ||
103 | &do_abort, | ||
104 | NULL); | ||
105 | test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply( | ||
106 | GNUNET_TIME_UNIT_SECONDS, 1), | ||
107 | &test, | ||
108 | (void *)cfg); | ||
109 | |||
68 | } | 110 | } |
69 | 111 | ||
70 | 112 | ||
71 | int main (int argc, char *argv[]) { | 113 | int |
114 | main (int argc, char *argv[]) | ||
115 | { | ||
72 | int ret; | 116 | int ret; |
73 | char *const argv2[] = {"test-mesh-api", | 117 | char *const argv2[] = {"test-mesh-api", |
74 | "-c", "test_mesh.conf", | 118 | "-c", "test_mesh.conf", |
@@ -82,9 +126,15 @@ int main (int argc, char *argv[]) { | |||
82 | ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, | 126 | ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, |
83 | argv2, "test-mesh-api", "nohelp", | 127 | argv2, "test-mesh-api", "nohelp", |
84 | options, &run, NULL); | 128 | options, &run, NULL); |
85 | if (ret != GNUNET_OK) { | 129 | |
130 | if ( GNUNET_OK != ret ) { | ||
131 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
132 | "test-mesh-api': run failed with error code %d\n", ret); | ||
133 | return 1; | ||
134 | } | ||
135 | if ( GNUNET_SYSERR == result ) { | ||
86 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 136 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
87 | "test-mesh-api': Failed with error code %d\n", ret); | 137 | "test-mesh-api': test failed\n"); |
88 | return 1; | 138 | return 1; |
89 | } | 139 | } |
90 | return 0; | 140 | return 0; |