Skip to content

Commit

Permalink
ftests/013: Refactor code to match outputs with same line
Browse files Browse the repository at this point in the history
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 24 11:17:11
        Passed:                                  1 test(s)
        Skipped:                                 0 test(s)
        Failed:                                  0 test(s)
-----------------------------------------------------------------
Timing Results:
        Test                              Time (sec)
        --------------------------------------------
        setup                                   0.00
        013-cgget-multiple_g_flags.py           0.05
        teardown                                0.00
        --------------------------------------------
        Total Run Time                          0.05

Signed-off-by: Kamalesh Babulal <[email protected]>
  • Loading branch information
kamalesh-babulal committed Jun 24, 2024
1 parent 75d45a4 commit 6059478
Showing 1 changed file with 25 additions and 38 deletions.
63 changes: 25 additions & 38 deletions tests/ftests/013-cgget-multiple_g_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from cgroup import Cgroup, CgroupVersion
import consts
import ftests
import utils
import sys
import os

Expand All @@ -32,51 +33,37 @@ def test(config):
result = consts.TEST_PASSED
cause = None

# Append pid controller [0] and cpu controller [N - 2]
EXPECTED_OUT_V1 = [OUT_PREFIX + consts.EXPECTED_PIDS_OUT[0] + expected_out
for expected_out in consts.EXPECTED_CPU_OUT_V1[:-2]]
# Append pid controller [1] and cpu controller [N, N - 1]
EXPECTED_OUT_V1.extend(OUT_PREFIX + consts.EXPECTED_PIDS_OUT[1] + expected_out
for expected_out in consts.EXPECTED_CPU_OUT_V1[-2:])

# Append pid controller [0] and cpu controller [N - 2]
EXPECTED_OUT_V2 = [OUT_PREFIX + consts.EXPECTED_PIDS_OUT[0] + expected_out
for expected_out in consts.EXPECTED_CPU_OUT_V2[:-2]]
# Append pid controller [1] and cpu controller [N, N - 1]
EXPECTED_OUT_V2.extend(OUT_PREFIX + consts.EXPECTED_PIDS_OUT[1] + expected_out
for expected_out in consts.EXPECTED_CPU_OUT_V2[-2:])

out = Cgroup.get(config, controller=[CONTROLLER1, CONTROLLER2],
cgname=CGNAME)
version = CgroupVersion.get_version(CONTROLLER1)

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:
if len(out.splitlines()) == len(expected_out.splitlines()):
# Append pid controller [0] and cpu controller [N - 2]
EXPECTED_OUT = [OUT_PREFIX + consts.EXPECTED_PIDS_OUT[0] + expected_out
for expected_out in consts.EXPECTED_CPU_OUT_V1[:-2]]
# Append pid controller [1] and cpu controller [N, N - 1]
EXPECTED_OUT.extend(OUT_PREFIX + consts.EXPECTED_PIDS_OUT[1] + expected_out
for expected_out in consts.EXPECTED_CPU_OUT_V1[-2:])
else:
# Append pid controller [0] and cpu controller [N - 2]
EXPECTED_OUT = [OUT_PREFIX + consts.EXPECTED_PIDS_OUT[0] + expected_out
for expected_out in consts.EXPECTED_CPU_OUT_V2[:-2]]
# Append pid controller [1] and cpu controller [N, N - 1]
EXPECTED_OUT.extend(OUT_PREFIX + consts.EXPECTED_PIDS_OUT[1] + expected_out
for expected_out in consts.EXPECTED_CPU_OUT_V2[-2:])

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 {} 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

Expand Down

0 comments on commit 6059478

Please sign in to comment.