Skip to content

Commit

Permalink
compat.sh: support option --append-outcome
Browse files Browse the repository at this point in the history
By default, we record each test cases into a new file if
MBEDTLS_TEST_OUTCOME_FILE is set. With --append-outcome, append
records to the existing outcome file if it's set.

Signed-off-by: Yanray Wang <[email protected]>
  • Loading branch information
Yanray Wang committed Feb 21, 2023
1 parent 880cc2d commit 0d9bb6c
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions tests/compat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ guess_config_name() {
: ${MBEDTLS_TEST_OUTCOME_FILE=}
: ${MBEDTLS_TEST_CONFIGURATION:="$(guess_config_name)"}
: ${MBEDTLS_TEST_PLATFORM:="$(uname -s | tr -c \\n0-9A-Za-z _)-$(uname -m | tr -c \\n0-9A-Za-z _)"}
# By default, we record the outcome to a new file
append_outcome=0

# default values for options
# /!\ keep this synchronised with:
Expand Down Expand Up @@ -129,6 +131,7 @@ print_usage() {
printf " -v|--verbose\tSet verbose output.\n"
printf " --outcome-file\tFile where test outcomes are written\n"
printf " \t(default: \$MBEDTLS_TEST_OUTCOME_FILE, none if empty)\n"
printf " --append-outcome\tAppend records to the outcome file (if used)\n"
}

get_options() {
Expand Down Expand Up @@ -161,6 +164,9 @@ get_options() {
--outcome-file)
shift; MBEDTLS_TEST_OUTCOME_FILE=$1
;;
--append-outcome)
append_outcome=1
;;
-h|--help)
print_usage
exit 0
Expand All @@ -179,6 +185,18 @@ get_options() {
TYPES="$( echo $TYPES | tr [a-z] [A-Z] )"
}

prepare_outcome_file() {
# Make the outcome file path relative to the original directory, not
# to .../tests
if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
MBEDTLS_TEST_OUTCOME_FILE="$ORIGINAL_PWD/$MBEDTLS_TEST_OUTCOME_FILE"
# Should we write to a new outcome file?
if [ "$append_outcome" -eq 0 ]; then
rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
fi
fi
}

log() {
if [ "X" != "X$VERBOSE" ]; then
echo ""
Expand Down Expand Up @@ -971,14 +989,7 @@ run_client() {
#

get_options "$@"

# Make the outcome file path relative to the original directory, not
# to .../tests
case "$MBEDTLS_TEST_OUTCOME_FILE" in
[!/]*)
MBEDTLS_TEST_OUTCOME_FILE="$ORIGINAL_PWD/$MBEDTLS_TEST_OUTCOME_FILE"
;;
esac
prepare_outcome_file

# sanity checks, avoid an avalanche of errors
if [ ! -x "$M_SRV" ]; then
Expand Down

0 comments on commit 0d9bb6c

Please sign in to comment.