mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-05 22:41:44 +00:00
Make target for test coverage report generation
By 'make coverage', lcov is used to generate test coverage report in HTML format stored in coverage_rpt folder. BUG=chrome-os-partner:19235 TEST=Generate a report. BRANCH=None Change-Id: I44142eaaeb897cf09179764781120370920144cd Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/58203
This commit is contained in:
@@ -84,7 +84,7 @@ $(host-test-targets): host-%:
|
||||
@set -e ; \
|
||||
echo " BUILD host - build/host/$*" ; \
|
||||
$(MAKE) --no-print-directory BOARD=host PROJECT=$* \
|
||||
V=$(V) out=build/host/$* TEST_BUILD=y EMU_BUILD=y \
|
||||
V=$(V) out=build/host/$* TEST_BUILD=y EMU_BUILD=y $(TEST_FLAG) \
|
||||
CROSS_COMPILE= build/host/$*/$*.exe
|
||||
|
||||
$(run-test-targets): run-%: host-%
|
||||
@@ -93,6 +93,24 @@ $(run-test-targets): run-%: host-%
|
||||
hosttests: $(host-test-targets)
|
||||
runtests: $(run-test-targets)
|
||||
|
||||
cov-test-targets=$(foreach t,$(test-list-host),build/host/$(t).info)
|
||||
bldversion=$(shell (./util/getversion.sh ; echo VERSION) | $(CPP) -P)
|
||||
|
||||
# lcov fails when multiple instances run at the same time.
|
||||
# We need to run them sequentially by using flock
|
||||
cmd_lcov=flock .lcov_lock -c "lcov -q -o $@ -c -d build/host/$*"
|
||||
cmd_report_cov=genhtml -q -o build/host/coverage_rpt -t \
|
||||
"EC Unittest "$(bldversion) $^
|
||||
|
||||
build/host/%.info: run-%
|
||||
$(call quiet,lcov,COV )
|
||||
|
||||
coverage: TEST_FLAG=TEST_COVERAGE=y
|
||||
coverage: $(cov-test-targets)
|
||||
$(call quiet,report_cov,REPORT )
|
||||
|
||||
.PHONY: coverage
|
||||
|
||||
$(out)/firmware_image.lds: common/firmware_image.lds.S
|
||||
$(call quiet,lds,LDS )
|
||||
$(out)/%.lds: core/$(CORE)/ec.lds.S
|
||||
|
||||
@@ -30,11 +30,14 @@ CFLAGS_TEST=$(if $(TEST_BUILD),-DTEST_BUILD \
|
||||
-DTEST_TASKFILE=$(PROJECT).tasklist,) \
|
||||
$(if $(EMU_BUILD),-DEMU_BUILD) \
|
||||
$(if $($(PROJECT)-scale),-DTEST_TIME_SCALE=$($(PROJECT)-scale))
|
||||
CFLAGS_COVERAGE=$(if $(TEST_COVERAGE),-fprofile-arcs -ftest-coverage \
|
||||
-DTEST_COVERAGE,)
|
||||
CFLAGS_DEFINE=-DOUTDIR=$(out) -DCHIP=$(CHIP) -DBOARD_TASKFILE=ec.tasklist \
|
||||
-DBOARD=$(BOARD) -DBOARD_$(BOARD) -DCORE=$(CORE) \
|
||||
-DCHIP_$(CHIP) -DCHIP_VARIANT=$(CHIP_VARIANT) \
|
||||
-DCHIP_VARIANT_$(CHIP_VARIANT) -DPROJECT=$(PROJECT)
|
||||
CPPFLAGS=$(CFLAGS_DEFINE) $(CFLAGS_INCLUDE) $(CFLAGS_TEST) $(EXTRA_CFLAGS)
|
||||
CPPFLAGS=$(CFLAGS_DEFINE) $(CFLAGS_INCLUDE) $(CFLAGS_TEST) \
|
||||
$(EXTRA_CFLAGS) $(CFLAGS_COVERAGE)
|
||||
CFLAGS=$(CPPFLAGS) $(CFLAGS_CPU) $(CFLAGS_DEBUG) $(CFLAGS_WARN) $(CFLAGS_y)
|
||||
|
||||
FTDIVERSION=$(shell $(PKG_CONFIG) --modversion libftdi1 2>/dev/null)
|
||||
@@ -51,4 +54,5 @@ BUILD_CFLAGS= $(LIBFTDI_CFLAGS) $(CPPFLAGS) -O3 $(CFLAGS_DEBUG) $(CFLAGS_WARN)
|
||||
HOST_CFLAGS=$(CPPFLAGS) -O3 $(CFLAGS_DEBUG) $(CFLAGS_WARN)
|
||||
LDFLAGS=-nostdlib -X
|
||||
BUILD_LDFLAGS=$(LIBFTDI_LDLIBS)
|
||||
HOST_TEST_LDFLAGS=-T core/host/host_exe.lds -lrt -pthread
|
||||
HOST_TEST_LDFLAGS=-T core/host/host_exe.lds -lrt -pthread \
|
||||
$(if $(TEST_COVERAGE),-fprofile-arcs,)
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
* Test utilities.
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "console.h"
|
||||
#include "test_util.h"
|
||||
#include "util.h"
|
||||
@@ -14,11 +17,40 @@ int __test_error_count;
|
||||
/* Weak reference function as an entry point for unit test */
|
||||
test_mockable void run_test(void) { }
|
||||
|
||||
#ifdef TEST_COVERAGE
|
||||
extern void __gcov_flush(void);
|
||||
|
||||
void test_end_hook(int sig)
|
||||
{
|
||||
__gcov_flush();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void register_test_end_hook(void)
|
||||
{
|
||||
signal(SIGTERM, test_end_hook);
|
||||
}
|
||||
#else
|
||||
void register_test_end_hook(void)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
void test_reset(void)
|
||||
{
|
||||
__test_error_count = 0;
|
||||
}
|
||||
|
||||
void test_pass(void)
|
||||
{
|
||||
ccprintf("Pass!\n");
|
||||
}
|
||||
|
||||
void test_fail(void)
|
||||
{
|
||||
ccprintf("Fail!\n");
|
||||
}
|
||||
|
||||
void test_print_result(void)
|
||||
{
|
||||
if (__test_error_count)
|
||||
|
||||
@@ -8,11 +8,14 @@
|
||||
#include "flash.h"
|
||||
#include "hooks.h"
|
||||
#include "task.h"
|
||||
#include "test_util.h"
|
||||
#include "timer.h"
|
||||
#include "uart.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
register_test_end_hook();
|
||||
|
||||
flash_pre_init();
|
||||
|
||||
timer_init();
|
||||
|
||||
@@ -62,10 +62,16 @@
|
||||
return EC_ERROR_UNKNOWN; \
|
||||
} while (0)
|
||||
|
||||
void register_test_end_hook(void);
|
||||
|
||||
void run_test(void);
|
||||
|
||||
void test_reset(void);
|
||||
|
||||
void test_pass(void);
|
||||
|
||||
void test_fail(void);
|
||||
|
||||
void test_print_result(void);
|
||||
|
||||
int test_get_error_count(void);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "console.h"
|
||||
#include "common.h"
|
||||
#include "task.h"
|
||||
#include "test_util.h"
|
||||
#include "timer.h"
|
||||
#include "util.h"
|
||||
|
||||
@@ -108,7 +109,7 @@ int mutex_main_task(void *unused)
|
||||
rdelay = prng(rdelay);
|
||||
}
|
||||
|
||||
ccprintf("Pass!\n");
|
||||
test_pass();
|
||||
task_wait_event(0);
|
||||
|
||||
return EC_SUCCESS;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "common.h"
|
||||
#include "console.h"
|
||||
#include "task.h"
|
||||
#include "test_util.h"
|
||||
#include "timer.h"
|
||||
#include "util.h"
|
||||
|
||||
@@ -31,9 +32,9 @@ int TaskAbc(void *data)
|
||||
if (myid == 2 && wake_count[myid] == TEST_COUNT) {
|
||||
if (wake_count[0] == TEST_COUNT &&
|
||||
wake_count[1] == TEST_COUNT)
|
||||
ccputs("Pass!\n");
|
||||
test_pass();
|
||||
else
|
||||
ccputs("Fail!\n");
|
||||
test_fail();
|
||||
wake_count[0] = wake_count[1] = wake_count[2] = 0;
|
||||
task_wait_event(-1);
|
||||
} else {
|
||||
|
||||
@@ -45,6 +45,8 @@ def RunOnce(test_name, log, timeout_secs):
|
||||
return RESULT_ID_REBOOT
|
||||
else:
|
||||
raise
|
||||
finally:
|
||||
child.kill(15)
|
||||
|
||||
log = StringIO()
|
||||
tee_log = Tee(log)
|
||||
|
||||
Reference in New Issue
Block a user