1# -----------------------------------------------------------------
2# Make target for line coverage. This target generates a zip file
3# called `line_coverage_profiles.zip` that contains a large set of
4# zip files one for each fuzz target/critical component. Each zip
5# file contains a set of profile files (*.gcno) that we will use
6# to generate line coverage reports. Furthermore, target compiles
7# all fuzz targets with line coverage instrumentation enabled and
8# packs them into another zip file called `line_coverage_profiles.zip`.
9#
10# To run the make target set the coverage related envvars first:
11# 	NATIVE_COVERAGE=true NATIVE_COVERAGE_PATHS=* make haiku-line-coverage
12# -----------------------------------------------------------------
13
14# TODO(b/148306195): Due this issue some fuzz targets cannot be built with
15# line coverage instrumentation. For now we just block them.
16blocked_fuzz_targets := libneuralnetworks_fuzzer
17
18fuzz_targets := $(ALL_FUZZ_TARGETS)
19fuzz_targets := $(filter-out $(blocked_fuzz_targets),$(fuzz_targets))
20
21
22# Android components that considered critical.
23# Please note that adding/Removing critical components is very rare.
24critical_components_static := \
25	lib-bt-packets \
26	libbt-stack \
27	libffi \
28	libhevcdec \
29	libhevcenc \
30	libmpeg2dec \
31	libosi \
32	libpdx \
33	libselinux \
34	libvold \
35	libyuv
36
37# Format is <module_name> or <module_name>:<apex_name>
38critical_components_shared := \
39	libaudioprocessing \
40	libbinder \
41	libbluetooth_gd \
42	libbrillo \
43	libcameraservice \
44	libcurl \
45	libhardware \
46	libinputflinger \
47	libopus \
48	libstagefright \
49	libvixl:com.android.art.debug
50
51# Use the intermediates directory to avoid installing libraries to the device.
52intermediates := $(call intermediates-dir-for,PACKAGING,haiku-line-coverage)
53
54
55# We want the profile files for all fuzz targets + critical components.
56line_coverage_profiles := $(intermediates)/line_coverage_profiles.zip
57
58critical_components_static_inputs := $(foreach lib,$(critical_components_static), \
59	$(call intermediates-dir-for,STATIC_LIBRARIES,$(lib))/$(lib).a)
60
61critical_components_shared_inputs := $(foreach lib,$(critical_components_shared), \
62	$(eval filename := $(call word-colon,1,$(lib))) \
63	$(eval modulename := $(subst :,.,$(lib))) \
64	$(call intermediates-dir-for,SHARED_LIBRARIES,$(modulename))/$(filename).so)
65
66fuzz_target_inputs := $(foreach fuzz,$(fuzz_targets), \
67	$(call intermediates-dir-for,EXECUTABLES,$(fuzz))/$(fuzz))
68
69# When coverage is enabled (NATIVE_COVERAGE is set), make creates
70# a "coverage" directory and stores all profile (*.gcno) files in inside.
71# We need everything that is stored inside this directory.
72$(line_coverage_profiles): $(fuzz_target_inputs)
73$(line_coverage_profiles): $(critical_components_static_inputs)
74$(line_coverage_profiles): $(critical_components_shared_inputs)
75$(line_coverage_profiles): $(SOONG_ZIP)
76	$(SOONG_ZIP) -o $@ -D $(PRODUCT_OUT)/coverage
77
78
79# Zip all fuzz targets compiled with line coverage.
80line_coverage_fuzz_targets := $(intermediates)/line_coverage_fuzz_targets.zip
81
82$(line_coverage_fuzz_targets): $(fuzz_target_inputs)
83$(line_coverage_fuzz_targets): $(SOONG_ZIP)
84	$(SOONG_ZIP) -o $@ -j $(addprefix -f ,$(fuzz_target_inputs))
85
86
87.PHONY: haiku-line-coverage
88haiku-line-coverage: $(line_coverage_profiles) $(line_coverage_fuzz_targets)
89$(call dist-for-goals, haiku-line-coverage, \
90	$(line_coverage_profiles):line_coverage_profiles.zip \
91	$(line_coverage_fuzz_targets):line_coverage_fuzz_targets.zip)
92
93line_coverage_profiles :=
94line_coverage_fuzz_targets :=
95