From 42b6d224289af6060c90ccefbb1110bc67fd1c6a Mon Sep 17 00:00:00 2001 From: Jiaxun Yang Date: Wed, 18 Dec 2024 18:47:23 +0000 Subject: [PATCH] test/test_integration: Derive from test_cpu Derive test_integration from test_cpu to prepare for other boot tests. Signed-off-by: Jiaxun Yang --- test/{test_cpu.py => test_integration.py} | 37 +++++++++++++---------- 1 file changed, 21 insertions(+), 16 deletions(-) rename test/{test_cpu.py => test_integration.py} (74%) diff --git a/test/test_cpu.py b/test/test_integration.py similarity index 74% rename from test/test_cpu.py rename to test/test_integration.py index 7a151d9bf..bddaa0ecf 100644 --- a/test/test_cpu.py +++ b/test/test_integration.py @@ -6,16 +6,21 @@ import unittest import pexpect -import sys import os +import sys +import tempfile -class TestCPU(unittest.TestCase): - def boot_test(self, cpu_type, jobs, cpu_variant="standard"): - cmd = f'litex_sim --cpu-type={cpu_type} --cpu-variant={cpu_variant} --opt-level=O0 --jobs {jobs}' - litex_prompt = [b'\033\[[0-9;]+mlitex\033\[[0-9;]+m>'] +class TestIntegration(unittest.TestCase): + def boot_test(self, cpu_type="vexriscv", cpu_variant="standard", args=""): + cmd = f'litex_sim --cpu-type={cpu_type} --cpu-variant={cpu_variant} {args} --opt-level=O0 --jobs {os.cpu_count()}' + litex_prompt = [r'\033\[[0-9;]+mlitex\033\[[0-9;]+m>'] is_success = True - with open("/tmp/test_boot_log", "wb") as result_file: - p = pexpect.spawn(cmd, timeout=None, logfile=result_file) + + with tempfile.TemporaryFile(mode='w', prefix="litex_test") as log_file: + log_file.writelines(f"Command: {cmd}") + log_file.flush() + + p = pexpect.spawn(cmd, timeout=None, encoding=sys.getdefaultencoding(), logfile=log_file) try: match_id = p.expect(litex_prompt, timeout=1200) except pexpect.EOF: @@ -25,13 +30,13 @@ class TestCPU(unittest.TestCase): print('\n*** Timeout ') is_success = False - if not is_success: - print(f'*** {cpu_type} Boot Failure') - with open("/tmp/test_boot_log", "r") as result_file: - print(result_file.read()) - else: - p.terminate(force=True) - print(f'*** {cpu_type} Boot Success') + if not is_success: + print(f'*** ({self.id()}) Boot Failure: {cmd}') + log_file.seek(0) + print(log_file.read()) + else: + p.terminate(force=True) + print(f'*** ({self.id()}) Boot Success: {cmd}') return is_success @@ -66,7 +71,7 @@ class TestCPU(unittest.TestCase): "zynq7000", # (arm / hardcore) -> Hardcore. "zynqmp", # (aarch64 / hardcore) -> Hardcore. ] - jobs = os.cpu_count() + for cpu in tested_cpus: with self.subTest(target=cpu): - self.assertTrue(self.boot_test(cpu, jobs)) + self.assertTrue(self.boot_test(cpu))