在CI系统中,我使用valgrind运行一系列测试,如果valgrind和0
没有找到错误,我期望返回值1
。测试本身成功运行并返回0
。
error-exitcode
似乎是这样的:
--error-exitcode=<number> exit code to return if errors found [0=disable]
现在我有一个程序从第三方库生成still reachable
。不理想,但没关系。我尝试通过调用:
still reachable
不是错误
valgrind --errors-for-leak-kinds=definite,indirect,possible --error-exitcode=1 ./tests
打印
==9198== LEAK SUMMARY:
==9198== definitely lost: 0 bytes in 0 blocks
==9198== indirectly lost: 0 bytes in 0 blocks
==9198== possibly lost: 0 bytes in 0 blocks
==9198== still reachable: 392 bytes in 4 blocks
==9198== suppressed: 0 bytes in 0 blocks
但仍然会返回1
。
有没有办法忽略返回值中的still reachable
?
答案 0 :(得分:0)
TL; DR:使用
valgrind --leak-check=full --error-exitcode=1 ./tests
好的,我认为我在构建SSCCE时找到了答案
<强> SSCCE 强>
让memLeakTest.cpp
成为
#include <cstdlib>
#include <iostream>
void makeDefinitelyLostPointer()
{
int* definitelyLostPointer = new int(5555);
(*definitelyLostPointer) += 1;
}
void makeStillReachablePointer()
{
int* stillReachablePointer = new int(3333);
std::exit(0);
(*stillReachablePointer) += 1;
}
int main()
{
//makeDefinitelyLostPointer();
makeStillReachablePointer();
return 0;
}
g++ memLeakTest.cpp -o memLeakTest
./memLeakTest; echo $?
,其中显示返回值0
valgrind ./memLeakTest; echo $?
,返回0
valgrind --leak-check=full --error-exitcode=1 ./memLeakTest
,如果0
已停用,则返回makeDefinitelyLostPointer()
;如果1
已启用,则返回makeDefinitelyLostPointer()
。在这两种情况下仍然存在可达物。