I'm using colcon
to run tests for my ROS2 application.
Up until now I haven't had any problems, but now after adding a simple fixture
我正在使用COLCON为我的ROS2应用程序运行测试。到目前为止,我还没有遇到任何问题,但现在在添加了一个简单的灯具后
class ElectionTest : public ::testing::Test {
protected:
ElectionModule core_;
};
and relative tests it seems like the underlying GTest is crashing: in the test summary I see
与相关测试相比,底层的GTest似乎正在崩溃:我在测试摘要中看到
[ RUN ] ElectionTest.CantPrepareTopics
-- run_test.py: return code -11
-- run_test.py: generate result file '/home/slim71/Documents/git/SpartanLIFT/build/pelican/test_results/pelican/pelican_test.gtest.xml' with failed test
-- run_test.py: verify result file '/home/slim71/Documents/git/SpartanLIFT/build/pelican/test_results/pelican/pelican_test.gtest.xml'
and everything stops of course. Code -11
should be SEGFAULT
, which I don't know where is coming from.
当然,一切都会停止。代码11应该是SEGFAULT,我不知道这是从哪里来的。
Introducing some cout
here and there I can see that the crash happens after calling the object destructor, but then I don't know what the problem can be.
If the ElectionModule
destructor is being called before the test ends, my guess is that there's no problem with my class...
在这里和那里介绍一些代码,我可以看到崩溃是在调用对象析构函数之后发生的,但是我不知道会有什么问题。如果在测试结束之前调用electionModule析构函数,我猜我的类没有问题……
Is there any way to debug or find out more?
有什么方法可以调试或了解更多信息吗?
更多回答
优秀答案推荐
In the end, my "guess" was wrong!
It was indeed due to my code (which to be honest is always the most probable explanation): there was indeed some problem in the use of pointers, so it would have been better if I shared at least parts of it..
最后,我的“猜测”错了!这确实是因为我的代码(老实说,这总是最有可能的解释):指针的使用确实存在一些问题,所以如果我至少共享其中的一部分会更好。
To be precise, in case anybody else stumbles in this: it seemed like something out of my code because it was the invoked at the very end of the destructor. I was using RCLCPP_DEBUG_STREAM
with an empty pointer to rclcpp::Logger
. I had added a boolean check, aka if(logger_)
, but since logger_
wasn't initialized to a nullptr
I guess here and there the boolean conversion passed and the code tried to access some protected memory. Definitely my bad!
准确地说,以防其他人在这方面遇到困难:它看起来像是我的代码之外的东西,因为它是在析构函数的末尾调用的。我使用带有指向rclcpp::logger的空指针的RCLCPP_DEBUG_STREAM。我添加了一个布尔检查,也就是if(Logger_),但是由于logger_没有被初始化为nullptr,我猜这里和那里传递了布尔转换,代码试图访问一些受保护的内存。绝对是我的错!
The most useful thing I got from this, which I'll share just in case, is how to correctly debug the ROS2 executable used by colcon test
:
我从中得到的最有用的东西是如何正确调试colcon test使用的ROS2可执行文件,这一点我将与大家分享,以防万一:
- Be sure to compile the executable with debug info, i.e. by adding
set(CMAKE_BUILD_TYPE Debug)
in the CMakeLists.txt.
- Get the path to the compiled executable (for example, you can manually launch
colcon test
and inspect the summary, like I did)
- Just launch that executable in the debugger with the appropriate command! I've used
gdbtui /path/to/test_exe
Well, I guess the loss in reputation is what I get from this! ¯_(ツ)_/¯
好吧,我想这就是我在声誉上的损失!_(ツ)_/
更多回答
我是一名优秀的程序员,十分优秀!