From 55720e9b40347c74974ca1b9448414abdd1c575d Mon Sep 17 00:00:00 2001 From: Kamalesh Babulal Date: Fri, 5 Jul 2024 15:28:01 +0530 Subject: [PATCH] ftests/utils: Add helper to check if output matches Add a helper to check if the output from the controller(s), matches the expected controller(s) output. It returns True/False and None in case of matching output, a line that doesn't match in differing output. Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- tests/ftests/utils.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/ftests/utils.py b/tests/ftests/utils.py index 67fdd80e..6dedfd90 100644 --- a/tests/ftests/utils.py +++ b/tests/ftests/utils.py @@ -87,4 +87,21 @@ def get_kernel_version(config): kernel_version = kernel_version_str.split('.')[0:3] return kernel_version + +# match if both outputs are same +def is_output_same(config, out, expected_out): + result = True + cause = None + + for line_num, line in enumerate(out.splitlines()): + if line.strip() != expected_out.splitlines()[line_num].strip(): + cause = ( + 'Expected line:\n\t{}\nbut received line:\n\t{}' + ''.format(expected_out.splitlines()[line_num].strip(), line.strip()) + ) + result = False + + return result, cause + + # vim: set et ts=4 sw=4: -- 2.47.3