From: Tom Hromatka Date: Wed, 2 Feb 2022 17:48:10 +0000 (+0000) Subject: ftests: Add a test for unmappable settings X-Git-Tag: v3.1.0~308^2~2^2~105^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c2c6fd2e725f9aada70716c0613a6d4735436f08;p=thirdparty%2Flibcgroup.git ftests: Add a test for unmappable settings ----------------------------------------------------------------- Test Results: Run Date: Feb 02 17:47:50 Passed: 1 test(s) Skipped: 0 test(s) Failed: 0 test(s) ----------------------------------------------------------------- Timing Results: Test Time (sec) --------------------------------------- setup 0.00 042-cgxget-unmappable.py 0.19 teardown 0.00 --------------------------------------- Total Run Time 0.19 Signed-off-by: Tom Hromatka --- diff --git a/ftests/042-cgxget-unmappable.py b/ftests/042-cgxget-unmappable.py new file mode 100755 index 00000000..0c48247f --- /dev/null +++ b/ftests/042-cgxget-unmappable.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python3 +# +# Cgxget test with no mappable settings +# +# Copyright (c) 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 = '042cgxget' +SETTING = 'cpu.stat' + +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 + + if CgroupVersion.get_version(CONTROLLER) == CgroupVersion.CGROUP_V1: + # request the opposite version of what this system is running + requested_ver = CgroupVersion.CGROUP_V2 + else: + requested_ver = CgroupVersion.CGROUP_V1 + + out = Cgroup.xget(config, cgname=CGNAME, setting=SETTING, + version=requested_ver, print_headers=False, + ignore_unmappable=True) + if len(out): + result = consts.TEST_FAILED + cause = "Expected cgxget to return nothing. Received {}".format(out) + + 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))