使用 check 调试 C 中的单元测试

发布于 2024-08-09 06:00:12 字数 374 浏览 7 评论 0原文

我正在尝试为我的 C 应用程序使用 check 单元测试框架。但我无法使用调试器 (gdb),因为有两点:

  • 首先,检查使用一些复杂的宏(START_TESTEND_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 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

醉生梦死 2024-08-16 06:00:12

查看无分叉模式

通常检查分叉以创建单独的地址空间。这允许捕获并报告信号或提前退出,而不是取消整个测试程序,并且通常非常有用。但是,当您尝试调试分段错误或其他程序错误发生的原因时,分叉使得很难使用调试工具。

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.

堇年纸鸢 2024-08-16 06:00:12

实际上,你也可以使用 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.

缺⑴份安定 2024-08-16 06:00:12

我读了这个,他建议非常简单的解决方案:

gdb > set environment CK_FORK=no

这对我有用。然后,我可以在测试用例调用的函数(即被测试的函数)中设置断点,并且它在正确的位置中断。

I read this and he suggests a very simple solution:

gdb > set environment CK_FORK=no

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.

可爱咩 2024-08-16 06:00:12

尝试 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 with gdb.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文