From a0fc6fa93fde8d5691259f46ff15136687d2d899 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Thu, 1 Jun 2017 19:58:40 +0000 Subject: [PATCH] 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. MFC after: 2 weeks Sponsored by: Dell EMC Isilon --- tests/sys/opencrypto/runtests.sh | 34 +++++++++++++++++++------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/tests/sys/opencrypto/runtests.sh b/tests/sys/opencrypto/runtests.sh index 26c673a40b5f..7886cdb49019 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