aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTyler Hicks <tyhicks@canonical.com>2014-02-24 18:52:42 -0600
committerDavid Howells <dhowells@redhat.com>2014-02-25 11:14:31 +0000
commitbf67fbfacb700b7d7aae757cd52a804295422b67 (patch)
tree73bb234e3aff0682c30763d0e83b70f1a5167c15
parentf0d9a8c15f1525d0404077f32fddccb606a61bac (diff)
downloadkeyutils-bf67fbfacb700b7d7aae757cd52a804295422b67.tar.gz
TEST: Skip tests when external commands are unavailable
When relying on external commands, such as getenforce, skip the test if the required commands are unavailable. This patch adds a function to the toolbox that allows tests to declare their required commands at the top of the test script. If which cannot locate the command, a message is written to the output file, a marker is printed indicating which command is missing, and the test script is terminated with a passing result. Additionally, the patch adds require_command declarations for commands required in the bz1031154 test. Signed-off-by: Tyler Hicks <tyhicks@canonical.com> Signed-off-by: David Howells <dhowells@redhat.com>
-rw-r--r--tests/bugzillas/bz1031154/runtest.sh6
-rw-r--r--tests/toolbox.inc.sh19
2 files changed, 25 insertions, 0 deletions
diff --git a/tests/bugzillas/bz1031154/runtest.sh b/tests/bugzillas/bz1031154/runtest.sh
index 5e139ca..fa30567 100644
--- a/tests/bugzillas/bz1031154/runtest.sh
+++ b/tests/bugzillas/bz1031154/runtest.sh
@@ -9,6 +9,12 @@
# ---- do the actual testing ----
result=PASS
+
+require_command getenforce
+require_command setenforce
+require_command runcon
+require_command ausearch
+
echo "++++ BEGINNING TEST" >$OUTPUTFILE
# we need a reference time to scan the audit log from so as not to pick up old
diff --git a/tests/toolbox.inc.sh b/tests/toolbox.inc.sh
index fe3c7f7..5a2db22 100644
--- a/tests/toolbox.inc.sh
+++ b/tests/toolbox.inc.sh
@@ -132,6 +132,25 @@ function keyutils_at_or_older_than ()
###############################################################################
#
+# Return true if the command is found in $PATH. If not, log that the test is
+# being skipped, report the result as PASS, and exit.
+#
+###############################################################################
+function require_command ()
+{
+ which "$1" >&/dev/null
+ if [ $? != 0 ]
+ then
+ echo "++++ SKIPPING TEST" >>$OUTPUTFILE
+ marker "SKIP DUE TO MISSING COMMAND: $1"
+ toolbox_report_result $TEST PASS
+
+ exit 0
+ fi
+}
+
+###############################################################################
+#
# extract an error message from the log file and check it
#
###############################################################################