Commit 1c6696e8 authored by Ondřej Surý's avatar Ondřej Surý

Modernize autotools usage and split unittests into separate TESTS target

and use absolute path in build directory for zscanner tests.

Change-Id: I75b6d02b93d28cc9ff1354d5432d10b20cf734b5
parent 3dec54cf
# -*- Autoconf -*-
AC_PREREQ([2.60])
AC_INIT([knot], [1.2.0], [knot-dns@labs.nic.cz])
AM_INIT_AUTOMAKE([gnu -Wall -Werror])
AC_INIT([knot], [1.3.0-dev], [knot-dns@labs.nic.cz])
AM_INIT_AUTOMAKE([gnu subdir-objects dist-xz -Wall -Werror])
AC_CONFIG_SRCDIR([src/knot/main.c])
AC_CONFIG_HEADERS([src/config.h])
AC_CONFIG_MACRO_DIR([m4])
AC_USE_SYSTEM_EXTENSIONS([_GNU_SOURCE])
# Check SSE, SSE2 and SSE3 support
AX_EXT
CFLAGS="$CFLAGS $SIMD_FLAGS"
# Set compiler compatibility flags
AC_PROG_CC_C99
AM_PROG_CC_C_O
AC_PROG_CPP_WERROR
# Checks for programs.
AC_PROG_CC
m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) # call AM_PROG_AR only if available
# Initialize libtool
......@@ -18,6 +25,9 @@ AC_DISABLE_STATIC
AC_PROG_LIBTOOL
LT_INIT
# Use pkg-config
PKG_PROG_PKG_CONFIG
AC_CACHE_CHECK([for reentrant lex], [ac_cv_path_LEX],
[AC_PATH_PROGS_FEATURE_CHECK([LEX], [$LEX flex gflex],
[cat >conftest.l <<_ACEOF
......@@ -50,10 +60,6 @@ AS_IF([test "x$YACC_BISON" != "xbison"],
[AC_MSG_ERROR([GNU bison needed for reentrant parsers, set the \$YACC variable before running configure])])
AC_PROG_INSTALL
# Full path to Knot source
abs_srcdir=`(cd $srcdir && pwd)`
AC_DEFINE_UNQUOTED([SOURCE_ABSOLUTE_DIR], ["$abs_srcdir"], [Knot source full path.])
# Check for Ragel
AC_PATH_PROG([RAGEL], [ragel], [echo !UNPROCESSED! ragel])
......@@ -64,10 +70,6 @@ AC_ARG_ENABLE([fastparser],
[touch src/zscanner/scanner.rl; AC_SUBST([FSM_TYPE], [-G2])],
[])
# Set compiler compatibility flags
AC_PROG_CPP_WERROR
AC_PROG_CC_C99
# Debug modules
AC_ARG_ENABLE([debug],
AS_HELP_STRING([--enable-debug=server,zones,xfr,packet,dname,rr,ns,hash,compiler,stash],
......@@ -158,16 +160,102 @@ AX_CHECK_COMPILE_FLAG("-fno-strict-aliasing", [CFLAGS="$CFLAGS -fno-strict-alias
# Checks for libraries.
# FIXME: Replace `main' with a function in `-lm':
# TODO: check if paths exist before appending
CFLAGS="$CFLAGS -I/usr/local/include $SIMD_FLAGS"
LDFLAGS="$LDFLAGS -L/usr/local/lib"
dnl Check for userspace-rcu library
AC_ARG_WITH(urcu,
[ --with-urcu=DIR where to find userspace-rcu library])
AS_IF([test "$with_urcu" != "no"], [
PKG_CHECK_MODULES([liburcu], liburcu, [
CPPFLAGS="$CPPFLAGS $liburcu_CFLAGS"
LIBS="$LIBS $liburcu_LIBS"
with_urcu=yes
],[
for try_urcu in "$with_urcu" "" "/usr/local"; do
save_LIBS="$LIBS"
save_CPPFLAGS="$CPPFLAGS"
AS_IF([test -d "$try_urcu"], [
liburcu_CFLAGS="-I$try_urcu/include"
liburcu_LIBS="-L$try_urcu/lib"
],[
liburcu_CFLAGS=""
liburcu_LIBS=""
])
CPPFLAGS="$CPPFLAGS $liburcu_CFLAGS"
LIBS="$LIBS $liburcu_LIBS"
AC_SEARCH_LIBS([rcu_set_pointer_sym], [urcu], [
with_urcu=yes
break
],[
with_urcu=no
# do not cache result of AC_SEARCH_LIBS test
unset ac_cv_search_rcu_set_pointer_sym
])
CPPFLAGS="$save_CPPFLAGS"
LIBS="$save_LIBS"
done
AS_IF([test "$with_urcu" = "no"],[
AC_MSG_ERROR([liburcu is required])
])
])
])
AC_SEARCH_LIBS([urcu_init], [urcu], [AC_MSG_ERROR([liburcu is too old (< 0.4.0), urcu_init symbol found])], [])
dnl Check for OpenSSL
AC_ARG_WITH(openssl,
[ --with-openssl=DIR where to find openssl library])
AS_IF([test "$with_openssl" != "no"],[
PKG_CHECK_MODULES([libcrypto], libcrypto, [
CPPFLAGS="$CPPFLAGS $libcrypto_CFLAGS"
LIBS="$LIBS $libcrypto_LIBS"
with_openssl=yes
],[
for try_openssl in "$with_openssl" "" "/usr/local"; do
save_LIBS="$LIBS"
save_CPPFLAGS="$CPPFLAGS"
AS_IF([test -d "$try_openssl"], [
libcrypto_CFLAGS="-I$try_openssl/include"
libcrypto_LIBS="-L$try_openssl/lib"
],[
libcrypto_CFLAGS=""
libcrypto_LIBS=""
])
CPPFLAGS="$CPPFLAGS $libcrypto_CFLAGS"
LIBS="$LIBS $libcrypto_LIBS"
AC_SEARCH_LIBS([OpenSSL_add_all_digests], [crypto], [
with_openssl=yes
break
],[
with_openssl=no
# do not cache result of AC_SEARCH_LIBS test
unset ac_cv_search_OpenSSL_add_all_digests
])
CPPFLAGS="$save_CPPFLAGS"
LIBS="$save_LIBS"
done
AS_IF([test "$with_openssl" = "no"],[
AC_MSG_ERROR([libcrypto (part of OpenSSL) is required])
])
])
])
AC_SEARCH_LIBS([pow], [m])
AC_SEARCH_LIBS([pthread_create], [pthread], [], [AC_MSG_ERROR([pthreads not found])])
AC_SEARCH_LIBS([rcu_set_pointer_sym], [urcu], [], [AC_MSG_ERROR([liburcu not found])])
AC_SEARCH_LIBS([urcu_init], [urcu], [AC_MSG_ERROR([liburcu is too old (< 0.4.0), urcu_init symbol found])], [])
AC_SEARCH_LIBS([dlopen], [dl])
AC_SEARCH_LIBS([clock_gettime], [rt])
AC_SEARCH_LIBS([OpenSSL_add_all_digests], [crypto],[], [AC_MSG_ERROR([libcrypto not found])])
AC_SEARCH_LIBS([capng_apply], [cap-ng])
AC_SEARCH_LIBS([adler32], [z])
......@@ -182,7 +270,7 @@ AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
# Set PRNG parameters
AC_DEFINE([DSFMT_MEXP], [521], [DSFMT parameters.])
AC_DEFINE([DSFMT_MEXP], [521], [DSFMT parameters])
# Checks for library functions.
AC_CHECK_FUNCS([clock_gettime gettimeofday epoll_wait fgetln getline kqueue madvise poll posix_memalign pselect pthread_setaffinity_np regcomp select sendmmsg setgroups])
......@@ -201,6 +289,12 @@ CFLAGS="$CFLAGS $CFLAG_VISIBILITY"
AC_CONFIG_FILES([Makefile
samples/Makefile
src/Makefile
src/tests/Makefile
doc/Makefile
man/Makefile])
man/Makefile
src/zscanner/test/run_tests.sh
src/zscanner/test/cases/06-3_INCLUDE.in:src/zscanner/test/cases/06-3_INCLUDE.inin
src/zscanner/test/cases/06-4_INCLUDE.in:src/zscanner/test/cases/06-4_INCLUDE.inin
src/zscanner/test/cases/06-0_INCLUDE.in:src/zscanner/test/cases/06-0_INCLUDE.inin
])
AC_OUTPUT
ACLOCAL_AMFLAGS = -I ../m4
ACLOCAL_AMFLAGS = -I $(top_srcdir)/m4
SUBDIRS = . tests
sbin_PROGRAMS = knotc knotd kdig khost knsupdate
noinst_PROGRAMS = unittests unittests-xfr zscanner-tool
noinst_PROGRAMS = zscanner-tool
noinst_LTLIBRARIES = libknot.la libknotd.la libknots.la libzscanner.la
# $(YACC) will generate header file
AM_CFLAGS = -std=gnu99 -D_GNU_SOURCE -Wall -I$(top_srcdir)/src/libknot -DSYSCONFDIR='"$(sysconfdir)"' -DSBINDIR='"$(sbindir)"'
AM_CPPFLAGS = -I$(top_srcdir)/src/libknot -DSYSCONFDIR='"$(sysconfdir)"' -DSBINDIR='"$(sbindir)"'
AM_YFLAGS = -d
libknotd_la_YFLAGS = -pcf_ -d
libknotd_la_LFLAGS = # TODO: reentrant parser, prefix
EXTRA_DIST = \
tests/files/sample_conf \
zscanner/scanner.rl \
zscanner/scanner_body.rl \
zscanner/test/run_tests.sh \
zscanner/test/cases
BUILT_SOURCES = \
sample_conf.rc \
libknotd_la-cf-lex.c \
libknotd_la-cf-parse.c \
libknotd_la-cf-parse.h \
knot/conf/libknotd_la-cf-lex.c \
knot/conf/libknotd_la-cf-parse.c \
knot/conf/libknotd_la-cf-parse.h \
zscanner/scanner.c
CLEANFILES = \
sample_conf.rc \
libknotd_la-cf-lex.c \
libknotd_la-cf-parse.c \
libknotd_la-cf-parse.h
nodist_unittests_SOURCES = \
tests/sample_conf.rc
knot/conf/libknotd_la-cf-lex.c \
knot/conf/libknotd_la-cf-parse.c \
knot/conf/libknotd_la-cf-parse.h
knotc_SOURCES = \
knot/ctl/knotc_main.c
......@@ -98,53 +93,6 @@ knsupdate_SOURCES = \
utils/nsupdate/nsupdate_exec.h \
utils/nsupdate/nsupdate_exec.c
unittests_SOURCES = \
tests/common/acl_tests.c \
tests/common/acl_tests.h \
tests/common/base32hex_tests.c \
tests/common/base32hex_tests.h \
tests/common/base64_tests.c \
tests/common/base64_tests.h \
tests/common/descriptor_tests.h \
tests/common/descriptor_tests.c \
tests/common/events_tests.c \
tests/common/events_tests.h \
tests/common/fdset_tests.c \
tests/common/fdset_tests.h \
tests/common/skiplist_tests.c \
tests/common/skiplist_tests.h \
tests/common/hattrie_tests.c \
tests/common/hattrie_tests.h \
tests/common/slab_tests.c \
tests/common/slab_tests.h \
tests/knot/conf_tests.c \
tests/knot/conf_tests.h \
tests/knot/dthreads_tests.c \
tests/knot/dthreads_tests.h \
tests/knot/journal_tests.c \
tests/knot/journal_tests.h \
tests/knot/server_tests.c \
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 \
tests/libknot/ztree_tests.c \
tests/libknot/wire_tests.h \
tests/libknot/wire_tests.c \
tests/libknot/rrset_tests.c \
tests/libknot/rrset_tests.h \
tests/libknot/sign_tests.c \
tests/libknot/sign_tests.h \
tests/unittests_main.c
unittests_xfr_SOURCES = \
tests/xfr_tests.c \
tests/xfr_tests.h
libknot_la_SOURCES = \
libknot/common.h \
libknot/consts.h \
......@@ -332,7 +280,7 @@ libknotd_la_SOURCES = \
knot/server/server.h
zscanner/scanner.c: zscanner/scanner.rl zscanner/scanner_body.rl
$(RAGEL) $(FSM_TYPE) -s -o zscanner/scanner.c zscanner/scanner.rl
$(RAGEL) $(FSM_TYPE) -s -o $@ $(srcdir)/zscanner/scanner.rl
zscanner_tool_SOURCES = \
zscanner/test/zscanner-tool.c \
......@@ -357,9 +305,4 @@ knotc_LDADD = libknotd.la libknot.la libknots.la @LIBOBJS@
kdig_LDADD = libknotd.la libknot.la libknots.la @LIBOBJS@
khost_LDADD = libknotd.la libknot.la libknots.la @LIBOBJS@
knsupdate_LDADD = libknotd.la libknot.la libknots.la libzscanner.la @LIBOBJS@
unittests_LDADD = libknotd.la libknots.la @LIBOBJS@
unittests_xfr_LDADD = libknotd.la libknot.la libknots.la @LIBOBJS@
zscanner_tool_LDADD = libknots.la libknot.la libknotd.la libzscanner.la @LIBOBJS@
sample_conf.rc: tests/files/sample_conf
$(top_srcdir)/resource.sh $(srcdir)/tests/files/sample_conf >$@
ACLOCAL_AMFLAGS = -I $(top_srcdir)/m4
AM_CPPFLAGS = -I$(top_srcdir)/src/libknot -I$(top_srcdir)/src -DSYSCONFDIR='"$(sysconfdir)"' -DSBINDIR='"$(sbindir)"'
check_PROGRAMS = \
unittests
EXTRA_PROGRAMS = \
unittests_xfr
TESTS = $(check_PROGRAMS)
EXTRA_DIST = \
files/sample_conf
BUILT_SOURCES = \
sample_conf.rc
CLEANFILES = \
sample_conf.rc
nodist_unittests_SOURCES = \
sample_conf.rc
unittests_SOURCES = \
common/acl_tests.c \
common/acl_tests.h \
common/base32hex_tests.c \
common/base32hex_tests.h \
common/base64_tests.c \
common/base64_tests.h \
common/descriptor_tests.h \
common/descriptor_tests.c \
common/events_tests.c \
common/events_tests.h \
common/fdset_tests.c \
common/fdset_tests.h \
common/skiplist_tests.c \
common/skiplist_tests.h \
common/hattrie_tests.c \
common/hattrie_tests.h \
common/slab_tests.c \
common/slab_tests.h \
knot/conf_tests.c \
knot/conf_tests.h \
knot/dthreads_tests.c \
knot/dthreads_tests.h \
knot/journal_tests.c \
knot/journal_tests.h \
knot/server_tests.c \
knot/server_tests.h \
knot/rrl_tests.h \
knot/rrl_tests.c \
zscanner/zscanner_tests.h \
zscanner/zscanner_tests.c \
libknot/dname_tests.h \
libknot/dname_tests.c \
libknot/ztree_tests.h \
libknot/ztree_tests.c \
libknot/wire_tests.h \
libknot/wire_tests.c \
libknot/rrset_tests.c \
libknot/rrset_tests.h \
libknot/sign_tests.c \
libknot/sign_tests.h \
unittests_main.c
unittests_xfr_SOURCES = \
xfr_tests.c \
xfr_tests.h
unittests_LDADD = ../libknotd.la ../libknots.la @LIBOBJS@
unittests_xfr_LDADD = ../libknotd.la ../libknot.la ../libknots.la @LIBOBJS@
sample_conf.rc: files/sample_conf
$(top_srcdir)/resource.sh $(srcdir)/files/sample_conf >$@
......@@ -37,7 +37,7 @@ static int zscanner_tests_run(int argc, char *argv[])
{
int ret;
ret = system(SOURCE_ABSOLUTE_DIR "/src/zscanner/test/run_tests.sh test");
ret = system("/bin/sh ../zscanner/test/run_tests.sh test");
cmp_ok(ret, "==", 0, "zscanner unittests");
return 0;
......
......@@ -19,10 +19,10 @@ $INCLUDE \./includes/include2 _a_.-b-c-./d/. ; Slashed character in file name,
$INCLUDE ./includes/include2 \0320\ \\\"\.\@\*.tld. ; Origin with special chars
5. NS @
$INCLUDE /tmp/zscanner_tests/includes/include2 ; Absolute path without origin
$INCLUDE @abs_builddir@/zscanner_tests/includes/include2 ; Absolute path without origin
6. NS @
$INCLUDE /tmp/zscanner_tests/includes/include2 tld. ; Absolute path with origin
$INCLUDE @abs_builddir@/zscanner_tests/includes/include2 tld. ; Absolute path with origin
7. NS @
; KO
......
$ORIGIN .
$TTL 1
; KO
$INCLUDE /tmp/zscanner_tests/ ; Given file is a directory
$ORIGIN .
$TTL 1
; KO
$INCLUDE @abs_builddir@/zscanner_tests/ ; Given file is a directory
$ORIGIN .
$TTL 1
; KO
$INCLUDE /tmp/zscanner_tests/_ ; File doesn't exist
$ORIGIN .
$TTL 1
; KO
$INCLUDE @abs_builddir@/zscanner_tests/file-doesnt-exist ; File doesn't exist
#!/bin/sh
TESTS_DIR="./cases"
OUTS_DIR="/tmp/zscanner_tests"
TEST_BIN="../../zscanner-tool -m 2"
# If verbose (default - no parameter) mode.
if [ $# -eq 0 ]; then
RESULT_DIR=`mktemp -d /tmp/zscanner_tests.XXXX`
echo "ZSCANNER TEST ${RESULT_DIR}"
fi
# Change working directory due to relative paths usage.
cd `dirname $0`
# Create output directory and copy include zone files.
mkdir -p ${OUTS_DIR}/${TESTS_DIR}
cp -r ${TESTS_DIR}/includes ${OUTS_DIR}
# 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}
# 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
rm -rf ${OUTS_DIR}
return 1
fi
fi
done
if [ $# -eq 0 ]; then
mv ${OUTS_DIR} ${RESULT_DIR}
echo "\nFINISHED ${RESULT_DIR}"
else
rm -rf ${OUTS_DIR}
fi
#!/bin/sh
TESTS_DIR="@abs_srcdir@/cases"
OUTS_DIR="@abs_builddir@/zscanner_tests"
TEST_BIN="@builddir@/../zscanner-tool -m 2"
trap "chmod -R u+rw ${OUTS_DIR} && rm -rf ${OUTS_DIR}" EXIT
if [ $# -eq 0 ]; then
RESULT_DIR=`mktemp -d /tmp/zscanner_tests.XXXX`
echo "ZSCANNER TEST ${RESULT_DIR}"
fi
# Create output directory and copy include zone files.
mkdir -p "${OUTS_DIR}/cases"
cp -r "${TESTS_DIR}/includes" "${OUTS_DIR}"
# Run zscanner on all test zone files.
for file in $( (find "${TESTS_DIR}" -name "*.in"; find "@builddir@/../zscanner/test/cases" -name "*.in") | sort -n); do
fileout="$(basename "${file}" .in).out"
# Run zscanner.
${TEST_BIN} . "${file}" > "${OUTS_DIR}/${fileout}"
# Compare result with a reference one.
cmp -s "${OUTS_DIR}/${fileout}" "${fileout}"
RET=$?
# Check for differences.
if [ $RET -ne 0 ]; then
# If verbose print diff.
if [ $# -eq 0 ]; then
echo "\n=== ${fileout} DIFF ======================"
diff "${OUTS_DIR}/${fileout}" "${fileout}"
fi
fi
done
if [ $# -eq 0 ]; then
mv "${OUTS_DIR}" "${RESULT_DIR}"
echo "\nFINISHED ${RESULT_DIR}"
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment