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 /Makefile | |
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 'Makefile')
-rw-r--r-- | Makefile | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -188,6 +188,29 @@ $(foreach c,$(_tsk_cfg_rw) $(_flag_cfg_rw),$(eval $(c)=rw)) $(foreach c,$(_tsk_cfg_ro) $(_flag_cfg_ro),$(eval $(c)=ro)) $(foreach c,$(_tsk_cfg) $(_flag_cfg),$(eval $(c)=y)) +# Fetch list of mocks from .mocklist files for tests and fuzzers. +# The following will transform the the list of mocks into +# HAS_MOCK_<NAME> for use in the build systems and CPP, +# similar to task definitions. +_mock_lst_flags := $(if $(TEST_FUZZ),-Ifuzz,-Itest) -DTEST_BUILD=$(EMPTY) \ + -imacros $(PROJECT).mocklist \ + -I$(BDIR) -DBOARD_$(UC_BOARD)=$(EMPTY) -I$(BASEDIR) \ + -DBASEBOARD_$(UC_BASEBOARD)=$(EMPTY) \ + -D_MAKEFILE=$(EMPTY) +_mock_file := $(if $(TEST_FUZZ),fuzz,test)/$(PROJECT).mocklist + +# If test/fuzz build and mockfile exists, source the list of +# mocks from mockfile. +_mock_lst := +ifneq ($(and $(TEST_BUILD),$(wildcard $(_mock_file))),) + _mock_lst += $(shell $(CPP) -P $(_mock_lst_flags) \ + include/mock_filter.h) +endif + +_mock_cfg := $(foreach t,$(_mock_lst) ,HAS_MOCK_$(t)) +CPPFLAGS += $(foreach t,$(_mock_cfg),-D$(t)=$(EMPTY)) +$(foreach c,$(_mock_cfg),$(eval $(c)=y)) + ifneq "$(CONFIG_COMMON_RUNTIME)" "y" _irq_list:=$(shell $(CPP) $(CPPFLAGS) -P -Ichip/$(CHIP) -I$(BASEDIR) \ -I$(BDIR) -D"ENABLE_IRQ(x)=EN_IRQ x" \ |