0

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

Risusdan
  • 61
  • 7
  • What does its documentation or tutorials say about these macros? You might need to implement `clock_gettime()` and to define `HAVE_CLOCK_REALTIME`. – the busybee Aug 03 '22 at 09:15
  • @thebusybee I've check for clock_gettime(), however there's no such a function named like this in cmocka's source code. – Risusdan Aug 03 '22 at 09:40
  • That's why I wrote "_**You** might need to implement ..._". – the busybee Aug 03 '22 at 09:44

0 Answers0