diff --git a/configure.ac b/configure.ac index 066c9d54f8..1cbe601da9 100644 --- a/configure.ac +++ b/configure.ac @@ -756,7 +756,7 @@ AS_IF([test "$with_valgrind" == "yes"], [AC_PATH_PROGS(with_valgrind, valgrind, no)]) # Add conditionals and substitutions AM_CONDITIONAL(ENABLE_TESTS, test "$enable_tests" != "no") -AM_CONDITIONAL(RUN_ROOT_TESTS, test "$enable_tests" == "root") +AM_CONDITIONAL(REQUIRE_ROOT_TESTS, test "$enable_tests" == "root") AS_IF([test "$with_valgrind" != "no"], AC_SUBST(VALGRIND_RULES, 'TESTS_ENVIRONMENT = "$(top_srcdir)/tools/run-test-valgrind.sh" "$(LIBTOOL)" "$(with_valgrind)" "$(top_srcdir)/valgrind.suppressions"'), AC_SUBST(VALGRIND_RULES, [])) diff --git a/src/platform/tests/Makefile.am b/src/platform/tests/Makefile.am index 9bdb4452bc..9b10ea7b2a 100644 --- a/src/platform/tests/Makefile.am +++ b/src/platform/tests/Makefile.am @@ -14,6 +14,10 @@ AM_CPPFLAGS = \ $(GUDEV_CFLAGS) \ $(LIBNL_CFLAGS) +if REQUIRE_ROOT_TESTS +AM_CPPFLAGS += -DREQUIRE_ROOT_TESTS=1 +endif + PLATFORM_SOURCES = \ ../nm-platform.c \ ../nm-fake-platform.c \ @@ -106,20 +110,7 @@ test_cleanup_linux_CPPFLAGS = \ -DKERNEL_HACKS=1 test_cleanup_linux_LDADD = $(PLATFORM_LDADD) -# Unfortunately, we cannot run nm-linux-platform-test as an automatic test -# program by default, as it requires root access and modifies kernel -# configuration. -# -# However, we can check whether the fake platform fakes platform behavior -# correctly. +#@VALGRIND_RULES@ +TESTS = test-link-fake test-address-fake test-route-fake test-cleanup-fake test-link-linux test-address-linux test-route-linux test-cleanup-linux -@VALGRIND_RULES@ -USERTESTS = test-link-fake test-address-fake test-route-fake test-cleanup-fake -ROOTTESTS = test-link-linux test-address-linux test-route-linux test-cleanup-linux -# If explicitly enabled, we can run the root tests -if RUN_ROOT_TESTS -TESTS = $(USERTESTS) $(ROOTTESTS) -else -TESTS = $(USERTESTS) -endif diff --git a/src/platform/tests/test-common.c b/src/platform/tests/test-common.c index 686536f857..1c8550593b 100644 --- a/src/platform/tests/test-common.c +++ b/src/platform/tests/test-common.c @@ -145,9 +145,20 @@ int main (int argc, char **argv) { int result; + const char *program = *argv; nmtst_init (&argc, &argv, NULL, "ALL"); + if (SETUP == nm_linux_platform_setup && getuid() != 0) { +#ifdef REQUIRE_ROOT_TESTS + g_message ("Fail test: requires root privileges (%s)", program); + return EXIT_FAILURE; +#else + g_message ("Skipping test: requires root privileges (%s)", program); + return 77; +#endif + } + SETUP (); setup_tests ();