From: Tom Hromatka Date: Thu, 16 Dec 2021 14:59:44 +0000 (-0700) Subject: ftests: Add a cgxget/cgxset test for the cpu controller X-Git-Tag: v3.1.0~308^2~2^2~105^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c946ef39c6fd13bb7d49dc7a856d82dc2d73707d;p=thirdparty%2Flibcgroup.git ftests: Add a cgxget/cgxset test for the cpu controller Add a functional test that exercises the cpu v1/v2 mappings. ----------------------------------------------------------------- Test Results: Run Date: Apr 19 18:39:16 Passed: 1 test(s) Skipped: 0 test(s) Failed: 0 test(s) ----------------------------------------------------------------- Timing Results: Test Time (sec) --------------------------------------------------------- setup 0.00 037-cgxget-cpu_settings.py 0.50 teardown 0.00 --------------------------------------------------------- Total Run Time 0.50 Signed-off-by: Tom Hromatka --- diff --git a/ftests/037-cgxget-cpu_settings.py b/ftests/037-cgxget-cpu_settings.py new file mode 100755 index 00000000..38772c68 --- /dev/null +++ b/ftests/037-cgxget-cpu_settings.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python3 +# +# cgxget functionality test - various cpu settings +# +# Copyright (c) 2021-2022 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 + +CONTROLLER = 'cpu' +CGNAME = '037cgxget' + +TABLE = [ + # writesetting, writeval, writever, readsetting, readval, readver + ['cpu.shares', '512', CgroupVersion.CGROUP_V1, 'cpu.shares', '512', CgroupVersion.CGROUP_V1], + ['cpu.shares', '512', CgroupVersion.CGROUP_V1, 'cpu.weight', '50', CgroupVersion.CGROUP_V2], + ['cpu.weight', '200', CgroupVersion.CGROUP_V2, 'cpu.shares', '2048', CgroupVersion.CGROUP_V1], + ['cpu.weight', '200', CgroupVersion.CGROUP_V2, 'cpu.weight', '200', CgroupVersion.CGROUP_V2], +] + +def prereqs(config): + result = consts.TEST_PASSED + cause = None + + return result, cause + +def setup(config): + Cgroup.create(config, CONTROLLER, CGNAME) + +def test(config): + result = consts.TEST_PASSED + cause = None + + for entry in TABLE: + Cgroup.xset(config, cgname=CGNAME, setting=entry[0], value=entry[1], + version=entry[2]) + + out = Cgroup.xget(config, cgname=CGNAME, setting=entry[3], + version=entry[5], values_only=True, + print_headers=False) + if out != entry[4]: + result = consts.TEST_FAILED + cause = "After setting {}={}, expected {}={}, but received {}={}".format( + entry[0], entry[1], entry[3], entry[4], entry[3], out) + return result, cause + + return result, cause + +def teardown(config): + Cgroup.delete(config, CONTROLLER, CGNAME) + +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))