diff --git a/.gitignore b/.gitignore index 8171289a2ead2efcceaf466aca6d08027da29d1d..f77f9c3efeb0d1fe0718b1a07712345b230c675b 100644 --- a/.gitignore +++ b/.gitignore @@ -38,7 +38,7 @@ src/unittests src/unittests-libknot src/unittests-libknot-realdata src/unittests-zcompile -src/unittests-zscanner +src/zscanner-tool src/knotc src/knotd src/knot-zcompile diff --git a/Knot.files b/Knot.files index 3fca581e16f309b90eb943bfd1e689b86c77eafe..25603da95fd9f72df68f8e7b556c8516428d35cf 100644 --- a/Knot.files +++ b/Knot.files @@ -17,6 +17,7 @@ doc/requirements.texi doc/running.texi doc/security.texi doc/troubleshooting.texi +man/Makefile.am samples/Makefile.am src/Makefile.am src/common/acl.c @@ -214,6 +215,8 @@ src/tests/knot/server_tests.c src/tests/knot/server_tests.h src/tests/libknot/dname_tests.c src/tests/libknot/dname_tests.h +src/tests/libknot/rrset_tests.c +src/tests/libknot/rrset_tests.h src/tests/libknot/sign_tests.c src/tests/libknot/sign_tests.h src/tests/libknot/unittests_libknot.c @@ -221,8 +224,6 @@ src/tests/libknot/wire_tests.c src/tests/libknot/wire_tests.h src/tests/libknot/ztree_tests.c src/tests/libknot/ztree_tests.h -src/tests/libknot/rrset_tests.c -src/tests/libknot/rrset_tests.h src/tests/unittests_main.c src/tests/xfr_tests.c src/tests/xfr_tests.h diff --git a/src/Makefile.am b/src/Makefile.am index 959e77341571823b2648d1d5ccf5e7a178a017a8..56fbba44c6d0bf60506eb6e51c8b126df8389c6f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,5 @@ ACLOCAL_AMFLAGS = -I ../m4 -libexec_PROGRAMS = unittests unittests-xfr unittests-zscanner unittests-libknot +libexec_PROGRAMS = unittests unittests-xfr unittests-libknot zscanner-tool sbin_PROGRAMS = knotc knotd kdig khost knsupdate # $(YACC) will generate header file @@ -109,6 +109,8 @@ unittests_SOURCES = \ tests/knot/server_tests.h \ tests/knot/rrl_tests.h \ tests/knot/rrl_tests.c \ + tests/zscanner/zscanner_tests.h \ + tests/zscanner/zscanner_tests.c \ tests/libknot/dname_tests.h \ tests/libknot/dname_tests.c \ tests/libknot/ztree_tests.h \ @@ -122,7 +124,7 @@ unittests_SOURCES = \ unittests_xfr_SOURCES = \ tests/xfr_tests.c \ tests/xfr_tests.h - + unittests_libknot_SOURCES = \ tests/libknot/unittests_libknot.c \ tests/libknot/dname_tests.h \ @@ -314,13 +316,13 @@ libknotd_la_SOURCES = \ zscanner/scanner.c: zscanner/scanner.rl zscanner/scanner_body.rl $(RAGEL) $(FSM_TYPE) -s -o zscanner/scanner.c zscanner/scanner.rl -unittests_zscanner_SOURCES = \ - zscanner/test/zscanner_test.c \ +zscanner_tool_SOURCES = \ + zscanner/test/zscanner-tool.c \ zscanner/test/tests.h \ zscanner/test/tests.c \ zscanner/test/processing.h \ zscanner/test/processing.c - + libzscanner_la_SOURCES = \ zscanner/file_loader.h \ zscanner/file_loader.c \ @@ -340,11 +342,10 @@ knsupdate_LDADD = libknotd.la libknot.la libknots.la libzscanner.la @LIBOBJS@ unittests_LDADD = libknotd.la libknots.la @LIBOBJS@ unittests_libknot_LDADD = libknotd.la libknots.la @LIBOBJS@ unittests_xfr_LDADD = libknotd.la libknot.la libknots.la @LIBOBJS@ -unittests_zscanner_LDADD = libknots.la libknot.la libknotd.la libzscanner.la @LIBOBJS@ +zscanner_tool_LDADD = libknots.la libknot.la libknotd.la libzscanner.la @LIBOBJS@ # automake complains on % rules: # `%'-style pattern rules are a GNU make extension tests/sample_conf.rc: tests/files/sample_conf ../resource.sh tests/files/sample_conf >$@ - diff --git a/src/tests/unittests_main.c b/src/tests/unittests_main.c index cafe4951e6775b29fa1c96bc9c90404d4999754b..f8737424c50f7c194b5c4aa2408f042a20b7ce9f 100644 --- a/src/tests/unittests_main.c +++ b/src/tests/unittests_main.c @@ -32,6 +32,7 @@ #include "tests/knot/server_tests.h" #include "tests/knot/conf_tests.h" #include "tests/knot/rrl_tests.h" +#include "tests/zscanner/zscanner_tests.h" #include "tests/libknot/wire_tests.h" #include "tests/libknot/dname_tests.h" #include "tests/libknot/ztree_tests.h" @@ -65,6 +66,9 @@ int main(int argc, char *argv[]) &server_tests_api, //! Server unit &rrl_tests_api, //! RRL tests + /* Zone scanner. */ + &zscanner_tests_api, //! Wrapper for external unittests + /* Libknot library. */ &wire_tests_api, &dname_tests_api, diff --git a/src/tests/zscanner/zscanner_tests.c b/src/tests/zscanner/zscanner_tests.c new file mode 100644 index 0000000000000000000000000000000000000000..7642fbd7bb4b87ff349f3f67c73568079f349c98 --- /dev/null +++ b/src/tests/zscanner/zscanner_tests.c @@ -0,0 +1,46 @@ +/* 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 "tests/zscanner/zscanner_tests.h" + +#include <stdlib.h> +#include <stdint.h> +#include <string.h> + +static int zscanner_tests_count(int argc, char *argv[]); +static int zscanner_tests_run(int argc, char *argv[]); + +unit_api zscanner_tests_api = { + "Zone scanner", + &zscanner_tests_count, + &zscanner_tests_run +}; + +static int zscanner_tests_count(int argc, char *argv[]) +{ + return 1; +} + +static int zscanner_tests_run(int argc, char *argv[]) +{ + int ret; + + // Run zscanner unittests via external tool. + ret = system("cd ./zscanner/test; ./run_tests.sh brief"); + cmp_ok(ret, "==", 0, "zscanner unittests"); + + return 0; +} diff --git a/src/tests/zscanner/zscanner_tests.h b/src/tests/zscanner/zscanner_tests.h new file mode 100644 index 0000000000000000000000000000000000000000..eae23caed166686358104fb569936fe63ee310eb --- /dev/null +++ b/src/tests/zscanner/zscanner_tests.h @@ -0,0 +1,25 @@ +/* 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 _ZSCANNER_TESTS_H_ +#define _ZSCANNER_TESTS_H_ + +#include "common/libtap/tap_unit.h" + +/* Unit API. */ +unit_api zscanner_tests_api; + +#endif /* _ZSCANNER_TESTS_H_ */ diff --git a/src/zscanner/test/run_tests.sh b/src/zscanner/test/run_tests.sh index 9d8ac86edcf2077687fb1d516f528dccb21ed328..d1a0550974fba2f48fd325c5a8b5f0692f7bbc66 100755 --- a/src/zscanner/test/run_tests.sh +++ b/src/zscanner/test/run_tests.sh @@ -2,19 +2,43 @@ TESTS_DIR="./tests" OUTS_DIR="/tmp/zscanner_tests" -TEST_BIN="../../unittests-zscanner -m 2" +TEST_BIN="../../zscanner-tool -m 2" -SEPARATION="=========================================================" +# If verbose (default - no parameter) mode. +if [ $# -eq 0 ]; then + echo "Launching zscanner tests" +fi +# Create output directory and copy include zone files. mkdir -p ${OUTS_DIR}/${TESTS_DIR} cp -r ${TESTS_DIR}/includes ${OUTS_DIR} -echo ${SEPARATION} - +# Run zscanner on all test zone files. for file in `find ${TESTS_DIR} -name "*.in" | sort`; do fileout=`echo "${file}" | sed 's/.in/.out/'` + + # Run zscanner. ${TEST_BIN} . ${file} > ${OUTS_DIR}/${fileout} - echo ${fileout} - diff ${OUTS_DIR}/${fileout} ${fileout} - echo ${SEPARATION} + + # Compare result with a reference one. + cmp ${OUTS_DIR}/${fileout} ${fileout} > /dev/null 2>&1 + + # Check for differences. + if [ $? -ne 0 ]; then + # If verbose print diff. + if [ $# -eq 0 ]; then + echo "\n=== ${fileout} DIFF ======================" + diff ${OUTS_DIR}/${fileout} ${fileout} + # Return error and exit. + else + return 1 + fi + fi done + +if [ $# -eq 0 ]; then + echo "\nFinished" +else + return 0 +fi + diff --git a/src/zscanner/test/zscanner_test.c b/src/zscanner/test/zscanner-tool.c similarity index 100% rename from src/zscanner/test/zscanner_test.c rename to src/zscanner/test/zscanner-tool.c