1

I am building unit tests with CMocka. My function char some_func(some_enum e) maps valid values of e to a char. It uses assert to check e is valid, which by definition calls abort if not.

Mocking abort is proving to be hard. Following this example and building a function ...

static volatile abort_calls = 0;

void 
__wrap_abort(void)
{
    fprintf(stderr, "Call to __wrap_abort()\n");
    abort_calls++;
}

static void
test_some_func(void **state)
{
    some_func( (some_enum)99);
    assert_int_equal(1, abort_calls);
}

.. that when compiled with -Wl,--wrap=abort makes no complaints. However, when executed it does not call __wrap_abort.

Is what I'm attempting even possible?

Martin Cowie
  • 2,788
  • 7
  • 38
  • 74
  • 1
    The wrap stuff is dangerous to use with `abort`. See this question and answer: https://stackoverflow.com/questions/39725138/strange-behaviour-while-wrapping-abort-system-call/39725443#39725443 – Art Sep 26 '17 at 13:43

0 Answers0