]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
test-009: add support for newer cpu.* output
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Tue, 19 Jul 2022 20:59:52 +0000 (14:59 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Tue, 19 Jul 2022 20:59:56 +0000 (14:59 -0600)
With Ubuntu 5.15.0-1014 kernel, there are a few changes to the output
of cgget -g cpu:<cgroup> 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 <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 96b533988a10ba877673adebe70fc5808844e862)

ftests/009-cgget-g_flag_controller_only.py

index 155369ccc5378316016eddee9053488a04acefc1..e57352d842e5b052f9d9b97620dd057fd7e70e9a 100755 (executable)
@@ -29,16 +29,43 @@ import sys
 CONTROLLER = 'cpu'
 CGNAME = '009cgget'
 
-EXPECTED_OUT = '''009cgget:
-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 = [
+    '''009cgget:
+    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
+    '''009cgget:
+    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
+    '''009cgget:
+    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 +82,24 @@ def test(config):
 
     out = Cgroup.get(config, controller=CONTROLLER, cgname=CGNAME)
 
+    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 {} 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