From 18eeb2c56b849ad7bffa04c2e212619237449216 Mon Sep 17 00:00:00 2001 From: Rutherther Date: Sun, 12 Nov 2023 00:05:06 +0100 Subject: [PATCH] tests: compile only once, copy proram, memory files to correct locations --- tests/official/Makefile | 2 +- tests/run.py | 38 +++++++++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/tests/official/Makefile b/tests/official/Makefile index 5f688a3b49cad9edc208e4d5f57900315f340811..ffeac6f4637c5ae3938ad4a5815f66e583b9cb17 100755 --- a/tests/official/Makefile +++ b/tests/official/Makefile @@ -2,7 +2,7 @@ XLEN = 32 src_dir = . isa_dir = ./riscv-tests/isa -CFLAGS=-march=rv32i -mabi=ilp32 -c +CFLAGS=-march=rv32i_zifencei -mabi=ilp32 -c CC=riscv32-none-elf-gcc LD=riscv32-none-elf-ld diff --git a/tests/run.py b/tests/run.py index 158bc3e4777f8be19f7965cb6c03d1ae1abab324..1d25ea3957e8b81eecd039b44a6f5426760f91f5 100755 --- a/tests/run.py +++ b/tests/run.py @@ -5,6 +5,7 @@ import argparse import sys import subprocess import re +import shutil from pathlib import Path from test_types import bcolors, TestGroup, Test, Validation @@ -31,14 +32,18 @@ def validate_test(test: Test) -> Validation: matches = (actual_arr == expected_arr) ) -def compile_test(project_dir: Path, comp_list: Path, out_dir: Path, test: Test) -> bool: +def compile(project_dir: Path, comp_list: Path, out_dir: Path) -> bool: + program_path = out_dir / "program.dat" + memory_write_file = out_dir / "memory_out.dat" + memory_load_file = out_dir / "memory_in.dat" + generics = { - 'CPU_PROGRAM_PATH': f"\\\"{test.group.dat_test_file}\\\"", - 'CPU_PROGRAM_NAME': f"\\\"{test.group.dat_test_file.stem}\\\"", + 'CPU_PROGRAM_PATH': f"\\\"{program_path}\\\"", + 'CPU_PROGRAM_NAME': f"\\\"testcase\\\"", 'MEMORY_LOAD_FILE': 1, - 'MEMORY_LOAD_FILE_PATH': f"\\\"{test.input_file}\\\"", + 'MEMORY_LOAD_FILE_PATH': f"\\\"{memory_load_file}\\\"", 'MEMORY_WRITE_FILE': 1, - 'MEMORY_WRITE_FILE_PATH': f"\\\"{test.output_file}\\\"", + 'MEMORY_WRITE_FILE_PATH': f"\\\"{memory_write_file}\\\"", } params = [] @@ -49,7 +54,7 @@ def compile_test(project_dir: Path, comp_list: Path, out_dir: Path, test: Test) params.append("--Mdir") params.append(f"{out_dir}") params.append("-o") - params.append(f"test_{test.group.name}_{test.name}") + params.append(f"simulate_cpu_program") params.append("--top") params.append("tb_cpu_program") @@ -65,12 +70,23 @@ def compile_test(project_dir: Path, comp_list: Path, out_dir: Path, test: Test) ).returncode == 0 def run_test(out_dir: Path, test: Test) -> bool: - return subprocess.run( - [out_dir / f"test_{test.group.name}_{test.name}"], + program_path = out_dir / "program.dat" + memory_write_file = out_dir / "memory_out.dat" + memory_load_file = out_dir / "memory_in.dat" + + shutil.copy(test.input_file, memory_load_file) + shutil.copy(test.group.dat_test_file, program_path) + + subprocess.run( + [out_dir / f"simulate_cpu_program"], stdout = subprocess.DEVNULL, shell = True, check = True, - ).returncode == 0 + ) + + shutil.copy(memory_write_file, test.output_file) + + return True # Program parser = argparse.ArgumentParser("Test simple RISC-V processor written in Verilog.") @@ -105,6 +121,8 @@ groups_dir = here / "custom" # TODO support multiple tests group_name, test_name = args.filter[0].split('.') if args.filter is not None else (None, None) +compile(project_dir, here / "comp_list.lst", out_dir) + if args.type == "custom": test_groups: list[TestGroup] = custom_tests.find_tests( groups_dir, programs_dir, out_dir, group_name, test_name @@ -119,7 +137,6 @@ if args.type == "custom": for group in test_groups: custom_tests.compile_program(project_dir, group) for test in group.tests: - compile_test(project_dir, here / "comp_list.lst", out_dir, test) run_test(out_dir, test) validation = validate_test(test) @@ -144,7 +161,6 @@ else: # official for group in test_groups: for test in group.tests: official_tests.compile_program(project_dir, test) - compile_test(project_dir, here / "comp_list.lst", out_dir, test) run_test(out_dir, test) validation = validate_test(test)