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): paths to contexts files
21# $(2): path to the host tool
22# $(3): additional argument to be passed to the tool
23define run_contexts_test
24$$(LOCAL_BUILT_MODULE): PRIVATE_CONTEXTS := $(1)
25$$(LOCAL_BUILT_MODULE): PRIVATE_SEPOLICY := $$(built_sepolicy)
26$$(LOCAL_BUILT_MODULE): $(2) $(1) $$(built_sepolicy)
27	$$(hide) $$< $(3) $$(PRIVATE_SEPOLICY) $$(PRIVATE_CONTEXTS)
28	$$(hide) mkdir -p $$(dir $$@)
29	$$(hide) touch $$@
30endef
31
32system_out := $(TARGET_OUT)/etc/selinux
33system_ext_out := $(TARGET_OUT_SYSTEM_EXT)/etc/selinux
34product_out := $(TARGET_OUT_PRODUCT)/etc/selinux
35vendor_out := $(TARGET_OUT_VENDOR)/etc/selinux
36odm_out := $(TARGET_OUT_ODM)/etc/selinux
37
38checkfc := $(HOST_OUT_EXECUTABLES)/checkfc
39property_info_checker := $(HOST_OUT_EXECUTABLES)/property_info_checker
40
41##################################
42LOCAL_MODULE := plat_file_contexts_test
43LOCAL_MODULE_CLASS := FAKE
44LOCAL_MODULE_TAGS := optional
45
46include $(BUILD_SYSTEM)/base_rules.mk
47
48$(eval $(call run_contexts_test, $(system_out)/plat_file_contexts, $(checkfc),))
49
50##################################
51include $(CLEAR_VARS)
52
53LOCAL_MODULE := system_ext_file_contexts_test
54LOCAL_MODULE_CLASS := FAKE
55LOCAL_MODULE_TAGS := optional
56
57include $(BUILD_SYSTEM)/base_rules.mk
58
59$(eval $(call run_contexts_test, $(system_ext_out)/system_ext_file_contexts, $(checkfc),))
60
61##################################
62include $(CLEAR_VARS)
63
64LOCAL_MODULE := product_file_contexts_test
65LOCAL_MODULE_CLASS := FAKE
66LOCAL_MODULE_TAGS := optional
67
68include $(BUILD_SYSTEM)/base_rules.mk
69
70$(eval $(call run_contexts_test, $(product_out)/product_file_contexts, $(checkfc),))
71
72##################################
73include $(CLEAR_VARS)
74
75LOCAL_MODULE := vendor_file_contexts_test
76LOCAL_MODULE_CLASS := FAKE
77LOCAL_MODULE_TAGS := optional
78
79include $(BUILD_SYSTEM)/base_rules.mk
80
81$(eval $(call run_contexts_test, $(vendor_out)/vendor_file_contexts, $(checkfc),))
82
83##################################
84include $(CLEAR_VARS)
85
86LOCAL_MODULE := odm_file_contexts_test
87LOCAL_MODULE_CLASS := FAKE
88LOCAL_MODULE_TAGS := optional
89
90include $(BUILD_SYSTEM)/base_rules.mk
91
92$(eval $(call run_contexts_test, $(odm_out)/odm_file_contexts, $(checkfc),))
93
94##################################
95
96include $(CLEAR_VARS)
97
98LOCAL_MODULE := plat_hwservice_contexts_test
99LOCAL_MODULE_CLASS := FAKE
100LOCAL_MODULE_TAGS := optional
101
102include $(BUILD_SYSTEM)/base_rules.mk
103
104$(eval $(call run_contexts_test, $(system_out)/plat_hwservice_contexts, $(checkfc), -e -l))
105
106##################################
107include $(CLEAR_VARS)
108
109LOCAL_MODULE := system_ext_hwservice_contexts_test
110LOCAL_MODULE_CLASS := FAKE
111LOCAL_MODULE_TAGS := optional
112
113include $(BUILD_SYSTEM)/base_rules.mk
114
115$(eval $(call run_contexts_test, $(system_ext_out)/system_ext_hwservice_contexts, $(checkfc), -e -l))
116
117##################################
118include $(CLEAR_VARS)
119
120LOCAL_MODULE := product_hwservice_contexts_test
121LOCAL_MODULE_CLASS := FAKE
122LOCAL_MODULE_TAGS := optional
123
124include $(BUILD_SYSTEM)/base_rules.mk
125
126$(eval $(call run_contexts_test, $(product_out)/product_hwservice_contexts, $(checkfc), -e -l))
127
128##################################
129include $(CLEAR_VARS)
130
131LOCAL_MODULE := vendor_hwservice_contexts_test
132LOCAL_MODULE_CLASS := FAKE
133LOCAL_MODULE_TAGS := optional
134
135include $(BUILD_SYSTEM)/base_rules.mk
136
137$(eval $(call run_contexts_test, $(vendor_out)/vendor_hwservice_contexts, $(checkfc), -e -l))
138
139##################################
140include $(CLEAR_VARS)
141
142LOCAL_MODULE := odm_hwservice_contexts_test
143LOCAL_MODULE_CLASS := FAKE
144LOCAL_MODULE_TAGS := optional
145
146include $(BUILD_SYSTEM)/base_rules.mk
147
148$(eval $(call run_contexts_test, $(odm_out)/odm_hwservice_contexts, $(checkfc), -e -l))
149
150##################################
151
152pc_files := $(system_out)/plat_property_contexts
153
154include $(CLEAR_VARS)
155
156LOCAL_MODULE := plat_property_contexts_test
157LOCAL_MODULE_CLASS := FAKE
158LOCAL_MODULE_TAGS := optional
159
160include $(BUILD_SYSTEM)/base_rules.mk
161
162$(eval $(call run_contexts_test, $(pc_files), $(property_info_checker),))
163
164##################################
165
166ifdef HAS_SYSTEM_EXT_SEPOLICY_DIR
167
168pc_files += $(system_ext_out)/system_ext_property_contexts
169
170include $(CLEAR_VARS)
171
172LOCAL_MODULE := system_ext_property_contexts_test
173LOCAL_MODULE_CLASS := FAKE
174LOCAL_MODULE_TAGS := optional
175
176include $(BUILD_SYSTEM)/base_rules.mk
177
178$(eval $(call run_contexts_test, $(pc_files), $(property_info_checker),))
179
180endif
181
182##################################
183
184pc_files += $(vendor_out)/vendor_property_contexts
185
186include $(CLEAR_VARS)
187
188LOCAL_MODULE := vendor_property_contexts_test
189LOCAL_MODULE_CLASS := FAKE
190LOCAL_MODULE_TAGS := optional
191
192include $(BUILD_SYSTEM)/base_rules.mk
193
194$(eval $(call run_contexts_test, $(pc_files), $(property_info_checker),))
195
196##################################
197
198ifdef BOARD_ODM_SEPOLICY_DIRS
199
200pc_files += $(odm_out)/odm_property_contexts
201
202include $(CLEAR_VARS)
203
204LOCAL_MODULE := odm_property_contexts_test
205LOCAL_MODULE_CLASS := FAKE
206LOCAL_MODULE_TAGS := optional
207
208include $(BUILD_SYSTEM)/base_rules.mk
209
210$(eval $(call run_contexts_test, $(pc_files), $(property_info_checker),))
211
212endif
213
214##################################
215
216ifdef HAS_PRODUCT_SEPOLICY_DIR
217
218pc_files += $(product_out)/product_property_contexts
219
220include $(CLEAR_VARS)
221
222LOCAL_MODULE := product_property_contexts_test
223LOCAL_MODULE_CLASS := FAKE
224LOCAL_MODULE_TAGS := optional
225
226include $(BUILD_SYSTEM)/base_rules.mk
227
228$(eval $(call run_contexts_test, $(pc_files), $(property_info_checker),))
229
230endif
231
232pc_files :=
233
234##################################
235include $(CLEAR_VARS)
236
237LOCAL_MODULE := plat_service_contexts_test
238LOCAL_MODULE_CLASS := FAKE
239LOCAL_MODULE_TAGS := optional
240
241include $(BUILD_SYSTEM)/base_rules.mk
242
243$(eval $(call run_contexts_test, $(system_out)/plat_service_contexts, $(checkfc), -s))
244
245##################################
246include $(CLEAR_VARS)
247
248LOCAL_MODULE := system_ext_service_contexts_test
249LOCAL_MODULE_CLASS := FAKE
250LOCAL_MODULE_TAGS := optional
251
252include $(BUILD_SYSTEM)/base_rules.mk
253
254$(eval $(call run_contexts_test, $(system_ext_out)/system_ext_service_contexts, $(checkfc), -s))
255
256##################################
257include $(CLEAR_VARS)
258
259LOCAL_MODULE := product_service_contexts_test
260LOCAL_MODULE_CLASS := FAKE
261LOCAL_MODULE_TAGS := optional
262
263include $(BUILD_SYSTEM)/base_rules.mk
264
265$(eval $(call run_contexts_test, $(product_out)/product_service_contexts, $(checkfc), -s))
266
267##################################
268# nonplat_service_contexts is only allowed on non-full-treble devices
269ifneq ($(PRODUCT_SEPOLICY_SPLIT),true)
270
271include $(CLEAR_VARS)
272
273LOCAL_MODULE := vendor_service_contexts_test
274LOCAL_MODULE_CLASS := FAKE
275LOCAL_MODULE_TAGS := optional
276
277include $(BUILD_SYSTEM)/base_rules.mk
278
279$(eval $(call run_contexts_test, $(vendor_out)/vendor_service_contexts, $(checkfc), -s))
280
281endif
282
283system_out :=
284product_out :=
285vendor_out :=
286odm_out :=
287checkfc :=
288property_info_checker :=
289run_contexts_test :=
290