From 40a23924efc64598d580b5fd92ef3937583d1fc9 Mon Sep 17 00:00:00 2001
From: Steve Muir <muir@fb.com>
Date: Wed, 27 Jul 2016 14:19:37 -0700
Subject: tests: don't test hostname if it looks like an id128

The condition tests for hostname will fail if hostname looks like an id128.
The test function attempts to convert hostname to an id128, and if that
succeeds compare it to the machine ID (presumably because the 'hostname'
condition test is overloaded to also test machine ID). That will typically
fail, and unfortunately the 'mock' utility generates a random hostname that
happens to have the same format as an id128, thus causing a test failure.
---
 src/test/test-condition.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

(limited to 'src/test')

diff --git a/src/test/test-condition.c b/src/test/test-condition.c
index 987862f1c6..4ef61ebfa5 100644
--- a/src/test/test-condition.c
+++ b/src/test/test-condition.c
@@ -25,6 +25,7 @@
 #include "audit-util.h"
 #include "condition.h"
 #include "hostname-util.h"
+#include "id128-util.h"
 #include "ima-util.h"
 #include "log.h"
 #include "macro.h"
@@ -142,9 +143,14 @@ static void test_condition_test_host(void) {
         hostname = gethostname_malloc();
         assert_se(hostname);
 
-        condition = condition_new(CONDITION_HOST, hostname, false, false);
-        assert_se(condition_test(condition));
-        condition_free(condition);
+        /* if hostname looks like an id128 then skip testing it */
+        if (id128_is_valid(hostname)) {
+                log_notice("hostname is an id128, skipping test");
+        } else {
+                condition = condition_new(CONDITION_HOST, hostname, false, false);
+                assert_se(condition_test(condition));
+                condition_free(condition);
+        }
 }
 
 static void test_condition_test_architecture(void) {
-- 
cgit v1.2.3-54-g00ecf


From 76c19e9f6c8e8e5922e43716137d532c542e34c8 Mon Sep 17 00:00:00 2001
From: Davide Cavalca <dcavalca@fb.com>
Date: Wed, 27 Jul 2016 14:22:26 -0700
Subject: tests: skip process 1 tests if systemd not is running

No point running tests against process 1 if systemd is not running as that
process. This is a rework of an unpublished patch by @9muir.
---
 src/test/test-process-util.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

(limited to 'src/test')

diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c
index 562ad4acb8..9ada46b1e9 100644
--- a/src/test/test-process-util.c
+++ b/src/test/test-process-util.c
@@ -40,6 +40,7 @@
 #include "stdio-util.h"
 #include "string-util.h"
 #include "terminal-util.h"
+#include "test-helper.h"
 #include "util.h"
 #include "virt.h"
 
@@ -357,7 +358,7 @@ int main(int argc, char *argv[]) {
                 (void) parse_pid(argv[1], &pid);
                 test_get_process_comm(pid);
         } else {
-                test_get_process_comm(1);
+                TEST_REQ_RUNNING_SYSTEMD(test_get_process_comm(1));
                 test_get_process_comm(getpid());
         }
 
-- 
cgit v1.2.3-54-g00ecf


From 4dd4cb8fe40baea007336a346ec2aa645890eec3 Mon Sep 17 00:00:00 2001
From: Steve Muir <muir@fb.com>
Date: Wed, 27 Jul 2016 14:23:44 -0700
Subject: tests: don't run private device tests if running in a container

Private devices don't exist when running in a container, so skip the related
tests.
---
 src/test/test-execute.c | 5 +++++
 1 file changed, 5 insertions(+)

(limited to 'src/test')

diff --git a/src/test/test-execute.c b/src/test/test-execute.c
index 77ef4e8b2a..baf5b96487 100644
--- a/src/test/test-execute.c
+++ b/src/test/test-execute.c
@@ -33,6 +33,7 @@
 #include "test-helper.h"
 #include "unit.h"
 #include "util.h"
+#include "virt.h"
 
 typedef void (*test_function_t)(Manager *m);
 
@@ -111,6 +112,10 @@ static void test_exec_privatetmp(Manager *m) {
 }
 
 static void test_exec_privatedevices(Manager *m) {
+        if (detect_container() > 0) {
+                log_notice("testing in container, skipping private device tests");
+                return;
+        }
         test(m, "exec-privatedevices-yes.service", 0, CLD_EXITED);
         test(m, "exec-privatedevices-no.service", 0, CLD_EXITED);
 }
-- 
cgit v1.2.3-54-g00ecf