From 990d9817a9a9b3d16279be9d922d71ed6699a567 Mon Sep 17 00:00:00 2001 From: Luca Toniolo <10792599+grandixximo@users.noreply.github.com> Date: Sat, 10 Oct 2026 19:45:14 +1100 Subject: [PATCH] tests: drop sudo from the test suite and the package CI job Tests that installed a component with `${SUDO} halcompile --install` now use plain halcompile and an executable skip file, so they run on RIP and skip against installed packages. Remove SUDO, the control file handling and -u from runtests, and sudo from the package-arch job. --- .github/workflows/ci.yml | 4 +--- docs/src/code/writing-tests.adoc | 11 ++++------- scripts/runtests.in | 17 +---------------- tests/README | 17 ++++++----------- tests/halcompile/personalities_mod/control | 1 - tests/halcompile/personalities_mod/skip | 4 ++++ tests/halcompile/personalities_mod/test.sh | 6 +++--- tests/halcompile/relative-header-user/control | 1 - tests/halcompile/userspace-count-names/skip | 4 ++++ tests/halcompile/userspace-count-names/test.sh | 2 +- tests/kins-frames/test.sh | 2 +- tests/kins-jacobian/test.sh | 2 +- .../module-loading/rtapi-app-main-fails/control | 1 - tests/module-loading/rtapi-app-main-fails/skip | 4 ++++ .../module-loading/rtapi-app-main-fails/test.sh | 2 +- tests/realtime-math/control | 1 - tests/realtime-math/skip | 4 ++++ tests/realtime-math/test.sh | 2 +- tests/rtapi-shmem/control | 1 - tests/rtapi-shmem/skip | 4 ++++ tests/rtapi-shmem/test.sh | 2 +- tests/symbols.0/control | 1 - tests/symbols.0/skip | 4 ++++ tests/symbols.0/test.sh | 4 ++-- tests/symbols.1/control | 1 - tests/symbols.1/skip | 4 ++++ tests/symbols.1/test.sh | 4 ++-- tests/uspace/spawnv-root/control | 1 - tests/uspace/spawnv-root/skip | 4 ++++ tests/uspace/spawnv-root/test.sh | 2 +- 30 files changed, 58 insertions(+), 59 deletions(-) delete mode 100644 tests/halcompile/personalities_mod/control create mode 100755 tests/halcompile/personalities_mod/skip delete mode 100644 tests/halcompile/relative-header-user/control create mode 100755 tests/halcompile/userspace-count-names/skip delete mode 100644 tests/module-loading/rtapi-app-main-fails/control create mode 100755 tests/module-loading/rtapi-app-main-fails/skip delete mode 100644 tests/realtime-math/control create mode 100755 tests/realtime-math/skip delete mode 100644 tests/rtapi-shmem/control create mode 100755 tests/rtapi-shmem/skip delete mode 100644 tests/symbols.0/control create mode 100755 tests/symbols.0/skip delete mode 100644 tests/symbols.1/control create mode 100755 tests/symbols.1/skip delete mode 100644 tests/uspace/spawnv-root/control create mode 100755 tests/uspace/spawnv-root/skip diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d04b5052449..599a9ee837c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -330,7 +330,7 @@ jobs: apt-get -q update apt --yes upgrade # Install stuff needed to check out the linuxcnc repo and turn it into a debian source package and run tests. - apt-get --yes --no-install-recommends install curl git lsb-release python3 devscripts sudo adduser xauth + apt-get --yes --no-install-recommends install curl git lsb-release python3 devscripts adduser xauth - name: Checkout repository uses: actions/checkout@v6 with: @@ -360,8 +360,6 @@ jobs: run: | set -x adduser --disabled-password --gecos "" testrunner - passwd -d testrunner - adduser testrunner sudo chmod 0777 $(find tests/ -type d) # make test dirs world-writable for the testrunner su -c "./scripts/runtests -p -d ./tests" testrunner - name: Verify no untracked or modified files after test diff --git a/docs/src/code/writing-tests.adoc b/docs/src/code/writing-tests.adoc index 02e73c5465f..f399ba08602 100644 --- a/docs/src/code/writing-tests.adoc +++ b/docs/src/code/writing-tests.adoc @@ -31,8 +31,8 @@ The _runtests_ script accepts the following arguments, see the output from `scri -s stop after any failed test. -p print stderr and result files. -c Remove temporary files from an earlier test run. --u Only run tests that require normal user access. -v Show stdout and stderr (normally it's hidden). +-d Enable crash dumps: print a gdb backtrace of the core when a test crashes. ---- == Writing tests @@ -69,12 +69,9 @@ checkresult:: If both `expected` and `checkresult` exist, only `checkresult` is consulted to validate the test output. skip:: - If this file exist, the test is skipped and not executed at all. - - control:: - This file can be used to flag specific needs in the test. - At the moment, the use of _sudo_ can be flagged, and tests requiring sudo can be skipped when using `runtests -u`. - To flag such requirements, add a line with `Restrictions: sudo` to this file. + If this file exists and is not executable, the test is skipped and not executed at all. + If it is executable, it is run first and the test is skipped when it exits non-zero. + Tests never use _sudo_: a test that builds or installs a component with `halcompile` needs the build tree, so its `skip` file is `[ -z "$SYSTEM_BUILD" ]`, which skips it when testing installed packages. musthave:: This file can contain a list of prerequisites from config.h (one per line). If it's not met, the test will be skipped. diff --git a/scripts/runtests.in b/scripts/runtests.in index 76ccab8ce3d..823f9c10401 100755 --- a/scripts/runtests.in +++ b/scripts/runtests.in @@ -33,7 +33,6 @@ else export LIBDIR=@EMC2_HOME@/lib export LINUXCNC_EMCSH=@WISH@ export REALTIME=@REALTIME@ - export SUDO=sudo fi export PYTHON_CPPFLAGS="@PYTHON_CPPFLAGS@" export PYTHON_EXTRA_LIBS="@PYTHON_EXTRA_LIBS@" @@ -236,14 +235,6 @@ run_tests () { continue fi fi - if $NOSUDO && [ -e "$testdir/control" ] && \ - grep Restrictions: "$testdir/control" | grep -q sudo; then - if ! [ -x "$testdir/skip" ] || ! "$testdir/skip"; then - echo "Skipping sudo test: $testdir" 1>&2 - SKIP=$((SKIP + 1)) - continue - fi - fi NUM=$((NUM + 1)) TEST_DIR=$(readlink -f "$testdir") export TEST_DIR @@ -338,10 +329,6 @@ Usage: $P -c tests Remove temporary files from an earlier test run. - $P -u - Only run tests that require normal user access. Skip tests - requiring root or sudo. - $P -v Show stdout and stderr (normally it's hidden). @@ -354,14 +341,12 @@ EOF CLEAN_ONLY=0 NOCLEAN=0 -NOSUDO=false STOP=0 PRINT=0 -while getopts cnuvsphd opt; do +while getopts cnvsphd opt; do case "$opt" in c) CLEAN_ONLY=1 ;; n) NOCLEAN=1 ;; - u) NOSUDO=true ;; v) VERBOSE=1 ;; s) STOP=1 ;; p) PRINT=1 ;; diff --git a/tests/README b/tests/README index 2516d36435f..81fc0676bfd 100644 --- a/tests/README +++ b/tests/README @@ -30,11 +30,6 @@ can be run by executing (from the top emc2 directory) A subset of the tests can also be run: scripts/runtests tests/xyz tests/a* -To only run the tests that do not require root or sudo access, use the --u option: - - scripts/runtests -u tests - The directories named on the commandline are searched recursively for 'test.hal' or 'test.sh' files, and a directory with such a file is assumed to contain a regression test or a functional test. @@ -100,10 +95,10 @@ and see if it indicates success. The test passes if the command "checkresult actual" returns a shell success value (exit code 0). Otherwise, the test fails. -Tests requiring root or sudo access are flagged by creating a file -named control in the test directory, with the 'sudo' flag in the -Restrictions field: - - Restrictions: sudo +Tests never use root or sudo. A test directory may hold an executable +file named skip; the test is skipped when it exits non-zero. A test +that builds or installs a component with halcompile needs the build +tree, so it skips when testing installed packages: -Other restrictions might be added in the future + #!/bin/sh + [ -z "$SYSTEM_BUILD" ] diff --git a/tests/halcompile/personalities_mod/control b/tests/halcompile/personalities_mod/control deleted file mode 100644 index 5cc4825bdc1..00000000000 --- a/tests/halcompile/personalities_mod/control +++ /dev/null @@ -1 +0,0 @@ -Restrictions: sudo diff --git a/tests/halcompile/personalities_mod/skip b/tests/halcompile/personalities_mod/skip new file mode 100755 index 00000000000..2b852bb0362 --- /dev/null +++ b/tests/halcompile/personalities_mod/skip @@ -0,0 +1,4 @@ +#!/bin/sh +# Installs a component with halcompile, which needs a writable build +# tree. Skip when testing installed packages. +[ -z "$SYSTEM_BUILD" ] diff --git a/tests/halcompile/personalities_mod/test.sh b/tests/halcompile/personalities_mod/test.sh index f7a7727ac74..5c7594fb895 100755 --- a/tests/halcompile/personalities_mod/test.sh +++ b/tests/halcompile/personalities_mod/test.sh @@ -1,9 +1,9 @@ #!/bin/bash set -e -${SUDO} halcompile --personalities=2 --install lincurve_test.comp -${SUDO} halcompile --personalities=2 --install logic_test.comp -${SUDO} halcompile --personalities=2 --install bitslice_test.comp +halcompile --personalities=2 --install lincurve_test.comp +halcompile --personalities=2 --install logic_test.comp +halcompile --personalities=2 --install bitslice_test.comp # This tells us the expected filename extension ${MODULE_EXT} of realtime # modules. diff --git a/tests/halcompile/relative-header-user/control b/tests/halcompile/relative-header-user/control deleted file mode 100644 index 5cc4825bdc1..00000000000 --- a/tests/halcompile/relative-header-user/control +++ /dev/null @@ -1 +0,0 @@ -Restrictions: sudo diff --git a/tests/halcompile/userspace-count-names/skip b/tests/halcompile/userspace-count-names/skip new file mode 100755 index 00000000000..2b852bb0362 --- /dev/null +++ b/tests/halcompile/userspace-count-names/skip @@ -0,0 +1,4 @@ +#!/bin/sh +# Installs a component with halcompile, which needs a writable build +# tree. Skip when testing installed packages. +[ -z "$SYSTEM_BUILD" ] diff --git a/tests/halcompile/userspace-count-names/test.sh b/tests/halcompile/userspace-count-names/test.sh index 371cc9b3770..d21d9133aaf 100755 --- a/tests/halcompile/userspace-count-names/test.sh +++ b/tests/halcompile/userspace-count-names/test.sh @@ -1,7 +1,7 @@ #!/bin/bash set -e -${SUDO} halcompile --install userspace_count_names.comp +halcompile --install userspace_count_names.comp INSTALLED_FILE="${EMC2_HOME}/bin/userspace_count_names" if [[ ! -f "${INSTALLED_FILE}" ]]; then diff --git a/tests/kins-frames/test.sh b/tests/kins-frames/test.sh index 4bb8e108765..b1471ea45b7 100755 --- a/tests/kins-frames/test.sh +++ b/tests/kins-frames/test.sh @@ -1,7 +1,7 @@ #!/bin/bash set -e -${SUDO} halcompile --install framecheck.c >/dev/null +halcompile --install framecheck.c >/dev/null # One hal file per module: they all define the same entry points, so # only one can be loaded at a time. diff --git a/tests/kins-jacobian/test.sh b/tests/kins-jacobian/test.sh index 57a3a2e45e3..b275b2fc0fb 100755 --- a/tests/kins-jacobian/test.sh +++ b/tests/kins-jacobian/test.sh @@ -1,7 +1,7 @@ #!/bin/bash set -e -${SUDO} halcompile --install jaccheck.c >/dev/null +halcompile --install jaccheck.c >/dev/null # One hal file per module: they all define the same entry points, so # only one can be loaded at a time. A run that leaves the sweep at its diff --git a/tests/module-loading/rtapi-app-main-fails/control b/tests/module-loading/rtapi-app-main-fails/control deleted file mode 100644 index 5cc4825bdc1..00000000000 --- a/tests/module-loading/rtapi-app-main-fails/control +++ /dev/null @@ -1 +0,0 @@ -Restrictions: sudo diff --git a/tests/module-loading/rtapi-app-main-fails/skip b/tests/module-loading/rtapi-app-main-fails/skip new file mode 100755 index 00000000000..2b852bb0362 --- /dev/null +++ b/tests/module-loading/rtapi-app-main-fails/skip @@ -0,0 +1,4 @@ +#!/bin/sh +# Installs a component with halcompile, which needs a writable build +# tree. Skip when testing installed packages. +[ -z "$SYSTEM_BUILD" ] diff --git a/tests/module-loading/rtapi-app-main-fails/test.sh b/tests/module-loading/rtapi-app-main-fails/test.sh index 84ee3daf3b7..81e8df05a93 100644 --- a/tests/module-loading/rtapi-app-main-fails/test.sh +++ b/tests/module-loading/rtapi-app-main-fails/test.sh @@ -1,5 +1,5 @@ #!/bin/sh -${SUDO} halcompile --install rtapi_app_main_fails.comp +halcompile --install rtapi_app_main_fails.comp halrun -v setup.hal RETVAL=$? diff --git a/tests/realtime-math/control b/tests/realtime-math/control deleted file mode 100644 index 5cc4825bdc1..00000000000 --- a/tests/realtime-math/control +++ /dev/null @@ -1 +0,0 @@ -Restrictions: sudo diff --git a/tests/realtime-math/skip b/tests/realtime-math/skip new file mode 100755 index 00000000000..2b852bb0362 --- /dev/null +++ b/tests/realtime-math/skip @@ -0,0 +1,4 @@ +#!/bin/sh +# Installs a component with halcompile, which needs a writable build +# tree. Skip when testing installed packages. +[ -z "$SYSTEM_BUILD" ] diff --git a/tests/realtime-math/test.sh b/tests/realtime-math/test.sh index cafd12fcca5..40436748e27 100644 --- a/tests/realtime-math/test.sh +++ b/tests/realtime-math/test.sh @@ -1,4 +1,4 @@ #!/bin/sh set -xe -${SUDO} halcompile --install rtmath.comp +halcompile --install rtmath.comp halrun dotest.hal diff --git a/tests/rtapi-shmem/control b/tests/rtapi-shmem/control deleted file mode 100644 index 5cc4825bdc1..00000000000 --- a/tests/rtapi-shmem/control +++ /dev/null @@ -1 +0,0 @@ -Restrictions: sudo diff --git a/tests/rtapi-shmem/skip b/tests/rtapi-shmem/skip new file mode 100755 index 00000000000..2b852bb0362 --- /dev/null +++ b/tests/rtapi-shmem/skip @@ -0,0 +1,4 @@ +#!/bin/sh +# Installs a component with halcompile, which needs a writable build +# tree. Skip when testing installed packages. +[ -z "$SYSTEM_BUILD" ] diff --git a/tests/rtapi-shmem/test.sh b/tests/rtapi-shmem/test.sh index 20b2afa1f78..e732675f904 100644 --- a/tests/rtapi-shmem/test.sh +++ b/tests/rtapi-shmem/test.sh @@ -1,5 +1,5 @@ #!/bin/sh -${SUDO} halcompile --install test_shmem_rtcomp.comp +halcompile --install test_shmem_rtcomp.comp halrun -V setup.hal diff --git a/tests/symbols.0/control b/tests/symbols.0/control deleted file mode 100644 index 5cc4825bdc1..00000000000 --- a/tests/symbols.0/control +++ /dev/null @@ -1 +0,0 @@ -Restrictions: sudo diff --git a/tests/symbols.0/skip b/tests/symbols.0/skip new file mode 100755 index 00000000000..2b852bb0362 --- /dev/null +++ b/tests/symbols.0/skip @@ -0,0 +1,4 @@ +#!/bin/sh +# Installs a component with halcompile, which needs a writable build +# tree. Skip when testing installed packages. +[ -z "$SYSTEM_BUILD" ] diff --git a/tests/symbols.0/test.sh b/tests/symbols.0/test.sh index 239bfdba619..d1a1b3ec871 100644 --- a/tests/symbols.0/test.sh +++ b/tests/symbols.0/test.sh @@ -1,5 +1,5 @@ #!/bin/sh set -xe -${SUDO} halcompile --install test_define.comp -${SUDO} halcompile --install test_use.comp +halcompile --install test_define.comp +halcompile --install test_use.comp ! halrun dotest.hal diff --git a/tests/symbols.1/control b/tests/symbols.1/control deleted file mode 100644 index 5cc4825bdc1..00000000000 --- a/tests/symbols.1/control +++ /dev/null @@ -1 +0,0 @@ -Restrictions: sudo diff --git a/tests/symbols.1/skip b/tests/symbols.1/skip new file mode 100755 index 00000000000..2b852bb0362 --- /dev/null +++ b/tests/symbols.1/skip @@ -0,0 +1,4 @@ +#!/bin/sh +# Installs a component with halcompile, which needs a writable build +# tree. Skip when testing installed packages. +[ -z "$SYSTEM_BUILD" ] diff --git a/tests/symbols.1/test.sh b/tests/symbols.1/test.sh index dd72fd69b1f..35dbef38291 100644 --- a/tests/symbols.1/test.sh +++ b/tests/symbols.1/test.sh @@ -1,5 +1,5 @@ #!/bin/sh set -e -${SUDO} halcompile --install test_define1.comp -${SUDO} halcompile --install test_use1.comp +halcompile --install test_define1.comp +halcompile --install test_use1.comp halrun dotest.hal diff --git a/tests/uspace/spawnv-root/control b/tests/uspace/spawnv-root/control deleted file mode 100644 index 5cc4825bdc1..00000000000 --- a/tests/uspace/spawnv-root/control +++ /dev/null @@ -1 +0,0 @@ -Restrictions: sudo diff --git a/tests/uspace/spawnv-root/skip b/tests/uspace/spawnv-root/skip new file mode 100755 index 00000000000..2b852bb0362 --- /dev/null +++ b/tests/uspace/spawnv-root/skip @@ -0,0 +1,4 @@ +#!/bin/sh +# Installs a component with halcompile, which needs a writable build +# tree. Skip when testing installed packages. +[ -z "$SYSTEM_BUILD" ] diff --git a/tests/uspace/spawnv-root/test.sh b/tests/uspace/spawnv-root/test.sh index 4485af3693c..e6e6b9b7347 100644 --- a/tests/uspace/spawnv-root/test.sh +++ b/tests/uspace/spawnv-root/test.sh @@ -9,5 +9,5 @@ if [ "$RTPREFIX" != uspace ]; then exit 0 fi -${SUDO} halcompile --install test_uspace_spawnv.c +halcompile --install test_uspace_spawnv.c halrun test_uspace_spawnv.hal