`FAIL_IF macro will print out the failing point and the comparison code upon failure, but there's no option to provide additional detail on object state (which would give us an insight into why a test failed without having to breakpoint/step through it). While one could add prints before every check, that would needlessly pollute the log.
I propose a second optional parameter (or a new macro for older simulators that don't support optional macro parameters), that would work something like this:
`define FAIL_IF(condition, msg="") \
if (msg != "") \
$display({"FAIL MSG: ", msg}); \
..do whatever `FAIL_IF does...
This is similar to how most assert-like statements work.
In my setup, I've created `FAIL_IF_LOG:
`define FAIL_IF_LOG(condition, msg="") \
if (msg != "") \
$display({"FAIL MSG: ", msg}); \
`FAIL_IF(condition)
..but I think this would be useful enough to include in baseline code.
Example usage:
`SVTEST_BEGIN(sqrt16)
int unsigned res = sqrt(16);
`FAIL_IF(res != 4, $psprintf("sqrt(16) returned %0d", res))
`SVTEST_END
Anonymous
Good suggestion. I work around this myself with the print statements :(.
This'll be another that I look at once the 3.1 dust settles.
finally. released in v3.7. not exactly as you've described in that I inserted the extra string within the usual log message. but hopefully this gives others what you're looking for. I added both a FAIL_IF_LOG and FAIL_UNLESS_LOG but not the other macros yet. if they do what you're looking for, I'll do the rest.