Hello,
I am trying to understand how Cucumber C++ behaves when the execution of the definition of a step yields a segmentation fault.
Let's say I have the following feature file:
Feature: Understanding a segmentation fault
Scenario: we have a problem here
Given We have a segmentation fault
Then I think we should not be here
Whose steps are defined as:
#include <boost/test/unit_test.hpp>
#include <cucumber-cpp/defs.hpp>
GIVEN("^We have a segmentation fault$") {
int *pointer = NULL;
*pointer = 42;
}
THEN("^I think we should not be here$") {
BOOST_CHECK(true); // should not be executed?
}
Since the first step yields a segmentation fault, i thought the second one would not be executed. However:
./steps & cucumber features/seg_fault.feature
Feature: Understanding a segmentation fault
Scenario: we have a problem here # features/seg_fault.feature:2
Given We have a segmentation fault # steps.cpp:4
Then I think we should not be here # steps.cpp:9
1 scenario (1 passed)
2 steps (2 passed)
I have compiled the steps definitions with -O0 to avoid optimizations which could remove the code yielding the segmentation fault.
Moreover, I tried running the tests with gdb; weirdly:
gdb steps
...
(gdb) handle SIGSEGV nostop (so that gdb does not catch the signal)
Signal Stop Print Pass to program Description
SIGSEGV No Yes Yes Segmentation fault
(gdb) run
Starting program: /path/to/steps
[Thread debugging using libthread_db enabled]
(Here I run cucumber in another terminal)
Program received signal SIGSEGV, Segmentation fault.
Program terminated with signal SIGSEGV, Segmentation fault.
The program no longer exists.
And cucumber's output:
cucumber features/seg_fault.feature
Feature: Understanding a segmentation fault
Scenario: we have a problem here # features/seg_fault.feature:2
Given We have a segmentation fault # steps.cpp:4
Remote Socket with localhost:3902 closed. (Cucumber::WireSupport::WireException)
features/seg_fault.feature:3:in 'Given We have a segmentation fault'
Broken pipe (Errno::EPIPE)
(cucumber backtrace follows)
I tried taking a look at the code, but I didn't manage to understand how Cucumber C++ handles these cases neither why does running with gdb give a different result.
Could somebody enlighten me about this issue?
Thanks in advance.
Regards,
Felipe Musse