Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0-only |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 2 | |
Jakub Czapiga | eaf5ff3 | 2021-08-09 14:20:28 +0200 | [diff] [blame] | 3 | testsrc := $(top)/tests |
Paul Fagerburg | de6cbac | 2021-05-11 09:56:48 -0600 | [diff] [blame] | 4 | |
| 5 | # Place the build output in one of two places depending on COV, so that code |
| 6 | # built with code coverage never mixes with code built without code coverage. |
| 7 | ifeq ($(COV),1) |
Jakub Czapiga | eaf5ff3 | 2021-08-09 14:20:28 +0200 | [diff] [blame] | 8 | testobj := $(obj)/coverage |
Paul Fagerburg | de6cbac | 2021-05-11 09:56:48 -0600 | [diff] [blame] | 9 | else |
Jakub Czapiga | eaf5ff3 | 2021-08-09 14:20:28 +0200 | [diff] [blame] | 10 | testobj := $(obj)/tests |
Paul Fagerburg | de6cbac | 2021-05-11 09:56:48 -0600 | [diff] [blame] | 11 | endif |
| 12 | |
Jakub Czapiga | eaf5ff3 | 2021-08-09 14:20:28 +0200 | [diff] [blame] | 13 | cmockasrc := 3rdparty/cmocka |
| 14 | cmockaobj := $(objutil)/cmocka |
| 15 | coverage_dir := coverage_reports |
Jan Dabros | 7f00dba | 2020-05-22 09:57:17 +0200 | [diff] [blame] | 16 | |
| 17 | CMOCKA_LIB := $(cmockaobj)/src/libcmocka.so |
| 18 | |
Jakub Czapiga | eaf5ff3 | 2021-08-09 14:20:28 +0200 | [diff] [blame] | 19 | CMAKE := cmake |
| 20 | OBJCOPY ?= objcopy |
| 21 | OBJDUMP ?= objdump |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 22 | |
Jakub Czapiga | eaf5ff3 | 2021-08-09 14:20:28 +0200 | [diff] [blame] | 23 | TEST_DEFAULT_CONFIG := $(top)/configs/config.emulation_qemu_x86_i440fx |
| 24 | TEST_DOTCONFIG := $(testobj)/.config |
Jakub Czapiga | 5c3b05e | 2021-04-28 16:50:51 +0200 | [diff] [blame] | 25 | TEST_KCONFIG_AUTOHEADER := $(testobj)/config.src.h |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 26 | TEST_KCONFIG_AUTOCONFIG := $(testobj)/auto.conf |
| 27 | TEST_KCONFIG_DEPENDENCIES := $(testobj)/auto.conf.cmd |
Jakub Czapiga | 21863e3 | 2021-07-15 12:54:27 +0200 | [diff] [blame] | 28 | TEST_KCONFIG_SPLITCONFIG := $(testobj)/config/ |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 29 | TEST_KCONFIG_TRISTATE := $(testobj)/tristate.conf |
| 30 | |
Jakub Czapiga | eaf5ff3 | 2021-08-09 14:20:28 +0200 | [diff] [blame] | 31 | TEST_CFLAGS := -include $(src)/include/kconfig.h \ |
Julius Werner | 2174481 | 2020-05-04 17:44:04 -0700 | [diff] [blame] | 32 | -include $(src)/commonlib/bsd/include/commonlib/bsd/compiler.h \ |
| 33 | -include $(src)/include/rules.h |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 34 | |
| 35 | # Include generic test mock headers, before original ones |
Julius Werner | 2174481 | 2020-05-04 17:44:04 -0700 | [diff] [blame] | 36 | TEST_CFLAGS += -I$(testsrc)/include/mocks -I$(testsrc)/include |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 37 | |
Jakub Czapiga | d0bd012 | 2021-08-09 15:51:37 +0200 | [diff] [blame] | 38 | TEST_CFLAGS += -I$(src) -I$(src)/include -I$(src)/commonlib/include \ |
| 39 | -I$(src)/commonlib/bsd/include -I$(src)/arch/x86/include \ |
| 40 | -I$(top)/3rdparty/vboot/firmware/include |
Julius Werner | 1e14de8 | 2020-06-10 15:35:08 -0700 | [diff] [blame] | 41 | |
| 42 | # Note: This is intentionally just a subset of the warnings in the toplevel |
| 43 | # Makefile.inc. We don't need to be as strict with test code, and things like |
| 44 | # -Wmissing-prototypes just make working with the test framework cumbersome. |
| 45 | # Only put conservative warnings here that really detect code that's obviously |
| 46 | # unintentional. |
Julius Werner | e54d784 | 2021-02-16 19:32:24 -0800 | [diff] [blame] | 47 | TEST_CFLAGS += -Wall -Werror -Wundef -Wstrict-prototypes -Wno-inline-asm |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 48 | |
| 49 | # Path for Kconfig autoheader |
| 50 | TEST_CFLAGS += -I$(dir $(TEST_KCONFIG_AUTOHEADER)) |
| 51 | |
Julius Werner | 2540037 | 2020-05-04 17:46:31 -0700 | [diff] [blame] | 52 | TEST_CFLAGS += -std=gnu11 -Os -ffunction-sections -fdata-sections -fno-builtin |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 53 | |
Jakub Czapiga | 084ad93 | 2021-03-25 13:10:31 +0100 | [diff] [blame] | 54 | TEST_CFLAGS += -D__TEST__ |
| 55 | |
Jan Dabros | 7f00dba | 2020-05-22 09:57:17 +0200 | [diff] [blame] | 56 | TEST_CFLAGS += -I$(cmockasrc)/include |
| 57 | |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 58 | # Link against Cmocka |
Jakub Czapiga | eaf5ff3 | 2021-08-09 14:20:28 +0200 | [diff] [blame] | 59 | TEST_LDFLAGS := -L$(cmockaobj)/src -lcmocka -Wl,-rpath=$(cmockaobj)/src |
Jan Dabros | 7f00dba | 2020-05-22 09:57:17 +0200 | [diff] [blame] | 60 | TEST_LDFLAGS += -Wl,--gc-sections |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 61 | |
Julius Werner | 84446e6 | 2021-02-12 17:37:27 -0800 | [diff] [blame] | 62 | # Some memlayout symbols don't work with userspace relocation -- disable it. |
| 63 | TEST_CFLAGS += -fno-pie -fno-pic |
| 64 | TEST_LDFLAGS += -no-pie |
| 65 | |
Paul Fagerburg | de6cbac | 2021-05-11 09:56:48 -0600 | [diff] [blame] | 66 | # Enable code coverage if COV=1 |
| 67 | ifeq ($(COV),1) |
| 68 | TEST_CFLAGS += --coverage |
| 69 | TEST_LDFLAGS += --coverage |
| 70 | endif |
| 71 | |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 72 | # Extra attributes for unit tests, declared per test |
Jakub Czapiga | eaf5ff3 | 2021-08-09 14:20:28 +0200 | [diff] [blame] | 73 | attributes := srcs cflags config mocks stage |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 74 | |
Jakub Czapiga | eaf5ff3 | 2021-08-09 14:20:28 +0200 | [diff] [blame] | 75 | stages := decompressor bootblock romstage smm verstage |
| 76 | stages += ramstage rmodule postcar libagesa |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 77 | |
Jakub Czapiga | eaf5ff3 | 2021-08-09 14:20:28 +0200 | [diff] [blame] | 78 | alltests := |
| 79 | subdirs := tests/arch tests/acpi tests/commonlib tests/console tests/cpu |
| 80 | subdirs += tests/device tests/drivers tests/ec tests/lib tests/mainboard |
| 81 | subdirs += tests/northbridge tests/security tests/soc tests/southbridge |
| 82 | subdirs += tests/superio tests/vendorcode |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 83 | |
| 84 | define tests-handler |
| 85 | alltests += $(1)$(2) |
| 86 | $(foreach attribute,$(attributes), |
| 87 | $(eval $(1)$(2)-$(attribute) += $($(2)-$(attribute)))) |
| 88 | $(foreach attribute,$(attributes), |
Jakub Czapiga | eaf5ff3 | 2021-08-09 14:20:28 +0200 | [diff] [blame] | 89 | $(eval $(2)-$(attribute) := )) |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 90 | |
| 91 | # Sanity check for stage attribute value |
Jakub Czapiga | eaf5ff3 | 2021-08-09 14:20:28 +0200 | [diff] [blame] | 92 | $(eval $(1)$(2)-stage := $(if $($(1)$(2)-stage),$($(1)$(2)-stage),ramstage)) |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 93 | $(if $(findstring $($(1)$(2)-stage), $(stages)),, |
| 94 | $(error Wrong $(1)$(2)-stage value $($(1)$(2)-stage). \ |
| 95 | Check your $(dir $(1)$(2))Makefile.inc)) |
| 96 | endef |
| 97 | |
Jakub Czapiga | 9bf716e | 2021-08-09 15:00:43 +0200 | [diff] [blame] | 98 | # Copy attributes of one test to another. |
| 99 | # $1 - input test name |
| 100 | # $2 - output test name |
| 101 | copy-test = $(foreach attr,$(attributes), \ |
| 102 | $(eval $(strip $(2))-$(attr) := $($(strip $(1))-$(attr)))) |
| 103 | |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 104 | $(call add-special-class, tests) |
| 105 | $(call evaluate_subdirs) |
| 106 | |
| 107 | # Create actual targets for unit test binaries |
| 108 | # $1 - test name |
| 109 | define TEST_CC_template |
Jakub Czapiga | 5c3b05e | 2021-04-28 16:50:51 +0200 | [diff] [blame] | 110 | |
Julius Werner | ab91407 | 2021-08-17 19:50:22 -0700 | [diff] [blame] | 111 | # Generate custom config.h redefining given config symbols, and declaring mocked |
| 112 | # functions weak. It is important that the compiler already sees that they are |
| 113 | # weak (and they aren't just turned weak at a later stage) to prevent certain |
| 114 | # optimizations that would break if the function gets replaced. (For clang this |
| 115 | # file needs to be marked `system_header` to prevent it from warning about |
| 116 | # #pragma weak entries without a matching function declaration, since there's no |
| 117 | # -Wno-xxx command line option for that.) |
Jakub Czapiga | 203698a | 2021-05-25 15:56:36 +0200 | [diff] [blame] | 118 | $(1)-config-file := $(testobj)/$(1)/config.h |
Jakub Czapiga | 5c3b05e | 2021-04-28 16:50:51 +0200 | [diff] [blame] | 119 | $$($(1)-config-file): $(TEST_KCONFIG_AUTOHEADER) |
| 120 | mkdir -p $$(dir $$@) |
| 121 | printf '// File generated by tests/Makefile.inc\n// Do not change\n' > $$@ |
| 122 | printf '#include <%s>\n\n' "$(notdir $(TEST_KCONFIG_AUTOHEADER))" >> $$@ |
| 123 | for kv in $$($(1)-config); do \ |
| 124 | key="`echo $$$$kv | cut -d '=' -f -1`"; \ |
| 125 | value="`echo $$$$kv | cut -d '=' -f 2-`"; \ |
| 126 | printf '#undef %s\n' "$$$$key" >> $$@; \ |
| 127 | printf '#define %s %s\n\n' "$$$$key" "$$$$value" >> $$@; \ |
| 128 | done |
Julius Werner | ab91407 | 2021-08-17 19:50:22 -0700 | [diff] [blame] | 129 | printf '#ifdef __clang__\n' >> $$@; |
| 130 | printf '#pragma clang system_header\n' >> $$@; |
| 131 | printf '#endif\n' >> $$@; |
| 132 | printf '#ifdef __TEST_SRCOBJ__\n' >> $$@; |
| 133 | for m in $$($(1)-mocks); do \ |
| 134 | printf '#pragma weak %s\n' "$$$$m" >> $$@; \ |
| 135 | done |
| 136 | printf '#endif\n' >> $$@; |
Jakub Czapiga | 5c3b05e | 2021-04-28 16:50:51 +0200 | [diff] [blame] | 137 | |
| 138 | $($(1)-objs): TEST_CFLAGS += -I$$(dir $$($(1)-config-file)) \ |
Jakub Czapiga | 7c6081e | 2021-08-25 16:27:35 +0200 | [diff] [blame^] | 139 | -D__$$(shell echo $$($(1)-stage) | tr '[:lower:]' '[:upper:]')__ \ |
| 140 | -D__TEST_NAME__=\"$(1)\" |
Jakub Czapiga | a7a49e6 | 2021-07-29 13:27:54 +0200 | [diff] [blame] | 141 | |
Julius Werner | ab91407 | 2021-08-17 19:50:22 -0700 | [diff] [blame] | 142 | # Give us a way to distinguish between coreboot source files and test files in code. |
| 143 | $($(1)-srcobjs): TEST_CFLAGS += -D__TEST_SRCOBJ__ |
Jakub Czapiga | a7a49e6 | 2021-07-29 13:27:54 +0200 | [diff] [blame] | 144 | |
| 145 | # Compile sources and apply mocking/wrapping of selected symbols. |
| 146 | # For each listed mock add new symbol with prefix `__real_`, |
| 147 | # and pointing to the same section:address. |
Paul Fagerburg | de6cbac | 2021-05-11 09:56:48 -0600 | [diff] [blame] | 148 | $($(1)-objs): $(testobj)/$(1)/%.o: $$$$*.c $$($(1)-config-file) |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 149 | mkdir -p $$(dir $$@) |
Yu-Ping Wu | 0f88f6f | 2021-07-20 14:32:40 +0800 | [diff] [blame] | 150 | $(HOSTCC) $(HOSTCFLAGS) $$(TEST_CFLAGS) $($(1)-cflags) -MMD \ |
| 151 | -MF $$(basename $$@).d -MT $$@ -c $$< -o $$@.orig |
Jakub Czapiga | a7a49e6 | 2021-07-29 13:27:54 +0200 | [diff] [blame] | 152 | objcopy_wrap_flags=''; \ |
| 153 | for sym in $$($(1)-mocks); do \ |
Julius Werner | ab91407 | 2021-08-17 19:50:22 -0700 | [diff] [blame] | 154 | sym_line="$$$$($(OBJDUMP) -t $$@.orig | grep -E "[0-9a-fA-F]+\\s+w\\s+F\\s+.*\\s$$$$sym$$$$")"; \ |
Jakub Czapiga | a7a49e6 | 2021-07-29 13:27:54 +0200 | [diff] [blame] | 155 | if [ ! -z "$$$$sym_line" ] ; then \ |
| 156 | addr="$$$$(echo \"$$$$sym_line\" | awk '{ print $$$$1 }')"; \ |
| 157 | section="$$$$(echo \"$$$$sym_line\" | awk '{ print $$$$(NF - 2) }')"; \ |
| 158 | objcopy_wrap_flags="$$$$objcopy_wrap_flags --add-symbol __real_$$$${sym}=$$$${section}:0x$$$${addr},function,global"; \ |
| 159 | fi \ |
| 160 | done ; \ |
Julius Werner | ab91407 | 2021-08-17 19:50:22 -0700 | [diff] [blame] | 161 | $(OBJCOPY) $$@.orig $$$$objcopy_wrap_flags $$@ |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 162 | |
Jan Dabros | 7f00dba | 2020-05-22 09:57:17 +0200 | [diff] [blame] | 163 | $($(1)-bin): $($(1)-objs) $(CMOCKA_LIB) |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 164 | $(HOSTCC) $$^ $($(1)-cflags) $$(TEST_LDFLAGS) -o $$@ |
| 165 | |
| 166 | endef |
| 167 | |
| 168 | $(foreach test, $(alltests), \ |
Jakub Czapiga | eaf5ff3 | 2021-08-09 14:20:28 +0200 | [diff] [blame] | 169 | $(eval $(test)-srcobjs := $(addprefix $(testobj)/$(test)/, \ |
Patrick Georgi | ce55ca2 | 2021-06-09 18:37:42 +0200 | [diff] [blame] | 170 | $(patsubst %.c,%.o,$(filter src/%,$($(test)-srcs))))) \ |
Jakub Czapiga | eaf5ff3 | 2021-08-09 14:20:28 +0200 | [diff] [blame] | 171 | $(eval $(test)-objs := $(addprefix $(testobj)/$(test)/, \ |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 172 | $(patsubst %.c,%.o,$($(test)-srcs))))) |
| 173 | $(foreach test, $(alltests), \ |
Jakub Czapiga | eaf5ff3 | 2021-08-09 14:20:28 +0200 | [diff] [blame] | 174 | $(eval $(test)-bin := $(testobj)/$(test)/run)) |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 175 | $(foreach test, $(alltests), \ |
| 176 | $(eval $(call TEST_CC_template,$(test)))) |
| 177 | |
| 178 | $(foreach test, $(alltests), \ |
Jakub Czapiga | eaf5ff3 | 2021-08-09 14:20:28 +0200 | [diff] [blame] | 179 | $(eval all-test-objs += $($(test)-objs))) |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 180 | $(foreach test, $(alltests), \ |
Jakub Czapiga | eaf5ff3 | 2021-08-09 14:20:28 +0200 | [diff] [blame] | 181 | $(eval test-bins += $($(test)-bin))) |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 182 | |
| 183 | DEPENDENCIES += $(addsuffix .d,$(basename $(all-test-objs))) |
| 184 | -include $(DEPENDENCIES) |
| 185 | |
Jan Dabros | 7f00dba | 2020-05-22 09:57:17 +0200 | [diff] [blame] | 186 | # Build cmocka |
| 187 | $(CMOCKA_LIB): |
| 188 | echo "*** Building CMOCKA ***" |
| 189 | mkdir -p $(cmockaobj) |
| 190 | cd $(cmockaobj) && $(CMAKE) $(abspath $(cmockasrc)) |
| 191 | $(MAKE) -C $(cmockaobj) |
| 192 | |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 193 | # Kconfig targets |
| 194 | $(TEST_DOTCONFIG): |
| 195 | mkdir -p $(dir $@) |
| 196 | cp $(TEST_DEFAULT_CONFIG) $(TEST_DOTCONFIG) |
| 197 | |
| 198 | # Don't override default Kconfig variables, since this will affect all |
| 199 | # Kconfig targets. Change them only when calling sub-make instead. |
Jakub Czapiga | eaf5ff3 | 2021-08-09 14:20:28 +0200 | [diff] [blame] | 200 | $(TEST_KCONFIG_AUTOHEADER): TEST_KCONFIG_FLAGS := DOTCONFIG=$(TEST_DOTCONFIG) \ |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 201 | KCONFIG_AUTOHEADER=$(TEST_KCONFIG_AUTOHEADER) \ |
| 202 | KCONFIG_AUTOCONFIG=$(TEST_KCONFIG_AUTOCONFIG) \ |
| 203 | KCONFIG_DEPENDENCIES=$(TEST_KCONFIG_DEPENDENCIES) \ |
| 204 | KCONFIG_SPLITCONFIG=$(TEST_KCONFIG_SPLITCONFIG) \ |
| 205 | KCONFIG_TRISTATE=$(TEST_KCONFIG_TRISTATE) \ |
| 206 | KBUILD_DEFCONFIG=$(TEST_DEFAULT_CONFIG) |
| 207 | |
| 208 | $(TEST_KCONFIG_AUTOHEADER): $(TEST_DOTCONFIG) $(objutil)/kconfig/conf |
| 209 | mkdir -p $(dir $@) |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 210 | $(MAKE) $(TEST_KCONFIG_FLAGS) olddefconfig |
| 211 | $(MAKE) $(TEST_KCONFIG_FLAGS) syncconfig |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 212 | |
| 213 | $(TEST_KCONFIG_AUTOCONFIG): $(TEST_KCONFIG_AUTOHEADER) |
| 214 | true |
| 215 | |
| 216 | .PHONY: $(alltests) $(addprefix clean-,$(alltests)) |
| 217 | .PHONY: unit-tests build-unit-tests run-unit-tests clean-unit-tests |
| 218 | |
Patrick Georgi | a0a198f | 2020-05-27 10:59:09 +0200 | [diff] [blame] | 219 | ifeq ($(JUNIT_OUTPUT),y) |
| 220 | $(alltests): export CMOCKA_MESSAGE_OUTPUT=xml |
Jakub Czapiga | 1add483 | 2021-03-05 11:37:23 +0100 | [diff] [blame] | 221 | $(alltests): export CMOCKA_XML_FILE=$(testobj)/junit-$(subst /,_,$^)-%g.xml |
Patrick Georgi | a0a198f | 2020-05-27 10:59:09 +0200 | [diff] [blame] | 222 | endif |
| 223 | |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 224 | $(alltests): $$($$(@)-bin) |
Patrick Georgi | 1b35ec9 | 2020-05-27 11:39:32 +0200 | [diff] [blame] | 225 | rm -f $(testobj)/junit-$(subst /,_,$^).xml $(testobj)/$(subst /,_,$^).failed |
| 226 | -./$^ || echo failed > $(testobj)/$(subst /,_,$^).failed |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 227 | |
Paul Fagerburg | de6cbac | 2021-05-11 09:56:48 -0600 | [diff] [blame] | 228 | # Build a code coverage report by collecting all the gcov files into a single |
| 229 | # report. If COV is not set, this might be a user error, and they're trying |
| 230 | # to generate a coverage report without first having built and run the code |
| 231 | # with code coverage. So instead of silently correcting it by adding COV=1, |
| 232 | # let's flag it to the user so they can be sure they're doing the thing they |
| 233 | # want to do. |
Paul Fagerburg | 045fbf1 | 2021-04-16 11:36:25 -0600 | [diff] [blame] | 234 | |
Paul Fagerburg | de6cbac | 2021-05-11 09:56:48 -0600 | [diff] [blame] | 235 | .PHONY: coverage-report clean-coverage-report |
| 236 | |
| 237 | ifeq ($(COV),1) |
| 238 | coverage-report: |
| 239 | lcov -o $(testobj)/tests.info -c -d $(testobj) --exclude '$(testsrc)/*' |
| 240 | genhtml -q -o $(testobj)/$(coverage_dir) -t "coreboot unit tests" \ |
Paul Fagerburg | 045fbf1 | 2021-04-16 11:36:25 -0600 | [diff] [blame] | 241 | -s $(testobj)/tests.info |
| 242 | |
Paul Fagerburg | de6cbac | 2021-05-11 09:56:48 -0600 | [diff] [blame] | 243 | clean-coverage-report: |
| 244 | rm -Rf $(testobj)/$(coverage_dir) |
| 245 | else |
| 246 | coverage-report: |
| 247 | COV=1 V=$(V) $(MAKE) coverage-report |
| 248 | |
| 249 | clean-coverage-report: |
| 250 | COV=1 V=$(V) $(MAKE) clean-coverage-report |
| 251 | endif |
| 252 | |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 253 | unit-tests: build-unit-tests run-unit-tests |
| 254 | |
| 255 | build-unit-tests: $(test-bins) |
| 256 | |
| 257 | run-unit-tests: $(alltests) |
Patrick Georgi | 1b35ec9 | 2020-05-27 11:39:32 +0200 | [diff] [blame] | 258 | if [ `find $(testobj) -name '*.failed' | wc -l` -gt 0 ]; then \ |
| 259 | echo "**********************"; \ |
| 260 | echo " TESTS FAILED"; \ |
| 261 | echo "**********************"; \ |
| 262 | exit 1; \ |
| 263 | else \ |
| 264 | echo "**********************"; \ |
| 265 | echo " ALL TESTS PASSED"; \ |
| 266 | echo "**********************"; \ |
| 267 | exit 0; \ |
| 268 | fi |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 269 | |
| 270 | $(addprefix clean-,$(alltests)): clean-%: |
Paul Fagerburg | de6cbac | 2021-05-11 09:56:48 -0600 | [diff] [blame] | 271 | rm -rf $(testobj)/$* |
Jan Dabros | ef1c968 | 2020-03-28 00:15:03 +0100 | [diff] [blame] | 272 | |
| 273 | clean-unit-tests: |
| 274 | rm -rf $(testobj) |
Jakub Czapiga | a4819b3 | 2021-04-13 16:07:05 +0200 | [diff] [blame] | 275 | |
| 276 | list-unit-tests: |
| 277 | @echo "unit-tests:" |
| 278 | for t in $(sort $(alltests)); do \ |
| 279 | echo " $$t"; \ |
| 280 | done |
| 281 | |
| 282 | help-unit-tests help:: |
| 283 | @echo '*** coreboot unit-tests targets ***' |
Paul Fagerburg | de6cbac | 2021-05-11 09:56:48 -0600 | [diff] [blame] | 284 | @echo ' Use "COV=1 make [target]" to enable code coverage for unit tests' |
Paul Fagerburg | 045fbf1 | 2021-04-16 11:36:25 -0600 | [diff] [blame] | 285 | @echo ' unit-tests - Run all unit-tests from tests/' |
| 286 | @echo ' clean-unit-tests - Remove unit-tests build artifacts' |
| 287 | @echo ' list-unit-tests - List all unit-tests' |
| 288 | @echo ' <unit-test> - Build and run single unit-test' |
| 289 | @echo ' clean-<unit-test> - Remove single unit-test build artifacts' |
Paul Fagerburg | de6cbac | 2021-05-11 09:56:48 -0600 | [diff] [blame] | 290 | @echo ' coverage-report - Generate a code coverage report' |
| 291 | @echo ' clean-coverage-report - Remove the code coverage report' |
Jakub Czapiga | a4819b3 | 2021-04-13 16:07:05 +0200 | [diff] [blame] | 292 | @echo |