1# Copyright (C) 2020 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15# `host-unit-tests` shall only include hostside unittest that don't require a device to run. Tests 16# included will be run as part of presubmit check. 17# To add tests to the suite, do one of the following: 18# * For test modules configured with Android.bp, set attribute `test_options: { unit_test: true }` 19# * For test modules configured with mk, set `LOCAL_IS_UNIT_TEST := true` 20.PHONY: host-unit-tests 21 22intermediates_dir := $(call intermediates-dir-for,PACKAGING,host-unit-tests) 23host_unit_tests_zip := $(PRODUCT_OUT)/host-unit-tests.zip 24# Get the hostside libraries to be packaged in the test zip. Unlike 25# device-tests.mk or general-tests.mk, the files are not copied to the 26# testcases directory. 27my_host_shared_lib_for_host_unit_tests := $(foreach f,$(COMPATIBILITY.host-unit-tests.HOST_SHARED_LIBRARY.FILES),$(strip \ 28 $(eval _cmf_tuple := $(subst :, ,$(f))) \ 29 $(eval _cmf_src := $(word 1,$(_cmf_tuple))) \ 30 $(_cmf_src))) 31 32my_symlinks_for_host_unit_tests := $(foreach f,$(COMPATIBILITY.host-unit-tests.SYMLINKS),\ 33 $(strip $(eval _cmf_tuple := $(subst :, ,$(f))) \ 34 $(eval _cmf_dep := $(word 1,$(_cmf_tuple))) \ 35 $(eval _cmf_src := $(word 2,$(_cmf_tuple))) \ 36 $(eval _cmf_dest := $(word 3,$(_cmf_tuple))) \ 37 $(call symlink-file,$(_cmf_dep),$(_cmf_src),$(_cmf_dest)) \ 38 $(_cmf_dest))) 39 40$(host_unit_tests_zip) : PRIVATE_HOST_SHARED_LIBS := $(my_host_shared_lib_for_host_unit_tests) 41 42$(host_unit_tests_zip) : PRIVATE_SYMLINKS := $(my_symlinks_for_host_unit_tests) 43 44$(host_unit_tests_zip) : $(COMPATIBILITY.host-unit-tests.FILES) $(my_host_shared_lib_for_host_unit_tests) $(my_symlinks_for_host_unit_tests) $(SOONG_ZIP) 45 echo $(sort $(COMPATIBILITY.host-unit-tests.FILES)) | tr " " "\n" > $@.list 46 grep $(HOST_OUT_TESTCASES) $@.list > $@-host.list || true 47 echo "" >> $@-host-libs.list 48 $(hide) for shared_lib in $(PRIVATE_HOST_SHARED_LIBS); do \ 49 echo $$shared_lib >> $@-host-libs.list; \ 50 done 51 $(hide) for symlink in $(PRIVATE_SYMLINKS); do \ 52 echo $$symlink >> $@-host.list; \ 53 done 54 grep $(TARGET_OUT_TESTCASES) $@.list > $@-target.list || true 55 $(hide) $(SOONG_ZIP) -d -o $@ -P host -C $(HOST_OUT) -l $@-host.list \ 56 -P target -C $(PRODUCT_OUT) -l $@-target.list \ 57 -P host/testcases -C $(HOST_OUT) -l $@-host-libs.list -sha256 58 rm -f $@.list $@-host.list $@-target.list $@-host-libs.list 59 60host-unit-tests: $(host_unit_tests_zip) 61$(call dist-for-goals, host-unit-tests, $(host_unit_tests_zip)) 62 63$(call declare-1p-container,$(host_unit_tests_zip),) 64$(call declare-container-license-deps,$(host_unit_tests_zip),$(COMPATIBILITY.host-unit-tests.FILES) $(my_host_shared_lib_for_host_unit_tests),$(PRODUCT_OUT)/:/) 65 66tests: host-unit-tests 67