Segmentation Fault with parameterized tests on Linux (gtest 1.7 - gcc 4.8.1)

2,863 views
Skip to first unread message

Mike McNees

unread,
Feb 13, 2014, 7:18:20 PM2/13/14
to googletes...@googlegroups.com
Up until now we have been building our unit tests using Visual Studio and gcc using MinGw on Windows. We have now built a Linux (Ubuntu) box as an additional build agent and when we build and run the unit tests all of the tests that have parameterized tests finish with a Segmentation Fault. Below is an example:

Running main() from gtest_main.cc
[==========] Running 2 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 2 tests from CharTypes/FooTest
[ RUN      ] CharTypes/FooTest.DoesBlah/0
[       OK ] CharTypes/FooTest.DoesBlah/0 (0 ms)
[ RUN      ] CharTypes/FooTest.DoesBlah/1
[       OK ] CharTypes/FooTest.DoesBlah/1 (0 ms)
[----------] 2 tests from CharTypes/FooTest (0 ms total)

[----------] Global test environment tear-down
[==========] 2 tests from 1 test case ran. (0 ms total)
[  PASSED  ] 2 tests.
Segmentation fault (core dumped)

The xml file produced looks correct so far, the results look correct but the segmentation fault is not good. We use ctest to run all of the unit tests and it detects the segfault and fails the build.

Running tests...
Test project /opt/builds/b20d41c8bd14fb14/UnitTests/build/gcc
    Start 1: RollGridTests
1/5 Test #1: RollGridTests ....................   Passed    0.05 sec
    Start 2: EncoderTests
2/5 Test #2: EncoderTests .....................***Exception: SegFault  0.24 sec
    Start 3: LaserConfigTests
3/5 Test #3: LaserConfigTests .................   Passed    0.06 sec
    Start 4: StatusTests
4/5 Test #4: StatusTests ......................   Passed    0.03 sec
    Start 5: StatisticsTests
5/5 Test #5: StatisticsTests ..................   Passed    0.03 sec

80% tests passed, 1 tests failed out of 5

Total Test time (real) =   0.45 sec

The following tests FAILED:
      2 - EncoderTests (SEGFAULT)
Errors while running CTest
make: *** [test] Error 8


 Anyone seen this or know how to fix it?

Billy Donahue

unread,
Feb 13, 2014, 7:31:26 PM2/13/14
to Mike McNees, Google C++ Testing Framework
Because you're crashing at the end of the program, maybe you're using a static variable after it has been destroyed.
Like you have a destructor for one static duration object using another static duration object. Something like that.
Start with a debugger. Figure out where that segfault is being thrown.



--
 
---
You received this message because you are subscribed to the Google Groups "Google C++ Testing Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframe...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Mike McNees

unread,
Feb 14, 2014, 12:29:41 PM2/14/14
to googletes...@googlegroups.com, Mike McNees
I've made a small test file that will let me reproduce the problem. Here is the code:

#ifndef UNIT_TESTING
#define UNIT_TESTING
#endif

#include "gtest/gtest.h"

class FooTest:public ::testing::TestWithParam<uint32_t>
{

};

INSTANTIATE_TEST_CASE_P(CharTypes, FooTest, ::testing::Range(1u, 3u));

TEST_P(FooTest, DoesBlah)
{
    EXPECT_EQ(GetParam(), GetParam());
}

I don't have any variables, no statics, but it seg faults on exit. I'm not very experienced at debugging on Linux, but I rebuilt the test with symbols and loaded it up in ddd. I run through and see the following at the end:

Program received signal SIGSEGV, Segmentation fault.
0x08171f33 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() ()
(gdb) break /opt/builds/b20d41c8bd14fb14/UnitTests/tests/perception/3DLaser/Linux/EncoderTests.cpp:8
Breakpoint 1 at 0x80b53c2: file /opt/builds/b20d41c8bd14fb14/UnitTests/tests/perception/3DLaser/Linux/EncoderTests.cpp, line 8.

The backtrace looks like this:

#0  0x08171f33 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() ()
#1  0x081322c5 in void std::_Destroy<std::string>(std::string*) () at /usr/include/c++/4.8/bits/stl_construct.h:93
#2  0x0812ed88 in void std::_Destroy_aux<false>::__destroy<std::string*>(std::string*, std::string*) () at /usr/include/c++/4.8/bits/stl_construct.h:103
#3  0x08128843 in void std::_Destroy<std::string*>(std::string*, std::string*) () at /usr/include/c++/4.8/bits/stl_construct.h:126
#4  0x08120952 in void std::_Destroy<std::string*, std::string>(std::string*, std::string*, std::allocator<std::string>&) () at /usr/include/c++/4.8/bits/stl_construct.h:151
#5  0x08114712 in std::vector<std::string, std::allocator<std::string> >::~vector() () at /usr/include/c++/4.8/bits/stl_vector.h:415
#6  0xb7e52f51 in ?? () from /lib/i386-linux-gnu/libc.so.6
#7  0xb7e52fdd in exit () from /lib/i386-linux-gnu/libc.so.6
#8  0xb7e394db in __libc_start_main () from /lib/i386-linux-gnu/libc.so.6
#9  0x080b52d5 in _start ()

I trace through and can see it return from RUN_ALL_TESTS() with no problems that I can see. Any tips or pointers of where I might look to progress?


Billy Donahue

unread,
Feb 14, 2014, 2:49:47 PM2/14/14
to Mike McNees, Google C++ Testing Framework
Wow. That's deep. It's probably some library you're linking with. Let's see the BUILD rule. Can you get the name of the static duration string that was being destroyed when you crash? That's a clue.



Mike McNees

unread,
May 29, 2014, 6:46:08 PM5/29/14
to googletes...@googlegroups.com, mmc...@gmail.com
After beating my head on this I gave up for a while. The problem started causing more problems today and so I started messing with it again. I spent time debugging and checking my cmake files. While doing this I zeroed in on gtest_disable_pthreads which was set to on since I was building on windows. Once I set it to off there was no more segmentation fault. Go figure. ;)
Reply all
Reply to author
Forward
0 new messages