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 blacklist them.
16blacklisted_fuzz_targets := libneuralnetworks_fuzzer
17
18fuzz_targets := $(ALL_FUZZ_TARGETS)
19fuzz_targets := $(filter-out $(blacklisted_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	libunwind \
50	libvixl:com.android.art.debug
51
52# Use the intermediates directory to avoid installing libraries to the device.
53intermediates := $(call intermediates-dir-for,PACKAGING,haiku-line-coverage)
54
55
56# We want the profile files for all fuzz targets + critical components.
57line_coverage_profiles := $(intermediates)/line_coverage_profiles.zip
58
59critical_components_static_inputs := $(foreach lib,$(critical_components_static), \
60	$(call intermediates-dir-for,STATIC_LIBRARIES,$(lib))/$(lib).a)
61
62critical_components_shared_inputs := $(foreach lib,$(critical_components_shared), \
63	$(eval filename := $(call word-colon,1,$(lib))) \
64	$(eval modulename := $(subst :,.,$(lib))) \
65	$(call intermediates-dir-for,SHARED_LIBRARIES,$(modulename))/$(filename).so)
66
67fuzz_target_inputs := $(foreach fuzz,$(fuzz_targets), \
68	$(call intermediates-dir-for,EXECUTABLES,$(fuzz))/$(fuzz))
69
70# When coverage is enabled (NATIVE_COVERAGE is set), make creates
71# a "coverage" directory and stores all profile (*.gcno) files in inside.
72# We need everything that is stored inside this directory.
73$(line_coverage_profiles): $(fuzz_target_inputs)
74$(line_coverage_profiles): $(critical_components_static_inputs)
75$(line_coverage_profiles): $(critical_components_shared_inputs)
76$(line_coverage_profiles): $(SOONG_ZIP)
77	$(SOONG_ZIP) -o $@ -D $(PRODUCT_OUT)/coverage
78
79
80# Zip all fuzz targets compiled with line coverage.
81line_coverage_fuzz_targets := $(intermediates)/line_coverage_fuzz_targets.zip
82
83$(line_coverage_fuzz_targets): $(fuzz_target_inputs)
84$(line_coverage_fuzz_targets): $(SOONG_ZIP)
85	$(SOONG_ZIP) -o $@ -j $(addprefix -f ,$(fuzz_target_inputs))
86
87
88.PHONY: haiku-line-coverage
89haiku-line-coverage: $(line_coverage_profiles) $(line_coverage_fuzz_targets)
90$(call dist-for-goals, haiku-line-coverage, \
91	$(line_coverage_profiles):line_coverage_profiles.zip \
92	$(line_coverage_fuzz_targets):line_coverage_fuzz_targets.zip)
93
94line_coverage_profiles :=
95line_coverage_fuzz_targets :=
96