简体   繁体   English

Boost单元测试因sigabrt而失败

[英]Boost unit tests fail with sigabrt

I wrote a dynamic library and unit tests for it. 我编写了一个动态库并对其进行了单元测试。 Recently, I checked the library with Valgrind for any memory leaks and after some polishing I managed to get rid of every single leak. 最近,我与Valgrind一起检查了库是否有内存泄漏,经过一番磨合后,我设法摆脱了每个泄漏。 But after running the boost unit tests, I encountered several weird errors from boost and I just can't find the origin... 但是在运行boost单元测试之后,我遇到了来自boost的几个奇怪的错误,我只是找不到原点...

Here is the complete console error log: 这是完整的控制台错误日志:

nddlgen-core-test: /usr/include/boost/smart_ptr/shared_ptr.hpp:653: typename boost::detail::sp_member_access<T>::type boost::shared_ptr<T>::operator->() const [with T = sdf::Element; typename boost::detail::sp_member_access<T>::type = sdf::Element*]: Assertion `px != 0' failed.
nddlgen-core-test: /usr/include/boost/smart_ptr/shared_ptr.hpp:653: typename boost::detail::sp_member_access<T>::type boost::shared_ptr<T>::operator->() const [with T = sdf::Element; typename boost::detail::sp_member_access<T>::type = sdf::Element*]: Assertion `px != 0' failed.
nddlgen-core-test: /usr/include/boost/smart_ptr/shared_ptr.hpp:653: typename boost::detail::sp_member_access<T>::type boost::shared_ptr<T>::operator->() const [with T = sdf::Element; typename boost::detail::sp_member_access<T>::type = sdf::Element*]: Assertion `px != 0' failed.
nddlgen-core-test: /usr/include/boost/smart_ptr/shared_ptr.hpp:653: typename boost::detail::sp_member_access<T>::type boost::shared_ptr<T>::operator->() const [with T = sdf::Element; typename boost::detail::sp_member_access<T>::type = sdf::Element*]: Assertion `px != 0' failed.
nddlgen-core-test: /usr/include/boost/smart_ptr/shared_ptr.hpp:653: typename boost::detail::sp_member_access<T>::type boost::shared_ptr<T>::operator->() const [with T = sdf::Element; typename boost::detail::sp_member_access<T>::type = sdf::Element*]: Assertion `px != 0' failed.
nddlgen-core-test: /usr/include/boost/smart_ptr/shared_ptr.hpp:653: typename boost::detail::sp_member_access<T>::type boost::shared_ptr<T>::operator->() const [with T = sdf::Element; typename boost::detail::sp_member_access<T>::type = sdf::Element*]: Assertion `px != 0' failed.
nddlgen-core-test: /usr/include/boost/smart_ptr/shared_ptr.hpp:653: typename boost::detail::sp_member_access<T>::type boost::shared_ptr<T>::operator->() const [with T = sdf::Element; typename boost::detail::sp_member_access<T>::type = sdf::Element*]: Assertion `px != 0' failed.
nddlgen-core-test: /usr/include/boost/smart_ptr/shared_ptr.hpp:653: typename boost::detail::sp_member_access<T>::type boost::shared_ptr<T>::operator->() const [with T = sdf::Element; typename boost::detail::sp_member_access<T>::type = sdf::Element*]: Assertion `px != 0' failed.
nddlgen-core-test: /usr/include/boost/smart_ptr/shared_ptr.hpp:653: typename boost::detail::sp_member_access<T>::type boost::shared_ptr<T>::operator->() const [with T = sdf::Element; typename boost::detail::sp_member_access<T>::type = sdf::Element*]: Assertion `px != 0' failed.
nddlgen-core-test: /usr/include/boost/smart_ptr/shared_ptr.hpp:653: typename boost::detail::sp_member_access<T>::type boost::shared_ptr<T>::operator->() const [with T = sdf::Element; typename boost::detail::sp_member_access<T>::type = sdf::Element*]: Assertion `px != 0' failed.
nddlgen-core-test: /usr/include/boost/smart_ptr/shared_ptr.hpp:653: typename boost::detail::sp_member_access<T>::type boost::shared_ptr<T>::operator->() const [with T = sdf::Element; typename boost::detail::sp_member_access<T>::type = sdf::Element*]: Assertion `px != 0' failed.

In the results of the unit tests, it also says for each of those errors above something like the following: 在单元测试的结果中,它还针对上述错误中的每一个都表示如下内容:

../src/base/Controller_Test.cpp(72): Exception: signal: SIGABRT (application abort requested)
Last check point was here.

The weird thing is, that every single BOOST_CHECK_* without any exception passes without a problem, but eventually some (not all!) test functions would fail anyway with the errors mentioned above... 奇怪的是,每个BOOST_CHECK_*都毫无例外地通过而没有问题,但是最终某些(不是全部!)测试函数无论如何都会因上述错误而失败...

Here is a part of my unit test class, I marked line 72 above with a comment. 这是我的单元测试课的一部分,我在上面的第72行加上了注释。 Since the error is always the same, I cut the test class to contain one example. 由于错误始终是相同的,因此我将测试类剪切为包含一个示例。

#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE ControllerTest

#include <boost/test/included/unit_test.hpp>
#include <boost/algorithm/string.hpp>

#include <nddlgen/Controller.h>

using namespace std;
using namespace nddlgen;
using namespace boost;
using namespace boost::unit_test;

struct UnitUnderTest
{
    UnitUnderTest()
    {
        c = new Controller(&this->errorText);
    }

    ~UnitUnderTest()
    {
        boost::checked_delete(c);
    }

    Controller* c;
    string errorText;
};

string existingFile = "res/testmodel.sdf";
string corruptedFile = "res/corruptedmodel.sdf";

/**
 * ======================================================
 * Tests for normal operation
 * ======================================================
 */
BOOST_AUTO_TEST_SUITE (ControllerTestNormalBehaviour)

    /**
     * Test if the output file names match the expected behavior.
     */
    BOOST_AUTO_TEST_CASE (testGetOutputFileNames)
    {
        UnitUnderTest uut;
        string actualModelOutputFileName;
        string actualInitialStateOutputFileName;

        // Should work since a file identifier has not been set yet
        BOOST_CHECK_EQUAL(uut.c->setFileIdentifier(existingFile), true);

        actualModelOutputFileName = uut.c->getModelsOutputFileName();
        actualInitialStateOutputFileName = uut.c->getInitialStateOutputFileName();

        BOOST_CHECK_EQUAL(actualModelOutputFileName, "testmodel-model.nddl");
        BOOST_CHECK_EQUAL(actualInitialStateOutputFileName, "testmodel-initial-state.nddl"); // This is line 72
    }

BOOST_AUTO_TEST_SUITE_END()

After that, I checked the compiled unit test program with Valgrind and found several memory leaks... I don't know if this is relevant, but since my library is (according to Valgrind) mem-leak-free, I assume that it must be boost... 之后,我用Valgrind检查了已编译的单元测试程序,发现了几次内存泄漏...我不知道这是否相关,但是由于我的库(根据Valgrind)是无内存泄漏的,因此我认为必须提升...

What can I do to fix the problem so that my unit tests will run without these kind of errors? 我该如何解决该问题,以便我的单元测试可以在没有此类错误的情况下运行? Or does anyone got a tip for me for how I could debug this in any way? 还是有人为我提供了如何以任何方式调试它的提示?

The error is not in the code posted. 该错误不在发布的代码中。

Live On Coliru 生活在Coliru

You'll have to debug this yourself. 必须这样调试自己。

The problem appears to be with freed or uninitialized shared pointers to sdf::Element . 问题似乎在于释放或未初始化的指向sdf::Element共享指针。 See whether you use any static data that could have become linked into both the executable and the dynamic library (perhaps they're defined in header files). 查看您是否使用了可能已链接到可执行文件和动态库中的任何静态数据(也许它们是在头文件中定义的)。

See whether you have shared pointers aliasing other shared pointers. 查看是否有共享指针别名其他共享指针。 See if you used shared_from_this (indirectly) from the object's constructor. 查看是否从对象的构造函数中使用了shared_from_this (间接)。

If not, just eliminate causes. 如果没有,请消除原因。 Comment all tests until the error disappears. 注释所有测试,直到错误消失。 Remove TUs. 删除TU。 Make more stuff TU-local. 使更多的东西TU-local。 Etc. etc. right until you have a sample that fits into an SO question and still exhibits the problem. 等等,直到您拥有适合SO问题的样本,并且仍然显示出该问题为止。

Likely, you'll spot the source of the problem before that. 在此之前,您可能会发现问题的根源。 If not, we're still here to help (even more). 如果没有,我们仍然会在这里提供帮助(甚至更多)。


See also: 也可以看看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM