From 35d883a830af0284efafe94d1a6bd1c1ad04bae7 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 13 Mar 2017 13:52:51 +0100 Subject: [PATCH] rec: Run unit tests, split recursor-specific unit tests from the auth Some unit tests are common and will be run twice, once in the auth build and once in the rec one. This ensures that they will be run on rec-4.0.x and auth-4.0.x branches as well. --- build-scripts/travis.sh | 6 +- pdns/Makefile.am | 15 ---- pdns/recursordist/Makefile.am | 73 +++++++++++++++++++ pdns/recursordist/configure.ac | 1 + .../recursordist/m4/pdns_enable_unit_tests.m4 | 1 + pdns/recursordist/sha.hh | 1 - pdns/recursordist/test-arguments_cc.cc | 1 + pdns/recursordist/test-base32_cc.cc | 1 + pdns/recursordist/test-base64_cc.cc | 1 + pdns/recursordist/test-dns_random_hh.cc | 1 + pdns/recursordist/test-dnsname_cc.cc | 1 + pdns/recursordist/test-dnsparser_hh.cc | 1 + pdns/recursordist/test-dnsrecordcontent.cc | 1 + pdns/recursordist/test-dnsrecords_cc.cc | 1 + pdns/recursordist/test-iputils_hh.cc | 1 + pdns/recursordist/test-misc_hh.cc | 1 + pdns/recursordist/test-nmtree.cc | 1 + pdns/recursordist/test-rcpgenerator_cc.cc | 1 + pdns/recursordist/test-recpacketcache_cc.cc | 1 + pdns/recursordist/test-tsig.cc | 1 + pdns/recursordist/testrunner.cc | 31 ++++++++ 21 files changed, 125 insertions(+), 17 deletions(-) create mode 120000 pdns/recursordist/m4/pdns_enable_unit_tests.m4 delete mode 120000 pdns/recursordist/sha.hh create mode 120000 pdns/recursordist/test-arguments_cc.cc create mode 120000 pdns/recursordist/test-base32_cc.cc create mode 120000 pdns/recursordist/test-base64_cc.cc create mode 120000 pdns/recursordist/test-dns_random_hh.cc create mode 120000 pdns/recursordist/test-dnsname_cc.cc create mode 120000 pdns/recursordist/test-dnsparser_hh.cc create mode 120000 pdns/recursordist/test-dnsrecordcontent.cc create mode 120000 pdns/recursordist/test-dnsrecords_cc.cc create mode 120000 pdns/recursordist/test-iputils_hh.cc create mode 120000 pdns/recursordist/test-misc_hh.cc create mode 120000 pdns/recursordist/test-nmtree.cc create mode 120000 pdns/recursordist/test-rcpgenerator_cc.cc create mode 120000 pdns/recursordist/test-recpacketcache_cc.cc create mode 120000 pdns/recursordist/test-tsig.cc create mode 100644 pdns/recursordist/testrunner.cc diff --git a/build-scripts/travis.sh b/build-scripts/travis.sh index 6b314cb8b6..bbeb86fd37 100755 --- a/build-scripts/travis.sh +++ b/build-scripts/travis.sh @@ -357,7 +357,7 @@ install_recursor() { } install_dnsdist() { - # recursor test requirements / setup + # test requirements / setup run "sudo apt-get -qq --no-install-recommends install \ snmpd \ libsnmp-dev" @@ -399,6 +399,7 @@ build_recursor() { run "cd pdns-recursor-*" run "CFLAGS='-O1' CXXFLAGS='-O1' ./configure \ --prefix=$PDNS_RECURSOR_DIR \ + --enable-unit-tests \ --disable-silent-rules" run "make -k -j3" run "make install" @@ -553,6 +554,9 @@ test_recursor() { export PDNSRECURSOR="${PDNS_RECURSOR_DIR}/sbin/pdns_recursor" export DNSBULKTEST="/usr/bin/dnsbulktest" export RECCONTROL="${PDNS_RECURSOR_DIR}/bin/rec_control" + run "cd pdns/recursordist/pdns-recursor-*" + run "make -j 3 check" + run "cd ${TRAVIS_BUILD_DIR}" run "./build-scripts/test-recursor" export RECURSOR="${PDNSRECURSOR}" run "cd regression-tests" diff --git a/pdns/Makefile.am b/pdns/Makefile.am index 33b829ca5e..65482f5305 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -1131,8 +1131,6 @@ testrunner_SOURCES = \ packetcache.cc \ qtype.cc \ rcpgenerator.cc \ - recpacketcache.cc recpacketcache.hh \ - rec-protobuf.hh \ responsestats.cc \ responsestats-auth.cc \ sillyrecords.cc \ @@ -1155,7 +1153,6 @@ testrunner_SOURCES = \ test-nmtree.cc \ test-packetcache_cc.cc \ test-rcpgenerator_cc.cc \ - test-recpacketcache_cc.cc \ test-sha_hh.cc \ test-statbag_cc.cc \ test-tsig.cc \ @@ -1176,18 +1173,6 @@ testrunner_LDADD = \ $(RT_LIBS) \ $(LIBDL) -if HAVE_PROTOBUF -if HAVE_PROTOC -nodist_testrunner_SOURCES = \ - dnsmessage.pb.cc dnsmessage.pb.h - -testrunner_LDADD += \ - $(PROTOBUF_LIBS) - -recpacketcache.$(OBJEXT): dnsmessage.pb.cc -endif -endif - if PKCS11 testrunner_SOURCES += pkcs11signers.cc pkcs11signers.hh testrunner_LDADD += $(P11KIT1_LIBS) diff --git a/pdns/recursordist/Makefile.am b/pdns/recursordist/Makefile.am index ddfb76bf9b..c1738df56f 100644 --- a/pdns/recursordist/Makefile.am +++ b/pdns/recursordist/Makefile.am @@ -64,6 +64,16 @@ EXTRA_DIST = \ sbin_PROGRAMS = pdns_recursor bin_PROGRAMS = rec_control +if UNIT_TESTS +noinst_PROGRAMS = testrunner +TESTS_ENVIRONMENT = env BOOST_TEST_LOG_LEVEL=message SRCDIR='$(srcdir)' +TESTS=testrunner +else +check-local: + @echo "Unit tests are not enabled" + @echo "Run ./configure --enable-unit-tests" +endif + pdns_recursor_SOURCES = \ arguments.cc \ base32.cc base32.hh \ @@ -163,6 +173,64 @@ pdns_recursor_LDADD = \ pdns_recursor_LDFLAGS = $(AM_LDFLAGS) \ $(LIBCRYPTO_LDFLAGS) $(BOOST_CONTEXT_LDFLAGS) +testrunner_SOURCES = \ + arguments.cc \ + base32.cc \ + base64.cc base64.hh \ + dns.cc dns.hh \ + dnslabeltext.cc \ + dnsname.cc dnsname.hh \ + dnsparser.hh dnsparser.cc \ + dnsrecords.cc \ + dnssecinfra.cc \ + dnswriter.cc dnswriter.hh \ + ednsoptions.cc ednsoptions.hh \ + ednssubnet.cc ednssubnet.hh \ + gettime.cc gettime.hh \ + gss_context.cc gss_context.hh \ + iputils.cc iputils.hh \ + logger.cc logger.hh \ + misc.cc misc.hh \ + namespaces.hh \ + nsecrecords.cc \ + pdnsexception.hh \ + protobuf.cc protobuf.hh \ + qtype.cc qtype.hh \ + rcpgenerator.cc \ + recpacketcache.cc recpacketcache.hh \ + rec-protobuf.cc rec-protobuf.hh \ + responsestats.cc \ + sillyrecords.cc \ + sholder.hh \ + sstuff.hh \ + test-arguments_cc.cc \ + test-base32_cc.cc \ + test-base64_cc.cc \ + test-dnsrecordcontent.cc \ + test-dns_random_hh.cc \ + test-dnsname_cc.cc \ + test-dnsparser_hh.cc \ + test-dnsrecords_cc.cc \ + test-iputils_hh.cc \ + test-misc_hh.cc \ + test-nmtree.cc \ + test-rcpgenerator_cc.cc \ + test-recpacketcache_cc.cc \ + test-tsig.cc \ + testrunner.cc \ + unix_utility.cc \ + zoneparser-tng.cc zoneparser-tng.hh + +testrunner_LDFLAGS = \ + $(AM_LDFLAGS) \ + $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) \ + $(LIBCRYPTO_LDFLAGS) + +testrunner_LDADD = \ + $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) \ + $(LIBCRYPTO_LIBS) \ + $(RT_LIBS) + if BOTAN110 pdns_recursor_SOURCES += \ botan110signers.cc @@ -209,6 +277,11 @@ BUILT_SOURCES += dnsmessage.pb.cc pdns_recursor_LDADD += $(PROTOBUF_LIBS) nodist_pdns_recursor_SOURCES = dnsmessage.pb.cc dnsmessage.pb.h pdns_recursor.$(OBJEXT): dnsmessage.pb.cc + +nodist_testrunner_SOURCES = dnsmessage.pb.cc dnsmessage.pb.h +testrunner_LDADD += $(PROTOBUF_LIBS) +testrunner$(OBJEXT): dnsmessage.pb.cc + endif endif diff --git a/pdns/recursordist/configure.ac b/pdns/recursordist/configure.ac index e79af91b8c..7bca7a6861 100644 --- a/pdns/recursordist/configure.ac +++ b/pdns/recursordist/configure.ac @@ -94,6 +94,7 @@ AS_IF([test "x$PROTOBUF_LIBS" != "x" -a x"$PROTOC" != "x"], BOOST_REQUIRE([$boost_required_version]) PDNS_SELECT_CONTEXT_IMPL +PDNS_ENABLE_UNIT_TESTS PDNS_ENABLE_REPRODUCIBLE PDNS_WITH_LUAJIT diff --git a/pdns/recursordist/m4/pdns_enable_unit_tests.m4 b/pdns/recursordist/m4/pdns_enable_unit_tests.m4 new file mode 120000 index 0000000000..469b730077 --- /dev/null +++ b/pdns/recursordist/m4/pdns_enable_unit_tests.m4 @@ -0,0 +1 @@ +../../../m4/pdns_enable_unit_tests.m4 \ No newline at end of file diff --git a/pdns/recursordist/sha.hh b/pdns/recursordist/sha.hh deleted file mode 120000 index 53ffc66736..0000000000 --- a/pdns/recursordist/sha.hh +++ /dev/null @@ -1 +0,0 @@ -../sha.hh \ No newline at end of file diff --git a/pdns/recursordist/test-arguments_cc.cc b/pdns/recursordist/test-arguments_cc.cc new file mode 120000 index 0000000000..8c0885c664 --- /dev/null +++ b/pdns/recursordist/test-arguments_cc.cc @@ -0,0 +1 @@ +../test-arguments_cc.cc \ No newline at end of file diff --git a/pdns/recursordist/test-base32_cc.cc b/pdns/recursordist/test-base32_cc.cc new file mode 120000 index 0000000000..092c6375b3 --- /dev/null +++ b/pdns/recursordist/test-base32_cc.cc @@ -0,0 +1 @@ +../test-base32_cc.cc \ No newline at end of file diff --git a/pdns/recursordist/test-base64_cc.cc b/pdns/recursordist/test-base64_cc.cc new file mode 120000 index 0000000000..1f4893086d --- /dev/null +++ b/pdns/recursordist/test-base64_cc.cc @@ -0,0 +1 @@ +../test-base64_cc.cc \ No newline at end of file diff --git a/pdns/recursordist/test-dns_random_hh.cc b/pdns/recursordist/test-dns_random_hh.cc new file mode 120000 index 0000000000..5707086464 --- /dev/null +++ b/pdns/recursordist/test-dns_random_hh.cc @@ -0,0 +1 @@ +../test-dns_random_hh.cc \ No newline at end of file diff --git a/pdns/recursordist/test-dnsname_cc.cc b/pdns/recursordist/test-dnsname_cc.cc new file mode 120000 index 0000000000..1bd7c6351c --- /dev/null +++ b/pdns/recursordist/test-dnsname_cc.cc @@ -0,0 +1 @@ +../test-dnsname_cc.cc \ No newline at end of file diff --git a/pdns/recursordist/test-dnsparser_hh.cc b/pdns/recursordist/test-dnsparser_hh.cc new file mode 120000 index 0000000000..b80a824d09 --- /dev/null +++ b/pdns/recursordist/test-dnsparser_hh.cc @@ -0,0 +1 @@ +../test-dnsparser_hh.cc \ No newline at end of file diff --git a/pdns/recursordist/test-dnsrecordcontent.cc b/pdns/recursordist/test-dnsrecordcontent.cc new file mode 120000 index 0000000000..c6e85a50ad --- /dev/null +++ b/pdns/recursordist/test-dnsrecordcontent.cc @@ -0,0 +1 @@ +../test-dnsrecordcontent.cc \ No newline at end of file diff --git a/pdns/recursordist/test-dnsrecords_cc.cc b/pdns/recursordist/test-dnsrecords_cc.cc new file mode 120000 index 0000000000..d72a22ed66 --- /dev/null +++ b/pdns/recursordist/test-dnsrecords_cc.cc @@ -0,0 +1 @@ +../test-dnsrecords_cc.cc \ No newline at end of file diff --git a/pdns/recursordist/test-iputils_hh.cc b/pdns/recursordist/test-iputils_hh.cc new file mode 120000 index 0000000000..5536c3e9d9 --- /dev/null +++ b/pdns/recursordist/test-iputils_hh.cc @@ -0,0 +1 @@ +../test-iputils_hh.cc \ No newline at end of file diff --git a/pdns/recursordist/test-misc_hh.cc b/pdns/recursordist/test-misc_hh.cc new file mode 120000 index 0000000000..f1e02f0ad8 --- /dev/null +++ b/pdns/recursordist/test-misc_hh.cc @@ -0,0 +1 @@ +../test-misc_hh.cc \ No newline at end of file diff --git a/pdns/recursordist/test-nmtree.cc b/pdns/recursordist/test-nmtree.cc new file mode 120000 index 0000000000..923334b33d --- /dev/null +++ b/pdns/recursordist/test-nmtree.cc @@ -0,0 +1 @@ +../test-nmtree.cc \ No newline at end of file diff --git a/pdns/recursordist/test-rcpgenerator_cc.cc b/pdns/recursordist/test-rcpgenerator_cc.cc new file mode 120000 index 0000000000..94a123efd0 --- /dev/null +++ b/pdns/recursordist/test-rcpgenerator_cc.cc @@ -0,0 +1 @@ +../test-rcpgenerator_cc.cc \ No newline at end of file diff --git a/pdns/recursordist/test-recpacketcache_cc.cc b/pdns/recursordist/test-recpacketcache_cc.cc new file mode 120000 index 0000000000..cd15923d0f --- /dev/null +++ b/pdns/recursordist/test-recpacketcache_cc.cc @@ -0,0 +1 @@ +../test-recpacketcache_cc.cc \ No newline at end of file diff --git a/pdns/recursordist/test-tsig.cc b/pdns/recursordist/test-tsig.cc new file mode 120000 index 0000000000..5302c4b6ae --- /dev/null +++ b/pdns/recursordist/test-tsig.cc @@ -0,0 +1 @@ +../test-tsig.cc \ No newline at end of file diff --git a/pdns/recursordist/testrunner.cc b/pdns/recursordist/testrunner.cc new file mode 100644 index 0000000000..b6a6852886 --- /dev/null +++ b/pdns/recursordist/testrunner.cc @@ -0,0 +1,31 @@ +/* + * This file is part of PowerDNS or dnsdist. + * Copyright -- PowerDNS.COM B.V. and its contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * In addition, for the avoidance of any doubt, permission is granted to + * link this program with OpenSSL and to (re)distribute the binaries + * produced as the result of such linking. + * + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MAIN +#define BOOST_TEST_MODULE unit + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include + + -- 2.47.2