I may have some functions that assert and fail if they're not happy.
How do I test this functionality with VUnit to ensure that these functions do in-fact throw the failure in the right conditions?
For instance, lets say I wanted to check this function:
function to_normalised_float(slv: std_logic_vector) return half_float is
variable temp_hf: half_float;
begin
assert slv'high = 15 report "SLV provided is incorrect length for an FP16";
-- ConstructFloat
return normalise_float(temp_hf);
end function;
I can quite easily test that it returns the expected value if I pass in a value and then assert on the output in my testbench.
However, I also want to be able to test, using VUnit, that if I pass in a 22 bit SLV, that the assertion throws.
This is obviously a very simplified example, but it should explain what I mean.
The equivalent in C# would be Assert.Throws(function) if that helps.
The ability to inspect asserts will improve with VHDL-2019 support in your simulator but since you're using VUnit I recommend using VUnit mocking (http://vunit.github.io/logging/user_guide.html#mocking and https://github.com/VUnit/vunit/blob/f02c21452a505c527db575b10db94195ceb7ed2f/vunit/vhdl/logging/src/logger_pkg.vhd#L342) which is provided exactly to support your use case.
First replace your
assertwith a VUnitcheck:When that check fails you will see an error message looking something like this:
checkis the VUnitloggermanaging this message. You can get this logger by name (get_logger("check")) and mock it. Mocking means that all output messages (of a specific severity level) will be placed in a queue rather than passed to stdout. The messages in this queue can be inspected to determine if the function works as expected. Here is a slightly modified example testbench to show the principleThe first test case will fail (which is your problem) but the last two will pass
I can also recommend using
check_equalfor a more informative output.will give you the following error output: