Miles Dai | 395e451 | 2022-07-01 15:24:31 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright lowRISC contributors. |
| 3 | # Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 4 | # SPDX-License-Identifier: Apache-2.0 |
| 5 | # |
Alexander Williams | b05d61d | 2022-08-23 15:47:23 -0700 | [diff] [blame] | 6 | # A shell script for executing rust-based tests for functional and e2e tests, |
| 7 | # especially for harnesses built atop opentitanlib. |
| 8 | # |
| 9 | # There are three components that make up the harness invocation: |
| 10 | # - test harness |
| 11 | # - arguments |
| 12 | # - test commands |
| 13 | # |
| 14 | # The test harness is invoked with arguments first, then the test commands. |
| 15 | # The test harness and test commands are both passed in by environment variables. |
| 16 | # Note that bazel passes user-specified test_arg arguments as arguments to this |
| 17 | # script, and because the user-specified test_arg arguments come after the bazel |
| 18 | # rule's arguments, they can override the ones coming from the bazel rule. |
| 19 | # Thus, the test harness and test script represent portions of the invocation |
| 20 | # that cannot be overridden, but the arguments in the middle can. |
Miles Dai | 395e451 | 2022-07-01 15:24:31 -0400 | [diff] [blame] | 21 | |
| 22 | set -e |
| 23 | |
| 24 | if [ -z "$TEST_HARNESS" ]; then |
| 25 | echo "TEST_HARNESS variable needs to be specified." |
| 26 | exit 1 |
| 27 | fi |
| 28 | |
Alexander Williams | b05d61d | 2022-08-23 15:47:23 -0700 | [diff] [blame] | 29 | # eval the environment variable string to break up the components and have bash |
| 30 | # interpret quotes and other special characters in arguments. This happens |
| 31 | # during the invocation line. |
| 32 | eval "TEST_CMDS_ARRAY=( ${TEST_CMDS} )" |
| 33 | |
| 34 | echo Invoking test: "${TEST_HARNESS}" "$@" "${TEST_CMDS_ARRAY[@]}" |
| 35 | RUST_BACKTRACE=1 ${TEST_HARNESS} "$@" "${TEST_CMDS_ARRAY[@]}" |