From cecb1e4b6e30382ba3dfa05b369fd2794d1d12ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= <ondrej@sury.org> Date: Tue, 15 Oct 2013 16:37:47 +0200 Subject: [PATCH] Remove old src/tests/ --- src/tests/Makefile.am | 71 - src/tests/common/acl_tests.c | 167 --- src/tests/common/acl_tests.h | 25 - src/tests/common/base32hex_tests.c | 196 --- src/tests/common/base32hex_tests.h | 25 - src/tests/common/base64_tests.c | 184 --- src/tests/common/base64_tests.h | 25 - src/tests/common/descriptor_tests.c | 269 ---- src/tests/common/descriptor_tests.h | 25 - src/tests/common/events_tests.c | 199 --- src/tests/common/events_tests.h | 25 - src/tests/common/fdset_tests.c | 167 --- src/tests/common/fdset_tests.h | 25 - src/tests/common/hattrie_tests.c | 161 --- src/tests/common/hattrie_tests.h | 25 - src/tests/common/slab_tests.c | 117 -- src/tests/common/slab_tests.h | 25 - src/tests/files/sample_conf | 59 - src/tests/knot/conf_tests.c | 147 -- src/tests/knot/conf_tests.h | 25 - src/tests/knot/dthreads_tests.c | 292 ---- src/tests/knot/dthreads_tests.h | 25 - src/tests/knot/journal_tests.c | 283 ---- src/tests/knot/journal_tests.h | 25 - src/tests/knot/rrl_tests.c | 227 --- src/tests/knot/rrl_tests.h | 25 - src/tests/knot/server_tests.c | 115 -- src/tests/knot/server_tests.h | 25 - src/tests/libknot/dname_tests.c | 164 --- src/tests/libknot/dname_tests.h | 24 - src/tests/libknot/dnssec_keys_tests.c | 259 ---- src/tests/libknot/dnssec_keys_tests.h | 24 - src/tests/libknot/dnssec_nsec3_tests.c | 114 -- src/tests/libknot/dnssec_nsec3_tests.h | 24 - src/tests/libknot/dnssec_sign_tests.c | 152 -- src/tests/libknot/dnssec_sign_tests.h | 24 - src/tests/libknot/dnssec_zone_nsec_tests.c | 63 - src/tests/libknot/dnssec_zone_nsec_tests.h | 24 - src/tests/libknot/rrset_tests.c | 1468 -------------------- src/tests/libknot/rrset_tests.h | 34 - src/tests/libknot/wire_tests.c | 58 - src/tests/libknot/wire_tests.h | 24 - src/tests/libknot/ztree_tests.c | 135 -- src/tests/libknot/ztree_tests.h | 24 - src/tests/unittests_main.c | 110 -- 45 files changed, 5704 deletions(-) delete mode 100644 src/tests/Makefile.am delete mode 100644 src/tests/common/acl_tests.c delete mode 100644 src/tests/common/acl_tests.h delete mode 100644 src/tests/common/base32hex_tests.c delete mode 100644 src/tests/common/base32hex_tests.h delete mode 100644 src/tests/common/base64_tests.c delete mode 100644 src/tests/common/base64_tests.h delete mode 100644 src/tests/common/descriptor_tests.c delete mode 100644 src/tests/common/descriptor_tests.h delete mode 100644 src/tests/common/events_tests.c delete mode 100644 src/tests/common/events_tests.h delete mode 100644 src/tests/common/fdset_tests.c delete mode 100644 src/tests/common/fdset_tests.h delete mode 100644 src/tests/common/hattrie_tests.c delete mode 100644 src/tests/common/hattrie_tests.h delete mode 100644 src/tests/common/slab_tests.c delete mode 100644 src/tests/common/slab_tests.h delete mode 100644 src/tests/files/sample_conf delete mode 100644 src/tests/knot/conf_tests.c delete mode 100644 src/tests/knot/conf_tests.h delete mode 100644 src/tests/knot/dthreads_tests.c delete mode 100644 src/tests/knot/dthreads_tests.h delete mode 100644 src/tests/knot/journal_tests.c delete mode 100644 src/tests/knot/journal_tests.h delete mode 100644 src/tests/knot/rrl_tests.c delete mode 100644 src/tests/knot/rrl_tests.h delete mode 100644 src/tests/knot/server_tests.c delete mode 100644 src/tests/knot/server_tests.h delete mode 100644 src/tests/libknot/dname_tests.c delete mode 100644 src/tests/libknot/dname_tests.h delete mode 100644 src/tests/libknot/dnssec_keys_tests.c delete mode 100644 src/tests/libknot/dnssec_keys_tests.h delete mode 100644 src/tests/libknot/dnssec_nsec3_tests.c delete mode 100644 src/tests/libknot/dnssec_nsec3_tests.h delete mode 100644 src/tests/libknot/dnssec_sign_tests.c delete mode 100644 src/tests/libknot/dnssec_sign_tests.h delete mode 100644 src/tests/libknot/dnssec_zone_nsec_tests.c delete mode 100644 src/tests/libknot/dnssec_zone_nsec_tests.h delete mode 100644 src/tests/libknot/rrset_tests.c delete mode 100644 src/tests/libknot/rrset_tests.h delete mode 100644 src/tests/libknot/wire_tests.c delete mode 100644 src/tests/libknot/wire_tests.h delete mode 100644 src/tests/libknot/ztree_tests.c delete mode 100644 src/tests/libknot/ztree_tests.h delete mode 100644 src/tests/unittests_main.c diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am deleted file mode 100644 index e326542512..0000000000 --- a/src/tests/Makefile.am +++ /dev/null @@ -1,71 +0,0 @@ -ACLOCAL_AMFLAGS = -I $(top_srcdir)/m4 - -AM_CPPFLAGS = -I$(top_srcdir)/src \ - -DSYSCONFDIR='"$(sysconfdir)"' -DSBINDIR='"$(sbindir)"' - -check_PROGRAMS = \ - unittests - -TESTS = unittests - -EXTRA_DIST = \ - files/sample_conf - -BUILT_SOURCES = \ - sample_conf.rc - -CLEANFILES = \ - sample_conf.rc - -nodist_unittests_SOURCES = \ - sample_conf.rc - -unittests_SOURCES = \ - common/acl_tests.c \ - common/acl_tests.h \ - common/base32hex_tests.c \ - common/base32hex_tests.h \ - common/base64_tests.c \ - common/base64_tests.h \ - common/descriptor_tests.h \ - common/descriptor_tests.c \ - common/events_tests.c \ - common/events_tests.h \ - common/fdset_tests.c \ - common/fdset_tests.h \ - common/hattrie_tests.c \ - common/hattrie_tests.h \ - common/slab_tests.c \ - common/slab_tests.h \ - knot/conf_tests.c \ - knot/conf_tests.h \ - knot/dthreads_tests.c \ - knot/dthreads_tests.h \ - knot/journal_tests.c \ - knot/journal_tests.h \ - knot/server_tests.c \ - knot/server_tests.h \ - knot/rrl_tests.h \ - knot/rrl_tests.c \ - libknot/dname_tests.h \ - libknot/dname_tests.c \ - libknot/ztree_tests.h \ - libknot/ztree_tests.c \ - libknot/wire_tests.h \ - libknot/wire_tests.c \ - libknot/rrset_tests.c \ - libknot/rrset_tests.h \ - libknot/dnssec_keys_tests.c \ - libknot/dnssec_keys_tests.h \ - libknot/dnssec_nsec3_tests.c \ - libknot/dnssec_nsec3_tests.h \ - libknot/dnssec_sign_tests.c \ - libknot/dnssec_sign_tests.h \ - libknot/dnssec_zone_nsec_tests.c \ - libknot/dnssec_zone_nsec_tests.h \ - unittests_main.c - -unittests_LDADD = ../libknotd.la ../libknots.la @LIBOBJS@ - -sample_conf.rc: files/sample_conf - $(top_srcdir)/resource.sh $(srcdir)/files/sample_conf >$@ diff --git a/src/tests/common/acl_tests.c b/src/tests/common/acl_tests.c deleted file mode 100644 index f63ac3dbda..0000000000 --- a/src/tests/common/acl_tests.c +++ /dev/null @@ -1,167 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <config.h> -#include <sys/types.h> -#include <sys/socket.h> - -#include "common/errcode.h" -#include "tests/common/acl_tests.h" -#include "common/sockaddr.h" -#include "common/acl.h" - -static int acl_tests_count(int argc, char *argv[]); -static int acl_tests_run(int argc, char *argv[]); - -/*! Exported unit API. - */ -unit_api acl_tests_api = { - "ACL", //! Unit name - &acl_tests_count, //! Count scheduled tests - &acl_tests_run //! Run scheduled tests -}; - -static int acl_tests_count(int argc, char *argv[]) -{ - return 19; -} - -static int acl_tests_run(int argc, char *argv[]) -{ - // 1. Create an ACL - acl_match_t *match = NULL; - acl_t *acl = acl_new(); - ok(acl != 0, "acl: new"); - - // 2. Create IPv4 address - sockaddr_t test_v4; - int ret = sockaddr_set(&test_v4, AF_INET, "127.0.0.1", 12345); - ok(ret > 0, "acl: new IPv4 address"); - - // 3. Create IPv6 address - sockaddr_t test_v6; - ret = sockaddr_set(&test_v6, AF_INET6, "::1", 54321); - ok(ret > 0, "acl: new IPv6 address"); - - // 4. Create simple IPv4 rule - ret = acl_insert(acl, &test_v4, NULL); - ok(ret == KNOT_EOK, "acl: inserted IPv4 rule"); - - // 5. Create simple IPv6 rule - ret = acl_insert(acl, &test_v6, NULL); - ok(ret == KNOT_EOK, "acl: inserted IPv6 rule"); - - // 6. Create simple IPv4 'any port' rule - sockaddr_t test_v4a; - sockaddr_set(&test_v4a, AF_INET, "20.20.20.20", 0); - ret = acl_insert(acl, &test_v4a, NULL); - ok(ret == KNOT_EOK, "acl: inserted IPv4 'any port' rule"); - - // 7. Attempt to match unmatching address - sockaddr_t unmatch_v4; - sockaddr_set(&unmatch_v4, AF_INET, "10.10.10.10", 24424); - match = acl_find(acl, &unmatch_v4); - ok(match == NULL, "acl: matching non-existing address"); - - // 8. Attempt to match unmatching IPv6 address - sockaddr_t unmatch_v6; - sockaddr_set(&unmatch_v6, AF_INET6, "2001:db8::1428:57ab", 24424); - match = acl_find(acl, &unmatch_v6); - ok(match == NULL, "acl: matching non-existing IPv6 address"); - - // 9. Attempt to match matching address - match = acl_find(acl, &test_v4); - ok(match != NULL, "acl: matching existing address"); - - // 10. Attempt to match matching address - match = acl_find(acl, &test_v6); - ok(match != NULL, "acl: matching existing IPv6 address"); - - // 11. Attempt to match matching 'any port' address - sockaddr_t match_v4a; - sockaddr_set(&match_v4a, AF_INET, "20.20.20.20", 24424); - match = acl_find(acl, &match_v4a); - ok(match != NULL, "acl: matching existing IPv4 'any port' address"); - - // 12. Attempt to match matching address without matching port - skip(1, 1) { - sockaddr_set(&unmatch_v4, AF_INET, "127.0.0.1", 54321); - match = acl_find(acl, &unmatch_v4); - ok(match == NULL, "acl: matching address without matching port"); - } endskip; - - // 13. Invalid parameters - lives_ok({ - acl_delete(0); - acl_insert(0, 0, NULL); - acl_find(0, 0); - acl_truncate(0); - }, "acl: won't crash with NULL parameters"); - - // 14. Attempt to match subnet - sockaddr_t match_pf4, test_pf4; - sockaddr_set(&match_pf4, AF_INET, "192.168.1.0", 0); - sockaddr_setprefix(&match_pf4, 24); - acl_insert(acl, &match_pf4, NULL); - sockaddr_set(&test_pf4, AF_INET, "192.168.1.20", 0); - match = acl_find(acl, &test_pf4); - ok(match != NULL, "acl: searching address in matching prefix /24"); - - // 15. Attempt to search non-matching subnet - sockaddr_set(&test_pf4, AF_INET, "192.168.2.20", 0); - match = acl_find(acl, &test_pf4); - ok(match == NULL, "acl: searching address in non-matching prefix /24"); - - // 16. Attempt to match v6 subnet - sockaddr_t match_pf6, test_pf6; - sockaddr_set(&match_pf6, AF_INET6, "2001:0DB8:0400:000e:0:0:0:AB00", 0); - sockaddr_setprefix(&match_pf6, 120); - acl_insert(acl, &match_pf6, NULL); - sockaddr_set(&test_pf6, AF_INET6, "2001:0DB8:0400:000e:0:0:0:AB03", 0); - match = acl_find(acl, &test_pf6); - ok(match != NULL, "acl: searching v6 address in matching prefix /120"); - - // 17. Attempt to search non-matching subnet - sockaddr_set(&test_pf6, AF_INET6, "2001:0DB8:0400:000e:0:0:0:CCCC", 0); - match = acl_find(acl, &test_pf6); - ok(match == NULL, "acl: searching v6 address in non-matching prefix /120"); - - // 18. Add preferred node - sockaddr_set(&test_pf4, AF_INET, "192.168.0.0", 0); - sockaddr_setprefix(&test_pf4, 16); - acl_insert(acl, &test_pf4, NULL); - sockaddr_set(&match_pf4, AF_INET, "192.168.1.20", 0); - void *sval = (void*)0x1234; - acl_insert(acl, &match_pf4, sval); - match = acl_find(acl, &match_pf4); - ok(match && match->val == sval, "acl: search for preferred node"); - - // 19. Scenario after truncating - acl_truncate(acl); - sockaddr_set(&test_pf6, AF_INET6, "2001:a1b0:e11e:50d1::3:300", 0); - acl_insert(acl, &test_pf6, NULL); - sockaddr_set(&test_pf4, AF_INET, "231.17.67.223", 0); - acl_insert(acl, &test_pf4, NULL); - sockaddr_set(&test_pf4, AF_INET, "82.87.48.136", 0); - acl_insert(acl, &test_pf4, NULL); - sockaddr_set(&match_pf4, AF_INET, "82.87.48.136", 12345); - match = acl_find(acl, &match_pf4); - ok(match != NULL, "acl: scenario after truncating"); - acl_delete(&acl); - - // Return - return 0; -} diff --git a/src/tests/common/acl_tests.h b/src/tests/common/acl_tests.h deleted file mode 100644 index a928e2db9c..0000000000 --- a/src/tests/common/acl_tests.h +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef _KNOTD_ACL_TESTS_H_ -#define _KNOTD_ACL_TESTS_H_ - -#include "common/libtap/tap_unit.h" - -/* Unit API. */ -unit_api acl_tests_api; - -#endif /* _KNOTD_ACL_TESTS_H_ */ diff --git a/src/tests/common/base32hex_tests.c b/src/tests/common/base32hex_tests.c deleted file mode 100644 index 1303e4405d..0000000000 --- a/src/tests/common/base32hex_tests.c +++ /dev/null @@ -1,196 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <config.h> -#include "tests/common/base32hex_tests.h" - -#include <stdlib.h> -#include <stdint.h> -#include <string.h> - -#include "common/errcode.h" -#include "common/base32hex.h" - -#define BUF_LEN 256 - -static int base32hex_tests_count(int argc, char *argv[]); -static int base32hex_tests_run(int argc, char *argv[]); - -unit_api base32hex_tests_api = { - "Base32hex encoding", - &base32hex_tests_count, - &base32hex_tests_run -}; - -static int base32hex_tests_count(int argc, char *argv[]) -{ - return 42; -} - -static int base32hex_tests_run(int argc, char *argv[]) -{ - int32_t ret; - uint8_t in[BUF_LEN], ref[BUF_LEN], out[BUF_LEN], out2[BUF_LEN]; - uint32_t in_len, ref_len; - - // 1. test vector -> ENC -> DEC - strcpy((char *)in, ""); - in_len = strlen((char *)in); - strcpy((char *)ref, ""); - ref_len = strlen((char *)ref); - ret = base32hex_encode(in, in_len, out, BUF_LEN); - cmp_ok(ret, "==", ref_len, "1. test vector - ENC output length"); - skip(ret < 0, 1); - ok(memcmp(out, ref, ret) == 0, "1. test vector - ENC output content"); - endskip; - ret = base32hex_decode(out, ret, out2, BUF_LEN); - cmp_ok(ret, "==", in_len, "1. test vector - DEC output length"); - skip(ret < 0, 1); - ok(memcmp(out2, in, ret) == 0, "1. test vector - DEC output content"); - endskip; - - // 2. test vector -> ENC -> DEC - strcpy((char *)in, "f"); - in_len = strlen((char *)in); - strcpy((char *)ref, "CO======"); - ref_len = strlen((char *)ref); - ret = base32hex_encode(in, in_len, out, BUF_LEN); - cmp_ok(ret, "==", ref_len, "2. test vector - ENC output length"); - skip(ret < 0, 1); - ok(memcmp(out, ref, ret) == 0, "2. test vector - ENC output content"); - endskip; - ret = base32hex_decode(out, ret, out2, BUF_LEN); - cmp_ok(ret, "==", in_len, "2. test vector - DEC output length"); - skip(ret < 0, 1); - ok(memcmp(out2, in, ret) == 0, "2. test vector - DEC output content"); - endskip; - - // 3. test vector -> ENC -> DEC - strcpy((char *)in, "fo"); - in_len = strlen((char *)in); - strcpy((char *)ref, "CPNG===="); - ref_len = strlen((char *)ref); - ret = base32hex_encode(in, in_len, out, BUF_LEN); - cmp_ok(ret, "==", ref_len, "3. test vector - ENC output length"); - skip(ret < 0, 1); - ok(memcmp(out, ref, ret) == 0, "3. test vector - ENC output content"); - endskip; - ret = base32hex_decode(out, ret, out2, BUF_LEN); - cmp_ok(ret, "==", in_len, "3. test vector - DEC output length"); - skip(ret < 0, 1); - ok(memcmp(out2, in, ret) == 0, "3. test vector - DEC output content"); - endskip; - - // 4. test vector -> ENC -> DEC - strcpy((char *)in, "foo"); - in_len = strlen((char *)in); - strcpy((char *)ref, "CPNMU==="); - ref_len = strlen((char *)ref); - ret = base32hex_encode(in, in_len, out, BUF_LEN); - cmp_ok(ret, "==", ref_len, "4. test vector - ENC output length"); - skip(ret < 0, 1); - ok(memcmp(out, ref, ret) == 0, "4. test vector - ENC output content"); - endskip; - ret = base32hex_decode(out, ret, out2, BUF_LEN); - cmp_ok(ret, "==", in_len, "4. test vector - DEC output length"); - skip(ret < 0, 1); - ok(memcmp(out2, in, ret) == 0, "4. test vector - DEC output content"); - endskip; - - // 5. test vector -> ENC -> DEC - strcpy((char *)in, "foob"); - in_len = strlen((char *)in); - strcpy((char *)ref, "CPNMUOG="); - ref_len = strlen((char *)ref); - ret = base32hex_encode(in, in_len, out, BUF_LEN); - cmp_ok(ret, "==", ref_len, "5. test vector - ENC output length"); - skip(ret < 0, 1); - ok(memcmp(out, ref, ret) == 0, "5. test vector - ENC output content"); - endskip; - ret = base32hex_decode(out, ret, out2, BUF_LEN); - cmp_ok(ret, "==", in_len, "5. test vector - DEC output length"); - skip(ret < 0, 1); - ok(memcmp(out2, in, ret) == 0, "5. test vector - DEC output content"); - endskip; - - // 6. test vector -> ENC -> DEC - strcpy((char *)in, "fooba"); - in_len = strlen((char *)in); - strcpy((char *)ref, "CPNMUOJ1"); - ref_len = strlen((char *)ref); - ret = base32hex_encode(in, in_len, out, BUF_LEN); - cmp_ok(ret, "==", ref_len, "6. test vector - ENC output length"); - skip(ret < 0, 1); - ok(memcmp(out, ref, ret) == 0, "6. test vector - ENC output content"); - endskip; - ret = base32hex_decode(out, ret, out2, BUF_LEN); - cmp_ok(ret, "==", in_len, "6. test vector - DEC output length"); - skip(ret < 0, 1); - ok(memcmp(out2, in, ret) == 0, "6. test vector - DEC output content"); - endskip; - - // 7. test vector -> ENC -> DEC - strcpy((char *)in, "foobar"); - in_len = strlen((char *)in); - strcpy((char *)ref, "CPNMUOJ1E8======"); - ref_len = strlen((char *)ref); - ret = base32hex_encode(in, in_len, out, BUF_LEN); - cmp_ok(ret, "==", ref_len, "7. test vector - ENC output length"); - skip(ret < 0, 1); - ok(memcmp(out, ref, ret) == 0, "7. test vector - ENC output content"); - endskip; - ret = base32hex_decode(out, ret, out2, BUF_LEN); - cmp_ok(ret, "==", in_len, "7. test vector - DEC output length"); - skip(ret < 0, 1); - ok(memcmp(out2, in, ret) == 0, "7. test vector - DEC output content"); - endskip; - - // Bad paddings - ret = base32hex_decode((uint8_t *)"AAAAAA==", 8, out, BUF_LEN); - cmp_ok(ret, "==", KNOT_BASE32HEX_ECHAR, "Bad padding length 2"); - ret = base32hex_decode((uint8_t *)"AAA=====", 8, out, BUF_LEN); - cmp_ok(ret, "==", KNOT_BASE32HEX_ECHAR, "Bad padding length 5"); - ret = base32hex_decode((uint8_t *)"A======", 8, out, BUF_LEN); - cmp_ok(ret, "==", KNOT_BASE32HEX_ECHAR, "Bad padding length 7"); - ret = base32hex_decode((uint8_t *)"=======", 8, out, BUF_LEN); - cmp_ok(ret, "==", KNOT_BASE32HEX_ECHAR, "Bad padding length 8"); - - // Bad data length - ret = base32hex_decode((uint8_t *)"A", 1, out, BUF_LEN); - cmp_ok(ret, "==", KNOT_BASE32HEX_ESIZE, "Bad data length 1"); - ret = base32hex_decode((uint8_t *)"AA", 2, out, BUF_LEN); - cmp_ok(ret, "==", KNOT_BASE32HEX_ESIZE, "Bad data length 2"); - ret = base32hex_decode((uint8_t *)"AAA", 3, out, BUF_LEN); - cmp_ok(ret, "==", KNOT_BASE32HEX_ESIZE, "Bad data length 3"); - ret = base32hex_decode((uint8_t *)"AAAA", 4, out, BUF_LEN); - cmp_ok(ret, "==", KNOT_BASE32HEX_ESIZE, "Bad data length 4"); - ret = base32hex_decode((uint8_t *)"AAAAA", 5, out, BUF_LEN); - cmp_ok(ret, "==", KNOT_BASE32HEX_ESIZE, "Bad data length 5"); - ret = base32hex_decode((uint8_t *)"AAAAAA", 6, out, BUF_LEN); - cmp_ok(ret, "==", KNOT_BASE32HEX_ESIZE, "Bad data length 6"); - ret = base32hex_decode((uint8_t *)"AAAAAAA", 7, out, BUF_LEN); - cmp_ok(ret, "==", KNOT_BASE32HEX_ESIZE, "Bad data length 7"); - ret = base32hex_decode((uint8_t *)"AAAAAAAAA", 9, out, BUF_LEN); - cmp_ok(ret, "==", KNOT_BASE32HEX_ESIZE, "Bad data length 9"); - - // Bad data character - ret = base32hex_decode((uint8_t *)"AAAAAAA$", 8, out, BUF_LEN); - cmp_ok(ret, "==", KNOT_BASE32HEX_ECHAR, "Bad data character dollar"); - ret = base32hex_decode((uint8_t *)"AAAAAAA ", 8, out, BUF_LEN); - cmp_ok(ret, "==", KNOT_BASE32HEX_ECHAR, "Bad data character space"); - - return 0; -} diff --git a/src/tests/common/base32hex_tests.h b/src/tests/common/base32hex_tests.h deleted file mode 100644 index 57d4153d1e..0000000000 --- a/src/tests/common/base32hex_tests.h +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef _KNOTD_BASE32HEX_TESTS_H_ -#define _KNOTD_BASE32HEX_TESTS_H_ - -#include "common/libtap/tap_unit.h" - -/* Unit API. */ -unit_api base32hex_tests_api; - -#endif /* _KNOTD_BASE32HEX_TESTS_H_ */ diff --git a/src/tests/common/base64_tests.c b/src/tests/common/base64_tests.c deleted file mode 100644 index 0893c0949d..0000000000 --- a/src/tests/common/base64_tests.c +++ /dev/null @@ -1,184 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <config.h> -#include "tests/common/base64_tests.h" - -#include <stdlib.h> -#include <stdint.h> -#include <string.h> - -#include "common/errcode.h" -#include "common/base64.h" - -#define BUF_LEN 256 - -static int base64_tests_count(int argc, char *argv[]); -static int base64_tests_run(int argc, char *argv[]); - -unit_api base64_tests_api = { - "Base64 encoding", - &base64_tests_count, - &base64_tests_run -}; - -static int base64_tests_count(int argc, char *argv[]) -{ - return 36; -} - -static int base64_tests_run(int argc, char *argv[]) -{ - int32_t ret; - uint8_t in[BUF_LEN], ref[BUF_LEN], out[BUF_LEN], out2[BUF_LEN]; - uint32_t in_len, ref_len; - - // 1. test vector -> ENC -> DEC - strcpy((char *)in, ""); - in_len = strlen((char *)in); - strcpy((char *)ref, ""); - ref_len = strlen((char *)ref); - ret = base64_encode(in, in_len, out, BUF_LEN); - cmp_ok(ret, "==", ref_len, "1. test vector - ENC output length"); - skip(ret < 0, 1); - ok(memcmp(out, ref, ret) == 0, "1. test vector - ENC output content"); - endskip; - ret = base64_decode(out, ret, out2, BUF_LEN); - cmp_ok(ret, "==", in_len, "1. test vector - DEC output length"); - skip(ret < 0, 1); - ok(memcmp(out2, in, ret) == 0, "1. test vector - DEC output content"); - endskip; - - // 2. test vector -> ENC -> DEC - strcpy((char *)in, "f"); - in_len = strlen((char *)in); - strcpy((char *)ref, "Zg=="); - ref_len = strlen((char *)ref); - ret = base64_encode(in, in_len, out, BUF_LEN); - cmp_ok(ret, "==", ref_len, "2. test vector - ENC output length"); - skip(ret < 0, 1); - ok(memcmp(out, ref, ret) == 0, "2. test vector - ENC output content"); - endskip; - ret = base64_decode(out, ret, out2, BUF_LEN); - cmp_ok(ret, "==", in_len, "2. test vector - DEC output length"); - skip(ret < 0, 1); - ok(memcmp(out2, in, ret) == 0, "2. test vector - DEC output content"); - endskip; - - // 3. test vector -> ENC -> DEC - strcpy((char *)in, "fo"); - in_len = strlen((char *)in); - strcpy((char *)ref, "Zm8="); - ref_len = strlen((char *)ref); - ret = base64_encode(in, in_len, out, BUF_LEN); - cmp_ok(ret, "==", ref_len, "3. test vector - ENC output length"); - skip(ret < 0, 1); - ok(memcmp(out, ref, ret) == 0, "3. test vector - ENC output content"); - endskip; - ret = base64_decode(out, ret, out2, BUF_LEN); - cmp_ok(ret, "==", in_len, "3. test vector - DEC output length"); - skip(ret < 0, 1); - ok(memcmp(out2, in, ret) == 0, "3. test vector - DEC output content"); - endskip; - - // 4. test vector -> ENC -> DEC - strcpy((char *)in, "foo"); - in_len = strlen((char *)in); - strcpy((char *)ref, "Zm9v"); - ref_len = strlen((char *)ref); - ret = base64_encode(in, in_len, out, BUF_LEN); - cmp_ok(ret, "==", ref_len, "4. test vector - ENC output length"); - skip(ret < 0, 1); - ok(memcmp(out, ref, ret) == 0, "4. test vector - ENC output content"); - endskip; - ret = base64_decode(out, ret, out2, BUF_LEN); - cmp_ok(ret, "==", in_len, "4. test vector - DEC output length"); - skip(ret < 0, 1); - ok(memcmp(out2, in, ret) == 0, "4. test vector - DEC output content"); - endskip; - - // 5. test vector -> ENC -> DEC - strcpy((char *)in, "foob"); - in_len = strlen((char *)in); - strcpy((char *)ref, "Zm9vYg=="); - ref_len = strlen((char *)ref); - ret = base64_encode(in, in_len, out, BUF_LEN); - cmp_ok(ret, "==", ref_len, "5. test vector - ENC output length"); - skip(ret < 0, 1); - ok(memcmp(out, ref, ret) == 0, "5. test vector - ENC output content"); - endskip; - ret = base64_decode(out, ret, out2, BUF_LEN); - cmp_ok(ret, "==", in_len, "5. test vector - DEC output length"); - skip(ret < 0, 1); - ok(memcmp(out2, in, ret) == 0, "5. test vector - DEC output content"); - endskip; - - // 6. test vector -> ENC -> DEC - strcpy((char *)in, "fooba"); - in_len = strlen((char *)in); - strcpy((char *)ref, "Zm9vYmE="); - ref_len = strlen((char *)ref); - ret = base64_encode(in, in_len, out, BUF_LEN); - cmp_ok(ret, "==", ref_len, "6. test vector - ENC output length"); - skip(ret < 0, 1); - ok(memcmp(out, ref, ret) == 0, "6. test vector - ENC output content"); - endskip; - ret = base64_decode(out, ret, out2, BUF_LEN); - cmp_ok(ret, "==", in_len, "6. test vector - DEC output length"); - skip(ret < 0, 1); - ok(memcmp(out2, in, ret) == 0, "6. test vector - DEC output content"); - endskip; - - // 7. test vector -> ENC -> DEC - strcpy((char *)in, "foobar"); - in_len = strlen((char *)in); - strcpy((char *)ref, "Zm9vYmFy"); - ref_len = strlen((char *)ref); - ret = base64_encode(in, in_len, out, BUF_LEN); - cmp_ok(ret, "==", ref_len, "7. test vector - ENC output length"); - skip(ret < 0, 1); - ok(memcmp(out, ref, ret) == 0, "7. test vector - ENC output content"); - endskip; - ret = base64_decode(out, ret, out2, BUF_LEN); - cmp_ok(ret, "==", in_len, "7. test vector - DEC output length"); - skip(ret < 0, 1); - ok(memcmp(out2, in, ret) == 0, "7. test vector - DEC output content"); - endskip; - - // Bad paddings - ret = base64_decode((uint8_t *)"A===", 4, out, BUF_LEN); - cmp_ok(ret, "==", KNOT_BASE64_ECHAR, "Bad padding length 3"); - ret = base64_decode((uint8_t *)"====", 4, out, BUF_LEN); - cmp_ok(ret, "==", KNOT_BASE64_ECHAR, "Bad padding length 4"); - - // Bad data length - ret = base64_decode((uint8_t *)"A", 1, out, BUF_LEN); - cmp_ok(ret, "==", KNOT_BASE64_ESIZE, "Bad data length 1"); - ret = base64_decode((uint8_t *)"AA", 2, out, BUF_LEN); - cmp_ok(ret, "==", KNOT_BASE64_ESIZE, "Bad data length 2"); - ret = base64_decode((uint8_t *)"AAA", 3, out, BUF_LEN); - cmp_ok(ret, "==", KNOT_BASE64_ESIZE, "Bad data length 3"); - ret = base64_decode((uint8_t *)"AAAAA", 5, out, BUF_LEN); - cmp_ok(ret, "==", KNOT_BASE64_ESIZE, "Bad data length 5"); - - // Bad data character - ret = base64_decode((uint8_t *)"AAA$", 4, out, BUF_LEN); - cmp_ok(ret, "==", KNOT_BASE64_ECHAR, "Bad data character dollar"); - ret = base64_decode((uint8_t *)"AAA ", 4, out, BUF_LEN); - cmp_ok(ret, "==", KNOT_BASE64_ECHAR, "Bad data character space"); - - return 0; -} diff --git a/src/tests/common/base64_tests.h b/src/tests/common/base64_tests.h deleted file mode 100644 index 57a0edc557..0000000000 --- a/src/tests/common/base64_tests.h +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef _KNOTD_BASE64_TESTS_H_ -#define _KNOTD_BASE64_TESTS_H_ - -#include "common/libtap/tap_unit.h" - -/* Unit API. */ -unit_api base64_tests_api; - -#endif /* _KNOTD_BASE64_TESTS_H_ */ diff --git a/src/tests/common/descriptor_tests.c b/src/tests/common/descriptor_tests.c deleted file mode 100644 index 4f1fb6c677..0000000000 --- a/src/tests/common/descriptor_tests.c +++ /dev/null @@ -1,269 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <config.h> -#include "tests/common/descriptor_tests.h" - -#include <stdlib.h> -#include <stdint.h> -#include <string.h> - -#include "common/descriptor.h" - -#define BUF_LEN 256 - -static int descriptor_tests_count(int argc, char *argv[]); -static int descriptor_tests_run(int argc, char *argv[]); - -unit_api descriptor_tests_api = { - "RR descriptors", - &descriptor_tests_count, - &descriptor_tests_run -}; - -static int descriptor_tests_count(int argc, char *argv[]) -{ - return 81; -} - -static int descriptor_tests_run(int argc, char *argv[]) -{ - const rdata_descriptor_t *descr; - char name[BUF_LEN]; - int ret; - uint16_t num; - - // Get descriptor, type num to string: - // 1. TYPE0 - descr = get_rdata_descriptor(0); - ok(descr->type_name == 0, "get TYPE0 descriptor name"); - cmp_ok(descr->block_types[0], "==", KNOT_RDATA_WF_REMAINDER, - "get TYPE0 descriptor 1. item type"); - cmp_ok(descr->block_types[1], "==", KNOT_RDATA_WF_END, - "get TYPE0 descriptor 2. item type"); - - ret = knot_rrtype_to_string(0, name, BUF_LEN); - cmp_ok(ret, "!=", -1, "get TYPE0 ret"); - ok(strcmp(name, "TYPE0") == 0, "get TYPE0 name"); - - // 2. A - descr = get_rdata_descriptor(1); - ok(strcmp(descr->type_name, "A") == 0, "get A descriptor name"); - cmp_ok(descr->block_types[0], "==", 4, - "get A descriptor 1. item type"); - cmp_ok(descr->block_types[1], "==", KNOT_RDATA_WF_END, - "get A descriptor 2. item type"); - - ret = knot_rrtype_to_string(1, name, BUF_LEN); - cmp_ok(ret, "!=", -1, "get A ret"); - ok(strcmp(name, "A") == 0, "get A name"); - - // 3. CNAME - descr = get_rdata_descriptor(5); - ok(strcmp(descr->type_name, "CNAME") == 0, "get CNAME descriptor name"); - cmp_ok(descr->block_types[0], "==", KNOT_RDATA_WF_COMPRESSED_DNAME, - "get CNAME descriptor 1. item type"); - cmp_ok(descr->block_types[1], "==", KNOT_RDATA_WF_END, - "get CNAME descriptor 2. item type"); - - ret = knot_rrtype_to_string(5, name, BUF_LEN); - cmp_ok(ret, "!=", -1, "get CNAME ret"); - ok(strcmp(name, "CNAME") == 0, "get CNAME name"); - - // 4. TYPE38 (A6) - descr = get_rdata_descriptor(38); - ok(descr->type_name == 0, "get TYPE38 descriptor name"); - cmp_ok(descr->block_types[0], "==", KNOT_RDATA_WF_REMAINDER, - "get TYPE38 descriptor 1. item type"); - cmp_ok(descr->block_types[1], "==", KNOT_RDATA_WF_END, - "get TYPE38 descriptor 2. item type"); - - ret = knot_rrtype_to_string(38, name, BUF_LEN); - cmp_ok(ret, "!=", -1, "get TYPE38 ret"); - ok(strcmp(name, "TYPE38") == 0, "get TYPE38 name"); - - // 5. ANY - descr = get_rdata_descriptor(255); - ok(strcmp(descr->type_name, "ANY") == 0, "get ANY descriptor name"); - cmp_ok(descr->block_types[0], "==", KNOT_RDATA_WF_REMAINDER, - "get ANY descriptor 1. item type"); - cmp_ok(descr->block_types[1], "==", KNOT_RDATA_WF_END, - "get ANY descriptor 2. item type"); - - ret = knot_rrtype_to_string(255, name, BUF_LEN); - cmp_ok(ret, "!=", -1, "get ANY ret"); - ok(strcmp(name, "ANY") == 0, "get ANY name"); - - // 6. TYPE256 - descr = get_rdata_descriptor(256); - ok(descr->type_name == 0, "get TYPE256 descriptor name"); - cmp_ok(descr->block_types[0], "==", KNOT_RDATA_WF_REMAINDER, - "get TYPE256 descriptor 1. item type"); - cmp_ok(descr->block_types[1], "==", KNOT_RDATA_WF_END, - "get TYPE256 descriptor 2. item type"); - - ret = knot_rrtype_to_string(256, name, BUF_LEN); - cmp_ok(ret, "!=", -1, "get TYPE256 ret"); - ok(strcmp(name, "TYPE256") == 0, "get TYPE256 name"); - - - // Class num to string: - // 7. CLASS0 - ret = knot_rrclass_to_string(0, name, BUF_LEN); - cmp_ok(ret, "!=", -1, "get CLASS0 ret"); - ok(strcmp(name, "CLASS0") == 0, "get CLASS0 name"); - - // 8. IN - ret = knot_rrclass_to_string(1, name, BUF_LEN); - cmp_ok(ret, "!=", -1, "get IN ret"); - ok(strcmp(name, "IN") == 0, "get IN name"); - - // 9. ANY - ret = knot_rrclass_to_string(255, name, BUF_LEN); - cmp_ok(ret, "!=", -1, "get ANY ret"); - ok(strcmp(name, "ANY") == 0, "get ANY name"); - - // 10. CLASS65535 - ret = knot_rrclass_to_string(65535, name, BUF_LEN); - cmp_ok(ret, "!=", -1, "get CLASS65535 ret"); - ok(strcmp(name, "CLASS65535") == 0, "get CLASS65535 name"); - - // String to type num: - // 11. A - ret = knot_rrtype_from_string("A", &num); - cmp_ok(ret, "!=", -1, "get A num ret"); - cmp_ok(num, "==", 1, "get A num"); - - // 12. a - ret = knot_rrtype_from_string("a", &num); - cmp_ok(ret, "!=", -1, "get a num ret"); - cmp_ok(num, "==", 1, "get a num"); - - // 13. AaAa - ret = knot_rrtype_from_string("AaAa", &num); - cmp_ok(ret, "!=", -1, "get AaAa num ret"); - cmp_ok(num, "==", 28, "get AaAa num"); - - // 14. "" - ret = knot_rrtype_from_string("", &num); - cmp_ok(ret, "==", -1, "get "" num ret"); - - // 15. DUMMY - ret = knot_rrtype_from_string("DUMMY", &num); - cmp_ok(ret, "==", -1, "get DUMMY num ret"); - - // 16. TypE33 - ret = knot_rrtype_from_string("TypE33", &num); - cmp_ok(ret, "!=", -1, "get TypE33 num ret"); - cmp_ok(num, "==", 33, "get TypE33 num"); - - // 17. TYPE - ret = knot_rrtype_from_string("TYPE", &num); - cmp_ok(ret, "==", -1, "get TYPE num ret"); - - // 18. TYPE0 - ret = knot_rrtype_from_string("TYPE0", &num); - cmp_ok(ret, "!=", -1, "get TYPE0 num ret"); - cmp_ok(num, "==", 0, "get TYPE0 num"); - - // 19. TYPE65535 - ret = knot_rrtype_from_string("TYPE65535", &num); - cmp_ok(ret, "!=", -1, "get TYPE65535 num ret"); - cmp_ok(num, "==", 65535, "get TYPE65535 num"); - - // 20. TYPE65536 - ret = knot_rrtype_from_string("TYPE65536", &num); - cmp_ok(ret, "==", -1, "get TYPE65536 num ret"); - - // String to class num: - // 21. In - ret = knot_rrclass_from_string("In", &num); - cmp_ok(ret, "!=", -1, "get In num ret"); - cmp_ok(num, "==", 1, "get In num"); - - // 22. ANY - ret = knot_rrclass_from_string("ANY", &num); - cmp_ok(ret, "!=", -1, "get ANY num ret"); - cmp_ok(num, "==", 255, "get ANY num"); - - // 23. "" - ret = knot_rrclass_from_string("", &num); - cmp_ok(ret, "==", -1, "get "" num ret"); - - // 24. DUMMY - ret = knot_rrclass_from_string("DUMMY", &num); - cmp_ok(ret, "==", -1, "get DUMMY num ret"); - - // 25. CLass33 - ret = knot_rrclass_from_string("CLass33", &num); - cmp_ok(ret, "!=", -1, "get CLass33 num ret"); - cmp_ok(num, "==", 33, "get CLass33 num"); - - // 26. CLASS - ret = knot_rrclass_from_string("CLASS", &num); - cmp_ok(ret, "==", -1, "get CLASS num ret"); - - // 27. CLASS0 - ret = knot_rrclass_from_string("CLASS0", &num); - cmp_ok(ret, "!=", -1, "get CLASS0 num ret"); - cmp_ok(num, "==", 0, "get CLASS0 num"); - - // 28. CLASS65535 - ret = knot_rrclass_from_string("CLASS65535", &num); - cmp_ok(ret, "!=", -1, "get CLASS65535 num ret"); - cmp_ok(num, "==", 65535, "get CLASS65535 num"); - - // 29. CLASS65536 - ret = knot_rrclass_from_string("CLASS65536", &num); - cmp_ok(ret, "==", -1, "get CLASS65536 num ret"); - - // Get obsolete descriptor: - // 30. TYPE0 - descr = get_obsolete_rdata_descriptor(0); - ok(descr->type_name == 0, "get TYPE0 descriptor name"); - cmp_ok(descr->block_types[0], "==", KNOT_RDATA_WF_REMAINDER, - "get TYPE0 descriptor 1. item type"); - cmp_ok(descr->block_types[1], "==", KNOT_RDATA_WF_END, - "get TYPE0 descriptor 2. item type"); - - // 31. MD - descr = get_obsolete_rdata_descriptor(3); - ok(strcmp(descr->type_name, "MD") == 0, "get MD descriptor name"); - cmp_ok(descr->block_types[0], "==", KNOT_RDATA_WF_COMPRESSED_DNAME, - "get A descriptor 1. item type"); - cmp_ok(descr->block_types[1], "==", KNOT_RDATA_WF_END, - "get A descriptor 2. item type"); - - // 32. NXT - descr = get_obsolete_rdata_descriptor(30); - ok(strcmp(descr->type_name, "NXT") == 0, "get NXT descriptor name"); - cmp_ok(descr->block_types[0], "==", KNOT_RDATA_WF_COMPRESSED_DNAME, - "get CNAME descriptor 1. item type"); - cmp_ok(descr->block_types[1], "==", KNOT_RDATA_WF_REMAINDER, - "get CNAME descriptor 2. item type"); - cmp_ok(descr->block_types[2], "==", KNOT_RDATA_WF_END, - "get CNAME descriptor 3. item type"); - - // 33. TYPE38 (A6) - descr = get_obsolete_rdata_descriptor(38); - ok(descr->type_name == 0, "get TYPE38 descriptor name"); - cmp_ok(descr->block_types[0], "==", KNOT_RDATA_WF_REMAINDER, - "get TYPE38 descriptor 1. item type"); - cmp_ok(descr->block_types[1], "==", KNOT_RDATA_WF_END, - "get TYPE38 descriptor 2. item type"); - - return 0; -} diff --git a/src/tests/common/descriptor_tests.h b/src/tests/common/descriptor_tests.h deleted file mode 100644 index 7b7f861a99..0000000000 --- a/src/tests/common/descriptor_tests.h +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef _KNOTD_DESCRIPTOR_TESTS_H_ -#define _KNOTD_DESCRIPTOR_TESTS_H_ - -#include "common/libtap/tap_unit.h" - -/* Unit API. */ -unit_api descriptor_tests_api; - -#endif /* _KNOTD_DESCRIPTOR_TESTS_H_ */ diff --git a/src/tests/common/events_tests.c b/src/tests/common/events_tests.c deleted file mode 100644 index 6ceb17a97e..0000000000 --- a/src/tests/common/events_tests.c +++ /dev/null @@ -1,199 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <config.h> -#include <stdlib.h> -#include <stdint.h> -#include <sys/time.h> - -#include "tests/common/events_tests.h" -#include "common/evqueue.h" -#include "common/evsched.h" - -static int events_tests_count(int argc, char *argv[]); -static int events_tests_run(int argc, char *argv[]); - -/*! Exported unit API. - */ -unit_api events_tests_api = { - "Event queue and scheduler", //! Unit name - &events_tests_count, //! Count scheduled tests - &events_tests_run //! Run scheduled tests -}; - -void* term_thr(void *arg) -{ - evsched_t *s = (evsched_t *)arg; - - /* Sleep for 100ms. */ - struct timeval tv; - tv.tv_sec = 0; - tv.tv_usec = 100 * 1000; // 100ms - select(0, 0, 0, 0, &tv); - - /* Issue termination event. */ - evsched_schedule_term(s, 0); - return 0; -} - -static int events_tests_count(int argc, char *argv[]) -{ - int count = 9 + 10; -#ifdef ENABLE_TIMED_TESTS - count += 1; -#endif - return count; -} - -static int events_tests_run(int argc, char *argv[]) -{ - /* - * Event queue tests. - */ - - // 1. Construct an event queue - evqueue_t *q = evqueue_new(); - ok(q != 0, "evqueue: new"); - - // 2. Send integer through event queue - int ret = 0; - uint8_t sent = 0xaf, rcvd = 0; - ret = evqueue_write(q, &sent, sizeof(uint8_t)); - ok(ret == sizeof(uint8_t), "evqueue: send byte through"); - - // 3. Receive byte from event queue - ret = evqueue_read(q, &rcvd, sizeof(uint8_t)); - ok(ret == sizeof(uint8_t), "evqueue: received byte"); - - // 4. Received match - ok(sent == rcvd, "evqueue: received byte match"); - - // 5. Sending event - event_t ev, rev; - memset(&ev, 0, sizeof(event_t)); - memset(&rev, 0, sizeof(event_t)); - ev.type = 0xfa11; - ev.data = (void*)0xceed; - ret = evqueue_add(q, &ev); - ok(ret == 0, "evqueue: sent event to queue"); - - // 6. Poll for new events - struct timespec ts; - ts.tv_sec = 0; - ts.tv_nsec = 100 * 1000 * 1000; // 100ms - ret = evqueue_poll(q, &ts, 0); - ok(ret > 0, "evqueue: polling queue for events"); - - // 7. Compare received event - ret = evqueue_get(q, &rev); - /* Compare useful data, as event owner was changed in evqueue_get(). */ - if (ev.type == rev.type && ev.data == rev.data) { - ret = 0; - } - ok(ret == 0, "evqueue: received event matches sent"); - - // 8. Invalid parameters - lives_ok({ - evqueue_free(0); - evqueue_poll(0,0,0); - evqueue_read(0, 0, 0); - evqueue_write(0, 0, 0); - evqueue_read(0, 0, 0); - evqueue_get(0, 0); - evqueue_add(0, 0); - }, "evqueue: won't crash with NULL parameters"); - - // 9. Free event queue - lives_ok({evqueue_free(&q);}, "evqueue: delete"); - - /* - * Event scheduler tests. - */ - - // 1. Construct event scheduler - event_t *e = 0; - evsched_t *s = evsched_new(); - ok(s != 0, "evsched: new"); - - // 2. Schedule event to happen after N ms - int msecs = 200; - struct timeval st, rt; - gettimeofday(&st, 0); - e = evsched_schedule_cb(s, 0, (void*)0xcafe, msecs); - ok(e != 0, "evsched: scheduled empty event after %dms", msecs); - - // 3. Wait for next event - e = evsched_next(s); - evsched_event_finished(s); - gettimeofday(&rt, 0); - ok(e != 0, "evsched: received valid event"); - -#ifdef ENABLE_TIMED_TESTS - // 4. Check receive time - double passed = (rt.tv_sec - st.tv_sec) * 1000; - passed += (rt.tv_usec - st.tv_usec) / 1000; - double margin = msecs * 0.4; - double lb = msecs - margin, ub = msecs + margin; - int in_bounds = (passed >= lb) && (passed <= ub); - ok(in_bounds, "evsched: receive time %.1lfms is in <%.1lf,%.1lf>", - passed, lb, ub); -#endif - - // 5. Check data - ok(e->data == (void*)0xcafe, "evsched: received data is valid"); - - // 6. Delete event - lives_ok({evsched_event_free(s, e);}, "evsched: deleted event"); - - // 7. Insert and immediately cancel an event - e = evsched_schedule_cb(s, 0, (void*)0xdead, 1000); - ret = evsched_cancel(s, e); - ok(ret >= 0, "evsched: inserted and cancelled an event"); - if (e) { - evsched_event_free(s, e); - } - - // 8. Start listener thread and block - pthread_t t; - pthread_create(&t, 0, term_thr, s); - e = evsched_next(s); - evsched_event_finished(s); - ok(e != 0, "evsched: received termination event"); - - // 9. Termination event is valid - ok(e->type == EVSCHED_TERM, "evsched: termination event is valid"); - evsched_event_free(s, e); - pthread_join(t, 0); - - // 10. Invalid parameters - lives_ok({ - evsched_delete(0); - evsched_event_new(0, 0); - evsched_event_free(0, 0); - evsched_next(0); - evsched_schedule(0, 0, 0); - evsched_schedule_cb(0, 0, 0, 0); - evsched_schedule_term(0, 0); - evsched_cancel(0, 0); - - }, "evsched: won't crash with NULL parameters"); - - // 11. Delete event scheduler - lives_ok({evsched_delete(&s);}, "evsched: delete"); - - - return 0; -} diff --git a/src/tests/common/events_tests.h b/src/tests/common/events_tests.h deleted file mode 100644 index b54b6da3de..0000000000 --- a/src/tests/common/events_tests.h +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef _KNOTD__EVENTS_TESTS_H_ -#define _KNOTD__EVENTS_TESTS_H_ - -#include "common/libtap/tap_unit.h" - -/* Unit API. */ -unit_api events_tests_api; - -#endif /* _KNOTD__EVENTS_TESTS_H_ */ diff --git a/src/tests/common/fdset_tests.c b/src/tests/common/fdset_tests.c deleted file mode 100644 index f5d351c7b0..0000000000 --- a/src/tests/common/fdset_tests.c +++ /dev/null @@ -1,167 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <config.h> -#include <stdlib.h> -#include <stdint.h> -#include <sys/time.h> -#include <pthread.h> - -#include "tests/common/fdset_tests.h" -#include "common/fdset.h" - -#define WRITE_PATTERN ((char) 0xde) -#define WRITE_PATTERN_LEN sizeof(char) - - -/* Subtract the `struct timeval' values X and Y, - storing the result in RESULT. - Return 1 if the difference is negative, otherwise 0. - Copyright http://www.delorie.com/gnu/docs/glibc/libc_428.html -*/ -static int timeval_subtract (struct timeval *result, struct timeval *x, struct timeval* y) -{ - /* Perform the carry for the later subtraction by updating y. */ - if (x->tv_usec < y->tv_usec) { - int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1; - y->tv_usec -= 1000000 * nsec; - y->tv_sec += nsec; - } - if (x->tv_usec - y->tv_usec > 1000000) { - int nsec = (x->tv_usec - y->tv_usec) / 1000000; - y->tv_usec += 1000000 * nsec; - y->tv_sec -= nsec; - } - - /* Compute the time remaining to wait. - tv_usec is certainly positive. */ - result->tv_sec = x->tv_sec - y->tv_sec; - result->tv_usec = x->tv_usec - y->tv_usec; - - /* Return 1 if result is negative. */ - return x->tv_sec < y->tv_sec; -} - -static size_t timeval_diff(struct timeval *from, struct timeval *to) { - struct timeval res; - timeval_subtract(&res, to, from); - return res.tv_sec*1000 + res.tv_usec/1000; -} - -static int fdset_tests_count(int argc, char *argv[]); -static int fdset_tests_run(int argc, char *argv[]); - -/*! Exported unit API. - */ -unit_api fdset_tests_api = { - "Native fdset poll wrapper", //! Unit name - &fdset_tests_count, //! Count scheduled tests - &fdset_tests_run //! Run scheduled tests -}; - -void* thr_action(void *arg) -{ - int *fd = (int *)arg; - - /* Sleep for 100ms. */ - struct timeval tv; - tv.tv_sec = 0; - tv.tv_usec = 100 * 1000; // 100ms - select(0, 0, 0, 0, &tv); - - /* Write pattern. */ - char pattern = WRITE_PATTERN; - if (write(*fd, &pattern, WRITE_PATTERN_LEN) == -1) { - // Error. - } - - return NULL; -} - -static int fdset_tests_count(int argc, char *argv[]) -{ - return 11; -} - -static int fdset_tests_run(int argc, char *argv[]) -{ - /* 1. Create fdset. */ - fdset_t set; - int ret = fdset_init(&set, 32); - ok(ret == 0, "fdset: init"); - - /* 2. Create pipe. */ - int fds[2], tmpfds[2]; - ret = pipe(fds); - ok(ret >= 0, "fdset: pipe() works"); - ret = pipe(tmpfds); - - /* 3. Add fd to set. */ - ret = fdset_add(&set, fds[0], POLLIN, NULL); - ok(ret == 0, "fdset: add to set works"); - fdset_add(&set, tmpfds[0], POLLIN, NULL); - - /* Schedule write. */ - struct timeval ts, te; - gettimeofday(&ts, 0); - pthread_t t; - pthread_create(&t, 0, thr_action, &fds[1]); - - /* 4. Watch fdset. */ - int nfds = poll(set.pfd, set.n, 60 * 1000); - gettimeofday(&te, 0); - size_t diff = timeval_diff(&ts, &te); - - ok(nfds > 0, "fdset: poll returned %d events in %zu ms", nfds, diff); - - /* 5. Prepare event set. */ - ok(set.pfd[0].revents & POLLIN, "fdset: pipe is active"); - - /* 6. Receive data. */ - char buf = 0x00; - ret = read(set.pfd[0].fd, &buf, WRITE_PATTERN_LEN); - ok(ret >= 0 && buf == WRITE_PATTERN, "fdset: contains valid data"); - - /* 7-9. Remove from event set. */ - ret = fdset_remove(&set, 0); - ok(ret == 0, "fdset: remove from fdset works"); - close(fds[0]); - close(fds[1]); - ret = fdset_remove(&set, 0); - close(tmpfds[1]); - close(tmpfds[1]); - ok(ret == 0, "fdset: remove from fdset works (2)"); - ret = fdset_remove(&set, 0); - ok(ret != 0, "fdset: removing nonexistent item"); - - /* 10. Crash test. */ - lives_ok({ - fdset_init(0, 0); - fdset_add(0, 1, 1, 0); - fdset_add(0, 0, 1, 0); - fdset_remove(0, 1); - fdset_remove(0, 0); - }, "fdset: crash test successful"); - - /* 11. Destroy fdset. */ - ret = fdset_clear(&set); - ok(ret == 0, "fdset: destroyed"); - - /* Cleanup. */ - pthread_join(t, 0); - - return 0; -} diff --git a/src/tests/common/fdset_tests.h b/src/tests/common/fdset_tests.h deleted file mode 100644 index d29e1a9d83..0000000000 --- a/src/tests/common/fdset_tests.h +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef _KNOTD_FDSET_TESTS_H_ -#define _KNOTD_FDSET_TESTS_H_ - -#include "common/libtap/tap_unit.h" - -/* Unit API. */ -unit_api fdset_tests_api; - -#endif /* _KNOTD_FDSET_TESTS_H_ */ diff --git a/src/tests/common/hattrie_tests.c b/src/tests/common/hattrie_tests.c deleted file mode 100644 index 941f38cc97..0000000000 --- a/src/tests/common/hattrie_tests.c +++ /dev/null @@ -1,161 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <config.h> -#include <string.h> -#include <time.h> - -#include "tests/common/hattrie_tests.h" -#include "common/mempattern.h" -#include "common/hattrie/hat-trie.h" - -static const char *alphabet = "abcdefghijklmn"; -static char *randstr() { - unsigned len = (1 + rand() % 64) + 1; /* (1-64) + '\0' */ - char *s = xmalloc(len * sizeof(char)); - for (unsigned i = 0; i < len - 1; ++i) { - s[i] = alphabet[rand() % strlen(alphabet)]; - } - s[len - 1] = '\0'; - return s; -} - -static int hattrie_tests_count(int argc, char *argv[]); -static int hattrie_tests_run(int argc, char *argv[]); - -/* - * Unit API. - */ -unit_api hattrie_tests_api = { - "HAT trie", - &hattrie_tests_count, - &hattrie_tests_run -}; - -/* - * Unit implementation. - */ - -static const int HAT_TEST_COUNT = 6; - -static int hattrie_tests_count(int argc, char *argv[]) -{ - return HAT_TEST_COUNT; -} - -static int hattrie_tests_run(int argc, char *argv[]) -{ - /* Interesting intems. */ - unsigned count = 10; - const char *items[] = { - "abcd", - "abc", - "ab", - "a", - "abcdefghijklmnopqrstuvw", - "abAcd", - "abcA", - "abA", - "Aab", - "A" - }; - - /* Dummy items. */ - srand(time(NULL)); - unsigned dummy_count = 10000; - char **dummy = xmalloc(sizeof(char*) * dummy_count); - for (unsigned i = 0; i < dummy_count; ++i) { - dummy[i] = randstr(); - } - - /* Test 1: Create */ - unsigned passed = 1; - value_t *v = NULL; - hattrie_t *t = hattrie_create(); - ok(t != NULL, "hattrie: create"); - - /* Test 2: Insert */ - passed = 1; - for (unsigned i = 0; i < count; ++i) { - v = hattrie_get(t, items[i], strlen(items[i])); - if (!v) { - passed = 0; - break; - } - *v = (value_t)items[i]; - } - ok(passed, "hattrie: insert"); - - /* Test 3: Insert dummy. */ - passed = 1; - for (unsigned i = 0; i < dummy_count; ++i) { - v = hattrie_get(t, dummy[i], strlen(dummy[i])); - if (!v) { - passed = 0; - break; - } - if (*v == NULL) { - *v = dummy[i]; - } - } - ok(passed, "hattrie: dummy insert"); - - /* Test 4: Lookup */ - passed = 1; - for (unsigned i = 0; i < count; ++i) { - v = hattrie_tryget(t, items[i], strlen(items[i])); - if (!v || *v != items[i]) { - diag("hattrie: mismatch on element '%u'", i); - passed = 0; - break; - } - } - ok(passed, "hattrie: lookup"); - - /* Test 5: LPR lookup */ - unsigned lpr_count = 5; - const char *lpr[] = { - "abcdZ", - "abcZ", - "abZ", - "aZ", - "abcdefghijklmnopqrstuvw" - }; - passed = 1; - for (unsigned i = 0; i < lpr_count; ++i) { - int ret = hattrie_find_lpr(t, lpr[i], strlen(lpr[i]), &v); - if (!v || ret != 0 || *v != items[i]) { - diag("hattrie: lpr='%s' mismatch lpr(%s) != %s", - !v ? NULL : *v, lpr[i], items[i]); - passed = 0; - break; - } - } - ok(passed, "hattrie: longest prefix match"); - - /* Test 6: false LPR lookup */ - const char *false_lpr = "Z"; - int ret = hattrie_find_lpr(t, false_lpr, strlen(false_lpr), &v); - ok(ret != 0 && v == NULL, "hattrie: non-existent prefix lookup"); - - - for (unsigned i = 0; i < dummy_count; ++i) { - free(dummy[i]); - } - free(dummy); - hattrie_free(t); - return 0; -} diff --git a/src/tests/common/hattrie_tests.h b/src/tests/common/hattrie_tests.h deleted file mode 100644 index c1e02e624e..0000000000 --- a/src/tests/common/hattrie_tests.h +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef _KNOTD_HATTRIE_TESTS_H_ -#define _KNOTD_HATTRIE_TESTS_H_ - -#include "common/libtap/tap_unit.h" - -/* Unit API. */ -unit_api hattrie_tests_api; - -#endif /* _KNOTD_HATTRIE_TESTS_H_ */ diff --git a/src/tests/common/slab_tests.c b/src/tests/common/slab_tests.c deleted file mode 100644 index 088370d35e..0000000000 --- a/src/tests/common/slab_tests.c +++ /dev/null @@ -1,117 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <config.h> -#include <unistd.h> -#include <stdlib.h> -#include <time.h> -#include <stdbool.h> - -#include "tests/common/slab_tests.h" -#include "common/slab/slab.h" - -/*! \brief Type-safe maximum macro. */ -#define SLAB_MAX(a, b) \ - ({ typeof (a) _a = (a); typeof (b) _b = (b); _a > _b ? _a : _b; }) - - -/* Explicitly ask for symbols, - * as the constructor and destructor - * aren't created for test modules. - */ -extern void slab_init(); -extern void slab_deinit(); - -static int slab_tests_count(int argc, char *argv[]); -static int slab_tests_run(int argc, char *argv[]); - -/*! Exported unit API. - */ -unit_api slab_tests_api = { - "SLAB allocator", //! Unit name - &slab_tests_count, //! Count scheduled tests - &slab_tests_run //! Run scheduled tests -}; - -static int slab_tests_count(int argc, char *argv[]) -{ - return 5; -} - -static int slab_tests_run(int argc, char *argv[]) -{ - // 1. Create slab cache - srand(time(0)); - const unsigned pattern = 0xdeadbeef; - slab_cache_t cache; - int ret = slab_cache_init(&cache, sizeof(int)); - ok(ret == 0, "slab: created empty cache"); - - // 2. Couple alloc/free - bool valid_free = true; - lives_ok({ - for(int i = 0; i < 100; ++i) { - int* data = (int*)slab_cache_alloc(&cache); - *data = pattern; - slab_free(data); - if (*data == pattern) - valid_free = false; - } - }, "slab: couple alloc/free"); - - // 5. Verify freed block - ok(valid_free, "slab: freed memory is correctly invalidated"); - - // 4. Reap memory - slab_t* slab = cache.slabs_free; - int free_count = 0; - while (slab) { - slab_t* next = slab->next; - if (slab_isempty(slab)) { - ++free_count; - } - slab = next; - } - - int reaped = slab_cache_reap(&cache); - cmp_ok(reaped, "==", free_count, "slab: cache reaping works"); - - // Stress cache - int alloc_count = 73521; - void** ptrs = alloca(alloc_count * sizeof(void*)); - int ptrs_i = 0; - for(int i = 0; i < alloc_count; ++i) { - double roll = rand() / (double) RAND_MAX; - if ((ptrs_i == 0) || (roll < 0.6)) { - int id = ptrs_i++; - ptrs[id] = slab_cache_alloc(&cache); - if (ptrs[id] == 0) { - ptrs_i--; - } else { - int* data = (int*)ptrs[id]; - *data = pattern; - } - } else { - slab_free(ptrs[--ptrs_i]); - } - } - - // 5. Delete cache - slab_cache_destroy(&cache); - ok(cache.bufsize == 0, "slab: freed cache"); - - return 0; -} diff --git a/src/tests/common/slab_tests.h b/src/tests/common/slab_tests.h deleted file mode 100644 index 4d45fb8ca4..0000000000 --- a/src/tests/common/slab_tests.h +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef _KNOTD_SLAB_TESTS_H_ -#define _KNOTD_SLAB_TESTS_H_ - -#include "common/libtap/tap_unit.h" - -/* Unit API. */ -unit_api slab_tests_api; - -#endif /* _KNOTD_SLAB_TESTS_H_ */ diff --git a/src/tests/files/sample_conf b/src/tests/files/sample_conf deleted file mode 100644 index 2a3704f2cd..0000000000 --- a/src/tests/files/sample_conf +++ /dev/null @@ -1,59 +0,0 @@ -# configuration file will follow bird (and juniper) type of configuration file -# i.e. curly brackets will be used; - -# what to do with }; -# a) ignore ; if it follows } - -system { - - identity "I have no mouth and must scream"; - version "Infinitesimal"; - storage "."; -} - -keys { - key0.example.net hmac-md5 "Wg=="; # key special for one remote - key1.example.net hmac-md5 "ZGFuCg=="; # implicit key for whole zone -} - -remotes { - remote0 { address 1.2.3.4; } -} - -zones { - example.net { - file "/var/lib/knot/example.net"; - xfr-out remote0; - } -} - -interfaces { - interface0 { - address 10.10.1.1; - port 53531; - } - - interface1 { - address ::0; - # port 53; - } -} - -log { - syslog { - any notice, warning, error; - zone all; - } - - file "/var/log/knot/server.err" { - server error; - } - - stderr { - any warning, error; - } - - stdout { - any info; - } -} diff --git a/src/tests/knot/conf_tests.c b/src/tests/knot/conf_tests.c deleted file mode 100644 index c7b510ffbf..0000000000 --- a/src/tests/knot/conf_tests.c +++ /dev/null @@ -1,147 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <config.h> -#include <stdio.h> - -#include "tests/knot/conf_tests.h" -#include "knot/conf/conf.h" - -/* Resources. */ -#include "sample_conf.rc" - -static int conf_tests_count(int argc, char *argv[]); -static int conf_tests_run(int argc, char *argv[]); - -/*! Exported unit API. - */ -unit_api conf_tests_api = { - "Configuration parser", //! Unit name - &conf_tests_count, //! Count scheduled tests - &conf_tests_run //! Run scheduled tests -}; - -/*! This helper routine should report number of - * scheduled tests for given parameters. - */ -static int conf_tests_count(int argc, char *argv[]) -{ - return 21; -} - -/*! Run all scheduled tests for given parameters. - */ -static int conf_tests_run(int argc, char *argv[]) -{ - - // Test 1: Allocate new config - const char *config_fn = "rc:/sample_conf"; - conf_t *conf = conf_new(config_fn); - ok(conf != 0, "config_new()"); - - // Test 2: Parse config - int ret = conf_parse_str(conf, sample_conf_rc); - ok(ret == 0, "parsing configuration file %s", config_fn); - skip(ret != 0, conf_tests_count(argc, argv) - 2); - { - - // Test 3: Test server version (0-level depth) - is(conf->version, "Infinitesimal", "server version loaded ok"); - - // Test 4: Test interfaces (1-level depth) - ok(!EMPTY_LIST(conf->ifaces), "configured interfaces exist"); - - // Test 5,6,7,8: Interfaces content (2-level depth) - struct node *n = HEAD(conf->ifaces); - conf_iface_t *iface = (conf_iface_t*)n; - is(iface->address, "10.10.1.1", "interface0 address check"); - cmp_ok(iface->port, "==", 53531, "interface0 port check"); - n = n->next; - iface = (conf_iface_t*)n; - is(iface->address, "::0", "interface1 address check"); - cmp_ok(iface->port, "==", 53, "interface1 default port check"); - - // Test 9,10: Check server key - if(conf->key_count <= 0) { - ok(0, "TSIG key algorithm check - NO KEY FOUND"); - ok(0, "TSIG key secret check - NO KEY FOUND"); - } else { - knot_tsig_key_t *k = &((conf_key_t *)HEAD(conf->keys))->k; - uint8_t decoded_secret[] = { 0x5a }; - - cmp_ok(k->algorithm, "==", KNOT_TSIG_ALG_HMAC_MD5, - "TSIG key algorithm check"); - ok(k->secret.size == sizeof(decoded_secret) - && memcmp(k->secret.data, decoded_secret, - sizeof(decoded_secret)) == 0, - "TSIG key secret check"); - } - - // Test 11,12,13,14,15,16,17,18: Check logging facilities - cmp_ok(conf->logs_count, "==", 4, "log facilites count check"); - n = HEAD(conf->logs); - ok(!EMPTY_LIST(conf->logs), "log facilities not empty"); - - conf_log_t *log = (conf_log_t*)n; - node_t *nm = HEAD(log->map); - conf_log_map_t *m = (conf_log_map_t*)nm; - cmp_ok(log->type, "==", LOGT_SYSLOG, "log0 is syslog"); - - skip(EMPTY_LIST(log->map), 5); - { - cmp_ok(m->source, "==", LOG_ANY, "syslog first rule is ANY"); - int mask = LOG_MASK(LOG_NOTICE)|LOG_MASK(LOG_WARNING)|LOG_MASK(LOG_ERR); - cmp_ok(m->prios, "==", mask, "syslog mask is equal"); - nm = nm->next; - m = (conf_log_map_t*)nm; - ok(m != 0, "syslog has more than 1 rule"); - skip(!m, 2); - { - cmp_ok(m->source, "==", LOG_ZONE, "syslog next rule is for zone"); - cmp_ok(m->prios, "==", 0xff, "rule for zone is: any level"); - } - endskip; - } endskip; - - // Test 19,20: File facility checks - n = n->next; - log = (conf_log_t*)n; - ok(n != 0, "log has next facility"); - skip(!n, 1); - { - is(log->file, "/var/log/knot/server.err", "log file matches"); - } endskip; - - // Test 21: Load key dname - const char *sample_str = "key0.example.net"; - knot_dname_t *sample = knot_dname_from_str(sample_str, - strlen(sample_str)); - if (conf->key_count > 0) { - knot_tsig_key_t *k = &((conf_key_t *)HEAD(conf->keys))->k; - ok(knot_dname_cmp(sample, k->name) == 0, - "TSIG key dname check"); - } else { - ok(0, "TSIG key dname check - NO KEY FOUND"); - } - knot_dname_free(&sample); - - } endskip; - - // Deallocating config - conf_free(conf); - - return 0; -} diff --git a/src/tests/knot/conf_tests.h b/src/tests/knot/conf_tests.h deleted file mode 100644 index dfd2fd7a06..0000000000 --- a/src/tests/knot/conf_tests.h +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef _KNOTD_CONF_TESTS_H_ -#define _KNOTD_CONF_TESTS_H_ - -#include "common/libtap/tap_unit.h" - -/* Unit API. */ -unit_api conf_tests_api; - -#endif /* _KNOTD_CONF_TESTS_H_ */ diff --git a/src/tests/knot/dthreads_tests.c b/src/tests/knot/dthreads_tests.c deleted file mode 100644 index 0d1945a420..0000000000 --- a/src/tests/knot/dthreads_tests.c +++ /dev/null @@ -1,292 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <config.h> -#include <pthread.h> -#include <sched.h> -#include <sys/select.h> -#include <signal.h> - -#include "tests/knot/dthreads_tests.h" -#include "knot/server/dthreads.h" - -static int dt_tests_count(int argc, char *argv[]); -static int dt_tests_run(int argc, char *argv[]); - -/* - * Unit API. - */ -unit_api dthreads_tests_api = { - "DThreads", - &dt_tests_count, - &dt_tests_run -}; - -/* - * Unit implementation. - */ -static const int DT_TEST_COUNT = 18; - -/* Unit runnable data. */ -static pthread_mutex_t _runnable_mx; -static volatile int _runnable_i = 0; -static const int _runnable_cycles = 10000; - -/*! \brief Unit runnable. */ -int runnable(struct dthread_t *thread) -{ - for (int i = 0; i < _runnable_cycles; ++i) { - - // Increase counter - pthread_mutex_lock(&_runnable_mx); - ++_runnable_i; - pthread_mutex_unlock(&_runnable_mx); - - // Cancellation point - if (dt_is_cancelled(thread)) { - break; - } - - // Yield - sched_yield(); - } - - return 0; -} - -/*! \brief Unit blocking runnable. */ -int runnable_simio(struct dthread_t *thread) -{ - // Infinite blocking, must be interrupted - select(0, 0, 0, 0, 0); - return 0; -} - -/*! \brief Create unit. */ -static inline dt_unit_t *dt_test_create(int size) -{ - return dt_create(size); -} - -/*! \brief Assign a task. */ -static inline int dt_test_single(dt_unit_t *unit) -{ - return dt_repurpose(unit->threads[0], &runnable, NULL) == 0; -} - -/*! \brief Assign task to all unit threads. */ -static inline int dt_test_coherent(dt_unit_t *unit) -{ - int ret = 0; - for (int i = 0; i < unit->size; ++i) { - ret += dt_repurpose(unit->threads[i], &runnable, NULL); - } - - return ret == 0; -} - -/*! \brief Repurpose single thread. */ -static inline int dt_test_repurpose(dt_unit_t *unit, int id) -{ - return dt_repurpose(unit->threads[id], &runnable_simio, NULL) == 0; -} - -/*! \brief Cancel single thread. */ -static inline int dt_test_cancel(dt_unit_t *unit, int id) -{ - int ret = dt_cancel(unit->threads[id]); - ret |= dt_signalize(unit->threads[id], SIGALRM); - return ret == 0; /* Both succeeded. */ -} - -/*! \brief Reanimate dead threads. */ -static inline int dt_test_reanimate(dt_unit_t *unit) -{ - // Compact all threads - int ret = 0; - ret += dt_compact(unit); - - // Remove purpose from all - for (int i = 0; i < unit->size; ++i) { - ret += dt_repurpose(unit->threads[i], 0, 0); - } - - // Set single thread to purpose - ret += dt_repurpose(unit->threads[0], &runnable, 0); - - // Restart - _runnable_i = 0; - ret += dt_start(unit); - - // Wait for finish - ret += dt_join(unit); - - // Verify - int expected = 1 * _runnable_cycles; - if (_runnable_i != expected) { - return 0; - } - - // Check return codes - return ret == 0; -} - -/*! \brief Start unit. */ -static inline int dt_test_start(dt_unit_t *unit) -{ - return dt_start(unit) == 0; -} - -/*! \brief Stop unit. */ -static inline int dt_test_stop(dt_unit_t *unit) -{ - return dt_stop(unit); -} - -/*! \brief Join unit. */ -static inline int dt_test_join(dt_unit_t *unit) -{ - return dt_join(unit) == 0; -} - -/*! API: return number of tests. */ -static int dt_tests_count(int argc, char *argv[]) -{ - return DT_TEST_COUNT; -} - -// Signal handler -static void interrupt_handle(int s) -{ -} - -/*! API: run tests. */ -static int dt_tests_run(int argc, char *argv[]) -{ - // Register service and signal handler - struct sigaction sa; - sa.sa_handler = interrupt_handle; - sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; - sigaction(SIGALRM, &sa, NULL); // Interrupt - - /* Initialize */ - srand(time(NULL)); - struct timeval tv; - pthread_mutex_init(&_runnable_mx, NULL); - - /* Test 1: Create unit */ - dt_unit_t *unit = dt_test_create(2); - ok(unit != 0, "dthreads: create unit (optimal size %d)", unit->size); - skip(unit == 0, DT_TEST_COUNT - 1); - - /* Test 2: Assign a single task. */ - ok(dt_test_single(unit), "dthreads: assign single task"); - - /* Test 3: Start tasks. */ - _runnable_i = 0; - ok(dt_test_start(unit), "dthreads: start single task"); - - /* Test 4: Wait for tasks. */ - ok(dt_test_join(unit), "dthreads: join threads"); - - /* Test 5: Compare counter. */ - int expected = _runnable_cycles * 1; - cmp_ok(_runnable_i, "==", expected, "dthreads: result ok"); - - /* Test 6: Repurpose threads. */ - _runnable_i = 0; - ok(dt_test_coherent(unit), "dthreads: repurpose to coherent"); - - /* Test 7: Restart threads. */ - ok(dt_test_start(unit), "dthreads: start coherent unit"); - - /* Test 8: Repurpose single thread. */ - tv.tv_sec = 0; - tv.tv_usec = 4000 + rand() % 1000; // 4-5ms - note("waiting for %dus to let thread do some work ...", - tv.tv_usec); - select(0, 0, 0, 0, &tv); - ok(dt_test_repurpose(unit, 0), "dthreads: repurpose on-the-fly"); - - /* Test 9: Cancel blocking thread. */ - tv.tv_sec = 0; - tv.tv_usec = (250 + rand() % 500) * 1000; // 250-750ms - note("waiting for %dms to let thread pretend blocking I/O ...", - tv.tv_usec / 1000); - select(0, 0, 0, 0, &tv); - ok(dt_test_cancel(unit, 0), "dthreads: cancel blocking thread"); - - /* Test 10: Wait for tasks. */ - ok(dt_test_join(unit), "dthreads: join threads"); - - /* Test 11: Compare counter. */ - int expected_lo = _runnable_cycles * (unit->size - 1); - cmp_ok(_runnable_i, ">=", expected_lo, - "dthreads: result %d is => %d", _runnable_i, expected_lo); - - /* Test 12: Compare counter #2. */ - /*! \note repurpose could trigger next run of the unit if both finished */ - int expected_hi = _runnable_cycles * (unit->size + unit->size - 1); - cmp_ok(_runnable_i, "<=", expected_hi, - "dthreads: result %d is <= %d", _runnable_i, expected_hi); - - /* Test 13: Reanimate dead threads. */ - ok(dt_test_reanimate(unit), "dthreads: reanimate dead threads"); - - /* Test 14: Deinitialize */ - dt_delete(&unit); - ok(unit == 0, "dthreads: delete unit"); - endskip; - - /* Test 15: Wrong values. */ - unit = dt_create(-1); - ok(unit == 0, "dthreads: create with negative count"); - unit = dt_create_coherent(dt_optimal_size(), 0, 0, 0); - - /* Test 16: NULL runnable. */ - cmp_ok(dt_start(unit), "==", 0, "dthreads: start with NULL runnable"); - - /* Test 17: NULL operations crashing. */ - int op_count = 14; - int expected_min = op_count * -1; - // All functions must return -1 at least - int ret = 0; - lives_ok( { - ret += dt_activate(0); // -1 - ret += dt_cancel(0); // -1 - ret += dt_compact(0); // -1 - dt_delete(0); // - ret += dt_is_cancelled(0); // 0 - ret += dt_join(0); // -1 - ret += dt_repurpose(0, 0, 0); // -1 - ret += dt_signalize(0, SIGALRM); // -1 - ret += dt_start(0); // -1 - ret += dt_start_id(0); // -1 - ret += dt_stop(0); // -1 - ret += dt_stop_id(0); // -1 - ret += dt_unit_lock(0); // -1 - ret += dt_unit_unlock(0); // -1 - }, "dthreads: not crashed while executing functions on NULL context"); - - /* Test 18: expected results. */ - cmp_ok(ret, "<=", expected_min, - "dthreads: correct values when passed NULL context " - "(%d, min: %d)", ret, expected_min); - - pthread_mutex_destroy(&_runnable_mx); - return 0; -} diff --git a/src/tests/knot/dthreads_tests.h b/src/tests/knot/dthreads_tests.h deleted file mode 100644 index e41bdc5156..0000000000 --- a/src/tests/knot/dthreads_tests.h +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef _KNOTD_DTHREADS_TESTS_H_ -#define _KNOTD_DTHREADS_TESTS_H_ - -#include "common/libtap/tap_unit.h" - -/* Unit API. */ -unit_api dthreads_tests_api; - -#endif /* _KNOTD_DTHREADS_TESTS_H_ */ diff --git a/src/tests/knot/journal_tests.c b/src/tests/knot/journal_tests.c deleted file mode 100644 index d61a1498d8..0000000000 --- a/src/tests/knot/journal_tests.c +++ /dev/null @@ -1,283 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <config.h> -#include <string.h> - -#include "tests/knot/journal_tests.h" -#include "knot/server/journal.h" -#include "knot/knot.h" - -static int journal_tests_count(int argc, char *argv[]); -static int journal_tests_run(int argc, char *argv[]); - -/* - * Unit API. - */ -unit_api journal_tests_api = { - "Journal", - &journal_tests_count, - &journal_tests_run -}; - -/* - * Unit implementation. - */ -static const int JOURNAL_TEST_COUNT = 21; - -/*! \brief Generate random string with given length. */ -static int randstr(char* dst, size_t len) -{ - for (int i = 0; i < len - 1; ++i) { - dst[i] = '0' + (int) (('Z'-'0') * (rand() / (RAND_MAX + 1.0))); - } - dst[len - 1] = '\0'; - - return 0; -} - -/*! \brief Walk journal of chars into buffer. */ -static int _wbi = 0; -static char _walkbuf[7]; -static int walkchars_cmp(uint64_t k1, uint64_t k2) { - return k1 - k2; -} - -static int walkchars(journal_t *j, journal_node_t *n) { - journal_read(j, n->id, walkchars_cmp, _walkbuf + _wbi); - ++_wbi; - return 0; -} - -/*! API: return number of tests. */ -static int journal_tests_count(int argc, char *argv[]) -{ - return JOURNAL_TEST_COUNT; -} - -/*! API: run tests. */ -static int journal_tests_run(int argc, char *argv[]) -{ - /* Test 1: Create tmpfile. */ - int fsize = 8092; - int jsize = 6; - char jfn_buf[] = "/tmp/journal.XXXXXX"; - int tmp_fd = mkstemp(jfn_buf); - ok(tmp_fd >= 0, "journal: create temporary file"); - skip(tmp_fd < 0, JOURNAL_TEST_COUNT - 1); - close(tmp_fd); - - /* Test 2: Create journal. */ - const char *jfilename = jfn_buf; - int ret = journal_create(jfilename, jsize); - ok(ret == KNOT_EOK, "journal: create journal '%s'", jfilename); - - /* Test 3: Open journal. */ - journal_t *journal = journal_open(jfilename, fsize, JOURNAL_LAZY, 0); - ok(journal != 0, "journal: open"); - - /* Retain journal. */ - journal_t *j = journal_retain(journal); - - /* Test 4: Write entry to log. */ - const char *sample = "deadbeef"; - ret = journal_write(j, 0x0a, sample, strlen(sample)); - ok(ret == KNOT_EOK, "journal: write"); - - /* Test 5: Read entry from log. */ - char tmpbuf[64] = {'\0'}; - ret = journal_read(j, 0x0a, 0, tmpbuf); - ok(ret == KNOT_EOK, "journal: read entry"); - - /* Test 6: Compare read data. */ - ret = strncmp(sample, tmpbuf, strlen(sample)); - ok(ret == 0, "journal: read data integrity check"); - - /* Append several characters. */ - journal_write(j, 0, "X", 1); /* Dummy */ - char word[7] = { 'w', 'o', 'r', 'd', '0', '\0', '\0' }; - for (int i = 0; i < strlen(word); ++i) { - journal_write(j, i, word+i, 1); - } - - /* Test 7: Compare journal_walk() result. */ - _wbi = 0; - journal_walk(j, walkchars); - _walkbuf[_wbi] = '\0'; - ret = strcmp(word, _walkbuf); - ok(ret == 0, "journal: read data integrity check 2 '%s'", _walkbuf); - _wbi = 0; - - /* Test 8: Change single letter and compare. */ - word[5] = 'X'; - journal_write(j, 5, word+5, 1); /* append 'X', shifts out 'w' */ - journal_walk(j, walkchars); - _walkbuf[_wbi] = '\0'; - ret = strcmp(word + 1, _walkbuf); - ok(ret == 0, "journal: read data integrity check 3 '%s'", _walkbuf); - _wbi = 0; - - /* Test 9: Attempt to retain and release. */ - journal_t *tmp = journal_retain(j); - ok(tmp == j, "journal: tested journal retaining"); - journal_release(tmp); - - /* Release journal. */ - journal_release(j); - - /* Close journal. */ - journal_close(journal); - - /* Recreate journal = NORMAL mode. */ - if (remove(jfilename) < 0) { - diag("journal: couldn't remove filename"); - } - fsize = 8092; - jsize = 512; - ret = journal_create(jfilename, jsize); - j = journal_open(jfilename, fsize, 0, 0); - - /* Test 10: Write random data. */ - int chk_key = 0; - char chk_buf[64] = {'\0'}; - ret = 0; - const int itcount = jsize * 5 + 5; - for (int i = 0; i < itcount; ++i) { - int key = rand() % 65535; - randstr(tmpbuf, sizeof(tmpbuf)); - if (journal_write(j, key, tmpbuf, sizeof(tmpbuf)) != KNOT_EOK) { - ret = -1; - break; - } - - /* Store some key on the end. */ - if (i == itcount - 2) { - chk_key = key; - memcpy(chk_buf, tmpbuf, sizeof(chk_buf)); - } - } - ok(j && ret == 0, "journal: sustained looped writes"); - - /* Test 11: Check data integrity. */ - memset(tmpbuf, 0, sizeof(tmpbuf)); - journal_read(j, chk_key, 0, tmpbuf); - ret = strncmp(chk_buf, tmpbuf, sizeof(chk_buf)); - ok(j && ret == 0, "journal: read data integrity check"); - - /* Test 12: Reopen log and re-read value. */ - memset(tmpbuf, 0, sizeof(tmpbuf)); - journal_close(j); - j = journal_open(jfilename, fsize, 0, 0); - journal_read(j, chk_key, 0, tmpbuf); - ret = strncmp(chk_buf, tmpbuf, sizeof(chk_buf)); - ok(j && ret == 0, "journal: read data integrity check after close/open"); - - /* Test 13: Map journal entry. */ - char *mptr = NULL; - memset(chk_buf, 0xde, sizeof(chk_buf)); - ret = journal_map(j, 0x12345, &mptr, sizeof(chk_buf)); - ok(j && mptr && ret == 0, "journal: mapped journal entry"); - skip(ret != 0, 2); - - /* Test 14: Write to mmaped entry and unmap. */ - memcpy(mptr, chk_buf, sizeof(chk_buf)); - ret = journal_unmap(j, 0x12345, mptr, 1); - ok(j && mptr && ret == 0, "journal: written to mapped entry and finished"); - - /* Test 15: Compare mmaped entry. */ - memset(tmpbuf, 0, sizeof(tmpbuf)); - journal_read(j, 0x12345, NULL, tmpbuf); - ret = strncmp(chk_buf, tmpbuf, sizeof(chk_buf)); - ok(j && ret == 0, "journal: mapped entry data integrity check"); - endskip; - - /* Test 16: Make a transaction. */ - uint64_t tskey = 0x75750000; - ret = journal_trans_begin(j); - ok(j && ret == 0, "journal: TRANS begin"); - for (int i = 0; i < 16; ++i) { - memset(tmpbuf, i, sizeof(tmpbuf)); - journal_write(j, tskey + i, tmpbuf, sizeof(tmpbuf)); - } - - /* Test 17: Check if uncommited node exists. */ - ret = journal_read(j, tskey + rand() % 16, NULL, chk_buf); - ok(j && ret != 0, "journal: check for uncommited node"); - - /* Test 18: Commit transaction. */ - ret = journal_trans_commit(j); - int read_ret = journal_read(j, tskey + rand() % 16, NULL, chk_buf); - ok(j && ret == 0 && read_ret == 0, "journal: transaction commit"); - - /* Test 19: Rollback transaction. */ - tskey = 0x6B6B0000; - journal_trans_begin(j); - for (int i = 0; i < 16; ++i) { - memset(tmpbuf, i, sizeof(tmpbuf)); - journal_write(j, tskey + i, tmpbuf, sizeof(tmpbuf)); - } - ret = journal_trans_rollback(j); - read_ret = journal_read(j, tskey + rand() % 16, NULL, chk_buf); - ok(j && ret == 0 && read_ret != 0, "journal: transaction rollback"); - - /* Test 20: Write random data. */ - ret = 0; - for (int i = 0; i < 512; ++i) { - int key = i; - randstr(tmpbuf, sizeof(tmpbuf)); - ret = journal_map(j, key, &mptr, sizeof(tmpbuf)); - if (ret != KNOT_EOK) { - diag("journal_map failed: %s", knot_strerror(ret)); - break; - } - memcpy(mptr, tmpbuf, sizeof(tmpbuf)); - if ((ret = journal_unmap(j, key, mptr, 1)) != KNOT_EOK) { - diag("journal_unmap failed: %s", knot_strerror(ret)); - break; - } - - /* Store some key on the end. */ - memset(chk_buf, 0, sizeof(chk_buf)); - ret = journal_read(j, key, 0, chk_buf); - if (ret != 0) { - diag("journal_map integrity check failed %s", - knot_strerror(ret)); - break; - } - ret = strncmp(chk_buf, tmpbuf, sizeof(chk_buf)); - if (ret != 0) { - diag("journal_map integrity check failed"); - break; - } - } - ok(j && ret == 0, "journal: sustained mmap r/w"); - - /* Test 21: Open + create journal. */ - journal_close(j); - remove(jfilename); - j = journal_open(jfilename, fsize, 0, 0); - ok(j != NULL, "journal: open+create from scratch"); - - /* Close journal. */ - journal_close(j); - - /* Delete journal. */ - remove(jfilename); - - endskip; - - return 0; -} diff --git a/src/tests/knot/journal_tests.h b/src/tests/knot/journal_tests.h deleted file mode 100644 index beec8caa54..0000000000 --- a/src/tests/knot/journal_tests.h +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef _KNOTD_JOURNAL_TESTS_H_ -#define _KNOTD_JOURNAL_TESTS_H_ - -#include "common/libtap/tap_unit.h" - -/* Unit API. */ -unit_api journal_tests_api; - -#endif /* _KNOTD_JOURNAL_TESTS_H_ */ diff --git a/src/tests/knot/rrl_tests.c b/src/tests/knot/rrl_tests.c deleted file mode 100644 index 8571f21d87..0000000000 --- a/src/tests/knot/rrl_tests.c +++ /dev/null @@ -1,227 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <config.h> -#include <sys/types.h> -#include <sys/socket.h> -#include "tests/knot/rrl_tests.h" -#include "knot/server/rrl.h" -#include "knot/server/dthreads.h" -#include "knot/knot.h" -#include "libknot/packet/response.h" -#include "libknot/packet/query.h" -#include "libknot/nameserver/name-server.h" -#include "common/descriptor.h" -#include "common/prng.h" - -/* Enable time-dependent tests. */ -//#define ENABLE_TIMED_TESTS -#define RRL_SIZE 196613 -#define RRL_THREADS 8 -#define RRL_INSERTS (RRL_SIZE/(5*RRL_THREADS)) /* lf = 1/5 */ -#define RRL_LOCKS 64 - -/* Disabled as default as it depends on random input. - * Table may be consistent even if some collision occur (and they may occur). - */ -#ifdef ENABLE_TIMED_TESTS -struct bucketmap_t { - unsigned i; - uint64_t x; -}; - -/*! \brief Unit runnable. */ -struct runnable_data { - int passed; - rrl_table_t *rrl; - sockaddr_t *addr; - rrl_req_t *rq; - knot_zone_t *zone; -}; - -static void* rrl_runnable(void *arg) -{ - struct runnable_data* d = (struct runnable_data*)arg; - sockaddr_t addr; - memcpy(&addr, d->addr, sizeof(sockaddr_t)); - int lock = -1; - uint32_t now = time(NULL); - struct bucketmap_t *m = malloc(RRL_INSERTS * sizeof(struct bucketmap_t)); - for (unsigned i = 0; i < RRL_INSERTS; ++i) { - m[i].i = tls_rand() * UINT32_MAX; - addr.addr4.sin_addr.s_addr = m[i].i; - rrl_item_t *b = rrl_hash(d->rrl, &addr, d->rq, d->zone, now, &lock); - rrl_unlock(d->rrl, lock); - m[i].x = b->netblk; - } - for (unsigned i = 0; i < RRL_INSERTS; ++i) { - addr.addr4.sin_addr.s_addr = m[i].i; - rrl_item_t *b = rrl_hash(d->rrl, &addr, d->rq, d->zone, now, &lock); - rrl_unlock(d->rrl, lock); - if (b->netblk != m[i].x) { - d->passed = 0; - } - } - free(m); - return NULL; -} - -static void rrl_hopscotch(struct runnable_data* rd) -{ - rd->passed = 1; - pthread_t thr[RRL_THREADS]; - for (unsigned i = 0; i < RRL_THREADS; ++i) { - pthread_create(thr + i, NULL, &rrl_runnable, rd); - } - for (unsigned i = 0; i < RRL_THREADS; ++i) { - pthread_join(thr[i], NULL); - } -} -#endif - -static int rrl_tests_count(int argc, char *argv[]); -static int rrl_tests_run(int argc, char *argv[]); - -/* - * Unit API. - */ -unit_api rrl_tests_api = { - "RRL", - &rrl_tests_count, - &rrl_tests_run -}; - -/* - * Unit implementation. - */ - -static int rrl_tests_count(int argc, char *argv[]) -{ - int c = 5; -#ifdef ENABLE_TIMED_TESTS - c += 5; -#endif - return c; -} - -static int rrl_tests_run(int argc, char *argv[]) -{ - /* Prepare query. */ - knot_packet_t *query = knot_packet_new(); - if (knot_packet_set_max_size(query, 512) < 0) { - knot_packet_free(&query); - return KNOT_ERROR; /* Fatal */ - } - knot_query_init(query); - - knot_dname_t *qname = knot_dname_from_str("beef.", 5); - int ret = knot_query_set_question(query, qname, KNOT_CLASS_IN, KNOT_RRTYPE_A); - knot_dname_free(&qname); - if (ret != KNOT_EOK) { - knot_packet_free(&query); - return KNOT_ERROR; /* Fatal */ - } - - - /* Prepare response */ - knot_nameserver_t *ns = knot_ns_create(); - uint8_t rbuf[65535]; - size_t rlen = sizeof(rbuf); - memset(rbuf, 0, sizeof(rbuf)); - knot_ns_error_response_from_query(ns, query, KNOT_RCODE_NOERROR, rbuf, &rlen); - - rrl_req_t rq; - rq.w = rbuf; - rq.len = rlen; - rq.query = query; - rq.flags = 0; - - /* 1. create rrl table */ - rrl_table_t *rrl = rrl_create(RRL_SIZE); - ok(rrl != NULL, "rrl: create"); - - /* 2. set rate limit */ - uint32_t rate = 10; - rrl_setrate(rrl, rate); - ok(rate == rrl_rate(rrl), "rrl: setrate"); - - /* 3. setlocks */ - ret = rrl_setlocks(rrl, RRL_LOCKS); - ok(ret == KNOT_EOK, "rrl: setlocks"); - - /* 4. N unlimited requests. */ - knot_dname_t *apex = knot_dname_from_str("rrl.", 4); - knot_zone_t *zone = knot_zone_new(knot_node_new(apex, NULL, 0)); - sockaddr_t addr; - sockaddr_t addr6; - sockaddr_set(&addr, AF_INET, "1.2.3.4", 0); - sockaddr_set(&addr6, AF_INET6, "1122:3344:5566:7788::aabb", 0); - ret = 0; - for (unsigned i = 0; i < rate; ++i) { - if (rrl_query(rrl, &addr, &rq, zone) != KNOT_EOK || - rrl_query(rrl, &addr6, &rq, zone) != KNOT_EOK) { - ret = KNOT_ELIMIT; - break; - } - } - ok(ret == 0, "rrl: unlimited IPv4/v6 requests"); - -#ifdef ENABLE_TIMED_TESTS - /* 5. limited request */ - ret = rrl_query(rrl, &addr, &rq, zone); - ok(ret != 0, "rrl: throttled IPv4 request"); - - /* 6. limited IPv6 request */ - ret = rrl_query(rrl, &addr6, &rq, zone); - ok(ret != 0, "rrl: throttled IPv6 request"); -#endif - - /* 7. invalid values. */ - ret = 0; - lives_ok( { - rrl_create(0); // NULL - ret += rrl_setrate(0, 0); // 0 - ret += rrl_rate(0); // 0 - ret += rrl_setlocks(0,0); // -1 - ret += rrl_query(0, 0, 0, 0); // -1 - ret += rrl_query(rrl, 0, 0, 0); // -1 - ret += rrl_query(rrl, (void*)0x1, 0, 0); // -1 - ret += rrl_destroy(0); // -1 - }, "rrl: not crashed while executing functions on NULL context"); - -#ifdef ENABLE_TIMED_TESTS - /* 8. hopscotch test */ - struct runnable_data rd = { - 1, rrl, &addr, &rq, zone - }; - rrl_hopscotch(&rd); - ok(rd.passed, "rrl: hashtable is ~ consistent"); - - /* 9. reseed */ - ok(rrl_reseed(rrl) == 0, "rrl: reseed"); - - /* 10. hopscotch after reseed. */ - rrl_hopscotch(&rd); - ok(rd.passed, "rrl: hashtable is ~ consistent"); -#endif - - knot_dname_free(&apex); - knot_zone_deep_free(&zone); - knot_ns_destroy(&ns); - knot_packet_free(&query); - rrl_destroy(rrl); - return 0; -} diff --git a/src/tests/knot/rrl_tests.h b/src/tests/knot/rrl_tests.h deleted file mode 100644 index 447b735d0b..0000000000 --- a/src/tests/knot/rrl_tests.h +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef _KNOTD_RRL_TESTS_H_ -#define _KNOTD_RRL_TESTS_H_ - -#include "common/libtap/tap_unit.h" - -/* Unit API. */ -unit_api rrl_tests_api; - -#endif /* _KNOTD_RRL_TESTS_H_ */ diff --git a/src/tests/knot/server_tests.c b/src/tests/knot/server_tests.c deleted file mode 100644 index d84d2c9dc3..0000000000 --- a/src/tests/knot/server_tests.c +++ /dev/null @@ -1,115 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <config.h> -#include "tests/knot/server_tests.h" -#include "knot/server/server.h" - -static int server_tests_count(int argc, char *argv[]); -static int server_tests_run(int argc, char *argv[]); - -/* - * Unit API. - */ -unit_api server_tests_api = { - "Server", - &server_tests_count, - &server_tests_run -}; - -/* - * Unit implementation. - */ - -static const int SERVER_TEST_COUNT = 4; - -/*! Test: create server. */ -server_t *test_server_create() -{ - return server_create(); -} - -/*! Test: start server. */ -int test_server_start(server_t *s) -{ - return server_start(s) == 0; -} - -/*! Test: finish server. */ -int test_server_finish(server_t *s) -{ - return server_wait(s) == 0; -} - -/*! Test: stop server. */ -int test_server_destroy(server_t *s) -{ - server_destroy(&s); - return s == 0; -} - -/*! API: return number of tests. */ -static int server_tests_count(int argc, char *argv[]) -{ - return SERVER_TEST_COUNT + 1; -} - -// Signal handler -static void interrupt_handle(int s) -{ -} - -/*! API: run tests. */ -static int server_tests_run(int argc, char *argv[]) -{ - server_t *server = 0; - int ret = 0; - - // Register service and signal handler - struct sigaction sa; - sa.sa_handler = interrupt_handle; - sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; - sigaction(SIGALRM, &sa, NULL); // Interrupt - - //! Test server for correct initialization - server = test_server_create(); - ok(server != 0, "server: initialized"); - - //! Test server startup - ret = 0; - lives_ok( { - ret = test_server_start(server); - }, "server: not crashing on runtime"); - - //! Test server exit code - ok(ret, "server: started ok"); - if (ret) { - server_stop(server); - } else { - diag("server crashed, skipping deinit and destroy tests"); - } - - //! Test server waiting for finish - skip(!ret, 2); - ok(test_server_finish(server), "server: waiting for finish"); - - //! Test server for correct deinitialization - ok(test_server_destroy(server), "server: deinit"); - endskip; - - return 0; -} diff --git a/src/tests/knot/server_tests.h b/src/tests/knot/server_tests.h deleted file mode 100644 index 43ad0c1f92..0000000000 --- a/src/tests/knot/server_tests.h +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef _KNOTD_SERVER_TESTS_H_ -#define _KNOTD_SERVER_TESTS_H_ - -#include "common/libtap/tap_unit.h" - -/* Unit API. */ -unit_api server_tests_api; - -#endif /* _KNOTD_SERVER_TESTS_H_ */ diff --git a/src/tests/libknot/dname_tests.c b/src/tests/libknot/dname_tests.c deleted file mode 100644 index 515b4c2ac6..0000000000 --- a/src/tests/libknot/dname_tests.c +++ /dev/null @@ -1,164 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <config.h> -#include "tests/libknot/dname_tests.h" -#include "libknot/dname.h" - -/* Test dname_parse_from_wire */ -static int test_fw(size_t l, const char *w) { - const uint8_t *np = (const uint8_t *)w + l; - return knot_dname_wire_check((const uint8_t *)w, np, NULL) > 0; -} - -static int dname_tests_count(int argc, char *argv[]); -static int dname_tests_run(int argc, char *argv[]); - -unit_api dname_tests_api = { - "dname", - &dname_tests_count, - &dname_tests_run -}; - -static int dname_tests_count(int argc, char *argv[]) -{ - return 23; -} - -static int dname_tests_run(int argc, char *argv[]) -{ - knot_dname_t *d = NULL, *d2 = NULL; - const char *w = NULL, *t = NULL; - unsigned len = 0; - size_t pos = 0; - - /* 1. NULL wire */ - ok(!test_fw(0, NULL), "parsing NULL dname"); - - /* 2. empty label */ - ok(test_fw(1, ""), "parsing empty dname"); - - /* 3. incomplete dname */ - ok(!test_fw(5, "\x08""dddd"), "parsing incomplete wire"); - - /* 4. non-fqdn */ - ok(!test_fw(3, "\x02""ab"), "parsing non-fqdn name"); - - /* 5. label > 63b */ - w = "\x40""dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"; - ok(!test_fw(65, w), "parsing label > 63b"); - - /* 6. label count == 126 */ - w = "\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64"; - ok(test_fw(253, w), "parsing label count == 127"); - - /* 7. label count == 127 */ - w = "\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64"; - ok(test_fw(255, w), "parsing label count == 127"); - - /* 8. label count > 127 */ - w = "\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64\x01\x64"; - ok(!test_fw(257, w), "parsing label count > 127"); - - /* 9. dname length > 255 */ - w = "\xff""ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"; - ok(!test_fw(257, w), "parsing dname len > 255"); - - /* 10. special case - invalid label */ - w = "\x20\x68\x6d\x6e\x63\x62\x67\x61\x61\x61\x61\x65\x72\x6b\x30\x30\x30\x30\x64\x6c\x61\x61\x61\x61\x61\x61\x61\x61\x62\x65\x6a\x61\x6d\x20\x67\x6e\x69\x64\x68\x62\x61\x61\x61\x61\x65\x6c\x64\x30\x30\x30\x30\x64\x6c\x61\x61\x61\x61\x61\x61\x61\x61\x62\x65\x6a\x61\x6d\x20\x61\x63\x6f\x63\x64\x62\x61\x61\x61\x61\x65\x6b\x72\x30\x30\x30\x30\x64\x6c\x61\x61\x61\x61\x61\x61\x61\x61\x62\x65\x6a\x61\x6d\x20\x69\x62\x63\x6d\x6a\x6f\x61\x61\x61\x61\x65\x72\x6a\x30\x30\x30\x30\x64\x6c\x61\x61\x61\x61\x61\x61\x61\x61\x62\x65\x6a\x61\x6d\x20\x6f\x6c\x6e\x6c\x67\x68\x61\x61\x61\x61\x65\x73\x72\x30\x30\x30\x30\x64\x6c\x61\x61\x61\x61\x61\x61\x61\x61\x62\x65\x6a\x61\x6d\x20\x6a\x6b\x64\x66\x66\x67\x61\x61\x61\x61\x65\x6c\x68\x30\x30\x30\x30\x64\x6c\x61\x61\x61\x61\x61\x61\x61\x61\x62\x65\x6a\x61\x6d\x20\x67\x67\x6c\x70\x70\x61\x61\x61\x61\x61\x65\x73\x72\x30\x30\x30\x30\x64\x6c\x61\x61\x61\x61\x61\x61\x61\x61\x62\x65\x6a\x61\x6d\x20\x65\x6b\x6c\x67\x70\x66\x61\x61\x61\x61\x65\x6c\x68\x30\x30\x30\x30\x64\x6c\x61\x61\x61\x61\x61\x0\x21\x42\x63\x84\xa5\xc6\xe7\x8\xa\xd\x11\x73\x3\x6e\x69\x63\x2\x43\x5a"; - ok(!test_fw(277, w), "parsing invalid label (spec. case 1)"); - - /* 11. parse from string (correct) .*/ - len = 10; - w = "\x04""abcd""\x03""efg"; - t = "abcd.efg"; - d = knot_dname_from_str(t, strlen(t)); - ok(d && knot_dname_size(d) == len && memcmp(d, w, len) == 0, - "dname_fromstr: parsed correct non-FQDN name"); - knot_dname_free(&d); - - /* 12. parse FQDN from string (correct) .*/ - t = "abcd.efg."; - d = knot_dname_from_str(t, strlen(t)); - ok(d && knot_dname_size(d) == len && memcmp(d, w, len) == 0, - "dname_fromstr: parsed correct FQDN name"); - knot_dname_free(&d); - - /* 13. parse name from string (incorrect) .*/ - t = ".."; - d = knot_dname_from_str(t, strlen(t)); - ok(d == NULL, "dname_fromstr: parsed incorrect name"); - - /* 14. equal name is subdomain */ - t = "ab.cd.ef"; - d2 = knot_dname_from_str(t, strlen(t)); - t = "ab.cd.ef"; - d = knot_dname_from_str(t, strlen(t)); - ok(!knot_dname_is_sub(d, d2), "dname_subdomain: equal name"); - knot_dname_free(&d); - - /* 15. true subdomain */ - t = "0.ab.cd.ef"; - d = knot_dname_from_str(t, strlen(t)); - ok(knot_dname_is_sub(d, d2), "dname_subdomain: true subdomain"); - knot_dname_free(&d); - - /* 16. not subdomain */ - t = "cd.ef"; - d = knot_dname_from_str(t, strlen(t)); - ok(!knot_dname_is_sub(d, d2), "dname_subdomain: not subdomain"); - knot_dname_free(&d); - - /* 17. root subdomain */ - t = "."; - d = knot_dname_from_str(t, strlen(t)); - ok(knot_dname_is_sub(d2, d), "dname_subdomain: root subdomain"); - knot_dname_free(&d); - knot_dname_free(&d2); - - /* 18-19. dname cat (valid) */ - w = "\x03""cat"; - len = 5; - d = knot_dname_copy((const uint8_t *)w); - t = "*"; - d2 = knot_dname_from_str(t, strlen(t)); - d2 = knot_dname_cat(d2, d); - t = "\x01""*""\x03""cat"; - len = 2 + 4 + 1; - ok (d2 && len == knot_dname_size(d2), "dname_cat: valid concatenation size"); - ok(memcmp(d2, t, len) == 0, "dname_cat: valid concatenation"); - knot_dname_free(&d); - knot_dname_free(&d2); - - /* 20-21. parse from wire (valid) */ - t = "\x04""abcd""\x03""efg"; - len = 10; - pos = 0; - d = knot_dname_parse((const uint8_t *)t, &pos, len); - ok(d != NULL, "dname_parse: valid name"); - cmp_ok(pos, "==", len, "dname_parse: valid name (parsed length)"); - knot_dname_free(&d); - - /* 22-23. parse from wire (invalid) */ - t = "\x08""dddd"; - len = 5; - pos = 0; - d = knot_dname_parse((const uint8_t *)t, &pos, len); - ok(d == NULL, "dname_parse: bad name"); - cmp_ok(pos, "==", 0, "dname_parse: bad name (parsed length)"); - - return 0; -} diff --git a/src/tests/libknot/dname_tests.h b/src/tests/libknot/dname_tests.h deleted file mode 100644 index f3edff3675..0000000000 --- a/src/tests/libknot/dname_tests.h +++ /dev/null @@ -1,24 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef _KNOT_DNAME_TESTS_ -#define _KNOT_DNAME_TESTS_ - -#include "common/libtap/tap_unit.h" - -unit_api dname_tests_api; - -#endif diff --git a/src/tests/libknot/dnssec_keys_tests.c b/src/tests/libknot/dnssec_keys_tests.c deleted file mode 100644 index 300b577d46..0000000000 --- a/src/tests/libknot/dnssec_keys_tests.c +++ /dev/null @@ -1,259 +0,0 @@ -/* Copyright (C) 2013 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <config.h> -#include "tests/libknot/dnssec_keys_tests.h" -#include "libknot/dnssec/key.h" -#include "libknot/dnssec/key.c" // testing static functions - -static int sign_tests_count(int argc, char *argv[]); -static int sign_tests_run(int argc, char *argv[]); - -unit_api dnssec_keys_tests_api = { - "libknot/dnssec/sign", - &sign_tests_count, - &sign_tests_run -}; - -static int sign_tests_count(int argc, char *argv[]) -{ - return 26; -} - -static int sign_tests_run(int argc, char *argv[]) -{ - // 1-3. - strndup_with_suffix() - { - char *result; - - result = strndup_with_suffix("begin", 5, "end"); - ok(result && strcmp(result, "beginend") == 0, - "strndup_with_suffix(), matching length"); - free(result); - - result = strndup_with_suffix("begin", 3, "end"); - ok(result && strcmp(result, "begend") == 0, - "strndup_with_suffix(), shorter length"); - free(result); - - result = strndup_with_suffix("", 0, "end"); - ok(result && strcmp(result, "end") == 0, - "strndup_with_suffix(), empty base string"); - free(result); - } - - // 4.-9. - get_key_filenames() - { - char *public, *private; - int result; - - result = get_key_filenames("Kexample.com.+1.+2.private", - &public, &private); - ok(result == KNOT_EOK && - strcmp(public, "Kexample.com.+1.+2.key") == 0 && - strcmp(private, "Kexample.com.+1.+2.private") == 0, - "get_key_filenames(), from private key"); - free(public); - free(private); - - result = get_key_filenames("Kexample.com.+4.+8.key", - &public, &private); - ok(result == KNOT_EOK && - strcmp(public, "Kexample.com.+4.+8.key") == 0 && - strcmp(private, "Kexample.com.+4.+8.private") == 0, - "get_key_filenames(), from public key"); - free(public); - free(private); - - result = get_key_filenames("nic.cz.+4.+8", - &public, &private); - ok(result == KNOT_EOK && - strcmp(public, "nic.cz.+4.+8.key") == 0 && - strcmp(private, "nic.cz.+4.+8.private") == 0, - "get_key_filenames(), without extension"); - free(public); - free(private); - - result = get_key_filenames("nic.cz.+0.+1.", - &public, &private); - ok(result == KNOT_EOK && - strcmp(public, "nic.cz.+0.+1.key") == 0 && - strcmp(private, "nic.cz.+0.+1.private") == 0, - "get_key_filenames(), empty extension"); - free(public); - free(private); - - result = get_key_filenames("../keys/Kfoo.bar.+5.+10.private", - &public, &private); - ok(result == KNOT_EOK && - strcmp(public, "../keys/Kfoo.bar.+5.+10.key") == 0 && - strcmp(private, "../keys/Kfoo.bar.+5.+10.private") == 0, - "get_key_filenames(), with path"); - free(public); - free(private); - - result = get_key_filenames("keys/something.txt", - &public, &private); - ok(result == KNOT_EOK && - strcmp(public, "keys/something.txt.key") == 0 && - strcmp(private, "keys/something.txt.private") == 0, - "get_key_filenames(), nonstandard name"); - free(public); - free(private); - } - - // 10. - key_param_base64() - { - knot_binary_t output = { 0 }; - int result; - - result = key_param_base64(&output, "aGVsbG8gRE5TIHdvcmxk"); - - ok(result == KNOT_EOK && output.size == 15 - && memcmp((char *)output.data, "hello DNS world", 15) == 0, - "key_param_base64(), correct usage"); - - knot_binary_free(&output); - } - - // 11-16. - key_param_int() - { - int output = 0; - int result; - - result = key_param_int(&output, "12345"); - ok(result == KNOT_EOK && output == 12345, - "key_param_int(), correct number"); - - result = key_param_int(&output, "6789 whatever"); - ok(result == KNOT_EOK && output == 6789, - "key_param_int(), number, space, and text"); - - result = key_param_int(&output, "24680\n"); - ok(result == KNOT_EOK && output == 24680, - "key_param_int(), number and new line"); - - result = key_param_int(&output, "0"); - ok(result == KNOT_EOK && output == 0, - "key_param_int(), zero"); - - result = key_param_int(&output, ""); - ok(result == KNOT_EINVAL, - "key_param_int(), empty string"); - - result = key_param_int(&output, "\t \n"); - ok(result == KNOT_EINVAL, - "key_param_int(), only white spaces"); - - result = key_param_int(&output, "4444abc"); - ok(result == KNOT_EINVAL, - "key_param_int(), number and text"); - } - - // 17-21. - parse_keyfile_line() - { - knot_key_params_t key = { 0 }; - int result; - char *line; - - line = strdup("Algorithm: 123 ABC"); - result = parse_keyfile_line(&key, line, strlen(line)); - ok(result == KNOT_EOK && key.algorithm == 123, - "parse_keyfile_line(), simple line with algorithm"); - free(line); - - line = strdup("Key: c2VjcmV0\n"); - result = parse_keyfile_line(&key, line, strlen(line)); - ok(result == KNOT_EOK && key.secret.size == 6 - && memcmp((char *)key.secret.data, "secret", 6) == 0, - "parse_keyfile_line(), new line terminated line with key"); - knot_binary_free(&key.secret); - free(line); - - line = strdup("Cool: S25vdCBETlM="); - result = parse_keyfile_line(&key, line, strlen(line)); - ok(result == KNOT_EOK, - "parse_keyfile_line(), unknown parameter"); - free(line); - - line = strdup("Activate: 20130521144259\n"); - result = parse_keyfile_line(&key, line, strlen(line)); - ok(result == KNOT_EOK && key.time_activate == 1369147379, - "parse_keyfile_line(), timestamp parsing"); - free(line); - } - - // 22. - knot_free_key_params() - { - int result; - knot_key_params_t params = { 0 }; - knot_key_params_t empty_params = { 0 }; - - params.algorithm = 42; - knot_binary_from_base64("AQAB", ¶ms.public_exponent); - - result = knot_free_key_params(¶ms); - ok(result == KNOT_EOK - && memcmp(¶ms, &empty_params, sizeof(params)) == 0, - "knot_free_key_params(), regular free"); - } - - // 23-25. - knot_tsig_key_from_params() - { - int result; - knot_key_params_t params = { 0 }; - knot_tsig_key_t tsig_key = { 0 }; - const char *owner = "shared.example.com."; - knot_dname_t *name = knot_dname_from_str(owner, - strlen(owner)); - - result = knot_tsig_key_from_params(¶ms, &tsig_key); - ok(result == KNOT_EINVAL, - "knot_tsig_key_from_params(), empty parameters"); - - params.secret.data = (uint8_t *)"test"; - params.secret.size = 4; - result = knot_tsig_key_from_params(¶ms, &tsig_key); - ok(result == KNOT_EINVAL, - "knot_tsig_key_from_params(), no key name"); - - params.name = name; - params.secret.data = NULL; - params.secret.size = 0; - result = knot_tsig_key_from_params(¶ms, &tsig_key); - ok(result == KNOT_EINVAL, - "knot_tsig_key_from_params(), no shared secret"); - - params.name = name; - knot_binary_from_base64("Ok6NmA==", ¶ms.secret); - uint8_t decoded_secret[] = { 0x3a, 0x4e, 0x8d, 0x98 }; - result = knot_tsig_key_from_params(¶ms, &tsig_key); - ok(result == KNOT_EOK - && tsig_key.secret.size == sizeof(decoded_secret) - && memcmp(tsig_key.secret.data, decoded_secret, - sizeof(decoded_secret)) == 0, - "knot_tsig_key_from_params(), secret set properly"); - - knot_tsig_key_free(&tsig_key); - } - - //! \todo knot_keytag() - //! \todo get_key_info_from_public_key() -- working with files required - //! \todo knot_load_key_params() -- working with files required - //! \todo knot_get_key_type() - - return 0; -} diff --git a/src/tests/libknot/dnssec_keys_tests.h b/src/tests/libknot/dnssec_keys_tests.h deleted file mode 100644 index e764a5c5bf..0000000000 --- a/src/tests/libknot/dnssec_keys_tests.h +++ /dev/null @@ -1,24 +0,0 @@ -/* Copyright (C) 2013 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef _KNOTD_SIGN_TESTS_ -#define _KNOTD_SIGN_TESTS_ - -#include "common/libtap/tap_unit.h" - -unit_api dnssec_keys_tests_api; - -#endif diff --git a/src/tests/libknot/dnssec_nsec3_tests.c b/src/tests/libknot/dnssec_nsec3_tests.c deleted file mode 100644 index 84f579fa6b..0000000000 --- a/src/tests/libknot/dnssec_nsec3_tests.c +++ /dev/null @@ -1,114 +0,0 @@ -/* Copyright (C) 2013 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <config.h> -#include <string.h> - -#include "tests/libknot/dnssec_nsec3_tests.h" - -#include "common/descriptor.h" -#include "common/errcode.h" -#include "libknot/dname.h" -#include "libknot/dnssec/algorithm.h" -#include "libknot/dnssec/nsec3.h" -#include "libknot/rrset.h" - -static int dnssec_nsec3_tests_count(int argc, char *argv[]); -static int dnssec_nsec3_tests_run(int argc, char *argv[]); - -unit_api dnssec_nsec3_tests_api = { - "libknot/dnssec/nsec3", - &dnssec_nsec3_tests_count, - &dnssec_nsec3_tests_run -}; - -static int dnssec_nsec3_tests_count(int argc, char *argv[]) -{ - return 10; -} - -static int dnssec_nsec3_tests_run(int argc, char *argv[]) -{ - int result = KNOT_EOK; - - // lengths of different hashes - - ok(knot_nsec3_hash_length(1) == 20, - "raw hash length for SHA1"); - ok(knot_nsec3_hash_length(42) == 0, - "raw hash length for unknown algorithm"); - ok(knot_nsec3_hash_b32_length(1) == 32, - "B32 hash length for SHA1"); - ok(knot_nsec3_hash_b32_length(42) == 0, - "B32 hash length for unknown algorithm"); - - // parsing NSEC3PARAMs from wire - - knot_nsec3_params_t params = { 0 }; - knot_rrset_t *rrset = NULL; - uint8_t rdata[] = { - 0x01, // hash algorithm - 0x00, // flags - 0x00, 0x0a, // iterations - 0x04, // salt length - 'a', 'b', 'c', 'd' // salt - }; - - rrset = knot_rrset_new(NULL, KNOT_RRTYPE_NSEC3PARAM, KNOT_CLASS_IN, 0); - result = knot_rrset_add_rdata(rrset, rdata, sizeof(rdata)); - if (result == KNOT_EOK) { - result = knot_nsec3_params_from_wire(¶ms, rrset); - } - - ok(params.algorithm == 1, "parse algorithm from wire"); - ok(params.flags == 0, "parse flags from wire"); - ok(params.iterations == 10, "parse iterations from wire"); - ok(params.salt_length == 4, "parse salt length from wire"); - ok(memcmp(params.salt, "abcd", 4) == 0, "parse salt from wire"); - - knot_rrset_deep_free(&rrset, 1); - knot_nsec3_params_free(¶ms); - - // hash computation - - params.algorithm = 1; - params.flags = 0; - params.iterations = 7; - params.salt_length = 14; - params.salt = (uint8_t *)strdup("happywithnsec3"); - - const char *dname_str = "knot-dns.cz."; - knot_dname_t *dname = knot_dname_from_str(dname_str, strlen(dname_str)); - - size_t digest_size = 0; - uint8_t *digest = NULL; - result = knot_nsec3_hash(¶ms, dname, knot_dname_size(dname), - &digest, &digest_size); - - uint8_t expected[] = { - 0x72, 0x40, 0x55, 0x83, 0x92, 0x93, 0x95, 0x28, 0xee, 0xa2, - 0xcc, 0xe1, 0x13, 0xbe, 0xcd, 0x41, 0xee, 0x8a, 0x71, 0xfd - }; - - ok(result == KNOT_EOK && digest_size == sizeof(expected) && - memcmp(digest, expected, sizeof(expected)) == 0, "compute hash"); - - free(digest); - free(params.salt); - knot_dname_free(&dname); - - return 0; -} diff --git a/src/tests/libknot/dnssec_nsec3_tests.h b/src/tests/libknot/dnssec_nsec3_tests.h deleted file mode 100644 index 5ef80bab4d..0000000000 --- a/src/tests/libknot/dnssec_nsec3_tests.h +++ /dev/null @@ -1,24 +0,0 @@ -/* Copyright (C) 2013 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef _KNOTD_DNSSEC_NSEC3_TESTS_ -#define _KNOTD_DNSSEC_NSEC3_TESTS_ - -#include "common/libtap/tap_unit.h" - -unit_api dnssec_nsec3_tests_api; - -#endif diff --git a/src/tests/libknot/dnssec_sign_tests.c b/src/tests/libknot/dnssec_sign_tests.c deleted file mode 100644 index 3de93ad991..0000000000 --- a/src/tests/libknot/dnssec_sign_tests.c +++ /dev/null @@ -1,152 +0,0 @@ -/* Copyright (C) 2013 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <config.h> -#include <assert.h> -#include <openssl/opensslconf.h> - -#include "tests/libknot/dnssec_sign_tests.h" -#include "common/errcode.h" -#include "libknot/dnssec/sign.h" - -static int dnssec_sign_tests_count(int argc, char *argv[]); -static int dnssec_sign_tests_run(int argc, char *argv[]); - -#ifdef OPENSSL_NO_ECDSA -static const int ecdsa_supported = 0; -#else -static const int ecdsa_supported = 1; -#endif - -unit_api dnssec_sign_tests_api = { - "libknot/dnssec/sign", - &dnssec_sign_tests_count, - &dnssec_sign_tests_run -}; - -static void test_algorithm(const char *alg, const knot_key_params_t *kp) -{ - int result; - - knot_dnssec_key_t key = { 0 }; - result = knot_dnssec_key_from_params(kp, &key); - ok(result == KNOT_EOK, "%s: create key from params", alg); - - knot_dnssec_sign_context_t *ctx; - ctx = knot_dnssec_sign_init(&key); - ok(ctx != NULL, "%s: create signing context", alg); - - skip(ctx == NULL, 12, "%s: required test failed", alg); - - size_t sig_size = knot_dnssec_sign_size(&key); - ok(sig_size > 0, "%s: get signature size", alg); - - uint8_t *sig = malloc(sig_size); - assert(sig != NULL); - - result = knot_dnssec_sign_add(ctx, (uint8_t *)"test", 4); - ok(result == KNOT_EOK, "%s: add data A", alg); - - result = knot_dnssec_sign_new(ctx); - ok(result == KNOT_EOK, "%s: restart context", alg); - - result = knot_dnssec_sign_add(ctx, (uint8_t *)"hello", 5); - ok(result == KNOT_EOK, "%s: add data B", alg); - - result = knot_dnssec_sign_add(ctx, (uint8_t *)"dns", 3); - ok(result == KNOT_EOK, "%s: add data C", alg); - - result = knot_dnssec_sign_write(ctx, sig); - ok(result == KNOT_EOK, "%s: write signature", alg); - - result = knot_dnssec_sign_new(ctx); - ok(result == KNOT_EOK, "%s: restart context", alg); - - result = knot_dnssec_sign_add(ctx, (uint8_t *)"wrong", 5); - ok(result == KNOT_EOK, "%s: add data D", alg); - - result = knot_dnssec_sign_verify(ctx, sig, sig_size); - ok(result == KNOT_DNSSEC_EINVALID_SIGNATURE, "%s: verify invalid signature", alg); - - result = knot_dnssec_sign_new(ctx); - ok(result == KNOT_EOK, "%s: restart context", alg); - - result = knot_dnssec_sign_add(ctx, (uint8_t *)"hellodns", 8); - ok(result == KNOT_EOK, "%s: add data B + C", alg); - - result = knot_dnssec_sign_verify(ctx, sig, sig_size); - ok(result == KNOT_EOK, "%s: verify valid signature", alg); - - endskip; - - knot_dnssec_sign_free(ctx); - knot_dnssec_key_free(&key); -} - -static int dnssec_sign_tests_count(int argc, char *argv[]) -{ - return 42; -} - -static int dnssec_sign_tests_run(int argc, char *argv[]) -{ - knot_key_params_t kp = { 0 }; - - // RSA - - kp.name = knot_dname_from_str("example.com.", 12); - kp.algorithm = 5; - knot_binary_from_base64("pSxiFXG8wB1SSHdok+OdaAp6QdvqjpZ17ucNge21iYVfv+DZq52l21KdmmyEqoG9wG/87O7XG8XVLNyYPue8Mw==", &kp.modulus); - knot_binary_from_base64("AQAB", &kp.public_exponent); - knot_binary_from_base64("UuNK9Wf2SJJuUF9b45s9ypA3egVaV+O5mwHoDWO0ziWJxFXNMMsobDdusEDjCw64xnlLmrbzNJ3+ClrOnV04gQ==", &kp.private_exponent); - knot_binary_from_base64("0/wjqkgVZxqrFi5OMzq2qQYpxKn3HgS87Io9UG6iqis=", &kp.prime_one); - knot_binary_from_base64("x3gFCPpaJ4etPEM1hRd6WMAcmx5FBMjvuuzID6SWWhk=", &kp.prime_two); - knot_binary_from_base64("Z8qUS9NvZ0QPcJTLhRnCRY/W84ukivYW6lnlG3SQAHE=", &kp.exponent_one); - knot_binary_from_base64("C0kjH8rqZuoqRwqWcJ1Pcs4L0Er6JLcpuS3Ec/4f86E=", &kp.exponent_two); - knot_binary_from_base64("VYc62FQX0Vnd27VxkX6hsBcl7Oh00wVCeh3WTDutndg=", &kp.coefficient); - - test_algorithm("RSA", &kp); - knot_free_key_params(&kp); - - // DSA - - kp.name = knot_dname_from_str("example.com.", 12); - kp.algorithm = 6; - knot_binary_from_base64("u7tr4jc7CH0+r2muVEZyjYu7hpMrQ1dHGAMv7hr5dBFYzkutfdBmDSW4C+qxaXWo14gi+jJ8XqFqQ7rQn23DdQ==", &kp.prime); - knot_binary_from_base64("tgZ5X6pFoCOM2NzfiAYVG1434Mk=", &kp.subprime); - knot_binary_from_base64("bHidtFIFYAHXp7ZxTFd6poJJG8brqO9eyJygvYSFCej/FGDqhF2TsboVvS/evW/qTaSvhkd/aiDg5eAfu1HvrQ==", &kp.base); - knot_binary_from_base64("FiTBDsbFDNTw7IrhPeVbzM0DMmI=", &kp.private_value); - knot_binary_from_base64("G1pX04Bcew8wyHsmno4Q0tNdmBLlaEdbqvQ03W5XVXUM6MPrtzxgc6jdOogqZsvGK4c+FbThBu42Z1t/ioQr8A==", &kp.public_value); - - test_algorithm("DSA", &kp); - knot_free_key_params(&kp); - - // ECDSA - - skip(!ecdsa_supported, 14, "ECDSA: not supported on this system"); - - kp.name = knot_dname_from_str("example.com", 12); - kp.algorithm = 13; - knot_binary_from_base64("1N/PvpB8jZcvv+zr3Q987RKK1cBxDKULzEc5F/nnpSg=", &kp.private_key); - knot_binary_from_base64("fe3oR+S8crl9AwayWFZwJ8wXpDeg1uiXZ/X0MYBvyvj1lfuJDXawUjKuzYKLAPEVH1jt8XbM5nTTlVXUsDebVA==", &kp.rdata); - - test_algorithm("ECDSA", &kp); - knot_free_key_params(&kp); - - endskip; - - return 0; -} diff --git a/src/tests/libknot/dnssec_sign_tests.h b/src/tests/libknot/dnssec_sign_tests.h deleted file mode 100644 index a5f55342b5..0000000000 --- a/src/tests/libknot/dnssec_sign_tests.h +++ /dev/null @@ -1,24 +0,0 @@ -/* Copyright (C) 2013 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef _KNOTD_DNSSEC_SIGN_TESTS_ -#define _KNOTD_DNSSEC_SIGN_TESTS_ - -#include "common/libtap/tap_unit.h" - -unit_api dnssec_sign_tests_api; - -#endif diff --git a/src/tests/libknot/dnssec_zone_nsec_tests.c b/src/tests/libknot/dnssec_zone_nsec_tests.c deleted file mode 100644 index aef3a11124..0000000000 --- a/src/tests/libknot/dnssec_zone_nsec_tests.c +++ /dev/null @@ -1,63 +0,0 @@ -/* Copyright (C) 2013 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include <config.h> - -#include "tests/libknot/dnssec_zone_nsec_tests.h" -#include "libknot/dname.h" -#include "libknot/dnssec/zone-nsec.h" - -static int dnssec_zone_nsec_tests_count(int argc, char *argv[]); -static int dnssec_zone_nsec_tests_run(int argc, char *argv[]); - -unit_api dnssec_zone_nsec_tests_api = { - "libknot/dnssec/zone-nsec", - &dnssec_zone_nsec_tests_count, - &dnssec_zone_nsec_tests_run -}; - -static int dnssec_zone_nsec_tests_count(int argc, char *argv[]) -{ - return 1; -} - -static knot_dname_t *get_dname(const char *str) -{ - size_t length = strlen(str); - return knot_dname_from_str(str, length); -} - -static int dnssec_zone_nsec_tests_run(int argc, char *argv[]) -{ - knot_dname_t *owner = get_dname("name.example.com"); - knot_dname_t *apex = get_dname("example.com"); - knot_dname_t *expect = get_dname("sv9o5lv8kgv6lm1t9dkst43b3c0aagbj.example.com"); - - knot_nsec3_params_t params = { - .algorithm = 1, .flags = 0, .iterations = 10, - .salt = (uint8_t *)"\xc0\x01", .salt_length = 2 - }; - - knot_dname_t *result = create_nsec3_owner(owner, apex, ¶ms); - ok(knot_dname_cmp(result, expect) == 0, "create_nsec3_owner()"); - - knot_dname_free(&result); - knot_dname_free(&owner); - knot_dname_free(&apex); - knot_dname_free(&expect); - - return 0; -} diff --git a/src/tests/libknot/dnssec_zone_nsec_tests.h b/src/tests/libknot/dnssec_zone_nsec_tests.h deleted file mode 100644 index 7badb4f7a9..0000000000 --- a/src/tests/libknot/dnssec_zone_nsec_tests.h +++ /dev/null @@ -1,24 +0,0 @@ -/* Copyright (C) 2013 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef _KNOTD_DNSSEC_ZONE_NSEC_TESTS_ -#define _KNOTD_DNSSEC_ZONE_NSEC_TESTS_ - -#include "common/libtap/tap_unit.h" - -unit_api dnssec_zone_nsec_tests_api; - -#endif // _KNOTD_DNSSEC_ZONE_NSEC_TESTS_ diff --git a/src/tests/libknot/rrset_tests.c b/src/tests/libknot/rrset_tests.c deleted file mode 100644 index 2a952e0b1b..0000000000 --- a/src/tests/libknot/rrset_tests.c +++ /dev/null @@ -1,1468 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ -#if 0 -#include <config.h> -#include <assert.h> -#include <stdint.h> -#include <inttypes.h> - -#include "tests/libknot/rrset_tests.h" -#include "common/descriptor.h" -#include "common/errcode.h" -#include "common/print.h" -#include "libknot/rrset.h" -#include "libknot/util/wire.h" -#include "common/mempattern.h" - -static int knot_rrset_tests_count(int argc, char *argv[]); -static int knot_rrset_tests_run(int argc, char *argv[]); - -/*! Exported unit API. - */ -unit_api rrset_tests_api = { - "libknot/rrset", //! Unit name - &knot_rrset_tests_count, //! Count scheduled tests - &knot_rrset_tests_run //! Run scheduled tests -}; - -/* - * Unit implementation. - */ - -enum rrset_test_const { - TEST_RRSET_COUNT = 14, - TEST_RDATA_COUNT = 10, - TEST_DNAME_COUNT = 11, - - TEST_RDATA_A_LESS = 0, - TEST_RDATA_A_GT = 1, - TEST_RDATA_NS_LESS = 2, - TEST_RDATA_NS_GT = 3, - TEST_RDATA_MX_DNAME_LESS = 4, - TEST_RDATA_MX_DNAME_GT = 5, - TEST_RDATA_MX_BIN_LESS = 6, - TEST_RDATA_MX_BIN_GT = 7, - TEST_RDATA_MINFO1 = 8, - TEST_RDATA_MINFO2 = 9, - - TEST_RRSET_A_LESS = 0, - TEST_RRSET_A_GT = 1, - TEST_RRSET_MERGE_UNIQUE1 = 0, - TEST_RRSET_MERGE_UNIQUE2 = 1, - TEST_RRSET_MERGE_RESULT1 = 10, - TEST_RRSET_NS_LESS = 2, - TEST_RRSET_NS_GT = 3, - TEST_RRSET_MX_BIN_LESS = 4, - TEST_RRSET_MX_BIN_GT = 5, - TEST_RRSET_MX_DNAME_LESS = 6, - TEST_RRSET_MX_DNAME_GT = 7, - TEST_RRSET_MINFO = 8, - TEST_RRSET_MINFO_MULTIPLE1 = 9, - TEST_RRSET_MINFO_MULTIPLE2 = 13, - TEST_RRSET_OWNER_LESS = 11, - TEST_RRSET_OWNER_GT = 12, - - CHECK_LAST_INDEX = 0, - OMMIT_LAST_INDEX = 1, - TEST_DNAME_GENERIC = 0, - TEST_DNAME_LESS = 1, - TEST_DNAME_GREATER = 2 -}; - -static char *test_dname_strings[TEST_DNAME_COUNT] = { - "a.dname.com.", - "b.dname.com.", - "c.dname.com.", - "d.dname.com.", - "e.dname.com.", - "f.dname.com.", - "ns1.nic.cz.", - "ns2.nic.cz.", - "ns3.nic.cz.", - "ns4.nic.cz.", - "ns5.nic.cz." -}; - -static knot_dname_t *test_dnames[TEST_DNAME_COUNT]; - -struct test_rdata { - uint8_t *rdata; // RDATA in knot internal format - uint8_t *wire; // RDATA in wireformat - uint16_t size; // RDATA internal size - uint16_t wire_size; // Wireformat size -}; - -typedef struct test_rdata test_rdata_t; - -struct test_rrset { - int owner_id; // Owners have to be dynamically allocated, IDs used to connect. - knot_rrset_t rrset; // Dynamically created knot_rrset_t structure. - uint8_t *header_wire; // Owner, class, TTL. - size_t header_wire_size; // Header size. - size_t rr_count; // RR count. - int test_rdata_ids[16]; // RDATA IDs - will be used to assign RDATA. - test_rdata_t **test_rdata; // Dynamically created test RDATA. -}; - -typedef struct test_rrset test_rrset_t; - -/* Artificial RDATA definitions: */ -static test_rdata_t test_rdata_array[TEST_RDATA_COUNT] = { - [TEST_RDATA_A_LESS] = {(uint8_t *)"\x1\x1\x1\0", (uint8_t *)"\x1\x1\x1\0", 4, 4}, - [TEST_RDATA_A_GT] = {(uint8_t *)"\x1\x1\x1\1", (uint8_t *)"\x1\x1\x1\1", 4, 4}, - [TEST_RDATA_NS_LESS] = {NULL, NULL, sizeof(knot_dname_t *), 0}, - [TEST_RDATA_NS_GT] = {NULL, NULL, sizeof(knot_dname_t *), 0}, - [TEST_RDATA_MX_DNAME_LESS] = {NULL, NULL, sizeof(knot_dname_t *) + 2, 0}, - [TEST_RDATA_MX_DNAME_GT] = {NULL, NULL, sizeof(knot_dname_t *) + 2, 0}, - [TEST_RDATA_MX_BIN_LESS] = {NULL, NULL, sizeof(knot_dname_t *) + 2, 0}, - [TEST_RDATA_MX_BIN_GT] = {NULL, NULL, sizeof(knot_dname_t *) + 2, 0}, - [TEST_RDATA_MINFO1] = {NULL, NULL, sizeof(knot_dname_t *) * 2, 0}, - [TEST_RDATA_MINFO2] = {NULL, NULL, sizeof(knot_dname_t *) * 2, 0}, -}; - - -test_rrset_t test_rrset_array[TEST_RRSET_COUNT] = { - [TEST_RRSET_A_LESS] = {TEST_DNAME_GENERIC, {NULL, KNOT_RRTYPE_A, KNOT_CLASS_IN, 3600, NULL, NULL, 0, NULL}, - NULL, 0, 1, {TEST_RDATA_A_LESS}, NULL}, - [TEST_RRSET_A_GT] = {TEST_DNAME_GENERIC, {NULL, KNOT_RRTYPE_A, KNOT_CLASS_IN, 3600, NULL, NULL, 0, NULL}, - NULL, 0, 1, {TEST_RDATA_A_GT}, NULL}, - [TEST_RRSET_NS_LESS] = {TEST_DNAME_GENERIC, {NULL, KNOT_RRTYPE_NS, KNOT_CLASS_IN, 3600, NULL, NULL, 0, NULL}, - NULL, 0, 1, {TEST_RDATA_NS_LESS}, NULL}, - [TEST_RRSET_NS_GT] = {TEST_DNAME_GENERIC, {NULL, KNOT_RRTYPE_NS, KNOT_CLASS_IN, 3600, NULL, NULL, 0, NULL}, - NULL, 0, 1, {TEST_RDATA_NS_GT}, NULL}, - [TEST_RRSET_MX_DNAME_LESS] = {TEST_DNAME_GENERIC, {NULL, KNOT_RRTYPE_MX, KNOT_CLASS_IN, 3600, NULL, NULL, 0, NULL}, - NULL, 0, 1, {TEST_RDATA_MX_DNAME_LESS}, NULL}, - [TEST_RRSET_MX_DNAME_GT] = {TEST_DNAME_GENERIC, {NULL, KNOT_RRTYPE_MX, KNOT_CLASS_IN, 3600, NULL, NULL, 0, NULL}, - NULL, 0, 1, {TEST_RDATA_MX_DNAME_GT}, NULL}, - [TEST_RRSET_MX_BIN_LESS] = {TEST_DNAME_GENERIC, {NULL, KNOT_RRTYPE_MX, KNOT_CLASS_IN, 3600, NULL, NULL, 0, NULL}, - NULL, 0, 1, {TEST_RDATA_MX_BIN_LESS}, NULL}, - [TEST_RRSET_MX_BIN_GT] = {TEST_DNAME_GENERIC, {NULL, KNOT_RRTYPE_MX, KNOT_CLASS_IN, 3600, NULL, NULL, 0, NULL}, - NULL, 0, 1, {TEST_RDATA_MX_BIN_GT}, NULL}, - [TEST_RRSET_MINFO] = {TEST_DNAME_GENERIC, {NULL, KNOT_RRTYPE_MINFO, KNOT_CLASS_IN, 3600, NULL, NULL, 0, NULL}, - NULL, 0, 1, {TEST_RDATA_MINFO1}, NULL}, - [TEST_RRSET_MINFO_MULTIPLE1] = {TEST_DNAME_GENERIC, {NULL, KNOT_RRTYPE_MINFO, KNOT_CLASS_IN, 3600, NULL, NULL, 0, NULL}, - NULL, 0, 2, {TEST_RDATA_MINFO1, TEST_RDATA_MINFO2}, NULL}, - [TEST_RRSET_MINFO_MULTIPLE2] = {TEST_DNAME_GENERIC, {NULL, KNOT_RRTYPE_MINFO, KNOT_CLASS_IN, 3600, NULL, NULL, 0, NULL}, - NULL, 0, 2, {TEST_RDATA_MINFO2, TEST_RDATA_MINFO1}, NULL}, - [TEST_RRSET_MERGE_RESULT1] = {TEST_DNAME_GENERIC, {NULL, KNOT_RRTYPE_A, KNOT_CLASS_IN, 3600, NULL, NULL, 0, NULL}, - NULL, 0, 2, {TEST_RDATA_A_LESS, TEST_RDATA_A_GT}, NULL}, - [TEST_RRSET_OWNER_LESS] = {TEST_DNAME_LESS, {NULL, KNOT_RRTYPE_A, KNOT_CLASS_IN, 3600, NULL, NULL, 0, NULL}, - NULL, 0, 1, {TEST_RDATA_A_LESS}, NULL}, - [TEST_RRSET_OWNER_GT] = {TEST_DNAME_GREATER, {NULL, KNOT_RRTYPE_A, KNOT_CLASS_IN, 3600, NULL, NULL, 0, NULL}, - NULL, 0, 1, {TEST_RDATA_A_LESS}, NULL} -}; - -static void create_test_dnames() -{ - for (int i = 0; i < TEST_DNAME_COUNT; i++) { - test_dnames[i] = - knot_dname_from_str(test_dname_strings[i], - strlen(test_dname_strings[i])); - } -} - -static void init_test_rdata_with_dname(uint8_t **rdata, uint16_t *rdata_size, - uint8_t **wire, uint16_t *wire_size, - size_t pos, size_t wire_pos, - size_t alloc_size, - size_t wire_alloc_size, - knot_dname_t *dname) -{ - if (pos == 0) { - *rdata = xmalloc(alloc_size); - *rdata_size = 0; - *wire = xmalloc(wire_alloc_size); - *wire_size = 0; - } - memcpy(*rdata + pos, &dname, sizeof(knot_dname_t *)); - *rdata_size += sizeof(knot_dname_t *); - memcpy(*wire + wire_pos, dname, knot_dname_size(dname)); - *wire_size += knot_dname_size(dname); -} - -static void init_test_rdata_with_binary(uint8_t **rdata, uint16_t *rdata_size, - uint8_t **wire, uint16_t *wire_size, - size_t pos, size_t wire_pos, - size_t alloc_size, - size_t wire_alloc_size, - const void *data, size_t data_size) -{ - if (pos == 0) { - // New structure, allocate. - *rdata = xmalloc(alloc_size); - *rdata_size = 0; - *wire = xmalloc(wire_alloc_size); - *wire_size = 0; - } - memcpy(*rdata + pos, data, data_size); - *rdata_size += data_size; - memcpy(*wire + wire_pos, data, data_size); - *wire_size += data_size; -} - -static void create_test_rdata() -{ - /* NS, MX and MINFO types need an init. */ - - /* NS RDATA DNAME = a.dname.com. */ - init_test_rdata_with_dname(&test_rdata_array[TEST_RDATA_NS_LESS].rdata, - &test_rdata_array[TEST_RDATA_NS_LESS].size, - &test_rdata_array[TEST_RDATA_NS_LESS].wire, - &test_rdata_array[TEST_RDATA_NS_LESS].wire_size, - 0, 0, sizeof(knot_dname_t *), - knot_dname_size(test_dnames[0]), test_dnames[0]); - - /* NS RDATA DNAME = b.dname.com. */ - init_test_rdata_with_dname(&test_rdata_array[TEST_RDATA_NS_GT].rdata, - &test_rdata_array[TEST_RDATA_NS_GT].size, - &test_rdata_array[TEST_RDATA_NS_GT].wire, - &test_rdata_array[TEST_RDATA_NS_GT].wire_size, - 0, 0, sizeof(knot_dname_t *), - knot_dname_size(test_dnames[1]), test_dnames[1]); - - /* MX RDATA - short = 10 DNAME = a.dname.com. */ - uint16_t id = htobe16(10); - init_test_rdata_with_binary(&test_rdata_array[TEST_RDATA_MX_DNAME_LESS].rdata, - &test_rdata_array[TEST_RDATA_MX_DNAME_LESS].size, - &test_rdata_array[TEST_RDATA_MX_DNAME_LESS].wire, - &test_rdata_array[TEST_RDATA_MX_DNAME_LESS].wire_size, - 0, 0, sizeof(knot_dname_t *) + 2, - knot_dname_size(test_dnames[1]) + 2, &id, 2); - - init_test_rdata_with_dname(&test_rdata_array[TEST_RDATA_MX_DNAME_LESS].rdata, - &test_rdata_array[TEST_RDATA_MX_DNAME_LESS].size, - &test_rdata_array[TEST_RDATA_MX_DNAME_LESS].wire, - &test_rdata_array[TEST_RDATA_MX_DNAME_LESS].wire_size, - 2, 2, sizeof(knot_dname_t *), - knot_dname_size(test_dnames[1]), test_dnames[0]); - - /* MX RDATA - short = 10 DNAME = b.dname.com. */ - init_test_rdata_with_binary(&test_rdata_array[TEST_RDATA_MX_DNAME_GT].rdata, - &test_rdata_array[TEST_RDATA_MX_DNAME_GT].size, - &test_rdata_array[TEST_RDATA_MX_DNAME_GT].wire, - &test_rdata_array[TEST_RDATA_MX_DNAME_GT].wire_size, - 0, 0, sizeof(knot_dname_t *) + 2, - knot_dname_size(test_dnames[1]) + 2, &id, 2); - - init_test_rdata_with_dname(&test_rdata_array[TEST_RDATA_MX_DNAME_GT].rdata, - &test_rdata_array[TEST_RDATA_MX_DNAME_GT].size, - &test_rdata_array[TEST_RDATA_MX_DNAME_GT].wire, - &test_rdata_array[TEST_RDATA_MX_DNAME_GT].wire_size, - 2, 2, sizeof(knot_dname_t *), - knot_dname_size(test_dnames[1]), test_dnames[1]); - - test_rdata_array[TEST_RDATA_MX_BIN_LESS] = test_rdata_array[TEST_RDATA_MX_DNAME_LESS]; - - /* MX RDATA - short = 20 DNAME = b.dname.com. */ - id = htobe16(20); - init_test_rdata_with_binary(&test_rdata_array[TEST_RDATA_MX_BIN_GT].rdata, - &test_rdata_array[TEST_RDATA_MX_BIN_GT].size, - &test_rdata_array[TEST_RDATA_MX_BIN_GT].wire, - &test_rdata_array[TEST_RDATA_MX_BIN_GT].wire_size, - 0, 0, sizeof(knot_dname_t *) + 2, - knot_dname_size(test_dnames[1]) + 2, &id, 2); - - init_test_rdata_with_dname(&test_rdata_array[TEST_RDATA_MX_BIN_GT].rdata, - &test_rdata_array[TEST_RDATA_MX_BIN_GT].size, - &test_rdata_array[TEST_RDATA_MX_BIN_GT].wire, - &test_rdata_array[TEST_RDATA_MX_BIN_GT].wire_size, - 2, 2, sizeof(knot_dname_t *), - knot_dname_size(test_dnames[1]), test_dnames[1]); - - /* MINFO RRs. */ - init_test_rdata_with_dname(&test_rdata_array[TEST_RDATA_MINFO1].rdata, - &test_rdata_array[TEST_RDATA_MINFO1].size, - &test_rdata_array[TEST_RDATA_MINFO1].wire, - &test_rdata_array[TEST_RDATA_MINFO1].wire_size, - 0, 0, sizeof(knot_dname_t *) * 2, - knot_dname_size(test_dnames[0]) + knot_dname_size(test_dnames[1]), - test_dnames[0]); - - init_test_rdata_with_dname(&test_rdata_array[TEST_RDATA_MINFO1].rdata, - &test_rdata_array[TEST_RDATA_MINFO1].size, - &test_rdata_array[TEST_RDATA_MINFO1].wire, - &test_rdata_array[TEST_RDATA_MINFO1].wire_size, - sizeof(knot_dname_t *), knot_dname_size(test_dnames[0]), - sizeof(knot_dname_t *), - knot_dname_size(test_dnames[1]), test_dnames[1]); - - init_test_rdata_with_dname(&test_rdata_array[TEST_RDATA_MINFO2].rdata, - &test_rdata_array[TEST_RDATA_MINFO2].size, - &test_rdata_array[TEST_RDATA_MINFO2].wire, - &test_rdata_array[TEST_RDATA_MINFO2].wire_size, - 0, 0, sizeof(knot_dname_t *) * 2, - knot_dname_size(test_dnames[2]) + knot_dname_size(test_dnames[3]), - test_dnames[2]); - - init_test_rdata_with_dname(&test_rdata_array[TEST_RDATA_MINFO2].rdata, - &test_rdata_array[TEST_RDATA_MINFO2].size, - &test_rdata_array[TEST_RDATA_MINFO2].wire, - &test_rdata_array[TEST_RDATA_MINFO2].wire_size, - sizeof(knot_dname_t *), knot_dname_size(test_dnames[2]), - sizeof(knot_dname_t *), - knot_dname_size(test_dnames[3]), test_dnames[3]); -} - -static void create_test_rrsets() -{ - for (int i = 0; i < TEST_RRSET_COUNT; i++) { - /* Create memory representation. */ - test_rrset_t *test_rrset = &test_rrset_array[i]; - /* Assign owner. */ - test_rrset->rrset.owner = test_dnames[test_rrset->owner_id]; - - /* Create wire representation. */ - - /* Create header wire. */ - test_rrset->header_wire_size = knot_dname_size(test_rrset->rrset.owner) + 8; - test_rrset->header_wire = - xmalloc(test_rrset->header_wire_size); - /* Copy owner wire to header wire. */ - memcpy(test_rrset->header_wire, test_rrset->rrset.owner, - knot_dname_size(test_rrset->rrset.owner)); - /* Copy type to wire. */ - size_t offset = knot_dname_size(test_rrset->rrset.owner); - knot_wire_write_u16(test_rrset->header_wire + offset, - test_rrset->rrset.type); - offset += sizeof(uint16_t); - /* Copy class to wire. */ - knot_wire_write_u16(test_rrset->header_wire + offset, - test_rrset->rrset.rclass); - offset += sizeof(uint16_t); - /* Copy TTL to wire. */ - knot_wire_write_u32(test_rrset->header_wire + offset, - test_rrset->rrset.ttl); - - /* Create RDATA. */ - test_rrset->test_rdata = - xmalloc(sizeof(void *) * test_rrset->rr_count); - size_t actual_length = 0; - size_t rdlength = 0; - test_rrset->rrset.rdata_count = test_rrset->rr_count; - for (int j = 0; j < test_rrset->rr_count; j++) { - test_rrset->test_rdata[j] = - &test_rdata_array[test_rrset->test_rdata_ids[j]]; - rdlength += test_rrset->test_rdata[j]->wire_size; - actual_length += test_rrset->test_rdata[j]->size; - } - /* Assign RDATA (including indices). */ - offset = 0; - test_rrset->rrset.rdata = xmalloc(actual_length); - test_rrset->rrset.rdata_indices = - xmalloc(sizeof(uint32_t) * test_rrset->rr_count); - for (int j = 0; j < test_rrset->rr_count; j++) { - if (j > 0) { - test_rrset->rrset.rdata_indices[j - 1] = - test_rrset->test_rdata[j]->size; - } - - memcpy(test_rrset->rrset.rdata + offset, - test_rrset->test_rdata[j]->rdata, - test_rrset->test_rdata[j]->size); - offset += test_rrset->test_rdata[j]->size; - } - /* Store sum of indices to the last index. */ - test_rrset->rrset.rdata_indices[test_rrset->rr_count - 1] = - offset; - } -} - -static int check_rrset_values(const knot_rrset_t *rrset, - knot_dname_t *dname, uint16_t type, - uint16_t rclass, uint16_t ttl, uint16_t rr_count) -{ - int errors = 0; - - if (!knot_dname_is_equal(rrset->owner, dname)) { - diag("Wrong DNAME in the created RRSet.\n"); - ++errors; - } - - if (rrset->type != type) { - diag("Wrong type in the created RRSet.\n"); - ++errors; - } - - if (rrset->rclass != rclass) { - diag("Wrong class in the created RRSet.\n"); - ++errors; - } - - if (rrset->ttl != ttl) { - diag("Wrong TTL in the created RRSet.\n"); - ++errors; - } - - if (rrset->rdata_count!= rr_count) { - diag("Wrong RR count in the created RRSet.\n"); - ++errors; - } - - return errors; -} - -static int test_rrset_new() -{ - /* Actual values don't matter in this case. */ - knot_dname_t *dname = test_dnames[0]; - uint16_t type = 1; - uint16_t rclass = 1; - uint32_t ttl = 1; - - knot_rrset_t *rrset = knot_rrset_new(dname, type, rclass, ttl); - if (rrset == NULL) { - diag("Failed to create new RRSet.\n"); - return 0; - } - - int check_errors = check_rrset_values(rrset, dname, type, rclass, ttl, - 0); - free(rrset); - - return (check_errors == 0); -} - -static int test_rrset_create_rdata() -{ - /* Two cases need to be tested - empty RRSet and non-empty RRSet. */ - - - knot_rrset_t *rrset = knot_rrset_new(test_dnames[0], 0, 0, 0); - assert(rrset); - - /* - * Again, actual data are not crutial, we need to see if indices - * are changed accordingly and so on, but the data are not important. - */ - uint8_t *write_pointer = - knot_rrset_create_rdata(rrset, - test_rdata_array[0].size); - if (write_pointer == NULL) { - diag("Could not create data of size %d\n", - test_rdata_array[0].size); - knot_rrset_deep_free(&rrset, 1, 1); - return 0; - } - - /* Write dummy data. */ - memcpy(write_pointer, test_rdata_array[0].rdata, - test_rdata_array[0].size); - - /* Check that indices are set right. */ - if (rrset->rdata_indices[0] != test_rdata_array[0].size) { - diag("Wrong RDATA index after inserting RDATA to RRSet.\n"); - knot_rrset_deep_free(&rrset, 1, 1); - return 0; - } - - /* Rdata count must be equal to one. */ - if (rrset->rdata_count != 1) { - diag("Wrong RDATA count after inserting RDATA to RRSet.\n"); - knot_rrset_deep_free(&rrset, 1, 1); - return 0; - } - - /* Make sure that the data in the RRSet are the same. */ - int ret = memcmp(rrset->rdata, test_rdata_array[0].rdata, - test_rdata_array[0].size); - if (ret) { - diag("Wrong data inserted into RRSet.\n"); - knot_rrset_deep_free(&rrset, 1, 1); - return 0; - } - - /* Insert second item - all other inserts will do the same thing. */ - write_pointer = knot_rrset_create_rdata(rrset, - test_rdata_array[1].size); - if (write_pointer == NULL) { - diag("Could not create data of size %d\n", - test_rdata_array[1].size); - knot_rrset_deep_free(&rrset, 1, 1); - return 0; - } - - /* Write dummy data. */ - memcpy(write_pointer, test_rdata_array[1].rdata, - test_rdata_array[1].size); - - /* Check that indices are set right. */ - if (rrset->rdata_indices[0] != test_rdata_array[1].size) { - diag("Wrong RDATA first index after " - "inserting RDATA to RRSet.\n"); - knot_rrset_deep_free(&rrset, 1, 1); - return 0; - } - - if (rrset->rdata_indices[1] != - test_rdata_array[0].size + test_rdata_array[1].size) { - diag("Wrong RDATA last index after " - "inserting RDATA to RRSet.\n"); - knot_rrset_deep_free(&rrset, 1, 1); - return 0; - } - - /* Rdata count must be equal to two. */ - if (rrset->rdata_count != 2) { - diag("Wrong RDATA count after inserting second " - "RDATA to RRSet.\n"); - knot_rrset_deep_free(&rrset, 1, 1); - return 0; - } - - /* Make sure that the data in the RRSet are the same. */ - ret = memcmp(rrset->rdata + test_rdata_array[0].size, - test_rdata_array[1].rdata, test_rdata_array[1].size); - if (ret) { - diag("Wrong data inserted into RRSet.\n"); - knot_rrset_deep_free(&rrset, 1, 1); - return 0; - } - - /* Test that data of length 0 are not inserted. */ - void *ret_ptr = knot_rrset_create_rdata(rrset, 0); - if (ret_ptr != NULL) { - diag("Empty RDATA inserted.\n"); - knot_rrset_deep_free(&rrset, 1, 1); - return 0; - } - - knot_rrset_deep_free(&rrset, 1, 1); - return 1; -} - -static int test_rrset_rdata_item_size() -{ - /* Test that types containing DNAMEs only return OK values. */ - knot_rrset_t *rrset = - &test_rrset_array[TEST_RRSET_MINFO_MULTIPLE1].rrset; - if (rrset_rdata_item_size(rrset, 0) != sizeof(knot_dname_t *) * 2) { - diag("Wrong item length read from RRSet (first item).\n"); - return 0; - } - - if (rrset_rdata_item_size(rrset, 1) != sizeof(knot_dname_t *) * 2) { - diag("Wrong item length read from RRSet (last item).\n"); - return 0; - } - - if (rrset_rdata_size_total(rrset) != sizeof(knot_dname_t *) * 4) { - diag("Wrong total size returned (MINFO RRSet)\n"); - return 0; - } - - rrset = &test_rrset_array[TEST_RRSET_A_GT].rrset; - if (rrset_rdata_item_size(rrset, 0) != 4) { - diag("Wrong item length read from A RRSet.\n"); - return 0; - } - - rrset = &test_rrset_array[TEST_RRSET_MX_BIN_GT].rrset; - if (rrset_rdata_item_size(rrset, 0) != 2 + sizeof(knot_dname_t *)) { - diag("Wrong item length read from A RRSet.\n"); - return 0; - } - - knot_rrset_t *rrset1 = knot_rrset_new(rrset->owner, - KNOT_RRTYPE_TXT, KNOT_CLASS_IN, - 3600); - - knot_rrset_create_rdata(rrset1, 16); - knot_rrset_add_rdata(rrset1, - (uint8_t *)"thesearesomedatathatdonotmatter", 25); - knot_rrset_create_rdata(rrset1, 38); - - if (rrset_rdata_item_size(rrset1, 0) != 16) { - diag("Wrong item lenght in read (first).\n"); - knot_rrset_deep_free(&rrset1, 1, 1); - return 0; - } - - if (rrset_rdata_item_size(rrset1, 1) != 25) { - diag("Wrong item lenght in read (middle).\n"); - knot_rrset_deep_free(&rrset1, 1, 1); - return 0; - } - - if (rrset_rdata_item_size(rrset1, 2) != 38) { - diag("Wrong item lenght in read (last).\n"); - knot_rrset_deep_free(&rrset1, 1, 1); - return 0; - } - - knot_rrset_deep_free(&rrset1, 1, 1); - return 1; -} - -static int test_rrset_get_rdata() -{ - knot_rrset_t *rrset = knot_rrset_new(test_dnames[0], - KNOT_RRTYPE_TXT, KNOT_CLASS_IN, 3600); - assert(rrset); - uint8_t *ref_pointer = knot_rrset_create_rdata(rrset, 16); - memcpy(ref_pointer, "badcafecafebabee", 16); - uint8_t *pointer = knot_rrset_get_rdata(rrset, 0); - if (pointer != ref_pointer) { - diag("Could not get RDATA from RRSet (%p vs %p).\n", - pointer, ref_pointer); - knot_rrset_deep_free(&rrset, 1, 1); - return 0; - } - - int ret = memcmp(pointer, ref_pointer, 16); - if (ret) { - diag("Got bad RDATA from RRSet (comparison failed).\n"); - knot_rrset_deep_free(&rrset, 1, 1); - return 0; - } - - uint8_t *ref_pointer2 = knot_rrset_create_rdata(rrset, 16); - memcpy(ref_pointer2, "foobarfoobarfoob", 16); - pointer = knot_rrset_get_rdata(rrset, 1); - if (pointer != ref_pointer2) { - diag("Could not ger RDATA from RRSet (%p vs %p).\n", - pointer, ref_pointer2); - knot_rrset_deep_free(&rrset, 1, 1); - return 0; - } - - ret = memcmp(pointer, ref_pointer2, 16); - if (ret) { - diag("Got bad RDATA from RRSet (comparison failed).\n"); - knot_rrset_deep_free(&rrset, 1, 1); - return 0; - } - - knot_rrset_deep_free(&rrset, 1, 1); - return 1; -} - -static int test_rrset_shallow_copy() -{ - for (int i = 0; i < TEST_RRSET_COUNT; i++) { - knot_rrset_t *rrset_copy = NULL; - knot_rrset_t *rrset = &test_rrset_array[i].rrset; - int ret = knot_rrset_shallow_copy(rrset, - &rrset_copy); - if (ret != KNOT_EOK) { - knot_rrset_free(&rrset_copy); - diag("Could not copy RRSet.\n"); - return 0; - } - - /* Check that created RRSet has the same as the old one. */ - int errors = check_rrset_values(rrset_copy, rrset->owner, rrset->type, - rrset->rclass, rrset->ttl, - rrset->rdata_count); - if (errors) { - knot_rrset_free(&rrset_copy); - return 0; - } - - /* Check that created RRSet has the same RDATA. */ - if (rrset->rdata != rrset_copy->rdata) { - diag("RDATA in the new RRSet do not match.\n"); - knot_rrset_free(&rrset_copy); - return 0; - } - - /* Check that RDATA indices are the same. */ - if (rrset->rdata_indices != rrset_copy->rdata_indices) { - diag("RDATA indices in the new RRSet do not match.\n"); - knot_rrset_free(&rrset_copy); - return 0; - } - - knot_rrset_free(&rrset_copy); - } - - return 1; -} - -static int test_rrset_deep_copy() -{ - for (int i = 0; i < TEST_RRSET_COUNT; i++) { - knot_rrset_t *rrset_copy = NULL; - knot_rrset_t *rrset = &test_rrset_array[i].rrset; - int ret = knot_rrset_deep_copy(rrset, &rrset_copy); - if (ret != KNOT_EOK) { - diag("Could not copy RRSet.\n"); - return 0; - } - - /* Check that created RRSet has the same as the old one. */ - int errors = check_rrset_values(rrset_copy, rrset->owner, rrset->type, - rrset->rclass, rrset->ttl, - rrset->rdata_count); - if (errors) { - knot_rrset_deep_free(&rrset_copy, 1, 1); - return 0; - } - - /* Check that RDATA indices contain the same data. */ - ret = memcmp(rrset->rdata_indices, rrset_copy->rdata_indices, - rrset->rdata_count); - if (ret) { - diag("Copied RRSet has different RDATA indices.\n"); - knot_rrset_deep_free(&rrset_copy, 1, 1); - return 0; - } - - /* - * Go through RDATA and compare blocks. Cannot compare the whole thing - * since DNAMEs are copied as well and will have different address. - */ - ret = knot_rrset_rdata_equal(rrset, rrset_copy); - if (!ret) { - diag("Copied RRSet has different RDATA.\n"); - knot_rrset_deep_free(&rrset_copy, 1, 1); - return 0; - } - knot_rrset_deep_free(&rrset_copy, 1, 1); - } - - return 1; -} - -static int test_rrset_to_wire() -{ - size_t wire_size = 65535; - uint8_t wire[wire_size]; - uint16_t rr_count = 0; - - /* Test correct conversions. */ - for (int i = 0; i < TEST_RRSET_COUNT; i++) { - memset(wire, 0, wire_size); - wire_size = 65535; - /* Convert to wire. */ - int ret = knot_rrset_to_wire(&test_rrset_array[i].rrset, wire, - &wire_size, 65535, &rr_count, NULL); - if (ret != KNOT_EOK) { - diag("Could not convert RRSet to wire (%s).\n", - knot_strerror(ret)); - return 0; - } - - if (rr_count != test_rrset_array[i].rrset.rdata_count) { - diag("Wrong number of RRs converted.\n"); - return 0; - } - - size_t offset = 0; - for (int j = 0; j < rr_count; ++j) { - /* Check that header is OK. */ - ret = memcmp(wire + offset, - test_rrset_array[i].header_wire, - test_rrset_array[i].header_wire_size); - if (ret) { - diag("Header of RRSet %d, RR %d is wrongly converted.\n", - i, j); - return 0; - } - - offset += test_rrset_array[i].header_wire_size; - /* Check RDLENGTH. */ - uint16_t rdlength = knot_wire_read_u16(wire + offset); - if (rdlength != test_rrset_array[i].test_rdata[j]->wire_size) { - diag("Wrong RDLENGTH\n"); - return 0; - } - offset += sizeof(uint16_t); - - /* Check that the RDATA are OK. */ - ret = memcmp(wire + offset, - test_rrset_array[i].test_rdata[j]->wire, - rdlength); - if (ret) { - diag("RDATA of RRSet %d, RR %d, " - "are wrongly converted. Type=%"PRIu16"\n", - i, j, test_rrset_array[i].rrset.type); - return 0; - } - offset += rdlength; - } - - if (offset != wire_size) { - diag("Wrong wire size, in RRSet=%d " - "(should be=%d, is=%d).\n", i, - offset, wire_size); - return 0; - } - } - - /* Check that function does not crash if given small wire. */ - int ret = knot_rrset_to_wire(&test_rrset_array[0].rrset, wire, - &wire_size, 5, &rr_count, NULL); - if (ret != KNOT_ESPACE) { - diag("RRSet was converted to wire even though twe wire was" - " not big enough.\n"); - return 0; - } - /* RDATA do not fit. */ - ret = knot_rrset_to_wire(&test_rrset_array[0].rrset, wire, - &wire_size, 25, &rr_count, NULL); - if (ret != KNOT_ESPACE) { - diag("RRSet was converted to wire even though twe wire was" - " not big enough.\n"); - return 0; - } - - return 1; -} - -static int test_rrset_merge() -{ - knot_rrset_t *merge_to; - knot_rrset_deep_copy(&test_rrset_array[TEST_RRSET_MERGE_UNIQUE1].rrset, - &merge_to); - knot_rrset_t *merge_from; - knot_rrset_deep_copy(&test_rrset_array[TEST_RRSET_MERGE_UNIQUE2].rrset, - &merge_from); - assert(merge_to); - assert(merge_from); - int ret = knot_rrset_merge(merge_to, merge_from); - if (ret != KNOT_EOK) { - diag("Could not merge RRSets.\n"); - knot_rrset_deep_free(&merge_to, 1, 1); - knot_rrset_deep_free(&merge_from, 1, 1); - return 0; - } - - //TODO check that merge operation does not change second rr - //TODO check that two RRSet that are not mergable will not merge - if (!knot_rrset_equal(&test_rrset_array[TEST_RRSET_MERGE_UNIQUE2].rrset, - merge_from, - KNOT_RRSET_COMPARE_WHOLE)) { - diag("Merge corrupted second RRSet.\n"); - return 0; - } - - if (merge_to->rdata_count != - test_rrset_array[TEST_RRSET_MERGE_UNIQUE1].rrset.rdata_count + - merge_from->rdata_count) { - diag("Not all RDATA were merged.\n"); - knot_rrset_deep_free(&merge_to, 1, 1); - knot_rrset_deep_free(&merge_from, 1, 1); - return 0; - } - - /* Check that the first RRSet now contains RDATA from the second. */ - /* Indices first. */ - ret = memcmp(merge_to->rdata_indices, - test_rrset_array[TEST_RRSET_MERGE_RESULT1].rrset.rdata_indices, - merge_to->rdata_count); - if (ret) { - diag("Merge operation corrupted the first RRSet's indices.\n"); - knot_rrset_deep_free(&merge_to, 1, 1); - knot_rrset_deep_free(&merge_from, 1, 1); - return 0; - } - - /* Check actual RDATA. */ - ret = knot_rrset_rdata_equal(merge_to, - &test_rrset_array[TEST_RRSET_MERGE_RESULT1].rrset); - if (!ret) { - diag("Merged RDATA are wrong.\n"); - knot_rrset_deep_free(&merge_to, 1, 1); - knot_rrset_deep_free(&merge_from, 1, 1); - return 0; - } - - knot_rrset_deep_free(&merge_to, 1, 1); - knot_rrset_deep_free(&merge_from, 1, 1); - - return 1; -} - -static int test_rrset_merge_sort() -{ - /* Test that merge of two identical RRSets results in no-op. */ - knot_rrset_t *merge_to = NULL; - knot_rrset_deep_copy(&test_rrset_array[TEST_RRSET_MERGE_UNIQUE1].rrset, - &merge_to); - knot_rrset_t *merge_from = NULL; - knot_rrset_deep_copy(&test_rrset_array[TEST_RRSET_MERGE_UNIQUE1].rrset, - &merge_from); - int merged, removed_rrs; - int ret = knot_rrset_merge_sort(merge_to, merge_from, &merged, &removed_rrs); - if (ret != KNOT_EOK) { - diag("Merge of identical RRSets failed.\n"); - return 0; - } - - if (!knot_rrset_equal(&test_rrset_array[TEST_RRSET_MERGE_UNIQUE1].rrset, - merge_to, KNOT_RRSET_COMPARE_WHOLE)) { - diag("Merge corrupted first RRSet.\n"); - return 0; - } - - if (!knot_rrset_equal(&test_rrset_array[TEST_RRSET_MERGE_UNIQUE1].rrset, - merge_from, KNOT_RRSET_COMPARE_WHOLE)) { - diag("Merge corrupted second RRSet.\n"); - return 0; - } - - knot_rrset_deep_free(&merge_to, 1, 1); - knot_rrset_deep_free(&merge_from, 1, 1); - - /* Merge normal, non-duplicated RRSets. */ - knot_rrset_deep_copy(&test_rrset_array[TEST_RRSET_MERGE_UNIQUE1].rrset, - &merge_to); - knot_rrset_deep_copy(&test_rrset_array[TEST_RRSET_MERGE_UNIQUE2].rrset, - &merge_from); - assert(merge_to); - assert(merge_from); - - ret = knot_rrset_merge_sort(merge_to, merge_from, &merged, - &removed_rrs); - if (ret != KNOT_EOK) { - diag("Merge of identical RRSets failed.\n"); - return 0; - } - - if (!knot_rrset_equal(&test_rrset_array[TEST_RRSET_MERGE_UNIQUE2].rrset, - merge_from, - KNOT_RRSET_COMPARE_WHOLE)) { - diag("Merge corrupted second RRSet.\n"); - return 0; - } - - if (!knot_rrset_equal(&test_rrset_array[TEST_RRSET_MERGE_RESULT1].rrset, - merge_to, - KNOT_RRSET_COMPARE_WHOLE)) { - diag("Merge did not create correct RDATA.\n"); - return 0; - } - - knot_rrset_deep_free(&merge_to, 1, 1); - knot_rrset_deep_free(&merge_from, 1, 1); - - /* Merge RRSets with both duplicated and unique RDATAs. */ - knot_rrset_deep_copy(&test_rrset_array[TEST_RRSET_MERGE_UNIQUE1].rrset, - &merge_to); - knot_rrset_deep_copy(&test_rrset_array[TEST_RRSET_MERGE_RESULT1].rrset, - &merge_from); - assert(merge_to); - assert(merge_from); - - ret = knot_rrset_merge_sort(merge_to, merge_from, &merged, - &removed_rrs); - if (ret != KNOT_EOK) { - diag("Merge of identical RRSets failed.\n"); - return 0; - } - - if (!knot_rrset_equal(&test_rrset_array[TEST_RRSET_MERGE_RESULT1].rrset, - merge_from, - KNOT_RRSET_COMPARE_WHOLE)) { - diag("Merge corrupted second RRSet.\n"); - return 0; - } - - if (!knot_rrset_equal(&test_rrset_array[TEST_RRSET_MERGE_RESULT1].rrset, - merge_to, - KNOT_RRSET_COMPARE_WHOLE)) { - diag("Merge did not create correct RDATA.\n"); - return 0; - } - - knot_rrset_deep_free(&merge_to, 1, 1); - knot_rrset_deep_free(&merge_from, 1, 1); - - return 1; -} - -static int test_rrset_equal() -{ - /* Test pointer comparison. */ - int ret = knot_rrset_equal((knot_rrset_t *)0xdeadbeef, - (knot_rrset_t *)0xdeadbeef, - KNOT_RRSET_COMPARE_PTR); - if (!ret) { - diag("Pointer comparison failed (1).\n"); - return 0; - } - - ret = knot_rrset_equal((knot_rrset_t *)0xdeadbeef, - (knot_rrset_t *)0xcafebabe, - KNOT_RRSET_COMPARE_PTR); - if (ret) { - diag("Pointer comparison failed (0).\n"); - return 0; - } - - /* Create equal RRSets. */ - knot_rrset_t *rrs1 = NULL; - knot_rrset_deep_copy(&test_rrset_array[TEST_RRSET_A_GT].rrset, - &rrs1); - knot_rrset_t *rrs2 = &test_rrset_array[TEST_RRSET_A_GT].rrset; - /* Test header comparison. */ - ret = knot_rrset_equal(rrs1, rrs2, KNOT_RRSET_COMPARE_HEADER); - if (!ret) { - diag("Header comparison failed (Header equal).\n"); - knot_rrset_deep_free(&rrs1, 1, 1); - return 0; - } - /* Change DNAME. */ - knot_rrset_set_owner(rrs1, test_dnames[4]); - ret = knot_rrset_equal(rrs1, rrs2, KNOT_RRSET_COMPARE_HEADER); - if (ret) { - char *owner1 = knot_dname_to_str(rrs1->owner); - char *owner2 = knot_dname_to_str(rrs2->owner); - diag("Header comparison failed " - "(DNAMEs different (%s %s), but ret=%d).\n", owner1, - owner2, ret); - rrs1->owner = test_dnames[0]; - knot_rrset_deep_free(&rrs1, 1, 1); - free(owner1); - free(owner2); - return 0; - } - rrs1->owner = test_dnames[0]; - /* Change CLASS. */ - rrs1->rclass = KNOT_CLASS_CH; - ret = knot_rrset_equal(rrs1, rrs2, KNOT_RRSET_COMPARE_HEADER); - if (ret) { - diag("Header comparison failed (CLASSEs different).\n"); - knot_rrset_deep_free(&rrs1, 1, 1); - return 0; - } - rrs1->rclass = KNOT_CLASS_IN; - - /* Test whole comparison. */ - ret = knot_rrset_equal(rrs1, rrs2, KNOT_RRSET_COMPARE_WHOLE); - if (!ret) { - diag("Whole comparison failed (Same RRSets).\n"); - knot_rrset_deep_free(&rrs1, 1, 1); - return 0; - } - - rrs2 = &test_rrset_array[TEST_RRSET_A_LESS].rrset; - ret = knot_rrset_equal(rrs1, rrs2, KNOT_RRSET_COMPARE_WHOLE); - if (ret) { - diag("Whole comparison failed (Different RRSets).\n"); - knot_rrset_deep_free(&rrs1, 1, 1); - return 0; - } - - knot_rrset_deep_free(&rrs1, 1, 1); - - return 1; -} - -static int test_rrset_rdata_equal() -{ - /* Equal - raw data only. */ - knot_rrset_t *rrset1 = &test_rrset_array[TEST_RRSET_A_LESS].rrset; - knot_rrset_t *rrset2 = &test_rrset_array[TEST_RRSET_A_LESS].rrset; - if (!knot_rrset_rdata_equal(rrset1, rrset2)) { - diag("rrset_rdata_equal() returned wrong " - "value, should be 1. (raw data) %d %d\n", - rrset1->type, rrset2->type); - return 0; - } - - /* Equal - DNAME only. */ - rrset1 = &test_rrset_array[TEST_RRSET_NS_LESS].rrset; - rrset2 = &test_rrset_array[TEST_RRSET_NS_LESS].rrset; - if (!knot_rrset_rdata_equal(rrset1, rrset2)) { - diag("rrset_rdata_equal() returned wrong " - "value, should be 1. (DNAME only)\n"); - return 0; - } - - /* Equal - combination. */ - rrset1 = &test_rrset_array[TEST_RRSET_MX_BIN_LESS].rrset; - rrset2 = &test_rrset_array[TEST_RRSET_MX_BIN_LESS].rrset; - if (!knot_rrset_rdata_equal(rrset1, rrset2)) { - diag("rrset_rdata_equal() returned wrong " - "value, should be 1. (MX combination)\n"); - return 0; - } - - /* Equal - combination, different order. */ - rrset1 = &test_rrset_array[TEST_RRSET_MINFO_MULTIPLE1].rrset; - rrset2 = &test_rrset_array[TEST_RRSET_MINFO_MULTIPLE2].rrset; - if (!knot_rrset_rdata_equal(rrset1, rrset2)) { - diag("rrset_rdata_equal() returned wrong " - "value, should be 1. (MINFO - order, combination)\n"); - return 0; - } - - /* Not equal - second item missing. */ - rrset1 = &test_rrset_array[TEST_RRSET_MINFO_MULTIPLE1].rrset; - rrset2 = &test_rrset_array[TEST_RRSET_MINFO].rrset; - if (knot_rrset_rdata_equal(rrset1, rrset2)) { - diag("rrset_rdata_equal() returned wrong " - "value, should be 0. (MINFO - combination)\n"); - return 0; - } - - /* Other way around. */ - if (knot_rrset_rdata_equal(rrset2, rrset1)) { - diag("rrset_rdata_equal() returned wrong " - "value, should be 0. (combination)\n"); - return 0; - } - - /* Not equal - second item different. */ - - /* Other way around. */ - - /* Not equal - raw data only. */ - rrset1 = &test_rrset_array[TEST_RRSET_A_LESS].rrset; - rrset2 = &test_rrset_array[TEST_RRSET_A_GT].rrset; - if (knot_rrset_rdata_equal(rrset1, rrset2) == 1) { - diag("rrset_rdata_equal() returned wrong " - "value, should be 0. (raw data only)\n"); - return 0; - } - - /* Not equal - raw data only. */ - if (knot_rrset_rdata_equal(rrset2, rrset1) == 1) { - diag("rrset_rdata_equal() returned wrong " - "value, should be 0. (raw data only)\n"); - return 0; - } - - /* Not equal - DNAME only. */ - rrset1 = &test_rrset_array[TEST_RRSET_NS_LESS].rrset; - rrset2 = &test_rrset_array[TEST_RRSET_NS_GT].rrset; - if (knot_rrset_rdata_equal(rrset1, rrset2) == 1) { - diag("rrset_rdata_equal() returned wrong " - "value, should be 0. (DNAME only)\n"); - return 0; - } - - /* Not equal - DNAME only. */ - if (knot_rrset_rdata_equal(rrset2, rrset1) == 1) { - diag("rrset_rdata_equal() returned wrong " - "value, should be 0. (DNAME only)\n"); - return 0; - } - - /* Not equal - combination, difference in binary part. */ - rrset1 = &test_rrset_array[TEST_RRSET_MX_BIN_LESS].rrset; - rrset2 = &test_rrset_array[TEST_RRSET_MX_BIN_GT].rrset; - if (knot_rrset_rdata_equal(rrset1, rrset2) == 1) { - diag("rrset_rdata_equal() returned wrong " - "value, should be 0. (combination)\n"); - return 0; - } - - /* Not equal - combination, difference in binary part. */ - if (knot_rrset_rdata_equal(rrset2, rrset1) == 1) { - diag("rrset_rdata_equal() returned wrong " - "value, should be 0. (combination)\n"); - return 0; - } - - /* Not equal - combination, difference in DNAME part. */ - rrset1 = &test_rrset_array[TEST_RRSET_MX_DNAME_LESS].rrset; - rrset2 = &test_rrset_array[TEST_RRSET_MX_DNAME_GT].rrset; - if (knot_rrset_rdata_equal(rrset1, rrset2) == 1) { - diag("rrset_rdata_equal() returned wrong " - "value, should be 0. (combination)\n"); - return 0; - } - - /* Not equal - combination, difference in DNAME part. */ - if (knot_rrset_rdata_equal(rrset2, rrset1) == 1) { - diag("rrset_rdata_equal() returned wrong " - "value, should be 0 (combination)\n"); - return 0; - } - - return 1; -} - -static int test_rrset_next_dname() -{ - /* Same test as in above, but we'll use multiple RRs within one SET. */ - knot_rrset_t *rrset = &test_rrset_array[TEST_RRSET_MINFO_MULTIPLE1].rrset; - knot_dname_t *extracted_dnames[4]; - extracted_dnames[0] = test_dnames[0]; - extracted_dnames[1] = test_dnames[1]; - extracted_dnames[2] = test_dnames[2]; - extracted_dnames[3] = test_dnames[3]; - knot_dname_t **dname = NULL; - int i = 0; - while ((dname = knot_rrset_get_next_dname(rrset, dname))) { - if (!knot_dname_is_equal(extracted_dnames[i], *dname)) { - diag("Got wrong DNAME from RDATA. on index %d\n", i); - char *ext_name = knot_dname_to_str(extracted_dnames[i]); - char *act_name = knot_dname_to_str(*dname); - diag("DNAME should be %s, but was %s (%p - %p)\n", - ext_name, act_name, extracted_dnames[i], *dname); - free(ext_name); - free(act_name); - return 0; - } - i++; - } - - if (i != 4) { - diag("Not all DNAMEs were extracted (%d out of 4).\n", - i); - return 0; - } - - /* Now try NS. */ - rrset = &test_rrset_array[TEST_RRSET_NS_LESS].rrset; - dname = NULL; - dname = knot_rrset_get_next_dname(rrset, dname); - if (dname == NULL || !knot_dname_is_equal(*dname, test_dnames[TEST_DNAME_GENERIC])) { - diag("Got wrong DNAME from NS RDATA. Was %p, should be %p \n", - dname ? *dname: NULL, test_dnames[TEST_DNAME_GENERIC]); - return 0; - } - dname = knot_rrset_get_next_dname(rrset, dname); - if (dname != NULL) { - diag("Got DNAME from RRSet even though all had been extracted previously. (NS)\n"); - return 0; - } - /* Now try MX. */ - rrset = &test_rrset_array[TEST_RRSET_MX_BIN_GT].rrset; - dname = NULL; - dname = knot_rrset_get_next_dname(rrset, dname); - if (dname == NULL || !knot_dname_is_equal(*dname, test_dnames[1])) { - diag("Got wrong DNAME from MX RDATA.\n"); - return 0; - } - dname = knot_rrset_get_next_dname(rrset, dname); - if (dname != NULL) { - diag("Got DNAME from RRSet even though all had been extracted previously. (MX)\n"); - return 0; - } - - /* Try writes into DNAMEs you've gotten. */ - rrset = NULL; - knot_rrset_deep_copy(&test_rrset_array[TEST_RRSET_MINFO_MULTIPLE1].rrset, - &rrset); - dname = NULL; - i = 4; - while ((dname = knot_rrset_get_next_dname(rrset, dname))) { - knot_dname_free(dname); - memcpy(dname, &test_dnames[i], sizeof(knot_dname_t *)); - i++; - } - - if (i != 8) { - diag("Not all DNAMEs were traversed (%d).\n", i); - knot_rrset_deep_free(&rrset, 1, 1); - return 0; - } - - knot_dname_t **dname_read = NULL; - i = 4; - while ((dname_read = knot_rrset_get_next_dname(rrset, - dname_read))) { - if (*dname_read != test_dnames[i]) { - diag("Rewriting of DNAMEs in RDATA was " - "not successful.\n"); - knot_rrset_deep_free(&rrset, 1, 1); - return 0; - } - i++; - } - - if (i != 8) { - diag("Not all DNAMEs were traversed (%d).\n", i); - knot_rrset_deep_free(&rrset, 1, 1); - return 0; - } - - knot_rrset_deep_free(&rrset, 1, 1); - - return 1; -} - -static int test_rrset_find_pos() -{ - /* Create some mockup TXT RRSets. */ - knot_rrset_t *rrset_source = knot_rrset_new(test_dnames[0], KNOT_RRTYPE_TXT, - KNOT_CLASS_IN, 3600); - uint8_t *mock_data = (uint8_t *)"cafebabebadcafecafecafecafe"; - /* Test removal of two exactly same items. */ - uint8_t *rdata = knot_rrset_create_rdata(rrset_source, - strlen((char *)mock_data)); - memcpy(rdata, mock_data, strlen((char *)mock_data)); - knot_rrset_t *rrset_find_in = NULL; - knot_rrset_deep_copy(rrset_source, &rrset_find_in); - rdata = knot_rrset_create_rdata(rrset_source, 10); - memcpy(rdata, mock_data ,10); - size_t rr_pos = 0; - int ret = knot_rrset_find_rr_pos(rrset_source, rrset_find_in, 0, &rr_pos); - if (ret != KNOT_EOK) { - knot_rrset_deep_free(&rrset_source, 1, 1); - knot_rrset_deep_free(&rrset_find_in, 1, 1); - diag("RR was not found, even though it should have been."); - return 0; - } - if (rr_pos != 0) { - knot_rrset_deep_free(&rrset_source, 1, 1); - knot_rrset_deep_free(&rrset_find_in, 1, 1); - diag("Wrong index returned. Should be 0, was %zu", rr_pos); - return 0; - } - - /* Add second RR. */ - knot_rrset_deep_free(&rrset_find_in, 1, 1); - knot_rrset_shallow_copy(rrset_source, &rrset_find_in); - /* Reset RRSet. */ - rrset_find_in->rdata = NULL; - rrset_find_in->rdata_indices = NULL; - rrset_find_in->rdata_count = 0; - - rdata = knot_rrset_create_rdata(rrset_find_in, 10); - memcpy(rdata, mock_data ,10); - ret = knot_rrset_find_rr_pos(rrset_source, rrset_find_in, 0, &rr_pos); - if (ret != KNOT_EOK) { - diag("RR was not found, even though it should have been."); - return 0; - } - if (rr_pos != 1) { - diag("Wrong index returned. Should be 1, was %zu", rr_pos); - return 0; - } - - knot_rrset_deep_free(&rrset_source, 1, 1); - knot_rrset_deep_free(&rrset_find_in, 1, 1); - - return 1; -} - -static int test_rrset_remove_rr() -{ - /* Remove RR and test that the returned data were OK. */ - - /* Create some mockup TXT RRSets. */ - knot_rrset_t *rrset_source = knot_rrset_new(test_dnames[0], KNOT_RRTYPE_TXT, - KNOT_CLASS_IN, 3600); - uint8_t *mock_data = (uint8_t *)"cafebabebadcafecafecafecafe"; - /* Test removal of two exactly same items. */ - uint8_t *rdata = knot_rrset_create_rdata(rrset_source, - strlen((char *)mock_data)); - memcpy(rdata, mock_data, strlen((char *)mock_data)); - rdata = knot_rrset_create_rdata(rrset_source, 10); - memcpy(rdata, mock_data ,10); - knot_rrset_t *rrset_dest = NULL; - /* Create copy. */ - knot_rrset_deep_copy(rrset_source, &rrset_dest); - rdata = knot_rrset_create_rdata(rrset_dest, 16); - memcpy(rdata, "foobarfoobarfoo", 16); - knot_rrset_t *returned_rr = NULL; - int ret = knot_rrset_remove_rr_using_rrset(rrset_dest, rrset_source, &returned_rr, 0); - if (ret != KNOT_EOK) { - diag("Could not remove"); - knot_rrset_deep_free(&rrset_source, 1, 1); - knot_rrset_deep_free(&returned_rr, 1, 1); - return 0; - } - -// diag("Returned\n"); -// knot_rrset_dump(returned_rr); -// diag("Source\n"); -// knot_rrset_dump(rrset_source); -// diag("Destinantion\n"); -// knot_rrset_dump(rrset_dest); - - /* Only one RR within RRSet, needs to be the same. */ - if (!knot_rrset_equal(rrset_source, returned_rr, - KNOT_RRSET_COMPARE_WHOLE)) { - diag("Got wrong data in return rrset."); - knot_rrset_deep_free(&rrset_source, 1, 1); - knot_rrset_deep_free(&returned_rr, 1, 1); - return 0; - } - - knot_rrset_deep_free(&rrset_source, 1, 1); - knot_rrset_deep_free(&rrset_dest, 1, 1); - knot_rrset_deep_free(&returned_rr, 1, 1); - - return 1; -} - -static int knot_rrset_tests_count(int argc, char *argv[]) -{ - return 14; -} - -static int knot_rrset_tests_run(int argc, char *argv[]) -{ - int res = 0, - res_final = 1; - - create_test_dnames(); - create_test_rdata(); - create_test_rrsets(); - - res = test_rrset_new(); - ok(res, "rrset: create"); - res_final *= res; - - res = test_rrset_create_rdata(); - ok(res, "rrset: create_rdata"); - res_final *= res; - - res = test_rrset_get_rdata(); - ok(res, "rrset: get rdata"); - res_final *= res; - - res = test_rrset_equal(); - ok(res, "rrset: rrset_equal"); - res_final *= res; - - res = test_rrset_rdata_equal(); - ok(res, "rrset: rrset_rdata_equal"); - - res = test_rrset_shallow_copy(); - ok(res, "rrset: shallow copy"); - res_final *= res; - - res = test_rrset_deep_copy(); - ok(res, "rrset: deep copy"); - res_final *= res; - - res = test_rrset_to_wire(); - ok(res, "rrset: to wire"); - res_final *= res; - - res = test_rrset_rdata_item_size(); - ok(res, "rrset: rdata_item_size"); - res_final *= res; - - res = test_rrset_merge(); - ok(res, "rrset: merge"); - res_final *= res; - - res = test_rrset_merge_sort(); - ok(res, "rrset: merge + sort"); - res_final *= res; - - res = test_rrset_next_dname(); - ok(res, "rrset: next dname"); - res_final *= res; - - res = test_rrset_remove_rr(); - ok(res, "rrset: remove rr"); - - res = test_rrset_find_pos(); - ok(res, "rrset: find pos"); - res_final *= res; - - return res_final; -} -#endif diff --git a/src/tests/libknot/rrset_tests.h b/src/tests/libknot/rrset_tests.h deleted file mode 100644 index b0787d6939..0000000000 --- a/src/tests/libknot/rrset_tests.h +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ -/*! - * \file rrset_tests.h - * - * \author Jan Kadlec <jan.kadlec@nic.cz> - * - * Contains unit tests for RRSet (knot_rrset_t) and its API. - * - * Contains tests for: - * - - */ -#ifndef _KNOTD_RRSET_TESTS_H_ -#define _KNOTD_RRSET_TESTS_H_ - -#include "common/libtap/tap_unit.h" - -/* Unit API. */ -unit_api rrset_tests_api; - -#endif /* _KNOTD_RRSET_TESTS_H_ */ diff --git a/src/tests/libknot/wire_tests.c b/src/tests/libknot/wire_tests.c deleted file mode 100644 index 51969ca8aa..0000000000 --- a/src/tests/libknot/wire_tests.c +++ /dev/null @@ -1,58 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <config.h> -#include "tests/libknot/wire_tests.h" -#include "libknot/util/utils.h" - -static int wire_tests_count(int argc, char *argv[]); -static int wire_tests_run(int argc, char *argv[]); - -unit_api wire_tests_api = { - "Wire", - &wire_tests_count, - &wire_tests_run -}; - -#define write_test(size, value, ...) { \ - const uint8_t expect[] = { __VA_ARGS__ }; \ - uint8_t wdata[sizeof(expect)] = { 0x00 }; \ - knot_wire_write_u ## size(wdata, value); \ - ok(memcmp(wdata, expect, sizeof(expect)) == 0, "%d-bit write", size); \ -} - -static int wire_tests_count(int argc, char *argv[]) -{ - return 8; -} - -static int wire_tests_run(int argc, char *argv[]) -{ - const uint8_t rdata[] = { 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; - - ok(knot_wire_read_u16(rdata) == 0x8899, "16-bit read"); - ok(knot_wire_read_u32(rdata) == 0x8899aabb, "32-bit read"); - ok(knot_wire_read_u48(rdata) == 0x8899aabbccdd, "48-bit read"); - ok(knot_wire_read_u64(rdata) == 0x8899aabbccddeeff, "64-bit read"); - - write_test(16, 0x1122, 0x11, 0x22); - write_test(32, 0x66778899, 0x66, 0x77, 0x88, 0x99); - write_test(48, 0xbbccdd778899, 0xbb, 0xcc, 0xdd, 0x77, 0x88, 0x99); - write_test(64, 0xbbccddee66778899, 0xbb, 0xcc, 0xdd, 0xee, - 0x66, 0x77, 0x88, 0x99); - - return 0; -} diff --git a/src/tests/libknot/wire_tests.h b/src/tests/libknot/wire_tests.h deleted file mode 100644 index 37e038d45a..0000000000 --- a/src/tests/libknot/wire_tests.h +++ /dev/null @@ -1,24 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef _KNOTD_WIRE_TESTS_ -#define _KNOTD_WIRE_TESTS_ - -#include "common/libtap/tap_unit.h" - -unit_api wire_tests_api; - -#endif diff --git a/src/tests/libknot/ztree_tests.c b/src/tests/libknot/ztree_tests.c deleted file mode 100644 index 0a9c9475e6..0000000000 --- a/src/tests/libknot/ztree_tests.c +++ /dev/null @@ -1,135 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <config.h> -#include "tests/libknot/ztree_tests.h" -#include "libknot/zone/zone-tree.h" - -#define NCOUNT 4 -static knot_dname_t* NAME[NCOUNT]; -static knot_node_t NODE[NCOUNT]; -static knot_dname_t* ORDER[NCOUNT]; -static void ztree_init_data() -{ - NAME[0] = knot_dname_from_str(".", 1); - NAME[1] = knot_dname_from_str("master.ac.", 10); - NAME[2] = knot_dname_from_str("ac.", 3); - NAME[3] = knot_dname_from_str("ns.", 3); - - knot_dname_t *order[NCOUNT] = { - NAME[0], NAME[2], NAME[1], NAME[3] - }; - memcpy(ORDER, order, NCOUNT * sizeof(knot_dname_t*)); - - for (unsigned i = 0; i < NCOUNT; ++i) { - memset(NODE + i, 0, sizeof(knot_node_t)); - NODE[i].owner = NAME[i]; - NODE[i].prev = NODE + ((NCOUNT + i - 1) % NCOUNT); - NODE[i].rrset_count = 1; /* required for ordered search */ - } -} - -static void ztree_free_data() -{ - for (unsigned i = 0; i < NCOUNT; ++i) - knot_dname_free(NAME + i); -} - -struct ztree_iter { - int ret; - unsigned i; -}; - -static void ztree_iter_data(knot_node_t **node, void *data) -{ - struct ztree_iter *it = (struct ztree_iter*)data; - knot_dname_t *owner = (*node)->owner; - if (owner != ORDER[it->i]) { - it->ret = KNOT_ERROR; - char *exp_s = knot_dname_to_str(ORDER[it->i]); - char *owner_s = knot_dname_to_str(owner); - diag("ztree: at index: %u expected '%s' got '%s'\n", it->i, exp_s, owner_s); - free(exp_s); - free(owner_s); - } - ++it->i; -} - -static int ztree_tests_count(int argc, char *argv[]); -static int ztree_tests_run(int argc, char *argv[]); - -unit_api ztree_tests_api = { - "zone tree", - &ztree_tests_count, - &ztree_tests_run -}; - -static int ztree_tests_count(int argc, char *argv[]) -{ - return 5; -} - -static int ztree_tests_run(int argc, char *argv[]) -{ - ztree_init_data(); - - /* 1. create test */ - knot_zone_tree_t* t = knot_zone_tree_create(); - ok(t != NULL, "ztree: created"); - - /* 2. insert test */ - unsigned passed = 1; - for (unsigned i = 0; i < NCOUNT; ++i) { - if (knot_zone_tree_insert(t, NODE + i) != KNOT_EOK) { - passed = 0; - break; - } - } - ok(passed, "ztree: insertion"); - - /* 3. check data test */ - passed = 1; - const knot_node_t *node = NULL; - for (unsigned i = 0; i < NCOUNT; ++i) { - int r = knot_zone_tree_find(t, NAME[i], &node); - if (r != KNOT_EOK || node != NODE + i) { - passed = 0; - break; - } - } - ok(passed, "ztree: lookup"); - - /* heal index for ordered lookup */ - hattrie_build_index(t); - - /* 4. ordered lookup */ - passed = 1; - node = NULL; - const knot_node_t *prev = NULL; - knot_dname_t *tmp_dn = knot_dname_from_str("z.ac.", 5); - knot_zone_tree_find_less_or_equal(t, tmp_dn, &node, &prev); - knot_dname_free(&tmp_dn); - ok(prev == NODE + 1, "ztree: ordered lookup"); - - /* 5. ordered traversal */ - struct ztree_iter it = { KNOT_EOK, 0 }; - knot_zone_tree_apply_inorder(t, ztree_iter_data, &it); - ok (it.ret == KNOT_EOK, "ztree: ordered traversal"); - - knot_zone_tree_free(&t); - ztree_free_data(); - return 0; -} diff --git a/src/tests/libknot/ztree_tests.h b/src/tests/libknot/ztree_tests.h deleted file mode 100644 index 5362eebbe4..0000000000 --- a/src/tests/libknot/ztree_tests.h +++ /dev/null @@ -1,24 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef _KNOT_ZTREE_TESTS_ -#define _KNOT_ZTREE_TESTS_ - -#include "common/libtap/tap_unit.h" - -unit_api ztree_tests_api; - -#endif diff --git a/src/tests/unittests_main.c b/src/tests/unittests_main.c deleted file mode 100644 index 5513fc19d0..0000000000 --- a/src/tests/unittests_main.c +++ /dev/null @@ -1,110 +0,0 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <config.h> -#include "knot/knot.h" -#include "common/libtap/tap_unit.h" - -// Units to test -#include "tests/common/slab_tests.h" -#include "tests/common/hattrie_tests.h" -#include "tests/common/events_tests.h" -#include "tests/common/acl_tests.h" -#include "tests/common/fdset_tests.h" -#include "tests/common/base64_tests.h" -#include "tests/common/base32hex_tests.h" -#include "tests/common/descriptor_tests.h" -#include "tests/knot/dthreads_tests.h" -#include "tests/knot/journal_tests.h" -#include "tests/knot/server_tests.h" -#include "tests/knot/conf_tests.h" -#include "tests/knot/rrl_tests.h" -#include "tests/libknot/wire_tests.h" -#include "tests/libknot/dname_tests.h" -#include "tests/libknot/ztree_tests.h" -#include "tests/libknot/dnssec_keys_tests.h" -#include "tests/libknot/dnssec_nsec3_tests.h" -#include "tests/libknot/dnssec_sign_tests.h" -#include "tests/libknot/dnssec_zone_nsec_tests.h" -#include "tests/libknot/rrset_tests.h" - -// Run all loaded units -int main(int argc, char *argv[]) -{ - // Open log - log_init(); - log_levels_set(LOGT_SYSLOG, LOG_ANY, 0); - log_levels_set(LOGT_STDERR, LOG_ANY, 0); - log_levels_set(LOGT_STDOUT, LOG_ANY, LOG_MASK(LOG_DEBUG)); - - // Build test set - unit_api *tests[] = { - /* Core data structures. */ - &journal_tests_api, //! Journal unit - &slab_tests_api, //! SLAB allocator unit - &hattrie_tests_api, //! HAT trie unit - &dthreads_tests_api, //! DThreads testing unit - &events_tests_api, //! Events testing unit - &acl_tests_api, //! ACLs - &fdset_tests_api, //! FDSET polling wrapper - &base64_tests_api, //! Base64 encoding - &base32hex_tests_api, //! Base32hex encoding - &descriptor_tests_api, //! RR descriptors - - /* Server parts. */ - &conf_tests_api, //! Configuration parser tests - &server_tests_api, //! Server unit - &rrl_tests_api, //! RRL tests - - /* Libknot library. */ - &wire_tests_api, - &dname_tests_api, - &ztree_tests_api, - &dnssec_keys_tests_api, //! DNSSEC key manipulation. - &dnssec_nsec3_tests_api, //! DNSSEC NSEC3 operations. - &dnssec_sign_tests_api, //! DNSSEC signing/verification. - &dnssec_zone_nsec_tests_api, //! Zone NSEC functions. -// &rrset_tests_api, - - NULL - }; - - // Plan number of tests - int id = 0; - int test_count = 0; - note("Units:"); - while (tests[id] != NULL) { - note("- %s : %d tests", tests[id]->name, - tests[id]->count(argc, argv)); - test_count += tests[id]->count(argc, argv); - ++id; - } - - plan(test_count); - - // Run tests - id = 0; - while (tests[id] != NULL) { - diag("Testing unit: %s", tests[id]->name); - tests[id]->run(argc, argv); - ++id; - } - - log_close(); - - // Evaluate - return exit_status(); -} -- GitLab