From: Tom Hromatka Date: Thu, 25 Mar 2021 16:35:32 +0000 (+0000) Subject: ftests: Add an lscgroup test with multiple '-g' flags X-Git-Tag: v2.0.3~11^2^2~18^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=58bdb7b4c5ac476e1966836913d37ca21082510e;p=thirdparty%2Flibcgroup.git ftests: Add an lscgroup test with multiple '-g' flags 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 --- diff --git a/ftests/032-lscgroup-multiple_g_flags.py b/ftests/032-lscgroup-multiple_g_flags.py new file mode 100755 index 00000000..307b1c73 --- /dev/null +++ b/ftests/032-lscgroup-multiple_g_flags.py @@ -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 +# + +# +# 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 . +# + +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))