Skip to content

Commit 44a3d05

Browse files
committed
Convert tests to Python
1 parent 7747bcd commit 44a3d05

38 files changed

+559
-584
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ DRIVER_FLAGS ?= -j 0 --quiet --rerun
3434
SCENARIOS ?= --vlt --vltmt --dist
3535

3636
test:
37-
t/bootstrap.pl $(DRIVER_FLAGS) $(SCENARIOS) t/t_*.pl
37+
t/vltest_bootstrap.py $(DRIVER_FLAGS) $(SCENARIOS) t/t_*.py
3838

3939
######################################################################
4040

docs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Run an individual test:
2121
```
2222
export VERILATOR_ROOT=location # if your shell is bash
2323
setenv VERILATOR_ROOT location # if your shell is csh
24-
t/t_a_hello.pl
24+
t/t_a_hello.py
2525
```
2626

2727
Automatically run these tests as part of normal Verilator "make test"
@@ -39,7 +39,7 @@ make clean
3939

4040
# Adding additional tests
4141

42-
To add additional tests, add a `t/t_{name}.pl` file. See the Verilator
42+
To add additional tests, add a `t/t_{name}.py` file. See the Verilator
4343
internals documentation for instructions on the test file format.
4444

4545
To be accepted in this package, an external submodule tested here must:

t/bootstrap.pl

Lines changed: 0 additions & 28 deletions
This file was deleted.

t/t_a_hello.pl

Lines changed: 0 additions & 20 deletions
This file was deleted.

t/t_a_hello.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python3
2+
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
3+
#
4+
# Copyright 2024 by Wilson Snyder. This program is free software; you
5+
# can redistribute it and/or modify it under the terms of either the GNU
6+
# Lesser General Public License Version 3 or the Perl Artistic License
7+
# Version 2.0.
8+
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
9+
10+
import vltest_bootstrap
11+
12+
test.scenarios('vlt')
13+
14+
test.compile()
15+
16+
test.execute(check_finished=True)
17+
18+
test.passes()

t/t_bench_synmul.pl

Lines changed: 0 additions & 30 deletions
This file was deleted.

t/t_bench_synmul.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python3
2+
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
3+
#
4+
# Copyright 2024 by Wilson Snyder. This program is free software; you
5+
# can redistribute it and/or modify it under the terms of either the GNU
6+
# Lesser General Public License Version 3 or the Perl Artistic License
7+
# Version 2.0.
8+
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
9+
10+
import vltest_bootstrap
11+
12+
test.scenarios('simulator')
13+
test.top_filename = "t/t_math_synmul.v"
14+
15+
cycles = 100
16+
test.sim_time = cycles * 100
17+
18+
test.compile(v_flags2=[
19+
"+define+SIM_CYCLES=" + str(cycles), "--stats", "-Wno-UNOPTTHREADS"
20+
], )
21+
22+
test.execute(check_finished=True)
23+
24+
test.passes()

t/t_bench_wallace.pl

Lines changed: 0 additions & 27 deletions
This file was deleted.

t/t_bench_wallace.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python3
2+
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
3+
#
4+
# Copyright 2024 by Wilson Snyder. This program is free software; you
5+
# can redistribute it and/or modify it under the terms of either the GNU
6+
# Lesser General Public License Version 3 or the Perl Artistic License
7+
# Version 2.0.
8+
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
9+
10+
import vltest_bootstrap
11+
12+
test.scenarios("simulator")
13+
test.top_filename = "t/t_math_wallace.v"
14+
15+
cycles = 100
16+
test.sim_time = cycles * 100
17+
18+
test.compile(v_flags2=["+define+SIM_CYCLES=" + str(cycles)])
19+
20+
test.execute(check_finished=True)
21+
22+
test.passes()

t/t_cores_eh2_cmark.pl

Lines changed: 0 additions & 42 deletions
This file was deleted.

t/t_cores_el2_cmark.pl

Lines changed: 0 additions & 41 deletions
This file was deleted.

t/t_cores_swerv_cmark.pl

Lines changed: 0 additions & 46 deletions
This file was deleted.

t/t_cores_swerv_cmark.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python3
2+
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
3+
#
4+
# Copyright 2024 by Wilson Snyder. This program is free software; you
5+
# can redistribute it and/or modify it under the terms of either the GNU
6+
# Lesser General Public License Version 3 or the Perl Artistic License
7+
# Version 2.0.
8+
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
9+
10+
import vltest_bootstrap
11+
12+
test.scenarios('vlt')
13+
14+
test.setenv('RV_ROOT',
15+
os.path.abspath(test.t_dir + "/../submodules/Cores-SweRV"))
16+
test.setenv('VERILATOR', os.environ["VERILATOR_ROOT"] + "/bin/verilator")
17+
18+
# Find compiler flag needed
19+
fc = test.file_contents(os.environ["VERILATOR_ROOT"] + "/include/verilated.mk")
20+
m = re.search(r'CFG_CXXFLAGS_STD_NEWEST = (\S+)', fc)
21+
if not m:
22+
test.error("Couldn't determine CFG_CXXFLAGS_STD_NEWEST")
23+
CFG_CXXFLAGS_STD_NEWEST = m.group(1)
24+
25+
# This will run the canned CoreMark (even if you have a riscv64-unknown-elf
26+
# toolchain on your path), from ICCM but otherwise using the default core
27+
# configuration. Running from ICCM is faster and hopefully more exciting.
28+
# Note the build happens in test.obj_dir as the SweRV build system can
29+
# find everything via RV_ROOT. This leaves the submodule clean.
30+
test.run(
31+
cmd=[
32+
"make -j4 -C " + test.obj_dir + " -f " + os.environ["RV_ROOT"] +
33+
"/tools/Makefile",
34+
("VERILATOR='" + os.environ["VERILATOR"] +
35+
" --debug-check -Wno-IMPLICITSTATIC --stats " +
36+
' '.join(test.driver_verilator_flags) + "'"),
37+
# Because Cores-SweRV-EH2/tools/Makefile has -std=c++11 which is too old
38+
# Unfortunately it's too late in the Makefile to pass in VERILATOR above
39+
"VERILATOR_DEBUG='-CFLAGS " + CFG_CXXFLAGS_STD_NEWEST + "'", #
40+
"CONF_PARAMS=-iccm_enable=1", #
41+
"GCC_PREFIX=none TEST=cmark_iccm", #
42+
"VERILATOR_MAKE_FLAGS=VM_PARALLEL_BUILDS=1 verilator"
43+
], #
44+
logfile=test.obj_dir + "/sim.log")
45+
46+
test.file_grep(test.obj_dir + "/sim.log", r'\nTEST_PASSED\n')
47+
48+
test.passes()

0 commit comments

Comments
 (0)