test/test_integration: Derive from test_cpu

Derive test_integration from test_cpu to prepare for other boot tests.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
This commit is contained in:
Jiaxun Yang 2024-12-18 18:47:23 +00:00
parent a6bdbedc07
commit 42b6d22428
1 changed files with 21 additions and 16 deletions

View File

@ -6,16 +6,21 @@
import unittest import unittest
import pexpect import pexpect
import sys
import os import os
import sys
import tempfile
class TestCPU(unittest.TestCase): class TestIntegration(unittest.TestCase):
def boot_test(self, cpu_type, jobs, cpu_variant="standard"): def boot_test(self, cpu_type="vexriscv", cpu_variant="standard", args=""):
cmd = f'litex_sim --cpu-type={cpu_type} --cpu-variant={cpu_variant} --opt-level=O0 --jobs {jobs}' cmd = f'litex_sim --cpu-type={cpu_type} --cpu-variant={cpu_variant} {args} --opt-level=O0 --jobs {os.cpu_count()}'
litex_prompt = [b'\033\[[0-9;]+mlitex\033\[[0-9;]+m>'] litex_prompt = [r'\033\[[0-9;]+mlitex\033\[[0-9;]+m>']
is_success = True 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: try:
match_id = p.expect(litex_prompt, timeout=1200) match_id = p.expect(litex_prompt, timeout=1200)
except pexpect.EOF: except pexpect.EOF:
@ -26,12 +31,12 @@ class TestCPU(unittest.TestCase):
is_success = False is_success = False
if not is_success: if not is_success:
print(f'*** {cpu_type} Boot Failure') print(f'*** ({self.id()}) Boot Failure: {cmd}')
with open("/tmp/test_boot_log", "r") as result_file: log_file.seek(0)
print(result_file.read()) print(log_file.read())
else: else:
p.terminate(force=True) p.terminate(force=True)
print(f'*** {cpu_type} Boot Success') print(f'*** ({self.id()}) Boot Success: {cmd}')
return is_success return is_success
@ -66,7 +71,7 @@ class TestCPU(unittest.TestCase):
"zynq7000", # (arm / hardcore) -> Hardcore. "zynq7000", # (arm / hardcore) -> Hardcore.
"zynqmp", # (aarch64 / hardcore) -> Hardcore. "zynqmp", # (aarch64 / hardcore) -> Hardcore.
] ]
jobs = os.cpu_count()
for cpu in tested_cpus: for cpu in tested_cpus:
with self.subTest(target=cpu): with self.subTest(target=cpu):
self.assertTrue(self.boot_test(cpu, jobs)) self.assertTrue(self.boot_test(cpu))