From 1c4aefc2b80df30fde528fb47d34f72dade18fc2 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 26 Oct 2015 15:03:37 +0100 Subject: [PATCH] btrfs-progs: tests: add support for command instrumentation Add a way to wrap commands executed by the tests. This means the common wrappers: run_check, run_check_stdout and run_mayfail , with the exception of the use root_helper. The contents of the shell variable INSTRUMENT are prepended to the command, without quotes. Use with care. Example: this has been tested with valgrind, the output goes to the RESULTS file. $ INSTRUMENT=valgrind make test-misc Any use of root_helper/SUDO_HELPER will skip the instrumentation. Signed-off-by: David Sterba --- tests/common | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/common b/tests/common index 4542fa8..ea9a569 100644 --- a/tests/common +++ b/tests/common @@ -25,7 +25,11 @@ run_check() { echo "############### $@" >> $RESULTS 2>&1 if [ "$TEST_LOG" = 'tty' ]; then echo "CMD: $@" > /dev/tty; fi - "$@" >> $RESULTS 2>&1 || _fail "failed: $@" + if [ "$1" = 'root_helper' ]; then + "$@" >> $RESULTS 2>&1 || _fail "failed: $@" + else + $INSTRUMENT "$@" >> $RESULTS 2>&1 || _fail "failed: $@" + fi } # same as run_check but the stderr+stdout output is duplicated on stdout and @@ -34,7 +38,11 @@ run_check_stdout() { echo "############### $@" >> $RESULTS 2>&1 if [ "$TEST_LOG" = 'tty' ]; then echo "CMD(stdout): $@" > /dev/tty; fi - "$@" 2>&1 | tee -a $RESULTS || _fail "failed: $@" + if [ "$1" = 'root_helper' ]; then + "$@" 2>&1 | tee -a $RESULTS || _fail "failed: $@" + else + $INSTRUMENT "$@" 2>&1 | tee -a $RESULTS || _fail "failed: $@" + fi } # same as run_check but does not fail the test, output is logged @@ -42,7 +50,11 @@ run_mayfail() { echo "############### $@" >> $RESULTS 2>&1 if [ "$TEST_LOG" = 'tty' ]; then echo "CMD(mayfail): $@" > /dev/tty; fi - "$@" >> $RESULTS 2>&1 || _log "failed (ignored): $@" + if [ "$1" = 'root_helper' ]; then + "$@" >> $RESULTS 2>&1 || _log "failed (ignored): $@" + else + $INSTRUMENT "$@" >> $RESULTS 2>&1 || _log "failed (ignored): $@" + fi } check_prereq() -- 2.7.4