diff options
author | Tomek Mrugalski <tomasz@isc.org> | 2012-06-29 19:56:27 +0200 |
---|---|---|
committer | Tomek Mrugalski <tomasz@isc.org> | 2012-06-29 19:56:27 +0200 |
commit | 9f89d01ec134c3dbf1909b8653957b9aec21c939 (patch) | |
tree | 29bdb973db0b90ee7f51c3db2d9c5cb291f05913 /server/tests | |
parent | f3d7118fd1222bbb102bf8f7c310c39ec6f4817d (diff) | |
download | isc-dhcp-9f89d01ec134c3dbf1909b8653957b9aec21c939.tar.gz |
[25901_atf] First test for client-id hash table implemented.
It still lacks many checks and clean-ups, but the core code is there.
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/Makefile.am | 8 | ||||
-rw-r--r-- | server/tests/hash_unittest.c | 142 | ||||
-rw-r--r-- | server/tests/simple_unittest.c | 2 |
3 files changed, 149 insertions, 3 deletions
diff --git a/server/tests/Makefile.am b/server/tests/Makefile.am index 6d6561d4..a15ef57c 100644 --- a/server/tests/Makefile.am +++ b/server/tests/Makefile.am @@ -1,7 +1,7 @@ SUBDIRS = . AM_CPPFLAGS = $(ATF_CFLAGS) -DUNIT_TEST -I$(top_srcdir)/includes -AM_CPPFLAGS += -I$(top_srcdir)/bind/include -I$(top_srcdir) +AM_CPPFLAGS += -std=c99 -I$(top_srcdir)/bind/include -I$(top_srcdir) AM_CPPFLAGS += -DLOCALSTATEDIR='"."' -Wno-unused-function -Wno-error=unused-variable # for autotools debugging only @@ -26,7 +26,7 @@ if HAVE_ATF check: $(ATF_TESTS) atf-run | atf-report -ATF_TESTS += dhcpd_unittests legacy_unittests +ATF_TESTS += dhcpd_unittests legacy_unittests hash_unittests dhcpd_unittests_SOURCES = $(DHCPSRC) dhcpd_unittests_SOURCES += simple_unittest.c @@ -36,6 +36,10 @@ dhcpd_unittests_LDADD += $(DHCPLIBS) dhcpd_unittests_LDFLAGS = $(AM_LDFLAGS) $(ATF_LDFLAGS) +hash_unittests_SOURCES = $(DHCPSRC) hash_unittest.c +hash_unittests_LDADD = $(DHCPLIBS) $(ATF_LDFLAGS) + + # This is a legacy unittest. It replaces main() with something that was in mdb6.c legacy_unittests_SOURCES = $(DHCPSRC) mdb6_unittest.c legacy_unittests_LDADD = $(DHCPLIBS) $(ATF_LDFLAGS) diff --git a/server/tests/hash_unittest.c b/server/tests/hash_unittest.c new file mode 100644 index 00000000..9bb30b82 --- /dev/null +++ b/server/tests/hash_unittest.c @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2012 by Internet Systems Consortium, Inc. ("ISC") + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + * + */ + +#include "config.h" +#include <atf-c.h> +#include <omapip/omapip_p.h> +#include "dhcpd.h" + +#if 0 +/* copied from server/omapi.c:49 */ +omapi_object_type_t *dhcp_type_lease; +omapi_object_type_t *dhcp_type_pool; +omapi_object_type_t *dhcp_type_class; +omapi_object_type_t *dhcp_type_subclass; +omapi_object_type_t *dhcp_type_host; + +/* copied from server/salloc.c:138 */ +OMAPI_OBJECT_ALLOC (lease, struct lease, dhcp_type_lease) +OMAPI_OBJECT_ALLOC (class, struct class, dhcp_type_class) +OMAPI_OBJECT_ALLOC (subclass, struct class, dhcp_type_subclass) +OMAPI_OBJECT_ALLOC (pool, struct pool, dhcp_type_pool) +OMAPI_OBJECT_ALLOC (host, struct host_decl, dhcp_type_host) + +/* copied from server/mdb.c:2686 */ +HASH_FUNCTIONS(lease_ip, const unsigned char *, struct lease, lease_ip_hash_t, + lease_reference, lease_dereference, do_ip4_hash) +HASH_FUNCTIONS(lease_id, const unsigned char *, struct lease, lease_id_hash_t, + lease_reference, lease_dereference, do_id_hash) +HASH_FUNCTIONS (host, const unsigned char *, struct host_decl, host_hash_t, + host_reference, host_dereference, do_string_hash) +HASH_FUNCTIONS (class, const char *, struct class, class_hash_t, + class_reference, class_dereference, do_string_hash) + +host_hash_t *host_hw_addr_hash; +host_hash_t *host_uid_hash; +host_hash_t *host_name_hash; +lease_id_hash_t *lease_uid_hash; +lease_ip_hash_t *lease_ip_addr_hash; +lease_id_hash_t *lease_hw_addr_hash; +#endif + +ATF_TC(lease_hash); + +ATF_TC_HEAD(lease_hash, tc) { + atf_tc_set_md_var(tc, "descr", "Basic hash functions tests"); + +#if 0 + host_hw_addr_hash = 0; + host_uid_hash = 0; + host_name_hash = 0; + lease_uid_hash = 0; + lease_ip_addr_hash = 0; + lease_hw_addr_hash = 0; +#endif +} + +ATF_TC_BODY(lease_hash, tc) { + + dhcp_db_objects_setup (); + dhcp_common_objects_setup (); + + /* check that there is actually zero hosts in the hash */ + // host_hash_for_each( + + struct host_decl *host1 = 0, *host2 = 0; + ATF_CHECK_MSG(host_allocate(&host1, MDL) == ISC_R_SUCCESS, + "Failed to allocate host"); + ATF_CHECK_MSG(host_allocate(&host2, MDL) == ISC_R_SUCCESS, + "Failed to allocate host"); + + /* check that there is actually two hosts in the hash */ + // host_hash_for_each(...) + + if (!host_new_hash(&host_uid_hash, HOST_HASH_SIZE, MDL)) { + atf_tc_fail("Unable to create new hash"); + } else { + printf("#### Hash created\n"); + } + + /* Let's create client-identifier */ + char buf[32]; + memset(buf,0, 32); + for (int i = 0; i < 32; i++) { + buf[i] = i; + } + int bufLen = 16; + + /* clean-up this mess and set client-identifier in a sane way */ + memset(&host1->client_identifier, 0, sizeof(host1->client_identifier)); + host1->client_identifier.len = bufLen; + if (!buffer_allocate(&host1->client_identifier.buffer, bufLen, MDL)) { + atf_tc_fail("Can't allocate uid buffer"); + } + host1->client_identifier.data = host1->client_identifier.buffer->data; + memcpy((char *)host1->client_identifier.data, buf, bufLen); + + /* actual test begins. Add hash */ + host_hash_add(host_uid_hash, host1->client_identifier.data, + host1->client_identifier.len, host1, MDL); + + /** @todo: do some checks here */ + + /* delete host from hash */ + host_hash_delete(host_uid_hash, + host1->client_identifier.data, + host1->client_identifier.len, + MDL); + + /** @todo: do some checks here */ + +#if defined (DEBUG_MEMORY_LEAKAGE) && defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT) + /* @todo: Should be called in cleanup */ + free_everything (); +#endif + +} + +ATF_TP_ADD_TCS(tp) { + ATF_TP_ADD_TC(tp, lease_hash); + + return (atf_no_error()); +} diff --git a/server/tests/simple_unittest.c b/server/tests/simple_unittest.c index 825397ac..e6d04b90 100644 --- a/server/tests/simple_unittest.c +++ b/server/tests/simple_unittest.c @@ -59,7 +59,7 @@ ATF_TC_BODY(simple_test_case, tc) atf_tc_skip("Skipping test. This Linux-only test."); } - if (condition && linux) { + if (condition && this_is_linux) { /* no extra comments for pass needed. It just passed. */ atf_tc_pass(); } |