【问题标题】:valgrind --error-exitcode , negative valuesvalgrind --error-exitcode ,负值
【发布时间】:2021-03-25 15:30:53
【问题描述】:

如果valgrind 报告错误(构建测试脚本),我正在尝试设置自定义错误代码,但是在设置负值时它似乎没有按预期工作,这就是我运行valgrind的方式:

valgrind --leak-check=full --error-exitcode=-1 -q ./leaks

然而,这会返回 0(这是 leaks 的返回值),而不是 -1

echo $?
0

如果设置为正值,则按预期工作:

valgrind --leak-check=full --error-exitcode=1 -q ./leaks

echo $?
1

Valgrind manual,指定:

--error-exitcode=<number> [default: 0]

如果 Valgrind 在运行中报告任何错误,则指定要返回的替代退出代码。当设置为默认值(零)时, Valgrind 的返回值总是 被模拟的过程。当设置为非零值时,该值是 如果 Valgrind 检测到任何错误,则返回。这对 使用 Valgrind 作为自动化测试套件的一部分,因为它使 易于检测 Valgrind 报告错误的测试用例,只需 通过检查返回码。

有人知道为什么会出现这种情况吗?

使用 Valgrind-3.10.0

【问题讨论】:

    标签: bash valgrind


    【解决方案1】:

    手册不准确,Valgrind 不能返回负值,它在Valgrind's source。它将选项的值分配给clo_eror_exitcode

    else if VG_INT_CLO (arg, "--error-exitcode", VG_(clo_error_exitcode)) {}
    

    然后检查是否为正,否则忽略该选项。

    if (VG_(clo_error_exitcode) > 0
        && VG_(get_n_errs_found)() > 0) {
       VG_(client_exit)( VG_(clo_error_exitcode) );
    } else {
       /* otherwise, return the client's exit code, in the normal
          way. */
       VG_(client_exit)( VG_(threads)[tid].os_state.exitcode );
    }
    

    即使可以,也不会像Linux, negative exit codes?那样有用

    【讨论】:

    • 太棒了,感谢您提供更多信息!
    猜你喜欢
    • 2019-01-15
    • 1970-01-01
    • 1970-01-01
    • 2018-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-09
    • 1970-01-01
    相关资源
    最近更新 更多