6 from argparse
import ArgumentParser
9 parser
= ArgumentParser()
10 parser
.add_argument("--sdram-module", type=str)
11 args
= parser
.parse_args()
17 'command': f
'python3 -m litex.tools.litex_sim --with-sdram --sdram-module {args.sdram_module}',
20 { 'timeout': 240, 'good': [b
'\n\\s*BIOS built on[^\n]+\n'] },
21 { 'timeout': 30, 'good': [b
'Memtest OK'],
22 'bad': [b
'(Memory initialization failed|Booting from)'] },
28 def run_test(id, command
, cwd
, checkpoints
):
29 print(f
'*** Test ID: {id}')
30 print(f
'*** CWD: {cwd}')
31 print(f
'*** Command: {command}')
33 p
= pexpect
.spawn(command
, timeout
=None, logfile
=sys
.stdout
.buffer)
36 for cp
in checkpoints
:
37 good
= cp
.get('good', [])
38 bad
= cp
.get('bad', [])
40 timeout
= cp
.get('timeout', None)
42 timediff
= time
.time()
44 match_id
= p
.expect(patterns
, timeout
=timeout
)
46 print(f
'\n*** {id}: premature termination')
48 except pexpect
.TIMEOUT
:
49 timediff
= time
.time() - timediff
50 print(f
'\n*** {id}: timeout (checkpoint {checkpoint_id}: +{int(timediff)}s)')
52 timediff
= time
.time() - timediff
54 if match_id
>= len(good
):
57 sys
.stdout
.buffer.write(b
'<<checkpoint %d: +%ds>>' % (checkpoint_id
, int(timediff
)))
60 is_success
= checkpoint_id
== len(checkpoints
)
62 # Let it print rest of line
63 match_id
= p
.expect_exact([b
'\n', pexpect
.TIMEOUT
, pexpect
.EOF
], timeout
=1)
64 p
.terminate(force
=True)
66 line_break
= '\n' if match_id
!= 0 else ''
67 print(f
'{line_break}*** {id}: {"success" if is_success else "failure"}')
73 success
= run_test(**test
)