From f28099ea23ab3e7ca8e0111a1e4b90fe2f381015 Mon Sep 17 00:00:00 2001 From: Kamalesh Babulal Date: Tue, 17 Oct 2023 15:56:37 +0530 Subject: [PATCH] ftests: add test to cgcreate of non default controllers Add test to create cgroups with non default controllers (hugetlb, misc) using the cgcreate. ----------------------------------------------------------------- Test Results: Run Date: Oct 20 05:21:48 Passed: 1 test(s) Skipped: 0 test(s) Failed: 0 test(s) ----------------------------------------------------------------- Timing Results: Test Time (sec) --------------------------------------------------------- setup 0.00 091-cgcreate-non-default-controllers-v2.py 0.04 teardown 0.00 --------------------------------------------------------- Total Run Time 0.04 Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- ...091-cgcreate-non-default-controllers-v2.py | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100755 tests/ftests/091-cgcreate-non-default-controllers-v2.py diff --git a/tests/ftests/091-cgcreate-non-default-controllers-v2.py b/tests/ftests/091-cgcreate-non-default-controllers-v2.py new file mode 100755 index 00000000..e279e3e1 --- /dev/null +++ b/tests/ftests/091-cgcreate-non-default-controllers-v2.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: LGPL-2.1-only +# +# cgcreate non default controller functionality test +# +# Copyright (c) 2023 Oracle and/or its affiliates. +# Author: Kamalesh Babulal +# + +from cgroup import Cgroup, Mode +import consts +import ftests +import sys +import os + +CONTROLLERS = ['hugetlb', 'misc'] + +CGNAME = '090cgcreate' +CGNAME1 = os.path.join(CGNAME, 'childcg') +CGNAME2 = os.path.join(CGNAME1, 'grandchildcg') + + +def prereqs(config): + result = consts.TEST_PASSED + cause = None + + if Cgroup.get_cgroup_mode(config) != Mode.CGROUP_MODE_UNIFIED: + result = consts.TEST_SKIPPED + cause = 'This test requires the unified cgroup v2 hierarchy' + + return result, cause + + +def setup(config): + Cgroup.create(config, CONTROLLERS, CGNAME2) + + +def test(config): + result = consts.TEST_PASSED + cause = None + + # checking if the controller is enabled in granchildcg, in turn will + # check its parent cgroup childcg's subtree_control file, if it's enabled + # in parent cgroup, it's also enabled in the grandparent too. + if not Cgroup.is_controller_enabled(config, CGNAME2, CONTROLLERS[0]): + result = consts.TEST_FAILED + cause = 'Controller {} is not enabled in the child cgroup'.format(CONTROLLERS[0]) + + if not Cgroup.is_controller_enabled(config, CGNAME2, CONTROLLERS[1]): + result = consts.TEST_FAILED + tmp_cause = 'Controller {} is not enabled in the child cgroup'.format(CONTROLLERS[1]) + cause = '\n'.join(filter(None, [cause, tmp_cause])) + + # for the grandchildcg read it cgroup.subtree_control, is_controller_enabled + # will check its parent cgroup childcg's subtree_control + if Cgroup.get(config, None, CGNAME2, setting='cgroup.subtree_control', + print_headers=False, values_only=True): + result = consts.TEST_FAILED + tmp_cause = 'Controller {} enabled in grandchild cgroup'.format(CONTROLLERS[0]) + cause = '\n'.join(filter(None, [cause, tmp_cause])) + + return result, cause + + +def teardown(config): + Cgroup.delete(config, CONTROLLERS, 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)) + +# vim: set et ts=4 sw=4: -- 2.47.2