Skip to content

Commit

Permalink
integration-tests: Various script improvements
Browse files Browse the repository at this point in the history
Improvements include:
* Use descriptive names for symbols in lines with other test scripts
* Add docstrings
* Add type annotations
* Use Python assignment operators where appropriate
* Use f-strings to make print statement more readable

Signed-off-by: Hugues Kamba-Mpiana <[email protected]>
  • Loading branch information
hugueskamba committed Feb 12, 2024
1 parent 60be953 commit c1e43e5
Showing 1 changed file with 54 additions and 35 deletions.
89 changes: 54 additions & 35 deletions tools/tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Arm Limited. All rights reserved.
# Copyright (c) 2023-2024 Arm Limited. All rights reserved.
# SPDX-License-Identifier: MIT

import subprocess
Expand All @@ -8,16 +8,26 @@
import re

# If you have failing test cases to ignore,
# specify the test suites and test cases as shown below
# afterwards remove the empty ignore_tests dictionary.
# Cases = "TestSuite1, TestCase_1, TestSuite2, TestCase_2, TestSuiten, TestCase_n"
# Output = "Reason to ignore"
# ignore_tests = {Cases: Output}
ignore_tests = {}
# specify the test suites and test cases as shown below.
# test_cases_to_ignore = {
# "test_suite_1, test_case_1": "ignore_reason_1",
# "test_suite_2, test_case_2": "ignore_reason_2",
# "test_suite_n, test_case_n": "ignore_reason_n",
# }
test_cases_to_ignore = {}


@fixture(scope="function")
def aws_resources(build_artefacts_path, credentials_path, signed_update_bin_name):
def setup_resources(
build_artefacts_path: str, credentials_path: str, signed_update_bin_name: str
):
"""
Setup resources needed to run the test.
build_artefacts_path: Path to all the artefacts needed to create AWS resources.
credentials_path: Path to AWS credentials.
signed_update_bin_name: Name of the binary to be used for the OTA update.
"""
flags = Flags(build_artefacts_path, credentials_path, signed_update_bin_name)
flags = create_aws_resources(flags)
try:
Expand All @@ -28,10 +38,19 @@ def aws_resources(build_artefacts_path, credentials_path, signed_update_bin_name


def test_integration(
aws_resources,
setup_resources,
fvp_process: subprocess.Popen,
timeout_seconds: int,
):
"""
Compare the actual output on the FVP with the expectations in
pass and fail output files for the applications.
setup_resources: Input coming out as a result of executing of setup_resources
function defined above.
fvp_process (subprocess.Popen): FVP execution process
timeout_seconds (int): Timeout in seconds to wait before terminating the test.
"""
end_string = "RunQualificationTest returned"

start = timer()
Expand All @@ -42,10 +61,10 @@ def test_integration(
regex_fail = re.compile(r":FAIL:")
current_test = ""

tests = 0
failures = 0
ignored = 0
failed_tests = []
test_cases_ran_count = 0
test_cases_ignored_count = 0
test_cases_failed_count = 0
failed_test_cases = []

while (current_time - start) < timeout_seconds:
line = fvp_process.stdout.readline()
Expand All @@ -55,37 +74,37 @@ def test_integration(
line = line.rstrip()
print(line)
# look for test summary string
result = regex.search(line)
if result:
tests = tests + int(result.group(1))
failures = failures + int(result.group(2))
ignored = ignored + int(result.group(3))
test_summary = regex.search(line)
if test_summary:
test_cases_ran_count += int(test_summary.group(1))
test_cases_failed_count += int(test_summary.group(2))
test_cases_ignored_count += int(test_summary.group(3))
# look for test name and FAIL so we can list failed tests
result = regex_test_name.search(line)
if result:
current_test = result.group(1)
test_name = regex_test_name.search(line)
if test_name:
current_test = test_name.group(1)
# FAIL can appear on the line with test name or later
result = regex_fail.search(line)
if result:
failed_tests.append(current_test)
test_failed = regex_fail.search(line)
if test_failed:
failed_test_cases.append(current_test)
if end_string in line:
break
current_time = timer()

print("-------------------- SUMMARY --------------------")
print("Total Tests:", tests)
print("Total Failures:", failures)
print("Total Ignored:", ignored)
print(f"Total Tests: {test_cases_ran_count}")
print(f"Total Failures: {test_cases_failed_count}")
print(f"Total Ignored: {test_cases_ignored_count}")
print("---------------------------------------------------")
if len(failed_tests):
if len(failed_test_cases):
print("Failed tests:")
for fail in failed_tests:
# ignore tests that we know fail
if fail in ignore_tests.keys():
failures = failures - 1
print(" * Ignoring failure:", fail, "-", ignore_tests[fail])
for test_case in failed_test_cases:
if test_case in test_cases_to_ignore:
test_cases_failed_count -= 1
test_case_ignore_reason = test_cases_to_ignore[test_case]
print(f" * Ignoring failure: {test_case} - {test_case_ignore_reason}")
else:
print(" -", fail)
print(f" - {test_case}")
print("---------------------------------------------------")

assert failures == 0
assert test_cases_failed_count == 0

0 comments on commit c1e43e5

Please sign in to comment.