malsyned / pfstest

Professional Firmware Services Unit Test Framework
Other
1 stars 0 forks source link

Support for capturing mock arguments #55

Closed malsyned closed 6 years ago

malsyned commented 6 years ago

Sometimes it's important that the same argument be passed to multiple calls, but it's not important what the argument is (such as a pointer to a stack variable, that sort of thing).

In those cases, it would be nice to be able to say something like:

uint8_t *ptr;
when(mock_init, capture_arg(&ptr));
verify(when(mock_next_step(arg_that(is(the_pointer(ptr))))));
malsyned commented 6 years ago

capture_arg could expand to a macro which invokes sizeof(*(arg)) and passes it into a system that uses memcpy to capture the arg.

malsyned commented 6 years ago

I developed this pretty far along, then ran into a problem. Everything comes in to a mock invocation as the_pointer, and loses information about whether it's been indirected or not. As a result, there's no way currently to tell whether an actual value should have its pointer copied or the data it points to.

Here is a patch for how far I got on it before running into this problem.

issue-55-capture_arg.patch.txt

automock.py knows the answer to this question, and I could devise a way for it to store it somewhere that capture_arg_matched could get at it. One idea that occurred to me right away was to use the_memory/sizeof on primitive arguments and the_pointer on pointers, and do the usual size == 0 test to determine whether we have a pointer or a boxed primitive on our hands.

malsyned commented 6 years ago

Fixed by modifying automock as described in the previous comment.