[systemd-devel] [PATCH] test: fix some tests when running inside a container

Jan Synacek jsynacek at redhat.com
Wed Dec 10 00:57:58 PST 2014


---
 src/test/test-execute.c | 2 +-
 src/test/test-util.c    | 3 ---
 test/udev-test.pl       | 8 ++++++++
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/test/test-execute.c b/src/test/test-execute.c
index 85deb27..60466f0 100644
--- a/src/test/test-execute.c
+++ b/src/test/test-execute.c
@@ -164,7 +164,7 @@ int main(int argc, char *argv[]) {
         r = manager_new(SYSTEMD_USER, true, &m);
         if (IN_SET(r, -EPERM, -EACCES, -EADDRINUSE, -EHOSTDOWN, -ENOENT)) {
                 printf("Skipping test: manager_new: %s", strerror(-r));
-                return -EXIT_TEST_SKIP;
+                return EXIT_TEST_SKIP;
         }
         assert_se(r >= 0);
         assert_se(manager_startup(m, NULL, NULL) >= 0);
diff --git a/src/test/test-util.c b/src/test/test-util.c
index 20e711d..c055955 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -495,7 +495,6 @@ static void test_get_process_comm(void) {
         pid_t e;
         uid_t u;
         gid_t g;
-        dev_t h;
         int r;
         pid_t me;
 
@@ -544,8 +543,6 @@ static void test_get_process_comm(void) {
         assert_se(r >= 0 || r == -EACCES);
         log_info("self strlen(environ): '%zd'", strlen(env));
 
-        assert_se(get_ctty_devnr(1, &h) == -ENOENT);
-
         getenv_for_pid(1, "PATH", &i);
         log_info("pid1 $PATH: '%s'", strna(i));
 }
diff --git a/test/udev-test.pl b/test/udev-test.pl
index 14f11df..3e05b61 100755
--- a/test/udev-test.pl
+++ b/test/udev-test.pl
@@ -27,6 +27,7 @@ my $udev_dev            = "test/dev";
 my $udev_run            = "test/run";
 my $udev_rules_dir      = "$udev_run/udev/rules.d";
 my $udev_rules          = "$udev_rules_dir/udev-test.rules";
+my $EXIT_TEST_SKIP      = 77;
 
 my @tests = (
         {
@@ -1485,6 +1486,13 @@ if (!($<==0)) {
         exit;
 }
 
+# skip the test when running in a container
+system("systemd-detect-virt", "-c", "-q");
+if ($? >> 8 == 0) {
+    print "Running in a container, skipping the test.\n";
+    exit($EXIT_TEST_SKIP);
+}
+
 udev_setup();
 
 my $test_num = 1;
-- 
1.9.3



More information about the systemd-devel mailing list