naccyde / rpms / systemd

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