From cabc3143870e12d5d2c988c982f38b9363de4fb2 Mon Sep 17 00:00:00 2001 From: Jan Vcelak <jan.vcelak@nic.cz> Date: Tue, 25 Feb 2014 15:16:24 +0100 Subject: [PATCH] build: separate libtap, separate tests --- .gitignore | 38 ++---------- Knot.files | 13 +--- Makefile.am | 4 +- configure.ac | 6 +- libtap/.gitignore | 4 ++ libtap/Makefile.am | 9 +++ {tests => libtap}/runtests.c | 0 {tests => libtap}/tap/basic.c | 2 +- {tests => libtap}/tap/basic.h | 2 +- {tests => libtap}/tap/float.c | 4 +- {tests => libtap}/tap/float.h | 2 +- {tests => libtap}/tap/libtap.sh | 0 {tests => libtap}/tap/macros.h | 0 tests/{TESTS => .gitignore} | 34 ++++++----- tests/Makefile.am | 50 +++++++++++++++ tests/Makefile.inc | 64 ------------------- tests/TAP/LICENSE | 23 ------- tests/TAP/Simple.py | 37 ----------- tests/TAP/__init__.py | 105 -------------------------------- tests/conf.c | 2 +- 20 files changed, 100 insertions(+), 299 deletions(-) create mode 100644 libtap/.gitignore create mode 100644 libtap/Makefile.am rename {tests => libtap}/runtests.c (100%) rename {tests => libtap}/tap/basic.c (99%) rename {tests => libtap}/tap/basic.h (99%) rename {tests => libtap}/tap/float.c (97%) rename {tests => libtap}/tap/float.h (98%) rename {tests => libtap}/tap/libtap.sh (100%) rename {tests => libtap}/tap/macros.h (100%) rename tests/{TESTS => .gitignore} (76%) create mode 100644 tests/Makefile.am delete mode 100644 tests/Makefile.inc delete mode 100644 tests/TAP/LICENSE delete mode 100644 tests/TAP/Simple.py delete mode 100644 tests/TAP/__init__.py diff --git a/.gitignore b/.gitignore index b977b23b46..9e2b3333cb 100644 --- a/.gitignore +++ b/.gitignore @@ -15,8 +15,6 @@ /Makefile.in /src/Makefile /src/Makefile.in -/src/tests/Makefile -/src/tests/Makefile.in /src/zscanner/Makefile /src/zscanner/Makefile.in /patches/Makefile @@ -57,12 +55,12 @@ /src/knot/conf/libknotd_la-cf-lex.c /src/knot/conf/libknotd_la-cf-parse.c /src/knot/conf/libknotd_la-cf-parse.h -/tests/sample_conf.c /src/zscanner/scanner.c -/src/zscanner/tests/tap/libtap.a -/tests/tap/libtap.a -/tests/tmp/ + +# zscanner /src/zscanner/tests/tmp/ +/src/zscanner/tests/runtests +/src/zscanner/tests/zscanner-tool # Binaries /src/knotc @@ -71,31 +69,3 @@ /src/khost /src/knsupdate /src/knsec3hash -/src/zscanner/tests/runtests -/src/zscanner/tests/zscanner-tool -/tests/runtests -/tests/acl -/tests/base32hex -/tests/base64 -/tests/conf -/tests/descriptor -/tests/dname -/tests/dnssec_keys -/tests/dnssec_nsec3 -/tests/dnssec_sign -/tests/dnssec_zone_nsec -/tests/dthreads -/tests/events -/tests/fdset -/tests/hattrie -/tests/hhash -/tests/journal -/tests/pkt -/tests/process_query -/tests/rrl -/tests/rrset -/tests/server -/tests/slab -/tests/wire -/tests/zonedb -/tests/ztree diff --git a/Knot.files b/Knot.files index 2bd8f946b6..81065a67dd 100644 --- a/Knot.files +++ b/Knot.files @@ -15,6 +15,7 @@ doc/requirements.texi doc/running.texi doc/security.texi doc/troubleshooting.texi +libtap/Makefile.am man/Makefile.am patches/Makefile.am samples/Makefile.am @@ -249,15 +250,11 @@ src/zscanner/scanner_functions.h src/zscanner/tests/processing.c src/zscanner/tests/processing.h src/zscanner/tests/runtests.c -src/zscanner/tests/tap/basic.c -src/zscanner/tests/tap/basic.h -src/zscanner/tests/tap/float.c -src/zscanner/tests/tap/float.h -src/zscanner/tests/tap/macros.h src/zscanner/tests/tests.c src/zscanner/tests/tests.h src/zscanner/tests/zscanner-tool.c src/zscanner/zscanner.h +tests/Makefile.am tests/acl.c tests/base32hex.c tests/base64.c @@ -277,15 +274,9 @@ tests/pkt.c tests/process_query.c tests/rrl.c tests/rrset.c -tests/runtests.c tests/sample_conf.h tests/server.c tests/slab.c -tests/tap/basic.c -tests/tap/basic.h -tests/tap/float.c -tests/tap/float.h -tests/tap/macros.h tests/wire.c tests/zonedb.c tests/ztree.c diff --git a/Makefile.am b/Makefile.am index b779470de7..20ad25258d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,2 @@ ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = src samples doc man patches - -include $(srcdir)/tests/Makefile.inc +SUBDIRS = libtap src tests samples doc man patches diff --git a/configure.ac b/configure.ac index a9412465ca..1f324cabe6 100644 --- a/configure.ac +++ b/configure.ac @@ -324,7 +324,7 @@ AC_CHECK_FUNCS([clock_gettime gettimeofday fgetln getline madvise malloc_trim po # Check for be64toh function AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <endian.h>]], [[return be64toh(0);]])], -[AC_DEFINE(HAVE_BE64TOH, 1, [Define to 1 if you have the `be64toh' function.])]) +[AC_DEFINE(HAVE_BE64TOH, 1, [Define to 1 if you have the 'be64toh' function.])]) # Check for cpu_set_t/cpuset_t compatibility AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pthread.h>]], [[cpu_set_t set; CPU_ZERO(&set);]])], @@ -342,9 +342,11 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sched.h>]], [[cpuset_t* set = cpuset AC_CONFIG_FILES([Makefile doc/Makefile man/Makefile - src/Makefile samples/Makefile patches/Makefile + libtap/Makefile + src/Makefile + tests/Makefile src/zscanner/Makefile man/khost.1 man/knotc.8 diff --git a/libtap/.gitignore b/libtap/.gitignore new file mode 100644 index 0000000000..6a2b4b004e --- /dev/null +++ b/libtap/.gitignore @@ -0,0 +1,4 @@ +Makefile +Makefile.in +runtests +libtap.a diff --git a/libtap/Makefile.am b/libtap/Makefile.am new file mode 100644 index 0000000000..61c403a8c2 --- /dev/null +++ b/libtap/Makefile.am @@ -0,0 +1,9 @@ +libtap_a_SOURCES = \ + tap/basic.c tap/basic.h \ + tap/float.c tap/float.h \ + tap/macros.h + +check_LIBRARIES = libtap.a + +check_PROGRAMS = \ + runtests diff --git a/tests/runtests.c b/libtap/runtests.c similarity index 100% rename from tests/runtests.c rename to libtap/runtests.c diff --git a/tests/tap/basic.c b/libtap/tap/basic.c similarity index 99% rename from tests/tap/basic.c rename to libtap/tap/basic.c index 2d19d19c31..f478f0f243 100644 --- a/tests/tap/basic.c +++ b/libtap/tap/basic.c @@ -48,7 +48,7 @@ #include <sys/types.h> #include <unistd.h> -#include <tests/tap/basic.h> +#include "basic.h" /* Windows provides mkdir and rmdir under different names. */ #ifdef _WIN32 diff --git a/tests/tap/basic.h b/libtap/tap/basic.h similarity index 99% rename from tests/tap/basic.h rename to libtap/tap/basic.h index 544de5194e..6371c9c840 100644 --- a/tests/tap/basic.h +++ b/libtap/tap/basic.h @@ -30,7 +30,7 @@ #ifndef TAP_BASIC_H #define TAP_BASIC_H 1 -#include <tests/tap/macros.h> +#include "macros.h" #include <stdarg.h> /* va_list */ #include <sys/types.h> /* size_t */ diff --git a/tests/tap/float.c b/libtap/tap/float.c similarity index 97% rename from tests/tap/float.c rename to libtap/tap/float.c index 67dd555f31..5c0c643c9e 100644 --- a/tests/tap/float.c +++ b/libtap/tap/float.c @@ -42,8 +42,8 @@ #include <stdarg.h> #include <stdio.h> -#include <tests/tap/basic.h> -#include <tests/tap/float.h> +#include "basic.h" +#include "float.h" /* * Takes an expected double and a seen double and assumes the test passes if diff --git a/tests/tap/float.h b/libtap/tap/float.h similarity index 98% rename from tests/tap/float.h rename to libtap/tap/float.h index 746453564c..2d194d31aa 100644 --- a/tests/tap/float.h +++ b/libtap/tap/float.h @@ -28,7 +28,7 @@ #ifndef TAP_FLOAT_H #define TAP_FLOAT_H 1 -#include <tests/tap/macros.h> +#include "macros.h" BEGIN_DECLS diff --git a/tests/tap/libtap.sh b/libtap/tap/libtap.sh similarity index 100% rename from tests/tap/libtap.sh rename to libtap/tap/libtap.sh diff --git a/tests/tap/macros.h b/libtap/tap/macros.h similarity index 100% rename from tests/tap/macros.h rename to libtap/tap/macros.h diff --git a/tests/TESTS b/tests/.gitignore similarity index 76% rename from tests/TESTS rename to tests/.gitignore index f4736ea400..d22ba5e5d1 100644 --- a/tests/TESTS +++ b/tests/.gitignore @@ -1,24 +1,30 @@ -journal -slab -hattrie -hhash -dthreads +Makefile +Makefile.in +sample_conf.c + +# Test binaries: acl -fdset -base64 base32hex -descriptor -server +base64 conf -rrl -wire +descriptor dname -ztree -zonedb dnssec_keys dnssec_nsec3 dnssec_sign dnssec_zone_nsec -rrset +dthreads +events +fdset +hattrie +hhash +journal pkt process_query +rrl +rrset +server +slab +wire +zonedb +ztree diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000000..4b954d8853 --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,50 @@ +AM_CPPFLAGS = \ + -I$(top_srcdir)/libtap \ + -I$(top_srcdir)/src + +LDADD = \ + $(top_srcdir)/libtap/libtap.a \ + $(top_srcdir)/src/libknotd.la \ + $(top_srcdir)/src/libknots.la + +check_PROGRAMS = \ + journal \ + slab \ + hattrie \ + hhash \ + dthreads \ + acl \ + fdset \ + base64 \ + base32hex \ + descriptor \ + server \ + conf \ + rrl \ + wire \ + dname \ + ztree \ + zonedb \ + dnssec_keys \ + dnssec_nsec3 \ + dnssec_sign \ + dnssec_zone_nsec \ + rrset \ + pkt \ + process_query + +check-compile-only: $(check_PROGRAMS) + +check-local: $(check_PROGRAMS) + $(top_srcdir)/libtap/runtests \ + -s $(abs_top_srcdir)/tests -b $(abs_top_srcdir)/tests \ + $(check_PROGRAMS) + +EXTRA_DIST = data +dist_check_SCRIPTS = resource.sh + +conf_SOURCES = conf.c sample_conf.h +nodist_conf_SOURCES = sample_conf.c +CLEANFILES = sample_conf.c +sample_conf.c: data/sample_conf + $(abs_srcdir)/resource.sh $(abs_srcdir)/data/sample_conf >$@ diff --git a/tests/Makefile.inc b/tests/Makefile.inc deleted file mode 100644 index c7730e2717..0000000000 --- a/tests/Makefile.inc +++ /dev/null @@ -1,64 +0,0 @@ -# -*- mode: makefile; -*- -check_PROGRAMS = \ - tests/runtests \ - tests/journal \ - tests/slab \ - tests/hattrie \ - tests/hhash \ - tests/dthreads \ - tests/acl \ - tests/fdset \ - tests/base64 \ - tests/base32hex \ - tests/descriptor \ - tests/server \ - tests/conf \ - tests/rrl \ - tests/wire \ - tests/dname \ - tests/ztree \ - tests/zonedb \ - tests/dnssec_keys \ - tests/dnssec_nsec3 \ - tests/dnssec_sign \ - tests/dnssec_zone_nsec \ - tests/rrset \ - tests/pkt \ - tests/process_query - -check_LIBRARIES = tests/tap/libtap.a - -AM_CPPFLAGS = \ - -I$(top_srcdir)/src \ - -I$(top_srcdir)/tests - -tests_runtests_CPPFLAGS = \ - -DSOURCE='"$(abs_top_srcdir)/tests"' \ - -DBUILD='"$(abs_top_builddir)/tests"' - -tests_tap_libtap_a_CPPFLAGS = -I$(abs_top_srcdir)/tests -tests_tap_libtap_a_SOURCES = \ - tests/tap/basic.c tests/tap/basic.h \ - tests/tap/float.c tests/tap/float.h \ - tests/tap/macros.h - -check-compile-only: $(check_PROGRAMS) - -check-local: $(check_PROGRAMS) - cd tests && ./runtests -l $(abs_top_srcdir)/tests/TESTS - -LDADD = \ - tests/tap/libtap.a \ - src/libknotd.la src/libknots.la \ - @LIBOBJS@ - -tests_conf_SOURCES = tests/conf.c tests/sample_conf.h -nodist_tests_conf_SOURCES = tests/sample_conf.c -CLEANFILES = tests/sample_conf.c - -EXTRA_DIST = tests/data tests/TESTS - -dist_check_SCRIPTS = tests/resource.sh - -tests/sample_conf.c: tests/data/sample_conf - $(abs_top_srcdir)/tests/resource.sh $(abs_top_srcdir)/tests/data/sample_conf >$@ diff --git a/tests/TAP/LICENSE b/tests/TAP/LICENSE deleted file mode 100644 index 6fcd49349a..0000000000 --- a/tests/TAP/LICENSE +++ /dev/null @@ -1,23 +0,0 @@ -The MIT/X11 License - -Copyright (c) 2005-2008 Ricardo Signes - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - diff --git a/tests/TAP/Simple.py b/tests/TAP/Simple.py deleted file mode 100644 index 8558eda457..0000000000 --- a/tests/TAP/Simple.py +++ /dev/null @@ -1,37 +0,0 @@ - -import TAP -import re - -builder = TAP.Builder() - -def plan(plan, plan_param=None): - builder.set_plan(plan, plan_param) - -ok = builder.ok - -def diag(comment): - print(("# %s" % re.compile("\n(.)").sub(comment, '\n#\1'))) - -def eq_ok(have, want, comment): - okness = have == want - ok(okness, comment) - if not okness: - diag("want: %s" % want) - diag("have: %s" % have) - return okness - -def is_ok(have, want, comment): - okness = have is want - ok(okness, comment) - if not okness: - diag("want id: %s" % id(want)) - diag("have id: %s" % id(have)) - return okness - -def isa_ok(object, cls, object_name="the object"): - okness = isinstance(object, cls) - ok(okness, object_name + " is a " + repr(cls)) - # if not okness: - # diag("want id: %s" % id(want)) - # diag("have id: %s" % id(have)) - return okness diff --git a/tests/TAP/__init__.py b/tests/TAP/__init__.py deleted file mode 100644 index 2f45ead42e..0000000000 --- a/tests/TAP/__init__.py +++ /dev/null @@ -1,105 +0,0 @@ -import sys -import atexit - -# todo: make written-to stream passable - -class Plan(object): - def __init__(self, plan, param=None): - self.counter = 0 - self.expected_tests = None - self.ended = False - - if isinstance(plan, int): - self.expected_tests = plan - print(("1..%u" % self.expected_tests)) - elif plan == "no_plan" or plan == None: 1 - elif plan == "skip_all": - print(("1..0 # skip %s" % param)) - raise SystemExit(0) # ??? this is what T::B does, but sucks - else: - raise TestBadPlan(plan) - - def increment_counter(self): - self.counter += 1 - - def __del__(self): - if self.ended: return - self.ended = True - if self.expected_tests is None: - print(("1..%u" % self.counter)) - elif self.counter != self.expected_tests: - print(("# Looks like you planned %u tests but ran %u." \ - % (self.expected_tests, self.counter))) - -class Builder(object): - global_defaults = { - "_plan": None, - "current": 1, - "has_plan": False, - } - global_test_builder = global_defaults.copy() - - def __init__(self, plan=None, plan_param=None): - self.__dict__ = self.global_test_builder - if plan: self.set_plan(plan, plan_param) - - @classmethod # XXX: why did this fail? - def create(cls, plan=None, plan_param=None): - # self = new.instance(cls) # ? this sucks, too - self = Builder() - self.__dict__ = self.global_defaults.copy() - if plan: self.set_plan(plan, plan_param) - return self - - def set_plan(self, plan, plan_param=None): - if self.get_plan(): raise TestPlannedAlready(plan, plan_param) - self._plan = Plan(plan, plan_param) - atexit.register(self._plan.__del__) - - def get_plan(self): return self._plan - - def ok(self, is_ok, desc=None, skip=None, todo=None): - self.get_plan().increment_counter() - - if skip and todo: raise TestBadDirective(self) - - if is_ok: report = "ok" - else: report = "not ok" - - sys.stdout.write("%s %u" % (report, self.current)) - - if desc: sys.stdout.write(" - %s" % desc) - if skip: sys.stdout.write(" # SKIP %s" % skip) - if todo: sys.stdout.write(" # TODO %s" % todo) - - print("") - - self.current += 1 - - return is_ok - - def reset(self): - self.__dict__.clear() - for key in list(self.global_defaults.keys()): - self.__dict__[key] = self.global_defaults[key] - -class TestPlannedAlready(Exception): - def __init__(self, plan, param=None): - self.plan = plan - self.param = param - def __str__(self): - return "tried to plan twice; second plan: %s, %s" % self.plan, self.param - -class TestWithoutPlan(Exception): - def __str__(self): - return "tried running tests without a plan" - -class TestBadPlan(Exception): - def __init__(self, plan): - self.plan = plan - def __str__(self): - return "didn't understand plan '%s'" % self.plan - -class TestBadDirective(Exception): - def __str__(self): - return "tried running a test with more than one directive" diff --git a/tests/conf.c b/tests/conf.c index ec8737b470..f814322713 100644 --- a/tests/conf.c +++ b/tests/conf.c @@ -21,7 +21,7 @@ #include "knot/conf/conf.h" /* Resources. */ -#include "tests/sample_conf.h" +#include "sample_conf.h" /*! Run all scheduled tests for given parameters. */ -- GitLab