diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-06-18 02:21:46 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-06-18 02:21:46 +0000 |
commit | d5e417f094cac294282deafe46409342796263c6 (patch) | |
tree | 0f050bb7602193a9e829d2727171fbccf9b03e6a /src/hostlist/test_gnunet_daemon_hostlist.c | |
parent | c3ca725eb3c48d1f1726d3abd2c9816af924d222 (diff) | |
download | gnunet-d5e417f094cac294282deafe46409342796263c6.tar.gz gnunet-d5e417f094cac294282deafe46409342796263c6.zip |
testing-design
Diffstat (limited to 'src/hostlist/test_gnunet_daemon_hostlist.c')
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist.c | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/src/hostlist/test_gnunet_daemon_hostlist.c b/src/hostlist/test_gnunet_daemon_hostlist.c new file mode 100644 index 000000000..443a0d17e --- /dev/null +++ b/src/hostlist/test_gnunet_daemon_hostlist.c | |||
@@ -0,0 +1,135 @@ | |||
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 hostlist/test_gnunet_daemon_hostlist.c | ||
22 | * @brief test for gnunet_daemon_hostslist.c | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "gnunet_util_lib.h" | ||
27 | #include "gnunet_arm_lib.h" | ||
28 | |||
29 | #define VERBOSE GNUNET_YES | ||
30 | |||
31 | #define START_ARM GNUNET_YES | ||
32 | |||
33 | struct PeerContext | ||
34 | { | ||
35 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
36 | struct GNUNET_CORE_Handle *ch; | ||
37 | struct GNUNET_PeerIdentity id; | ||
38 | struct GNUNET_TRANSPORT_Handle *th; | ||
39 | struct GNUNET_MessageHeader *hello; | ||
40 | #if START_ARM | ||
41 | pid_t arm_pid; | ||
42 | #endif | ||
43 | }; | ||
44 | |||
45 | |||
46 | |||
47 | static void | ||
48 | setup_peer (struct PeerContext *p, const char *cfgname) | ||
49 | { | ||
50 | p->cfg = GNUNET_CONFIGURATION_create (); | ||
51 | #if START_ARM | ||
52 | p->arm_pid = GNUNET_OS_start_process ("gnunet-service-arm", | ||
53 | "gnunet-service-arm", | ||
54 | #if VERBOSE | ||
55 | "-L", "DEBUG", | ||
56 | #endif | ||
57 | "-c", cfgname, NULL); | ||
58 | sleep (1); /* allow ARM to start */ | ||
59 | #endif | ||
60 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | ||
61 | GNUNET_ARM_start_service ("core", p->cfg, sched, TIMEOUT, NULL, NULL); | ||
62 | p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, p, NULL, NULL, NULL); | ||
63 | GNUNET_assert (p->th != NULL); | ||
64 | GNUNET_TRANSPORT_get_hello (p->th, TIMEOUT, &process_hello, p); | ||
65 | } | ||
66 | |||
67 | |||
68 | static void | ||
69 | run (void *cls, | ||
70 | struct GNUNET_SCHEDULER_Handle *s, | ||
71 | char *const *args, | ||
72 | const char *cfgfile, struct GNUNET_CONFIGURATION_Handle *cfg) | ||
73 | { | ||
74 | GNUNET_assert (ok == 1); | ||
75 | OKPP; | ||
76 | sched = s; | ||
77 | setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf"); | ||
78 | setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf"); | ||
79 | } | ||
80 | |||
81 | |||
82 | static void | ||
83 | stop_arm (struct PeerContext *p) | ||
84 | { | ||
85 | #if START_ARM | ||
86 | if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) | ||
87 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
88 | if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK) | ||
89 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | ||
90 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
91 | "ARM process %u stopped\n", p->arm_pid); | ||
92 | #endif | ||
93 | GNUNET_CONFIGURATION_destroy (p->cfg); | ||
94 | } | ||
95 | |||
96 | |||
97 | static int | ||
98 | check () | ||
99 | { | ||
100 | char *const argv[] = { "test-gnunet-daemon-hostlist", | ||
101 | "-c", "test_gnunet_daemon_hostlist.conf", | ||
102 | #if VERBOSE | ||
103 | "-L", "DEBUG", | ||
104 | #endif | ||
105 | NULL | ||
106 | }; | ||
107 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
108 | GNUNET_GETOPT_OPTION_END | ||
109 | }; | ||
110 | ok = 1; | ||
111 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | ||
112 | argv, "test-gnunet-daemon-hostlist", | ||
113 | "nohelp", options, &run, &ok); | ||
114 | stop_arm (&p1); | ||
115 | stop_arm (&p2); | ||
116 | return ok; | ||
117 | } | ||
118 | |||
119 | |||
120 | int | ||
121 | main (int argc, char *argv[]) | ||
122 | { | ||
123 | |||
124 | int ret; | ||
125 | |||
126 | GNUNET_log_setup ("test-gnunet-daemon-hostlist", | ||
127 | #if VERBOSE | ||
128 | "DEBUG", | ||
129 | #else | ||
130 | "WARNING", | ||
131 | #endif | ||
132 | NULL); | ||
133 | ret = check (); | ||
134 | return 0; | ||
135 | } | ||