summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2023-03-16 14:17:14 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-03-21 00:48:29 +0000
commit45c25c16ae0d66204eb8bc4a6991bbaeae29b4e5 (patch)
tree58164e949ac6ef2d7df48af847816fdc4835280b
parenta1766789aaa5d7b4e00713617dc8b3c61d173c56 (diff)
downloadchrome-ec-45c25c16ae0d66204eb8bc4a6991bbaeae29b4e5.tar.gz
third_party: Add option to build and link googletest
When CONFIG_GOOGLETEST is enabled, the googletest library will be built and linked into the test images. BRANCH=none BUG=b:254530679 TEST=make BOARD=bloonchipper test-fpsensor_hw -j Cq-Depend: chrome-internal:5548068 Change-Id: I969599ed441415fd809b08396aefcfa92275fbcd Signed-off-by: Tom Hughes <tomhughes@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4348152 Reviewed-by: Andrea Grandi <agrandi@google.com>
-rw-r--r--include/config.h5
-rw-r--r--third_party/rules.mk40
-rw-r--r--util/config_allowed.txt1
3 files changed, 46 insertions, 0 deletions
diff --git a/include/config.h b/include/config.h
index 59900a7fcb..6d374ef53b 100644
--- a/include/config.h
+++ b/include/config.h
@@ -5848,6 +5848,11 @@
*/
#define CONFIG_HOST_INTERFACE_ESPI_DEFAULT_VW_WIDTH_US 65
+/*
+ * Build and link *test* images with googletest.
+ */
+#undef CONFIG_GOOGLETEST
+
/*****************************************************************************/
/*
* Include board and core configs, since those hold the CONFIG_ constants for a
diff --git a/third_party/rules.mk b/third_party/rules.mk
index 57707d87dd..4b64b82310 100644
--- a/third_party/rules.mk
+++ b/third_party/rules.mk
@@ -55,3 +55,43 @@ $(third-party-test-targets): LDFLAGS_EXTRA += $(CRYPTOC_LDFLAGS)
$(third-party-test-targets): $(out)/cryptoc/libcryptoc.a
endif # CONFIG_LIBCRYPTOC
+
+# Build and link against googletest in *test* builds if configured.
+ifeq ($(TEST_BUILD),y)
+ifeq ($(CONFIG_GOOGLETEST),y)
+
+# The googletest path can be overridden on invocation. For example:
+# $ make GOOGLETEST_DIR=~/src/googletest BOARD=bloonchipper
+GOOGLETEST_DIR ?= $(realpath ../../third_party/googletest)
+GOOGLETEST_INSTALL_DIR := $(realpath $(out))/googletest/install
+CMAKE_TOOLCHAIN_FILE := $(CURDIR)/cmake/toolchain-armv7m.cmake
+
+GOOGLETEST_CFLAGS := -I$(GOOGLETEST_INSTALL_DIR)/include
+GOOGLETEST_LDFLAGS := -L$(GOOGLETEST_INSTALL_DIR)/lib -lgtest
+GOOGLETEST_LIB := $(GOOGLETEST_INSTALL_DIR)/lib/libgtest.a
+
+$(GOOGLETEST_LIB):
+ mkdir -p $(out)/googletest && \
+ cd $(out)/googletest && \
+ cmake -Dgtest_disable_pthreads=ON \
+ -GNinja \
+ -DCMAKE_TOOLCHAIN_FILE=$(CMAKE_TOOLCHAIN_FILE) \
+ -DCMAKE_INSTALL_PREFIX=$(GOOGLETEST_INSTALL_DIR) \
+ $(GOOGLETEST_DIR) && \
+ cmake --build . && \
+ cmake --install .
+
+# On-device tests.
+third-party-test-targets=$(foreach test,$(test-list-y),\
+ $(out)/RW/$(test).RW.elf $(out)/RO/$(test).RO.elf)
+$(third-party-test-targets): LDFLAGS_EXTRA += $(GOOGLETEST_LDFLAGS)
+$(third-party-test-targets): CFLAGS += $(GOOGLETEST_CFLAGS)
+$(third-party-test-targets): $(GOOGLETEST_LIB)
+
+# Test files can include googletest headers, so the headers need to be
+# installed first.
+$(ro-objs): $(GOOGLETEST_LIB)
+$(rw-objs): $(GOOGLETEST_LIB)
+
+endif # CONFIG_GOOGLETEST
+endif # TEST_BUILD
diff --git a/util/config_allowed.txt b/util/config_allowed.txt
index a6e2b823b4..b3a2341536 100644
--- a/util/config_allowed.txt
+++ b/util/config_allowed.txt
@@ -438,6 +438,7 @@ CONFIG_GESTURE_TAP_OUTER_WINDOW_T
CONFIG_GESTURE_TAP_SENSOR
CONFIG_GESTURE_TAP_THRES_MG
CONFIG_GMR_TABLET_MODE_CUSTOM
+CONFIG_GOOGLETEST
CONFIG_GPIO_GET_EXTENDED
CONFIG_GPIO_POWER_DOWN
CONFIG_GPOI_EXTENDED