为什么谷歌测试是分段故障
Why is Google Test segfaulting?
我是Google Test的新手,我正在使用提供的示例。我的问题是,当我引入一个故障并设置GTEST_BREAK_ON_FAILURE=1
(或使用命令行选项)时,GTest将出现segfault。
我正在考虑这个例子。如果我在任何测试中插入类似这样的内容,我将开始得到段错误:
EXPECT_EQ(8, 2*3);
只是重申,只有当我也设置了GTEST_BREAK_ON_FAILURE=1
。我已经从命令行运行,也与gdb。如果没有设置该环境变量,则报告错误,但不报告segfault。
任何线索可能导致这个/我做错了什么?我一直在寻找类似的问题,但我还没有遇到任何问题。
仅供参考,我使用谷歌测试版本1.7.0在64位CrunchBang Linux 11"Waldorf"上运行。
编辑代码示例:
// Tests factorial of positive numbers.
TEST(FactorialTest, Positive) {
EXPECT_EQ(1, Factorial(1));
EXPECT_EQ(2, Factorial(2));
EXPECT_EQ(6, Factorial(3));
EXPECT_EQ(40320, Factorial(8));
}
调试器输出:
(gdb) run
Starting program: /home/yourfavoriteprotein/bin/cpp_unit_test_frameworks/gtest-1.7.0/samples/mytest
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Running main() from test_main.cc
[==========] Running 6 tests from 2 test cases.
[----------] Global test environment set-up.
[----------] 3 tests from FactorialTest
[ RUN ] FactorialTest.Negative
[ OK ] FactorialTest.Negative (0 ms)
[ RUN ] FactorialTest.Zero
[ OK ] FactorialTest.Zero (0 ms)
[ RUN ] FactorialTest.Positive
sample1_unittest.cc:112: Failure
Value of: 2*3
Actual: 6
Expected: 8
Program received signal SIGSEGV, Segmentation fault.
0x0000000000413427 in testing::UnitTest::AddTestPartResult(testing::TestPartResult::Type, char const*, int, std::string const&, std::string const&) ()
(gdb) quit
GTEST_BREAK_ON_FAILURE=1
意味着如果测试失败,Google Test会将您放入调试器。
让你进入调试器的一个简单、便携的方法就是触发段错误。
换句话说,这种行为是设计出来的;Google Test故意触发一个段错误来运行调试器。(参见这里的Google测试代码)
相关文章:
- 分段故障(堆芯转储)矢量
- 数组的指针从不分段故障
- Windows 10-使用gtkmm-3.0库和g++[包括再现]的分段故障
- 分段故障 运行C++代码时出现 SIGSEGV
- 分段故障背包问题
- 分段故障 11,从类函数显示动态 C 字符串
- 面临分段故障 使用 ffmpeg 读取视频时,因为"pFormatCtx-> streams [i]-> codecpar"的地址0x00
- 在C++中,当指向删除和指向不同对象时,分段故障指针
- 分段故障说明
- 分段故障(核心转储)-不知道为什么
- 分段故障线程
- hiredis SET遇到分段故障
- 分段故障,合并排序算法
- 多线程程序中的分段故障和gdb回溯上的不完整信息
- 到达主C++之前分段故障
- 分段故障核心使用 IF流转储
- 使用向量的移动键盘排列(分段故障)
- 在二进制树插入和遍历期间,我得到了分段故障
- 分段故障在类之间返回整数
- C++分段故障BST