Skip to content

Commit

Permalink
Move all the unit tests to /tests/<libname>/
Browse files Browse the repository at this point in the history
The unit tests are now using a common base, which means that
lib/dns/tests/ code now has to include lib/isc/include/isc/test.h and
link with lib/isc/test.c and lib/ns/tests has to include both libisc and
libdns parts.

Instead of cross-linking code between the directories, move the
/lib/<foo>/test.c to /tests/<foo>.c and /lib/<foo>/include/<foo>test.h
to /tests/include/tests/<foo>.h and create a single libtest.la
convenience library in /tests/.

At the same time, move the /lib/<foo>/tests/ to /tests/<foo>/ (but keep
it symlinked to the old location) and adjust paths accordingly.  In few
places, we are now using absolute paths instead of relative paths,
because the directory level has changed.  By moving the directories
under the /tests/ directory, the test-related code is kept in a single
place and we can avoid referencing files between libns->libdns->libisc
which is unhealthy because they live in a separate Makefile-space.

In the future, the /bin/tests/ should be merged to /tests/ and symlink
kept, and the /fuzz/ directory moved to /tests/fuzz/.
  • Loading branch information
oerdnj authored and each committed May 28, 2022
1 parent 63fe931 commit 2c3b2da
Show file tree
Hide file tree
Showing 206 changed files with 191 additions and 199 deletions.
8 changes: 2 additions & 6 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ PointerAlignment: Right
PointerBindsToType: false
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<isc/test.h>$'
Priority: 100
- Regex: '^<dns/test.h>$'
Priority: 101
- Regex: '^<ns/test.h>$'
Priority: 102
- Regex: '^<isc/'
Priority: 5
- Regex: '^<(pk11|pkcs11)/'
Expand All @@ -64,6 +58,8 @@ IncludeCategories:
Priority: 55
- Regex: '^".*"'
Priority: 99
- Regex: '^<tests/'
Priority: 100
- Regex: '<openssl/'
Priority: 1
- Regex: '<(mysql|protobuf-c)/'
Expand Down
8 changes: 2 additions & 6 deletions .clang-format.headers
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ PointerAlignment: Right
PointerBindsToType: false
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<isc/test.h>$'
Priority: 100
- Regex: '^<dns/test.h>$'
Priority: 101
- Regex: '^<ns/test.h>$'
Priority: 102
- Regex: '^<isc/'
Priority: 2
- Regex: '^<dns/'
Expand All @@ -54,6 +48,8 @@ IncludeCategories:
Priority: 7
- Regex: '^(<[^/]*)/)'
Priority: 8
- Regex: '^<tests/'
Priority: 10
- Regex: '<[[:alnum:].]+>'
Priority: 1
- Regex: '".*"'
Expand Down
6 changes: 5 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ include $(top_srcdir)/Makefile.top

SUBDIRS = . lib doc bin fuzz

if HAVE_CMOCKA
SUBDIRS += tests
endif HAVE_CMOCKA

BUILT_SOURCES = bind.keys.h
CLEANFILES = bind.keys.h

Expand All @@ -12,7 +16,7 @@ dist_sysconf_DATA = bind.keys

.PHONY: doc

EXTRA_DIST = \
EXTRA_DIST = \
util/bindkeys.pl \
contrib \
CHANGES \
Expand Down
7 changes: 5 additions & 2 deletions Makefile.tests
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@

unit-local: check

if HAVE_CMOCKA
TESTS = $(check_PROGRAMS)
endif HAVE_CMOCKA

LOG_COMPILER = $(builddir)/../../unit-test-driver.sh
LOG_COMPILER = $(top_builddir)/tests/unit-test-driver.sh

AM_CFLAGS += \
-I$(top_srcdir)/tests/include \
$(TEST_CFLAGS)

AM_CPPFLAGS += \
$(CMOCKA_CFLAGS) \
-DNAMED_PLUGINDIR=\"$(pkglibdir)\" \
-DSKIPPED_TEST_EXIT_CODE=77 \
-DTESTS_DIR=\"$(abs_srcdir)\"

LDADD += \
$(top_builddir)/tests/libtest.la \
$(CMOCKA_LIBS)
17 changes: 9 additions & 8 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1581,14 +1581,15 @@ AC_CONFIG_FILES([doc/Makefile

# Unit Tests

AC_CONFIG_FILES([lib/isc/tests/Makefile
lib/dns/tests/Makefile
lib/ns/tests/Makefile
lib/irs/tests/Makefile
lib/isccfg/tests/Makefile])

AC_CONFIG_FILES([lib/unit-test-driver.sh],
[chmod +x lib/unit-test-driver.sh])
AC_CONFIG_FILES([tests/Makefile
tests/isc/Makefile
tests/dns/Makefile
tests/ns/Makefile
tests/irs/Makefile
tests/isccfg/Makefile])

AC_CONFIG_FILES([tests/unit-test-driver.sh],
[chmod +x tests/unit-test-driver.sh])

# System Tests

Expand Down
4 changes: 0 additions & 4 deletions lib/dns/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,3 @@ if HAVE_LMDB
libdns_la_CPPFLAGS += $(LMDB_CFLAGS)
libdns_la_LIBADD += $(LMDB_LIBS)
endif

if HAVE_CMOCKA
SUBDIRS = tests
endif
1 change: 1 addition & 0 deletions lib/dns/tests
4 changes: 0 additions & 4 deletions lib/irs/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,3 @@ libirs_la_LIBADD = \
libirs_la_LDFLAGS = \
$(AM_LDFLAGS) \
-release "$(PACKAGE_VERSION)"

if HAVE_CMOCKA
SUBDIRS = tests
endif
1 change: 1 addition & 0 deletions lib/irs/tests
4 changes: 0 additions & 4 deletions lib/isc/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,3 @@ libisc_la_CPPFLAGS += \
libisc_la_LIBADD += \
$(LIBXML2_LIBS)
endif HAVE_LIBXML2

if HAVE_CMOCKA
SUBDIRS = tests
endif
1 change: 1 addition & 0 deletions lib/isc/tests
4 changes: 0 additions & 4 deletions lib/isccfg/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,3 @@ libisccfg_la_LIBADD = \
libisccfg_la_LDFLAGS = \
$(AM_LDFLAGS) \
-release "$(PACKAGE_VERSION)"

if HAVE_CMOCKA
SUBDIRS = tests
endif
1 change: 1 addition & 0 deletions lib/isccfg/tests
4 changes: 0 additions & 4 deletions lib/ns/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,3 @@ libns_la_LIBADD = \
libns_la_LDFLAGS = \
$(AM_LDFLAGS) \
-release "$(PACKAGE_VERSION)"

if HAVE_CMOCKA
SUBDIRS = tests
endif
1 change: 1 addition & 0 deletions lib/ns/tests
1 change: 1 addition & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/unit-test-driver.sh
30 changes: 30 additions & 0 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
include $(top_srcdir)/Makefile.top

AM_CPPFLAGS += \
$(LIBISC_CFLAGS) \
$(LIBDNS_CFLAGS) \
$(LIBNS_CFLAGS) \
$(LIBUV_CFLAGS) \
-I$(top_srcdir)/lib/isc

LDADD += \
$(LIBISC_LIBS) \
$(LIBDNS_LIBS) \
$(LIBNS_LIBS)

SUBDIRS = . isc dns ns isccfg irs

check_LTLIBRARIES = libtest.la

noinst_libtest_ladir = .
noinst_libtest_la_HEADERS = \
include/tests/dns.h \
include/tests/isc.h \
include/tests/ns.h
libtest_la_SOURCES = \
$(noinst_libtest_la_HEADERS) \
dns.c \
isc.c \
ns.c

include $(top_srcdir)/Makefile.tests
2 changes: 1 addition & 1 deletion lib/dns/test.c → tests/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#include <dns/view.h>
#include <dns/zone.h>

#include <dns/test.h>
#include <tests/dns.h>

dns_zonemgr_t *zonemgr = NULL;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 5 additions & 10 deletions lib/dns/tests/Makefile.am → tests/dns/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,15 @@ AM_CPPFLAGS += \
$(LIBUV_CFLAGS) \
$(KRB5_CFLAGS) \
-DSRCDIR=\"$(abs_srcdir)\" \
-DBUILDDIR=\"$(abs_builddir)\"
-DBUILDDIR=\"$(abs_builddir)\" \
-I$(top_srcdir)/lib/isc \
-I$(top_srcdir)/lib/dns

LDADD += \
libdnstest.la \
$(LIBISC_LIBS) \
$(LIBUV_LIBS) \
$(LIBDNS_LIBS)

check_LTLIBRARIES = libdnstest.la
libdnstest_la_SOURCES = \
../../isc/test.c \
../../isc/include/isc/test.h \
../../dns/test.c \
../../dns/include/dns/test.h

check_PROGRAMS = \
acl_test \
db_test \
Expand Down Expand Up @@ -79,7 +73,8 @@ check_PROGRAMS += \

geoip_test_CPPFLAGS = \
$(AM_CPPFLAGS) \
$(MAXMINDDB_CFLAGS)
$(MAXMINDDB_CFLAGS) \
-DTEST_GEOIP_DATA=\"$(top_srcdir)/bin/tests/system/geoip2/data\"

geoip_test_LDADD = \
$(LDADD) \
Expand Down
2 changes: 1 addition & 1 deletion lib/dns/tests/acl_test.c → tests/dns/acl_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

#include <dns/acl.h>

#include <dns/test.h>
#include <tests/dns.h>

#define BUFLEN 255
#define BIGBUFLEN (70 * 1024)
Expand Down
2 changes: 1 addition & 1 deletion lib/dns/tests/db_test.c → tests/dns/db_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <dns/name.h>
#include <dns/rdatalist.h>

#include <dns/test.h>
#include <tests/dns.h>

#define BUFLEN 255
#define BIGBUFLEN (64 * 1024)
Expand Down
2 changes: 1 addition & 1 deletion lib/dns/tests/dbdiff_test.c → tests/dns/dbdiff_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <dns/journal.h>
#include <dns/name.h>

#include <dns/test.h>
#include <tests/dns.h>

#define BUFLEN 255
#define BIGBUFLEN (64 * 1024)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <dns/dbiterator.h>
#include <dns/name.h>

#include <dns/test.h>
#include <tests/dns.h>

#define BUFLEN 255
#define BIGBUFLEN (64 * 1024)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include <dns/rdataset.h>
#include <dns/rdatasetiter.h>

#include <dns/test.h>
#include <tests/dns.h>

static char tempname[11] = "dtXXXXXXXX";
static dns_db_t *db1 = NULL, *db2 = NULL;
Expand Down
4 changes: 2 additions & 2 deletions lib/dns/tests/dh_test.c → tests/dns/dh_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@

#include <dns/name.h>

#include "../dst_internal.h"
#include "dst_internal.h"

#include <dns/test.h>
#include <tests/dns.h>

static int
setup_test(void **state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include <dns/name.h>
#include <dns/view.h>

#include <dns/test.h>
#include <tests/dns.h>

uv_sem_t sem;

Expand Down
2 changes: 1 addition & 1 deletion lib/dns/tests/dns64_test.c → tests/dns/dns64_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <dns/rdatalist.h>
#include <dns/rdataset.h>

#include <dns/test.h>
#include <tests/dns.h>

static void
multiple_prefixes(void) {
Expand Down
10 changes: 5 additions & 5 deletions lib/dns/tests/dnstap_test.c → tests/dns/dnstap_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
#include <dns/dnstap.h>
#include <dns/view.h>

#include <dns/test.h>
#include <tests/dns.h>

#define TAPFILE "testdata/dnstap/dnstap.file"
#define TAPSOCK "testdata/dnstap/dnstap.sock"
#define TAPFILE TESTS_DIR "/testdata/dnstap/dnstap.file"
#define TAPSOCK TESTS_DIR "/testdata/dnstap/dnstap.sock"

#define TAPSAVED "testdata/dnstap/dnstap.saved"
#define TAPTEXT "testdata/dnstap/dnstap.text"
#define TAPSAVED TESTS_DIR "/testdata/dnstap/dnstap.saved"
#define TAPTEXT TESTS_DIR "/testdata/dnstap/dnstap.text"

static int
cleanup(void **state __attribute__((__unused__))) {
Expand Down
4 changes: 2 additions & 2 deletions lib/dns/tests/dst_test.c → tests/dns/dst_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@

#include <dst/dst.h>

#include "../dst_internal.h"
#include "dst_internal.h"

#include <dns/test.h>
#include <tests/dns.h>

static int
setup_test(void **state) {
Expand Down
7 changes: 2 additions & 5 deletions lib/dns/tests/geoip_test.c → tests/dns/geoip_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@

#include <dns/geoip.h>

#include "../geoip2.c"
#include "geoip2.c"

#include <dns/test.h>

/* Use GeoIP2 databases from the 'geoip2' system test */
#define TEST_GEOIP_DATA "../../../bin/tests/system/geoip2/data"
#include <tests/dns.h>

static dns_geoip_databases_t geoip;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

#include <dst/dst.h>

#include <dns/test.h>
#include <tests/dns.h>

dns_keytable_t *keytable = NULL;
dns_ntatable_t *ntatable = NULL;
Expand Down
2 changes: 1 addition & 1 deletion lib/dns/tests/master_test.c → tests/dns/master_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <dns/rdatalist.h>
#include <dns/rdataset.h>

#include <dns/test.h>
#include <tests/dns.h>

static void
nullmsg(dns_rdatacallbacks_t *cb, const char *fmt, ...) {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/dns/tests/name_test.c → tests/dns/name_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include <dns/fixedname.h>
#include <dns/name.h>

#include <dns/test.h>
#include <tests/dns.h>

/* Set to true (or use -v option) for verbose output */
static bool verbose = false;
Expand Down
Loading

0 comments on commit 2c3b2da

Please sign in to comment.