0

I am having a problem with unit tests failing randomly with seg faults and I cant figure out how to generate core dumps from those tests.

I am using cmake and ctest 3.21.1 to run those tests, and the tests are written using the gtest framework.

I dont believe it is a problem with the environment of my system, I can make a small c++ program that segfaults and generate a core dump. The problem is generating core dumps from tests ran using ctest.

  • If you can trigger the same error running the same test through a debugger, you might get to a solution quicker. – user4581301 Mar 03 '22 at 22:37
  • There are numerous ways that your test framework or the system or your programs themselves (via system calls) or something else may have disabled core dumps. And the way to reverse that, either temporarily or permanently, differs with each. – Peter Mar 03 '22 at 22:44
  • core dumps are going to be distro specific. This is much more of a linux question then it is a C++ question. FWIW, i get core dumps from google test all the time. – Taekahn Mar 03 '22 at 22:48
  • 1
    check apport, ulimit, /var/crash or /var/spool/abrt/ depending on distro – stark Mar 03 '22 at 23:09
  • I ran "ulimit -c unlimited" in my Ubuntu 20 environment to get a core dump file when my UT crashed (abort). Then used gdb to analyze it. Thanks. – Santiago Villafuerte Sep 15 '22 at 17:42
  • Do you run unit tests under the same user as your small test program? – dmitri Oct 06 '22 at 00:42

1 Answers1

0

If GTest is the underlaying test framework, there is a GTest command line option that has helped on windows: MyTest.exe --gtest_catch_exceptions=0

Note: This doesn't answer the question about CTest. I haven't found a similar option for CTest.

Help info from GTest:

Assertion Behavior:
  --gtest_break_on_failure
      Turn assertion failures into debugger break-points.
  --gtest_throw_on_failure
      Turn assertion failures into C++ exceptions for use by an external
      test framework.
  --gtest_catch_exceptions=0
      Do not report exceptions as test failures. Instead, allow them
      to crash the program or throw a pop-up (on Windows).
Jason
  • 336
  • 2
  • 5