kunit: print the mock function and input parameters in the failure message of EXPECT_CALL. To store the mock function and its input, we add a new field to the mock_expectation. The change in include/test/mock.h is brought from Google-Bug-Id(113269240#4, by Daniel Latypov). Google-Bug-Id: 113269240 Signed-off-by: Lin Xinan <linxinan@google.com> Change-Id: Ia4aaa0c1c4125c7c3205c15eeaa9c6000063642f
diff --git a/include/test/mock.h b/include/test/mock.h index e599d21..1796adc 100644 --- a/include/test/mock.h +++ b/include/test/mock.h
@@ -87,6 +87,7 @@ struct mock_expectation { int times_called; const char *file_name; int line_no; + const char* expectation_text; /* internal list of prerequisites */ struct list_head prerequisites; }; @@ -261,15 +262,18 @@ static inline bool is_naggy_mock(struct mock *mock) * allowing additional conditions and actions to be specified. */ #define EXPECT_CALL(expectation_call) \ - expect_call_wrapper(__FILE__, __LINE__, mock_master_##expectation_call) + expect_call_wrapper(__FILE__, __LINE__, \ + #expectation_call, mock_master_##expectation_call) static inline struct mock_expectation *expect_call_wrapper( const char *file_name, int line_no, + const char* expectation_text, struct mock_expectation *expectation) { expectation->file_name = file_name; expectation->line_no = line_no; + expectation->expectation_text = expectation_text; return expectation; }
diff --git a/test/mock.c b/test/mock.c index 7dc9576..ca8aedb 100644 --- a/test/mock.c +++ b/test/mock.c
@@ -459,7 +459,8 @@ static struct mock_expectation *mock_apply_expectations( expectations_all_saturated = false; attempted_matching_stream->add(attempted_matching_stream, - "Tried expectation: %s, but\n", ret->expectation_name); + "Tried expectation: %s at %s:%d, but\n", + ret->expectation_text, ret->file_name, ret->line_no); if (does_mock_expectation_match_call(ret, attempted_matching_stream, params, len)) { /*