Skip to content

Commit

Permalink
start running tests and wrinting xml files
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktor-Lake committed Nov 27, 2024
1 parent 46866df commit 16187ed
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 11 deletions.
4 changes: 0 additions & 4 deletions test_runner/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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)
Expand Down
56 changes: 49 additions & 7 deletions test_runner/verificator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,83 @@
import sys
import file as f
import argparse
import xmlrunner


sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))


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"<testcase name='{test_case_name}_{test_id}' result='{result}'/>\n")
test_id += 1
return 0

#default to test:
#python3 verificator.py -p /dev/ttyACM0 -b 115200 -t 2
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("<testsuite>\n")
verifier.run_tests()
report.write("</testsuite>\n")
return 0


Expand Down

0 comments on commit 16187ed

Please sign in to comment.