From: Tom Hromatka Date: Tue, 1 Jun 2021 22:10:12 +0000 (+0000) Subject: ftests: Modify functional test 008 to support cgroup v2 X-Git-Tag: v3.1.0~308^2~2^2~114^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dbd650e8f9efdfa345660dbbf234235717b0405d;p=thirdparty%2Flibcgroup.git ftests: Modify functional test 008 to support cgroup v2 Add cgroup v2 support to the 008-cgget-multiple_r_flags.py functional test. It continues to support cgroup v1 as well. Signed-off-by: Tom Hromatka --- diff --git a/ftests/008-cgget-multiple_r_flags.py b/ftests/008-cgget-multiple_r_flags.py index b0d5118b..605fab1a 100755 --- a/ftests/008-cgget-multiple_r_flags.py +++ b/ftests/008-cgget-multiple_r_flags.py @@ -29,10 +29,12 @@ import sys CONTROLLER = 'memory' CGNAME = '008cgget' -SETTING1 = 'memory.limit_in_bytes' +SETTING1_V1 = 'memory.limit_in_bytes' +SETTING1_V2 = 'memory.max' VALUE1 = '1048576' -SETTING2='memory.soft_limit_in_bytes' +SETTING2_V1 = 'memory.soft_limit_in_bytes' +SETTING2_V2 = 'memory.high' VALUE2 = '1024000' def prereqs(config): @@ -43,32 +45,45 @@ def prereqs(config): def setup(config): Cgroup.create(config, CONTROLLER, CGNAME) - Cgroup.set(config, CGNAME, SETTING1, VALUE1) - Cgroup.set(config, CGNAME, SETTING2, VALUE2) + + version = CgroupVersion.get_version(CONTROLLER) + + if version == CgroupVersion.CGROUP_V1: + Cgroup.set(config, CGNAME, SETTING1_V1, VALUE1) + Cgroup.set(config, CGNAME, SETTING2_V1, VALUE2) + elif version == CgroupVersion.CGROUP_V2: + Cgroup.set(config, CGNAME, SETTING1_V2, VALUE1) + Cgroup.set(config, CGNAME, SETTING2_V2, VALUE2) def test(config): result = consts.TEST_PASSED cause = None - out = Cgroup.get(config, controller=None, cgname=CGNAME, - setting=[SETTING1, SETTING2]) + version = CgroupVersion.get_version(CONTROLLER) + + if version == CgroupVersion.CGROUP_V1: + settings=[SETTING1_V1, SETTING2_V1] + elif version == CgroupVersion.CGROUP_V2: + settings=[SETTING1_V2, SETTING2_V2] + + out = Cgroup.get(config, controller=None, cgname=CGNAME, setting=settings) if out.splitlines()[0] != "{}:".format(CGNAME): result = consts.TEST_FAILED cause = "cgget expected the cgroup name {} in the first line.\n" \ "Instead it received {}".format(CGNAME, out.splitlines()[0]) - if out.splitlines()[1] != "{}: {}".format(SETTING1, VALUE1): + if out.splitlines()[1] != "{}: {}".format(settings[0], VALUE1): result = consts.TEST_FAILED cause = "cgget expected the following:\n\t" \ "{}: {}\nbut received:\n\t{}".format( - SETTING1, VALUE1, out.splitlines()[1]) + settings[0], VALUE1, out.splitlines()[1]) - if out.splitlines()[2] != "{}: {}".format(SETTING2, VALUE2): + if out.splitlines()[2] != "{}: {}".format(settings[1], VALUE2): result = consts.TEST_FAILED cause = "cgget expected the following:\n\t" \ "{}: {}\nbut received:\n\t{}".format( - SETTING2, VALUE2, out.splitlines()[2]) + settings[1], VALUE2, out.splitlines()[2]) return result, cause