From 986b4ab0afd551c232b5337195d60dab6405379b Mon Sep 17 00:00:00 2001 From: Tom Hromatka Date: Wed, 26 Oct 2022 10:19:03 -0600 Subject: [PATCH] ftests: Add support for running 'sudo' suite of tests Some tests require sudo support for python/C bindings. This is awkward to implement using the Run() class and error prone. Instead, invoke the entire test with sudo permissions via a separate invocation of ftests.py. This ensures that existing tests (that don't require sudo) remain the same and don't accidentally get elevated privileges. Signed-off-by: Tom Hromatka Reviewed-by: Kamalesh Babulal --- tests/ftests/ftests-nocontainer.sh | 36 ++++++++++++++++++++++++++++-- tests/ftests/ftests.py | 8 +++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/tests/ftests/ftests-nocontainer.sh b/tests/ftests/ftests-nocontainer.sh index 6ac4bdca..7fbb90a9 100755 --- a/tests/ftests/ftests-nocontainer.sh +++ b/tests/ftests/ftests-nocontainer.sh @@ -1,6 +1,9 @@ #!/bin/bash # SPDX-License-Identifier: LGPL-2.1-only +AUTOMAKE_SKIPPED=77 +AUTOMAKE_HARD_ERROR=99 + START_DIR=$PWD SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) @@ -16,12 +19,41 @@ fi ./ftests.py -l 10 -L "$START_DIR/ftests-nocontainer.py.log" --no-container \ -n Libcg"$RANDOM" -RET=$? +RET1=$? + +pushd ../../src || exit $AUTOMAKE_HARD_ERROR +PATH="$PATH:$(pwd)" +export PATH +popd || exit $AUTOMAKE_HARD_ERROR + +sudo PATH=$PATH PYTHONPATH=$PYTHONPATH ./ftests.py -l 10 -s "sudo" \ + -L "$START_DIR/ftests-nocontainer.py.sudo.log" --no-container -n Libcg"$RANDOM" +RET2=$? if [ "$START_DIR" != "$SCRIPT_DIR" ]; then rm -f "$START_DIR"/*.py rm -fr "$START_DIR"/__pycache__ rm -f ftests-nocontainer.py.log + rm -f ftests-nocontainer.py.sudo.log +fi + + +if [[ $RET1 -ne $AUTOMAKE_SKIPPED ]] && [[ $RET1 -ne 0 ]]; then + # always return errors from the first test run + exit $RET1 +fi +if [[ $RET2 -ne $AUTOMAKE_SKIPPED ]] && [[ $RET2 -ne 0 ]]; then + # return errors from the second test run + exit $RET2 +fi + +if [[ $RET1 -eq 0 ]] || [[ $RET2 -eq 0 ]]; then + exit 0 +fi + +if [[ $RET1 -eq $AUTOMAKE_SKIPPED ]] || [[ $RET2 -eq $AUTOMAKE_SKIPPED ]]; then + exit $AUTOMAKE_SKIPPED fi -exit $RET +# I don't think we should ever get here, but better safe than sorry +exit $AUTOMAKE_HARD_ERROR diff --git a/tests/ftests/ftests.py b/tests/ftests/ftests.py index d888fcd9..1817ca03 100755 --- a/tests/ftests/ftests.py +++ b/tests/ftests/ftests.py @@ -274,6 +274,14 @@ def run_tests(config): if config.args.num == consts.TESTS_RUN_ALL or \ config.args.num == filenum_int: + + if config.args.suite == consts.TESTS_RUN_ALL_SUITES and \ + filesuite == 'sudo': + # Don't run the 'sudo' tests if all tests have been specified. + # The sudo tests must be run as sudo and thus need to be separately + # invoked. + continue + if filenum_int in config.skip_list: continue -- 2.47.2