From: Kamalesh Babulal Date: Tue, 19 Jul 2022 21:04:21 +0000 (-0600) Subject: test-010: add support for newer cpu.* output X-Git-Tag: v2.0.3~11^2^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=332c0a9769bb145d123fe524347a058604dec955;p=thirdparty%2Flibcgroup.git test-010: add support for newer cpu.* output With Ubuntu 5.15.0-1014 kernel, there are a few changes to the output of cgget -g cpu: provides for both cgroup V1 and V2: cgroup V1: ---------- - new stat files cpu.cfs_burst_us. cpu.idle cgroup V2: ---------- - new stat files cpu.idle, cpu.max.burst adopt these changes while looking for expected out based on the cgroup version. Also, convert the expected out templates into per cgroup version list[], making it easier to match using a for loop, instead of nested if else. Using a list also makes it easier to append any new changes to the output template. Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka (cherry picked from commit cf0bd90e3d2f0cd30fd13602f814cbf05fa0d557) --- diff --git a/ftests/010-cgget-g_flag_controller_and_cgroup.py b/ftests/010-cgget-g_flag_controller_and_cgroup.py index 246490ed..74a111ff 100755 --- a/ftests/010-cgget-g_flag_controller_and_cgroup.py +++ b/ftests/010-cgget-g_flag_controller_and_cgroup.py @@ -29,15 +29,40 @@ import sys CONTROLLER = 'cpu' CGNAME = '010cgget' -EXPECTED_OUT = '''cpu.cfs_period_us: 100000 -cpu.stat: nr_periods 0 - nr_throttled 0 - throttled_time 0 -cpu.shares: 1024 -cpu.cfs_quota_us: -1 -cpu.uclamp.min: 0.00 -cpu.uclamp.max: max -''' +EXPECTED_OUT = [ + '''cpu.cfs_period_us: 100000 + cpu.stat: nr_periods 0 + nr_throttled 0 + throttled_time 0 + cpu.shares: 1024 + cpu.cfs_quota_us: -1 + cpu.uclamp.min: 0.00 + cpu.uclamp.max: max''', + # cfs_bandwidth without cpu.stat nr_busts, burst_time + '''cpu.cfs_burst_us: 0 + cpu.cfs_period_us: 100000 + cpu.stat: nr_periods 0 + nr_throttled 0 + throttled_time 0 + cpu.shares: 1024 + cpu.idle: 0 + cpu.cfs_quota_us: -1 + cpu.uclamp.min: 0.00 + cpu.uclamp.max: max''', + # cfs_bandwidth with cpu.stat nr_busts, burst_time + '''cpu.cfs_burst_us: 0 + cpu.cfs_period_us: 100000 + cpu.stat: nr_periods 0 + nr_throttled 0 + throttled_time 0 + nr_bursts 0 + burst_time 0 + cpu.shares: 1024 + cpu.idle: 0 + cpu.cfs_quota_us: -1 + cpu.uclamp.min: 0.00 + cpu.uclamp.max: max''' +] def prereqs(config): result = consts.TEST_PASSED @@ -55,11 +80,33 @@ def test(config): out = Cgroup.get(config, controller="{}:{}".format(CONTROLLER, CGNAME), print_headers=False) + for expected_out in EXPECTED_OUT: + if len(out.splitlines()) == len(expected_out.splitlines()): + break + + if len(out.splitlines()) != len(expected_out.splitlines()): + result = consts.TEST_FAILED + cause = ( + 'Expected line count: {}, but received line count: {}' + ''.format(len(expected_out.splitlines()), + len(out.splitlines())) + ) + return result, cause + + if len(out.splitlines()) != len(expected_out.splitlines()): + result = consts.TEST_FAILED + cause = ( + 'Expected {} lines but received {} lines' + ''.format(len(expected_out.splitlines()), + len(out.splitlines())) + ) + return result, cause + for line_num, line in enumerate(out.splitlines()): - if line.strip() != EXPECTED_OUT.splitlines()[line_num].strip(): + if line.strip() != expected_out.splitlines()[line_num].strip(): result = consts.TEST_FAILED cause = "Expected line:\n\t{}\nbut received line:\n\t{}".format( - EXPECTED_OUT.splitlines()[line_num].strip(), line.strip()) + expected_out.splitlines()[line_num].strip(), line.strip()) return result, cause return result, cause