Commit cfd96072 authored by Daniel Salzman's avatar Daniel Salzman

zscanner: reduce test building

parent c1e09ce4
......@@ -59,7 +59,7 @@
# zscanner
/src/zscanner/tests/tmp/
/src/zscanner/tests/runtests
/src/zscanner/tests/unittests
/src/zscanner/tests/zscanner-tool
# Binaries
......
......@@ -7,3 +7,6 @@ check_LIBRARIES = libtap.a
check_PROGRAMS = \
runtests
EXTRA_DIST = \
tap/libtap.sh
# -*- mode: makefile; -*-
# vim: syntax=automake
AM_CPPFLAGS = \
-I$(top_srcdir)/src
LDADD = \
$(top_builddir)/src/zscanner/libzscanner.la
tests_zscanner_tool_SOURCES = \
tests/zscanner-tool.c \
tests/tests.h \
tests/tests.c \
tests/processing.h \
tests/processing.c
check_PROGRAMS = \
tests/runtests \
tests/zscanner-tool
dist_check_SCRIPTS = \
tests/zscanner.sh
check_SCRIPTS = \
tests/unittests
AM_CPPFLAGS = \
-I$(top_srcdir)/src
CLEANFILES += $(check_SCRIPTS)
edit = sed \
-e 's|@top_srcdir[@]|$(abs_top_srcdir)|g' \
-e 's|@top_builddir[@]|$(abs_top_builddir)|g'
tests_runtests_CPPFLAGS = \
-DSOURCE='"$(abs_srcdir)/tests"' \
-DBUILD='"$(abs_builddir)/tests"'
tests/unittests:
$(edit) < $(top_srcdir)/src/zscanner/$@.in > $(top_builddir)/src/zscanner/$@
chmod +x $(top_builddir)/src/zscanner/$@
check-compile-only: $(check_PROGRAMS)
check-local: $(check_PROGRAMS)
cd tests && ./runtests -l $(abs_srcdir)/tests/TESTS
tests_zscanner_tool_SOURCES = \
tests/zscanner-tool.c \
tests/tests.h \
tests/tests.c \
tests/processing.h \
tests/processing.c
tests_zscanner_tool_LDADD = libzscanner.la
EXTRA_DIST += \
tests/TESTS \
tests/zscanner-TESTS \
tests/data \
tests/tap/libtap.sh
$(top_builddir)/libtap/runtests \
-s $(top_srcdir)/src/zscanner/tests \
-b $(top_builddir)/src/zscanner/tests \
$(top_builddir)/src/zscanner/tests/unittests
EXTRA_DIST += \
tests/unittests.in \
tests/TESTS \
tests/data
zscanner.sh
00-0_general
00-1_general
01_owner
02_class
03_rrttl
04-0_ORIGIN
04-1_ORIGIN
04-2_ORIGIN
04-3_ORIGIN
04-4_ORIGIN
04-5_ORIGIN
04-6_ORIGIN
04-7_ORIGIN
04-8_ORIGIN
04-9_ORIGIN
05-0_TTL
05-1_TTL
05-2_TTL
05-3_TTL
05-4_TTL
06-0_INCLUDE
06-1_INCLUDE
06-2_INCLUDE
06-3_INCLUDE
06-4_INCLUDE
06-5_INCLUDE
06-6_INCLUDE
06-7_INCLUDE
06-8_INCLUDE
10_A
11_AAAA
12_TXT
13_SPF
14_NS
15_CNAME
16_PTR
17_DNAME
18_MX
19_AFSDB
20_RT
21_KX
22_HINFO
23_MINFO
24_RP
25_SOA
26_SRV
27_NAPTR
28_TYPE
29_CERT
30_KEY
31_DNSKEY
32_APL
33_DS
34_SSHFP
35_IPSECKEY
36_RRSIG
37_NSEC
38_DHCID
39_NSEC3
40_NSEC3PARAM
41_TLSA
42_LOC
43_EUI48
44_EUI64
45_NID
46_L32
47_L64
48_LP
This diff is collapsed.
# Shell function library for test cases.
#
# Note that while many of the functions in this library could benefit from
# using "local" to avoid possibly hammering global variables, Solaris /bin/sh
# doesn't support local and this library aspires to be portable to Solaris
# Bourne shell. Instead, all private variables are prefixed with "tap_".
#
# This file provides a TAP-compatible shell function library useful for
# writing test cases. It is part of C TAP Harness, which can be found at
# <http://www.eyrie.org/~eagle/software/c-tap-harness/>.
#
# Written by Russ Allbery <rra@stanford.edu>
# Copyright 2009, 2010, 2011, 2012 Russ Allbery <rra@stanford.edu>
# Copyright 2006, 2007, 2008, 2013
# The Board of Trustees of the Leland Stanford Junior University
#
# 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.
# Print out the number of test cases we expect to run.
plan () {
count=1
planned="$1"
failed=0
echo "1..$1"
trap finish 0
}
# Prepare for lazy planning.
plan_lazy () {
count=1
planned=0
failed=0
trap finish 0
}
# Report the test status on exit.
finish () {
tap_highest=`expr "$count" - 1`
if [ "$planned" = 0 ] ; then
echo "1..$tap_highest"
planned="$tap_highest"
fi
tap_looks='# Looks like you'
if [ "$planned" -gt 0 ] ; then
if [ "$planned" -gt "$tap_highest" ] ; then
if [ "$planned" -gt 1 ] ; then
echo "$tap_looks planned $planned tests but only ran" \
"$tap_highest"
else
echo "$tap_looks planned $planned test but only ran" \
"$tap_highest"
fi
elif [ "$planned" -lt "$tap_highest" ] ; then
tap_extra=`expr "$tap_highest" - "$planned"`
if [ "$planned" -gt 1 ] ; then
echo "$tap_looks planned $planned tests but ran" \
"$tap_extra extra"
else
echo "$tap_looks planned $planned test but ran" \
"$tap_extra extra"
fi
elif [ "$failed" -gt 0 ] ; then
if [ "$failed" -gt 1 ] ; then
echo "$tap_looks failed $failed tests of $planned"
else
echo "$tap_looks failed $failed test of $planned"
fi
elif [ "$planned" -gt 1 ] ; then
echo "# All $planned tests successful or skipped"
else
echo "# $planned test successful or skipped"
fi
fi
}
# Skip the entire test suite. Should be run instead of plan.
skip_all () {
tap_desc="$1"
if [ -n "$tap_desc" ] ; then
echo "1..0 # skip $tap_desc"
else
echo "1..0 # skip"
fi
exit 0
}
# ok takes a test description and a command to run and prints success if that
# command is successful, false otherwise. The count starts at 1 and is
# updated each time ok is printed.
ok () {
tap_desc="$1"
if [ -n "$tap_desc" ] ; then
tap_desc=" - $tap_desc"
fi
shift
if "$@" ; then
echo ok "$count$tap_desc"
else
echo not ok "$count$tap_desc"
failed=`expr $failed + 1`
fi
count=`expr $count + 1`
}
# Skip the next test. Takes the reason why the test is skipped.
skip () {
echo "ok $count # skip $*"
count=`expr $count + 1`
}
# Report the same status on a whole set of tests. Takes the count of tests,
# the description, and then the command to run to determine the status.
ok_block () {
tap_i=$count
tap_end=`expr $count + $1`
shift
while [ "$tap_i" -lt "$tap_end" ] ; do
ok "$@"
tap_i=`expr $tap_i + 1`
done
}
# Skip a whole set of tests. Takes the count and then the reason for skipping
# the test.
skip_block () {
tap_i=$count
tap_end=`expr $count + $1`
shift
while [ "$tap_i" -lt "$tap_end" ] ; do
skip "$@"
tap_i=`expr $tap_i + 1`
done
}
# Portable variant of printf '%s\n' "$*". In the majority of cases, this
# function is slower than printf, because the latter is often implemented
# as a builtin command. The value of the variable IFS is ignored.
#
# This macro must not be called via backticks inside double quotes, since this
# will result in bizarre escaping behavior and lots of extra backslashes on
# Solaris.
puts () {
cat << EOH
$@
EOH
}
# Run a program expected to succeed, and print ok if it does and produces the
# correct output. Takes the description, expected exit status, the expected
# output, the command to run, and then any arguments for that command.
# Standard output and standard error are combined when analyzing the output of
# the command.
#
# If the command may contain system-specific error messages in its output,
# add strip_colon_error before the command to post-process its output.
ok_program () {
tap_desc="$1"
shift
tap_w_status="$1"
shift
tap_w_output="$1"
shift
tap_output=`"$@" 2>&1`
tap_status=$?
if [ $tap_status = $tap_w_status ] \
&& [ x"$tap_output" = x"$tap_w_output" ] ; then
ok "$tap_desc" true
else
echo "# saw: ($tap_status) $tap_output"
echo "# not: ($tap_w_status) $tap_w_output"
ok "$tap_desc" false
fi
}
# Strip a colon and everything after it off the output of a command, as long
# as that colon comes after at least one whitespace character. (This is done
# to avoid stripping the name of the program from the start of an error
# message.) This is used to remove system-specific error messages (coming
# from strerror, for example).
strip_colon_error() {
tap_output=`"$@" 2>&1`
tap_status=$?
tap_output=`puts "$tap_output" | sed 's/^\([^ ]* [^:]*\):.*/\1/'`
puts "$tap_output"
return $tap_status
}
# Bail out with an error message.
bail () {
echo 'Bail out!' "$@"
exit 255
}
# Output a diagnostic on standard error, preceded by the required # mark.
diag () {
echo '#' "$@"
}
# Search for the given file first in $BUILD and then in $SOURCE and echo the
# path where the file was found, or the empty string if the file wasn't
# found.
#
# This macro uses puts, so don't run it using backticks inside double quotes
# or bizarre quoting behavior will happen with Solaris sh.
test_file_path () {
if [ -n "$BUILD" ] && [ -f "$BUILD/$1" ] ; then
puts "$BUILD/$1"
elif [ -n "$SOURCE" ] && [ -f "$SOURCE/$1" ] ; then
puts "$SOURCE/$1"
else
echo ''
fi
}
# Create $BUILD/tmp for use by tests for storing temporary files and return
# the path (via standard output).
#
# This macro uses puts, so don't run it using backticks inside double quotes
# or bizarre quoting behavior will happen with Solaris sh.
test_tmpdir () {
if [ -z "$BUILD" ] ; then
tap_tmpdir="./tmp"
else
tap_tmpdir="$BUILD"/tmp
fi
if [ ! -d "$tap_tmpdir" ] ; then
mkdir "$tap_tmpdir" || bail "Error creating $tap_tmpdir"
fi
puts "$tap_tmpdir"
}
#!/bin/sh
. "$SOURCE"/tap/libtap.sh
SOURCE=@top_srcdir@/src/zscanner/tests
BUILD=@top_builddir@/src/zscanner/tests
. @top_srcdir@/libtap/tap/libtap.sh
cd "$BUILD"
TMPDIR=$(test_tmpdir)
......@@ -14,13 +18,13 @@ for a in 1 2 3 4 5 6; do
cat "$TESTS_DIR"/includes/include"$a" > "$TMPDIR"/includes/include"$a";
done
for case in $(cat "$SOURCE"/zscanner-TESTS); do
for case in $(cat "$SOURCE"/TESTS); do
casein=$(test_file_path data/"$case".in)
caseout=$(test_file_path data/"$case".out)
filein="$TMPDIR"/"$case".in
fileout="$TMPDIR"/"$case".out
sed -e "s|@TMPDIR@|$TMPDIR|;s|@SOURCE@|$SOURCE|;" < "$casein" > "$filein"
sed -e "s|@TMPDIR@|$TMPDIR|;" < "$casein" > "$filein"
diag $(ls "$filein")
"$ZSCANNER_TOOL" -m 2 . "$filein" > "$fileout"
......
00-0_general
00-1_general
01_owner
02_class
03_rrttl
04-0_ORIGIN
04-1_ORIGIN
04-2_ORIGIN
04-3_ORIGIN
04-4_ORIGIN
04-5_ORIGIN
04-6_ORIGIN
04-7_ORIGIN
04-8_ORIGIN
04-9_ORIGIN
05-0_TTL
05-1_TTL
05-2_TTL
05-3_TTL
05-4_TTL
06-0_INCLUDE
06-1_INCLUDE
06-2_INCLUDE
06-3_INCLUDE
06-4_INCLUDE
06-5_INCLUDE
06-6_INCLUDE
06-7_INCLUDE
06-8_INCLUDE
10_A
11_AAAA
12_TXT
13_SPF
14_NS
15_CNAME
16_PTR
17_DNAME
18_MX
19_AFSDB
20_RT
21_KX
22_HINFO
23_MINFO
24_RP
25_SOA
26_SRV
27_NAPTR
28_TYPE
29_CERT
30_KEY
31_DNSKEY
32_APL
33_DS
34_SSHFP
35_IPSECKEY
36_RRSIG
37_NSEC
38_DHCID
39_NSEC3
40_NSEC3PARAM
41_TLSA
42_LOC
43_EUI48
44_EUI64
45_NID
46_L32
47_L64
48_LP
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