Skip to content
Snippets Groups Projects
Commit ae938d9d authored by Marek Vavrusa's avatar Marek Vavrusa
Browse files

Divided dnslib unit to submodules, fixed code compilation.

Added missing unit headers.

Commit refs #701.
parent 2c6747df
No related branches found
No related tags found
No related merge requests found
Showing
with 204 additions and 163 deletions
......@@ -118,21 +118,35 @@ src/knot/conf/conf.h
src/knot/conf/logconf.c
src/knot/conf/logconf.h
src/tests/common/da_tests.c
src/tests/common/da_tests.h
src/tests/common/skiplist_tests.c
src/tests/common/skiplist_tests.h
src/tests/common/slab_tests.c
src/tests/dnslib/dnslib_dname_tests.c
src/tests/dnslib/dnslib_edns_tests.c
src/tests/dnslib/dnslib_node_tests.c
src/tests/dnslib/dnslib_rdata_tests.c
src/tests/dnslib/dnslib_response_tests.c
src/tests/dnslib/dnslib_rrset_tests.c
src/tests/dnslib/dnslib_zone_tests.c
src/tests/dnslib/dnslib_tests.c
src/tests/common/slab_tests.h
src/tests/dnslib/dname_tests.c
src/tests/dnslib/dname_tests.h
src/tests/dnslib/edns_tests.c
src/tests/dnslib/edns_tests.h
src/tests/dnslib/node_tests.c
src/tests/dnslib/node_tests.h
src/tests/dnslib/rdata_tests.c
src/tests/dnslib/rdata_tests.h
src/tests/dnslib/response_tests.c
src/tests/dnslib/response_tests.h
src/tests/dnslib/rrset_tests.c
src/tests/dnslib/rrset_tests.h
src/tests/dnslib/zone_tests.c
src/tests/dnslib/zone_tests.h
src/tests/dnslib/zonedb_tests.c
src/tests/dnslib/zonedb_tests.h
src/tests/dnslib/cuckoo_tests.c
src/tests/dnslib/cuckoo_tests.h
src/tests/knot/dthreads_tests.c
src/tests/knot/dthreads_tests.h
src/tests/knot/conf_tests.c
src/tests/knot/conf_tests.h
src/tests/knot/server_tests.c
src/tests/knot/server_tests.h
src/tests/libtap/tap.c
src/tests/libtap/tap.h
src/tests/libtap/tap_unit.h
......
......@@ -47,6 +47,21 @@ knot_zcompile_SOURCES = \
unittests_SOURCES = \
tests/libtap/tap.c \
tests/common/da_tests.c \
tests/common/skiplist_tests.c \
tests/common/slab_tests.c \
tests/dnslib/cuckoo_tests.c \
tests/dnslib/dname_tests.c \
tests/dnslib/edns_tests.c \
tests/dnslib/node_tests.c \
tests/dnslib/rdata_tests.c \
tests/dnslib/response_tests.c \
tests/dnslib/rrset_tests.c \
tests/dnslib/zone_tests.c \
tests/dnslib/zonedb_tests.c \
tests/knot/conf_tests.c \
tests/knot/dthreads_tests.c \
tests/knot/server_tests.c \
tests/unittests_main.c
unittests_zcompile_SOURCES = \
......
#include "tests/tap_unit.h"
#include "tests/common/da_tests.h"
#include "common/dynamic-array.h"
#include <unistd.h>
#include <urcu.h>
......
#ifndef _KNOT_DA_TESTS_H_
#define _KNOT_DA_TESTS_H_
#include "tests/libtap/tap_unit.h"
/* Unit API. */
unit_api da_tests_api;
#endif /* _KNOT_DA_TESTS_H_ */
#include <time.h>
#include "tests/tap_unit.h"
#include "tests/common/skiplist_tests.h"
#include "common/skip-list.h"
static int skiplist_tests_count(int argc, char *argv[]);
......
#ifndef _KNOT_SKIPLIST_TESTS_H_
#define _KNOT_SKIPLIST_TESTS_H_
#include "tests/libtap/tap_unit.h"
/* Unit API. */
unit_api skiplist_tests_api;
#endif /* _KNOT_SKIPLIST_TESTS_H_ */
......@@ -3,8 +3,9 @@
#include <time.h>
#include <stdbool.h>
#include "tests/tap_unit.h"
#include "tests/common/slab_tests.h"
#include "common/slab/slab.h"
#include "knot/common.h"
/* Explicitly ask for symbols,
* as the constructor and desctructor
......@@ -102,7 +103,7 @@ static int slab_tests_run(int argc, char *argv[])
for(int i = 0; i < alloc_count; ++i) {
double roll = rand() / (double) RAND_MAX;
size_t bsize = roll * 2048;
bsize = max(bsize, 8);
bsize = MAX(bsize, 8);
if ((ptrs_i == 0) || (roll < 0.6)) {
void* m = slab_alloc_alloc(&alloc, bsize);
if (m == 0) {
......
#ifndef _KNOT_SLAB_TESTS_H_
#define _KNOT_SLAB_TESTS_H_
#include "tests/libtap/tap_unit.h"
/* Unit API. */
unit_api slab_tests_api;
#endif /* _KNOT_SLAB_TESTS_H_ */
#include "tests/tap_unit.h"
#define CT_TEST_REHASH
#include <time.h>
#include <assert.h>
#include "tests/dnslib/cuckoo_tests.h"
#include "dnslib/hash/cuckoo-hash-table.h"
#define CT_TEST_REHASH
//#define CK_TEST_DEBUG
//#define CK_TEST_LOOKUP
//#define CK_TEST_OUTPUT
......
#ifndef _KNOT_CUCKOO_TESTS_H_
#define _KNOT_CUCKOO_TESTS_H_
#include "tests/libtap/tap_unit.h"
/* Unit API. */
unit_api cuckoo_tests_api;
#endif /* _KNOT_CUCKOO_TESTS_H_ */
#include <string.h>
#include <assert.h>
#include "tests/dnslib/dname_tests.h"
#include "dnslib/dname.h"
#include "dnslib/node.h"
......@@ -9,7 +10,7 @@ static int dnslib_dname_tests_run(int argc, char *argv[]);
/*! Exported unit API.
*/
unit_api dnslib_dname_tests_api = {
unit_api dname_tests_api = {
"DNS library - dname", //! Unit name
&dnslib_dname_tests_count, //! Count scheduled tests
&dnslib_dname_tests_run //! Run scheduled tests
......
#ifndef _KNOT_DNAME_TESTS_H_
#define _KNOT_DNAME_TESTS_H_
#include "tests/libtap/tap_unit.h"
/* Unit API. */
unit_api dname_tests_api;
#endif /* _KNOT_DNAME_TESTS_H_ */
#include "tests/tap_unit.h"
#include "tests/dnslib/dnslib_dname_tests.c"
#include "tests/dnslib/dnslib_rdata_tests.c"
#include "tests/dnslib/dnslib_node_tests.c"
#include "tests/dnslib/dnslib_rrset_tests.c"
#include "tests/dnslib/dnslib_zone_tests.c"
#include "tests/dnslib/dnslib_response_tests.c"
#include "tests/dnslib/dnslib_edns_tests.c"
static int dnslib_tests_count(int argc, char *argv[]);
static int dnslib_tests_run(int argc, char *argv[]);
/*! Exported unit API.
*/
unit_api dnslib_tests_api = {
"DNS library", //! Unit name
&dnslib_tests_count, //! Count scheduled tests
&dnslib_tests_run //! Run scheduled tests
};
/*! \todo Implement theese tests into API.
*/
/*! This helper routine should report number of
* scheduled tests for given parameters.
*/
static int dnslib_tests_count(int argc, char *argv[])
{
return dnslib_dname_tests_count(argc, argv)
+ dnslib_rdata_tests_count(argc, argv)
+ dnslib_rrset_tests_count(argc, argv)
+ dnslib_node_tests_count(argc, argv)
+ dnslib_zone_tests_count(argc, argv)
+ dnslib_response_tests_count(argc, argv)
+ dnslib_edns_tests_count(argc, argv);
}
/*! Run all scheduled tests for given parameters.
*/
static int dnslib_tests_run(int argc, char *argv[])
{
int res = 0;
int rrset_tests = dnslib_rrset_tests_count(argc, argv);
int node_tests = dnslib_node_tests_count(argc, argv);
int zone_tests = dnslib_zone_tests_count(argc, argv);
int response_tests = dnslib_response_tests_count(argc, argv);
int edns_tests = dnslib_edns_tests_count(argc, argv);
note("Testing module: dname");
res = dnslib_dname_tests_run(argc, argv);
note("Testing module: rdata");
res *= dnslib_rdata_tests_run(argc, argv);
skip(!res, rrset_tests + node_tests + zone_tests + response_tests);
note("Testing module: rrset");
res = dnslib_rrset_tests_run(argc, argv);
skip(!res, node_tests + zone_tests + response_tests);
note("Testing module: node");
res = dnslib_node_tests_run(argc, argv);
skip(!res, zone_tests);
note("Testing module: zone");
res = dnslib_zone_tests_run(argc, argv);
note("Testing module: response");
res = dnslib_response_tests_run(argc, argv);
skip(!res, edns_tests);
note("Testing module: edns");
res = dnslib_edns_tests_run(argc, argv);
endskip; // skipped edns
endskip; // skipped zone
endskip; // skipped node & zone
endskip; // skipped rrset & node & zone & response & edns
return res;
}
/*!
* \file dnslib_edns_tests.c
*
* \author Jan Kadlec <jan.kadlec@nic.cz>
*
* Contains unit tests for ENDS API
*
* Contains tests for:
* - ENDS API
*/
#include <assert.h>
#include "tests/dnslib/edns_tests.h"
#include "dnslib/dnslib-common.h"
#include "dnslib/edns.h"
static int dnslib_edns_tests_count(int argc, char *argv[]);
......@@ -16,7 +9,7 @@ static int dnslib_edns_tests_run(int argc, char *argv[]);
/*! Exported unit API.
*/
unit_api dnslib_edns_tests_api = {
unit_api edns_tests_api = {
"DNS library - EDNS", //! Unit name
&dnslib_edns_tests_count, //! Count scheduled tests
&dnslib_edns_tests_run //! Run scheduled tests
......
/*!
* \file dnslib_edns_tests.c
*
* \author Jan Kadlec <jan.kadlec@nic.cz>
*
* Contains unit tests for ENDS API
*
* Contains tests for:
* - ENDS API
*/
#ifndef _KNOT_EDNS_TESTS_H_
#define _KNOT_EDNS_TESTS_H_
#include "tests/libtap/tap_unit.h"
/* Unit API. */
unit_api edns_tests_api;
#endif /* _KNOT_EDNS_TESTS_H_ */
#include "tests/dnslib/node_tests.h"
#include "dnslib/dname.h"
#include "dnslib/node.h"
#include "dnslib/descriptor.h"
......@@ -7,7 +8,7 @@ static int dnslib_node_tests_run(int argc, char *argv[]);
/*! Exported unit API.
*/
unit_api dnslib_node_tests_api = {
unit_api node_tests_api = {
"DNS library - node", //! Unit name
&dnslib_node_tests_count, //! Count scheduled tests
&dnslib_node_tests_run //! Run scheduled tests
......
#ifndef _KNOT_NODE_TESTS_H_
#define _KNOT_NODE_TESTS_H_
#include "tests/libtap/tap_unit.h"
/* Unit API. */
unit_api node_tests_api;
#endif /* _KNOT_NODE_TESTS_H_ */
/*!
* \file dnslib_rdata_tests.c
*
* \author Lubos Slovak <lubos.slovak@nic.cz>
*
* Contains unit tests for RDATA (dnslib_rdata_t) and RDATA item
* (dnslib_rdata_item_t) structures.
*
* Contains tests for:
* - creating empty RDATA structure with or without reserved space.
* - setting RDATA items one-by-one
* - setting RDATA items all at once
*
* As for now, the tests use several (TEST_RDATAS) RDATA structures, each
* with different number of RDATA items (given by test_rdatas). These are all
* initialized to pointers derived from RDATA_ITEM_PTR (first is RDATA_ITEM_PTR,
* second RDATA_ITEM_PTR + 1, etc.). The functions only test if the pointer
* is set properly.
*
* \todo It may be better to test also some RDATAs with predefined contents,
* such as some numbers, some domain name, etc. For this purpose, we'd
* need RDATA descriptors (telling the types of each RDATA item within an
* RDATA).
*
* \todo It will be fine to test all possible output values of all functions,
* e.g. test whether dnslib_rdata_get_item() returns NULL when passed an
* illegal position, etc.
*/
#include <stdlib.h>
#include <assert.h>
#include "tests/dnslib/rdata_tests.h"
#include "dnslib/dnslib-common.h"
#include "dnslib/rdata.h"
#include "dnslib/descriptor.h"
#include "dnslib/utils.h"
#include "dnslib/error.h"
static const struct test_domain test_domains_ok[];
enum { TEST_DOMAINS_OK = 8 };
struct test_domain {
char *str;
char *wire;
uint size;
char *labels;
short label_count;
};
/*! \warning Do not change the order in those, if you want to test some other
* feature with new dname, add it at the end of these arrays.
*/
static const struct test_domain
test_domains_ok[TEST_DOMAINS_OK] = {
{ "abc.test.domain.com.", "\3abc\4test\6domain\3com", 21,
"\x0\x4\x9\x10", 4 },
{ "some.test.domain.com.", "\4some\4test\6domain\3com", 22,
"\x0\x5\xA\x11", 4 },
{ "xyz.test.domain.com.", "\3xyz\4test\6domain\3com", 21,
"\x0\x4\x9\x10", 4 },
{ "some.test.domain.com.", "\4some\4test\6domain\3com", 22,
"\x0\x5\xA\x11", 4 },
{ "test.domain.com.", "\4test\6domain\3com", 17,
"\x0\x5\xC", 3 },
{ ".", "\0", 1,
"", 0 },
{ "foo.bar.net.", "\3foo\3bar\3net", 13,
"\x0\x4\x8", 3},
{ "bar.net.", "\3bar\3net", 9,
"\x0\x4", 2}
};
static int dnslib_rdata_tests_count(int argc, char *argv[]);
static int dnslib_rdata_tests_run(int argc, char *argv[]);
/*! Exported unit API.
*/
unit_api dnslib_rdata_tests_api = {
unit_api rdata_tests_api = {
"DNS library - rdata", //! Unit name
&dnslib_rdata_tests_count, //! Count scheduled tests
&dnslib_rdata_tests_run //! Run scheduled tests
......
/*!
* \file dnslib_rdata_tests.c
*
* \author Lubos Slovak <lubos.slovak@nic.cz>
*
* Contains unit tests for RDATA (dnslib_rdata_t) and RDATA item
* (dnslib_rdata_item_t) structures.
*
* Contains tests for:
* - creating empty RDATA structure with or without reserved space.
* - setting RDATA items one-by-one
* - setting RDATA items all at once
*
* As for now, the tests use several (TEST_RDATAS) RDATA structures, each
* with different number of RDATA items (given by test_rdatas). These are all
* initialized to pointers derived from RDATA_ITEM_PTR (first is RDATA_ITEM_PTR,
* second RDATA_ITEM_PTR + 1, etc.). The functions only test if the pointer
* is set properly.
*
* \todo It may be better to test also some RDATAs with predefined contents,
* such as some numbers, some domain name, etc. For this purpose, we'd
* need RDATA descriptors (telling the types of each RDATA item within an
* RDATA).
*
* \todo It will be fine to test all possible output values of all functions,
* e.g. test whether dnslib_rdata_get_item() returns NULL when passed an
* illegal position, etc.
*/
#ifndef _KNOT_RDATA_TESTS_H_
#define _KNOT_RDATA_TESTS_H_
#include "tests/libtap/tap_unit.h"
/* Unit API. */
unit_api rdata_tests_api;
#endif /* _KNOT_RDATA_TESTS_H_ */
/*!
* \file dnslib_response_tests.c
*
* \author Jan Kadlec <jan.kadlec@nic.cz>
*
* Contains unit tests for response structure (dnslib_response_t) and its API.
*
* Contains tests for:
* - Response API
* - \todo
*/
#include <assert.h>
#include <inttypes.h>
......@@ -18,6 +6,8 @@
#endif
//#define RESP_TEST_DEBUG
#include "tests/dnslib/response_tests.h"
#include "dnslib/dnslib-common.h"
#include "dnslib/response.h"
#include "dnslib/rdata.h"
#include "dnslib/rrset.h"
......@@ -40,7 +30,7 @@ static int dnslib_response_tests_run(int argc, char *argv[]);
/*! Exported unit API.
*/
unit_api dnslib_response_tests_api = {
unit_api response_tests_api = {
"DNS library - response", //! Unit name
&dnslib_response_tests_count, //! Count scheduled tests
&dnslib_response_tests_run //! Run scheduled tests
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment