|
| 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-2019, Lars Asplund lars.anders.asplund@gmail.com |
| 6 | + |
| 7 | +library vunit_lib; |
| 8 | +context vunit_lib.vunit_context; |
| 9 | +context vunit_lib.vc_context; |
| 10 | + |
| 11 | +library ieee; |
| 12 | +use ieee.std_logic_1164.all; |
| 13 | +use ieee.numeric_std.all; |
| 14 | +use ieee.numeric_std_unsigned.all; |
| 15 | + |
| 16 | +library vc_foo_bar_lib; |
| 17 | +use vc_foo_bar_lib.foo_bar_pkg.all; |
| 18 | + |
| 19 | +entity tb_compliance is |
| 20 | + generic( |
| 21 | + use_custom_logger : boolean := false; |
| 22 | + use_custom_actor : boolean := false; |
| 23 | + use_custom_checker : boolean := false; |
| 24 | + fail_on_unexpected_msg_type : boolean := true; |
| 25 | + runner_cfg : string |
| 26 | + ); |
| 27 | +end entity; |
| 28 | + |
| 29 | +architecture tb of tb_compliance is |
| 30 | + constant custom_actor : actor_t := new_actor("foo_bar", inbox_size => 1); |
| 31 | + constant custom_logger : logger_t := get_logger("custom logger"); |
| 32 | + constant custom_checker : checker_t := new_checker("custom checker"); |
| 33 | + |
| 34 | + impure function create_handle return foo_bar_handle_t is |
| 35 | + variable logger : logger_t; |
| 36 | + variable actor : actor_t; |
| 37 | + variable checker : checker_t; |
| 38 | + begin |
| 39 | + logger := custom_logger when use_custom_logger else null_logger; |
| 40 | + actor := custom_actor when use_custom_actor else null_actor; |
| 41 | + checker := custom_checker when use_custom_checker else null_checker; |
| 42 | + |
| 43 | + return new_foo_bar( |
| 44 | + logger => logger, |
| 45 | + actor => actor, |
| 46 | + checker => checker, |
| 47 | + fail_on_unexpected_msg_type => fail_on_unexpected_msg_type); |
| 48 | + end; |
| 49 | + |
| 50 | + constant foo_bar_h : foo_bar_handle_t := create_handle; |
| 51 | + constant unexpected_msg : msg_type_t := new_msg_type("unexpected msg"); |
| 52 | + |
| 53 | + signal foo_clk : std_logic; |
| 54 | + signal foo_output_on_dut : std_logic; |
| 55 | +begin |
| 56 | + main : process |
| 57 | + variable t_start : time; |
| 58 | + variable msg : msg_t; |
| 59 | + constant default_logger : logger_t := get_logger("foo_bar"); |
| 60 | + begin |
| 61 | + test_runner_setup(runner, runner_cfg); |
| 62 | + |
| 63 | + while test_suite loop |
| 64 | + |
| 65 | + if run("Test that the sync interface is supported") then |
| 66 | + t_start := now; |
| 67 | + wait_for_time(net, as_sync(foo_bar_h), 1 ns); |
| 68 | + wait_for_time(net, as_sync(foo_bar_h), 2 ns); |
| 69 | + wait_for_time(net, as_sync(foo_bar_h), 3 ns); |
| 70 | + check_equal(now - t_start, 0 ns); |
| 71 | + t_start := now; |
| 72 | + wait_until_idle(net, as_sync(foo_bar_h)); |
| 73 | + check_equal(now - t_start, 6 ns); |
| 74 | + elsif run("Test that the actor can be customized") then |
| 75 | + t_start := now; |
| 76 | + wait_for_time(net, as_sync(foo_bar_h), 1 ns); |
| 77 | + wait_for_time(net, as_sync(foo_bar_h), 2 ns); |
| 78 | + check_equal(now - t_start, 0 ns); |
| 79 | + wait_for_time(net, as_sync(foo_bar_h), 3 ns); |
| 80 | + check_equal(now - t_start, 1 ns); |
| 81 | + wait_until_idle(net, as_sync(foo_bar_h)); |
| 82 | + check_equal(now - t_start, 6 ns); |
| 83 | + elsif run("Test unexpected message handling") then |
| 84 | + mock(default_logger); |
| 85 | + msg := new_msg(unexpected_msg); |
| 86 | + send(net, custom_actor, msg); |
| 87 | + wait for 1 ns; |
| 88 | + if fail_on_unexpected_msg_type then |
| 89 | + check_only_log(default_logger, "Got unexpected message unexpected msg", failure); |
| 90 | + else |
| 91 | + check_no_log; |
| 92 | + end if; |
| 93 | + unmock(default_logger); |
| 94 | + elsif run("Test that the logger can be customized") then |
| 95 | + mock(custom_logger); |
| 96 | + msg := new_msg(unexpected_msg); |
| 97 | + send(net, custom_actor, msg); |
| 98 | + wait for 1 ns; |
| 99 | + check_only_log(custom_logger, "Got unexpected message unexpected msg", failure); |
| 100 | + unmock(custom_logger); |
| 101 | + elsif run("Test that the checker can be customized") then |
| 102 | + mock(get_logger(custom_checker)); |
| 103 | + msg := new_msg(unexpected_msg); |
| 104 | + send(net, custom_actor, msg); |
| 105 | + wait for 1 ns; |
| 106 | + check_only_log(get_logger(custom_checker), "Got unexpected message unexpected msg", failure); |
| 107 | + unmock(get_logger(custom_checker)); |
| 108 | + end if; |
| 109 | + end loop; |
| 110 | + |
| 111 | + test_runner_cleanup(runner); |
| 112 | + end process; |
| 113 | + |
| 114 | + vc_foo_bar : entity vc_foo_bar_lib.foo_bar |
| 115 | + generic map( |
| 116 | + foo_bar_h => foo_bar_h |
| 117 | + ) |
| 118 | + port map( |
| 119 | + foo_clk => foo_clk, |
| 120 | + foo_input_on_dut => open, |
| 121 | + foo_output_on_dut => foo_output_on_dut |
| 122 | + ); |
| 123 | +end architecture; |
0 commit comments