]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
ftests: add test case to excerise cgroup_setup_mode helpers
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Tue, 25 Apr 2023 12:36:28 +0000 (12:36 +0000)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 26 Apr 2023 19:27:51 +0000 (13:27 -0600)
Add tests to excerise the cgroup_setup_mode() helpers pybindings
is_cgroup_mode_{legacy,hybrid,unified}

-----------------------------------------------------------------
Test Results:
        Run Date:                          Apr 25 12:46:29
        Passed:                                  1 test(s)
        Skipped:                                 0 test(s)
        Failed:                                  0 test(s)
-----------------------------------------------------------------
Timing Results:
        Test                                      Time (sec)
        ----------------------------------------------------
        setup                                           0.00
        083-pybindings-helpers_cgroup_mode.py           0.00
        teardown                                        0.00
        ----------------------------------------------------
        Total Run Time                                  0.00

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
tests/ftests/083-pybindings-helpers_cgroup_mode.py [new file with mode: 0755]
tests/ftests/Makefile.am

diff --git a/tests/ftests/083-pybindings-helpers_cgroup_mode.py b/tests/ftests/083-pybindings-helpers_cgroup_mode.py
new file mode 100755 (executable)
index 0000000..8808a03
--- /dev/null
@@ -0,0 +1,79 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: LGPL-2.1-only
+#
+# Test to excerise cgroup_setup_mode() helpers
+#
+# Copyright (c) 2023 Oracle and/or its affiliates.
+# Author: Kamalesh Babulal <kamalesh.babulal@oracle.com>
+#
+
+from cgroup import Cgroup as CgroupCli
+from libcgroup import Cgroup, Mode
+import consts
+import ftests
+import sys
+import os
+
+
+def prereqs(config):
+    pass
+
+
+def setup(config):
+    pass
+
+
+def test(config):
+    result = consts.TEST_PASSED
+    cause = None
+
+    mode1 = Cgroup.cgroup_mode()
+    mode2 = CgroupCli.get_cgroup_mode(config)
+
+    if mode1 != mode2:
+        result = consts.TEST_FAILED
+        cause = 'mode mismatch: libcgroup mode: {}, tests mode: {}'.format(mode1, mode2)
+        return result, cause
+
+    if mode1 == Mode.CGROUP_MODE_LEGACY:
+        ret = Cgroup.is_cgroup_mode_legacy()
+        if ret is False:
+            result = consts.TEST_FAILED
+            cause = 'mode mismatch: libcgroup mode: legacy (v1) check, returned false'
+    elif mode1 == Mode.CGROUP_MODE_HYBRID:
+        ret = Cgroup.is_cgroup_mode_hybrid()
+        if ret is False:
+            result = consts.TEST_FAILED
+            cause = 'mode mismatch: libcgroup mode: hybrid (v1/v2) check, returned false'
+    elif mode1 == Mode.CGROUP_MODE_UNIFIED:
+        ret = Cgroup.is_cgroup_mode_unified()
+        if ret is False:
+            result = consts.TEST_FAILED
+            cause = 'mode mismatch: libcgroup mode: unified (v2) check, returned false'
+    else:
+        result = consts.TEST_FAILED
+        cause = 'Unknown libcgroup mode: {}'.format(mode1)
+
+    return result, cause
+
+
+def teardown(config):
+    pass
+
+
+def main(config):
+    prereqs(config)
+    setup(config)
+    [result, cause] = test(config)
+    teardown(config)
+
+    return [result, cause]
+
+
+if __name__ == '__main__':
+    config = ftests.parse_args()
+    # this test was invoked directly.  run only it
+    config.args.num = int(os.path.basename(__file__).split('-')[0])
+    sys.exit(ftests.main(config))
+
+# vim: set et ts=4 sw=4:
index c810eb64d313124a5a9341954823ffaa26e3b2df..2f82f8bbe030e69fbe797ad906bc66e0ccfef621 100644 (file)
@@ -101,6 +101,7 @@ EXTRA_DIST_PYTHON_TESTS = \
                          078-sudo-cgcreate_systemd_scope.py \
                          079-sudo-cgcreate_default_systemd_scope.py \
                          080-kernel-domain_invalid.py \
+                         083-pybindings-helpers_cgroup_mode.py \
                          998-cgdelete-non-existing-shared-mnt-cgroup-v1.py
 # Intentionally omit the stress test from the extra dist
 # 999-stress-cgroup_init.py