13 Commits

Author SHA1 Message Date
Brendan Higgins
cb3cd75065 kunit: mock: add parameter capturers
Adds the concept of an argument capturer which, when used with a matcher
in an EXPECT_CALL(...), will capture the value of the matching argument.

Change-Id: I9cb7e16a29e02f02c2ba997a94fa98140519ca51
Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
2018-08-14 14:19:31 -07:00
Brendan Higgins
de4a21424c kunit: mock: added the concept of redirect-mockable functions
Similar to the concept of spying in Mockito
(http://static.javadoc.io/org.mockito/mockito-core/2.20.0/org/mockito/Mockito.html#spy-T-),
this adds the concept of redirect-mockable function declarations which
allow a function declared redirect-mockable to be mocked *and* to allow
the mock to redirect to the original function definition.

Change-Id: I36577b240f72a340732ad86bdd6d8444a5546ef3
Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
2018-08-14 14:19:31 -07:00
Brendan Higgins
314836f8ae kunit: mock: added support for arbitrary function mocking
Up to this point KUnit only supported method style function mocking
where there was some type of class or context object and the function
was only accessed via a pointer.

This adds support for mocking any function via the __mockable attribute.

Change-Id: I22f325a0fda3d16f5fb22f07332848feaa196b41
Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
2018-08-14 14:19:30 -07:00
Brendan Higgins
27d4b89a42 kunit: mock: add ability to mock functions with void context
Adds ability to mock functions with a void* context object.

Change-Id: I1e2f6ba92809d9160b4d5b40f36f7423d3164e32
Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
2018-08-14 14:19:30 -07:00
Felix Guo
9968a6fad0 kunit: mock: implemented nice, strict and naggy mock distinctions
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.

Change-Id: I87017601291ba4346b6f16b77b208eeb97b7674f
Signed-off-by: Felix Guo <felixguoxiuping@gmail.com>
Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
2018-08-14 14:19:30 -07:00
Brendan Higgins
8214dbf2ed kunit: mock: added parameter formatters
Added parameter formatters which provide string formatting for
parameters that have no matchers to be matched against.

Change-Id: Iafe3c676bc7cff4ec8a9d063fd17bcc99b4ded86
Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
2018-08-14 14:19:30 -07:00
Brendan Higgins
6316ace3e4 kunit: mock: added struct param matcher
Added parameter matcher builder for matching struct values.

Change-Id: I6aa4ca9706528b30c1cf23fbf0a6c66ac6245d58
Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
2018-08-14 14:19:30 -07:00
Brendan Higgins
ed7958db0b kunit: mock: added basic mock infrastructure
Introduces 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.

Change-Id: Id9d535be1da95dd42844c43f6dfcca3a7441bd81
Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
2018-08-14 14:19:29 -07:00
Brendan Higgins
153374323a kunit: mock: added parameter list minipulation macros
Adds macros for parsing and manipulating parameter lists needed for
generating mocks.

Change-Id: I60cf255753ab656b9c50bc7da67dc1438fd8b90f
Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
2018-08-14 14:19:29 -07:00
Brendan Higgins
dd3d334bb0 kunit: test: added concept of post conditions
Adds a way to specify that certain conditions must be met at the end of
a test case.

Change-Id: I4f90a68bbedcbb71e2fe7a0353d22885f430f54f
Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
2018-08-14 14:17:24 -07:00
Brendan Higgins
dcd3e8bc1f kunit: test: added concept of initcalls
Added a way to add plugins that require a test module to be loaded
during initialization.

Change-Id: I1d03f8249631a91b0334ccbe0b06889f3678caff
Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
2018-08-14 14:17:24 -07:00
Brendan Higgins
1b54a964ce kunit: test: added the concept of assertions
Added support for assertions which are like expectations except the test
terminates if the assertion is not satisfied.

Change-Id: I7fdcf4d0b602f2a5642ff50d2637e8ddd293ce7c
Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
2018-08-14 14:17:23 -07:00
Brendan Higgins
eee7f4a3f8 kunit: test: adds KUnit, a basic unit testing library for Linux
Adds the core of KUnit along with a minimal set of features. In
particular, this adds:
 - the base reporting infrastructure for reporting test results.
 - the concept of test modules and test cases, which is how tests are
   specified and organized.
 - infrastructure for running test modules and cases on UML.
 - expectations, which is how properties to be verified by a test are
   asserted.

Change-Id: I61ea0abe30fd0f1679e5cd16d0c101b956380d52
Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
2018-08-14 14:11:29 -07:00