Blob Blame History Raw
From 32a4ce451c3aa579d768005decd5342ba319a0e7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Tue, 1 Dec 2015 22:35:16 -0500
Subject: [PATCH 1/4] tests: turn check if manager cannot be intialized into
 macro

We need to check the same thing in multiple tests. Use a shared
macro to make it easier to update the list of errnos.

Change the errno code for "unitialized cgroup fs" for ENOMEDIUM.
Exec format error looks like something more serious.

This fixes test-execute invocation in mock.

(cherry picked from commit 8b3aa503c171acdb9ec63484a8c50e2680d31e79)

Resolves: #1286249
---
 src/basic/cgroup-util.c                |  2 +-
 src/libsystemd/sd-bus/test-bus-creds.c |  2 +-
 src/test/test-engine.c                 |  3 ++-
 src/test/test-execute.c                |  3 ++-
 src/test/test-helper.h                 | 12 ++++++++++++
 src/test/test-path.c                   |  3 ++-
 src/test/test-sched-prio.c             |  3 ++-
 7 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c
index f7fc2c2..263c726 100644
--- a/src/basic/cgroup-util.c
+++ b/src/basic/cgroup-util.c
@@ -2130,7 +2130,7 @@ int cg_unified(void) {
         else if (F_TYPE_EQUAL(fs.f_type, TMPFS_MAGIC))
                 unified_cache = false;
         else
-                return -ENOEXEC;
+                return -ENOMEDIUM;
 
         return unified_cache;
 }
diff --git a/src/libsystemd/sd-bus/test-bus-creds.c b/src/libsystemd/sd-bus/test-bus-creds.c
index bd0101a..de337bb 100644
--- a/src/libsystemd/sd-bus/test-bus-creds.c
+++ b/src/libsystemd/sd-bus/test-bus-creds.c
@@ -29,7 +29,7 @@ int main(int argc, char *argv[]) {
         _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
         int r;
 
-        if (cg_unified() == -ENOEXEC) {
+        if (cg_unified() == -ENOMEDIUM) {
                 puts("Skipping test: /sys/fs/cgroup/ not available");
                 return EXIT_TEST_SKIP;
         }
diff --git a/src/test/test-engine.c b/src/test/test-engine.c
index 4f14c58..f09df43 100644
--- a/src/test/test-engine.c
+++ b/src/test/test-engine.c
@@ -25,6 +25,7 @@
 
 #include "bus-util.h"
 #include "manager.h"
+#include "test-helper.h"
 
 int main(int argc, char *argv[]) {
         _cleanup_bus_error_free_ sd_bus_error err = SD_BUS_ERROR_NULL;
@@ -38,7 +39,7 @@ int main(int argc, char *argv[]) {
         /* prepare the test */
         assert_se(set_unit_path(TEST_DIR) >= 0);
         r = manager_new(MANAGER_USER, true, &m);
-        if (IN_SET(r, -EPERM, -EACCES, -EADDRINUSE, -EHOSTDOWN, -ENOENT, -ENOEXEC)) {
+        if (MANAGER_SKIP_TEST(r)) {
                 printf("Skipping test: manager_new: %s", strerror(-r));
                 return EXIT_TEST_SKIP;
         }
diff --git a/src/test/test-execute.c b/src/test/test-execute.c
index 03ec0fc..1ab10fb 100644
--- a/src/test/test-execute.c
+++ b/src/test/test-execute.c
@@ -29,6 +29,7 @@
 #include "mkdir.h"
 #include "path-util.h"
 #include "rm-rf.h"
+#include "test-helper.h"
 #include "unit.h"
 #include "util.h"
 
@@ -296,7 +297,7 @@ int main(int argc, char *argv[]) {
         assert_se(unsetenv("VAR3") == 0);
 
         r = manager_new(MANAGER_USER, true, &m);
-        if (IN_SET(r, -EPERM, -EACCES, -EADDRINUSE, -EHOSTDOWN, -ENOENT)) {
+        if (MANAGER_SKIP_TEST(r)) {
                 printf("Skipping test: manager_new: %s", strerror(-r));
                 return EXIT_TEST_SKIP;
         }
diff --git a/src/test/test-helper.h b/src/test/test-helper.h
index f75dd33..c0f6a91 100644
--- a/src/test/test-helper.h
+++ b/src/test/test-helper.h
@@ -23,9 +23,21 @@
 
 #include "sd-daemon.h"
 
+#include "macro.h"
+
 #define TEST_REQ_RUNNING_SYSTEMD(x)                                 \
         if (sd_booted() > 0) {                                      \
                 x;                                                  \
         } else {                                                    \
                 printf("systemd not booted skipping '%s'\n", #x);   \
         }
+
+#define MANAGER_SKIP_TEST(r)                                    \
+        IN_SET(r,                                               \
+               -EPERM,                                          \
+               -EACCES,                                         \
+               -EADDRINUSE,                                     \
+               -EHOSTDOWN,                                      \
+               -ENOENT,                                         \
+               -ENOMEDIUM /* cannot determine cgroup */         \
+               )
diff --git a/src/test/test-path.c b/src/test/test-path.c
index 8302bdd..6e6a72d 100644
--- a/src/test/test-path.c
+++ b/src/test/test-path.c
@@ -29,6 +29,7 @@
 #include "rm-rf.h"
 #include "string-util.h"
 #include "strv.h"
+#include "test-helper.h"
 #include "unit.h"
 #include "util.h"
 
@@ -44,7 +45,7 @@ static int setup_test(Manager **m) {
         assert_se(m);
 
         r = manager_new(MANAGER_USER, true, &tmp);
-        if (IN_SET(r, -EPERM, -EACCES, -EADDRINUSE, -EHOSTDOWN, -ENOENT, -ENOEXEC)) {
+        if (MANAGER_SKIP_TEST(r)) {
                 printf("Skipping test: manager_new: %s", strerror(-r));
                 return -EXIT_TEST_SKIP;
         }
diff --git a/src/test/test-sched-prio.c b/src/test/test-sched-prio.c
index 8396ae6..7958a6c 100644
--- a/src/test/test-sched-prio.c
+++ b/src/test/test-sched-prio.c
@@ -23,6 +23,7 @@
 
 #include "macro.h"
 #include "manager.h"
+#include "test-helper.h"
 
 int main(int argc, char *argv[]) {
         Manager *m = NULL;
@@ -35,7 +36,7 @@ int main(int argc, char *argv[]) {
         /* prepare the test */
         assert_se(set_unit_path(TEST_DIR) >= 0);
         r = manager_new(MANAGER_USER, true, &m);
-        if (IN_SET(r, -EPERM, -EACCES, -EADDRINUSE, -EHOSTDOWN, -ENOENT, -ENOEXEC)) {
+        if (MANAGER_SKIP_TEST(r)) {
                 printf("Skipping test: manager_new: %s", strerror(-r));
                 return EXIT_TEST_SKIP;
         }
-- 
2.5.0