How to get the duration time of each test cases in Cmocka?

189 Views Asked by At

I was learning how to work with CMocka unit-testing framework in my C project.

So far everything goes well, and I can also generate a HTML report from CMocka's XML output by junit2html. When I read about what's in the report, I saw that there's an item called "Duration" which was always being zero in each of my test cases. After checking the CMocka XML output file and its source code, I assumed the function of calculating the duration time is not enabled.

In the XML outputfile, every test case showed that <testcase name="test_MyFunctionName" time="0.000" >.

In the cmocka.c, I found HAVE_STRUCT_TIMESPEC wasn't defined. But even I used -DHAVE_STRUCT_TIMESPEC while compiling, it still not worked.

Besides I found a function called clock_gettime (please refer to the code below) and didn't find its definition. Maybe this is the reason why cmocka couldn't calculate the duration time? but how can I use this function?

#ifdef HAVE_CLOCK_REALTIME
#define CMOCKA_CLOCK_GETTIME(clock_id, ts) clock_gettime((clock_id), (ts))
#else
#define CMOCKA_CLOCK_GETTIME(clock_id, ts)
#endif

Here's my environment and the screenshot of my html test report. Thanks for you time!

  • Windows 10
  • gcc 9.2.0
  • cmocka 1.1.5

enter image description here

0

There are 0 best solutions below