]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
ftests: Add an lscgroup test with multiple '-g' flags
authorTom Hromatka <tom.hromatka@oracle.com>
Thu, 25 Mar 2021 16:35:32 +0000 (16:35 +0000)
committerTom Hromatka <tom.hromatka@oracle.com>
Thu, 8 Apr 2021 19:10:07 +0000 (13:10 -0600)
Add an lscgroup test with multiple '-g' flags.

-----------------------------------------------------------------
Test Results:
        Run Date:                          Mar 25 16:35:47
        Passed:                                  1 test(s)
        Skipped:                                 0 test(s)
        Failed:                                  0 test(s)
-----------------------------------------------------------------
Timing Results:
        Test                                    Time (sec)
        ---------------------------------------------------------
        setup                                        14.12
        032-lscgroup-multiple_g_flags.py              4.63
        teardown                                      0.00
        ---------------------------------------------------------
        Total Run Time                               18.75

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
ftests/032-lscgroup-multiple_g_flags.py [new file with mode: 0755]

diff --git a/ftests/032-lscgroup-multiple_g_flags.py b/ftests/032-lscgroup-multiple_g_flags.py
new file mode 100755 (executable)
index 0000000..307b1c7
--- /dev/null
@@ -0,0 +1,112 @@
+#!/usr/bin/env python3
+#
+# lscgroup functionality test - multiple '-g' flags
+#
+# Copyright (c) 2021 Oracle and/or its affiliates.
+# Author: Tom Hromatka <tom.hromatka@oracle.com>
+#
+
+#
+# This library is free software; you can redistribute it and/or modify it
+# under the terms of version 2.1 of the GNU Lesser General Public License as
+# published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+# for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this library; if not, see <http://www.gnu.org/licenses>.
+#
+
+from cgroup import Cgroup, CgroupVersion
+import consts
+import ftests
+import os
+import sys
+import utils
+
+CONTROLLER = 'cpuset'
+PARENT_CGNAME = '032lscgroup'
+CHILD_CGNAME = 'childlscgroup'
+GRANDCHILD_CGNAME = 'grandchildlscgroup'
+SIBLING_CGNAME = '032sibling'
+SIBLING_CHILD_CGNAME = 'cousinlscgroup'
+
+# lscgroup is inconsistent in its handling of trailing slashes
+#
+# When invoking lscgroup with no flags, no trailing slashes are present in
+# any of the cgroups.
+#
+# When invoking lscgroup with the -g flag, a trailing slash is present on
+# the first cgroup returned (i.e. the cgroup specified in the -g flag)
+#
+EXPECTED_OUT1 = '''{}:/{}/
+{}:/{}/{}
+{}:/{}/{}/{}
+{}:/{}/
+{}:/{}/{}'''.format(CONTROLLER, PARENT_CGNAME,
+                    CONTROLLER, PARENT_CGNAME, CHILD_CGNAME,
+                    CONTROLLER, PARENT_CGNAME, CHILD_CGNAME, GRANDCHILD_CGNAME,
+                    CONTROLLER, SIBLING_CGNAME,
+                    CONTROLLER, SIBLING_CGNAME, SIBLING_CHILD_CGNAME)
+
+def prereqs(config):
+    result = consts.TEST_PASSED
+    cause = None
+
+    return result, cause
+
+def setup(config):
+    Cgroup.create(config, CONTROLLER, PARENT_CGNAME)
+    Cgroup.create(config, CONTROLLER, os.path.join(PARENT_CGNAME, CHILD_CGNAME))
+    Cgroup.create(config, CONTROLLER,
+                  os.path.join(PARENT_CGNAME, CHILD_CGNAME, GRANDCHILD_CGNAME))
+
+    Cgroup.create(config, CONTROLLER, SIBLING_CGNAME)
+    Cgroup.create(config, CONTROLLER,
+                  os.path.join(SIBLING_CGNAME, SIBLING_CHILD_CGNAME))
+
+def test(config):
+    result = consts.TEST_PASSED
+    cause = None
+
+    out = Cgroup.lscgroup(config, controller=[CONTROLLER, CONTROLLER],
+                          path=[PARENT_CGNAME, SIBLING_CGNAME])
+    if out != EXPECTED_OUT1:
+        result = consts.TEST_FAILED
+        cause = "Expected lscgroup output doesn't match received output\n" \
+                "Expected:\n{}\n" \
+                "Received:\n{}\n".format(utils.indent(EXPECTED_OUT1, 4),
+                                         utils.indent(out, 4))
+        return result, cause
+
+    ret = Cgroup.lscgroup(config, cghelp=True)
+    if not "Usage:" in ret:
+        result = consts.TEST_FAILED
+        cause = "Failed to print help text"
+        return result, cause
+
+    return result, cause
+
+def teardown(config):
+    Cgroup.delete(config, CONTROLLER, PARENT_CGNAME, recursive=True)
+    Cgroup.delete(config, CONTROLLER, SIBLING_CGNAME, recursive=True)
+
+def main(config):
+    [result, cause] = prereqs(config)
+    if result != consts.TEST_PASSED:
+        return [result, cause]
+
+    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))