Criterion icon indicating copy to clipboard operation
Criterion copied to clipboard

Skipping a signal test is marked as an error

Open COLAMAroro opened this issue 5 years ago • 3 comments

Criterion version: 2.3.3 OS: Fedora 30 Compiler: GCC 9.2.1

#include <criterion/criterion.h>
#include <signal.h>
#include <string.h>

static void skip(void)
{
    cr_skip_test("Minimal skip");
}

TestSuite(c, .init=skip);

Test(c, should_skip, .signal=SIGSEGV)
{
    strlen(NULL);
}

Test(c, should_skip_too)
{
    cr_assert(1);
}

Excepted behaviour: Either both test skipping (if a skip is allowed in a TestSuite init), or both should be valid (if it's not allowed) Actual behaviour:

[0][cola@FedoKeon]%->gcc minimal_error.c -lcriterion                                                             
[0][cola@FedoKeon]%->./a.out --verbose                                                                           
[----] Criterion v2.3.3
[====] Running 2 tests from c:
[RUN ] c::should_skip
[FAIL] c::should_skip: (0,00s)
[RUN ] c::should_skip_too
[SKIP] c::should_skip_too: Minimal skip
[====] Synthesis: Tested: 1 | Passing: 0 | Failing: 1 | Crashing: 0

COLAMAroro avatar Feb 22 '20 10:02 COLAMAroro

Yeah, that happens due to the way that exit status get validated: skipping a test makes the test exit with status 0, while c::should_skip expects to die with SIGSEGV.

I'd need to add an edge-case to ignore the exit status if the test was skipped.

Snaipe avatar Mar 10 '20 16:03 Snaipe

I tried fixing it on my own (but sadly failed), but why not exit with attended value ? If a test want the exit code to be 3, a skip would exit with code 3

COLAMAroro avatar May 25 '20 14:05 COLAMAroro

why not exit with attended value ? If a test want the exit code to be 3, a skip would exit with code 3

It's dicier than that because the skip would need to also kill() the current process with the expected signal, and even then it wouldn't be able to lie to the parent on the circumstances where this happened. Overall, I think it's bad form over just handling the corner case correctly.

I'll look at whether this can be easily fixed, but immersing myself in that part of the code has been fairly challenging over the last couple of days.

Snaipe avatar Jan 03 '22 17:01 Snaipe