From owner-svn-src-all@freebsd.org Thu Jun 1 19:58:41 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id EFA36B7D94D; Thu, 1 Jun 2017 19:58:41 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id BEE1864F0A; Thu, 1 Jun 2017 19:58:41 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v51Jwedu009396; Thu, 1 Jun 2017 19:58:40 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v51JwemR009395; Thu, 1 Jun 2017 19:58:40 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201706011958.v51JwemR009395@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Ngie Cooper Date: Thu, 1 Jun 2017 19:58:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r319456 - head/tests/sys/opencrypto X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Jun 2017 19:58:42 -0000 Author: ngie Date: Thu Jun 1 19:58:40 2017 New Revision: 319456 URL: https://svnweb.freebsd.org/changeset/base/319456 Log: 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 Modified: head/tests/sys/opencrypto/runtests.sh Modified: head/tests/sys/opencrypto/runtests.sh ============================================================================== --- head/tests/sys/opencrypto/runtests.sh Thu Jun 1 19:46:48 2017 (r319455) +++ head/tests/sys/opencrypto/runtests.sh Thu Jun 1 19:58:40 2017 (r319456) @@ -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