diff options
author | Craig Hesling <hesling@chromium.org> | 2019-07-25 14:58:23 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-07-31 22:16:40 +0000 |
commit | 09d4632e694ab69c1785fdad910025990a37f15d (patch) | |
tree | b89d9b570ec83e08a3a2fc5eb5af86b4bcfdb3cb /include | |
parent | fec7f289d57a4382fa508a8f66615d7f9767e99b (diff) | |
download | chrome-ec-09d4632e694ab69c1785fdad910025990a37f15d.tar.gz |
mock: Add mock structure for fuzzers and tests
This introduces the common/mock and include/mock directories
which hold mock implementations of other common libraries.
The general idea it to create mocks which can be used in
simple scenarios, by providing meaningful default return
values and functionality, and more complicated scenarios
like fuzzers, where the return values need to continuously change.
The build system has been adapted to allow the inclusion of
a new .mocklist file for tests and fuzzers. This file specifies
exactly which mocks will be pulled into the build for a given
test/fuzz. In order to maintain cleanliness, this file is optional.
Examples:
* http://crrev.com/c/1682945/17 makes use of three different mocks,
one of which is the rollback mock.
* An upcoming rollback unit test ( http://crrev.com/c/1686460 ),
needs to pull in mocks that support the rollback interface, but
explicitly cannot pull in the rollback mock.
BRANCH=none
BUG=b:116065496
TEST=make buildall -j
Change-Id: Ib87b1a93b6d73309afaf7115276ead49218598ff
Signed-off-by: Craig Hesling <hesling@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1719569
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/config.h | 14 | ||||
-rw-r--r-- | include/mock_filter.h | 22 |
2 files changed, 36 insertions, 0 deletions
diff --git a/include/config.h b/include/config.h index 5b7c6661ce..ba18c558a5 100644 --- a/include/config.h +++ b/include/config.h @@ -3334,6 +3334,20 @@ #define CONFIG_TASK_PROFILING /*****************************************************************************/ +/* Mock config */ + +/* + * List of mock implementations to pull into the build. + * + * This should contain a flat list of MOCK(the-mock-name) elements. + * + * This is defined in the following two files: + * test/{testname}.mocklist + * fuzz/{fuzzname}.mocklist + */ +#undef CONFIG_TEST_MOCK_LIST + +/*****************************************************************************/ /* Temperature sensor config */ /* Compile common code for temperature sensor support */ diff --git a/include/mock_filter.h b/include/mock_filter.h new file mode 100644 index 0000000000..113c227a3b --- /dev/null +++ b/include/mock_filter.h @@ -0,0 +1,22 @@ +/* Copyright 2019 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* + * Filter mocklists for makefile relevant items. + * A mocklist is the .mocklist file in test/ and fuzz/ directories. + * See common/mock/README.md for more information. + */ + +#ifndef __CROS_EC_MOCK_FILTER_H +#define __CROS_EC_MOCK_FILTER_H + +/* If included directly from Makefile, dump mock list. */ +#ifdef _MAKEFILE +#define MOCK(n) n +CONFIG_TEST_MOCK_LIST +#endif + + +#endif /* __CROS_EC_MOCK_FILTER_H */ |