How to print the content of TestError raised in Cocotb

262 views Asked by At

If I raise a TestError under cocotb test coroutine :

@cocotb.test()
def double_cmd(dut):
    ...
    raise TestError("Wrong CRC value found")

I know that error raised in test log, but I don't see the message "Wrong CRC value found":

12580176.01ns ERROR    Test Failed: double_cmd (result was TestError)
12580176.01ns ERROR    Failed 1 out of 1 tests (3 skipped)
12580176.01ns INFO     ************************************************************************************
                       ** TEST                        PASS/FAIL  SIM TIME(NS)  REAL TIME(S)  RATIO(NS/S) **
                       ************************************************************************************
                       ** test_laser_com.simple_test     N/A            0.00          0.00         0.00  **
                       ** test_laser_com.wrong_crc       N/A            0.00          0.00         0.00  **
                       ** test_laser_com.gas_cmd         N/A            0.00          0.00         0.00  **
                       ** test_laser_com.double_cmd     FAIL     12580176.01         14.41    872921.37  **
                       ************************************************************************************

Is there a proper way to print the TestError message in log ?

3

There are 3 answers

0
FabienM On BEST ANSWER

The only solution I found currently is to print the message before raising TestError:

@cocotb.test()
def double_cmd(dut):
    ...
    dut._log.error("Wrong CRC value found")
    raise TestError()

But maybe it's the thing to do?

0
cmarqu On

I would consider this a bug. Maybe you want to report it at https://github.com/potentialventures/cocotb/issues?

Activity in cocotb has picked quite a lot recently, so it will be worth reporting.

0
ferdepe On

Nowadays it is possible to do the following:

@cocotb.test()
def double_cmd(dut):
   ...
   raise cocotb.result.TestError("Wrong CRC value found")

Which will produce the output:

#     50.00ns INFO     cocotb.regression                  test_crc failed
#                                                         Traceback (most recent call last):
#                                                           File "/home/user/test_crc.py", line 230, in test_crc
#                                                             raise cocotb.result.TestError("Wrong CRC value found")
#                                                         cocotb.result.TestError: Wrong CRC value found