kunit: introduce class mocking support.
Subsystems (3)
v2 cover kunit: introduce class mocking support.
# Background
KUnit currently lacks any first-class support for mocking. For an overview and discussion on the pros and cons, see
https://martinfowler.com/articles/mocksArentStubs.html
This patch set introduces the basic machinery needed for mocking:
setting and validating expectations, setting default actions, etc.
Using that basic infrastructure, we add macros for "class mocking", as it's probably the easiest type of mocking to start with.
## Class mocking
By "class mocking", we're referring mocking out function pointers stored in structs like:
struct sender {
int (*send)(struct sender *sender, int data); };
or in ops structs
struct sender {
struct send_ops *ops; // contains send
};
After the necessary DEFINE_* macros, we can then write code like
struct MOCK(sender) mock_sender = CONSTRUCT_MOCK(sender, test);
/* Fake an error for a specific input. */ handle = KUNIT_EXPECT_CALL(send(<omitted>, kunit_int_eq(42))); handle->action = kunit_int_return(test, -EINVAL);
/* Pass the mocked object to some code under test. */ KUNIT_EXPECT_EQ(test, -EINVAL, send_message(...));
I.e. the goal is to make it easier to test
1) with less dependencies (we don't need to setup a real sender)
2) unusual/error conditions more easily.
In the future, we hope to build upon this to support mocking in more contexts, e.g. standalone funcs, etc.
# TODOs
## Naming
This introduces a number of new macros for dealing with mocks, e.g:
DEFINE_STRUCT_CLASS_MOCK(METHOD(foo), CLASS(example),
RETURNS(int),
PARAMS(struct example *, int)); ...
KUNIT_EXPECT_CALL(foo(mock_get_ctrl(mock_example), ...);
For consistency, we could prefix everything with KUNIT, e.g. KUNIT_DEFINE_STRUCT_CLASS_MOCK and kunit_mock_get_ctrl, but it feels like the names might be long enough that they would hinder readability.
## Usage
For now the only use of class mocking is in kunit-example-test.c As part of changing this from an RFC to a real patch set, we're hoping to include at least one example.
Pointers to bits of code where this would be useful that aren't too hairy would be appreciated.
E.g. could easily add a test for tools/perf/ui/progress.h, e.g. that ui_progress__init() calls ui_progress_ops.init(), but that likely isn't useful to anyone.
---
v2:
* Pass struct kunit * to mock init's to allow allocating ops structs.
* Update kunit-example-test.cc to do so as a more realistic example.
v1: https://lore.kernel.org/linux-kselftest/[email protected]/
---
Brendan Higgins (9):
kunit: test: add kunit_stream a std::stream like logger
kunit: test: add concept of post conditions
checkpatch: add support for struct MOCK(foo) syntax
kunit: mock: add parameter list manipulation macros
kunit: mock: add internal mock infrastructure
kunit: mock: add basic matchers and actions
kunit: mock: add class mocking support
kunit: mock: add struct param matcher
kunit: mock: implement nice, strict and naggy mock distinctions
Daniel Latypov (2):
Revert "kunit: move string-stream.h to lib/kunit"
kunit: expose kunit_set_failure() for use by mocking
Marcelo Schmitt (1):
kunit: mock: add macro machinery to pick correct format args
include/kunit/assert.h | 3 +-
include/kunit/kunit-stream.h | 94 +++
include/kunit/mock.h | 902 +++++++++++++++++++++++++
include/kunit/params.h | 305 +++++++++
{lib => include}/kunit/string-stream.h | 2 +
include/kunit/test.h | 9 +
lib/kunit/Makefile | 9 +-
lib/kunit/assert.c | 2 -
lib/kunit/common-mocks.c | 409 +++++++++++
lib/kunit/kunit-example-test.c | 98 +++
lib/kunit/kunit-stream.c | 110 +++
lib/kunit/mock-macro-test.c | 241 +++++++
lib/kunit/mock-test.c | 531 +++++++++++++++
lib/kunit/mock.c | 370 ++++++++++
lib/kunit/string-stream-test.c | 3 +-
lib/kunit/string-stream.c | 5 +-
lib/kunit/test.c | 15 +-
scripts/checkpatch.pl | 4 +
18 files changed, 3099 insertions(+), 13 deletions(-)
create mode 100644 include/kunit/kunit-stream.h
create mode 100644 include/kunit/mock.h
create mode 100644 include/kunit/params.h
rename {lib => include}/kunit/string-stream.h (95%)
create mode 100644 lib/kunit/common-mocks.c
create mode 100644 lib/kunit/kunit-stream.c
create mode 100644 lib/kunit/mock-macro-test.c
create mode 100644 lib/kunit/mock-test.c
create mode 100644 lib/kunit/mock.cbase-commit: 10b82d5176488acee2820e5a2cf0f2ec5c3488b6
Signature · 1 line
2.28.0.1011.ga647a8990f-goog
RFC v2 1/12 Revert "kunit: move string-stream.h to lib/kunit"
This reverts commit 109fb06fdc6f6788df7dfbc235f7636a38e28fd4.
string-stream will be used by kunit mocking code to print messages about mock expectations.
It makes the code signifcantly simpler if string-stream objects can be part of structs declared in mocking headers.
---
include/kunit/assert.h | 3 +--
{lib => include}/kunit/string-stream.h | 0
lib/kunit/assert.c | 2 --
lib/kunit/string-stream-test.c | 3 +--
lib/kunit/string-stream.c | 3 +--
lib/kunit/test.c | 2 +-
6 files changed, 4 insertions(+), 9 deletions(-)
rename {lib => include}/kunit/string-stream.h (100%)include/kunit/assert.h +1 -2
@@ -9,11 +9,10 @@#ifndef _KUNIT_ASSERT_H#define _KUNIT_ASSERT_H +#include <kunit/string-stream.h> #include <linux/err.h> -#include <linux/kernel.h> struct kunit ; -struct string_stream ;/** * enum kunit_assert_type - Type of expectation/assertion.
include/kunit/string-stream.h renamed from lib/kunit/string-stream.h +0 -0
lib/kunit/assert.c +0 -2
@@ -8,8 +8,6 @@#include <kunit/assert.h> #include <kunit/test.h> -#include "string-stream.h" -void kunit_base_assert_format (const struct kunit_assert *assert,struct string_stream *stream) {
lib/kunit/string-stream-test.c +1 -2
@@ -6,11 +6,10 @@* Author: Brendan Higgins <[email protected]> */ +#include <kunit/string-stream.h> #include <kunit/test.h> #include <linux/slab.h> -#include "string-stream.h" -static void string_stream_test_empty_on_creation (struct kunit *test) {struct string_stream *stream =alloc_string_stream (test,GFP_KERNEL );
lib/kunit/string-stream.c +1 -2
@@ -6,12 +6,11 @@* Author: Brendan Higgins <[email protected]> */ +#include <kunit/string-stream.h> #include <kunit/test.h> #include <linux/list.h> #include <linux/slab.h> -#include "string-stream.h" -struct string_stream_fragment_alloc_context {struct kunit *test;int len;
lib/kunit/test.c +1 -1
@@ -7,12 +7,12 @@*/ #include <kunit/test.h> +#include <kunit/string-stream.h> #include <linux/kernel.h> #include <linux/kref.h> #include <linux/sched/debug.h> #include "debugfs.h" -#include "string-stream.h" #include "try-catch-impl.h" static void kunit_set_failure (struct kunit *test)
Signature · 1 line
2.28.0.1011.ga647a8990f-goog
kernel test robot
build botRe: [RFC v2 01/12] Revert "kunit: move string-stream.h to lib/kunit"
reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # install arm64 cross compiling tool for…
Hi Daniel,
[FYI, it's a private test report for your RFC patch.] [auto build test ERROR on 10b82d5176488acee2820e5a2cf0f2ec5c3488b6]
url: https://github.com/0day-ci/linux/commits/Daniel-Latypov/kunit-introduce-class-mocking-support/20201013-062218 base: 10b82d5176488acee2820e5a2cf0f2ec5c3488b6 config: arm64-randconfig-r003-20201012 (attached as .config) compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project a324d8f964bf421fa7d8b882b0f64ead28c4149c)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# https://github.com/0day-ci/linux/commit/d69578f4d0c866b86936aace570ecc5cc7f4c505
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Daniel-Latypov/kunit-introduce-class-mocking-support/20201013-062218 git checkout d69578f4d0c866b86936aace570ecc5cc7f4c505
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> lib/kunit/debugfs.c:12:10: fatal error: 'string-stream.h' file not found
#include "string-stream.h"
^~~~~~~~~~~~~~~~~1 error generated.
vim +12 lib/kunit/debugfs.c
e2219db280e3fe Alan Maguire 2020-03-26 11e2219db280e3fe Alan Maguire 2020-03-26 @12 #include "string-stream.h" e2219db280e3fe Alan Maguire 2020-03-26 13
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
RFC v2 2/12 kunit: test: add kunit_stream a std::stream like logger
In reply to Daniel LatypovFrom: Brendan Higgins <[email protected]>
A lot of the expectation and assertion infrastructure prints out fairly complicated test failure messages, so add a C++ style log library for for logging test results called struct kunit_stream.
kunit_stream allows us to construct a message before we know whether we want to print it out; this can be extremely handy if there is information you might need for a failure message that is easiest to collect in the steps leading up to the actual check.
Note that kunit_stream is distinct from string_stream: whereas string_stream is really just a string builder, kunit_stream is specifically used for constructing expectation/assertion (introduced later in this series) messages to a user of KUnit.
Patch was previously reviewed at
https://lore.kernel.org/linux-fsdevel/[email protected]/
Primary differences are
* kunit/ => lib/kunit/
* re-expose string_stream_clear(), which was made static since then
--- include/kunit/kunit-stream.h | 94 +++++++++++++++++++++++++++++ include/kunit/string-stream.h | 2 + include/kunit/test.h | 1 + lib/kunit/Makefile | 1 + lib/kunit/kunit-stream.c | 110 ++++++++++++++++++++++++++++++++++ lib/kunit/string-stream.c | 2 +- 6 files changed, 209 insertions(+), 1 deletion(-) create mode 100644 include/kunit/kunit-stream.h create mode 100644 lib/kunit/kunit-stream.c
include/kunit/kunit-stream.h new file +94 -0
@@ -0,0 +1,94 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* C++ stream style string formatter and printer used in KUnit for outputting +* KUnit messages. +* +* Copyright (C) 2020, Google LLC. +* Author: Brendan Higgins <[email protected]> +*/ + +#ifndef _KUNIT_KUNIT_STREAM_H +#define _KUNIT_KUNIT_STREAM_H + +#include <linux/types.h> +#include <kunit/string-stream.h> + +struct kunit ; + +/** +* struct kunit_stream - a std::stream style string builder. +* +* A std::stream style string builder. Allows messages to be built up and +* printed all at once. Note that the intention is to only use +* &struct kunit_stream to communicate with a user of KUnit, most often to +* communicate something about an expectation or an assertion to the user. If +* you want a similar interface, but aren't sure if this is the right class for +* you to use, you probably want to use the related string_stream class, which +* is allowed for generic string construction in a similar manner. This class is +* really only for the KUnit library to communicate certain kinds of information +* to KUnit users and should not be used by anyone else. +* +* A note on &struct kunit_stream's usage: a kunit_stream will generally +* accompany *one* expectation or assertion. Multiple expectations/assertions +* may be validated concurrently at any given time, even within a single test +* case, so sharing a kunit_stream between expectations/assertions may result in +* unintended consequences. +*/ +struct kunit_stream { +/* private: internal use only. */ +struct kunit *test; +struct string_stream *internal_stream; +}; + +/** +* alloc_kunit_stream() - constructs a new &struct kunit_stream. +* @test: The test context object. +* @gfp: The GFP flags to use for internal allocations. +* +* Constructs a new test managed &struct kunit_stream. +*/ +struct kunit_stream *alloc_kunit_stream (struct kunit *test, +gfp_t gfp); + +/** +* kunit_stream_add(): adds the formatted input to the internal buffer. +* @kstream: the stream being operated on. +* @fmt: printf style format string to append to stream. +* +* Appends the formatted string, @fmt, to the internal buffer. +*/ +void __printf(2, 3) kunit_stream_add(struct kunit_stream *kstream, + const char *fmt, ...); + +/** + * kunit_stream_append(): appends the contents of @other to @kstream. + * @kstream: the stream to which @other is appended. + * @other: the stream whose contents are appended to @kstream. + * + * Appends the contents of @other to @kstream. + */ +void kunit_stream_append(struct kunit_stream *kstream, + struct kunit_stream *other); + +/** + * kunit_stream_commit(): prints out the internal buffer to the user. + * @kstream: the stream being operated on. + * + * Outputs the contents of the internal buffer as a kunit_printk formatted + * output. KUNIT_STREAM ONLY OUTPUTS ITS BUFFER TO THE USER IF COMMIT IS + * CALLED!!! The reason for this is that it allows us to construct a message + * before we know whether we want to print it out; this can be extremely handy + * if there is information you might need for a failure message that is easiest + * to collect in the steps leading up to the actual check. + */ +void kunit_stream_commit(struct kunit_stream *kstream); + +/** + * kunit_stream_clear(): clears the internal buffer. + * @kstream: the stream being operated on. + * + * Clears the contents of the internal buffer. + */ +void kunit_stream_clear(struct kunit_stream *kstream); + +#endif /* _KUNIT_KUNIT_STREAM_H */
include/kunit/string-stream.h +2 -0
@@ -46,6 +46,8 @@ int string_stream_append(struct string_stream *stream,bool string_stream_is_empty (struct string_stream *stream); +void string_stream_clear (struct string_stream *stream); +int string_stream_destroy (struct string_stream *stream);#endif /* _KUNIT_STRING_STREAM_H */
include/kunit/test.h +1 -0
@@ -10,6 +10,7 @@#define _KUNIT_TEST_H#include <kunit/assert.h> +#include <kunit/kunit-stream.h> #include <kunit/try-catch.h> #include <linux/kernel.h> #include <linux/module.h>
lib/kunit/Makefile +1 -0
@@ -3,6 +3,7 @@ obj-$(CONFIG_KUNIT) += kunit.o kunit-objs += test.o \ string-stream.o \ assert.o \ + kunit-stream.o \ try-catch.o ifeq ($(CONFIG_KUNIT_DEBUGFS),y)
lib/kunit/kunit-stream.c new file +110 -0
110 lines not on this page · raw message
lib/kunit/string-stream.c +1 -1
@@ -112,7 +112,7 @@ int string_stream_add(struct string_stream *stream, const char *fmt, ...)return result; } -static void string_stream_clear (struct string_stream *stream) +void string_stream_clear (struct string_stream *stream) {struct string_stream_fragment *frag_container, *frag_container_safe;
Signature · 1 line
2.28.0.1011.ga647a8990f-goog
RFC v2 3/12 kunit: test: add concept of post conditions
In reply to Daniel LatypovFrom: Brendan Higgins <[email protected]>
Add a way to specify that certain conditions must be met at the end of a test case.
--- include/kunit/test.h | 6 ++++++ lib/kunit/test.c | 11 +++++++++++ 2 files changed, 17 insertions(+)
include/kunit/test.h +6 -0
@@ -190,6 +190,11 @@ struct kunit_suite {char *log; }; +struct kunit_post_condition { +struct list_head node; +void (*validate)(struct kunit_post_condition *condition); +}; +/** * struct kunit - represents a running instance of a test. *
@@ -223,6 +228,7 @@ struct kunit {* protect it with some type of lock. */ struct list_head resources;/* Protected by lock. */ +struct list_head post_conditions; };void kunit_init_test (struct kunit *test,const char *name,char *log);
lib/kunit/test.c +11 -0
@@ -228,6 +228,7 @@ void kunit_init_test(struct kunit *test, const char *name, char *log) {spin_lock_init (&test->lock);INIT_LIST_HEAD (&test->resources); +INIT_LIST_HEAD (&test->post_conditions); test->name = name; test->log = log;if (test->log)
@@ -269,6 +270,16 @@ static void kunit_case_internal_cleanup(struct kunit *test)static void kunit_run_case_cleanup (struct kunit *test,struct kunit_suite *suite) { +struct kunit_post_condition *condition, *condition_safe; + +list_for_each_entry_safe (condition, + condition_safe, + &test->post_conditions, + node) { + condition->validate (condition); +list_del (&condition->node); + } +if (suite->exit) suite->exit (test);
Signature · 1 line
2.28.0.1011.ga647a8990f-goog
RFC v2 4/12 checkpatch: add support for struct MOCK(foo) syntax
In reply to Daniel LatypovFrom: Brendan Higgins <[email protected]>
KUnit will soon add macros for generating mocks from types, the generated mock types are named like struct MOCK(foo) (where the base type is struct foo).
Add struct MOCK(foo) as a NonptrType so that it is recognized correctly in declarations.
--- scripts/checkpatch.pl | 4 ++++ 1 file changed, 4 insertions(+)
scripts/checkpatch.pl +4 -0
@@ -796,6 +796,10 @@ sub build_types { (?: (?:typeof|__typeof__)\s*\([^\)]*\)| (?:$typeTypedefs\b)| + # Matching a \b breaks struct MOCK(foo) syntax, + # so we need to have it not lumped in with the + # types in @typeList. + (?:struct\s+MOCK\($Ident\))| (?:${all}\b) ) (?:\s+$Modifier|\s+const)*
Signature · 1 line
2.28.0.1011.ga647a8990f-goog
RFC v2 5/12 kunit: mock: add parameter list manipulation macros
In reply to Daniel LatypovFrom: Brendan Higgins <[email protected]>
Add macros for parsing and manipulating parameter lists needed for generating mocks.
--- include/kunit/params.h | 305 ++++++++++++++++++++++++++++++++++++ lib/kunit/Makefile | 3 +- lib/kunit/mock-macro-test.c | 150 ++++++++++++++++++ 3 files changed, 457 insertions(+), 1 deletion(-) create mode 100644 include/kunit/params.h create mode 100644 lib/kunit/mock-macro-test.c
include/kunit/params.h new file +305 -0
@@ -0,0 +1,305 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Macros for parsing and manipulating parameter lists needed for generating +* mocks. +* +* Copyright (C) 2020, Google LLC. +* Author: Brendan Higgins <[email protected]> +*/ + +#ifndef _KUNIT_PARAMS_H +#define _KUNIT_PARAMS_H + +#define NUM_VA_ARGS_IMPL (__dummy, \ + __1, \ + __2, \ + __3, \ + __4, \ + __5, \ + __6, \ + __7, \ + __8, \ + __9, \ + __10, \ + __11, \ + __12, \ + __13, \ + __14, \ + __15, \ + __16, \ + __nargs, args...) __nargs + +#define NUM_VA_ARGS(args...) NUM_VA_ARGS_IMPL(__dummy, ##args, \ + 16, \ + 15, \ + 14, \ + 13, \ + 12, \ + 11, \ + 10, \ + 9, \ + 8, \ + 7, \ + 6, \ + 5, \ + 4, \ + 3, \ + 2, \ + 1, \ + 0) + +#define CONCAT_INTERNAL (left, right) left##right +#define CONCAT (left, right) CONCAT_INTERNAL(left, right) + +#define EMPTY () + +/* +* Takes the name of a function style macro such as FOO() and prevents it from +* being evaluated on the current pass. +* +* This is useful when you need to write a "recursive" macro since a macro name +* becomes painted after it is pasted. If a different macro is pasted, this +* different macro won't be pasted; if we then defer the evaluation of the this +* "indirection macro", we can prevent the original definition from getting +* painted. +* +* Example: +* #define EXAMPLE EXPAND(FOO()) // FOO() is evaluated on 1st pass. +* #define EXAMPLE EXPAND(DEFER(FOO)()) // FOO() is evaluated on the second +* // pass. +*/ +#define DEFER (macro_id) macro_id EMPTY() + +/* +* Takes the name of a function style macro such as FOO() and prevents it from +* being evaluated on the current or following pass. +* +* This is useful when you need to DEFER inside an operation which causes an +* extra pass, like IF. +* +* Example: +* #define EXAMPLE EXPAND(FOO()) // FOO() is evaluated on 1st pass. +* #define EXAMPLE EXPAND(DEFER(FOO)()) // FOO() is evaluated on the second +* // pass. +* #define EXAMPLE EXPAND(OBSTRUCT(FOO)()) // FOO() is evaluated on the third +* // pass. +*/ +#define OBSTRUCT (macro_id) macro_id DEFER(EMPTY)() + +#define EXPAND_1(args...) args +#define EXPAND_2(args...) EXPAND_1(EXPAND_1(args)) +#define EXPAND_4(args...) EXPAND_2(EXPAND_2(args)) +#define EXPAND_8(args...) EXPAND_4(EXPAND_4(args)) +#define EXPAND_16(args...) EXPAND_8(EXPAND_8(args)) + +/* +* Causes multiple evaluation passes of a macro. +* +* CPP is implemented as a push down automaton. It consumes a stream of tokens +* and as it comes across macros, it either evaluates them and pastes the +* result, or if the macro is a function macro, it pushes the macro to a stack, +* it evaluates the input to the function macro, pops the state from the stack +* and continues. +* +* This macro serves the function of making the cursor return to the beginging +* of a macro that requires mulitple passes to evaluate. It is most useful when +* used with DEFER(...) and OBSTRUCT(...). +*/ +#define EXPAND(args...) EXPAND_16(args) + +#define INC (id) INC_##id +#define INC_0 1 +#define INC_1 2 +#define INC_2 3 +#define INC_3 4 +#define INC_4 5 +#define INC_5 6 +#define INC_6 7 +#define INC_7 8 +#define INC_8 9 +#define INC_9 10 +#define INC_10 11 +#define INC_11 12 +#define INC_12 13 +#define INC_13 14 +#define INC_14 15 +#define INC_15 16 +#define INC_16 17 + +#define DEC (id) DEC_##id +#define DEC_1 0 +#define DEC_2 1 +#define DEC_3 2 +#define DEC_4 3 +#define DEC_5 4 +#define DEC_6 5 +#define DEC_7 6 +#define DEC_8 7 +#define DEC_9 8 +#define DEC_10 9 +#define DEC_11 10 +#define DEC_12 11 +#define DEC_13 12 +#define DEC_14 13 +#define DEC_15 14 +#define DEC_16 15 + +#define DROP_FIRST_ARG_INTERNAL(dropped, x, args...) x +#define DROP_FIRST_ARG(args...) DROP_FIRST_ARG_INTERNAL(args) + +#define EQUAL (left, right) EQUAL_##left##_##right +#define EQUAL_0_0 dropped, 1 +#define EQUAL_1_1 dropped, 1 +#define EQUAL_2_2 dropped, 1 +#define EQUAL_3_3 dropped, 1 +#define EQUAL_4_4 dropped, 1 +#define EQUAL_5_5 dropped, 1 +#define EQUAL_6_6 dropped, 1 +#define EQUAL_7_7 dropped, 1 +#define EQUAL_8_8 dropped, 1 +#define EQUAL_9_9 dropped, 1 +#define EQUAL_10_10 dropped, 1 +#define EQUAL_11_11 dropped, 1 +#define EQUAL_12_12 dropped, 1 +#define EQUAL_13_13 dropped, 1 +#define EQUAL_14_14 dropped, 1 +#define EQUAL_15_15 dropped, 1 +#define EQUAL_16_16 dropped, 1 + +#define IS_EQUAL (left, right) DROP_FIRST_ARG(EQUAL(left, right), 0) + +#define NOT_INTERNAL (condition) NOT_##condition +#define NOT (condition) NOT_INTERNAL(condition) +#define NOT_0 1 +#define NOT_1 0 + +#define IS_NOT_EQUAL (left, right) NOT(IS_EQUAL(left, right)) + +#define EMPTY_IMPL (tokens) CONCAT(EMPTY_, tokens) +#define IS_EMPTY (tokens) + +#define OR_INTERNAL (left, right) OR_##left##_##right +#define OR (left, right) OR_INTERNAL(left, right) +#define OR_0_0 0 +#define OR_0_1 1 +#define OR_1_0 1 +#define OR_1_1 1 + +#define IF (condition) CONCAT(IF_, condition) +#define IF_0 (body) +#define IF_1 (body) body + +#define COMMA () , + +#define APPLY_TOKENS_INTERNAL (tokens, yield_token, seen_token) \ + IF(yield_token)(IF(seen_token)(COMMA()) tokens) +#define APPLY_TOKENS (tokens, yield_token, seen_token) \ + APPLY_TOKENS_INTERNAL(tokens, yield_token, seen_token) + +/* +* Provides the indirection to keep the PARAM_LIST_RECURSE_INTERNAL from getting +* pasted, only useful if used with DEFER(...) or OBSTRUCT(...). +*/ +#define PARAM_LIST_RECURSE_INDIRECT () PARAM_LIST_RECURSE_INTERNAL + +/* +* Given a starting index, a number of args, a MACRO to apply, and a list of +* types (with at least one element) this will call MACRO with the first type in +* the list and index; it will then call itself again on all remaining types, if +* any, while incrementing index, and decrementing nargs. +* +* Assumes nargs is the number of types in the list. +*/ +#define PARAM_LIST_RECURSE_INTERNAL (index, \ + nargs, \ +MACRO , \ +FILTER , \ + context, \ + seen_token, \ + type, \ + args...) \ + APPLY_TOKENS(MACRO(context, type, index), \ + FILTER(context, type, index), \ + seen_token) \ + IF(IS_NOT_EQUAL(nargs, 1)) \ + (OBSTRUCT(PARAM_LIST_RECURSE_INDIRECT)() \ + (INC(index), DEC(nargs), \ + MACRO, FILTER, context, \ + OR(seen_token, FILTER(context, type, index)), \ + args)) + +#define PARAM_LIST_RECURSE(index, nargs, MACRO, FILTER, context, args...) \ + IF(IS_NOT_EQUAL(nargs, 0)) \ + (OBSTRUCT(PARAM_LIST_RECURSE_INTERNAL)(index, \ + nargs, \ + MACRO, \ + FILTER, \ + context, \ + 0, \ + args)) + +#define FILTER_NONE (context, type, index) 1 + +#define FILTER_INDEX_INTERNAL (index_to_drop, type, index) \ + IS_NOT_EQUAL(index, index_to_drop) +#define FILTER_INDEX (index_to_drop, type, index) \ + FILTER_INDEX_INTERNAL(index_to_drop, type, index) + +/* +* Applies a MACRO which takes a type and the index of the type and outputs a +* sequence of tokens to a list of types. +*/ +#define FOR_EACH_PARAM(MACRO, FILTER, context, args...) \ + EXPAND(PARAM_LIST_RECURSE(0,\ + NUM_VA_ARGS(args),\ + MACRO,\ + FILTER,\ + context,\ + args)) + +#define PRODUCE_TYPE_AND_ARG (context, type, index) type arg##index +#define PARAM_LIST_FROM_TYPES(args...) \ + FOR_EACH_PARAM(PRODUCE_TYPE_AND_ARG, \ + FILTER_NONE, \ + not_used, \ + args) + +#define PRODUCE_TYPE_NAME (context, type, index) #type +#define TYPE_NAMES_FROM_TYPES(handle_index, args...) \ + FOR_EACH_PARAM(PRODUCE_TYPE_NAME, \ + FILTER_INDEX, \ + handle_index, \ + args) + +#define PRODUCE_PTR_TO_ARG (context, type, index) &arg##index +#define PTR_TO_ARG_FROM_TYPES(handle_index, args...) \ + FOR_EACH_PARAM(PRODUCE_PTR_TO_ARG, \ + FILTER_INDEX, \ + handle_index, \ + args) + +#define PRODUCE_MATCHER_AND_ARG (ctrl_index, type, index) \ + IF(IS_EQUAL(index, ctrl_index))(struct mock *arg##ctrl_index) \ + IF(IS_NOT_EQUAL(index, ctrl_index))( \ + struct mock_param_matcher *arg##index) +#define MATCHER_PARAM_LIST_FROM_TYPES(ctrl_index, args...) \ + FOR_EACH_PARAM(PRODUCE_MATCHER_AND_ARG, \ + FILTER_NONE, \ + ctrl_index, \ + args) + +#define PRODUCE_ARG (context, type, index) arg##index +#define ARG_NAMES_FROM_TYPES(ctrl_index, args...) \ + FOR_EACH_PARAM(PRODUCE_ARG, \ + FILTER_INDEX, \ + ctrl_index, \ + args) + +#define PRODUCE_ARRAY_ACCESSOR (context, type, index) *((type *) params[index]) +#define ARRAY_ACCESSORS_FROM_TYPES(args...) \ + FOR_EACH_PARAM(PRODUCE_ARRAY_ACCESSOR, \ + FILTER_NONE, \ + not_used, \ + args) + +#endif /* _KUNIT_PARAMS_H */
lib/kunit/Makefile +2 -1
@@ -10,7 +10,8 @@ ifeq ($(CONFIG_KUNIT_DEBUGFS),y) kunit-objs += debugfs.o endif -obj-$(CONFIG_KUNIT_TEST) += kunit-test.o +obj-$(CONFIG_KUNIT_TEST) += kunit-test.o \ + mock-macro-test.o # string-stream-test compiles built-in only. ifeq ($(CONFIG_KUNIT_TEST),y)
lib/kunit/mock-macro-test.c new file +150 -0
150 lines not on this page · raw message
Signature · 1 line
2.28.0.1011.ga647a8990f-goog
RFC v2 6/12 kunit: expose kunit_set_failure() for use by mocking
In reply to Daniel LatypovBeing able to fail the test outside of expectations and assertions is a requirement for new features, e.g. mocking, dynamic analysis, etc.
--- include/kunit/test.h | 2 ++ lib/kunit/test.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
include/kunit/test.h +2 -0
@@ -233,6 +233,8 @@ struct kunit {void kunit_init_test (struct kunit *test,const char *name,char *log); +void kunit_set_failure (struct kunit *test); +int kunit_run_tests (struct kunit_suite *suite);size_t kunit_suite_num_test_cases (struct kunit_suite *suite);
lib/kunit/test.c +1 -1
@@ -15,7 +15,7 @@#include "debugfs.h" #include "try-catch-impl.h" -static void kunit_set_failure (struct kunit *test) +void kunit_set_failure (struct kunit *test) {WRITE_ONCE (test->success, false); }
Signature · 1 line
2.28.0.1011.ga647a8990f-goog
RFC v2 7/12 kunit: mock: add internal mock infrastructure
In reply to Daniel LatypovFrom: Brendan Higgins <[email protected]>
Add the core internal mechanisms that mocks are implemented with; in particular, this adds the mechanisms by which expectation on mocks are validated and by which actions may be supplied and then executed when mocks are called.
--- include/kunit/mock.h | 126 +++++++++++++++ lib/kunit/Makefile | 1 + lib/kunit/mock.c | 364 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 491 insertions(+) create mode 100644 include/kunit/mock.h create mode 100644 lib/kunit/mock.c
include/kunit/mock.h new file +126 -0
@@ -0,0 +1,126 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Mocking API for KUnit. +* +* Copyright (C) 2020, Google LLC. +* Author: Brendan Higgins <[email protected]> +*/ + +#ifndef _KUNIT_MOCK_H +#define _KUNIT_MOCK_H + +#include <linux/types.h> +#include <linux/tracepoint.h> /* For PARAMS(...) */ +#include <kunit/test.h> +#include <kunit/kunit-stream.h> +#include <kunit/params.h> + +/** +* struct mock_param_matcher - represents a matcher used in a *call expectation* +* @match: the function that performs the matching +* +* The matching function takes a couple of parameters: +* +* - ``this``: refers to the parent struct +* - ``stream``: a &kunit_stream to which a detailed message should be added as +* to why the parameter matches or not +* - ``param``: a pointer to the parameter to check for a match +* +* The matching function should return whether or not the passed parameter +* matches. +*/ +struct mock_param_matcher { +bool (*match)(struct mock_param_matcher *this, +struct kunit_stream *stream, +const void *param); +}; + +#define MOCK_MAX_PARAMS 255 + +struct mock_matcher { +struct mock_param_matcher *matchers[MOCK_MAX_PARAMS ]; +int num; +}; + +/** +* struct mock_action - Represents an action that a mock performs when +* expectation is matched +* @do_action: the action to perform +* +* The action function is given some parameters: +* +* - ``this``: refers to the parent struct +* - ``params``: an array of pointers to the params passed into the mocked +* method or function. **The class argument is excluded for a mocked class +* method.** +* - ``len``: size of ``params`` +* +* The action function returns a pointer to the value that the mocked method +* or function should be returning. +*/ +struct mock_action { +void *(*do_action)(struct mock_action *this, +const void **params, +int len); +}; + +/** +* struct mock_expectation - represents a *call expectation* on a function. +* @action: A &struct mock_action to perform when the function is called. +* @max_calls_expected: maximum number of times an expectation may be called. +* @min_calls_expected: minimum number of times an expectation may be called. +* @retire_on_saturation: no longer match once ``max_calls_expected`` is +* reached. +* +* Represents a *call expectation* on a function created with +* KUNIT_EXPECT_CALL(). +*/ +struct mock_expectation { +struct mock_action *action; +int max_calls_expected; +int min_calls_expected; +bool retire_on_saturation; +/* private: internal use only. */ +const char *expectation_name; +struct list_head node; +struct mock_matcher *matcher; +int times_called; +}; + +struct mock_method { +struct list_head node; +const char *method_name; +const void *method_ptr; +struct mock_action *default_action; +struct list_head expectations; +}; + +struct mock { +struct kunit_post_condition parent; +struct kunit *test; +struct list_head methods; +/* TODO([email protected]): add locking to do_expect. */ +const void *(*do_expect)(struct mock *mock, +const char *method_name, +const void *method_ptr, +const char *const *param_types, +const void **params, +int len); +}; + +void mock_init_ctrl (struct kunit *test,struct mock *mock); + +void mock_validate_expectations (struct mock *mock); + +int mock_set_default_action (struct mock *mock, +const char *method_name, +const void *method_ptr, +struct mock_action *action); + +struct mock_expectation *mock_add_matcher (struct mock *mock, +const char *method_name, +const void *method_ptr, +struct mock_param_matcher *matchers[], +int len); + +#endif /* _KUNIT_MOCK_H */
lib/kunit/Makefile +1 -0
@@ -1,6 +1,7 @@ obj-$(CONFIG_KUNIT) += kunit.o kunit-objs += test.o \ + mock.o \ string-stream.o \ assert.o \ kunit-stream.o \
lib/kunit/mock.c new file +364 -0
364 lines not on this page · raw message
Signature · 1 line
2.28.0.1011.ga647a8990f-goog
RFC v2 8/12 kunit: mock: add basic matchers and actions
In reply to Daniel LatypovFrom: Brendan Higgins <[email protected]>
Add basic matchers and actions needed for any kind of mocking to be useful; these matchers and actions are how expectations for mocks are
described: what calls the mocks are expected to receive, and what the mock should do under those circumstances.
--- include/kunit/mock.h | 222 ++++++++++++++++++++++++++++++++ lib/kunit/Makefile | 1 + lib/kunit/common-mocks.c | 271 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 494 insertions(+) create mode 100644 lib/kunit/common-mocks.c
include/kunit/mock.h +222 -0
@@ -123,4 +123,226 @@ struct mock_expectation *mock_add_matcher(struct mock *mock,struct mock_param_matcher *matchers[], int len); +#define CONVERT_TO_ACTUAL_TYPE (type, ptr) (*((type *) ptr)) + +/** +* DOC: Built In Matchers +* +* These are the matchers that can be used when matching arguments in +* :c:func:`KUNIT_EXPECT_CALL` (more can be defined manually). +* +* For example, there's a matcher that matches any arguments: +* +* .. code-block:: c +* +* struct mock_param_matcher *any(struct kunit *test); +* +* There are matchers for integers based on the binary condition: +* +* * eq: equals to +* * ne: not equal to +* * lt: less than +* * le: less than or equal to +* * gt: greater than +* * ge: greater than or equal to +* +* .. code-block:: c +* +* struct mock_param_matcher *kunit_int_eq(struct kunit *test, int expected); +* struct mock_param_matcher *kunit_int_ne(struct kunit *test, int expected); +* struct mock_param_matcher *kunit_int_lt(struct kunit *test, int expected); +* struct mock_param_matcher *kunit_int_le(struct kunit *test, int expected); +* struct mock_param_matcher *kunit_int_gt(struct kunit *test, int expected); +* struct mock_param_matcher *kunit_int_ge(struct kunit *test, int expected); +* +* For a detailed list, please see +* ``include/linux/mock.h``. +*/ + +/* Matches any argument */ +struct mock_param_matcher *kunit_any (struct kunit *test); + +/* +* Matches different types of integers, the argument is compared to the +* `expected` field, based on the comparison defined. +*/ +struct mock_param_matcher *kunit_u8_eq (struct kunit *test,u8 expected); +struct mock_param_matcher *kunit_u8_ne (struct kunit *test,u8 expected); +struct mock_param_matcher *kunit_u8_le (struct kunit *test,u8 expected); +struct mock_param_matcher *kunit_u8_lt (struct kunit *test,u8 expected); +struct mock_param_matcher *kunit_u8_ge (struct kunit *test,u8 expected); +struct mock_param_matcher *kunit_u8_gt (struct kunit *test,u8 expected); + +struct mock_param_matcher *kunit_u16_eq (struct kunit *test,u16 expected); +struct mock_param_matcher *kunit_u16_ne (struct kunit *test,u16 expected); +struct mock_param_matcher *kunit_u16_le (struct kunit *test,u16 expected); +struct mock_param_matcher *kunit_u16_lt (struct kunit *test,u16 expected); +struct mock_param_matcher *kunit_u16_ge (struct kunit *test,u16 expected); +struct mock_param_matcher *kunit_u16_gt (struct kunit *test,u16 expected); + +struct mock_param_matcher *kunit_u32_eq (struct kunit *test,u32 expected); +struct mock_param_matcher *kunit_u32_ne (struct kunit *test,u32 expected); +struct mock_param_matcher *kunit_u32_le (struct kunit *test,u32 expected); +struct mock_param_matcher *kunit_u32_lt (struct kunit *test,u32 expected); +struct mock_param_matcher *kunit_u32_ge (struct kunit *test,u32 expected); +struct mock_param_matcher *kunit_u32_gt (struct kunit *test,u32 expected); + +struct mock_param_matcher *kunit_u64_eq (struct kunit *test,u64 expected); +struct mock_param_matcher *kunit_u64_ne (struct kunit *test,u64 expected); +struct mock_param_matcher *kunit_u64_le (struct kunit *test,u64 expected); +struct mock_param_matcher *kunit_u64_lt (struct kunit *test,u64 expected); +struct mock_param_matcher *kunit_u64_ge (struct kunit *test,u64 expected); +struct mock_param_matcher *kunit_u64_gt (struct kunit *test,u64 expected); + +struct mock_param_matcher *kunit_char_eq (struct kunit *test,char expected); +struct mock_param_matcher *kunit_char_ne (struct kunit *test,char expected); +struct mock_param_matcher *kunit_char_le (struct kunit *test,char expected); +struct mock_param_matcher *kunit_char_lt (struct kunit *test,char expected); +struct mock_param_matcher *kunit_char_ge (struct kunit *test,char expected); +struct mock_param_matcher *kunit_char_gt (struct kunit *test,char expected); + +struct mock_param_matcher *kunit_uchar_eq (struct kunit *test, +unsigned char expected); +struct mock_param_matcher *kunit_uchar_ne (struct kunit *test, +unsigned char expected); +struct mock_param_matcher *kunit_uchar_le (struct kunit *test, +unsigned char expected); +struct mock_param_matcher *kunit_uchar_lt (struct kunit *test, +unsigned char expected); +struct mock_param_matcher *kunit_uchar_ge (struct kunit *test, +unsigned char expected); +struct mock_param_matcher *kunit_uchar_gt (struct kunit *test, +unsigned char expected); + +struct mock_param_matcher *kunit_schar_eq (struct kunit *test, +signed char expected); +struct mock_param_matcher *kunit_schar_ne (struct kunit *test, +signed char expected); +struct mock_param_matcher *kunit_schar_le (struct kunit *test, +signed char expected); +struct mock_param_matcher *kunit_schar_lt (struct kunit *test, +signed char expected); +struct mock_param_matcher *kunit_schar_ge (struct kunit *test, +signed char expected); +struct mock_param_matcher *kunit_schar_gt (struct kunit *test, +signed char expected); + +struct mock_param_matcher *kunit_short_eq (struct kunit *test,short expected); +struct mock_param_matcher *kunit_short_ne (struct kunit *test,short expected); +struct mock_param_matcher *kunit_short_le (struct kunit *test,short expected); +struct mock_param_matcher *kunit_short_lt (struct kunit *test,short expected); +struct mock_param_matcher *kunit_short_ge (struct kunit *test,short expected); +struct mock_param_matcher *kunit_short_gt (struct kunit *test,short expected); + +struct mock_param_matcher *kunit_ushort_eq (struct kunit *test, +unsigned short expected); +struct mock_param_matcher *kunit_ushort_ne (struct kunit *test, +unsigned short expected); +struct mock_param_matcher *kunit_ushort_le (struct kunit *test, +unsigned short expected); +struct mock_param_matcher *kunit_ushort_lt (struct kunit *test, +unsigned short expected); +struct mock_param_matcher *kunit_ushort_ge (struct kunit *test, +unsigned short expected); +struct mock_param_matcher *kunit_ushort_gt (struct kunit *test, +unsigned short expected); + +struct mock_param_matcher *kunit_int_eq (struct kunit *test,int expected); +struct mock_param_matcher *kunit_int_ne (struct kunit *test,int expected); +struct mock_param_matcher *kunit_int_lt (struct kunit *test,int expected); +struct mock_param_matcher *kunit_int_le (struct kunit *test,int expected); +struct mock_param_matcher *kunit_int_gt (struct kunit *test,int expected); +struct mock_param_matcher *kunit_int_ge (struct kunit *test,int expected); + +struct mock_param_matcher *kunit_uint_eq (struct kunit *test, +unsigned int expected); +struct mock_param_matcher *kunit_uint_ne (struct kunit *test, +unsigned int expected); +struct mock_param_matcher *kunit_uint_lt (struct kunit *test, +unsigned int expected); +struct mock_param_matcher *kunit_uint_le (struct kunit *test, +unsigned int expected); +struct mock_param_matcher *kunit_uint_gt (struct kunit *test, +unsigned int expected); +struct mock_param_matcher *kunit_uint_ge (struct kunit *test, +unsigned int expected); + +struct mock_param_matcher *kunit_long_eq (struct kunit *test,long expected); +struct mock_param_matcher *kunit_long_ne (struct kunit *test,long expected); +struct mock_param_matcher *kunit_long_le (struct kunit *test,long expected); +struct mock_param_matcher *kunit_long_lt (struct kunit *test,long expected); +struct mock_param_matcher *kunit_long_ge (struct kunit *test,long expected); +struct mock_param_matcher *kunit_long_gt (struct kunit *test,long expected); + +struct mock_param_matcher *kunit_ulong_eq (struct kunit *test, +unsigned long expected); +struct mock_param_matcher *kunit_ulong_ne (struct kunit *test, +unsigned long expected); +struct mock_param_matcher *kunit_ulong_le (struct kunit *test, +unsigned long expected); +struct mock_param_matcher *kunit_ulong_lt (struct kunit *test, +unsigned long expected); +struct mock_param_matcher *kunit_ulong_ge (struct kunit *test, +unsigned long expected); +struct mock_param_matcher *kunit_ulong_gt (struct kunit *test, +unsigned long expected); + +struct mock_param_matcher *kunit_longlong_eq (struct kunit *test, +long long expected); +struct mock_param_matcher *kunit_longlong_ne (struct kunit *test, +long long expected); +struct mock_param_matcher *kunit_longlong_le (struct kunit *test, +long long expected); +struct mock_param_matcher *kunit_longlong_lt (struct kunit *test, +long long expected); +struct mock_param_matcher *kunit_longlong_ge (struct kunit *test, +long long expected); +struct mock_param_matcher *kunit_longlong_gt (struct kunit *test, +long long expected); + +struct mock_param_matcher *kunit_ulonglong_eq (struct kunit *test, +unsigned long long expected); +struct mock_param_matcher *kunit_ulonglong_ne (struct kunit *test, +unsigned long long expected); +struct mock_param_matcher *kunit_ulonglong_le (struct kunit *test, +unsigned long long expected); +struct mock_param_matcher *kunit_ulonglong_lt (struct kunit *test, +unsigned long long expected); +struct mock_param_matcher *kunit_ulonglong_ge (struct kunit *test, +unsigned long long expected); +struct mock_param_matcher *kunit_ulonglong_gt (struct kunit *test, +unsigned long long expected); + +/* Matches pointers. */ +struct mock_param_matcher *kunit_ptr_eq (struct kunit *test,void *expected); +struct mock_param_matcher *kunit_ptr_ne (struct kunit *test,void *expected); +struct mock_param_matcher *kunit_ptr_lt (struct kunit *test,void *expected); +struct mock_param_matcher *kunit_ptr_le (struct kunit *test,void *expected); +struct mock_param_matcher *kunit_ptr_gt (struct kunit *test,void *expected); +struct mock_param_matcher *kunit_ptr_ge (struct kunit *test,void *expected); + +/* Matches memory sections and strings. */ +struct mock_param_matcher *kunit_memeq (struct kunit *test, +const void *buf, +size_t size); +struct mock_param_matcher *kunit_streq (struct kunit *test,const char *str); + +struct mock_action *kunit_u8_return (struct kunit *test,u8 ret); +struct mock_action *kunit_u16_return (struct kunit *test,u16 ret); +struct mock_action *kunit_u32_return (struct kunit *test,u32 ret); +struct mock_action *kunit_u64_return (struct kunit *test,u64 ret); +struct mock_action *kunit_char_return (struct kunit *test,char ret); +struct mock_action *kunit_uchar_return (struct kunit *test,unsigned char ret); +struct mock_action *kunit_schar_return (struct kunit *test,signed char ret); +struct mock_action *kunit_short_return (struct kunit *test,short ret); +struct mock_action *kunit_ushort_return (struct kunit *test,unsigned short ret); +struct mock_action *kunit_int_return (struct kunit *test,int ret); +struct mock_action *kunit_uint_return (struct kunit *test,unsigned int ret); +struct mock_action *kunit_long_return (struct kunit *test,long ret); +struct mock_action *kunit_ulong_return (struct kunit *test,unsigned long ret); +struct mock_action *kunit_longlong_return (struct kunit *test,long long ret); +struct mock_action *kunit_ulonglong_return (struct kunit *test, +unsigned long long ret); +struct mock_action *kunit_ptr_return (struct kunit *test,void *ret); +#endif /* _KUNIT_MOCK_H */
lib/kunit/Makefile +1 -0
@@ -2,6 +2,7 @@ obj-$(CONFIG_KUNIT) += kunit.o kunit-objs += test.o \ mock.o \ + common-mocks.o \ string-stream.o \ assert.o \ kunit-stream.o \
lib/kunit/common-mocks.c new file +271 -0
271 lines not on this page · raw message
Signature · 1 line
2.28.0.1011.ga647a8990f-goog
kernel test robot
build botRe: [RFC v2 08/12] kunit: mock: add basic matchers and actions
reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # install arm64 cross compiling tool for…
Hi Daniel,
[FYI, it's a private test report for your RFC patch.] [auto build test WARNING on 10b82d5176488acee2820e5a2cf0f2ec5c3488b6]
url: https://github.com/0day-ci/linux/commits/Daniel-Latypov/kunit-introduce-class-mocking-support/20201013-062218 base: 10b82d5176488acee2820e5a2cf0f2ec5c3488b6 config: arm64-randconfig-r003-20201012 (attached as .config) compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project a324d8f964bf421fa7d8b882b0f64ead28c4149c)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# https://github.com/0day-ci/linux/commit/6189c327549d0bbce5bb21f28fb607f7ea04976e
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Daniel-Latypov/kunit-introduce-class-mocking-support/20201013-062218 git checkout 6189c327549d0bbce5bb21f28fb607f7ea04976e
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> lib/kunit/common-mocks.c:105:1: warning: no previous prototype for function 'to_mock_u8_matcher' [-Wmissing-prototypes]
DEFINE_MATCHER(u8);
^
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:37:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
to_mock_##type_name##_matcher( \
^
<scratch space>:81:1: note: expanded from here
to_mock_u8_matcher
^
lib/kunit/common-mocks.c:105:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:36:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
struct mock_##type_name##_matcher * \
^
>> lib/kunit/common-mocks.c:106:1: warning: no previous prototype for function 'to_mock_u16_matcher' [-Wmissing-prototypes]
DEFINE_MATCHER(u16);
^
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:37:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
to_mock_##type_name##_matcher( \
^
<scratch space>:194:1: note: expanded from here
to_mock_u16_matcher
^
lib/kunit/common-mocks.c:106:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:36:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
struct mock_##type_name##_matcher * \
^
>> lib/kunit/common-mocks.c:107:1: warning: no previous prototype for function 'to_mock_u32_matcher' [-Wmissing-prototypes]
DEFINE_MATCHER(u32);
^
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:37:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
to_mock_##type_name##_matcher( \
^
<scratch space>:101:1: note: expanded from here
to_mock_u32_matcher
^
lib/kunit/common-mocks.c:107:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:36:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
struct mock_##type_name##_matcher * \
^
>> lib/kunit/common-mocks.c:108:1: warning: no previous prototype for function 'to_mock_u64_matcher' [-Wmissing-prototypes]
DEFINE_MATCHER(u64);
^
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:37:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
to_mock_##type_name##_matcher( \
^
<scratch space>:214:1: note: expanded from here
to_mock_u64_matcher
^
lib/kunit/common-mocks.c:108:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:36:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
struct mock_##type_name##_matcher * \
^
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:90:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, eq, ==) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:59:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
actual, \
^~~~~~
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:90:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, eq, ==) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:60:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
matcher->expected); \
^~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:90:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, eq, ==) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:64:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
actual, \
^~~~~~
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:90:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, eq, ==) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:65:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
matcher->expected); \
^~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:92:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, ne, !=) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:59:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
actual, \
^~~~~~
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:92:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, ne, !=) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:60:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
matcher->expected); \
^~~~~~~~~~~~~~~~~ lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat] DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
--
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:65:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
matcher->expected); \
^~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:98:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, ge, >=) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:59:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
actual, \
^~~~~~
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:98:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, ge, >=) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:60:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
matcher->expected); \
^~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:98:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, ge, >=) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:64:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
actual, \
^~~~~~
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:98:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, ge, >=) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:65:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
matcher->expected); \
^~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:100:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, gt, >) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:59:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
actual, \
^~~~~~
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:100:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, gt, >) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:60:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
matcher->expected); \
^~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:100:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, gt, >) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:64:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
actual, \
^~~~~~
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:100:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, gt, >) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:65:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
matcher->expected); \
^~~~~~~~~~~~~~~~~
>> lib/kunit/common-mocks.c:109:1: warning: no previous prototype for function 'to_mock_char_matcher' [-Wmissing-prototypes]
DEFINE_MATCHER(char);
^
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:37:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
to_mock_##type_name##_matcher( \
^
<scratch space>:9:1: note: expanded from here
to_mock_char_matcher
^
lib/kunit/common-mocks.c:109:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:36:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
struct mock_##type_name##_matcher * \
^
>> lib/kunit/common-mocks.c:110:1: warning: no previous prototype for function 'to_mock_uchar_matcher' [-Wmissing-prototypes]
DEFINE_MATCHER_WITH_TYPENAME(uchar, unsigned char);
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:37:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
to_mock_##type_name##_matcher( \
^
<scratch space>:122:1: note: expanded from here
to_mock_uchar_matcher
^
lib/kunit/common-mocks.c:110:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:36:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
struct mock_##type_name##_matcher * \
^
>> lib/kunit/common-mocks.c:111:1: warning: no previous prototype for function 'to_mock_schar_matcher' [-Wmissing-prototypes]
DEFINE_MATCHER_WITH_TYPENAME(schar, signed char);
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:37:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
to_mock_##type_name##_matcher( \
^
<scratch space>:235:1: note: expanded from here
to_mock_schar_matcher
^
lib/kunit/common-mocks.c:111:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:36:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
struct mock_##type_name##_matcher * \
^
>> lib/kunit/common-mocks.c:112:1: warning: no previous prototype for function 'to_mock_short_matcher' [-Wmissing-prototypes]
DEFINE_MATCHER(short);
^
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:37:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
to_mock_##type_name##_matcher( \
^
<scratch space>:64:1: note: expanded from here
to_mock_short_matcher
^
lib/kunit/common-mocks.c:112:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:36:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
struct mock_##type_name##_matcher * \
^
>> lib/kunit/common-mocks.c:113:1: warning: no previous prototype for function 'to_mock_ushort_matcher' [-Wmissing-prototypes]
DEFINE_MATCHER_WITH_TYPENAME(ushort, unsigned short);
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:37:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
to_mock_##type_name##_matcher( \
^
<scratch space>:177:1: note: expanded from here
to_mock_ushort_matcher
^
lib/kunit/common-mocks.c:113:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:36:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
struct mock_##type_name##_matcher * \
^
>> lib/kunit/common-mocks.c:114:1: warning: no previous prototype for function 'to_mock_int_matcher' [-Wmissing-prototypes]
DEFINE_MATCHER(int);
^
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:37:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
to_mock_##type_name##_matcher( \
^
<scratch space>:16:1: note: expanded from here
to_mock_int_matcher
^
lib/kunit/common-mocks.c:114:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:36:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
struct mock_##type_name##_matcher * \
^
>> lib/kunit/common-mocks.c:115:1: warning: no previous prototype for function 'to_mock_uint_matcher' [-Wmissing-prototypes]
DEFINE_MATCHER_WITH_TYPENAME(uint, unsigned int);
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:37:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
to_mock_##type_name##_matcher( \
^
<scratch space>:129:1: note: expanded from here
to_mock_uint_matcher
^
lib/kunit/common-mocks.c:115:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:36:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
struct mock_##type_name##_matcher * \
^
>> lib/kunit/common-mocks.c:116:1: warning: no previous prototype for function 'to_mock_long_matcher' [-Wmissing-prototypes]
DEFINE_MATCHER(long);
^
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:37:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
to_mock_##type_name##_matcher( \
^
<scratch space>:242:1: note: expanded from here
to_mock_long_matcher
^
lib/kunit/common-mocks.c:116:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:36:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
struct mock_##type_name##_matcher * \
^
lib/kunit/common-mocks.c:116:1: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
DEFINE_MATCHER(long);
^~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:90:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, eq, ==) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:59:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
actual, \
^~~~~~
lib/kunit/common-mocks.c:116:1: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
DEFINE_MATCHER(long);
^~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:90:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, eq, ==) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:60:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
matcher->expected); \
^~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:116:1: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
DEFINE_MATCHER(long);
^~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:90:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, eq, ==) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:64:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
actual, \
^~~~~~
lib/kunit/common-mocks.c:116:1: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
DEFINE_MATCHER(long);
^~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:90:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, eq, ==) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:65:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
matcher->expected); \
^~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:116:1: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
DEFINE_MATCHER(long);
^~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:92:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, ne, !=) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:59:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
actual, \
^~~~~~
lib/kunit/common-mocks.c:116:1: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
DEFINE_MATCHER(long);
^~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:92:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, ne, !=) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:60:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
matcher->expected); \
^~~~~~~~~~~~~~~~~ lib/kunit/common-mocks.c:116:1: warning: format specifies type 'int' but the argument has type 'long' [-Wformat] DEFINE_MATCHER(long);
^~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
..
vim +/to_mock_u8_matcher +105 lib/kunit/common-mocks.c
104
> 105 DEFINE_MATCHER(u8);
> 106 DEFINE_MATCHER(u16);
> 107 DEFINE_MATCHER(u32);
> 108 DEFINE_MATCHER(u64);
> 109 DEFINE_MATCHER(char);
> 110 DEFINE_MATCHER_WITH_TYPENAME(uchar, unsigned char);
> 111 DEFINE_MATCHER_WITH_TYPENAME(schar, signed char);
> 112 DEFINE_MATCHER(short);
> 113 DEFINE_MATCHER_WITH_TYPENAME(ushort, unsigned short);
> 114 DEFINE_MATCHER(int);
> 115 DEFINE_MATCHER_WITH_TYPENAME(uint, unsigned int);
> 116 DEFINE_MATCHER(long);
> 117 DEFINE_MATCHER_WITH_TYPENAME(ulong, unsigned long);
> 118 DEFINE_MATCHER_WITH_TYPENAME(longlong, long long);
> 119 DEFINE_MATCHER_WITH_TYPENAME(ulonglong, unsigned long long);
120
> 121 DEFINE_MATCHER_WITH_TYPENAME(ptr, void *);
122
123 struct mock_memeq_matcher {
124 struct mock_param_matcher matcher;
125 const void *expected;
126 size_t size;
127 };
128
129 static bool match_memeq(struct mock_param_matcher *pmatcher,
130 struct kunit_stream *stream,
131 const void *pactual)
132 {
133 struct mock_memeq_matcher *matcher =
134 container_of(pmatcher,
135 struct mock_memeq_matcher,
136 matcher);
137 const void *actual = CONVERT_TO_ACTUAL_TYPE(const void *, pactual);
138 bool matches = !memcmp(actual, matcher->expected, matcher->size);
139 int i;
140
141 for (i = 0; i < matcher->size; i++)
142 kunit_stream_add(stream, "%02x, ", ((const char *) actual)[i]);
143 if (matches)
144 kunit_stream_add(stream, "== ");
145 else
146 kunit_stream_add(stream, "!= ");
147 for (i = 0; i < matcher->size; i++)
148 kunit_stream_add(stream,
149 "%02x, ",
150 ((const char *) matcher->expected)[i]);
151
152 return matches;
153 }
154
155 struct mock_param_matcher *kunit_memeq(struct kunit *test,
156 const void *buf,
157 size_t size)
158 {
159 struct mock_memeq_matcher *matcher;
160
161 matcher = kunit_kzalloc(test, sizeof(*matcher), GFP_KERNEL);
162 if (!matcher)
163 return NULL;
164
165 matcher->matcher.match = match_memeq;
166 matcher->expected = buf;
167 matcher->size = size;
168
169 return &matcher->matcher;
170 }
171
172 struct mock_streq_matcher {
173 struct mock_param_matcher matcher;
174 const char *expected;
175 };
176
177 static bool match_streq(struct mock_param_matcher *pmatcher,
178 struct kunit_stream *stream,
179 const void *pactual)
180 {
181 struct mock_streq_matcher *matcher =
182 container_of(pmatcher,
183 struct mock_streq_matcher,
184 matcher);
185 const char *actual = CONVERT_TO_ACTUAL_TYPE(const char *, pactual);
186 bool matches = !strcmp(actual, matcher->expected);
187
188 if (matches)
189 kunit_stream_add(stream, "%s == %s", actual, matcher->expected);
190 else
191 kunit_stream_add(stream, "%s != %s", actual, matcher->expected);
192
193 return matches;
194 }
195
196 struct mock_param_matcher *kunit_streq(struct kunit *test, const char *str)
197 {
198 struct mock_streq_matcher *matcher;
199
200 matcher = kunit_kzalloc(test, sizeof(*matcher), GFP_KERNEL);
201 if (!matcher)
202 return NULL;
203
204 matcher->matcher.match = match_streq;
205 matcher->expected = str;
206
207 return &matcher->matcher;
208 }
209
210 #define DEFINE_RETURN_ACTION_STRUCT(type_name, type) \
211 struct mock_##type_name##_action { \
212 struct mock_action action; \
213 type ret; \
214 }
215
216 #define DEFINE_RETURN_ACTION_FUNC(type_name, type) \
217 void *do_##type_name##_return(struct mock_action *paction, \
218 const void **params, \
219 int len) \
220 { \
221 struct mock_##type_name##_action *action = \
222 container_of(paction, \
223 struct mock_##type_name##_action,\
224 action); \
225 \
226 return (void *) &action->ret; \
227 }
228
229 #define DEFINE_RETURN_ACTION_FACTORY(type_name, type) \
230 struct mock_action *kunit_##type_name##_return( \
231 struct kunit *test, \
232 type ret) \
233 { \
234 struct mock_##type_name##_action *action; \
235 \
236 action = kunit_kmalloc(test, \
237 sizeof(*action), \
238 GFP_KERNEL); \
239 if (!action) \
240 return NULL; \
241 \
242 action->action.do_action = do_##type_name##_return; \
243 action->ret = ret; \
244 \
245 return &action->action; \
246 }
247
248 #define DEFINE_RETURN_ACTION_WITH_TYPENAME(type_name, type) \
249 DEFINE_RETURN_ACTION_STRUCT(type_name, type); \
250 DEFINE_RETURN_ACTION_FUNC(type_name, type); \
251 DEFINE_RETURN_ACTION_FACTORY(type_name, type)
252
253 #define DEFINE_RETURN_ACTION(type) \
254 DEFINE_RETURN_ACTION_WITH_TYPENAME(type, type)
255
> 256 DEFINE_RETURN_ACTION(u8);
> 257 DEFINE_RETURN_ACTION(u16);
> 258 DEFINE_RETURN_ACTION(u32);
> 259 DEFINE_RETURN_ACTION(u64);
> 260 DEFINE_RETURN_ACTION(char);
> 261 DEFINE_RETURN_ACTION_WITH_TYPENAME(uchar, unsigned char);
> 262 DEFINE_RETURN_ACTION_WITH_TYPENAME(schar, signed char);
> 263 DEFINE_RETURN_ACTION(short);
> 264 DEFINE_RETURN_ACTION_WITH_TYPENAME(ushort, unsigned short);
> 265 DEFINE_RETURN_ACTION(int);
> 266 DEFINE_RETURN_ACTION_WITH_TYPENAME(uint, unsigned int);
> 267 DEFINE_RETURN_ACTION(long);
> 268 DEFINE_RETURN_ACTION_WITH_TYPENAME(ulong, unsigned long);
> 269 DEFINE_RETURN_ACTION_WITH_TYPENAME(longlong, long long);
> 270 DEFINE_RETURN_ACTION_WITH_TYPENAME(ulonglong, unsigned long long);
> 271 DEFINE_RETURN_ACTION_WITH_TYPENAME(ptr, void *);---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [RFC v2 08/12] kunit: mock: add basic matchers and actions
In reply to Daniel Latypovreproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # install powerpc64 cross compiling tool…
Hi Daniel,
[FYI, it's a private test report for your RFC patch.] [auto build test WARNING on 10b82d5176488acee2820e5a2cf0f2ec5c3488b6]
url: https://github.com/0day-ci/linux/commits/Daniel-Latypov/kunit-introduce-class-mocking-support/20201013-062218 base: 10b82d5176488acee2820e5a2cf0f2ec5c3488b6 config: powerpc64-randconfig-r031-20201012 (attached as .config) compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project a324d8f964bf421fa7d8b882b0f64ead28c4149c)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install powerpc64 cross compiling tool for clang build
# apt-get install binutils-powerpc64-linux-gnu
# https://github.com/0day-ci/linux/commit/6189c327549d0bbce5bb21f28fb607f7ea04976e
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Daniel-Latypov/kunit-introduce-class-mocking-support/20201013-062218 git checkout 6189c327549d0bbce5bb21f28fb607f7ea04976e
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=powerpc64
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> lib/kunit/common-mocks.c:105:1: warning: no previous prototype for function 'to_mock_u8_matcher' [-Wmissing-prototypes]
DEFINE_MATCHER(u8);
^
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:37:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
to_mock_##type_name##_matcher( \
^
<scratch space>:55:1: note: expanded from here
to_mock_u8_matcher
^
lib/kunit/common-mocks.c:105:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:36:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
struct mock_##type_name##_matcher * \
^
>> lib/kunit/common-mocks.c:106:1: warning: no previous prototype for function 'to_mock_u16_matcher' [-Wmissing-prototypes]
DEFINE_MATCHER(u16);
^
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:37:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
to_mock_##type_name##_matcher( \
^
<scratch space>:168:1: note: expanded from here
to_mock_u16_matcher
^
lib/kunit/common-mocks.c:106:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:36:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
struct mock_##type_name##_matcher * \
^
>> lib/kunit/common-mocks.c:107:1: warning: no previous prototype for function 'to_mock_u32_matcher' [-Wmissing-prototypes]
DEFINE_MATCHER(u32);
^
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:37:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
to_mock_##type_name##_matcher( \
^
<scratch space>:281:1: note: expanded from here
to_mock_u32_matcher
^
lib/kunit/common-mocks.c:107:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:36:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
struct mock_##type_name##_matcher * \
^
>> lib/kunit/common-mocks.c:108:1: warning: no previous prototype for function 'to_mock_u64_matcher' [-Wmissing-prototypes]
DEFINE_MATCHER(u64);
^
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:37:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
to_mock_##type_name##_matcher( \
^
<scratch space>:89:1: note: expanded from here
to_mock_u64_matcher
^
lib/kunit/common-mocks.c:108:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:36:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
struct mock_##type_name##_matcher * \
^
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:90:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, eq, ==) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:59:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
actual, \
^~~~~~
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:90:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, eq, ==) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:60:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
matcher->expected); \
^~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:90:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, eq, ==) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:64:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
actual, \
^~~~~~
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:90:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, eq, ==) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:65:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
matcher->expected); \
^~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:92:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, ne, !=) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:59:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
actual, \
^~~~~~
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:92:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, ne, !=) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:60:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
matcher->expected); \
^~~~~~~~~~~~~~~~~ lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat] DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
--
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:65:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
matcher->expected); \
^~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:98:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, ge, >=) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:59:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
actual, \
^~~~~~
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:98:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, ge, >=) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:60:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
matcher->expected); \
^~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:98:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, ge, >=) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:64:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
actual, \
^~~~~~
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:98:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, ge, >=) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:65:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
matcher->expected); \
^~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:100:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, gt, >) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:59:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
actual, \
^~~~~~
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:100:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, gt, >) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:60:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
matcher->expected); \
^~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:100:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, gt, >) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:64:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
actual, \
^~~~~~
lib/kunit/common-mocks.c:108:1: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
DEFINE_MATCHER(u64);
^~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:100:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, gt, >) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:65:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
matcher->expected); \
^~~~~~~~~~~~~~~~~
>> lib/kunit/common-mocks.c:109:1: warning: no previous prototype for function 'to_mock_char_matcher' [-Wmissing-prototypes]
DEFINE_MATCHER(char);
^
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:37:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
to_mock_##type_name##_matcher( \
^
<scratch space>:202:1: note: expanded from here
to_mock_char_matcher
^
lib/kunit/common-mocks.c:109:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:36:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
struct mock_##type_name##_matcher * \
^
>> lib/kunit/common-mocks.c:110:1: warning: no previous prototype for function 'to_mock_uchar_matcher' [-Wmissing-prototypes]
DEFINE_MATCHER_WITH_TYPENAME(uchar, unsigned char);
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:37:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
to_mock_##type_name##_matcher( \
^
<scratch space>:6:1: note: expanded from here
to_mock_uchar_matcher
^
lib/kunit/common-mocks.c:110:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:36:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
struct mock_##type_name##_matcher * \
^
>> lib/kunit/common-mocks.c:111:1: warning: no previous prototype for function 'to_mock_schar_matcher' [-Wmissing-prototypes]
DEFINE_MATCHER_WITH_TYPENAME(schar, signed char);
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:37:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
to_mock_##type_name##_matcher( \
^
<scratch space>:119:1: note: expanded from here
to_mock_schar_matcher
^
lib/kunit/common-mocks.c:111:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:36:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
struct mock_##type_name##_matcher * \
^
>> lib/kunit/common-mocks.c:112:1: warning: no previous prototype for function 'to_mock_short_matcher' [-Wmissing-prototypes]
DEFINE_MATCHER(short);
^
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:37:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
to_mock_##type_name##_matcher( \
^
<scratch space>:232:1: note: expanded from here
to_mock_short_matcher
^
lib/kunit/common-mocks.c:112:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:36:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
struct mock_##type_name##_matcher * \
^
>> lib/kunit/common-mocks.c:113:1: warning: no previous prototype for function 'to_mock_ushort_matcher' [-Wmissing-prototypes]
DEFINE_MATCHER_WITH_TYPENAME(ushort, unsigned short);
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:37:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
to_mock_##type_name##_matcher( \
^
<scratch space>:67:1: note: expanded from here
to_mock_ushort_matcher
^
lib/kunit/common-mocks.c:113:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:36:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
struct mock_##type_name##_matcher * \
^
>> lib/kunit/common-mocks.c:114:1: warning: no previous prototype for function 'to_mock_int_matcher' [-Wmissing-prototypes]
DEFINE_MATCHER(int);
^
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:37:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
to_mock_##type_name##_matcher( \
^
<scratch space>:180:1: note: expanded from here
to_mock_int_matcher
^
lib/kunit/common-mocks.c:114:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:36:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
struct mock_##type_name##_matcher * \
^
>> lib/kunit/common-mocks.c:115:1: warning: no previous prototype for function 'to_mock_uint_matcher' [-Wmissing-prototypes]
DEFINE_MATCHER_WITH_TYPENAME(uint, unsigned int);
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:37:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
to_mock_##type_name##_matcher( \
^
<scratch space>:7:1: note: expanded from here
to_mock_uint_matcher
^
lib/kunit/common-mocks.c:115:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:36:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
struct mock_##type_name##_matcher * \
^
>> lib/kunit/common-mocks.c:116:1: warning: no previous prototype for function 'to_mock_long_matcher' [-Wmissing-prototypes]
DEFINE_MATCHER(long);
^
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:37:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
to_mock_##type_name##_matcher( \
^
<scratch space>:120:1: note: expanded from here
to_mock_long_matcher
^
lib/kunit/common-mocks.c:116:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^
lib/kunit/common-mocks.c:89:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_TO_MATCHER_STRUCT(type_name) \
^
lib/kunit/common-mocks.c:36:3: note: expanded from macro 'DEFINE_TO_MATCHER_STRUCT'
struct mock_##type_name##_matcher * \
^
lib/kunit/common-mocks.c:116:1: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
DEFINE_MATCHER(long);
^~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:90:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, eq, ==) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:59:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
actual, \
^~~~~~
lib/kunit/common-mocks.c:116:1: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
DEFINE_MATCHER(long);
^~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:90:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, eq, ==) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:60:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
matcher->expected); \
^~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:116:1: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
DEFINE_MATCHER(long);
^~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:90:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, eq, ==) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:64:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
actual, \
^~~~~~
lib/kunit/common-mocks.c:116:1: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
DEFINE_MATCHER(long);
^~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:90:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, eq, ==) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:65:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
matcher->expected); \
^~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:116:1: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
DEFINE_MATCHER(long);
^~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:92:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, ne, !=) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:59:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
actual, \
^~~~~~
lib/kunit/common-mocks.c:116:1: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
DEFINE_MATCHER(long);
^~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
#define DEFINE_MATCHER(type) DEFINE_MATCHER_WITH_TYPENAME(type, type)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:92:3: note: expanded from macro 'DEFINE_MATCHER_WITH_TYPENAME'
DEFINE_MATCH_FUNC(type_name, type, ne, !=) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:60:8: note: expanded from macro 'DEFINE_MATCH_FUNC'
matcher->expected); \
^~~~~~~~~~~~~~~~~ lib/kunit/common-mocks.c:116:1: warning: format specifies type 'int' but the argument has type 'long' [-Wformat] DEFINE_MATCHER(long);
^~~~~~~~~~~~~~~~~~~~
lib/kunit/common-mocks.c:103:30: note: expanded from macro 'DEFINE_MATCHER'
..
vim +/to_mock_u8_matcher +105 lib/kunit/common-mocks.c
104
> 105 DEFINE_MATCHER(u8);
> 106 DEFINE_MATCHER(u16);
> 107 DEFINE_MATCHER(u32);
> 108 DEFINE_MATCHER(u64);
> 109 DEFINE_MATCHER(char);
> 110 DEFINE_MATCHER_WITH_TYPENAME(uchar, unsigned char);
> 111 DEFINE_MATCHER_WITH_TYPENAME(schar, signed char);
> 112 DEFINE_MATCHER(short);
> 113 DEFINE_MATCHER_WITH_TYPENAME(ushort, unsigned short);
> 114 DEFINE_MATCHER(int);
> 115 DEFINE_MATCHER_WITH_TYPENAME(uint, unsigned int);
> 116 DEFINE_MATCHER(long);
> 117 DEFINE_MATCHER_WITH_TYPENAME(ulong, unsigned long);
> 118 DEFINE_MATCHER_WITH_TYPENAME(longlong, long long);
> 119 DEFINE_MATCHER_WITH_TYPENAME(ulonglong, unsigned long long);
120
> 121 DEFINE_MATCHER_WITH_TYPENAME(ptr, void *);
122
123 struct mock_memeq_matcher {
124 struct mock_param_matcher matcher;
125 const void *expected;
126 size_t size;
127 };
128
129 static bool match_memeq(struct mock_param_matcher *pmatcher,
130 struct kunit_stream *stream,
131 const void *pactual)
132 {
133 struct mock_memeq_matcher *matcher =
134 container_of(pmatcher,
135 struct mock_memeq_matcher,
136 matcher);
137 const void *actual = CONVERT_TO_ACTUAL_TYPE(const void *, pactual);
138 bool matches = !memcmp(actual, matcher->expected, matcher->size);
139 int i;
140
141 for (i = 0; i < matcher->size; i++)
142 kunit_stream_add(stream, "%02x, ", ((const char *) actual)[i]);
143 if (matches)
144 kunit_stream_add(stream, "== ");
145 else
146 kunit_stream_add(stream, "!= ");
147 for (i = 0; i < matcher->size; i++)
148 kunit_stream_add(stream,
149 "%02x, ",
150 ((const char *) matcher->expected)[i]);
151
152 return matches;
153 }
154
155 struct mock_param_matcher *kunit_memeq(struct kunit *test,
156 const void *buf,
157 size_t size)
158 {
159 struct mock_memeq_matcher *matcher;
160
161 matcher = kunit_kzalloc(test, sizeof(*matcher), GFP_KERNEL);
162 if (!matcher)
163 return NULL;
164
165 matcher->matcher.match = match_memeq;
166 matcher->expected = buf;
167 matcher->size = size;
168
169 return &matcher->matcher;
170 }
171
172 struct mock_streq_matcher {
173 struct mock_param_matcher matcher;
174 const char *expected;
175 };
176
177 static bool match_streq(struct mock_param_matcher *pmatcher,
178 struct kunit_stream *stream,
179 const void *pactual)
180 {
181 struct mock_streq_matcher *matcher =
182 container_of(pmatcher,
183 struct mock_streq_matcher,
184 matcher);
185 const char *actual = CONVERT_TO_ACTUAL_TYPE(const char *, pactual);
186 bool matches = !strcmp(actual, matcher->expected);
187
188 if (matches)
189 kunit_stream_add(stream, "%s == %s", actual, matcher->expected);
190 else
191 kunit_stream_add(stream, "%s != %s", actual, matcher->expected);
192
193 return matches;
194 }
195
196 struct mock_param_matcher *kunit_streq(struct kunit *test, const char *str)
197 {
198 struct mock_streq_matcher *matcher;
199
200 matcher = kunit_kzalloc(test, sizeof(*matcher), GFP_KERNEL);
201 if (!matcher)
202 return NULL;
203
204 matcher->matcher.match = match_streq;
205 matcher->expected = str;
206
207 return &matcher->matcher;
208 }
209
210 #define DEFINE_RETURN_ACTION_STRUCT(type_name, type) \
211 struct mock_##type_name##_action { \
212 struct mock_action action; \
213 type ret; \
214 }
215
216 #define DEFINE_RETURN_ACTION_FUNC(type_name, type) \
217 void *do_##type_name##_return(struct mock_action *paction, \
218 const void **params, \
219 int len) \
220 { \
221 struct mock_##type_name##_action *action = \
222 container_of(paction, \
223 struct mock_##type_name##_action,\
224 action); \
225 \
226 return (void *) &action->ret; \
227 }
228
229 #define DEFINE_RETURN_ACTION_FACTORY(type_name, type) \
230 struct mock_action *kunit_##type_name##_return( \
231 struct kunit *test, \
232 type ret) \
233 { \
234 struct mock_##type_name##_action *action; \
235 \
236 action = kunit_kmalloc(test, \
237 sizeof(*action), \
238 GFP_KERNEL); \
239 if (!action) \
240 return NULL; \
241 \
242 action->action.do_action = do_##type_name##_return; \
243 action->ret = ret; \
244 \
245 return &action->action; \
246 }
247
248 #define DEFINE_RETURN_ACTION_WITH_TYPENAME(type_name, type) \
249 DEFINE_RETURN_ACTION_STRUCT(type_name, type); \
250 DEFINE_RETURN_ACTION_FUNC(type_name, type); \
251 DEFINE_RETURN_ACTION_FACTORY(type_name, type)
252
253 #define DEFINE_RETURN_ACTION(type) \
254 DEFINE_RETURN_ACTION_WITH_TYPENAME(type, type)
255
> 256 DEFINE_RETURN_ACTION(u8);
> 257 DEFINE_RETURN_ACTION(u16);
> 258 DEFINE_RETURN_ACTION(u32);
> 259 DEFINE_RETURN_ACTION(u64);
> 260 DEFINE_RETURN_ACTION(char);
> 261 DEFINE_RETURN_ACTION_WITH_TYPENAME(uchar, unsigned char);
> 262 DEFINE_RETURN_ACTION_WITH_TYPENAME(schar, signed char);
> 263 DEFINE_RETURN_ACTION(short);
> 264 DEFINE_RETURN_ACTION_WITH_TYPENAME(ushort, unsigned short);
> 265 DEFINE_RETURN_ACTION(int);
> 266 DEFINE_RETURN_ACTION_WITH_TYPENAME(uint, unsigned int);
> 267 DEFINE_RETURN_ACTION(long);
> 268 DEFINE_RETURN_ACTION_WITH_TYPENAME(ulong, unsigned long);
> 269 DEFINE_RETURN_ACTION_WITH_TYPENAME(longlong, long long);
> 270 DEFINE_RETURN_ACTION_WITH_TYPENAME(ulonglong, unsigned long long);
> 271 DEFINE_RETURN_ACTION_WITH_TYPENAME(ptr, void *);---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
RFC v2 9/12 kunit: mock: add macro machinery to pick correct format args
In reply to Daniel LatypovFrom: Marcelo Schmitt <[email protected]>
Note: It was unclear if there was existing code that could be reused.
This is used by DEFINE_MATCHER to generate matching funcs for primitive types that don't trigger compiler warnings.
After preprocessing, we now generate matcher func code like
kunit_stream_add(stream, "%p not > "%p", actual, matcher->expected)
as opposed to the hoping %d will work for all types.
--- lib/kunit/common-mocks.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-)
lib/kunit/common-mocks.c +23 -2
@@ -42,6 +42,27 @@ struct mock_param_matcher *kunit_any(struct kunit *test) matcher); \ } +#define TYPE_FRMT (type_name) FORMAT_##type_name +#define FORMAT_u8 "%hu" +#define FORMAT_u16 "%hu" +#define FORMAT_u32 "%u" +#define FORMAT_u64 "%llu" +#define FORMAT_char "%c" +#define FORMAT_uchar "%c" +#define FORMAT_schar "%c" +#define FORMAT_short "%hd" +#define FORMAT_ushort "%hu" +#define FORMAT_int "%d" +#define FORMAT_uint "%u" +#define FORMAT_long "%ld" +#define FORMAT_ulong "%lu" +#define FORMAT_longlong "%lld" +#define FORMAT_ulonglong "%llu" +#define FORMAT_ptr "%p" + +#define CMP_FORMAT (type_name, msg, op) \ + TYPE_FRMT(type_name) msg " " #op " " TYPE_FRMT(type_name) +#define DEFINE_MATCH_FUNC (type_name, type, op_name, op) \ static bool match_##type_name##_##op_name( \ struct mock_param_matcher *pmatcher, \
@@ -55,12 +76,12 @@ struct mock_param_matcher *kunit_any(struct kunit *test) \if (matches) \kunit_stream_add (stream, \ - "%d "#op" %d", \ +CMP_FORMAT (type_name,"" , op),\ actual, \ matcher->expected); \else \kunit_stream_add (stream, \ - "%d not "#op" %d", \ +CMP_FORMAT (type_name," not" , op), \ actual, \ matcher->expected); \ \
Signature · 1 line
2.28.0.1011.ga647a8990f-goog
RFC v2 10/12 kunit: mock: add class mocking support
In reply to Daniel LatypovFrom: Brendan Higgins <[email protected]>
Introduce basic class mocking, the ability to automatically generate a Linux C-style class implementation whose behavior is controlled by test cases, which can also set expectations on when and how mocks are called.
--- include/kunit/mock.h | 433 +++++++++++++++++++++++++++++++++ lib/kunit/Makefile | 5 +- lib/kunit/kunit-example-test.c | 98 ++++++++ lib/kunit/mock-macro-test.c | 91 +++++++ lib/kunit/mock-test.c | 320 ++++++++++++++++++++++++ 5 files changed, 945 insertions(+), 2 deletions(-) create mode 100644 lib/kunit/mock-test.c
include/kunit/mock.h +433 -0
@@ -123,6 +123,439 @@ struct mock_expectation *mock_add_matcher(struct mock *mock,struct mock_param_matcher *matchers[], int len); +#define MOCK (name) name##_mock + +/** +* KUNIT_EXPECT_CALL() - Declares a *call expectation* on a mock function. +* @expectation_call: a mocked method or function with parameters replaced with +* matchers. +* +* Example: +* +* .. code-block:: c +* +* // Class to mock. +* struct example { +* int (*foo)(struct example *, int); +* }; +* +* // Define the mock. +* DECLARE_STRUCT_CLASS_MOCK_PREREQS(example); +* +* DEFINE_STRUCT_CLASS_MOCK(METHOD(foo), CLASS(example), +* RETURNS(int), +* PARAMS(struct example *, int)); +* +* static int example_init(struct MOCK(example) *mock_example) +* { +* struct example *example = mock_get_trgt(mock_example); +* +* example->foo = foo; +* return 0; +* } +* +* DEFINE_STRUCT_CLASS_MOCK_INIT(example, example_init); +* +* static void foo_example_test_success(struct kunit *test) +* { +* struct MOCK(example) *mock_example; +* struct example *example = mock_get_trgt(mock_example); +* struct mock_expectation *handle; +* +* mock_example = CONSTRUCT_MOCK(example, test); +* +* handle = KUNIT_EXPECT_CALL(foo(mock_get_ctrl(mock_example), +* kunit_int_eq(test, 5))); +* handle->action = int_return(test, 2); +* +* KUNIT_EXPECT_EQ(test, 2, example_bar(example, 5)); +* } +* +* Return: +* A &struct mock_expectation representing the call expectation. +* allowing additional conditions and actions to be specified. +*/ +#define KUNIT_EXPECT_CALL (expectation_call) mock_master_##expectation_call + +#define mock_get_ctrl_internal (mock_object) (&(mock_object)->ctrl) +#define mock_get_ctrl (mock_object) mock_get_ctrl_internal(mock_object) + +#define mock_get_trgt_internal (mock_object) (&(mock_object)->trgt) +#define mock_get_trgt (mock_object) mock_get_trgt_internal(mock_object) + +#define mock_get_test (mock_object) (mock_get_ctrl(mock_object)->test) + +#define CLASS (struct_name) struct_name +#define HANDLE_INDEX (index) index +#define METHOD (method_name) method_name +#define RETURNS (return_type) return_type +/* #define PARAMS(...) __VA_ARGS__ included by linux/tracepoint.h */ + +#define MOCK_INIT_ID (struct_name) struct_name##mock_init +#define REAL_ID (func_name) __real__##func_name +#define INVOKE_ID (func_name) __invoke__##func_name + +#define DECLARE_MOCK_CLIENT(name, return_type, param_types...) \ + return_type name(PARAM_LIST_FROM_TYPES(param_types)) + +#define DECLARE_MOCK_MASTER(name, ctrl_index, param_types...) \ + struct mock_expectation *mock_master_##name( \ + MATCHER_PARAM_LIST_FROM_TYPES(ctrl_index, \ + param_types)) + +#define DECLARE_MOCK_COMMON(name, handle_index, return_type, param_types...) \ + DECLARE_MOCK_CLIENT(name, return_type, param_types); \ + DECLARE_MOCK_MASTER(name, handle_index, param_types) + +#define DECLARE_STRUCT_CLASS_MOCK_STRUCT (struct_name) \ + struct MOCK(struct_name) { \ + struct mock ctrl; \ + struct struct_name trgt; \ + } + +#define DECLARE_STRUCT_CLASS_MOCK_CONVERTER (struct_name) \ + static inline struct mock *from_##struct_name##_to_mock( \ + const struct struct_name *trgt) \ + { \ + return mock_get_ctrl( \ + container_of(trgt, \ + struct MOCK(struct_name), \ + trgt)); \ + } + +/** +* DECLARE_STRUCT_CLASS_MOCK_PREREQS() - Create a mock child class +* @struct_name: name of the class/struct to be mocked +* +* Creates a mock child class of ``struct_name`` named +* ``struct MOCK(struct_name)`` along with supporting internally used methods. +* +* See KUNIT_EXPECT_CALL() for example usages. +*/ +#define DECLARE_STRUCT_CLASS_MOCK_PREREQS (struct_name) \ + DECLARE_STRUCT_CLASS_MOCK_STRUCT(struct_name); \ + DECLARE_STRUCT_CLASS_MOCK_CONVERTER(struct_name) + +#define DECLARE_STRUCT_CLASS_MOCK_HANDLE_INDEX_INTERNAL (name, \ + struct_name, \ + handle_index, \ + return_type, \ + param_types...) \ + DECLARE_MOCK_COMMON(name, \ + handle_index, \ + return_type, \ + param_types) + +#define DECLARE_STRUCT_CLASS_MOCK_HANDLE_INDEX (name, \ + struct_name, \ + handle_index, \ + return_type, \ + param_types...) \ + DECLARE_STRUCT_CLASS_MOCK_HANDLE_INDEX_INTERNAL(name, \ + struct_name, \ + handle_index, \ + return_type, \ + param_types) + +/** +* DECLARE_STRUCT_CLASS_MOCK() +* @name: method name +* @struct_name: name of the class/struct +* @return_type: return type of the method +* @param_types: parameters of the method +* +* Same as DEFINE_STRUCT_CLASS_MOCK(), but only makes header compatible +* declarations. +*/ +#define DECLARE_STRUCT_CLASS_MOCK (name, \ + struct_name, \ + return_type, \ + param_types...) \ + DECLARE_STRUCT_CLASS_MOCK_HANDLE_INDEX(name, \ + struct_name, \ + 0, \ + return_type, \ + param_types) + +/** +* DECLARE_STRUCT_CLASS_MOCK_VOID_RETURN() +* @name: method name +* @struct_name: name of the class/struct +* @param_types: parameters of the method +* +* Same as DEFINE_STRUCT_CLASS_MOCK_VOID_RETURN(), but only makes header +* compatible declarations. +*/ +#define DECLARE_STRUCT_CLASS_MOCK_VOID_RETURN (name, \ + struct_name, \ + param_types...) \ + DECLARE_STRUCT_CLASS_MOCK_HANDLE_INDEX(name, \ + struct_name, \ + 0, \ + void, \ + param_types) + +/** +* DECLARE_STRUCT_CLASS_MOCK_INIT() +* @struct_name: name of the class/struct +* +* Same as DEFINE_STRUCT_CLASS_MOCK_INIT(), but only makes header compatible +* declarations. +*/ +#define DECLARE_STRUCT_CLASS_MOCK_INIT (struct_name) \ + struct MOCK(struct_name) *MOCK_INIT_ID(struct_name)( \ + struct kunit *test) + +/** +* CONSTRUCT_MOCK() +* @struct_name: name of the class +* @test: associated test +* +* Constructs and allocates a test managed ``struct MOCK(struct_name)`` given +* the name of the class for which the mock is defined and a test object. +* +* See KUNIT_EXPECT_CALL() for example usage. +*/ +#define CONSTRUCT_MOCK (struct_name, test) MOCK_INIT_ID(struct_name)(test) + +#define DEFINE_MOCK_CLIENT_COMMON (name, \ + handle_index, \ +MOCK_SOURCE , \ + mock_source_ctx, \ + return_type, \ +RETURN , \ + param_types...) \ + return_type name(PARAM_LIST_FROM_TYPES(param_types)) \ + { \ + struct mock *mock = MOCK_SOURCE(mock_source_ctx, \ + handle_index); \ + static const char * const param_type_names[] = { \ + TYPE_NAMES_FROM_TYPES(handle_index, \ + param_types) \ + }; \ + const void *params[] = { \ + PTR_TO_ARG_FROM_TYPES(handle_index, \ + param_types) \ + }; \ + const void *retval; \ + \ + retval = mock->do_expect(mock, \ + #name, \ + name, \ + param_type_names, \ + params, \ + ARRAY_SIZE(params)); \ + KUNIT_ASSERT_NOT_ERR_OR_NULL(mock->test, retval); \ + if (!retval) { \ + kunit_info(mock->test, \ + "no action installed for "#name"\n");\ + BUG(); \ + } \ + RETURN(return_type, retval); \ + } + +#define CLASS_MOCK_CLIENT_SOURCE (ctx, handle_index) ctx(arg##handle_index) +#define DEFINE_MOCK_METHOD_CLIENT_COMMON (name, \ + handle_index, \ + mock_converter, \ + return_type, \ +RETURN , \ + param_types...) \ + DEFINE_MOCK_CLIENT_COMMON(name, \ + handle_index, \ + CLASS_MOCK_CLIENT_SOURCE, \ + mock_converter, \ + return_type, \ + RETURN, \ + param_types) + +#define CAST_AND_RETURN (return_type, retval) return *((return_type *) retval) +#define NO_RETURN (return_type, retval) + +#define DEFINE_MOCK_METHOD_CLIENT (name, \ + handle_index, \ + mock_converter, \ + return_type, \ + param_types...) \ + DEFINE_MOCK_METHOD_CLIENT_COMMON(name, \ + handle_index, \ + mock_converter, \ + return_type, \ + CAST_AND_RETURN, \ + param_types) + +#define DEFINE_MOCK_METHOD_CLIENT_VOID_RETURN (name, \ + handle_index, \ + mock_converter, \ + param_types...) \ + DEFINE_MOCK_METHOD_CLIENT_COMMON(name, \ + handle_index, \ + mock_converter, \ + void, \ + NO_RETURN, \ + param_types) + +#define DEFINE_MOCK_MASTER_COMMON_INTERNAL (name, \ + ctrl_index, \ +MOCK_SOURCE , \ + param_types...) \ + struct mock_expectation *mock_master_##name( \ + MATCHER_PARAM_LIST_FROM_TYPES(ctrl_index, \ + param_types)) \ + { \ + struct mock_param_matcher *matchers[] = { \ + ARG_NAMES_FROM_TYPES(ctrl_index, param_types) \ + }; \ + \ + return mock_add_matcher(MOCK_SOURCE(ctrl_index), \ + #name, \ + (const void *) name, \ + matchers, \ + ARRAY_SIZE(matchers)); \ + } +#define DEFINE_MOCK_MASTER_COMMON (name, \ + ctrl_index, \ +MOCK_SOURCE , \ + param_types...) \ + DEFINE_MOCK_MASTER_COMMON_INTERNAL(name, \ + ctrl_index, \ + MOCK_SOURCE, \ + param_types) + +#define CLASS_MOCK_MASTER_SOURCE (ctrl_index) arg##ctrl_index +#define DEFINE_MOCK_METHOD_MASTER(name, ctrl_index, param_types...) \ + DEFINE_MOCK_MASTER_COMMON(name, \ + ctrl_index, \ + CLASS_MOCK_MASTER_SOURCE, \ + param_types) + +#define DEFINE_MOCK_COMMON (name, \ + handle_index, \ + mock_converter, \ + return_type, \ + param_types...) \ + DEFINE_MOCK_METHOD_CLIENT(name, \ + handle_index, \ + mock_converter, \ + return_type, \ + param_types); \ + DEFINE_MOCK_METHOD_MASTER(name, handle_index, param_types) + +#define DEFINE_MOCK_COMMON_VOID_RETURN (name, \ + handle_index, \ + mock_converter, \ + param_types...) \ + DEFINE_MOCK_METHOD_CLIENT_VOID_RETURN(name, \ + handle_index, \ + mock_converter, \ + param_types); \ + DEFINE_MOCK_METHOD_MASTER(name, handle_index, param_types) + +#define DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_INTERNAL (name, \ + struct_name, \ + handle_index, \ + return_type, \ + param_types...) \ + DEFINE_MOCK_COMMON(name, \ + handle_index, \ + from_##struct_name##_to_mock, \ + return_type, param_types) +#define DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX (name, \ + struct_name, \ + handle_index, \ + return_type, \ + param_types...) \ + DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_INTERNAL(name, \ + struct_name, \ + handle_index, \ + return_type, \ + param_types) + +#define DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_VOID_RETURN_INTERNAL ( \ + name, \ + struct_name, \ + handle_index, \ + param_types...) \ + DEFINE_MOCK_COMMON_VOID_RETURN(name, \ + handle_index, \ + from_##struct_name##_to_mock, \ + param_types) +#define DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_VOID_RETURN (name, \ + struct_name, \ + handle_index, \ + param_types...) \ + DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_VOID_RETURN_INTERNAL( \ + name, \ + struct_name, \ + handle_index, \ + param_types) + +/** +* DEFINE_STRUCT_CLASS_MOCK() +* @name: name of the method +* @struct_name: name of the class of which the method belongs +* @return_type: return type of the method to be created. **Must not be void.** +* @param_types: parameters to method to be created. +* +* See KUNIT_EXPECT_CALL() for example usage. +*/ +#define DEFINE_STRUCT_CLASS_MOCK (name, \ + struct_name, \ + return_type, \ + param_types...) \ + DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX(name, \ + struct_name, \ + 0, \ + return_type, \ + param_types) + +/** +* DEFINE_STRUCT_CLASS_MOCK_VOID_RETURN() +* @name: name of the method +* @struct_name: name of the class of which the method belongs +* @param_types: parameters to method to be created. +* +* Same as DEFINE_STRUCT_CLASS_MOCK() except the method has a ``void`` return +* type. +*/ +#define DEFINE_STRUCT_CLASS_MOCK_VOID_RETURN(name, struct_name, param_types...)\ + DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_VOID_RETURN(name, \ + struct_name, \ + 0, \ + param_types) + +/** +* DEFINE_STRUCT_CLASS_MOCK_INIT() +* @struct_name: name of the class +* @init_func: a function of type ``int (*)(struct kunit *, struct MOCK(struct_name) *)``. +* The function is passed a pointer to an allocated, *but not +* initialized*, ``struct MOCK(struct_name)``. The job of this user +* provided function is to perform remaining initialization. Usually +* this entails assigning mock methods to the function pointers in +* the parent struct. +* +* See KUNIT_EXPECT_CALL() for example usage. +*/ +#define DEFINE_STRUCT_CLASS_MOCK_INIT (struct_name, init_func) \ + struct MOCK(struct_name) *MOCK_INIT_ID(struct_name)( \ + struct kunit *test) \ + { \ + struct MOCK(struct_name) *mock_obj; \ + \ + mock_obj = kunit_kzalloc(test, \ + sizeof(*mock_obj), \ + GFP_KERNEL); \ + if (!mock_obj) \ + return NULL; \ + \ + mock_init_ctrl(test, mock_get_ctrl(mock_obj)); \ + \ + if (init_func(test, mock_obj)) \ + return NULL; \ + \ + return mock_obj; \ + } +#define CONVERT_TO_ACTUAL_TYPE (type, ptr) (*((type *) ptr))/**
lib/kunit/Makefile +3 -2
@@ -13,11 +13,12 @@ kunit-objs += debugfs.o endif obj-$(CONFIG_KUNIT_TEST) += kunit-test.o \ - mock-macro-test.o + mock-macro-test.o \ + mock-test.o # string-stream-test compiles built-in only. ifeq ($(CONFIG_KUNIT_TEST),y) obj-$(CONFIG_KUNIT_TEST) += string-stream-test.o endif -obj-$(CONFIG_KUNIT_EXAMPLE_TEST) += kunit-example-test.o +obj-$(CONFIG_KUNIT_EXAMPLE_TEST) += kunit-example-test.o
lib/kunit/kunit-example-test.c +98 -0
122 lines not on this page · raw message
lib/kunit/mock-macro-test.c +91 -0
114 lines not on this page · raw message
lib/kunit/mock-test.c new file +320 -0
320 lines not on this page · raw message
Signature · 1 line
2.28.0.1011.ga647a8990f-goog
kernel test robot
build botRe: [RFC v2 10/12] kunit: mock: add class mocking support
reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # install arm64 cross compiling tool for…
Hi Daniel,
[FYI, it's a private test report for your RFC patch.] [auto build test ERROR on 10b82d5176488acee2820e5a2cf0f2ec5c3488b6]
url: https://github.com/0day-ci/linux/commits/Daniel-Latypov/kunit-introduce-class-mocking-support/20201013-062218 base: 10b82d5176488acee2820e5a2cf0f2ec5c3488b6 config: arm64-randconfig-r003-20201012 (attached as .config) compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project a324d8f964bf421fa7d8b882b0f64ead28c4149c)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# https://github.com/0day-ci/linux/commit/9e162e8cc1ac27ab6de97d84033753ff486214e9
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Daniel-Latypov/kunit-introduce-class-mocking-support/20201013-062218 git checkout 9e162e8cc1ac27ab6de97d84033753ff486214e9
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
All error/warnings (new ones prefixed by >>):
>> lib/kunit/mock-macro-test.c:24:33: warning: no previous prototype for function 'one_param' [-Wmissing-prototypes]
DEFINE_STRUCT_CLASS_MOCK(METHOD(one_param), CLASS(mock_macro_dummy_struct),
^
lib/kunit/mock-macro-test.c:25:13: note: declare 'static' if the function is not intended to be used outside of this translation unit
RETURNS(int),
^
include/kunit/mock.h:191:30: note: expanded from macro 'RETURNS'
#define RETURNS(return_type) return_type
^
include/kunit/mock.h:509:13: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK'
return_type, \
^
include/kunit/mock.h:471:15: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX'
return_type, \
^
note: (skipping 2 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/kunit/mock.h:383:8: note: expanded from macro 'DEFINE_MOCK_METHOD_CLIENT'
return_type, \
^
include/kunit/mock.h:368:8: note: expanded from macro 'DEFINE_MOCK_METHOD_CLIENT_COMMON'
return_type, \
^
include/kunit/mock.h:328:3: note: expanded from macro 'DEFINE_MOCK_CLIENT_COMMON'
return_type name(PARAM_LIST_FROM_TYPES(param_types)) \
^
>> lib/kunit/mock-macro-test.c:24:1: warning: no previous prototype for function 'mock_master_one_param' [-Wmissing-prototypes]
DEFINE_STRUCT_CLASS_MOCK(METHOD(one_param), CLASS(mock_macro_dummy_struct),
^
include/kunit/mock.h:506:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK'
DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX(name, \
^
include/kunit/mock.h:468:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX'
DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_INTERNAL(name, \
^
include/kunit/mock.h:459:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_INTERNAL'
DEFINE_MOCK_COMMON(name, \
^
note: (skipping 2 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/kunit/mock.h:420:3: note: expanded from macro 'DEFINE_MOCK_MASTER_COMMON'
DEFINE_MOCK_MASTER_COMMON_INTERNAL(name, \
^
include/kunit/mock.h:402:28: note: expanded from macro 'DEFINE_MOCK_MASTER_COMMON_INTERNAL'
struct mock_expectation *mock_master_##name( \
^
<scratch space>:150:1: note: expanded from here
mock_master_one_param
^
lib/kunit/mock-macro-test.c:24:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
include/kunit/mock.h:506:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK'
DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX(name, \
^
include/kunit/mock.h:468:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX'
DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_INTERNAL(name, \
^
include/kunit/mock.h:459:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_INTERNAL'
DEFINE_MOCK_COMMON(name, \
^
note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/kunit/mock.h:427:3: note: expanded from macro 'DEFINE_MOCK_METHOD_MASTER'
DEFINE_MOCK_MASTER_COMMON(name, \
^
include/kunit/mock.h:420:3: note: expanded from macro 'DEFINE_MOCK_MASTER_COMMON'
DEFINE_MOCK_MASTER_COMMON_INTERNAL(name, \
^
include/kunit/mock.h:402:3: note: expanded from macro 'DEFINE_MOCK_MASTER_COMMON_INTERNAL'
struct mock_expectation *mock_master_##name( \
^
>> lib/kunit/mock-macro-test.c:28:33: warning: no previous prototype for function 'two_param' [-Wmissing-prototypes]
DEFINE_STRUCT_CLASS_MOCK(METHOD(two_param), CLASS(mock_macro_dummy_struct),
^
lib/kunit/mock-macro-test.c:29:13: note: declare 'static' if the function is not intended to be used outside of this translation unit
RETURNS(int),
^
include/kunit/mock.h:191:30: note: expanded from macro 'RETURNS'
#define RETURNS(return_type) return_type
^
include/kunit/mock.h:509:13: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK'
return_type, \
^
include/kunit/mock.h:471:15: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX'
return_type, \
^
note: (skipping 2 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/kunit/mock.h:383:8: note: expanded from macro 'DEFINE_MOCK_METHOD_CLIENT'
return_type, \
^
include/kunit/mock.h:368:8: note: expanded from macro 'DEFINE_MOCK_METHOD_CLIENT_COMMON'
return_type, \
^
include/kunit/mock.h:328:3: note: expanded from macro 'DEFINE_MOCK_CLIENT_COMMON'
return_type name(PARAM_LIST_FROM_TYPES(param_types)) \
^
>> lib/kunit/mock-macro-test.c:28:1: warning: no previous prototype for function 'mock_master_two_param' [-Wmissing-prototypes]
DEFINE_STRUCT_CLASS_MOCK(METHOD(two_param), CLASS(mock_macro_dummy_struct),
^
include/kunit/mock.h:506:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK'
DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX(name, \
^
include/kunit/mock.h:468:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX'
DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_INTERNAL(name, \
^
include/kunit/mock.h:459:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_INTERNAL'
DEFINE_MOCK_COMMON(name, \
^
note: (skipping 2 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/kunit/mock.h:420:3: note: expanded from macro 'DEFINE_MOCK_MASTER_COMMON'
DEFINE_MOCK_MASTER_COMMON_INTERNAL(name, \
^
include/kunit/mock.h:402:28: note: expanded from macro 'DEFINE_MOCK_MASTER_COMMON_INTERNAL'
struct mock_expectation *mock_master_##name( \
^
<scratch space>:113:1: note: expanded from here
mock_master_two_param
^
lib/kunit/mock-macro-test.c:28:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
include/kunit/mock.h:506:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK'
DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX(name, \
^
include/kunit/mock.h:468:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX'
DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_INTERNAL(name, \
^
include/kunit/mock.h:459:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_INTERNAL'
DEFINE_MOCK_COMMON(name, \
^
note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/kunit/mock.h:427:3: note: expanded from macro 'DEFINE_MOCK_METHOD_MASTER'
DEFINE_MOCK_MASTER_COMMON(name, \
^
include/kunit/mock.h:420:3: note: expanded from macro 'DEFINE_MOCK_MASTER_COMMON'
DEFINE_MOCK_MASTER_COMMON_INTERNAL(name, \
^
include/kunit/mock.h:402:3: note: expanded from macro 'DEFINE_MOCK_MASTER_COMMON_INTERNAL'
struct mock_expectation *mock_master_##name( \
^
>> lib/kunit/mock-macro-test.c:32:46: warning: no previous prototype for function 'non_first_slot_param' [-Wmissing-prototypes]
DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX(METHOD(non_first_slot_param),
^
lib/kunit/mock-macro-test.c:34:13: note: declare 'static' if the function is not intended to be used outside of this translation unit
RETURNS(int),
^
include/kunit/mock.h:191:30: note: expanded from macro 'RETURNS'
#define RETURNS(return_type) return_type
^
include/kunit/mock.h:471:15: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX'
return_type, \
^
include/kunit/mock.h:462:8: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_INTERNAL'
return_type, param_types)
^
note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/kunit/mock.h:383:8: note: expanded from macro 'DEFINE_MOCK_METHOD_CLIENT'
return_type, \
^
include/kunit/mock.h:368:8: note: expanded from macro 'DEFINE_MOCK_METHOD_CLIENT_COMMON'
return_type, \
^
include/kunit/mock.h:328:3: note: expanded from macro 'DEFINE_MOCK_CLIENT_COMMON'
return_type name(PARAM_LIST_FROM_TYPES(param_types)) \
^
>> lib/kunit/mock-macro-test.c:32:1: warning: no previous prototype for function 'mock_master_non_first_slot_param' [-Wmissing-prototypes]
DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX(METHOD(non_first_slot_param),
^
include/kunit/mock.h:468:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX'
DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_INTERNAL(name, \
^
include/kunit/mock.h:459:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_INTERNAL'
DEFINE_MOCK_COMMON(name, \
^
include/kunit/mock.h:442:3: note: expanded from macro 'DEFINE_MOCK_COMMON'
DEFINE_MOCK_METHOD_MASTER(name, handle_index, param_types)
^
note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/kunit/mock.h:420:3: note: expanded from macro 'DEFINE_MOCK_MASTER_COMMON'
DEFINE_MOCK_MASTER_COMMON_INTERNAL(name, \
^
include/kunit/mock.h:402:28: note: expanded from macro 'DEFINE_MOCK_MASTER_COMMON_INTERNAL'
struct mock_expectation *mock_master_##name( \
^
<scratch space>:310:1: note: expanded from here
mock_master_non_first_slot_param
^
lib/kunit/mock-macro-test.c:32:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
include/kunit/mock.h:468:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX'
DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_INTERNAL(name, \
^
include/kunit/mock.h:459:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_INTERNAL'
DEFINE_MOCK_COMMON(name, \
^
include/kunit/mock.h:442:3: note: expanded from macro 'DEFINE_MOCK_COMMON'
DEFINE_MOCK_METHOD_MASTER(name, handle_index, param_types)
^
include/kunit/mock.h:427:3: note: expanded from macro 'DEFINE_MOCK_METHOD_MASTER'
DEFINE_MOCK_MASTER_COMMON(name, \
^
include/kunit/mock.h:420:3: note: expanded from macro 'DEFINE_MOCK_MASTER_COMMON'
DEFINE_MOCK_MASTER_COMMON_INTERNAL(name, \
^
include/kunit/mock.h:402:3: note: expanded from macro 'DEFINE_MOCK_MASTER_COMMON_INTERNAL'
struct mock_expectation *mock_master_##name( \
^
>> lib/kunit/mock-macro-test.c:37:33: warning: no previous prototype for function 'void_ptr_return' [-Wmissing-prototypes]
DEFINE_STRUCT_CLASS_MOCK(METHOD(void_ptr_return),
^
lib/kunit/mock-macro-test.c:39:13: note: declare 'static' if the function is not intended to be used outside of this translation unit
RETURNS(void *),
^
include/kunit/mock.h:191:30: note: expanded from macro 'RETURNS'
#define RETURNS(return_type) return_type
^
include/kunit/mock.h:509:13: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK'
return_type, \
^
include/kunit/mock.h:471:15: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX'
return_type, \
^
note: (skipping 2 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/kunit/mock.h:383:8: note: expanded from macro 'DEFINE_MOCK_METHOD_CLIENT'
return_type, \
^
include/kunit/mock.h:368:8: note: expanded from macro 'DEFINE_MOCK_METHOD_CLIENT_COMMON'
return_type, \
^
include/kunit/mock.h:328:3: note: expanded from macro 'DEFINE_MOCK_CLIENT_COMMON'
return_type name(PARAM_LIST_FROM_TYPES(param_types)) \
^
>> lib/kunit/mock-macro-test.c:37:1: warning: no previous prototype for function 'mock_master_void_ptr_return' [-Wmissing-prototypes]
DEFINE_STRUCT_CLASS_MOCK(METHOD(void_ptr_return),
^
include/kunit/mock.h:506:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK'
DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX(name, \
^
include/kunit/mock.h:468:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX'
DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_INTERNAL(name, \
^
include/kunit/mock.h:459:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_INTERNAL'
DEFINE_MOCK_COMMON(name, \
^
note: (skipping 2 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/kunit/mock.h:420:3: note: expanded from macro 'DEFINE_MOCK_MASTER_COMMON'
DEFINE_MOCK_MASTER_COMMON_INTERNAL(name, \
^
include/kunit/mock.h:402:28: note: expanded from macro 'DEFINE_MOCK_MASTER_COMMON_INTERNAL'
struct mock_expectation *mock_master_##name( \
^
<scratch space>:58:1: note: expanded from here
mock_master_void_ptr_return
^
lib/kunit/mock-macro-test.c:37:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
include/kunit/mock.h:506:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK'
DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX(name, \
^
include/kunit/mock.h:468:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX'
DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_INTERNAL(name, \
^
include/kunit/mock.h:459:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_INTERNAL'
DEFINE_MOCK_COMMON(name, \
^
note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/kunit/mock.h:427:3: note: expanded from macro 'DEFINE_MOCK_METHOD_MASTER'
DEFINE_MOCK_MASTER_COMMON(name, \
^
include/kunit/mock.h:420:3: note: expanded from macro 'DEFINE_MOCK_MASTER_COMMON'
DEFINE_MOCK_MASTER_COMMON_INTERNAL(name, \
^
include/kunit/mock.h:402:3: note: expanded from macro 'DEFINE_MOCK_MASTER_COMMON_INTERNAL'
struct mock_expectation *mock_master_##name( \
^
>> lib/kunit/mock-macro-test.c:54:1: error: too many arguments to function call, expected single argument 'mock_test_struct', have 2 arguments
DEFINE_STRUCT_CLASS_MOCK_INIT(mock_macro_dummy_struct,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/mock.h:553:24: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_INIT'
if (init_func(test, mock_obj)) \
~~~~~~~~~ ^~~~~~~~
lib/kunit/mock-macro-test.c:42:12: note: 'mock_macro_dummy_struct_init' declared here
static int mock_macro_dummy_struct_init(
^
>> lib/kunit/mock-macro-test.c:54:1: warning: no previous prototype for function 'mock_macro_dummy_structmock_init' [-Wmissing-prototypes]
DEFINE_STRUCT_CLASS_MOCK_INIT(mock_macro_dummy_struct,
^
include/kunit/mock.h:540:29: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_INIT'
struct MOCK(struct_name) *MOCK_INIT_ID(struct_name)( \
^
include/kunit/mock.h:194:35: note: expanded from macro 'MOCK_INIT_ID'
#define MOCK_INIT_ID(struct_name) struct_name##mock_init
^
<scratch space>:101:1: note: expanded from here
mock_macro_dummy_structmock_init
^
lib/kunit/mock-macro-test.c:54:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
DEFINE_STRUCT_CLASS_MOCK_INIT(mock_macro_dummy_struct,
^
static
include/kunit/mock.h:540:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_INIT'
struct MOCK(struct_name) *MOCK_INIT_ID(struct_name)( \
^
9 warnings and 1 error generated.
--
>> lib/kunit/mock-test.c:28:33: warning: no previous prototype for function 'mock_add' [-Wmissing-prototypes]
DEFINE_STRUCT_CLASS_MOCK(METHOD(mock_add), CLASS(adder), RETURNS(int),
^
lib/kunit/mock-test.c:28:66: note: declare 'static' if the function is not intended to be used outside of this translation unit
DEFINE_STRUCT_CLASS_MOCK(METHOD(mock_add), CLASS(adder), RETURNS(int),
^
static
include/kunit/mock.h:191:30: note: expanded from macro 'RETURNS'
#define RETURNS(return_type) return_type
^
include/kunit/mock.h:509:13: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK'
return_type, \
^
include/kunit/mock.h:471:15: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX'
return_type, \
^
note: (skipping 2 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/kunit/mock.h:383:8: note: expanded from macro 'DEFINE_MOCK_METHOD_CLIENT'
return_type, \
^
include/kunit/mock.h:368:8: note: expanded from macro 'DEFINE_MOCK_METHOD_CLIENT_COMMON'
return_type, \
^
include/kunit/mock.h:328:3: note: expanded from macro 'DEFINE_MOCK_CLIENT_COMMON'
return_type name(PARAM_LIST_FROM_TYPES(param_types)) \
^
>> lib/kunit/mock-test.c:28:1: warning: no previous prototype for function 'mock_master_mock_add' [-Wmissing-prototypes]
DEFINE_STRUCT_CLASS_MOCK(METHOD(mock_add), CLASS(adder), RETURNS(int),
^
include/kunit/mock.h:506:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK'
DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX(name, \
^
include/kunit/mock.h:468:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX'
DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_INTERNAL(name, \
^
include/kunit/mock.h:459:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_INTERNAL'
DEFINE_MOCK_COMMON(name, \
^
note: (skipping 2 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/kunit/mock.h:420:3: note: expanded from macro 'DEFINE_MOCK_MASTER_COMMON'
DEFINE_MOCK_MASTER_COMMON_INTERNAL(name, \
^
include/kunit/mock.h:402:28: note: expanded from macro 'DEFINE_MOCK_MASTER_COMMON_INTERNAL'
struct mock_expectation *mock_master_##name( \
^
<scratch space>:10:1: note: expanded from here
mock_master_mock_add
^
lib/kunit/mock-test.c:28:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
include/kunit/mock.h:506:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK'
DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX(name, \
^
include/kunit/mock.h:468:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX'
DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_INTERNAL(name, \
^
include/kunit/mock.h:459:3: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX_INTERNAL'
DEFINE_MOCK_COMMON(name, \
^
note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/kunit/mock.h:427:3: note: expanded from macro 'DEFINE_MOCK_METHOD_MASTER'
DEFINE_MOCK_MASTER_COMMON(name, \
^
include/kunit/mock.h:420:3: note: expanded from macro 'DEFINE_MOCK_MASTER_COMMON'
DEFINE_MOCK_MASTER_COMMON_INTERNAL(name, \
^
include/kunit/mock.h:402:3: note: expanded from macro 'DEFINE_MOCK_MASTER_COMMON_INTERNAL'
struct mock_expectation *mock_master_##name( \
^
>> lib/kunit/mock-test.c:46:1: error: too many arguments to function call, expected single argument 'mock_adder', have 2 arguments
DEFINE_STRUCT_CLASS_MOCK_INIT(adder, adder_mock_init);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/mock.h:553:24: note: expanded from macro 'DEFINE_STRUCT_CLASS_MOCK_INIT'
if (init_func(test, mock_obj)) \
~~~~~~~~~ ^~~~~~~~
lib/kunit/mock-test.c:33:12: note: 'adder_mock_init' declared here
static int adder_mock_init(struct MOCK(adder) *mock_adder)
^ 2 warnings and 1 error generated.
..
vim +/mock_test_struct +54 lib/kunit/mock-macro-test.c
23
> 24 DEFINE_STRUCT_CLASS_MOCK(METHOD(one_param), CLASS(mock_macro_dummy_struct),
25 RETURNS(int),
26 PARAMS(struct mock_macro_dummy_struct *));
27
> 28 DEFINE_STRUCT_CLASS_MOCK(METHOD(two_param), CLASS(mock_macro_dummy_struct),
29 RETURNS(int),
30 PARAMS(struct mock_macro_dummy_struct *, int));
31
> 32 DEFINE_STRUCT_CLASS_MOCK_HANDLE_INDEX(METHOD(non_first_slot_param),
33 CLASS(mock_macro_dummy_struct), HANDLE_INDEX(1),
34 RETURNS(int),
35 PARAMS(int, struct mock_macro_dummy_struct *));
36
> 37 DEFINE_STRUCT_CLASS_MOCK(METHOD(void_ptr_return),
38 CLASS(mock_macro_dummy_struct),
39 RETURNS(void *),
40 PARAMS(struct mock_macro_dummy_struct *));
41
42 static int mock_macro_dummy_struct_init(
43 struct MOCK(mock_macro_dummy_struct) *mock_test_struct)
44 {
45 struct mock_macro_dummy_struct *test_struct =
46 mock_get_trgt(mock_test_struct);
47
48 test_struct->one_param = one_param;
49 test_struct->two_param = two_param;
50 test_struct->non_first_slot_param = non_first_slot_param;
51 return 0;
52 }
53
> 54 DEFINE_STRUCT_CLASS_MOCK_INIT(mock_macro_dummy_struct,
55 mock_macro_dummy_struct_init);
56 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
RFC v2 11/12 kunit: mock: add struct param matcher
In reply to Daniel LatypovFrom: Brendan Higgins <[email protected]>
Add parameter matcher builder for matching struct values.
--- include/kunit/mock.h | 58 +++++++++++++++++++ lib/kunit/common-mocks.c | 117 +++++++++++++++++++++++++++++++++++++++ lib/kunit/mock-test.c | 40 +++++++++++++ 3 files changed, 215 insertions(+)
include/kunit/mock.h +58 -0
@@ -758,8 +758,18 @@ struct mock_param_matcher *kunit_ptr_ge(struct kunit *test, void *expected);struct mock_param_matcher *kunit_memeq (struct kunit *test,const void *buf,size_t size); +struct mock_param_matcher *kunit_streq (struct kunit *test,const char *str); +struct mock_param_matcher *kunit_str_contains (struct kunit *test, +const char *needle); + +/* Matches var-arg arguments. */ +struct mock_param_matcher *kunit_va_format_cmp ( +struct kunit *test, +struct mock_param_matcher *fmt_matcher, +struct mock_param_matcher *va_matcher); +struct mock_action *kunit_u8_return (struct kunit *test,u8 ret);struct mock_action *kunit_u16_return (struct kunit *test,u16 ret);struct mock_action *kunit_u32_return (struct kunit *test,u32 ret);
@@ -778,4 +788,52 @@ struct mock_action *kunit_ulonglong_return(struct kunit *test, unsigned long long ret);struct mock_action *kunit_ptr_return (struct kunit *test,void *ret); +/** +* struct mock_struct_matcher_entry - composed with other &struct +* mock_struct_matcher_entry to make a +* &struct struct_matcher +* @member_offset: offset of this member +* @matcher: matcher for this particular member +* +* This is used for struct_cmp() matchers. +*/ +struct mock_struct_matcher_entry { +size_t member_offset; +struct mock_param_matcher *matcher; +}; + +static inline void init_mock_struct_matcher_entry_internal ( +struct mock_struct_matcher_entry *entry, +size_t offset, +struct mock_param_matcher *matcher) +{ + entry->member_offset = offset; + entry->matcher = matcher; +} + +/** +* INIT_MOCK_STRUCT_MATCHER_ENTRY() +* @entry: the &struct mock_struct_matcher_entry to initialize +* @type: the struct being matched +* @member: the member of the struct being matched, used to calculate the offset +* @matcher: matcher to match that member +* +* Initializes ``entry`` to match ``type->member`` with ``matcher``. +*/ +#define INIT_MOCK_STRUCT_MATCHER_ENTRY (entry, type, member, matcher) \ + init_mock_struct_matcher_entry_internal(entry, \ + offsetof(type, member),\ + matcher) + +static inline void INIT_MOCK_STRUCT_MATCHER_ENTRY_LAST ( +struct mock_struct_matcher_entry *entry) +{ + entry->matcher =NULL ; +} + +struct mock_param_matcher *kunit_struct_cmp ( +struct kunit *test, +const char *struct_name, +struct mock_struct_matcher_entry *entries); +#endif /* _KUNIT_MOCK_H */
lib/kunit/common-mocks.c +117 -0
123 lines not on this page · raw message
lib/kunit/mock-test.c +40 -0
@@ -243,6 +243,45 @@ static void mock_test_do_expect_default_return(struct kunit *test)KUNIT_EXPECT_EQ (test,0 , expectation->times_called); } +/* +* Method called on naggy mock with no expectations will not fail, but will show +* a warning message +*/ +static void mock_test_naggy_no_expectations_no_fail (struct kunit *test) +{ +struct mock_test_context *ctx = test->priv; +struct kunit *failing_test = ctx->failing_test; +struct mock *mock = ctx->mock; + +int param0 =5 , param1 =-5 ; +static const char *const two_param_types[] = {"int" ,"int" }; +const void *two_params[] = {¶m0, ¶m1}; + +mock_set_default_action (mock, +"add" , + real_add, +kunit_int_return (failing_test,-4 )); + + +KUNIT_EXPECT_CALL (mock_add ( + mock, +kunit_any (failing_test), +kunit_va_format_cmp (failing_test, +kunit_str_contains (failing_test, +"Method was called with no expectations declared" ), +kunit_any (failing_test)))); + + mock->do_expect (mock, +"add" , + real_add, + two_param_types, + two_params, +ARRAY_SIZE (two_params)); +mock_validate_expectations (mock); + +KUNIT_EXPECT_FALSE (test, failing_test->success); +} +static void mock_test_mock_validate_expectations (struct kunit *test) {struct mock_test_context *ctx = test->priv;
@@ -307,6 +346,7 @@ static struct kunit_case mock_test_cases[] = {KUNIT_CASE (mock_test_failed_expect_call_fails_test),KUNIT_CASE (mock_test_do_expect_default_return),KUNIT_CASE (mock_test_mock_validate_expectations), + KUNIT_CASE(mock_test_naggy_no_expectations_no_fail), {} };
Signature · 1 line
2.28.0.1011.ga647a8990f-goog
RFC v2 12/12 kunit: mock: implement nice, strict and naggy mock distinctions
In reply to Daniel LatypovFrom: Brendan Higgins <[email protected]>
Nice mocks only fail when there is an expectation on a method, but none match a given call. Strict mocks only pass when there is a matching expectation for every call. Naggy mocks have the same pass/fail behavior as nice, but report a warning in any case a strict mock would fail.
--- include/kunit/mock.h | 63 ++++++++++++++++ lib/kunit/mock-test.c | 171 ++++++++++++++++++++++++++++++++++++++++++ lib/kunit/mock.c | 10 ++- 3 files changed, 242 insertions(+), 2 deletions(-)
include/kunit/mock.h +63 -0
@@ -95,10 +95,17 @@ struct mock_method {struct list_head expectations; }; +enum mock_type { +MOCK_TYPE_NICE , +MOCK_TYPE_NAGGY , +MOCK_TYPE_STRICT +}; +struct mock {struct kunit_post_condition parent;struct kunit *test;struct list_head methods; +enum mock_type type;/* TODO([email protected]): add locking to do_expect. */ const void *(*do_expect)(struct mock *mock, const char *method_name,
@@ -108,6 +115,8 @@ struct mock { int len); }; +#define DEFAULT_MOCK_TYPE MOCK_TYPE_NAGGY +void mock_init_ctrl (struct kunit *test,struct mock *mock);void mock_validate_expectations (struct mock *mock);
@@ -125,6 +134,60 @@ struct mock_expectation *mock_add_matcher(struct mock *mock,#define MOCK (name) name##_mock +/** +* STRICT_MOCK() - sets the mock to be strict and returns the mock +* @mock: the mock +* +* For an example, see ``The Nice, the Strict, and the Naggy`` under +* ``Using KUnit``. +*/ +#define STRICT_MOCK (mock) \ +({ \ + mock_get_ctrl(mock)->type = MOCK_TYPE_STRICT; \ + mock; \ +}) + +static inline bool is_strict_mock (struct mock *mock) +{ +return mock->type ==MOCK_TYPE_STRICT ; +} + +/** +* NICE_MOCK() - sets the mock to be nice and returns the mock +* @mock: the mock +* +* For an example, see ``The Nice, the Strict, and the Naggy`` under +* ``Using KUnit``. +*/ +#define NICE_MOCK (mock) \ +({ \ + mock_get_ctrl(mock)->type = MOCK_TYPE_NICE; \ + mock; \ +}) + +static inline bool is_nice_mock (struct mock *mock) +{ +return mock->type ==MOCK_TYPE_NICE ; +} + +/** +* NAGGY_MOCK() - sets the mock to be naggy and returns the mock +* @mock: the mock +* +* For an example, see ``The Nice, the Strict, and the Naggy`` under +* ``Using KUnit``. +*/ +#define NAGGY_MOCK (mock) \ +({ \ + mock_get_ctrl(mock)->type = MOCK_TYPE_NAGGY; \ + mock; \ +}) + +static inline bool is_naggy_mock (struct mock *mock) +{ +return mock->type ==MOCK_TYPE_NAGGY ; +} +/** * KUNIT_EXPECT_CALL() - Declares a *call expectation* on a mock function. * @expectation_call: a mocked method or function with parameters replaced with
lib/kunit/mock-test.c +171 -0
202 lines not on this page · raw message
lib/kunit/mock.c +8 -2
@@ -85,6 +85,7 @@ void mock_init_ctrl(struct kunit *test, struct mock *mock) mock->test = test;INIT_LIST_HEAD (&mock->methods); mock->do_expect = mock_do_expect; + mock->type =DEFAULT_MOCK_TYPE ; mock->parent.validate = mock_validate_wrapper;list_add_tail (&mock->parent.node, &test->post_conditions); }
@@ -283,7 +284,12 @@ static struct mock_expectation *mock_apply_expectations(mock_add_method_expectation_error (test, stream,"Method was called with no expectations declared: " , mock, method, type_names, params, len); -kunit_stream_commit (stream); +if (is_strict_mock (mock)) +fail_and_flush (test, stream); +else if (is_naggy_mock (mock)) +kunit_stream_commit (stream); +else +kunit_stream_clear (stream);return NULL ; }
@@ -313,7 +319,7 @@ static struct mock_expectation *mock_apply_expectations( } } -if (expectations_all_saturated) { +if (expectations_all_saturated && !is_nice_mock (mock)) {mock_add_method_expectation_error (test, stream,"Method was called with fully saturated expectations: " , mock, method, type_names, params, len);
Signature · 1 line
2.28.0.1011.ga647a8990f-goog
+Joel Stanley +Daniel Vetter
If I remember correctly, both of you said you were interested in mocking on KUnit. This RFC only has some of the mocking features that I mentioned previously, but I would still like to get your thoughts.
Quoted 125 lines · Daniel Latypov
# Background
KUnit currently lacks any first-class support for mocking. For an overview and discussion on the pros and cons, see
https://martinfowler.com/articles/mocksArentStubs.htmlThis patch set introduces the basic machinery needed for mocking:
setting and validating expectations, setting default actions, etc.Using that basic infrastructure, we add macros for "class mocking", as it's probably the easiest type of mocking to start with.
## Class mocking
By "class mocking", we're referring mocking out function pointers stored in structs like:
struct sender { int (*send)(struct sender *sender, int data);};
or in ops structs
struct sender {
structsend_ops*ops; // containssend
};After the necessary DEFINE_* macros, we can then write code like
struct MOCK(sender)mock_sender=CONSTRUCT_MOCK(sender, test);/* Fake an error for a specific input. */ handle = KUNIT_EXPECT_CALL(send(<omitted>, kunit_int_eq(42))); handle->action = kunit_int_return(test, -EINVAL);/* Pass the mocked object to some code under test. */
KUNIT_EXPECT_EQ(test, -EINVAL, send_message(...));I.e. the goal is to make it easier to test
1) with less dependencies (we don't need to setup a realsender)
2) unusual/error conditions more easily.In the future, we hope to build upon this to support mocking in more contexts, e.g. standalone funcs, etc.
# TODOs
## Naming
This introduces a number of new macros for dealing with mocks, e.g:
DEFINE_STRUCT_CLASS_MOCK(METHOD(foo), CLASS(example),RETURNS(int), PARAMS(struct example *, int));...
KUNIT_EXPECT_CALL(foo(mock_get_ctrl(mock_example), ...);
For consistency, we could prefix everything with KUNIT, e.g.KUNIT_DEFINE_STRUCT_CLASS_MOCKandkunit_mock_get_ctrl, but it feels like the names might be long enough that they would hinder readability.## Usage
For now the only use of class mocking is inkunit-example-test.cAs part of changing this from an RFC to a real patch set, we're hoping to include at least one example.Pointers to bits of code where this would be useful that aren't too hairy would be appreciated.
E.g. could easily add a test fortools/perf/ui/progress.h, e.g. thatui_progress__init()callsui_progress_ops.init(), but that likely isn't useful to anyone.---
v2:
* Passstruct kunit *to mock init's to allow allocating ops structs.
* Update kunit-example-test.cc to do so as a more realistic example.
v1: https://lore.kernel.org/linux-kselftest/[email protected]/
---Brendan Higgins (9):
kunit: test: addkunit_streamastd::streamlike logger
kunit: test: add concept of post conditions
checkpatch: add support for struct MOCK(foo) syntax
kunit: mock: add parameter list manipulation macros
kunit: mock: add internal mock infrastructure
kunit: mock: add basic matchers and actions
kunit: mock: add class mocking support
kunit: mock: add struct param matcher
kunit: mock: implement nice, strict and naggy mock distinctionsDaniel Latypov (2):
Revert "kunit: movestring-stream.hto lib/kunit"
kunit: exposekunit_set_failure()for use by mockingMarcelo Schmitt (1):
kunit: mock: add macro machinery to pick correct format argsinclude/kunit/assert.h | 3 +- include/kunit/kunit-stream.h | 94 +++ include/kunit/mock.h | 902 +++++++++++++++++++++++++ include/kunit/params.h | 305 +++++++++ {lib => include}/kunit/string-stream.h | 2 + include/kunit/test.h | 9 + lib/kunit/Makefile | 9 +- lib/kunit/assert.c | 2 - lib/kunit/common-mocks.c | 409 +++++++++++ lib/kunit/kunit-example-test.c | 98 +++ lib/kunit/kunit-stream.c | 110 +++ lib/kunit/mock-macro-test.c | 241 +++++++ lib/kunit/mock-test.c | 531 +++++++++++++++ lib/kunit/mock.c | 370 ++++++++++ lib/kunit/string-stream-test.c | 3 +- lib/kunit/string-stream.c | 5 +- lib/kunit/test.c | 15 +- scripts/checkpatch.pl | 4 + 18 files changed, 3099 insertions(+), 13 deletions(-) create mode 100644 include/kunit/kunit-stream.h create mode 100644 include/kunit/mock.h create mode 100644 include/kunit/params.h rename {lib => include}/kunit/string-stream.h (95%) create mode 100644 lib/kunit/common-mocks.c create mode 100644 lib/kunit/kunit-stream.c create mode 100644 lib/kunit/mock-macro-test.c create mode 100644 lib/kunit/mock-test.c create mode 100644 lib/kunit/mock.cbase-commit:
10b82d5176488acee2820e5a2cf0f2ec5c3488b6--
2.28.0.1011.ga647a8990f-goog