|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# This Source Code Form is subject to the terms of the Mozilla Public |
| 4 | +# License, v. 2.0. If a copy of the MPL was not distributed with this file, |
| 5 | +# You can obtain one at http://mozilla.org/MPL/2.0/. |
| 6 | +# |
| 7 | +# Copyright (c) 2014-2023, Lars Asplund lars.anders.asplund@gmail.com |
| 8 | + |
| 9 | +from pathlib import Path |
| 10 | +from vunit import VUnit |
| 11 | + |
| 12 | +vu = VUnit.from_argv() |
| 13 | +vu.add_vhdl_builtins() |
| 14 | +lib = vu.add_library("lib") |
| 15 | +root = Path(__file__).parent |
| 16 | +lib.add_source_files(root / "*.vhd") |
| 17 | + |
| 18 | +# VHDL configurations are treated as a special case of the broader VUnit configuration |
| 19 | +# concept. As such the configuration can be extended beyond the capabilities of a |
| 20 | +# pure VHDL configuration. For example, by running with different generic values. |
| 21 | +tb = lib.test_bench("tb_selecting_dut_with_vhdl_configuration") |
| 22 | + |
| 23 | +for vhdl_configuration_name in ["dff_rtl", "dff_behavioral"]: |
| 24 | + for width in [8, 16]: |
| 25 | + tb.add_config( |
| 26 | + name=f"{vhdl_configuration_name}_{width}", |
| 27 | + generics=dict(width=width), |
| 28 | + vhdl_configuration_name=vhdl_configuration_name, |
| 29 | + ) |
| 30 | + |
| 31 | +# A top-level VHDL configuration is bound to an entity, i.e. the testbench. However, |
| 32 | +# when handled as part of VUnit configurations it can also be applied to a |
| 33 | +# single test case |
| 34 | +tb.test("Test reset").add_config(name="dff_rtl_32", generics=dict(width=32), vhdl_configuration_name="dff_rtl") |
| 35 | + |
| 36 | + |
| 37 | +# If the test runner is placed in a component instantiated into the testbench, different architectures of that |
| 38 | +# component can implement different tests and VHDL configurations can be used to select what test to run. |
| 39 | +# This is the approach taken by a traditional OSVVM testbench. In VUnit, such a test becomes a VUnit configuration |
| 40 | +# selecting the associated VHDL configuration rather than a VUnit test case, but that is of less importance. Note that |
| 41 | +# this approach is limited in that the test runner architecture can't contain a test suite with explicit test cases |
| 42 | +# (run function calls) but only the test_runner_setup and test_runner_cleanup calls. Should you need multiple test |
| 43 | +# suites sharing the same test fixture (the DUT and the surrounding verification components), the proper approach |
| 44 | +# is to put each test suite in its own testbench and make the test fixture a component reused between the testbenches. |
| 45 | +# That approach do not require any VHDL configurations. |
| 46 | +tb = lib.test_bench("tb_selecting_test_runner_with_vhdl_configuration") |
| 47 | +for vhdl_configuration_name in ["test_reset", "test_state_change"]: |
| 48 | + for width in [8, 16]: |
| 49 | + tb.add_config( |
| 50 | + name=f"{vhdl_configuration_name}_{width}", |
| 51 | + generics=dict(width=width), |
| 52 | + vhdl_configuration_name=vhdl_configuration_name, |
| 53 | + ) |
| 54 | + |
| 55 | +vu.main() |
0 commit comments