]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
CI: Re-run some tests as root or as non-root, as appropriate
authorSimon McVittie <smcv@collabora.com>
Mon, 6 Feb 2023 13:24:11 +0000 (13:24 +0000)
committerSimon McVittie <smcv@collabora.com>
Mon, 6 Feb 2023 13:24:11 +0000 (13:24 +0000)
On Gitlab-CI we're always running the overall script as root (and
therefore we'll only enter the code path to re-run as non-root),
but when using these scripts for manual testing they might be run as
non-root to begin with.

Signed-off-by: Simon McVittie <smcv@collabora.com>
tools/ci-build.sh

index 989e1fc3f1d9f97ee6721165481a2e36842e84e4..df22b8ba821c399ec97e7ed79d3c2bf9dee06170 100755 (executable)
@@ -371,19 +371,34 @@ case "$ci_buildsys" in
                 maybe_fail_tests
             cat test/test-suite.log || :
 
-            # re-run them with gnome-desktop-testing
+            # Re-run them with gnome-desktop-testing.
+            # Also, one test needs a finite fd limit to be useful, so we
+            # can set that here.
             env LD_LIBRARY_PATH=/usr/local/lib \
+            bash -c 'ulimit -S -n 1024; ulimit -H -n 4096; exec "$@"' bash \
             gnome-desktop-testing-runner -d /usr/local/share dbus/ || \
                 maybe_fail_tests
 
-            # these tests benefit from being re-run as root, and one
-            # test needs a finite fd limit to be useful
-            sudo env LD_LIBRARY_PATH=/usr/local/lib \
-            bash -c 'ulimit -S -n 1024; ulimit -H -n 4096; exec "$@"' bash \
+            # Some tests benefit from being re-run as non-root, if we were
+            # not already...
+            if [ "$(id -u)" = 0 ] && [ "$ci_in_docker" = yes ]; then
+                sudo -u user \
+                env LD_LIBRARY_PATH=/usr/local/lib \
                 gnome-desktop-testing-runner -d /usr/local/share \
-                dbus/test-dbus-daemon_with_config.test \
-                dbus/test-uid-permissions_with_config.test || \
-                maybe_fail_tests
+                    dbus/test-dbus-daemon_with_config.test \
+                    || maybe_fail_tests
+            fi
+
+            # ... while other tests benefit from being re-run as root, if
+            # we were not already
+            if [ "$(id -u)" != 0 ]; then
+                sudo env LD_LIBRARY_PATH=/usr/local/lib \
+                bash -c 'ulimit -S -n 1024; ulimit -H -n 4096; exec "$@"' bash \
+                    gnome-desktop-testing-runner -d /usr/local/share \
+                    dbus/test-dbus-daemon_with_config.test \
+                    dbus/test-uid-permissions_with_config.test || \
+                    maybe_fail_tests
+            fi
         fi
         ;;