]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
ftests: Add support for running 'sudo' suite of tests
authorTom Hromatka <tom.hromatka@oracle.com>
Tue, 1 Nov 2022 22:14:30 +0000 (16:14 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Tue, 1 Nov 2022 22:14:30 +0000 (16:14 -0600)
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 <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
(cherry picked from commit 986b4ab0afd551c232b5337195d60dab6405379b)

tests/ftests/ftests-nocontainer.sh
tests/ftests/ftests.py

index 6ac4bdca15a99b90535f7992a57a2e81ec8a4961..7fbb90a9c831b8ea6f1da1e5ab06cb34c30aaf7c 100755 (executable)
@@ -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
index d888fcd9e30602dec7ff16e04ed0961cd05660c2..1817ca03907bced6c981254f3a8ee27f62b53615 100755 (executable)
@@ -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