platform/test: always run linux platform tests (will be skipped as non-root)

Always run the linux platform tests, even if called as non-root user.
In such a case, print a message and return 77 (signalizing that the test
was skipped).

Only if we configured with --enable-test=root, we enforce that the
user executes the tests as root.

Co-Authored-By: Pavel Šimerda <psimerda@redhat.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
Thomas Haller 2014-04-22 14:22:11 +02:00
parent 0fde65a14e
commit e3784fa618
3 changed files with 18 additions and 16 deletions

View file

@ -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, []))

View file

@ -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

View file

@ -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 ();