From f54ec71fa4e6c4153a57d519b3524300946cd8b8 Mon Sep 17 00:00:00 2001 From: Marcos Paulo de Souza Date: Thu, 5 Mar 2020 23:57:52 -0300 Subject: [PATCH 1/2] btrfs-progs: tests: common: Introduce run_mayfail_stdout This helper would help to run tests that can fail, but depending on the output of the error we can skip the test instead of failing. Signed-off-by: Marcos Paulo de Souza --- tests/common | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/common b/tests/common index f5efc58b..2f698e08 100644 --- a/tests/common +++ b/tests/common @@ -216,6 +216,37 @@ run_mayfail() fi } +# same as run_mayfail but prints the error message to stdout too +run_mayfail_stdout() +{ + local spec + local ins + local ret + + ins=$(_get_spec_ins "$@") + spec=$(($ins-1)) + spec=$(_cmd_spec "${@:$spec}") + set -- "${@:1:$(($ins-1))}" $spec "${@: $ins}" + echo "====== RUN MAYFAIL $@" >> "$RESULTS" 2>&1 + if [[ $TEST_LOG =~ tty ]]; then echo "CMD(mayfail): $@" > /dev/tty; fi + + if [ "$1" = 'root_helper' ]; then + "$@" 2>&1 | tee -a "$RESULTS" + else + $INSTRUMENT "$@" 2>&1 | tee -a "$RESULTS" + fi + ret=${PIPESTATUS[0]} + if [ $ret != 0 ]; then + echo "failed (ignored, ret=$ret): $@" >> "$RESULTS" + if [ $ret == 139 ]; then + _fail "mayfail: returned code 139 (SEGFAULT), not ignored" + elif [ $ret == 134 ]; then + _fail "mayfail: returned code 134 (SIGABRT), not ignored" + fi + return $ret + fi +} + # first argument is error message to print if it fails, otherwise # same as run_check but expects the command to fail, output is logged run_mustfail() -- 2.25.0