diff options
author | ngie <ngie@FreeBSD.org> | 2017-07-10 05:34:37 +0000 |
---|---|---|
committer | ngie <ngie@FreeBSD.org> | 2017-07-10 05:34:37 +0000 |
commit | bf0e780fc7230af85f770e016e165fadff417a12 (patch) | |
tree | d550bbec0e8c7c57235cbca836a097f401417a1d /tests | |
parent | d890b320abf266f4bf2e39be00bf3156e6c40d42 (diff) | |
download | FreeBSD-src-bf0e780fc7230af85f770e016e165fadff417a12.zip FreeBSD-src-bf0e780fc7230af85f770e016e165fadff417a12.tar.gz |
MFC r319455,r319456:
r319455:
Fix up `TEST_METADATA`
- `TEST_METADATA.foo` should be `TEST_METADATA.run_tests`: this will unbreak
trying to run the tests on a system without python installed in $PATH.
- The tests require root because they load aesni(4) and/or cryptodev(4) if
not already loaded.
r319456:
tests/sys/opencrypto/runtests: apply minor polish to test script
- Refactor kld loading/unloading logic:
-- Use a loop instead of an unrolled one.
-- Check for the module being loaded before trying to load it, to reduce
noise when loading modules that are already loaded.
-- Don't mute stderr from kldload -- it could be potentially useful to
the tester.
-- In the event that the test script was terminated early, it would leave
the modules still attached to the system (which is undesirable).
Always unload the modules at test end with EXIT/SIGINT/SIGTERM so the
system is returned to its former operating state as best possible.
Unload the modules in reverse order, in part for consistency and/or
dependency reasons.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/sys/opencrypto/Makefile | 4 | ||||
-rwxr-xr-x | tests/sys/opencrypto/runtests.sh | 34 |
2 files changed, 23 insertions, 15 deletions
diff --git a/tests/sys/opencrypto/Makefile b/tests/sys/opencrypto/Makefile index 17b9850..1493108 100644 --- a/tests/sys/opencrypto/Makefile +++ b/tests/sys/opencrypto/Makefile @@ -7,7 +7,9 @@ BINDIR= ${TESTSDIR} PLAIN_TESTS_SH= runtests -TEST_METADATA.foo+=required_programs="python" +TEST_METADATA.runtests+= required_programs="python" +TEST_METADATA.runtests+= required_user="root" + PYMODULES= cryptodev.py cryptodevh.py cryptotest.py dpkt.py ${PACKAGE}FILES+= ${PYMODULES} diff --git a/tests/sys/opencrypto/runtests.sh b/tests/sys/opencrypto/runtests.sh index 26c673a..7886cdb 100755 --- a/tests/sys/opencrypto/runtests.sh +++ b/tests/sys/opencrypto/runtests.sh @@ -29,20 +29,33 @@ # $FreeBSD$ # -set -e +set -ex if [ ! -d /usr/local/share/nist-kat ]; then echo 'Skipping, nist-kat package not installed for test vectors.' exit 0 fi -if kldload aesni 2>/dev/null; then - unloadaesni=1 -fi +loaded_modules= +cleanup_tests() +{ + trap - EXIT INT TERM -if kldload cryptodev 2>/dev/null; then - unloadcdev=1 -fi + set +e + + # Unload modules in reverse order + for loaded_module in $(echo $loaded_modules | tr ' ' '\n' | sort -r); do + kldunload $loaded_module + done +} +trap cleanup_tests EXIT INT TERM + +for required_module in aesni cryptodev; do + if ! kldstat -q -m $required_module; then + kldload $required_module + loaded_modules="$loaded_modules $required_module" + fi +done # Run software crypto test oldcdas=$(sysctl -e kern.cryptodevallowsoft) @@ -51,10 +64,3 @@ sysctl kern.cryptodevallowsoft=1 python $(dirname $0)/cryptotest.py sysctl "$oldcdas" - -if [ x"$unloadcdev" = x"1" ]; then - kldunload cryptodev -fi -if [ x"$unloadaesni" = x"1" ]; then - kldunload aesni -fi |