Skip to content

Commit 482195f

Browse files
committed
Added support for test prioritization.
1 parent acf7e7f commit 482195f

30 files changed

+1329
-220
lines changed

docs/cli.rst

Lines changed: 67 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -37,57 +37,85 @@ The :vunit_example:`VHDL User Guide Example <vhdl/user_guide/>` can be run to pr
3737
.. code-block:: console
3838
:caption: Run all tests
3939
40-
> python run.py -v lib.tb_example*
41-
Running test: lib.tb_example.all
42-
Running test: lib.tb_example_many.test_pass
43-
Running test: lib.tb_example_many.test_fail
44-
Running 3 tests
40+
> python run.py
41+
Re-compile not needed
4542
46-
running lib.tb_example.all
47-
Hello World!
48-
pass( P=1 S=0 F=0 T=3) lib.tb_example.all (0.1 seconds)
43+
(09:40:59) Starting lib.tb_example.all
44+
Output file: C:\vunit\examples\vhdl\user_guide\vunit_out\test_output\lib.tb_example.all_7b5933c73ddb812488c059080644e9fd58c418d9\output.txt
45+
pass (P=1 S=0 F=0 T=3) lib.tb_example.all (0.5 s)
4946
50-
running lib.tb_example.test_pass
51-
This will pass
52-
pass (P=2 S=0 F=0 T=3) lib.tb_example_many.test_pass (0.1 seconds)
47+
(09:40:59) Starting lib.tb_example_many.test_pass
48+
Output file: C:\vunit\examples\vhdl\user_guide\vunit_out\test_output\lib.tb_example_many.test_pass_aff64431373db20d8bbba18c28096f449861ccbe\output.txt
49+
pass (P=2 S=0 F=0 T=3) lib.tb_example_many.test_pass (0.5 s)
5350
54-
running lib.tb_example.test_fail
55-
Error: It fails
56-
fail (P=2 S=0 F=1 T=3) lib.tb_example_many.test_fail (0.1 seconds)
51+
(09:41:00) Starting lib.tb_example_many.test_fail
52+
Output file: C:\vunit\examples\vhdl\user_guide\vunit_out\test_output\lib.tb_example_many.test_fail_d8956871e3b3d178e412e37587673fe9df648faf\output.txt
53+
Seed for lib.tb_example_many.test_fail: 7efb6d37186ac077
54+
C:\vunit\examples\vhdl\user_guide\tb_example_many.vhd:26:9:@0ms:(assertion error): It fails
55+
ghdl:error: assertion failed
56+
ghdl:error: simulation failed
57+
fail (P=2 S=0 F=1 T=3) lib.tb_example_many.test_fail (0.5 s)
5758
5859
==== Summary =========================================
59-
pass lib.tb_example.all (0.1 seconds)
60-
pass lib.tb_example_many.test_pass (0.1 seconds)
61-
fail lib.tb_example_many.test_fail (0.1 seconds)
62-
======================================================
60+
pass lib.tb_example.all (0.5 s)
61+
pass lib.tb_example_many.test_pass (0.5 s)
62+
fail lib.tb_example_many.test_fail (0.5 s)
63+
======================================================
6364
pass 2 of 3
6465
fail 1 of 3
6566
======================================================
66-
Total time was 0.3 seconds
67-
Elapsed time was 0.3 seconds
67+
Total time was 1.5 s
68+
Elapsed time was 1.5 s
6869
======================================================
6970
Some failed!
7071
72+
By default, test output is shown only for failing tests. To display output for all tests, use the ``-v`` option. The example below demonstrates this,
73+
while also selecting a subset of tests using a test pattern.
74+
7175
.. code-block:: console
72-
:caption: Run a specific test
73-
74-
> python run.py -v lib.tb_example.all
75-
Running test: lib.tb_example.all
76-
Running 1 tests
77-
78-
Starting lib.tb_example.all
79-
Hello world!
80-
pass (P=1 S=0 F=0 T=1) lib.tb_example.all (0.1 seconds)
81-
82-
==== Summary ==========================
83-
pass lib.tb_example.all (0.9 seconds)
84-
=======================================
85-
pass 1 of 1
86-
=======================================
87-
Total time was 0.9 seconds
88-
Elapsed time was 1.2 seconds
89-
=======================================
90-
All passed!
76+
:caption: Run specific test(s) matching a pattern
77+
78+
79+
> python run.py -v lib.tb_example_many*
80+
Re-compile not needed
81+
82+
Running test: lib.tb_example_many.test_pass
83+
Running test: lib.tb_example_many.test_fail
84+
Running 2 tests
85+
86+
(09:57:18) Starting lib.tb_example_many.test_fail
87+
Output file: C:\vunit\examples\vhdl\user_guide\vunit_out\test_output\lib.tb_example_many.test_fail_d8956871e3b3d178e412e37587673fe9df648faf\output.txt
88+
Seed for lib.tb_example_many.test_fail: 2c14af95ae82a231
89+
C:\vunit\examples\vhdl\user_guide\tb_example_many.vhd:26:9:@0ms:(assertion error): It fails
90+
ghdl:error: assertion failed
91+
ghdl:error: simulation failed
92+
fail (P=0 S=0 F=1 T=2) lib.tb_example_many.test_fail (3.2 s)
93+
94+
(09:57:22) Starting lib.tb_example_many.test_pass
95+
Output file: C:\vunit\examples\vhdl\user_guide\vunit_out\test_output\lib.tb_example_many.test_pass_aff64431373db20d8bbba18c28096f449861ccbe\output.txt
96+
Seed for lib.tb_example_many.test_pass: 30e3764e6f87ca85
97+
C:\vunit\examples\vhdl\user_guide\tb_example_many.vhd:23:9:@0ms:(report note): This will pass
98+
simulation stopped @0ms with status 0
99+
pass (P=1 S=0 F=1 T=2) lib.tb_example_many.test_pass (0.5 s)
100+
101+
==== Summary =========================================
102+
pass lib.tb_example_many.test_pass (0.5 s)
103+
fail lib.tb_example_many.test_fail (3.2 s)
104+
======================================================
105+
pass 1 of 2
106+
fail 1 of 2
107+
======================================================
108+
Total time was 3.6 s
109+
Elapsed time was 3.7 s
110+
======================================================
111+
Some failed!
112+
113+
Note that the order of test execution has changed - the failing test is now run first. VUnit reorders tests based on
114+
previous results and recent code changes to achieve two main goals:
115+
116+
1. Prioritize likely failures - Tests more likely to fail are executed earlier to provide faster feedback. In this case, ``lib.tb_example_many.test_fail``
117+
has a history of failing, and no relevant code changes have been made, so it is assumed to fail again and is run first.
118+
2. Load balancing - When tests are executed in parallel using the ``-p`` option, VUnit distributes them across threads to minimize to total execution time.
91119

92120
Opening a Test Case in Simulator GUI
93121
====================================

docs/news.d/1114.feature.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Added support for test prioritization with two goals in mind:
2+
3+
1. Prioritize likely failures - Tests more likely to fail are executed earlier to provide faster feedback.
4+
2. Load balancing - When tests are executed in parallel using the -p option, VUnit will try to keep the threads balanced to minimize total execution time.
5+
6+
Added the ``--changed`` option that limits tests to those that depend on changes made after the last test run.

examples/vhdl/vhdl_configuration/test_reset.vhd

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,3 @@ begin
2727

2828
test_runner_watchdog(runner, 10 * clk_period);
2929
end;
30-
31-
configuration test_reset_behavioral of tb_selecting_test_runner_with_vhdl_configuration is
32-
for tb
33-
for test_runner_inst : test_runner
34-
use entity work.test_runner(test_reset_a);
35-
end for;
36-
37-
for test_fixture
38-
for dut : dff
39-
use entity work.dff(behavioral);
40-
end for;
41-
end for;
42-
end for;
43-
end;
44-
45-
configuration test_reset_rtl of tb_selecting_test_runner_with_vhdl_configuration is
46-
for tb
47-
for test_runner_inst : test_runner
48-
use entity work.test_runner(test_reset_a);
49-
end for;
50-
51-
for test_fixture
52-
for dut : dff
53-
use entity work.dff(rtl);
54-
end for;
55-
end for;
56-
end for;
57-
end;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- This Source Code Form is subject to the terms of the Mozilla Public
2+
-- License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
-- You can obtain one at http://mozilla.org/MPL/2.0/.
4+
--
5+
-- Copyright (c) 2014-2025, Lars Asplund [email protected]
6+
7+
configuration test_reset_behavioral of tb_selecting_test_runner_with_vhdl_configuration is
8+
for tb
9+
for test_runner_inst : test_runner
10+
use entity work.test_runner(test_reset_a);
11+
end for;
12+
13+
for test_fixture
14+
for dut : dff
15+
use entity work.dff(behavioral);
16+
end for;
17+
end for;
18+
end for;
19+
end;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- This Source Code Form is subject to the terms of the Mozilla Public
2+
-- License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
-- You can obtain one at http://mozilla.org/MPL/2.0/.
4+
--
5+
-- Copyright (c) 2014-2025, Lars Asplund [email protected]
6+
7+
configuration test_reset_rtl of tb_selecting_test_runner_with_vhdl_configuration is
8+
for tb
9+
for test_runner_inst : test_runner
10+
use entity work.test_runner(test_reset_a);
11+
end for;
12+
13+
for test_fixture
14+
for dut : dff
15+
use entity work.dff(rtl);
16+
end for;
17+
end for;
18+
end for;
19+
end;

examples/vhdl/vhdl_configuration/test_state_change.vhd

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,3 @@ begin
3333

3434
test_runner_watchdog(runner, 10 * clk_period);
3535
end;
36-
37-
configuration test_state_change_behavioral of tb_selecting_test_runner_with_vhdl_configuration is
38-
for tb
39-
for test_runner_inst : test_runner
40-
use entity work.test_runner(test_state_change_a);
41-
end for;
42-
43-
for test_fixture
44-
for dut : dff
45-
use entity work.dff(behavioral);
46-
end for;
47-
end for;
48-
end for;
49-
end;
50-
51-
configuration test_state_change_rtl of tb_selecting_test_runner_with_vhdl_configuration is
52-
for tb
53-
for test_runner_inst : test_runner
54-
use entity work.test_runner(test_state_change_a);
55-
end for;
56-
57-
for test_fixture
58-
for dut : dff
59-
use entity work.dff(rtl);
60-
end for;
61-
end for;
62-
end for;
63-
end;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- This Source Code Form is subject to the terms of the Mozilla Public
2+
-- License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
-- You can obtain one at http://mozilla.org/MPL/2.0/.
4+
--
5+
-- Copyright (c) 2014-2025, Lars Asplund [email protected]
6+
7+
configuration test_state_change_behavioral of tb_selecting_test_runner_with_vhdl_configuration is
8+
for tb
9+
for test_runner_inst : test_runner
10+
use entity work.test_runner(test_state_change_a);
11+
end for;
12+
13+
for test_fixture
14+
for dut : dff
15+
use entity work.dff(behavioral);
16+
end for;
17+
end for;
18+
end for;
19+
end;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- This Source Code Form is subject to the terms of the Mozilla Public
2+
-- License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
-- You can obtain one at http://mozilla.org/MPL/2.0/.
4+
--
5+
-- Copyright (c) 2014-2025, Lars Asplund [email protected]
6+
7+
configuration test_state_change_rtl of tb_selecting_test_runner_with_vhdl_configuration is
8+
for tb
9+
for test_runner_inst : test_runner
10+
use entity work.test_runner(test_state_change_a);
11+
end for;
12+
13+
for test_fixture
14+
for dut : dff
15+
use entity work.dff(rtl);
16+
end for;
17+
end for;
18+
end for;
19+
end;

tests/acceptance/artificial/vhdl/cfg1.vhd

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@
44
--
55
-- Copyright (c) 2014-2025, Lars Asplund [email protected]
66

7-
architecture arch1 of ent is
8-
begin
9-
arch <= "arch1";
10-
end;
11-
127
configuration cfg1 of tb_with_vhdl_configuration is
138
for tb
149
for ent_inst : ent
1510
use entity work.ent(arch1);
1611
end for;
1712
end for;
18-
end;
13+
end;

tests/acceptance/artificial/vhdl/cfg2.vhd

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@
44
--
55
-- Copyright (c) 2014-2025, Lars Asplund [email protected]
66

7-
architecture arch2 of ent is
8-
begin
9-
arch <= "arch2";
10-
end;
11-
127
configuration cfg2 of tb_with_vhdl_configuration is
138
for tb
149
for ent_inst : ent
1510
use entity work.ent(arch2);
1611
end for;
1712
end for;
18-
end;
13+
end;

0 commit comments

Comments
 (0)