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 20, 2023
1 parent 880cc2d commit d50c0f8
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 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,20 @@ 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
case "$MBEDTLS_TEST_OUTCOME_FILE" in
[!/]*)
MBEDTLS_TEST_OUTCOME_FILE="$ORIGINAL_PWD/$MBEDTLS_TEST_OUTCOME_FILE"
;;
esac
# Should we write to a new outcome file?
if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
fi
}

log() {
if [ "X" != "X$VERBOSE" ]; then
echo ""
Expand Down Expand Up @@ -971,14 +991,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 d50c0f8

Please sign in to comment.