[test] Enable passing arguments to the functest harness
Move the required args to the end and name them the "test commands."
Pass the test commands via an environment variable, and place them at
the end of the invocation.
This makes the test commands unable to be overridden by test_arg
arguments, and simultaneously, it allows the user to specify test_arg
arguments on the bazel command line to modify arguments to opentitantool
and friends. Those test_arg arguments can override or supplement the
test harness's arguments provided by the bazel rule.
Signed-off-by: Alexander Williams <awill@google.com>
diff --git a/util/dvsim_test_runner.sh b/util/dvsim_test_runner.sh
index cf70d22..4ddc8c4 100755
--- a/util/dvsim_test_runner.sh
+++ b/util/dvsim_test_runner.sh
@@ -11,4 +11,4 @@
readonly DVSIM="util/dvsim/dvsim.py"
echo "At this time, dvsim.py must be run manually (after building SW) via:
-${DVSIM} $*"
+${DVSIM} $* ${TEST_CMDS} "
diff --git a/util/opentitan_functest_runner.sh b/util/opentitan_functest_runner.sh
index cf481a3..af8eeec 100755
--- a/util/opentitan_functest_runner.sh
+++ b/util/opentitan_functest_runner.sh
@@ -3,8 +3,21 @@
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
#
-# A shell script for executing rust-based tests for functional and e2e tests.
-# The test runner should be passed in as the first argument.
+# A shell script for executing rust-based tests for functional and e2e tests,
+# especially for harnesses built atop opentitanlib.
+#
+# There are three components that make up the harness invocation:
+# - test harness
+# - arguments
+# - test commands
+#
+# The test harness is invoked with arguments first, then the test commands.
+# The test harness and test commands are both passed in by environment variables.
+# Note that bazel passes user-specified test_arg arguments as arguments to this
+# script, and because the user-specified test_arg arguments come after the bazel
+# rule's arguments, they can override the ones coming from the bazel rule.
+# Thus, the test harness and test script represent portions of the invocation
+# that cannot be overridden, but the arguments in the middle can.
set -e
@@ -13,5 +26,10 @@
exit 1
fi
-echo Invoking test: "${TEST_HARNESS}" "$@"
-RUST_BACKTRACE=1 ${TEST_HARNESS} "$@"
+# eval the environment variable string to break up the components and have bash
+# interpret quotes and other special characters in arguments. This happens
+# during the invocation line.
+eval "TEST_CMDS_ARRAY=( ${TEST_CMDS} )"
+
+echo Invoking test: "${TEST_HARNESS}" "$@" "${TEST_CMDS_ARRAY[@]}"
+RUST_BACKTRACE=1 ${TEST_HARNESS} "$@" "${TEST_CMDS_ARRAY[@]}"