From: Kamalesh Babulal Date: Sun, 7 Jul 2024 05:28:49 +0000 (+0530) Subject: ftests/010: Refactor code to match outputs with same line X-Git-Tag: v3.2.0~91 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=88ffe562376f435160aab2684a602686d6014554;p=thirdparty%2Flibcgroup.git ftests/010: Refactor code to match outputs with same line 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 23 10:58:49 Passed: 1 test(s) Skipped: 0 test(s) Failed: 0 test(s) ----------------------------------------------------------------- Timing Results: Test Time (sec) -------------------------------------------------------- setup 0.00 010-cgget-g_flag_controller_and_cgroup.py 0.03 teardown 0.00 -------------------------------------------------------- Total Run Time 0.03 Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- diff --git a/tests/ftests/010-cgget-g_flag_controller_and_cgroup.py b/tests/ftests/010-cgget-g_flag_controller_and_cgroup.py index 169a72f8..9dcaae43 100755 --- a/tests/ftests/010-cgget-g_flag_controller_and_cgroup.py +++ b/tests/ftests/010-cgget-g_flag_controller_and_cgroup.py @@ -10,6 +10,7 @@ from cgroup import Cgroup, CgroupVersion import consts import ftests +import utils import sys import os @@ -35,41 +36,22 @@ def test(config): version = CgroupVersion.get_version(CONTROLLER) if version == CgroupVersion.CGROUP_V1: - for expected_out in consts.EXPECTED_CPU_OUT_V1: - if len(out.splitlines()) == len(expected_out.splitlines()): - break - elif version == CgroupVersion.CGROUP_V2: - for expected_out in consts.EXPECTED_CPU_OUT_V2: - if len(out.splitlines()) == len(expected_out.splitlines()): + EXPECTED_OUT = consts.EXPECTED_CPU_OUT_V1 + else: + EXPECTED_OUT = consts.EXPECTED_CPU_OUT_V2 + + for expected_out in EXPECTED_OUT: + if len(out.splitlines()) == len(expected_out.splitlines()): + 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===============" - 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(): - 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 + cause = '\n'.join(filter(None, [cause, expected_out])) return result, cause