Add a test that invokes lscgroup with a single '-g' flag.

-----------------------------------------------------------------
Test Results:
        Run Date:                          Mar 25 16:34:25
        Passed:                                  1 test(s)
        Skipped:                                 0 test(s)
        Failed:                                  0 test(s)
-----------------------------------------------------------------
Timing Results:
        Test                                    Time (sec)
        ---------------------------------------------------------
        setup                                        18.41
        031-lscgroup-g_flag.py                        0.58
        teardown                                      0.00
        ---------------------------------------------------------
        Total Run Time                               18.98

Signed-off-by: Tom Hromatka <tom.hroma...@oracle.com>
---
 ftests/031-lscgroup-g_flag.py | 94 +++++++++++++++++++++++++++++++++++
 1 file changed, 94 insertions(+)
 create mode 100755 ftests/031-lscgroup-g_flag.py

diff --git a/ftests/031-lscgroup-g_flag.py b/ftests/031-lscgroup-g_flag.py
new file mode 100755
index 000000000000..2f9b5d01f4f6
--- /dev/null
+++ b/ftests/031-lscgroup-g_flag.py
@@ -0,0 +1,94 @@
+#!/usr/bin/env python3
+#
+# lscgroup functionality test
+#
+# Copyright (c) 2021 Oracle and/or its affiliates.
+# Author: Tom Hromatka <tom.hroma...@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 = '031lscgroup'
+CHILD_CGNAME = 'childlscgroup'
+GRANDCHILD_CGNAME = 'grandchildlscgroup'
+
+# 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)
+
+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))
+
+def test(config):
+    result = consts.TEST_PASSED
+    cause = None
+
+    out = Cgroup.lscgroup(config, controller=CONTROLLER, path=PARENT_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
+
+    return result, cause
+
+def teardown(config):
+    Cgroup.delete(config, CONTROLLER, PARENT_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))
-- 
2.26.2



_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to