[英]bazel test lacking SEGFAULT information
We are currently migrating from a CMake-based build to bazel.我们目前正在从基于 CMake 的构建迁移到 bazel。 For unit-testing, we are using our own implemented framework.对于单元测试,我们使用自己实现的框架。
When dealing with a SEGFAULT
, ctest
gives the following output:处理SEGFAULT
时, ctest
给出以下 output:
The following tests FAILED:
19 - SomeTest (SEGFAULT)
Errors while running CTest
However, when executing the exact same test with the exact same build-options and sources, the bazel
output looks like:但是,当使用完全相同的构建选项和源执行完全相同的测试时, bazel
output 看起来像:
//services/SomeTest:test FAILED in 0.2s
/root/.cache/bazel/_bazel_root/b343aed36e4de4757a8e698762574e37/execroot/repo/bazel-out/k8-fastbuild/testlogs/SomeTest/test/test.log
The other output is just the regular printout from the test, nothing regarding the SEGFAULT
.另一个 output 只是测试的常规打印输出,与SEGFAULT
。 Same goes for the contents of SomeTest/test/test.log
. SomeTest/test/test.log
的内容也是如此。
I tried the following options to bazel test
: --test_output=all
, --test_output=errors
, --verbose_test_summary
, and --verbose_failures
.我尝试了以下bazel test
选项: --test_output=all
、 --test_output=errors
、 --verbose_test_summary
和--verbose_failures
。
What am I missing here?我在这里想念什么?
The output you're seeing comes from CTest, not from your application under test.您看到的 output 来自 CTest,而不是来自您正在测试的应用程序。 If you want to see helpful information like that you'll need some testing framework to provide it to you.如果你想看到这样的有用信息,你需要一些测试框架来提供给你。 Here's a comparison between a vanilla test and a Catch2 test.这是普通测试和 Catch2 测试之间的比较。
test_vanilla.cc test_vanilla.cc
int main() { return 1 / 0; }
test_catch2.cc test_catch2.cc
#include <catch2/catch.hpp>
TEST_CASE("Hello") { REQUIRE(1 / 0); }
WORKSPACE工作空间
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "catch2",
sha256 = "3cdb4138a072e4c0290034fe22d9f0a80d3bcfb8d7a8a5c49ad75d3a5da24fae",
strip_prefix = "Catch2-2.13.7",
urls = ["https://github.com/catchorg/Catch2/archive/v2.13.7.tar.gz"],
)
BUILD建造
cc_test(
name = "test_vanilla",
srcs = ["test_vanilla.cc"],
)
cc_test(
name = "test_catch2",
srcs = ["test_catch2.cc"],
defines = ["CATCH_CONFIG_MAIN"],
deps = ["@catch2"],
)
Now let's run the tests.现在让我们运行测试。
❯ bazel test //:test_vanilla
[...]
//:test_vanilla FAILED in 0.3s
test.log测试日志
exec ${PAGER:-/usr/bin/less} "$0" || exit 1
Executing tests from //:test_vanilla
-----------------------------------------------------------------------------
You can see that the test failed, because it did not return 0
(as it failed by illegally dividing by zero. If you have systemd-coredump installed (and coredumps enabled), you can get some info with您可以看到测试失败,因为它没有返回0
(因为它因非法除以零而失败。如果您安装了 systemd-coredump(并且启用了 coredump),您可以通过以下方式获取一些信息
❯ coredumpctl -1 debug
[...]
Core was generated by `/home/laurenz/.cache/bazel/_bazel_laurenz/be59967ad4f5a83f16e874b5d49a28d5/sand'.
Program terminated with signal SIGFPE, Arithmetic exception.
#0 0x0000561398132668 in main ()
(gdb)
If you have a test framework like CTest or Catch2, it will provide more infos so you don't even need to check the coredump yourself.如果您有 CTest 或 Catch2 之类的测试框架,它将提供更多信息,因此您甚至不需要自己检查 coredump。 The test log will provide the problematic file and line as well as the signal.测试日志将提供有问题的文件和行以及信号。
❯ bazel test //:test_catch2
[...]
//:test_catch2 FAILED in 0.2s
test.log测试日志
exec ${PAGER:-/usr/bin/less} "$0" || exit 1
Executing tests from //:test_catch2
-----------------------------------------------------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test_catch2 is a Catch v2.13.7 host application.
Run with -? for options
-------------------------------------------------------------------------------
Hello
-------------------------------------------------------------------------------
test_catch2.cc:3
...............................................................................
test_catch2.cc:3: FAILED:
due to a fatal error condition:
SIGFPE - Floating point error signal
===============================================================================
test cases: 1 | 1 failed
assertions: 1 | 1 failed
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.