Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging unit test in C using check

I'm trying to use check unit testing framework for my C application. But I can't use the debugger (gdb) with it because of two points:

  • first, check use some complex macros (START_TEST and END_TEST) and the debugger has trouble to put a breakpoint in my code between these two macros (in fact, I can put a software breakpoint but It is never seen by gdb)

  • second, check define some sort of exceptions by redefining behavior of interruption. Hence, when I try to put a hardware breakpoint, the test failed and exit because check consider the hardware breakpoint as a failure of my test.

Does anyone has already met this problem and has a solution?

like image 781
Kartoch Avatar asked Oct 30 '09 13:10

Kartoch


People also ask

Can we debug unit test?

Debug and analyze unit tests with Test ExplorerYou can use Test Explorer to start a debugging session for your tests. Stepping through your code with the Visual Studio debugger seamlessly takes you back and forth between the unit tests and the project under test.

What do you check in a unit test?

A unit test typically features three different phases: Arrange, Act, and Assert (sometimes referred to as AAA). For a unit test to be successful, the resulting behavior in all three phases must be in line with expectations.

How do I debug a NUnit test?

Set a break point within the text of the test, use the menu option, and you should be able to immediately debug your test. A NUnit test is defined as a method that is public , not static , with no parameters, has a return type of void , and has the Test attribute.


2 Answers

Look at the no-fork mode:

Check normally forks to create a separate address space. This allows a signal or early exit to be caught and reported, rather than taking down the entire test program, and is normally very useful. However, when you are trying to debug why the segmentation fault or other program error occurred, forking makes it difficult to use debugging tools.

like image 170
Jonathan Leffler Avatar answered Sep 30 '22 14:09

Jonathan Leffler


Actually, you CAN use fork-mode too.

gdb has two interesting options related to fork behaviour:
- detach-on-fork (set this to false)
- follow-on-fork (either parent or child; I always take child)

This will make gdb follow the child process. When the child process has ended, you have to manually switch back to the parent process by using the inferior command.

like image 24
Paul Praet Avatar answered Sep 30 '22 15:09

Paul Praet