使用 check 调试 C 中的单元测试
我正在尝试为我的 C 应用程序使用 check 单元测试框架。但我无法使用调试器 (gdb),因为有两点:
首先,检查使用一些复杂的宏(
START_TEST
和END_TEST
)和调试器很难在我的代码中这两个宏之间放置断点(事实上,我可以放置软件断点,但 gdb 从未见过)第二, 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
andEND_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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
查看无分叉模式:
Look at the no-fork mode:
实际上,你也可以使用 fork 模式。
gdb 有两个与 fork 行为相关的有趣选项:
-
detach-on-fork
(将其设置为 false)-
follow-on-fork
(父进程或子进程;我总是选择子进程)这将使 gdb 跟随子进程。
当子进程结束后,您必须使用
inferior
命令手动切换回父进程。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.我读了这个,他建议非常简单的解决方案:
这对我有用。然后,我可以在测试用例调用的函数(即被测试的函数)中设置断点,并且它在正确的位置中断。
I read this and he suggests a very simple solution:
that worked for me. I could then set a breakpoint in functions the test cases call (that is, the functions under test), and it broke at the right place.
尝试 TAP(测试任何协议)……它更容易实现、发布和调试。使其具有
valgrind
感知能力也非常容易,并且与gdb
。Try TAP (Test Anything Protocol) … it's a lot easier to implement, ship and debug. It's also very easy to make it
valgrind
-aware and tends to play nicer withgdb
.