1# Copyright (C) 2019 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 15include $(CLEAR_VARS) 16 17# TODO: move tests into Soong after refactoring sepolicy module (b/130693869) 18 19# Run host-side test with contexts files and the sepolicy file. 20# $(1): names of modules containing context files 21# $(2): path to the host tool 22# $(3): additional argument to be passed to the tool 23define run_contexts_test 24my_contexts := $(foreach m,$(1),$$(call intermediates-dir-for,ETC,$(m))/$(m)) 25$$(LOCAL_BUILT_MODULE): PRIVATE_CONTEXTS := $$(my_contexts) 26$$(LOCAL_BUILT_MODULE): PRIVATE_SEPOLICY := $$(built_sepolicy) 27$$(LOCAL_BUILT_MODULE): $(2) $$(my_contexts) $$(built_sepolicy) 28 $$(hide) $$< $(3) $$(PRIVATE_SEPOLICY) $$(PRIVATE_CONTEXTS) 29 $$(hide) mkdir -p $$(dir $$@) 30 $$(hide) touch $$@ 31my_contexts := 32endef 33 34checkfc := $(HOST_OUT_EXECUTABLES)/checkfc 35property_info_checker := $(HOST_OUT_EXECUTABLES)/property_info_checker 36 37################################## 38LOCAL_MODULE := plat_file_contexts_test 39LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered 40LOCAL_LICENSE_CONDITIONS := notice unencumbered 41LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE 42LOCAL_MODULE_CLASS := FAKE 43LOCAL_MODULE_TAGS := optional 44 45include $(BUILD_SYSTEM)/base_rules.mk 46$(eval $(call run_contexts_test, plat_file_contexts, $(checkfc),)) 47 48################################## 49include $(CLEAR_VARS) 50 51LOCAL_MODULE := system_ext_file_contexts_test 52LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered 53LOCAL_LICENSE_CONDITIONS := notice unencumbered 54LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE 55LOCAL_MODULE_CLASS := FAKE 56LOCAL_MODULE_TAGS := optional 57 58include $(BUILD_SYSTEM)/base_rules.mk 59 60$(eval $(call run_contexts_test, system_ext_file_contexts, $(checkfc),)) 61 62################################## 63include $(CLEAR_VARS) 64 65LOCAL_MODULE := product_file_contexts_test 66LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered 67LOCAL_LICENSE_CONDITIONS := notice unencumbered 68LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE 69LOCAL_MODULE_CLASS := FAKE 70LOCAL_MODULE_TAGS := optional 71 72include $(BUILD_SYSTEM)/base_rules.mk 73 74$(eval $(call run_contexts_test, product_file_contexts, $(checkfc),)) 75 76################################## 77include $(CLEAR_VARS) 78 79LOCAL_MODULE := vendor_file_contexts_test 80LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered 81LOCAL_LICENSE_CONDITIONS := notice unencumbered 82LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE 83LOCAL_MODULE_CLASS := FAKE 84LOCAL_MODULE_TAGS := optional 85 86include $(BUILD_SYSTEM)/base_rules.mk 87 88$(eval $(call run_contexts_test, vendor_file_contexts, $(checkfc),)) 89 90################################## 91include $(CLEAR_VARS) 92 93LOCAL_MODULE := odm_file_contexts_test 94LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered 95LOCAL_LICENSE_CONDITIONS := notice unencumbered 96LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE 97LOCAL_MODULE_CLASS := FAKE 98LOCAL_MODULE_TAGS := optional 99 100include $(BUILD_SYSTEM)/base_rules.mk 101 102$(eval $(call run_contexts_test, odm_file_contexts, $(checkfc),)) 103 104################################## 105 106include $(CLEAR_VARS) 107 108LOCAL_MODULE := plat_hwservice_contexts_test 109LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered 110LOCAL_LICENSE_CONDITIONS := notice unencumbered 111LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE 112LOCAL_MODULE_CLASS := FAKE 113LOCAL_MODULE_TAGS := optional 114 115include $(BUILD_SYSTEM)/base_rules.mk 116 117$(eval $(call run_contexts_test, plat_hwservice_contexts, $(checkfc), -e -l)) 118 119################################## 120include $(CLEAR_VARS) 121 122LOCAL_MODULE := system_ext_hwservice_contexts_test 123LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered 124LOCAL_LICENSE_CONDITIONS := notice unencumbered 125LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE 126LOCAL_MODULE_CLASS := FAKE 127LOCAL_MODULE_TAGS := optional 128 129include $(BUILD_SYSTEM)/base_rules.mk 130 131$(eval $(call run_contexts_test, system_ext_hwservice_contexts, $(checkfc), -e -l)) 132 133################################## 134include $(CLEAR_VARS) 135 136LOCAL_MODULE := product_hwservice_contexts_test 137LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered 138LOCAL_LICENSE_CONDITIONS := notice unencumbered 139LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE 140LOCAL_MODULE_CLASS := FAKE 141LOCAL_MODULE_TAGS := optional 142 143include $(BUILD_SYSTEM)/base_rules.mk 144 145$(eval $(call run_contexts_test, product_hwservice_contexts, $(checkfc), -e -l)) 146 147################################## 148include $(CLEAR_VARS) 149 150LOCAL_MODULE := vendor_hwservice_contexts_test 151LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered 152LOCAL_LICENSE_CONDITIONS := notice unencumbered 153LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE 154LOCAL_MODULE_CLASS := FAKE 155LOCAL_MODULE_TAGS := optional 156 157include $(BUILD_SYSTEM)/base_rules.mk 158 159$(eval $(call run_contexts_test, vendor_hwservice_contexts, $(checkfc), -e -l)) 160 161################################## 162include $(CLEAR_VARS) 163 164LOCAL_MODULE := odm_hwservice_contexts_test 165LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered 166LOCAL_LICENSE_CONDITIONS := notice unencumbered 167LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE 168LOCAL_MODULE_CLASS := FAKE 169LOCAL_MODULE_TAGS := optional 170 171include $(BUILD_SYSTEM)/base_rules.mk 172 173$(eval $(call run_contexts_test, odm_hwservice_contexts, $(checkfc), -e -l)) 174 175################################## 176 177pc_modules := plat_property_contexts 178 179include $(CLEAR_VARS) 180 181LOCAL_MODULE := plat_property_contexts_test 182LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered 183LOCAL_LICENSE_CONDITIONS := notice unencumbered 184LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE 185LOCAL_MODULE_CLASS := FAKE 186LOCAL_MODULE_TAGS := optional 187 188include $(BUILD_SYSTEM)/base_rules.mk 189 190$(eval $(call run_contexts_test, $(pc_modules), $(property_info_checker),)) 191 192################################## 193 194ifdef HAS_SYSTEM_EXT_SEPOLICY_DIR 195 196pc_modules += system_ext_property_contexts 197 198include $(CLEAR_VARS) 199 200LOCAL_MODULE := system_ext_property_contexts_test 201LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered 202LOCAL_LICENSE_CONDITIONS := notice unencumbered 203LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE 204LOCAL_MODULE_CLASS := FAKE 205LOCAL_MODULE_TAGS := optional 206 207include $(BUILD_SYSTEM)/base_rules.mk 208 209$(eval $(call run_contexts_test, $(pc_modules), $(property_info_checker),)) 210 211endif 212 213################################## 214 215pc_modules += vendor_property_contexts 216 217include $(CLEAR_VARS) 218 219LOCAL_MODULE := vendor_property_contexts_test 220LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered 221LOCAL_LICENSE_CONDITIONS := notice unencumbered 222LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE 223LOCAL_MODULE_CLASS := FAKE 224LOCAL_MODULE_TAGS := optional 225 226include $(BUILD_SYSTEM)/base_rules.mk 227 228$(eval $(call run_contexts_test, $(pc_modules), $(property_info_checker),)) 229 230################################## 231 232ifdef BOARD_ODM_SEPOLICY_DIRS 233 234pc_modules += odm_property_contexts 235 236include $(CLEAR_VARS) 237 238LOCAL_MODULE := odm_property_contexts_test 239LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered 240LOCAL_LICENSE_CONDITIONS := notice unencumbered 241LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE 242LOCAL_MODULE_CLASS := FAKE 243LOCAL_MODULE_TAGS := optional 244 245include $(BUILD_SYSTEM)/base_rules.mk 246 247$(eval $(call run_contexts_test, $(pc_modules), $(property_info_checker),)) 248 249endif 250 251################################## 252 253ifdef HAS_PRODUCT_SEPOLICY_DIR 254 255pc_modules += product_property_contexts 256 257include $(CLEAR_VARS) 258 259LOCAL_MODULE := product_property_contexts_test 260LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered 261LOCAL_LICENSE_CONDITIONS := notice unencumbered 262LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE 263LOCAL_MODULE_CLASS := FAKE 264LOCAL_MODULE_TAGS := optional 265 266include $(BUILD_SYSTEM)/base_rules.mk 267 268$(eval $(call run_contexts_test, $(pc_modules), $(property_info_checker),)) 269 270endif 271 272pc_modules := 273 274################################## 275include $(CLEAR_VARS) 276 277LOCAL_MODULE := plat_service_contexts_test 278LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered 279LOCAL_LICENSE_CONDITIONS := notice unencumbered 280LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE 281LOCAL_MODULE_CLASS := FAKE 282LOCAL_MODULE_TAGS := optional 283 284include $(BUILD_SYSTEM)/base_rules.mk 285 286$(eval $(call run_contexts_test, plat_service_contexts, $(checkfc), -s)) 287 288################################## 289include $(CLEAR_VARS) 290 291LOCAL_MODULE := system_ext_service_contexts_test 292LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered 293LOCAL_LICENSE_CONDITIONS := notice unencumbered 294LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE 295LOCAL_MODULE_CLASS := FAKE 296LOCAL_MODULE_TAGS := optional 297 298include $(BUILD_SYSTEM)/base_rules.mk 299 300$(eval $(call run_contexts_test, system_ext_service_contexts, $(checkfc), -s)) 301 302################################## 303include $(CLEAR_VARS) 304 305LOCAL_MODULE := product_service_contexts_test 306LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered 307LOCAL_LICENSE_CONDITIONS := notice unencumbered 308LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE 309LOCAL_MODULE_CLASS := FAKE 310LOCAL_MODULE_TAGS := optional 311 312include $(BUILD_SYSTEM)/base_rules.mk 313 314$(eval $(call run_contexts_test, product_service_contexts, $(checkfc), -s)) 315 316################################## 317# nonplat_service_contexts is only allowed on non-full-treble devices 318ifneq ($(PRODUCT_SEPOLICY_SPLIT),true) 319 320include $(CLEAR_VARS) 321 322LOCAL_MODULE := vendor_service_contexts_test 323LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered 324LOCAL_LICENSE_CONDITIONS := notice unencumbered 325LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE 326LOCAL_MODULE_CLASS := FAKE 327LOCAL_MODULE_TAGS := optional 328 329include $(BUILD_SYSTEM)/base_rules.mk 330 331$(eval $(call run_contexts_test, vendor_service_contexts, $(checkfc), -s)) 332 333endif 334 335checkfc := 336property_info_checker := 337run_contexts_test := 338