152484
From 16908e1ec833d857cb418712c382c6f604426b36 Mon Sep 17 00:00:00 2001
152484
From: Frantisek Sumsal <frantisek@sumsal.cz>
152484
Date: Tue, 1 Feb 2022 20:18:29 +0100
152484
Subject: [PATCH] test: introduce `get_cgroup_hierarchy() helper
152484
152484
which returns the host's cgroup hierarchy (unified, hybrid, or legacy).
152484
152484
(cherry picked from commit f723740871bd3eb89d16a526a1ff77c04bb3787a)
152484
152484
Related: #2047768
152484
---
152484
 test/test-functions | 18 ++++++++++++++++++
152484
 1 file changed, 18 insertions(+)
152484
152484
diff --git a/test/test-functions b/test/test-functions
152484
index 35d8f074a9..4827b6bedf 100644
152484
--- a/test/test-functions
152484
+++ b/test/test-functions
152484
@@ -1996,6 +1996,24 @@ import_initdir() {
152484
     export initdir
152484
 }
152484
 
152484
+get_cgroup_hierarchy() {
152484
+    case "$(stat -c '%T' -f /sys/fs/cgroup)" in
152484
+        cgroup2fs)
152484
+            echo "unified"
152484
+            ;;
152484
+        tmpfs)
152484
+            if [[ -d /sys/fs/cgroup/unified && "$(stat -c '%T' -f /sys/fs/cgroup/unified)" == cgroup2fs ]]; then
152484
+                echo "hybrid"
152484
+            else
152484
+                echo "legacy"
152484
+            fi
152484
+            ;;
152484
+        *)
152484
+            dfatal "Failed to determine host's cgroup hierarchy"
152484
+            exit 1
152484
+    esac
152484
+}
152484
+
152484
 ## @brief Converts numeric logging level to the first letter of level name.
152484
 #
152484
 # @param lvl Numeric logging level in range from 1 to 6.