Generate standalone tests
v2 cover Generate standalone tests
Add support to convert unit tests to standalone scripts that can be run outside the framework. This is almost an RFC, but it doesn't impact the current framework (except for 'make install', but was that ever used?). The scripting is ugly, but I see value in having easily distributable unit tests.
Testing: if you run all standalone tests, concatenating all output to a file, then that file will match test.log after running run_tests.sh. Additionally, all prechecks are preserved, i.e. specific arch and 'check' conditions from unittests.cfg.
Thanks,
drew
v2:
- dropped several changes to run_tests.sh [drew]
- pass DRYRUN through env, not config [drew]
- share "run_all", rather than duplicating it [drew]
- rewrote the script, improving it, and reducing ugliness (well, a bit) [drew]
Andrew Jones (6):
run_tests.sh: share run_all as for_each_unittest
run: check DRYRUN
scripts: Introduce mkstandalone.sh arm/unittests.cfg: changes to be more standalone friendly
Makefile: change 'make install' to install standalone tests
standalone: add documentation to README
.gitignore | 1 + Makefile | 10 +++- README | 10 ++++ arm/run | 12 ++-- arm/unittests.cfg | 10 ++-- config/config-arm-common.mak | 2 - config/config-x86-common.mak | 2 - run_tests.sh | 46 +-------------- scripts/functions.bash | 42 ++++++++++++++ scripts/mkstandalone.sh | 131 +++++++++++++++++++++++++++++++++++++++++++ x86/run | 11 ++-- 11 files changed, 212 insertions(+), 65 deletions(-) create mode 100644 scripts/functions.bash create mode 100755 scripts/mkstandalone.sh
Signature · 1 line
2.4.3
PATCH v2 1/6 run_tests.sh: share run_all as for_each_unittest
To avoid duplicating unittests.cfg parsing code in other scripts, let's put it in a file where it can be shared.
--- run_tests.sh | 46 ++-------------------------------------------- scripts/functions.bash | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 44 deletions(-) create mode 100644 scripts/functions.bash
run_tests.sh +2 -44
@@ -5,6 +5,7 @@ if [ ! -f config.mak ]; then exit fi source config.mak +source scripts/functions.bash config=$TEST_DIR/unittests.cfg qemu=${QEMU:-qemu-system-$ARCH}
@@ -61,49 +62,6 @@ function run() fi } -function run_all() -{ - local config="$1" - local testname - local smp - local kernel - local opts - local groups - local arch - local check - - exec {config_fd}<$config - - while read -u $config_fd line; do - if [[ "$line" =~ ^\[(.*)\]$ ]]; then - run "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" - testname=${BASH_REMATCH[1]} - smp=1 - kernel="" - opts="" - groups="" - arch="" - check="" - elif [[ $line =~ ^file\ *=\ *(.*)$ ]]; then - kernel=$TEST_DIR/${BASH_REMATCH[1]} - elif [[ $line =~ ^smp\ *=\ *(.*)$ ]]; then - smp=${BASH_REMATCH[1]} - elif [[ $line =~ ^extra_params\ *=\ *(.*)$ ]]; then - opts=${BASH_REMATCH[1]} - elif [[ $line =~ ^groups\ *=\ *(.*)$ ]]; then - groups=${BASH_REMATCH[1]} - elif [[ $line =~ ^arch\ *=\ *(.*)$ ]]; then - arch=${BASH_REMATCH[1]} - elif [[ $line =~ ^check\ *=\ *(.*)$ ]]; then - check=${BASH_REMATCH[1]} - fi - done - - run "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" - - exec {config_fd}<&- -} - function usage() { cat <<EOF
@@ -139,4 +97,4 @@ while getopts "g:hv" opt; do esac done -run_all $config +for_each_unittest $config run
scripts/functions.bash new file +42 -0
42 lines not on this page · raw message
Signature · 1 line
2.4.3
PATCH v2 2/6 run: check DRYRUN
In reply to Andrew JonesOnly execute the test if DRYRUN isn't set to yes. This is used by mkstandalone.sh
--- arm/run | 12 +++++++----- x86/run | 11 +++++++---- 2 files changed, 14 insertions(+), 9 deletions(-)
arm/run +7 -5
@@ -44,9 +44,11 @@ fi command="$qemu $M -cpu $processor $chr_testdev" command+=" -display none -serial stdio -kernel" - echo $command "$@" -$command "$@" -ret=$? -echo Return value from qemu: $ret -exit $ret + +if [ "$DRYRUN" != "yes" ]; then + $command "$@" + ret=$? + echo Return value from qemu: $ret + exit $ret +fi
x86/run +7 -4
@@ -44,7 +44,10 @@ fi command="${qemu} -enable-kvm $pc_testdev -vnc none -serial stdio $pci_testdev -kernel" echo ${command} "$@" -${command} "$@" -ret=$? -echo Return value from qemu: $ret -exit $ret + +if [ "$DRYRUN" != "yes" ]; then + ${command} "$@" + ret=$? + echo Return value from qemu: $ret + exit $ret +fi
Signature · 1 line
2.4.3
PATCH v2 3/6 scripts: Introduce mkstandalone.sh
In reply to Andrew JonesThis is a pretty ugly bash script, wrapped around a couple ugly bash scripts, and it generates an ugly sh script. But, it gets the job done. What's the job? Take a unit test and generate a standalone script that can be run on any appropriate system with an appropriate qemu. This makes distributing single, pre-compiled, unit tests easy, even through email, which can be useful for getting test results from a variety of users, or even for deploying the unit test as utility (if it works that way) in a distribution. "Packaging" works like shar, but doesn't use shar, as it's better to avoid the dependency. Can be used to create just one unit test, or all of them ('make standalone'). The standalone test(s) are placed in ./tests.
--- .gitignore | 1 + Makefile | 4 ++ scripts/mkstandalone.sh | 131 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 136 insertions(+) create mode 100755 scripts/mkstandalone.sh
.gitignore +1 -0
@@ -14,3 +14,4 @@ cscope.* /*-run /test.log /msr.out +/tests
Makefile +4 -0
@@ -64,6 +64,9 @@ $(LIBFDT_archive): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS)) -include */.*.d */*/.*.d +standalone: all + @scripts/mkstandalone.sh + install: mkdir -p $(DESTDIR) install $(tests_and_config) $(DESTDIR)
@@ -78,6 +81,7 @@ libfdt_clean: distclean: clean libfdt_clean $(RM) lib/asm config.mak $(TEST_DIR)-run test.log msr.out cscope.* + $(RM) -r tests cscope: common_dirs = lib lib/libfdt lib/asm lib/asm-generic cscope:
scripts/mkstandalone.sh new file +131 -0
131 lines not on this page · raw message
Signature · 1 line
2.4.3
PATCH v2 4/6 arm/unittests.cfg: changes to be more standalone friendly
In reply to Andrew Jones--- arm/unittests.cfg | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
arm/unittests.cfg +5 -5
@@ -11,27 +11,27 @@ # that the configured amount of memory (-m <MB>) are correctly setup # by the framework. # -[selftest::setup] +[selftest-setup] file = selftest.flat smp = 2 extra_params = -m 256 -append 'setup smp=2 mem=256' groups = selftest # Test vector setup and exception handling (kernel mode). -[selftest::vectors-kernel] +[selftest-vectors-kernel] file = selftest.flat extra_params = -append 'vectors-kernel' groups = selftest # Test vector setup and exception handling (user mode). -[selftest::vectors-user] +[selftest-vectors-user] file = selftest.flat extra_params = -append 'vectors-user' groups = selftest # Test SMP support -[selftest::smp] +[selftest-smp] file = selftest.flat -smp = $(getconf _NPROCESSORS_CONF) +smp = `getconf _NPROCESSORS_CONF` extra_params = -append 'smp' groups = selftest
Signature · 1 line
2.4.3
PATCH v2 5/6 Makefile: change 'make install' to install standalone tests
In reply to Andrew Jonesmake install wasn't very useful without also installing scripts for the qemu command lines. I suspect 'make install' was never used. Installing standalone tests could be useful though, so let's do that instead.
--- Makefile | 6 +++--- config/config-arm-common.mak | 2 -- config/config-x86-common.mak | 2 -- 3 files changed, 3 insertions(+), 7 deletions(-)
Makefile +3 -3
@@ -5,7 +5,7 @@ endif include config.mak -DESTDIR := $(PREFIX)/share/qemu/tests +DESTDIR := $(PREFIX)/share/kvm-unit-tests/ .PHONY: arch_clean clean distclean cscope
@@ -67,9 +67,9 @@ $(LIBFDT_archive): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS)) standalone: all @scripts/mkstandalone.sh -install: +install: standalone mkdir -p $(DESTDIR) - install $(tests_and_config) $(DESTDIR) + install tests/* $(DESTDIR) clean: arch_clean $(RM) lib/.*.d $(libcflat) $(cflatobjs)
config/config-arm-common.mak +0 -2
@@ -64,8 +64,6 @@ arm_clean: libfdt_clean asm_offsets_clean ################################################################## -tests_and_config = $(TEST_DIR)/*.flat $(TEST_DIR)/unittests.cfg - generated_files = $(asm-offsets) test_cases: $(generated_files) $(tests-common) $(tests)
config/config-x86-common.mak +0 -2
@@ -43,8 +43,6 @@ tests-common += api/dirty-log tests-common += api/dirty-log-perf endif -tests_and_config = $(TEST_DIR)/*.flat $(TEST_DIR)/unittests.cfg - test_cases: $(tests-common) $(tests) $(TEST_DIR)/%.o: CFLAGS += -std=gnu99 -ffreestanding -I lib -I lib/x86
Signature · 1 line
2.4.3
PATCH v2 6/6 standalone: add documentation to README
In reply to Andrew Jones--- README | 10 ++++++++++ 1 file changed, 10 insertions(+)
README +10 -0
@@ -16,6 +16,16 @@ To select a specific qemu binary, specify the QEMU=<path> environment variable, e.g. QEMU=/tmp/qemu/x86_64-softmmu/qemu-system-x86_64 ./x86-run ./x86/msr.flat +To create and use standalone tests do + ./configure + make standalone + (send tests/some-test somewhere) + (go to somewhere) + ./some-test + +'make install' will install all tests in PREFIX/share/kvm-unit-tests/tests, +each as a standalone test. + Directory structure: .: configure script, top-level Makefile, and run_tests.sh ./config: collection of architecture dependent makefiles
Signature · 1 line
2.4.3
Paolo Bonzini
maintainerQuoted 10 lines · Andrew Jones
Add support to convert unit tests to standalone scripts that can be run outside the framework. This is almost an RFC, but it doesn't impact the current framework (except for 'make install', but was that ever used?). The scripting is ugly, but I see value in having easily distributable unit tests.
Testing: if you run all standalone tests, concatenating all output to a file, then that file will match test.log after running
run_tests.sh. Additionally, all prechecks are preserved, i.e. specific arch and 'check' conditions from unittests.cfg.
This is pretty wicked, but it's indeed useful. Applied. :)
Paolo
Quoted 33 lines
Thanks,
drewv2:
- dropped several changes torun_tests.sh[drew]
- pass DRYRUN through env, not config [drew]
- share "run_all", rather than duplicating it [drew]
- rewrote the script, improving it, and reducing ugliness (well, a bit) [drew]Andrew Jones (6):
run_tests.sh: sharerun_allasfor_each_unittest
run: check DRYRUN
scripts: Introducemkstandalone.sharm/unittests.cfg: changes to be more standalone friendly
Makefile: change 'make install' to install standalone tests
standalone: add documentation to README.gitignore | 1 + Makefile | 10 +++- README | 10 ++++ arm/run | 12 ++-- arm/unittests.cfg | 10 ++-- config/config-arm-common.mak | 2 - config/config-x86-common.mak | 2 - run_tests.sh | 46 +-------------- scripts/functions.bash | 42 ++++++++++++++ scripts/mkstandalone.sh | 131 +++++++++++++++++++++++++++++++++++++++++++ x86/run | 11 ++-- 11 files changed, 212 insertions(+), 65 deletions(-) create mode 100644 scripts/functions.bash create mode 100755 scripts/mkstandalone.sh