chiark / gitweb /
test: fix some tests when running inside a container
authorJan Synacek <jsynacek@redhat.com>
Wed, 10 Dec 2014 09:20:11 +0000 (10:20 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 10 Dec 2014 12:36:10 +0000 (13:36 +0100)
src/test/test-execute.c
src/test/test-util.c
test/udev-test.pl

index 85deb27f4393abd45530ef3a291941dcd8d0fd57..60466f0d3ffaae68375d6098df2b6fa03e8af1d4 100644 (file)
@@ -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);
index 20e711d415b7af2fcaf908184b553cf9994140e8..fe54586eeedc252b6c735c40ed1b894622196cda 100644 (file)
@@ -35,6 +35,7 @@
 #include "def.h"
 #include "fileio.h"
 #include "conf-parser.h"
+#include "virt.h"
 
 static void test_streq_ptr(void) {
         assert_se(streq_ptr(NULL, NULL));
@@ -544,7 +545,8 @@ 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);
+        if (!detect_container(NULL))
+                assert_se(get_ctty_devnr(1, &h) == -ENOENT);
 
         getenv_for_pid(1, "PATH", &i);
         log_info("pid1 $PATH: '%s'", strna(i));
index 14f11df8af94d53e1860ffb135cc2f52ac160a19..3e05b61777aaf50d92f9fe796cb8a2b85dc32f41 100755 (executable)
@@ -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;