]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
ftests/009: Refactor code to match outputs with same line
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Sat, 6 Jul 2024 10:35:02 +0000 (16:05 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 17 Jul 2024 21:26:47 +0000 (15:26 -0600)
Refactor the code to match controller(s) output, with expected
controller(s) output, where more than one items in the expected output
list matches number of lines. Without this patch, the output is matched
only against the first item matching the line count in the expected
output.

-----------------------------------------------------------------
Test Results:
        Run Date:                          Jun 22 10:18:38
        Passed:                                  1 test(s)
        Skipped:                                 0 test(s)
        Failed:                                  0 test(s)
-----------------------------------------------------------------
Timing Results:
        Test                                    Time (sec)
        --------------------------------------------------
        setup                                         0.00
        009-cgget-g_flag_controller_only.py           0.04
        teardown                                      0.00
        --------------------------------------------------
        Total Run Time                                0.04

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
tests/ftests/009-cgget-g_flag_controller_only.py

index 5301e77da01d968d59437042d523a23595605a2e..3ce06ff81816e86b2b6e0e358d9481a749b6d377 100755 (executable)
@@ -10,6 +10,7 @@
 from cgroup import Cgroup, CgroupVersion
 import consts
 import ftests
+import utils
 import sys
 import os
 
@@ -27,42 +28,30 @@ def setup(config):
 
 
 def test(config):
-    result = consts.TEST_PASSED
+    result = consts.TEST_FAILED
     cause = None
 
-    EXPECTED_OUT_V1 = [OUT_PREFIX + expected_out for expected_out in consts.EXPECTED_CPU_OUT_V1]
-    EXPECTED_OUT_V2 = [OUT_PREFIX + expected_out for expected_out in consts.EXPECTED_CPU_OUT_V2]
-
     out = Cgroup.get(config, controller=CONTROLLER, cgname=CGNAME)
     version = CgroupVersion.get_version(CONTROLLER)
 
     if version == CgroupVersion.CGROUP_V1:
-        for expected_out in EXPECTED_OUT_V1:
-            if len(out.splitlines()) == len(expected_out.splitlines()):
-                break
-    elif version == CgroupVersion.CGROUP_V2:
-        for expected_out in EXPECTED_OUT_V2:
+        EXPECTED_OUT = [OUT_PREFIX + expected_out for expected_out in consts.EXPECTED_CPU_OUT_V1]
+    else:
+        EXPECTED_OUT = [OUT_PREFIX + expected_out for expected_out in consts.EXPECTED_CPU_OUT_V2]
+
+    for expected_out in EXPECTED_OUT:
+        if len(out.splitlines()) == len(expected_out.splitlines()):
             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():
-            result = consts.TEST_FAILED
-            cause = (
-                        'Expected line:\n\t{}\nbut received line:\n\t{}'
-                        ''.format(expected_out.splitlines()[line_num].strip(),
-                                  line.strip())
-                    )
-            return result, cause
+                result_, tmp_cause = utils.is_output_same(config, out, expected_out)
+                if result_ is True:
+                    result = consts.TEST_PASSED
+                    cause = None
+                    break
+                else:
+                    if cause is None:
+                        cause = "Tried Matching:\n==============="
+
+                    cause = '\n'.join(filter(None, [cause, expected_out]))
 
     return result, cause