C++ 无法从项目';s示例项目
我从centos7得到了完全相同的结果,它是使用FedoraRPM规范文件从源代码构建的clang-3.6.1。Ubuntu 14.04,clang-3.4 使用此处wiki中的说明 尽可能接近。该页面上次更新是在6个月前 谷歌613版仍在使用tr1C++ 无法从项目';s示例项目,c++,clang++,sanitizer,msan,C++,Clang++,Sanitizer,Msan,我从centos7得到了完全相同的结果,它是使用FedoraRPM规范文件从源代码构建的clang-3.6.1。Ubuntu 14.04,clang-3.4 使用此处wiki中的说明 尽可能接近。该页面上次更新是在6个月前 谷歌613版仍在使用tr1 In file included from /home/hal/googletest/src/gtest-all.cc:39: In file included from /home/hal/googletest/include/gtest/gte
In file included from /home/hal/googletest/src/gtest-all.cc:39:
In file included from /home/hal/googletest/include/gtest/gtest.h:58:
In file included from /home/hal/googletest/include/gtest/internal/gtest-internal.h:40:
/home/hal/googletest/include/gtest/internal/gtest-port.h:507:13: fatal error:
'tr1/tuple' file not found
# include <tr1/tuple> // NOLINT
^
1 error generated.
而msan并没有注意到该页面中的琐碎建议案例
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from FooTest
[ RUN ] FooTest.Foo
test.cc:7: Failure
Value of: foo[4]
Actual: '\0'
Expected: 'z'
Which is: 'z' (122, 0x7A)
[ FAILED ] FooTest.Foo (1 ms)
[----------] 1 test from FooTest (1 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (1 ms total)
[ PASSED ] 0 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] FooTest.Foo
1 FAILED TEST
我有一个项目,valgrind由于使用了一些非常大的MMAP而呕吐,所以内存清理将非常有用。如果我做错了什么。谷歌测试似乎以某种方式抑制了错误。删除google测试并将测试用例转换为
如果(foo[4]=='z')
std::cout由于单元测试中看到的值是
'\0'
,因此可能是字符串实际初始化了位置4处的内存,使其与C字符串(尾随零)兼容。单元测试和手动测试用例之间的差异可能是编译器优化的结果。如果将字符串切换到std::vector{'f',o',o'}
,会发生什么情况
如果您也可以发布单元测试代码,这会很有帮助。这不是MemorySinitizer或googletest问题:显然libc++最近发生了变化,现在它初始化了实际四字节字符串“foo”之外的字节,因此MSan不会为这种越界访问生成报告 MSan wiki已更新为使用不同的示例,对于该示例,将按预期报告错误:
TEST(FooTest, Foo) {
int uninitialized;
EXPECT_GT(uninitialized, 5);
}
结果:
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from FooTest
[ RUN ] FooTest.Foo
==39032== WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x48d73c in testing::AssertionResult testing::internal::CmpHelperGT<int, int>(char const*, char const*, int const&, int const&) googletest/include/gtest/gtest.h:1463:1
#1 0x48ce7a in FooTest_Foo_Test::TestBody() test.cc:6:3
...
[=============]从一个测试用例运行一个测试。
[-------------]全局测试环境设置。
[-------------]1次足部测试
[跑步]最脚的。Foo
==39032==警告:MemorySInitiatizer:使用未初始化的值
#测试中的0 0x48d73c::断言结果测试::内部::CmpHelperGT(char const*,char const*,int const&,int const&)googletest/include/gtest/gtest.h:1463:1
#测试中的0x48ce7a::TestBody()测试。cc:6:3
...
另外,当配置googletest以在修订版613上构建它时,您可以添加
-DGTEST\u USE_OWN\u TR1\u TUPLE=1
来编译标志。所提供链接中的单元测试代码没有任何更改。将std::string更改为std::vector会产生完全相同的测试输出,读取foo[4]被消毒剂忽略。@Hal-“…读取foo[4]已被消毒剂忽略…-优化器可能已对其进行了更改,使其不再是您希望标记的简单读数。也许您应该重新编写问题,从头开始。它确实从头开始,并提供了每个步骤。无论如何,谢谢你。
TEST(FooTest, Foo) {
int uninitialized;
EXPECT_GT(uninitialized, 5);
}
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from FooTest
[ RUN ] FooTest.Foo
==39032== WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x48d73c in testing::AssertionResult testing::internal::CmpHelperGT<int, int>(char const*, char const*, int const&, int const&) googletest/include/gtest/gtest.h:1463:1
#1 0x48ce7a in FooTest_Foo_Test::TestBody() test.cc:6:3
...