]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
ftests: Add cgconfigparser auto convert test
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Fri, 7 Apr 2023 14:15:19 +0000 (19:45 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 12 Apr 2023 14:06:51 +0000 (08:06 -0600)
Add a test to exercise cgconfigparser auto convert functionality.

-----------------------------------------------------------------
Test Results:
        Run Date:                          Apr 07 14:14:57
        Passed:                                  1 test(s)
        Skipped:                                 0 test(s)
        Failed:                                  0 test(s)
-----------------------------------------------------------------
Timing Results:
        Test                             Time (sec)
        -------------------------------------------
        setup                                  0.00
        076-cgconfig-auto_convert.py           0.11
        teardown                               0.00
        -------------------------------------------
        Total Run Time                         0.11

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
TJH: Changed test number to 76 and added it to Makefile.am
(cherry picked from commit ed568ec5ac793ac1808e73af1a76a1adcc083fc5)

tests/ftests/076-cgconfig-auto_convert.py [new file with mode: 0755]
tests/ftests/Makefile.am

diff --git a/tests/ftests/076-cgconfig-auto_convert.py b/tests/ftests/076-cgconfig-auto_convert.py
new file mode 100755 (executable)
index 0000000..751feb2
--- /dev/null
@@ -0,0 +1,113 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: LGPL-2.1-only
+#
+# cgconfigparser auto convert functionality test using a configuration file
+#
+# Copyright (c) 2023 Oracle and/or its affiliates.
+# Author: Kamalesh Babulal <kamalesh.babulal@oracle.com>
+#
+
+from cgroup import Cgroup, CgroupVersion
+import consts
+import ftests
+import sys
+import os
+
+CONTROLLER = 'cpu'
+
+CGNAME_V1 = '076cgconfig_v1'
+CFS_PERIOD = '100000'
+CFS_QUOTA = '50000'
+CPU_SHARES = '1024'
+
+CGNAME_V2 = '076cgconfig_v2'
+CFS_MAX = '"max 100000"'
+CPU_WEIGHT = '50'
+
+CONFIG_FILE = '''
+group {} {{
+    {} {{
+        cpu.cfs_period_us = {};
+        cpu.cfs_quota_us = {};
+        cpu.shares = {};
+    }}
+}}
+group {} {{
+    {} {{
+        cpu.max = {};
+        cpu.weight = {};
+    }}
+}}'''.format(
+                CGNAME_V1, CONTROLLER, CFS_PERIOD, CFS_QUOTA, CPU_SHARES,
+                CGNAME_V2, CONTROLLER, CFS_MAX, CPU_WEIGHT
+            )
+
+CONFIG_FILE_NAME = os.path.join(os.getcwd(), '078cgconfig.conf')
+
+TABLE = [
+            [CGNAME_V1, 'cpu.weight', CgroupVersion.CGROUP_V2, '100'],
+            [CGNAME_V1, 'cpu.max', CgroupVersion.CGROUP_V2, '50000 100000'],
+            [CGNAME_V2, 'cpu.shares', CgroupVersion.CGROUP_V1, '512'],
+            [CGNAME_V2, 'cpu.cfs_period_us', CgroupVersion.CGROUP_V1, '100000'],
+            [CGNAME_V2, 'cpu.cfs_quota_us', CgroupVersion.CGROUP_V1, '-1'],
+        ]
+
+
+def prereqs(config):
+    return consts.TEST_PASSED, None
+
+
+def setup(config):
+    f = open(CONFIG_FILE_NAME, 'w')
+    f.write(CONFIG_FILE)
+    f.close()
+
+
+def test(config):
+    result = consts.TEST_PASSED
+    cause = None
+
+    Cgroup.configparser(config, load_file=CONFIG_FILE_NAME)
+
+    for entry in TABLE:
+        out = Cgroup.xget(
+                            config, cgname=entry[0], setting=entry[1],
+                            version=entry[2], values_only=True, print_headers=False
+                         )
+
+        if out != entry[3]:
+            result = consts.TEST_FAILED
+            tmp_cause = (
+                            'Expected {}={}, received {}={} '
+                            ''.format(entry[1], entry[3], entry[1], out)
+                        )
+            cause = '\n'.join(filter(None, [cause, tmp_cause]))
+
+    return result, cause
+
+
+def teardown(config):
+    Cgroup.delete(config, CONTROLLER, CGNAME_V1)
+    Cgroup.delete(config, CONTROLLER, CGNAME_V2)
+    os.remove(CONFIG_FILE_NAME)
+
+
+def main(config):
+    [result, cause] = prereqs(config)
+
+    try:
+        setup(config)
+        [result, cause] = test(config)
+    finally:
+        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 f25aab5ca596364fc8a1b8d4b4fdb5ce751d6aa8..5ed61db88eea525fd6b0db961702bf90ea908d77 100644 (file)
@@ -96,6 +96,7 @@ EXTRA_DIST_PYTHON_TESTS = \
                          073-pybindings-cgroup_add_all_controllers-v2.py \
                          074-pybindings-cgroup_add_all_controllers-v1.py \
                          075-pybindings-cgroup_compare_cgroup.py \
+                         076-cgconfig-auto_convert.py \
                          998-cgdelete-non-existing-shared-mnt-cgroup-v1.py
 # Intentionally omit the stress test from the extra dist
 # 999-stress-cgroup_init.py