summaryrefslogtreecommitdiff
path: root/common/test_util.c
diff options
context:
space:
mode:
authorPaul Fagerburg <pfagerburg@google.com>2020-05-05 20:00:54 -0600
committerCommit Bot <commit-bot@chromium.org>2020-05-11 19:32:40 +0000
commitbc8a9391e7ab32f8ace80e831d28b684737ca499 (patch)
tree57ad2f0c38d30c0f50d341eafe864a3f7790a5bf /common/test_util.c
parent12c3acd63fd8d73d8254afb48dc72f1deae10142 (diff)
downloadchrome-ec-bc8a9391e7ab32f8ace80e831d28b684737ca499.tar.gz
ec: fix `make coverage` code coverage reporting
Fixed problems that were preventing us from building the unit tests with code coverage testing via `make coverage`. * Changed test_util so that programs will cleanly exit on SIGTERM. * Changed run_host_test to wait for the child process to exit, and only proc.kill() if it times out, so the child process will generate code coverage output files on exit. * Changed Makefile.toolchain to use the --coverage flag for both compile and link. * Changed build.mk and Makefile.rules to exclude certain tests from code coverage because they were causing failures either during the individual stage of code coverage, or generating the overall report. BUG=b:143065231 BRANCH=none TEST=`make coverage` produces results Signed-off-by: Paul Fagerburg <pfagerburg@chromium.org> Change-Id: I8575013551ce1dba3fd249cd933a3cf6d110db8d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2186853 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Diffstat (limited to 'common/test_util.c')
-rw-r--r--common/test_util.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/common/test_util.c b/common/test_util.c
index 2d2d3ba462..6ad1474700 100644
--- a/common/test_util.c
+++ b/common/test_util.c
@@ -5,7 +5,8 @@
* Test utilities.
*/
-#ifdef TEST_COVERAGE
+#if defined(TEST_COVERAGE) || defined(TEST_HOSTTEST)
+/* We need signal() and exit() only when building to run on the host. */
#include <signal.h>
#include <stdlib.h>
#endif
@@ -46,7 +47,14 @@ void emulator_flush(void)
{
__gcov_flush();
}
+#else
+void emulator_flush(void)
+{
+}
+#endif
+#if defined(TEST_HOSTTEST) || defined(TEST_COVERAGE)
+/* Host-based unit tests need to exit(0) when they receive a SIGTERM. */
void test_end_hook(int sig)
{
emulator_flush();
@@ -58,10 +66,6 @@ void register_test_end_hook(void)
signal(SIGTERM, test_end_hook);
}
#else
-void emulator_flush(void)
-{
-}
-
void register_test_end_hook(void)
{
}