richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
b7dd4d
From 33305c6801c10b741b11a3f329dc339d2e8c5514 Mon Sep 17 00:00:00 2001
4262b8
From: Lukas Nykryn <lnykryn@redhat.com>
4262b8
Date: Thu, 18 Aug 2022 16:35:23 +0200
4262b8
Subject: [PATCH] test-procfs-util: skip test on certain errors
4262b8
4262b8
Inspired by upstream bf47f71c1c
4262b8
4262b8
RHEL-only
4262b8
Related: #2087152
4262b8
---
4262b8
 src/shared/tests.c          | 12 ++++++++++++
4262b8
 src/shared/tests.h          |  2 ++
4262b8
 src/test/test-procfs-util.c |  6 ++++--
4262b8
 3 files changed, 18 insertions(+), 2 deletions(-)
4262b8
4262b8
diff --git a/src/shared/tests.c b/src/shared/tests.c
4262b8
index 1da80d653f..b1c71b992f 100644
4262b8
--- a/src/shared/tests.c
4262b8
+++ b/src/shared/tests.c
4262b8
@@ -78,6 +78,18 @@ void test_setup_logging(int level) {
4262b8
         log_open();
4262b8
 }
4262b8
 
4262b8
+int log_tests_skipped(const char *message) {
4262b8
+        log_notice("%s: %s, skipping tests.",
4262b8
+                   program_invocation_short_name, message);
4262b8
+        return EXIT_TEST_SKIP;
4262b8
+}
4262b8
+
4262b8
+int log_tests_skipped_errno(int r, const char *message) {
4262b8
+        log_notice_errno(r, "%s: %s, skipping tests: %m",
4262b8
+                         program_invocation_short_name, message);
4262b8
+        return EXIT_TEST_SKIP;
4262b8
+}
4262b8
+
4262b8
 const char *ci_environment(void) {
4262b8
         /* We return a string because we might want to provide multiple bits of information later on: not
4262b8
          * just the general CI environment type, but also whether we're sanitizing or not, etc. The caller is
4262b8
diff --git a/src/shared/tests.h b/src/shared/tests.h
4262b8
index 4f8f349097..d50711338c 100644
4262b8
--- a/src/shared/tests.h
4262b8
+++ b/src/shared/tests.h
4262b8
@@ -5,6 +5,8 @@ char* setup_fake_runtime_dir(void);
4262b8
 bool test_is_running_from_builddir(char **exedir);
4262b8
 const char* get_testdata_dir(void);
4262b8
 void test_setup_logging(int level);
4262b8
+int log_tests_skipped(const char *message);
4262b8
+int log_tests_skipped_errno(int r, const char *message);
4262b8
 
4262b8
 /* Provide a convenient way to check if we're running in CI. */
4262b8
 const char *ci_environment(void);
4262b8
diff --git a/src/test/test-procfs-util.c b/src/test/test-procfs-util.c
4262b8
index d656c4df4f..aba5692e54 100644
4262b8
--- a/src/test/test-procfs-util.c
4262b8
+++ b/src/test/test-procfs-util.c
4262b8
@@ -7,6 +7,7 @@
4262b8
 #include "procfs-util.h"
4262b8
 #include "process-util.h"
4262b8
 #include "util.h"
4262b8
+#include "tests.h"
4262b8
 
4262b8
 int main(int argc, char *argv[]) {
4262b8
         char buf[CONST_MAX(FORMAT_TIMESPAN_MAX, FORMAT_BYTES_MAX)];
4262b8
@@ -52,8 +53,9 @@ int main(int argc, char *argv[]) {
4262b8
                 log_info("Reducing limit by one to %"PRIu64"…", v-1);
4262b8
 
4262b8
                 r = procfs_tasks_set_limit(v-1);
4262b8
-                log_info_errno(r, "procfs_tasks_set_limit: %m");
4262b8
-                assert_se(r >= 0 || ERRNO_IS_PRIVILEGE(r) || r == -EROFS);
4262b8
+                if (IN_SET(r, -ENOENT, -EROFS) || ERRNO_IS_PRIVILEGE(r))
4262b8
+                        return log_tests_skipped_errno(r, "can't set tasks limit");
4262b8
+                assert_se(r >= 0);
4262b8
 
4262b8
                 assert_se(procfs_get_threads_max(&w) >= 0);
4262b8
                 assert_se(r >= 0 ? w == v - 1 : w == v);