google / googletest

GoogleTest - Google Testing and Mocking Framework

Home Page:https://google.github.io/googletest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: StrictMock construction crashed when included in benchmark fixture

rikiwow opened this issue · comments

Describe the issue

If benchmark Fixture includes StrictMock class, running it will get Segmentation fault.
The crash seems happens when constructing StrictMock objects. Please check the gdb backtrace at the end.

Steps to reproduce the problem

#1. export compiler path and sysroot path
export OECORE_TARGET_SYSROOT=/fakepath/sdk-qemux86-64/tmp/sysroots/qemux86-64
export OECORE_NATIVE_SYSROOT=/fakepath/sdk-qemux86-64/tmp/sysroots/x86_64

#2. Build command:
${OECORE_NATIVE_SYSROOT}/usr/bin/x86_64-pc-linux-gnu-g++ --sysroot=${OECORE_TARGET_SYSROOT} -Wl,-rpath-link,${OECORE_TARGET_SYSROOT}/usr/lib64 -Wl,-rpath,${OECORE_TARGET_SYSROOT}/usr/lib64 -rdynamic -Wl,--dynamic-linker=${OECORE_TARGET_SYSROOT}/usr/lib64/ld-linux-x86-64.so.2 main.cpp -o gmockTest -rdynamic -L${OECORE_TARGET_SYSROOT}/usr/lib64 -L. -lgtest -lgmock -lpthread -lbenchmark

#3. run gmockTest built from step 2

Note: The compiler, google test and google benchmark are installed by using Yocto.

main.cpp:

#include "gmock/gmock.h"
#include <benchmark/benchmark.h>
using namespace testing;

class Foo {
public:
    virtual ~Foo() {}
    virtual void set() const = 0;
};

class MockFoo : public Foo {
    public:
        MOCK_METHOD(void, set, (), (const, override));
};

class TestBM: public benchmark::Fixture
{
    public:
        void SetUp(::benchmark::State& state) {
        }

        void TearDown(::benchmark::State& state) {
        }
        StrictMock<MockFoo> mock; //remove this line, testing pass
};

BENCHMARK_DEFINE_F(TestBM, TestcaseName)(benchmark::State& state)
{
    for (auto _ : state)
    {
        int sum = 0;
        for (int i=0; i< 100; i++)
            sum += i;
    }
}

BENCHMARK_REGISTER_F(TestBM, TestcaseName);

BENCHMARK_MAIN();

What version of GoogleTest are you using?

1.11.0

What operating system and version are you using?

Red Hat Enterprise Linux Server release 7.6 (Maipo)

What compiler and version are you using?

x86_64-pc-linux-gnu-g++ (GCC) 10.2.0

What build system are you using?

Yocto

Additional context

benchmark version: 1.6.1

gdb backtrace:

(gdb) bt
#0 0x00007ffff609bdee in std::_Rb_tree_decrement(std::_Rb_tree_node_base*) ()
from /fakepath/sdk-qemux86-64/tmp/sysroots/qemux86-64/usr/lib64/libstdc++.so.6
google/benchmark#1 0x0000000000736f0b in std::_Rb_tree_iterator<std::pair<void const* const, testing::internal::CallReaction> >::operator--() ()
google/benchmark#2 0x0000000000736e60 in std::_Rb_tree<void const*, std::pair<void const* const, testing::internal::CallReaction>, std::_Select1st<std::pair<void const* const, testing::internal::CallReaction> >, std::less<void const*>, std::allocator<std::pair<void const* const, testing::internal::CallReaction> > >::_M_get_insert_unique_pos(void const* const&) ()
google/benchmark#3 0x0000000000734fdb in std::_Rb_tree<void const*, std::pair<void const* const, testing::internal::CallReaction>, std::_Select1st<std::pair<void const* const, testing::internal::CallReaction> >, std::less<void const*>, std::allocator<std::pair<void const* const, testing::internal::CallReaction> > >::_M_get_insert_hint_unique_pos(std::_Rb_tree_const_iterator<std::pair<void const* const, testing::internal::CallReaction> >, void const* const&) ()
google/benchmark#4 0x0000000000733108 in std::_Rb_tree_iterator<std::pair<void const* const, testing::internal::CallReaction> > std::_Rb_tree<void const*, std::pair<void const* const, testing::internal::CallReaction>, std::_Select1st<std::pair<void const* const, testing::internal::CallReaction> >, std::less<void const*>, std::allocator<std::pair<void const* const, testing::internal::CallReaction> > >::_M_emplace_hint_unique<std::piecewise_construct_t const&, std::tuple<void const* const&>, std::tuple<> >(std::_Rb_tree_const_iterator<std::pair<void const* const, testing::internal::CallReaction> >, std::piecewise_construct_t const&, std::tuple<void const* const&>&&, std::tuple<>&&)
()
google/benchmark#5 0x0000000000730e10 in std::map<void const*, testing::internal::CallReaction, std::less<void const*>, std::allocator<std::pair<void const* const, testing::internal::CallReaction> > >::operator[](void const* const&) ()
google/benchmark#6 0x000000000072c0a3 in testing::(anonymous namespace)::SetReactionOnUninterestingCalls(void const*, testing::internal::CallReaction) ()
google/benchmark#7 0x000000000072c133 in testing::Mock::FailUninterestingCalls(void const*) ()
google/benchmark#8 0x0000000000663941 in TestBM_TestcaseName_Benchmark::TestBM_TestcaseName_Benchmark() ()
google/benchmark#9 0x00000000005b68e7 in _GLOBAL__sub_I_fake.cpp ()
google/benchmark#10 0x00007ffff5d24fee in __libc_start_main () from /fakepath/sdk-qemux86-64/tmp/sysroots/qemux86-64/usr/lib64/libc.so.6
google/benchmark#11 0x00000000005bc615 in _start ()