Browse Source

Attempt to simplify adding new tests

pull/947/head
Hamish Coleman 3 years ago
parent
commit
ecaba980ba
  1. 4
      CMakeLists.txt
  2. 4
      Makefile.in
  3. 21
      doc/Scripts.md
  4. 49
      scripts/test_harness.sh
  5. 11
      scripts/test_integration.sh
  6. 21
      scripts/test_units.sh
  7. 4
      tests/tests_integration.list
  8. 9
      tests/tests_units.list

4
CMakeLists.txt

@ -313,12 +313,12 @@ enable_testing()
add_test(NAME unit add_test(NAME unit
COMMAND ${CMAKE_COMMAND} -E env COMMAND ${CMAKE_COMMAND} -E env
TOPDIR=${PROJECT_SOURCE_DIR} BINDIR=${PROJECT_BINARY_DIR} TOPDIR=${PROJECT_SOURCE_DIR} BINDIR=${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/scripts/test_units.sh ${PROJECT_SOURCE_DIR}/scripts/test_harness.sh ${PROJECT_SOURCE_DIR}/tests/tests_units.list
) )
add_test(NAME integration add_test(NAME integration
COMMAND ${CMAKE_COMMAND} -E env COMMAND ${CMAKE_COMMAND} -E env
TOPDIR=${PROJECT_SOURCE_DIR} BINDIR=${PROJECT_BINARY_DIR} TOPDIR=${PROJECT_SOURCE_DIR} BINDIR=${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/scripts/test_integration.sh ${PROJECT_SOURCE_DIR}/scripts/test_harness.sh ${PROJECT_SOURCE_DIR}/tests/tests_integration.list
) )
endif(DEFINED UNIX) endif(DEFINED UNIX)

4
Makefile.in

@ -205,10 +205,10 @@ win32/n2n_win32.a: win32
test: test.units test.integration test: test.units test.integration
test.units: tools test.units: tools
scripts/test_units.sh scripts/test_harness.sh tests/tests_units.list
test.integration: $(APPS) test.integration: $(APPS)
scripts/test_integration.sh scripts/test_harness.sh tests/tests_integration.list
.PHONY: lint lint.python lint.ccode lint.shell lint.yaml .PHONY: lint lint.python lint.ccode lint.shell lint.yaml
lint: lint.python lint.ccode lint.shell lint.yaml lint: lint.python lint.ccode lint.shell lint.yaml

21
doc/Scripts.md

@ -98,21 +98,18 @@ Manually test fetching and config:
### `test_harness.sh` ### `test_harness.sh`
This shell script is used to run automated tests during development. It is This shell script is used to run automated tests during development. It is
run with the name of one or more other scripts, which are then run with their run with a testlist filename - pointing at a file containing the list of
output being sent to `*.out` files in the `tests` directory and compared with tests to run.
the matching `*.expected` file in that same dir.
### `scripts/test_units.sh` Each test needs a file containing the expected output `${TESTNAME}.expected`
which is expected to exist in the same directory as the testlist (this dir is
referred to as `${listdir}` below).
This runs all the unit tests via the `test_harness.sh`. Unit tests are those Each test is a program, searched for in several locations, including the
that are testing a small and isolated bit of code. In this project, the unit `${listdir}/../scripts` dir.
tests are the only ones that contribute towards the code coverage report.
### `scripts/test_integration.sh` Each test is run with its output being sent to `*.out` files in the `listdir`
and compared with the expected output.
This runs all the integration tests via the `test_harness.sh`. These are
tests that interact with multiple features and the test is mainly concerned
about the interactions between them (eg, testing an API interface)
### `scripts/test_integration_supernode.sh` ### `scripts/test_integration_supernode.sh`

49
scripts/test_harness.sh

@ -1,9 +1,9 @@
#!/bin/sh #!/bin/sh
# #
# Run with the name of a test list file.
#
# This expects to find the tests in the tools dir or scripts dir and the # This expects to find the tests in the tools dir or scripts dir and the
# expected results in the tests dir. # expected results in the tests dir.
#
# Run with the name(s) of the tests on the commandline
# boilerplate so we can support whaky cmake dirs # boilerplate so we can support whaky cmake dirs
[ -z "$TOPDIR" ] && TOPDIR="." [ -z "$TOPDIR" ] && TOPDIR="."
@ -11,40 +11,37 @@
export TOPDIR export TOPDIR
export BINDIR export BINDIR
if [ -d "$BINDIR/tools" ]; then if [ -z "$1" ]; then
TOOLSDIR="$BINDIR/tools" echo need test list filename
else exit 1
TOOLSDIR="$BINDIR"
fi fi
TESTLIST="$1"
LISTDIR=$(dirname "$TESTLIST")
TESTS=$* TESTS=$(sed -e "s/#.*//" "$TESTLIST")
SCRIPTSDIR="$TOPDIR/scripts"
TESTDATA="$TOPDIR/tests"
# Confirm we have all the tools and data # Actually run the tests
for i in $TESTS; do for i in $TESTS; do
if [ ! -e "$TOOLSDIR/$i" ] && [ ! -e "$SCRIPTSDIR/$i" ]; then # Look in several places for the test program
if [ -e "$BINDIR/$i" ]; then
TEST="$BINDIR/$i"
elif [ -e "$BINDIR/tools/$i" ]; then
TEST="$BINDIR/tools/$i"
elif [ -e "$LISTDIR/../scripts/$i" ]; then
TEST="$LISTDIR/../scripts/$i"
else
echo "Could not find test $i" echo "Could not find test $i"
exit 1 exit 1
fi fi
if [ ! -e "$TESTDATA/$i.expected" ]; then
echo "Could not find testdata $TESTDATA/$i.expected"
exit 1
fi
done
# Actually run the tests if [ ! -e "$LISTDIR/$i.expected" ]; then
for i in $TESTS; do echo "Could not find testdata $LISTDIR/$i.expected"
if [ -e "$TOOLSDIR/$i" ]; then exit 1
TEST="$TOOLSDIR/$i"
elif [ -e "$SCRIPTSDIR/$i" ]; then
TEST="$SCRIPTSDIR/$i"
fi fi
echo "$TEST >$TESTDATA/$i.out" echo "$TEST >$LISTDIR/$i.out"
set -e set -e
"$TEST" >"$TESTDATA/$i.out" "$TEST" >"$LISTDIR/$i.out"
cmp "$TESTDATA/$i.expected" "$TESTDATA/$i.out" cmp "$LISTDIR/$i.expected" "$LISTDIR/$i.out"
set +e set +e
done done

11
scripts/test_integration.sh

@ -1,11 +0,0 @@
#!/bin/sh
#
# Run all the integration tests via the test harness
# boilerplate so we can support whaky cmake dirs
[ -z "$TOPDIR" ] && TOPDIR=.
[ -z "$BINDIR" ] && BINDIR=.
export TOPDIR
export BINDIR
${TOPDIR}/scripts/test_harness.sh test_integration_supernode.sh

21
scripts/test_units.sh

@ -1,21 +0,0 @@
#!/bin/sh
#
# Run all the unit tests via the test harness
# boilerplate so we can support whaky cmake dirs
[ -z "$TOPDIR" ] && TOPDIR=.
[ -z "$BINDIR" ] && BINDIR=.
export TOPDIR
export BINDIR
TESTS="
tests-auth
tests-compress
tests-elliptic
tests-hashing
tests-transform
tests-wire
"
# shellcheck disable=SC2086
${TOPDIR}/scripts/test_harness.sh $TESTS

4
tests/tests_integration.list

@ -0,0 +1,4 @@
#
# The integration tests
test_integration_supernode.sh

9
tests/tests_units.list

@ -0,0 +1,9 @@
#
# The unit tests
tests-auth
tests-compress
tests-elliptic
tests-hashing
tests-transform
tests-wire
Loading…
Cancel
Save