Skip to content

Commit

Permalink
Merge pull request bgpsecurity#42 from rhansen/more-make-check-fixes
Browse files Browse the repository at this point in the history
Reviewed-by: David Mandelberg <[email protected]>
  • Loading branch information
rhansen committed Apr 22, 2016
2 parents 7bf7683 + 4fb936e commit 47382b7
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 63 deletions.
6 changes: 3 additions & 3 deletions bin/rpki-object/create_object/tests/empty_3779.sh.in
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/sh -e
#!/bin/sh

@SETUP_ENVIRONMENT@

OUTDIR="$TESTS_BUILDDIR/empty_3779"
rm -rf "$OUTDIR"
mkdir "$OUTDIR"
try rm -rf "$OUTDIR"
try mkdir "$OUTDIR"

TEST_LOG_NAME=empty_3779
TEST_LOG_DIR="$OUTDIR"
Expand Down
38 changes: 22 additions & 16 deletions mk/asn-files.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,31 @@ ASN_GENERATION_DEPS = \
# http://www.gnu.org/software/automake/manual/html_node/Multiple-Outputs.html
# for an overview.
$(ASN_C_FILES) $(ASN_H_FILES): $(ASN_GENERATION_DEPS)
$(AM_V_GEN)tmpdir=`$(MKTEMP_DIR)` && \
base=`echo "$(@F)" | $(SED) "s/\\.[ch]\$$//"` && \
$(AM_V_GEN)pecho() { printf %s\\n "$$*"; } ; \
log() { pecho "$$@"; } ; \
error() { log "ERROR: $$@" >&2; } ; \
fatal() { error "$$@"; exit 1; } ; \
try() { "$$@" || fatal "'$$@' failed"; } ; \
tmpdir=$$(try $(MKTEMP_DIR)) || exit 1; \
base=$$(echo "$(@F)" | try $(SED) "s/\\.[ch]\$$//") || exit 1; \
for f in $(ASN_BUILT_FILES); do \
dir=`dirname "$$f"` && \
mkdir -p "$$tmpdir/$$dir" && \
cp "$$f" "$$tmpdir/$$dir"; \
done && \
dir=$$(try dirname "$$f") || exit 1; \
try mkdir -p "$$tmpdir/$$dir"; \
try cp "$$f" "$$tmpdir/$$dir"; \
done; \
for f in $(ASN_SOURCE_FILES); do \
dir=`dirname "$$f"` && \
mkdir -p "$$tmpdir/$$dir" && \
cp "$(srcdir)/$$f" "$$tmpdir/$$dir"; \
done && \
cd "$$tmpdir/$(@D)" && \
dir=$$(try dirname "$$f") || exit 1; \
try mkdir -p "$$tmpdir/$$dir"; \
try cp "$(srcdir)/$$f" "$$tmpdir/$$dir"; \
done; \
try cd "$$tmpdir/$(@D)"; \
TEST_LOG_NAME="$(@F)" \
TEST_LOG_DIR="$(abs_builddir)/$(@D)" \
STRICT_CHECKS=0 \
$(LOG_COMPILER) \
$(abs_top_builddir)/lib/casn/asn_gen/asn_gen "$${base}.asn" && \
cd "$(abs_builddir)" && \
mkdir -p "$(@D)" && \
cp "$$tmpdir/$@" "$(@D)" && \
rm -rf "$$tmpdir"
$(abs_top_builddir)/lib/casn/asn_gen/asn_gen "$${base}.asn" \
|| fatal "'$(LOG_COMPILER) asn_gen $${base}.asn' failed"; \
try cd "$(abs_builddir)"; \
try mkdir -p "$(@D)"; \
try cp "$$tmpdir/$@" "$(@D)"; \
try rm -rf "$$tmpdir"
4 changes: 3 additions & 1 deletion mk/tests-environment.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Anything that uses $(LOG_COMPILER) before "make all" finishes should
## depend on this.
LOG_COMPILER_DEPS = \
etc/envir.setup \
lib/util/shell_utils \
tests/setup_test_environment.sh \
tests/test.include
LOG_COMPILER = $(abs_top_builddir)/tests/setup_test_environment.sh
Expand All @@ -14,7 +16,7 @@ TAP_LOG_COMPILER = $(LOG_COMPILER)
# show the individual TAP test cases; the return value of the TAP test
# scripts determine pass or fail as usual)
TAP_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
$(top_srcdir)/build-aux/tap-driver.sh --ignore-exit --merge
$(top_srcdir)/build-aux/tap-driver.sh --ignore-exit
EXTRA_DIST += tests/tap4sh.sh

EXTRA_DIST += etc/test.conf
Expand Down
7 changes: 5 additions & 2 deletions tests/conformance/scripts/run_tests.tap.in
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,16 @@ done
for BAD_SINGLE_FILE in bad*; do
reset_db
xfail=--xfail=ignored
skip=
case ${BAD_SINGLE_FILE} in
badGBRExtraProperty.gbr);;
badGBRNoContact.gbr);;
badGBRNotVCard.gbr) xfail=; skip="--skip=see issue #41";;
*) xfail=;;
esac
t4s_testcase ${xfail:+"${xfail}"} "BAD_SINGLE_FILE=${BAD_SINGLE_FILE}" '
add_file bad -f "$BAD_SINGLE_FILE"'
t4s_testcase ${xfail:+"${xfail}"} ${skip:+"${skip}"} \
"BAD_SINGLE_FILE=${BAD_SINGLE_FILE}" \
'add_file bad -f "$BAD_SINGLE_FILE"'
done

for CRL_CERT in CRL*.cer; do
Expand Down
52 changes: 35 additions & 17 deletions tests/setup_test_environment.sh.in
Original file line number Diff line number Diff line change
@@ -1,50 +1,68 @@
#!/bin/sh -e
#!/bin/sh

export TESTS_TOP_BUILDDIR="$(cd "@abs_top_builddir@" && pwd)"
export TESTS_TOP_SRCDIR="$(cd "@abs_top_srcdir@" && pwd)"
export TESTS_INCLUDE_CONFIG="$TESTS_TOP_BUILDDIR/tests/test.conf"
# These commands don't use try/fatal because they need to be run
# before @SETUP_ENVIRONMENT@.
TESTS_TOP_BUILDDIR=$(cd "@abs_top_builddir@" && pwd) \
&& export TESTS_TOP_BUILDDIR \
|| { printf %s\\n "Error getting TESTS_TOP_BUILDDIR" >&2; exit 1; }
TESTS_TOP_SRCDIR=$(cd "@abs_top_srcdir@" && pwd) \
&& export TESTS_TOP_SRCDIR \
|| { printf %s\\n "Error getting TESTS_TOP_SRCDIR" >&2; exit 1; }

@SETUP_ENVIRONMENT@

. "$TESTS_TOP_BUILDDIR/tests/test.include"
export TESTS_INCLUDE_CONFIG="$TESTS_TOP_BUILDDIR/tests/test.conf"

use_config_file "$TESTS_INCLUDE_CONFIG"

usage() {
cat <<EOF
Usage: $0 <command> [<arg>...]
EOF
}

PROG="$1"
shift
shift || usage_fatal "missing command"

# Determine and export TESTS_BUILDDIR and TESTS_SRCDIR, which are the paths to
# $PROG's directory in builddir and srcdir respectively.
PROG_DIR="$(cd "$(dirname "$PROG")" && pwd)"
PROG_DIR=$(try dirname "${PROG}") || exit 1
PROG_DIR=$(try cd "${PROG_DIR}"; try pwd) || exit 1
case "$PROG_DIR" in
"$TESTS_TOP_BUILDDIR" | "$TESTS_TOP_SRCDIR")
export TESTS_BUILDDIR="$TESTS_TOP_BUILDDIR"
export TESTS_SRCDIR="$TESTS_TOP_SRCDIR"
;;
"$TESTS_TOP_BUILDDIR"/*)
export TESTS_BUILDDIR="$PROG_DIR"
export TESTS_SRCDIR="$(echo "$PROG_DIR" | \
sed "s,^$TESTS_TOP_BUILDDIR,$TESTS_TOP_SRCDIR,")"
TESTS_SRCDIR=$(printf %s\\n "$PROG_DIR" |
try sed "s,^$TESTS_TOP_BUILDDIR,$TESTS_TOP_SRCDIR,") || exit 1
export TESTS_SRCDIR
;;
"$TESTS_TOP_SRCDIR"/*)
export TESTS_BUILDDIR="$(echo "$PROG_DIR" | \
sed "s,^$TESTS_TOP_SRCDIR,$TESTS_TOP_BUILDDIR,")"
TESTS_BUILDDIR=$(printf %s\\n "$PROG_DIR" |
try sed "s,^$TESTS_TOP_SRCDIR,$TESTS_TOP_BUILDDIR,") || exit 1
export TESTS_BUILDDIR
export TESTS_SRCDIR="$PROG_DIR"
;;
esac

shebang=$(printf %s "#!" | od -t x1 -A n) || exit 1
magic=$(od -N 2 -t x1 -A n "${PROG}") || exit 1
shebang=$(printf %s "#!" | try od -t x1 -A n) || exit 1
magic=$(try od -N 2 -t x1 -A n "${PROG}") || exit 1
case ${magic} in
# don't run valgrind on the interpreter, as that is unlikely to be
# useful, will unnecessarily slow down the tests, and will produce
# lots of uninteresting log output
"${shebang}")
"$PROG" "$@" || exit $?
"${PROG}" "$@"
;;

*)
test -n "$TEST_LOG_NAME" || TEST_LOG_NAME=check
test -n "$TEST_LOG_DIR" || TEST_LOG_DIR=`dirname "$PROG"`
test -n "$TEST_LOG_DIR" || TEST_LOG_DIR=$(try dirname "$PROG") \
|| exit 1
test -n "$STRICT_CHECKS" || STRICT_CHECKS=1
run `basename "$PROG"` "$PROG" "$@" || exit $?
basename_PROG=$(try basename "$PROG") || exit 1
run "${basename_PROG}" "$PROG" "$@"
;;
esac
esac || { ret=$?; error "'${PROG} $@' failed"; exit "${ret}"; }
54 changes: 33 additions & 21 deletions tests/tap4sh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
# https://github.com/rhansen/tap4sh

t4s_version_major=1
t4s_version_minor=5
t4s_version_minor=6
t4s_version=${t4s_version_major}.${t4s_version_minor}

t4s_usage() {
Expand Down Expand Up @@ -112,6 +112,17 @@ t4s_discard_last_args() {
printf \\n
}

# Work around a bug in old versions of the NetBSD shell:
# http://gnats.netbsd.org/49595
# NetBSD's unset command has non-zero exit status if the variable is
# already unset. If 'set -e' is in effect, this causes the shell to
# immediately exit without an error message. To work around this,
# ensure that the variable is set before unsetting it.
t4s_unset() {
eval "$1="
unset "$1"
}

## setup and cleanup

# internal helper
Expand All @@ -133,19 +144,19 @@ t4s_finalize() {
exit "${t4s_ret}"
}

unset t4s_setup_done
t4s_unset t4s_setup_done

# prepare to run tests
#
t4s_setup() {
t4s_testnum=0
t4s_ret=0
unset t4s_is_done
unset t4s_bailout_msg
t4s_unset t4s_is_done
t4s_unset t4s_bailout_msg
t4s_do_bailout=true
t4s_setup_done=true
unset t4s_exit_hook
unset t4s_exit_reason
t4s_unset t4s_exit_hook
t4s_unset t4s_exit_reason
trap 't4s_finalize' EXIT
for t4s_setup_sig in HUP INT TERM; do
trap "t4s_exit_reason=SIG${t4s_setup_sig}; exit 1" "${t4s_setup_sig}"
Expand All @@ -159,7 +170,7 @@ t4s_setup() {
shift
set -- "${t4s_arg%%=*}" "${t4s_arg#*=}" "$@"
continue;;
-h|--help) unset t4s_do_bailout; t4s_usage; exit 0;;
-h|--help) t4s_unset t4s_do_bailout; t4s_usage; exit 0;;
--exit-hook) shift; t4s_exit_hook=$1;;
--) shift; break;;
-*) t4s_usage_fatal "unknown option: '$1'";;
Expand All @@ -170,7 +181,7 @@ t4s_setup() {
[ "$#" -eq 0 ] || t4s_usage_fatal "unknown argument: '$1'"
}

unset t4s_in_test_script
t4s_unset t4s_in_test_script

# abort the test script
#
Expand Down Expand Up @@ -262,9 +273,9 @@ EOF
}
type=pass
unset t4s_needs
unset t4s_gives
unset t4s_skipmsg
t4s_unset t4s_needs
t4s_unset t4s_gives
t4s_unset t4s_skipmsg
while [ "$#" -gt 0 ]; do
arg=$1
case $1 in
Expand Down Expand Up @@ -453,6 +464,7 @@ t rmnum2
b error
:rmnum2
h
b skip
# extract the skip message
:skip
Expand Down Expand Up @@ -518,11 +530,11 @@ s/.*/t4s_tap_error=&/p
# variable for each component
#
t4s_parse_tap_line() {
unset t4s_tap_status
unset t4s_tap_testnum
unset t4s_tap_skip
unset t4s_tap_todo
unset t4s_tap_desc
t4s_unset t4s_tap_status
t4s_unset t4s_tap_testnum
t4s_unset t4s_tap_skip
t4s_unset t4s_tap_todo
t4s_unset t4s_tap_desc
while IFS= read -r t4s_ptl_line; do
case ${t4s_ptl_line} in
t4s_tap_line=*) continue;;
Expand Down Expand Up @@ -556,7 +568,7 @@ t4s_subtests() {
|| t4s_fatal "must run t4s_setup first"

exec 3>&1
unset t4s_subtests_bailout
t4s_unset t4s_subtests_bailout
t4s_subtests_failed=0
t4s_to_eval=$(
exec 4>&1 1>&3
Expand Down Expand Up @@ -631,12 +643,12 @@ EOF
}
testnum_offset=${t4s_testnum}
{
unset t4s_setup_done
t4s_unset t4s_setup_done
("$@") 3>&- 4>&-
} | {
unset plan
t4s_unset plan
firstline=true
unset plan_on_last
t4s_unset plan_on_last
t4s_testnum=0
s='[[:space:]]'
Expand Down Expand Up @@ -695,7 +707,7 @@ EOF
t4s_debug "t4s_subtests: misc line: ${line}"
t4s_pecho "${line}"
fi
unset firstline
t4s_unset firstline
done
t4s_debug "t4s_subtests: done parsing subtest output"
[ -n "${plan+set}" ] || t4s_subtests_bailout "${pfx}no TAP plan"
Expand Down
5 changes: 2 additions & 3 deletions tests/test.include.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# envir.setup that are not correct for tests (e.g. $PATH mangling).
#
# This file should not be included directly by regular scripts. It should only
# be included via @SETUP_ENVIRONMENT@ or by setup_test_environment.sh, which
# does bootstrapping for @SETUP_ENVIRONMENT@.
# be included via @SETUP_ENVIRONMENT@.

# add all binaries to the path
BIN_DIRS="`@MKTEMP@`"
Expand Down Expand Up @@ -57,7 +56,7 @@ check_num_output_lines()

run_bg () {
LOG="$1"
shift || exit 1
shift || fatal "run_bg() usage error: log tag missing"
[ "$#" -gt 0 ] || {
printf %s\\n "ERROR: run_bg(): must specify command to run" >&2
exit 1
Expand Down

0 comments on commit 47382b7

Please sign in to comment.