]>
git.ipfire.org Git - thirdparty/dhcp.git/blob - server/tests/hash_unittest.c
016d7acc438ac3c18e0ce9342fc8e4a070ee08a7
2 * Copyright (c) 2012 by Internet Systems Consortium, Inc. ("ISC")
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
14 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 * Internet Systems Consortium, Inc.
18 * Redwood City, CA 94063
20 * https://www.isc.org/
26 #include <omapip/omapip_p.h>
30 * The following structures are kept here for reference only. As hash functions
31 * are somewhat convoluted, they are copied here for the reference. Original
32 * location is specified. Keep in mind that it may change over time:
34 * copied from server/omapi.c:49 *
35 * omapi_object_type_t *dhcp_type_lease;
36 * omapi_object_type_t *dhcp_type_pool;
37 * omapi_object_type_t *dhcp_type_class;
38 * omapi_object_type_t *dhcp_type_subclass;
39 * omapi_object_type_t *dhcp_type_host;
41 * copied from server/salloc.c:138
42 * OMAPI_OBJECT_ALLOC (lease, struct lease, dhcp_type_lease)
43 * OMAPI_OBJECT_ALLOC (class, struct class, dhcp_type_class)
44 * OMAPI_OBJECT_ALLOC (subclass, struct class, dhcp_type_subclass)
45 * OMAPI_OBJECT_ALLOC (pool, struct pool, dhcp_type_pool)
46 * OMAPI_OBJECT_ALLOC (host, struct host_decl, dhcp_type_host)
48 * copied from server/mdb.c:2686
49 * HASH_FUNCTIONS(lease_ip, const unsigned char *, struct lease, lease_ip_hash_t,
50 * lease_reference, lease_dereference, do_ip4_hash)
51 * HASH_FUNCTIONS(lease_id, const unsigned char *, struct lease, lease_id_hash_t,
52 * lease_reference, lease_dereference, do_id_hash)
53 * HASH_FUNCTIONS (host, const unsigned char *, struct host_decl, host_hash_t,
54 * host_reference, host_dereference, do_string_hash)
55 * HASH_FUNCTIONS (class, const char *, struct class, class_hash_t,
56 * class_reference, class_dereference, do_string_hash)
58 * copied from server/mdb.c:46
59 * host_hash_t *host_hw_addr_hash;
60 * host_hash_t *host_uid_hash;
61 * host_hash_t *host_name_hash;
62 * lease_id_hash_t *lease_uid_hash;
63 * lease_ip_hash_t *lease_ip_addr_hash;
64 * lease_id_hash_t *lease_hw_addr_hash;
68 * @brief sets client-id field in host declaration
70 * @param host pointer to host declaration
71 * @param uid pointer to client-id data
72 * @param uid_len length of the client-id data
74 * @return 1 if successful, 0 otherwise
76 int lease_set_clientid(struct host_decl
*host
, const unsigned char *uid
, int uid_len
) {
78 /* clean-up this mess and set client-identifier in a sane way */
79 int real_len
= uid_len
;
81 real_len
= strlen((const char *)uid
) + 1;
84 memset(&host
->client_identifier
, 0, sizeof(host
->client_identifier
));
85 host
->client_identifier
.len
= uid_len
;
86 if (!buffer_allocate(&host
->client_identifier
.buffer
, real_len
, MDL
)) {
89 host
->client_identifier
.data
= host
->client_identifier
.buffer
->data
;
90 memcpy((char *)host
->client_identifier
.data
, uid
, real_len
);
95 /// @brief executes uid hash test for specified client-ids (2 hosts)
97 /// Creates two host structures, adds first host to the uid hash,
98 /// then adds second host to the hash, then removes first host,
99 /// then removed the second. Many checks are performed during all
102 /// @param clientid1 client-id of the first host
103 /// @param clientid1_len client-id1 length (may be 0 for strings)
104 /// @param clientid2 client-id of the second host
105 /// @param clientid2_len client-id2 length (may be 0 for strings)
106 void lease_hash_test_2hosts(unsigned char clientid1
[], size_t clientid1_len
,
107 unsigned char clientid2
[], size_t clientid2_len
) {
109 printf("Checking hash operation for 2 hosts: clientid1-len=%lu"
110 "clientid2-len=%lu\n", clientid1_len
, clientid2_len
);
112 dhcp_db_objects_setup ();
113 dhcp_common_objects_setup ();
115 /* check that there is actually zero hosts in the hash */
116 /* @todo: host_hash_for_each() */
118 struct host_decl
*host1
= 0, *host2
= 0;
119 struct host_decl
*check
= 0;
121 /* === step 1: allocate hosts === */
122 ATF_CHECK_MSG(host_allocate(&host1
, MDL
) == ISC_R_SUCCESS
,
123 "Failed to allocate host");
124 ATF_CHECK_MSG(host_allocate(&host2
, MDL
) == ISC_R_SUCCESS
,
125 "Failed to allocate host");
127 ATF_CHECK_MSG(host_new_hash(&host_uid_hash
, HOST_HASH_SIZE
, MDL
) != 0,
128 "Unable to create new hash");
130 ATF_CHECK_MSG(buffer_allocate(&host1
->client_identifier
.buffer
,
131 clientid1_len
, MDL
) != 0,
132 "Can't allocate uid buffer for host1");
134 ATF_CHECK_MSG(buffer_allocate(&host2
->client_identifier
.buffer
,
135 clientid2_len
, MDL
) != 0,
136 "Can't allocate uid buffer for host2");
138 /* setting up host1->client_identifier is actually not needed */
140 ATF_CHECK_MSG(lease_set_clientid(host1, clientid1, actual1_len) != 0,
141 "Failed to set client-id for host1");
143 ATF_CHECK_MSG(lease_set_clientid(host2, clientid2, actual2_len) != 0,
144 "Failed to set client-id for host2");
147 ATF_CHECK_MSG(host1
->refcnt
== 1, "Invalid refcnt for host1");
148 ATF_CHECK_MSG(host2
->refcnt
== 1, "Invalid refcnt for host2");
150 /* verify that our hosts are not in the hash yet */
151 ATF_CHECK_MSG(host_hash_lookup(&check
, host_uid_hash
, clientid1
,
152 clientid1_len
, MDL
) == 0,
153 "Host1 is not supposed to be in the uid_hash.");
155 ATF_CHECK_MSG(!check
, "Host1 is not supposed to be in the uid_hash.");
157 ATF_CHECK_MSG(host_hash_lookup(&check
, host_uid_hash
, clientid2
,
158 clientid2_len
, MDL
) == 0,
159 "Host2 is not supposed to be in the uid_hash.");
160 ATF_CHECK_MSG(!check
, "Host2 is not supposed to be in the uid_hash.");
163 /* === step 2: add first host to the hash === */
164 host_hash_add(host_uid_hash
, clientid1
, clientid1_len
, host1
, MDL
);
166 /* 2 pointers expected: ours (host1) and the one stored in hash */
167 ATF_CHECK_MSG(host1
->refcnt
== 2, "Invalid refcnt for host1");
168 /* 1 pointer expected: just ours (host2) */
169 ATF_CHECK_MSG(host2
->refcnt
== 1, "Invalid refcnt for host2");
171 /* verify that host1 is really in the hash and the we can find it */
172 ATF_CHECK_MSG(host_hash_lookup(&check
, host_uid_hash
, clientid1
,
174 "Host1 was supposed to be in the uid_hash.");
175 ATF_CHECK_MSG(check
, "Host1 was supposed to be in the uid_hash.");
177 /* Hey! That's not the host we were looking for! */
178 ATF_CHECK_MSG(check
== host1
, "Wrong host returned by host_hash_lookup");
180 /* 3 pointers: host1, (stored in hash), check */
181 ATF_CHECK_MSG(host1
->refcnt
== 3, "Invalid refcnt for host1");
183 /* reference count should be increased because we not have a pointer */
185 host_dereference(&check
, MDL
); /* we don't need it now */
187 ATF_CHECK_MSG(check
== NULL
, "check pointer is supposed to be NULL");
189 /* 2 pointers: host1, (stored in hash) */
190 ATF_CHECK_MSG(host1
->refcnt
== 2, "Invalid refcnt for host1");
192 /* verify that host2 is not in the hash */
193 ATF_CHECK_MSG(host_hash_lookup(&check
, host_uid_hash
, clientid2
,
194 clientid2_len
, MDL
) == 0,
195 "Host2 was not supposed to be in the uid_hash[2].");
196 ATF_CHECK_MSG(check
== NULL
, "Host2 was not supposed to be in the hash.");
199 /* === step 3: add second hot to the hash === */
200 host_hash_add(host_uid_hash
, clientid2
, clientid2_len
, host2
, MDL
);
202 /* 2 pointers expected: ours (host1) and the one stored in hash */
203 ATF_CHECK_MSG(host2
->refcnt
== 2, "Invalid refcnt for host2");
205 ATF_CHECK_MSG(host_hash_lookup(&check
, host_uid_hash
, clientid2
,
207 "Host2 was supposed to be in the uid_hash.");
208 ATF_CHECK_MSG(check
, "Host2 was supposed to be in the uid_hash.");
210 /* Hey! That's not the host we were looking for! */
211 ATF_CHECK_MSG(check
== host2
, "Wrong host returned by host_hash_lookup");
213 /* 3 pointers: host1, (stored in hash), check */
214 ATF_CHECK_MSG(host2
->refcnt
== 3, "Invalid refcnt for host1");
216 host_dereference(&check
, MDL
); /* we don't need it now */
218 /* now we have 2 hosts in the hash */
220 /* verify that host1 is still in the hash and the we can find it */
221 ATF_CHECK_MSG(host_hash_lookup(&check
, host_uid_hash
, clientid1
,
223 "Host1 was supposed to be in the uid_hash.");
224 ATF_CHECK_MSG(check
, "Host1 was supposed to be in the uid_hash.");
226 /* Hey! That's not the host we were looking for! */
227 ATF_CHECK_MSG(check
== host1
, "Wrong host returned by host_hash_lookup");
229 /* 3 pointers: host1, (stored in hash), check */
230 ATF_CHECK_MSG(host1
->refcnt
== 3, "Invalid refcnt for host1");
232 host_dereference(&check
, MDL
); /* we don't need it now */
236 * @todo check that there is actually two hosts in the hash.
237 * Use host_hash_for_each() for that.
240 /* === step 4: remove first host from the hash === */
242 /* delete host from hash */
243 host_hash_delete(host_uid_hash
, clientid1
, clientid1_len
, MDL
);
245 ATF_CHECK_MSG(host1
->refcnt
== 1, "Invalid refcnt for host1");
246 ATF_CHECK_MSG(host2
->refcnt
== 2, "Invalid refcnt for host2");
248 /* verify that host1 is no longer in the hash */
249 ATF_CHECK_MSG(host_hash_lookup(&check
, host_uid_hash
, clientid1
,
250 clientid1_len
, MDL
) == 0,
251 "Host1 is not supposed to be in the uid_hash.");
252 ATF_CHECK_MSG(!check
, "Host1 is not supposed to be in the uid_hash.");
254 /* host2 should be still there, though */
255 ATF_CHECK_MSG(host_hash_lookup(&check
, host_uid_hash
, clientid2
,
257 "Host2 was supposed to still be in the uid_hash.");
258 host_dereference(&check
, MDL
);
260 /* === step 5: remove second host from the hash === */
261 host_hash_delete(host_uid_hash
, clientid2
, clientid2_len
, MDL
);
263 ATF_CHECK_MSG(host1
->refcnt
== 1, "Invalid refcnt for host1");
264 ATF_CHECK_MSG(host2
->refcnt
== 1, "Invalid refcnt for host2");
266 ATF_CHECK_MSG(host_hash_lookup(&check
, host_uid_hash
, clientid2
,
267 clientid2_len
, MDL
) == 0,
268 "Host2 was not supposed to be in the uid_hash anymore.");
270 host_dereference(&host1
, MDL
);
271 host_dereference(&host2
, MDL
);
274 * No easy way to check if the host object were actually released.
275 * We could run it in valgrind and check for memory leaks.
278 #if defined (DEBUG_MEMORY_LEAKAGE) && defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
279 /* @todo: Should be called in cleanup */
284 /// @brief executes uid hash test for specified client-ids (3 hosts)
286 /// Creates three host structures, adds first host to the uid hash,
287 /// then adds second host to the hash, then removes first host,
288 /// then removed the second. Many checks are performed during all
291 /// @param clientid1 client-id of the first host
292 /// @param clientid1_len client-id1 length (may be 0 for strings)
293 /// @param clientid2 client-id of the second host
294 /// @param clientid2_len client-id2 length (may be 0 for strings)
295 /// @param clientid3 client-id of the second host
296 /// @param clientid3_len client-id2 length (may be 0 for strings)
297 void lease_hash_test_3hosts(unsigned char clientid1
[], size_t clientid1_len
,
298 unsigned char clientid2
[], size_t clientid2_len
,
299 unsigned char clientid3
[], size_t clientid3_len
) {
301 printf("Checking hash operation for 3 hosts: clientid1-len=%lu"
302 " clientid2-len=%lu clientid3-len=%lu\n",
303 clientid1_len
, clientid2_len
, clientid3_len
);
305 dhcp_db_objects_setup ();
306 dhcp_common_objects_setup ();
308 /* check that there is actually zero hosts in the hash */
309 /* @todo: host_hash_for_each() */
311 struct host_decl
*host1
= 0, *host2
= 0, *host3
= 0;
312 struct host_decl
*check
= 0;
314 /* === step 1: allocate hosts === */
315 ATF_CHECK_MSG(host_allocate(&host1
, MDL
) == ISC_R_SUCCESS
,
316 "Failed to allocate host");
317 ATF_CHECK_MSG(host_allocate(&host2
, MDL
) == ISC_R_SUCCESS
,
318 "Failed to allocate host");
319 ATF_CHECK_MSG(host_allocate(&host3
, MDL
) == ISC_R_SUCCESS
,
320 "Failed to allocate host");
322 ATF_CHECK_MSG(host_new_hash(&host_uid_hash
, HOST_HASH_SIZE
, MDL
) != 0,
323 "Unable to create new hash");
325 ATF_CHECK_MSG(buffer_allocate(&host1
->client_identifier
.buffer
,
326 clientid1_len
, MDL
) != 0,
327 "Can't allocate uid buffer for host1");
328 ATF_CHECK_MSG(buffer_allocate(&host2
->client_identifier
.buffer
,
329 clientid2_len
, MDL
) != 0,
330 "Can't allocate uid buffer for host2");
331 ATF_CHECK_MSG(buffer_allocate(&host3
->client_identifier
.buffer
,
332 clientid3_len
, MDL
) != 0,
333 "Can't allocate uid buffer for host3");
335 /* verify that our hosts are not in the hash yet */
336 ATF_CHECK_MSG(host_hash_lookup(&check
, host_uid_hash
, clientid1
,
337 clientid1_len
, MDL
) == 0,
338 "Host1 is not supposed to be in the uid_hash.");
340 ATF_CHECK_MSG(!check
, "Host1 is not supposed to be in the uid_hash.");
342 ATF_CHECK_MSG(host_hash_lookup(&check
, host_uid_hash
, clientid2
,
343 clientid2_len
, MDL
) == 0,
344 "Host2 is not supposed to be in the uid_hash.");
345 ATF_CHECK_MSG(!check
, "Host2 is not supposed to be in the uid_hash.");
347 ATF_CHECK_MSG(host_hash_lookup(&check
, host_uid_hash
, clientid3
,
348 clientid3_len
, MDL
) == 0,
349 "Host3 is not supposed to be in the uid_hash.");
350 ATF_CHECK_MSG(!check
, "Host3 is not supposed to be in the uid_hash.");
352 /* === step 2: add hosts to the hash === */
353 host_hash_add(host_uid_hash
, clientid1
, clientid1_len
, host1
, MDL
);
354 host_hash_add(host_uid_hash
, clientid2
, clientid2_len
, host2
, MDL
);
355 host_hash_add(host_uid_hash
, clientid3
, clientid3_len
, host3
, MDL
);
357 ATF_CHECK_MSG(host_hash_lookup(&check
, host_uid_hash
, clientid1
,
359 "Host1 was supposed to be in the uid_hash.");
360 /* Hey! That's not the host we were looking for! */
361 ATF_CHECK_MSG(check
== host1
, "Wrong host returned by host_hash_lookup");
362 host_dereference(&check
, MDL
); /* we don't need it now */
364 ATF_CHECK_MSG(host_hash_lookup(&check
, host_uid_hash
, clientid2
,
366 "Host2 was supposed to be in the uid_hash.");
367 ATF_CHECK_MSG(check
, "Host2 was supposed to be in the uid_hash.");
368 /* Hey! That's not the host we were looking for! */
369 ATF_CHECK_MSG(check
== host2
, "Wrong host returned by host_hash_lookup");
370 host_dereference(&check
, MDL
); /* we don't need it now */
372 ATF_CHECK_MSG(host_hash_lookup(&check
, host_uid_hash
, clientid3
,
374 "Host3 was supposed to be in the uid_hash.");
375 ATF_CHECK_MSG(check
, "Host3 was supposed to be in the uid_hash.");
376 /* Hey! That's not the host we were looking for! */
377 ATF_CHECK_MSG(check
== host3
, "Wrong host returned by host_hash_lookup");
378 host_dereference(&check
, MDL
); /* we don't need it now */
380 /* === step 4: remove first host from the hash === */
382 /* delete host from hash */
383 host_hash_delete(host_uid_hash
, clientid1
, clientid1_len
, MDL
);
385 /* verify that host1 is no longer in the hash */
386 ATF_CHECK_MSG(host_hash_lookup(&check
, host_uid_hash
, clientid1
,
387 clientid1_len
, MDL
) == 0,
388 "Host1 is not supposed to be in the uid_hash.");
389 ATF_CHECK_MSG(!check
, "Host1 is not supposed to be in the uid_hash.");
391 /* host2 and host3 should be still there, though */
392 ATF_CHECK_MSG(host_hash_lookup(&check
, host_uid_hash
, clientid2
,
394 "Host2 was supposed to still be in the uid_hash.");
395 host_dereference(&check
, MDL
);
396 ATF_CHECK_MSG(host_hash_lookup(&check
, host_uid_hash
, clientid3
,
398 "Host3 was supposed to still be in the uid_hash.");
399 host_dereference(&check
, MDL
);
401 /* === step 5: remove second host from the hash === */
402 host_hash_delete(host_uid_hash
, clientid2
, clientid2_len
, MDL
);
404 ATF_CHECK_MSG(host_hash_lookup(&check
, host_uid_hash
, clientid2
,
405 clientid2_len
, MDL
) == 0,
406 "Host2 was not supposed to be in the uid_hash anymore.");
407 ATF_CHECK_MSG(host_hash_lookup(&check
, host_uid_hash
, clientid3
,
409 "Host3 was supposed to still be in the uid_hash.");
410 host_dereference(&check
, MDL
);
412 /* === step 6: remove the last (third) host from the hash === */
413 host_hash_delete(host_uid_hash
, clientid3
, clientid3_len
, MDL
);
415 ATF_CHECK_MSG(host_hash_lookup(&check
, host_uid_hash
, clientid3
,
416 clientid3_len
, MDL
) == 0,
417 "Host3 was not supposed to be in the uid_hash anymore.");
418 host_dereference(&check
, MDL
);
421 host_dereference(&host1
, MDL
);
422 host_dereference(&host2
, MDL
);
423 host_dereference(&host3
, MDL
);
426 * No easy way to check if the host object were actually released.
427 * We could run it in valgrind and check for memory leaks.
430 #if defined (DEBUG_MEMORY_LEAKAGE) && defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
431 /* @todo: Should be called in cleanup */
436 void lease_hash_test_3hosts_negative(unsigned char clientid1
[], size_t clientid1_len
,
437 unsigned char clientid2
[], size_t clientid2_len
,
438 unsigned char clientid3
[], size_t clientid3_len
) {
440 printf("Checking negative hash operation for 3 hosts: clientid1-len=%lu"
441 " clientid2-len=%lu clientid3-len=%lu\n",
442 clientid1_len
, clientid2_len
, clientid3_len
);
444 dhcp_db_objects_setup ();
445 dhcp_common_objects_setup ();
447 /* check that there is actually zero hosts in the hash */
448 /* @todo: host_hash_for_each() */
450 struct host_decl
*host1
= 0, *host2
= 0, *host3
= 0;
451 struct host_decl
*check
= 0;
453 /* === step 1: allocate hosts === */
454 ATF_CHECK_MSG(host_allocate(&host1
, MDL
) == ISC_R_SUCCESS
,
455 "Failed to allocate host");
456 ATF_CHECK_MSG(host_allocate(&host2
, MDL
) == ISC_R_SUCCESS
,
457 "Failed to allocate host");
458 ATF_CHECK_MSG(host_allocate(&host3
, MDL
) == ISC_R_SUCCESS
,
459 "Failed to allocate host");
461 ATF_CHECK_MSG(host_new_hash(&host_uid_hash
, HOST_HASH_SIZE
, MDL
) != 0,
462 "Unable to create new hash");
464 /* === step 2: add hosts to the hash === */
465 host_hash_add(host_uid_hash
, clientid1
, clientid1_len
, host1
, MDL
);
466 host_hash_delete(host_uid_hash
, clientid1
, clientid1_len
, MDL
);
467 host_hash_add(host_uid_hash
, clientid2
, clientid2_len
, host2
, MDL
);
468 host_hash_delete(host_uid_hash
, clientid2
, clientid2_len
, MDL
);
469 host_hash_delete(host_uid_hash
, clientid2
, clientid2_len
, MDL
);
471 host_hash_delete(host_uid_hash
, clientid1
, clientid1_len
, MDL
);
472 host_hash_add(host_uid_hash
, clientid3
, clientid3_len
, host3
, MDL
);
473 host_hash_delete(host_uid_hash
, clientid3
, clientid3_len
, MDL
);
475 host_dereference(&host1
, MDL
);
476 host_dereference(&host2
, MDL
);
477 host_dereference(&host3
, MDL
);
480 * No easy way to check if the host object were actually released.
481 * We could run it in valgrind and check for memory leaks.
484 #if defined (DEBUG_MEMORY_LEAKAGE) && defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
485 /* @todo: Should be called in cleanup */
492 ATF_TC(lease_hash_basic_2hosts
);
494 ATF_TC_HEAD(lease_hash_basic_2hosts
, tc
) {
495 atf_tc_set_md_var(tc
, "descr", "Basic lease hash tests");
497 * The following functions are tested:
498 * host_allocate(), host_new_hash(), buffer_allocate(), host_hash_lookup()
499 * host_hash_add(), host_hash_delete()
503 ATF_TC_BODY(lease_hash_basic_2hosts
, tc
) {
505 unsigned char clientid1
[] = { 0x1, 0x2, 0x3 };
506 unsigned char clientid2
[] = { 0xff, 0xfe };
508 lease_hash_test_2hosts(clientid1
, sizeof(clientid1
),
509 clientid2
, sizeof(clientid2
));
513 ATF_TC(lease_hash_string_2hosts
);
515 ATF_TC_HEAD(lease_hash_string_2hosts
, tc
) {
516 atf_tc_set_md_var(tc
, "descr", "string-based lease hash tests");
518 * The following functions are tested:
519 * host_allocate(), host_new_hash(), buffer_allocate(), host_hash_lookup()
520 * host_hash_add(), host_hash_delete()
524 ATF_TC_BODY(lease_hash_string_2hosts
, tc
) {
526 unsigned char clientid1
[] = "Alice";
527 unsigned char clientid2
[] = "Bob";
529 lease_hash_test_2hosts(clientid1
, 0, clientid2
, 0);
533 ATF_TC(lease_hash_negative1
);
535 ATF_TC_HEAD(lease_hash_negative1
, tc
) {
536 atf_tc_set_md_var(tc
, "descr", "Negative tests for lease hash");
539 ATF_TC_BODY(lease_hash_negative1
, tc
) {
541 unsigned char clientid1
[] = { 0x1 };
542 unsigned char clientid2
[] = { 0x0 };
544 lease_hash_test_2hosts(clientid1
, 0, clientid2
, 1);
548 ATF_TC(lease_hash_negative2
);
550 ATF_TC_HEAD(lease_hash_negative2
, tc
) {
551 atf_tc_set_md_var(tc
, "descr", "Negative tests for lease hash");
554 ATF_TC_BODY(lease_hash_negative2
, tc
) {
556 unsigned char clientid1
[] = { 0x0 };
557 unsigned char clientid2
[] = { 0x0 };
558 unsigned char clientid3
[] = { 0x0 };
560 lease_hash_test_3hosts_negative(clientid1
, 1, clientid2
, 0, clientid3
, 1);
565 ATF_TC(lease_hash_string_3hosts
);
567 ATF_TC_HEAD(lease_hash_string_3hosts
, tc
) {
568 atf_tc_set_md_var(tc
, "descr", "string-based lease hash tests");
570 * The following functions are tested:
571 * host_allocate(), host_new_hash(), buffer_allocate(), host_hash_lookup()
572 * host_hash_add(), host_hash_delete()
576 ATF_TC_BODY(lease_hash_string_3hosts
, tc
) {
578 unsigned char clientid1
[] = "Alice";
579 unsigned char clientid2
[] = "Bob";
580 unsigned char clientid3
[] = "Charlie";
582 lease_hash_test_3hosts(clientid1
, 0, clientid2
, 0, clientid3
, 0);
586 ATF_TC(lease_hash_basic_3hosts
);
588 ATF_TC_HEAD(lease_hash_basic_3hosts
, tc
) {
589 atf_tc_set_md_var(tc
, "descr", "Basic lease hash tests");
591 * The following functions are tested:
592 * host_allocate(), host_new_hash(), buffer_allocate(), host_hash_lookup()
593 * host_hash_add(), host_hash_delete()
597 ATF_TC_BODY(lease_hash_basic_3hosts
, tc
) {
599 unsigned char clientid1
[] = { 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9 };
600 unsigned char clientid2
[] = { 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8 };
601 unsigned char clientid3
[] = { 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7 };
603 lease_hash_test_3hosts(clientid1
, sizeof(clientid1
),
604 clientid2
, sizeof(clientid2
),
605 clientid3
, sizeof(clientid3
));
608 /* this test is a direct reproduction of 29851 issue */
609 ATF_TC(uid_hash_rt29851
);
611 ATF_TC_HEAD(uid_hash_rt29851
, tc
) {
612 atf_tc_set_md_var(tc
, "descr", "Uid hash tests");
614 /* this test should last less than millisecond. If its execution
615 is longer than 3 second, we hit infinite loop. */
616 atf_tc_set_md_var(tc
, "timeout", "3");
619 ATF_TC_BODY(uid_hash_rt29851
, tc
) {
621 unsigned char clientid1
[] = { 0x0 };
622 unsigned char clientid2
[] = { 0x0 };
623 unsigned char clientid3
[] = { 0x0 };
625 int clientid1_len
= 1;
626 int clientid2_len
= 1;
627 int clientid3_len
= 0;
629 struct lease
*lease1
= 0, *lease2
= 0, *lease3
= 0;
631 dhcp_db_objects_setup ();
632 dhcp_common_objects_setup ();
634 ATF_CHECK(lease_id_new_hash(&lease_uid_hash
, LEASE_HASH_SIZE
, MDL
));
636 ATF_CHECK(lease_allocate (&lease1
, MDL
) == ISC_R_SUCCESS
);
637 ATF_CHECK(lease_allocate (&lease2
, MDL
) == ISC_R_SUCCESS
);
638 ATF_CHECK(lease_allocate (&lease3
, MDL
) == ISC_R_SUCCESS
);
640 lease1
->uid
= clientid1
;
641 lease2
->uid
= clientid2
;
642 lease3
->uid
= clientid3
;
644 lease1
->uid_len
= clientid1_len
;
645 lease2
->uid_len
= clientid2_len
;
646 lease3
->uid_len
= clientid3_len
;
648 uid_hash_add(lease1
);
649 // uid_hash_delete(lease2); // not necessary for actual issue repro
650 uid_hash_add(lease3
);
652 // lease2->uid_len = 0; // not necessary for actual issue repro
653 // uid_hash_delete(lease2); // not necessary for actual issue repro
654 // uid_hash_delete(lease3); // not necessary for actual issue repro
655 uid_hash_delete(lease1
);
657 // lease2->uid_len = 1; // not necessary for actual issue repro
658 uid_hash_add(lease1
);
659 uid_hash_delete(lease2
);
668 ATF_TP_ADD_TC(tp
, lease_hash_basic_2hosts
);
669 ATF_TP_ADD_TC(tp
, lease_hash_basic_3hosts
);
670 ATF_TP_ADD_TC(tp
, lease_hash_string_2hosts
);
671 ATF_TP_ADD_TC(tp
, lease_hash_string_3hosts
);
672 ATF_TP_ADD_TC(tp
, lease_hash_negative1
);
673 ATF_TP_ADD_TC(tp
, lease_hash_negative2
);
674 ATF_TP_ADD_TC(tp
, uid_hash_rt29851
);
675 return (atf_no_error());