From 16187ed374dc0658f285f65eda39bbf764b37140 Mon Sep 17 00:00:00 2001 From: Viktor-Lake Date: Wed, 27 Nov 2024 17:31:16 -0300 Subject: [PATCH] start running tests and wrinting xml files --- test_runner/file.py | 4 --- test_runner/verificator.py | 56 +++++++++++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/test_runner/file.py b/test_runner/file.py index 8c07a06..e9560c7 100755 --- a/test_runner/file.py +++ b/test_runner/file.py @@ -16,7 +16,6 @@ def read_files_in_dir(path): try: if path.endswith("/memory"): path = path[:-7] # Remove the '/memory' suffix - print("path: ", path) files = [] file_test = [] @@ -29,9 +28,6 @@ def read_files_in_dir(path): if entry.is_file() and entry.name.endswith(".hex"): file_answer.append(read_file(entry.path)) - print("Files in reference directory: ", [entry.path for entry in os.scandir(path) if entry.is_dir()]) - print("teste: ", file_test) - print("resposta: ", file_answer) files.append(file_test) files.append(file_answer) files.append(path) diff --git a/test_runner/verificator.py b/test_runner/verificator.py index f995948..94b9ffd 100755 --- a/test_runner/verificator.py +++ b/test_runner/verificator.py @@ -12,6 +12,7 @@ import sys import file as f import argparse +import xmlrunner sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))) @@ -19,22 +20,58 @@ from processor_ci_communication.core.serial import ProcessorCIInterface +MAX_SIZE = 16 + class Verificator: def __init__(self, path, port, baudrate, timeout): self.path = path self.interface = ProcessorCIInterface(port, baudrate, timeout) + self.id = self.interface.get_module_id() + self.interface.set_timeout(timeout) + self.interface.set_execution_end_address(60) + + + def clean_up(self, size, max_size): + size = size * 4 + max_size = max_size * 4 + for i in range(size, max_size - 4, 4): + self.interface.write_memory(i, 0) def run_tests(self): tests = [] paths = f.list_find_paths(self.path) - #print(paths) + for path in paths: tests.append(f.read_files_in_dir(path)) - #print(tests) - - + print("Tests: ", tests) + + for path_tests in tests: + test_path = path_tests[2] + test_case_name = test_path.split("/")[-1] + print("Test_case_name: ", test_case_name) #test_case_name = nome do diretório + + REPORT_FILE = f'{test_path}/results.xml' # Tem que ficar na raiz + + test_id = 0 + for test in path_tests[0]: #path_tests[0] = tests | path_tests[1] = answers | path_tests[2] = path + test_size = test[1] + self.clean_up(test_size, MAX_SIZE) + test_expected = path_tests[1][test_id][0] + print("Test_expected: ", test_expected) + print("Test_size: ", test_size) + self.interface.write_from_accumulator(test_size, test[0]) + self.interface.execute_until_stop() + return_value = self.interface.read_memory(60) + print("Return_value: ", return_value) + result = "PASS" if return_value == test_expected else "FAIL" + print(f"Test {test_case_name}_{test_id}: {result}") + + with open(REPORT_FILE, 'a') as report: + report.write(f"\n") + test_id += 1 + return 0 #default to test: #python3 verificator.py -p /dev/ttyACM0 -b 115200 -t 2 @@ -42,11 +79,16 @@ def main(): parser = argparse.ArgumentParser() parser.add_argument("--port", "-p", type=str, help="Porta de comunicação", required=True) parser.add_argument("--baudrate", "-b", type=int, help="Baudrate de comunicação", required=True) - parser.add_argument("--timeout", "-t", type=int, help="Timeout de comunicação", required=True) - args = parser.parse_args() + parser.add_argument("--timeout", "-t", type=int, help="Tempo limite de execução", required=True) + args = parser.parse_args() + verifier = Verificator("/home/victor/processor_ci/processor-ci-tests/test_runner/testing_testes", args.port, args.baudrate, args.timeout) - verifier.run_tests() + + with open(f"{verifier.path}/results.xml", 'w') as report: + report.write("\n") + verifier.run_tests() + report.write("\n") return 0