mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-06 13:48:36 +02:00
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:
parent
0fde65a14e
commit
e3784fa618
3 changed files with 18 additions and 16 deletions
|
|
@ -756,7 +756,7 @@ AS_IF([test "$with_valgrind" == "yes"],
|
||||||
[AC_PATH_PROGS(with_valgrind, valgrind, no)])
|
[AC_PATH_PROGS(with_valgrind, valgrind, no)])
|
||||||
# Add conditionals and substitutions
|
# Add conditionals and substitutions
|
||||||
AM_CONDITIONAL(ENABLE_TESTS, test "$enable_tests" != "no")
|
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"],
|
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, 'TESTS_ENVIRONMENT = "$(top_srcdir)/tools/run-test-valgrind.sh" "$(LIBTOOL)" "$(with_valgrind)" "$(top_srcdir)/valgrind.suppressions"'),
|
||||||
AC_SUBST(VALGRIND_RULES, []))
|
AC_SUBST(VALGRIND_RULES, []))
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,10 @@ AM_CPPFLAGS = \
|
||||||
$(GUDEV_CFLAGS) \
|
$(GUDEV_CFLAGS) \
|
||||||
$(LIBNL_CFLAGS)
|
$(LIBNL_CFLAGS)
|
||||||
|
|
||||||
|
if REQUIRE_ROOT_TESTS
|
||||||
|
AM_CPPFLAGS += -DREQUIRE_ROOT_TESTS=1
|
||||||
|
endif
|
||||||
|
|
||||||
PLATFORM_SOURCES = \
|
PLATFORM_SOURCES = \
|
||||||
../nm-platform.c \
|
../nm-platform.c \
|
||||||
../nm-fake-platform.c \
|
../nm-fake-platform.c \
|
||||||
|
|
@ -106,20 +110,7 @@ test_cleanup_linux_CPPFLAGS = \
|
||||||
-DKERNEL_HACKS=1
|
-DKERNEL_HACKS=1
|
||||||
test_cleanup_linux_LDADD = $(PLATFORM_LDADD)
|
test_cleanup_linux_LDADD = $(PLATFORM_LDADD)
|
||||||
|
|
||||||
# Unfortunately, we cannot run nm-linux-platform-test as an automatic test
|
#@VALGRIND_RULES@
|
||||||
# program by default, as it requires root access and modifies kernel
|
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
|
||||||
# configuration.
|
|
||||||
#
|
|
||||||
# However, we can check whether the fake platform fakes platform behavior
|
|
||||||
# correctly.
|
|
||||||
|
|
||||||
@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
|
|
||||||
|
|
|
||||||
|
|
@ -145,9 +145,20 @@ int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
const char *program = *argv;
|
||||||
|
|
||||||
nmtst_init (&argc, &argv, NULL, "ALL");
|
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 ();
|
||||||
|
|
||||||
setup_tests ();
|
setup_tests ();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue