svn commit: r320862 - stable/11/tests/sys/opencrypto

Ngie Cooper ngie at FreeBSD.org
Mon Jul 10 05:34:38 UTC 2017


Author: ngie
Date: Mon Jul 10 05:34:37 2017
New Revision: 320862
URL: https://svnweb.freebsd.org/changeset/base/320862

Log:
  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.

Modified:
  stable/11/tests/sys/opencrypto/Makefile
  stable/11/tests/sys/opencrypto/runtests.sh
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/tests/sys/opencrypto/Makefile
==============================================================================
--- stable/11/tests/sys/opencrypto/Makefile	Mon Jul 10 05:16:07 2017	(r320861)
+++ stable/11/tests/sys/opencrypto/Makefile	Mon Jul 10 05:34:37 2017	(r320862)
@@ -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}

Modified: stable/11/tests/sys/opencrypto/runtests.sh
==============================================================================
--- stable/11/tests/sys/opencrypto/runtests.sh	Mon Jul 10 05:16:07 2017	(r320861)
+++ stable/11/tests/sys/opencrypto/runtests.sh	Mon Jul 10 05:34:37 2017	(r320862)
@@ -29,21 +29,34 @@
 # $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)
 sysctl kern.cryptodevallowsoft=1
@@ -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


More information about the svn-src-all mailing list