diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-05-05 18:11:27 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-05-05 18:11:27 +0000 |
commit | 120c8b257ce936c84ac78f760b2f4e737bb60657 (patch) | |
tree | 2ead9c8902ad05d26d5377b281e5f68a72a20150 /src | |
parent | 8e4c75f917ce5aa92eb0b39eef44aaffac3a0a27 (diff) | |
download | gnunet-120c8b257ce936c84ac78f760b2f4e737bb60657.tar.gz gnunet-120c8b257ce936c84ac78f760b2f4e737bb60657.zip |
-draft of new low-level testing code structure
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_testing_lib-new.h | 5 | ||||
-rw-r--r-- | src/testing/testing_new.c | 119 |
2 files changed, 121 insertions, 3 deletions
diff --git a/src/include/gnunet_testing_lib-new.h b/src/include/gnunet_testing_lib-new.h index 0943d6d06..0121f4c52 100644 --- a/src/include/gnunet_testing_lib-new.h +++ b/src/include/gnunet_testing_lib-new.h | |||
@@ -77,9 +77,12 @@ GNUNET_TESTING_system_create (const char *tmppath, | |||
77 | * Free system resources. | 77 | * Free system resources. |
78 | * | 78 | * |
79 | * @param system system to be freed | 79 | * @param system system to be freed |
80 | * @param remove_paths should the 'tmppath' and all subdirectories | ||
81 | * be removed (clean up on shutdown)? | ||
80 | */ | 82 | */ |
81 | void | 83 | void |
82 | GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system); | 84 | GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system, |
85 | int remove_paths); | ||
83 | 86 | ||
84 | 87 | ||
85 | /** | 88 | /** |
diff --git a/src/testing/testing_new.c b/src/testing/testing_new.c index cc341e037..33065e954 100644 --- a/src/testing/testing_new.c +++ b/src/testing/testing_new.c | |||
@@ -39,6 +39,43 @@ | |||
39 | */ | 39 | */ |
40 | struct GNUNET_TESTING_System | 40 | struct GNUNET_TESTING_System |
41 | { | 41 | { |
42 | /** | ||
43 | * Prefix (i.e. "/tmp/gnunet-testing/") we prepend to each | ||
44 | * SERVICEHOME. | ||
45 | */ | ||
46 | char *tmppath; | ||
47 | |||
48 | /** | ||
49 | * Bitmap where each TCP port that has already been reserved for | ||
50 | * some GNUnet peer is recorded. Note that we additionally need to | ||
51 | * test if a port is already in use by non-GNUnet components before | ||
52 | * assigning it to a peer/service. If we detect that a port is | ||
53 | * already in use, we also mark it in this bitmap. So all the bits | ||
54 | * that are zero merely indicate ports that MIGHT be available for | ||
55 | * peers. | ||
56 | */ | ||
57 | uint32_t reserved_tcp_ports[65536 / 32]; | ||
58 | |||
59 | /** | ||
60 | * Bitmap where each UDP port that has already been reserved for | ||
61 | * some GNUnet peer is recorded. Note that we additionally need to | ||
62 | * test if a port is already in use by non-GNUnet components before | ||
63 | * assigning it to a peer/service. If we detect that a port is | ||
64 | * already in use, we also mark it in this bitmap. So all the bits | ||
65 | * that are zero merely indicate ports that MIGHT be available for | ||
66 | * peers. | ||
67 | */ | ||
68 | uint32_t reserved_udp_ports[65536 / 32]; | ||
69 | |||
70 | /** | ||
71 | * Counter we use to make service home paths unique on this system; | ||
72 | * the full path consists of the tmppath and this number. Each | ||
73 | * UNIXPATH for a peer is also modified to include the respective | ||
74 | * path counter to ensure uniqueness. This field is incremented | ||
75 | * by one for each configured peer. Even if peers are destroyed, | ||
76 | * we never re-use path counters. | ||
77 | */ | ||
78 | uint32_t path_counter; | ||
42 | }; | 79 | }; |
43 | 80 | ||
44 | 81 | ||
@@ -47,6 +84,26 @@ struct GNUNET_TESTING_System | |||
47 | */ | 84 | */ |
48 | struct GNUNET_TESTING_Peer | 85 | struct GNUNET_TESTING_Peer |
49 | { | 86 | { |
87 | |||
88 | /** | ||
89 | * Path to the configuration file for this peer. | ||
90 | */ | ||
91 | char *cfgfile; | ||
92 | |||
93 | /** | ||
94 | * Binary to be executed during 'GNUNET_TESTING_peer_start'. | ||
95 | * Typically 'gnunet-service-arm' (but can be set to a | ||
96 | * specific service by 'GNUNET_TESTING_service_run' if | ||
97 | * necessary). | ||
98 | */ | ||
99 | char *main_binary; | ||
100 | |||
101 | /** | ||
102 | * Handle to the running binary of the service, NULL if the | ||
103 | * peer/service is currently not running. | ||
104 | */ | ||
105 | struct GNUNET_OS_Process *main_process; | ||
106 | |||
50 | }; | 107 | }; |
51 | 108 | ||
52 | 109 | ||
@@ -73,15 +130,69 @@ GNUNET_TESTING_system_create (const char *tmppath, | |||
73 | * Free system resources. | 130 | * Free system resources. |
74 | * | 131 | * |
75 | * @param system system to be freed | 132 | * @param system system to be freed |
133 | * @param remove_paths should the 'tmppath' and all subdirectories | ||
134 | * be removed (clean up on shutdown)? | ||
76 | */ | 135 | */ |
77 | void | 136 | void |
78 | GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system) | 137 | GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system, |
138 | int remove_paths) | ||
139 | { | ||
140 | GNUNET_break (0); | ||
141 | } | ||
142 | |||
143 | |||
144 | /** | ||
145 | * Reserve a TCP or UDP port for a peer. | ||
146 | * | ||
147 | * @param system system to use for reservation tracking | ||
148 | * @param is_tcp GNUNET_YES for TCP ports, GNUNET_NO for UDP | ||
149 | * @return 0 if no free port was available | ||
150 | */ | ||
151 | // static | ||
152 | uint16_t | ||
153 | reserve_port (struct GNUNET_TESTING_System *system, | ||
154 | int is_tcp) | ||
79 | { | 155 | { |
80 | GNUNET_break (0); | 156 | GNUNET_break (0); |
157 | return 0; | ||
81 | } | 158 | } |
82 | 159 | ||
83 | 160 | ||
84 | /** | 161 | /** |
162 | * Release reservation of a TCP or UDP port for a peer | ||
163 | * (used during GNUNET_TESTING_peer_destroy). | ||
164 | * | ||
165 | * @param system system to use for reservation tracking | ||
166 | * @param is_tcp GNUNET_YES for TCP ports, GNUNET_NO for UDP | ||
167 | * @param port reserved port to release | ||
168 | */ | ||
169 | // static | ||
170 | void | ||
171 | release_port (struct GNUNET_TESTING_System *system, | ||
172 | int is_tcp, | ||
173 | uint16_t port) | ||
174 | { | ||
175 | GNUNET_break (0); | ||
176 | } | ||
177 | |||
178 | |||
179 | /** | ||
180 | * Reserve a SERVICEHOME path for a peer. | ||
181 | * | ||
182 | * @param system system to use for reservation tracking | ||
183 | * @return NULL on error, otherwise fresh unique path to use | ||
184 | * as the servicehome for the peer | ||
185 | */ | ||
186 | // static | ||
187 | char * | ||
188 | reserve_path (struct GNUNET_TESTING_System *system) | ||
189 | { | ||
190 | GNUNET_break (0); | ||
191 | return NULL; | ||
192 | } | ||
193 | |||
194 | |||
195 | /** | ||
85 | * Testing includes a number of pre-created hostkeys for | 196 | * Testing includes a number of pre-created hostkeys for |
86 | * faster peer startup. This function can be used to | 197 | * faster peer startup. This function can be used to |
87 | * access the n-th key of those pre-created hostkeys; note | 198 | * access the n-th key of those pre-created hostkeys; note |
@@ -124,7 +235,11 @@ GNUNET_TESTING_hostkey_get (uint32_t key_number, | |||
124 | */ | 235 | */ |
125 | int | 236 | int |
126 | GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system, | 237 | GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system, |
127 | struct GNUNET_CONFIGURATION_Handle *cfg); | 238 | struct GNUNET_CONFIGURATION_Handle *cfg) |
239 | { | ||
240 | GNUNET_break (0); | ||
241 | return GNUNET_SYSERR; | ||
242 | } | ||
128 | 243 | ||
129 | 244 | ||
130 | /** | 245 | /** |