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
This commit is contained in:
parent
5239532a82
commit
cdc66979da
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user