From c15857dd06dbefcc9f9ef5d9625472063d5a23a7 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. (cherry picked from commit 35d883a830af0284efafe94d1a6bd1c1ad04bae7) --- build-scripts/travis.sh | 4 ++ pdns/Makefile.am | 15 ---- pdns/recursordist/Makefile.am | 71 +++++++++++++++++++ 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-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/testrunner.cc | 31 ++++++++ 19 files changed, 120 insertions(+), 16 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-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 100644 pdns/recursordist/testrunner.cc diff --git a/build-scripts/travis.sh b/build-scripts/travis.sh index 112b82a326..2538b8b6af 100755 --- a/build-scripts/travis.sh +++ b/build-scripts/travis.sh @@ -383,6 +383,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" @@ -531,6 +532,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 66cd5676aa..6231b932f8 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -1127,8 +1127,6 @@ testrunner_SOURCES = \ packetcache.cc \ qtype.cc \ rcpgenerator.cc \ - recpacketcache.cc recpacketcache.hh \ - rec-protobuf.hh \ responsestats.cc \ responsestats-auth.cc \ sillyrecords.cc \ @@ -1150,7 +1148,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-zoneparser_tng_cc.cc \ @@ -1170,18 +1167,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 3b8b402d27..77b43c5e2b 100644 --- a/pdns/recursordist/Makefile.am +++ b/pdns/recursordist/Makefile.am @@ -62,6 +62,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 \ @@ -157,6 +167,62 @@ 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-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 \ + 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 @@ -197,6 +263,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 fe5e625612..d623f2efe6 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-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/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