Add cgroup v2 support to the 013-cgget-multiple_g_flags.py
functional test.  It continues to support cgroup v1 as well.

Signed-off-by: Tom Hromatka <tom.hroma...@oracle.com>
---
 ftests/013-cgget-multiple_g_flags.py | 61 ++++++++++++++++++++++++----
 1 file changed, 52 insertions(+), 9 deletions(-)

diff --git a/ftests/013-cgget-multiple_g_flags.py 
b/ftests/013-cgget-multiple_g_flags.py
index 1624dd355229..dbd8cc6f788e 100755
--- a/ftests/013-cgget-multiple_g_flags.py
+++ b/ftests/013-cgget-multiple_g_flags.py
@@ -24,16 +24,17 @@ from cgroup import Cgroup, CgroupVersion
 import consts
 import ftests
 import os
+from run import RunError
 import sys
 
-CONTROLLER1 = 'freezer'
+CONTROLLER1 = 'pids'
 CONTROLLER2 = 'cpu'
 CGNAME = '013cgget'
 
-EXPECTED_OUT = '''013cgget:
-freezer.self_freezing: 0
-freezer.parent_freezing: 0
-freezer.state: THAWED
+EXPECTED_OUT_V1 = '''013cgget:
+pids.current: 0
+pids.events: max 0
+pids.max: max
 cpu.cfs_period_us: 100000
 cpu.stat: nr_periods 0
         nr_throttled 0
@@ -44,6 +45,24 @@ cpu.uclamp.min: 0.00
 cpu.uclamp.max: max
 '''
 
+EXPECTED_OUT_V2 = '''013cgget:
+pids.current: 0
+pids.events: max 0
+pids.max: max
+cpu.weight: 100
+cpu.stat: usage_usec 0
+        user_usec 0
+        system_usec 0
+        nr_periods 0
+        nr_throttled 0
+        throttled_usec 0
+cpu.weight.nice: 0
+cpu.pressure: some avg10=0.00 avg60=0.00 avg300=0.00 total=0
+cpu.max: max 100000
+cpu.uclamp.min: 0.00
+cpu.uclamp.max: max
+'''
+
 def prereqs(config):
     result = consts.TEST_PASSED
     cause = None
@@ -61,18 +80,42 @@ def test(config):
     out = Cgroup.get(config, controller=[CONTROLLER1, CONTROLLER2],
                      cgname=CGNAME)
 
+    version = CgroupVersion.get_version(CONTROLLER1)
+
+    if version == CgroupVersion.CGROUP_V1:
+        expected_out = EXPECTED_OUT_V1
+    elif version == CgroupVersion.CGROUP_V2:
+        expected_out = EXPECTED_OUT_V2
+
+    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
 
+    print(result)
+    print(cause)
     return result, cause
 
 def teardown(config):
-    Cgroup.delete(config, CONTROLLER1, CGNAME)
-    Cgroup.delete(config, CONTROLLER2, CGNAME)
+    ver1 = CgroupVersion.get_version(CONTROLLER1)
+    ver2 = CgroupVersion.get_version(CONTROLLER2)
+
+    if ver1 == CgroupVersion.CGROUP_V2 and \
+       ver2 == CgroupVersion.CGROUP_V2:
+        # If both controllers are cgroup v2, then we only need to delete
+        # one cgroup.  The path will be the same for both
+        Cgroup.delete(config, [CONTROLLER1, CONTROLLER2], CGNAME)
+    else:
+        Cgroup.delete(config, CONTROLLER1, CGNAME)
+        Cgroup.delete(config, CONTROLLER2, CGNAME)
 
 def main(config):
     [result, cause] = prereqs(config)
-- 
2.31.1



_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to