blob: e5b3dea059fbd5276abd7d0931627b9f7a7a1093 [file] [log] [blame]
Inseob Kimc0907f12019-02-08 21:00:45 +09001// 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
15package sysprop
16
17import (
Paul Duffin9cbbbb82021-03-18 00:21:03 +000018 "os"
19 "strings"
20 "testing"
Paul Duffin7b3de8f2020-03-30 18:00:25 +010021
Inseob Kimc0907f12019-02-08 21:00:45 +090022 "android/soong/android"
23 "android/soong/cc"
24 "android/soong/java"
25
Inseob Kimc0907f12019-02-08 21:00:45 +090026 "github.com/google/blueprint/proptools"
27)
28
Inseob Kimc0907f12019-02-08 21:00:45 +090029func TestMain(m *testing.M) {
Paul Duffin9cbbbb82021-03-18 00:21:03 +000030 os.Exit(m.Run())
Inseob Kimc0907f12019-02-08 21:00:45 +090031}
32
Paul Duffin9cbbbb82021-03-18 00:21:03 +000033func test(t *testing.T, bp string) *android.TestResult {
Colin Cross98be1bb2019-12-13 20:41:13 -080034 t.Helper()
Colin Cross98be1bb2019-12-13 20:41:13 -080035
Jiyong Park5e914b22021-03-08 10:09:52 +090036 bp += `
37 cc_library {
38 name: "libbase",
39 host_supported: true,
40 }
41
42 cc_library_headers {
43 name: "libbase_headers",
44 vendor_available: true,
Justin Yunaf1fde42023-09-27 16:22:10 +090045 product_available: true,
Jiyong Park5e914b22021-03-08 10:09:52 +090046 recovery_available: true,
47 }
48
49 cc_library {
50 name: "liblog",
51 no_libcrt: true,
52 nocrt: true,
53 system_shared_libs: [],
54 recovery_available: true,
55 host_supported: true,
Colin Cross203b4212021-04-26 17:19:41 -070056 llndk: {
57 symbol_file: "liblog.map.txt",
58 }
Jiyong Park5e914b22021-03-08 10:09:52 +090059 }
60
61 java_library {
62 name: "sysprop-library-stub-platform",
63 sdk_version: "core_current",
64 }
65
66 java_library {
67 name: "sysprop-library-stub-vendor",
68 soc_specific: true,
69 sdk_version: "core_current",
70 }
71
72 java_library {
73 name: "sysprop-library-stub-product",
74 product_specific: true,
75 sdk_version: "core_current",
76 }
77 `
78
Paul Duffin9cbbbb82021-03-18 00:21:03 +000079 mockFS := android.MockFS{
Inseob Kim42882742019-07-30 17:55:33 +090080 "a.java": nil,
81 "b.java": nil,
82 "c.java": nil,
83 "d.cpp": nil,
84 "api/sysprop-platform-current.txt": nil,
85 "api/sysprop-platform-latest.txt": nil,
86 "api/sysprop-platform-on-product-current.txt": nil,
87 "api/sysprop-platform-on-product-latest.txt": nil,
88 "api/sysprop-vendor-current.txt": nil,
89 "api/sysprop-vendor-latest.txt": nil,
Inseob Kimfe612182020-10-20 16:29:55 +090090 "api/sysprop-vendor-on-product-current.txt": nil,
91 "api/sysprop-vendor-on-product-latest.txt": nil,
Inseob Kim42882742019-07-30 17:55:33 +090092 "api/sysprop-odm-current.txt": nil,
93 "api/sysprop-odm-latest.txt": nil,
94 "framework/aidl/a.aidl": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +090095
96 // For framework-res, which is an implicit dependency for framework
Dan Willemsen412160e2019-04-09 21:36:26 -070097 "AndroidManifest.xml": nil,
98 "build/make/target/product/security/testkey": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +090099
100 "build/soong/scripts/jar-wrapper.sh": nil,
101
Inseob Kimc0907f12019-02-08 21:00:45 +0900102 "jdk8/jre/lib/jce.jar": nil,
103 "jdk8/jre/lib/rt.jar": nil,
104 "jdk8/lib/tools.jar": nil,
105
106 "bar-doc/a.java": nil,
107 "bar-doc/b.java": nil,
108 "bar-doc/IFoo.aidl": nil,
109 "bar-doc/known_oj_tags.txt": nil,
110 "external/doclava/templates-sdk": nil,
111
112 "cert/new_cert.x509.pem": nil,
113 "cert/new_cert.pk8": nil,
114
115 "android/sysprop/PlatformProperties.sysprop": nil,
116 "com/android/VendorProperties.sysprop": nil,
Inseob Kim42882742019-07-30 17:55:33 +0900117 "com/android2/OdmProperties.sysprop": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900118 }
119
Paul Duffin89648f92021-03-20 00:36:55 +0000120 result := android.GroupFixturePreparers(
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000121 cc.PrepareForTestWithCcDefaultModules,
122 java.PrepareForTestWithJavaDefaultModules,
123 PrepareForTestWithSyspropBuildComponents,
124 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
125 variables.DeviceSystemSdkVersions = []string{"28"}
126 variables.DeviceVndkVersion = proptools.StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900127 variables.Platform_vndk_version = proptools.StringPtr("29")
Jiyong Park7416d672024-01-04 23:20:42 +0000128 variables.DeviceCurrentApiLevelForVendorModules = proptools.StringPtr("28")
129 }),
130 java.FixtureWithPrebuiltApis(map[string][]string{
131 "28": {},
132 "29": {},
133 "30": {},
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000134 }),
135 mockFS.AddToFixture(),
136 android.FixtureWithRootAndroidBp(bp),
Paul Duffin89648f92021-03-20 00:36:55 +0000137 ).RunTest(t)
Inseob Kimc0907f12019-02-08 21:00:45 +0900138
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000139 return result
Inseob Kimc0907f12019-02-08 21:00:45 +0900140}
141
142func TestSyspropLibrary(t *testing.T) {
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000143 result := test(t, `
Inseob Kimc0907f12019-02-08 21:00:45 +0900144 sysprop_library {
145 name: "sysprop-platform",
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100146 apex_available: ["//apex_available:platform"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900147 srcs: ["android/sysprop/PlatformProperties.sysprop"],
148 api_packages: ["android.sysprop"],
149 property_owner: "Platform",
150 vendor_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900151 host_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900152 }
153
154 sysprop_library {
155 name: "sysprop-platform-on-product",
156 srcs: ["android/sysprop/PlatformProperties.sysprop"],
157 api_packages: ["android.sysprop"],
158 property_owner: "Platform",
159 product_specific: true,
160 }
161
162 sysprop_library {
163 name: "sysprop-vendor",
164 srcs: ["com/android/VendorProperties.sysprop"],
165 api_packages: ["com.android"],
166 property_owner: "Vendor",
Inseob Kimfe612182020-10-20 16:29:55 +0900167 vendor: true,
168 }
169
170 sysprop_library {
171 name: "sysprop-vendor-on-product",
172 srcs: ["com/android/VendorProperties.sysprop"],
173 api_packages: ["com.android"],
174 property_owner: "Vendor",
Inseob Kimc0907f12019-02-08 21:00:45 +0900175 product_specific: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900176 }
177
Inseob Kim42882742019-07-30 17:55:33 +0900178 sysprop_library {
179 name: "sysprop-odm",
180 srcs: ["com/android2/OdmProperties.sysprop"],
181 api_packages: ["com.android2"],
182 property_owner: "Odm",
183 device_specific: true,
184 }
185
Inseob Kimc0907f12019-02-08 21:00:45 +0900186 java_library {
187 name: "java-platform",
188 srcs: ["c.java"],
189 sdk_version: "system_current",
190 libs: ["sysprop-platform"],
191 }
192
193 java_library {
Inseob Kimac1e9862019-12-09 18:15:47 +0900194 name: "java-platform-private",
195 srcs: ["c.java"],
196 platform_apis: true,
197 libs: ["sysprop-platform"],
198 }
199
200 java_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900201 name: "java-product",
202 srcs: ["c.java"],
203 sdk_version: "system_current",
204 product_specific: true,
Inseob Kimfe612182020-10-20 16:29:55 +0900205 libs: ["sysprop-platform", "sysprop-vendor-on-product"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900206 }
207
208 java_library {
209 name: "java-vendor",
210 srcs: ["c.java"],
211 sdk_version: "system_current",
212 soc_specific: true,
213 libs: ["sysprop-platform", "sysprop-vendor"],
214 }
215
216 cc_library {
217 name: "cc-client-platform",
218 srcs: ["d.cpp"],
Trevor Radcliffed82e8f62022-06-08 16:16:31 +0000219 static_libs: ["libsysprop-platform"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900220 }
221
Jiyong Park5d1598f2019-02-25 22:14:17 +0900222 cc_library_static {
223 name: "cc-client-platform-static",
224 srcs: ["d.cpp"],
Trevor Radcliffed82e8f62022-06-08 16:16:31 +0000225 whole_static_libs: ["libsysprop-platform"],
Jiyong Park5d1598f2019-02-25 22:14:17 +0900226 }
227
Inseob Kimc0907f12019-02-08 21:00:45 +0900228 cc_library {
229 name: "cc-client-product",
230 srcs: ["d.cpp"],
231 product_specific: true,
Trevor Radcliffed82e8f62022-06-08 16:16:31 +0000232 static_libs: ["libsysprop-platform-on-product", "libsysprop-vendor-on-product"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900233 }
234
235 cc_library {
236 name: "cc-client-vendor",
237 srcs: ["d.cpp"],
238 soc_specific: true,
Trevor Radcliffed82e8f62022-06-08 16:16:31 +0000239 static_libs: ["libsysprop-platform", "libsysprop-vendor"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900240 }
Inseob Kim1f959762019-03-27 17:20:37 +0900241
Inseob Kim89db15d2020-02-03 18:06:46 +0900242 cc_binary_host {
243 name: "hostbin",
Trevor Radcliffed82e8f62022-06-08 16:16:31 +0000244 static_libs: ["libsysprop-platform"],
Inseob Kim1f959762019-03-27 17:20:37 +0900245 }
Jiyong Park5e914b22021-03-08 10:09:52 +0900246 `)
Inseob Kimc0907f12019-02-08 21:00:45 +0900247
Inseob Kim42882742019-07-30 17:55:33 +0900248 // Check for generated cc_library
249 for _, variant := range []string{
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900250 "android_vendor.29_arm_armv7-a-neon_shared",
251 "android_vendor.29_arm_armv7-a-neon_static",
252 "android_vendor.29_arm64_armv8-a_shared",
253 "android_vendor.29_arm64_armv8-a_static",
Inseob Kim42882742019-07-30 17:55:33 +0900254 } {
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000255 result.ModuleForTests("libsysprop-platform", variant)
256 result.ModuleForTests("libsysprop-vendor", variant)
257 result.ModuleForTests("libsysprop-odm", variant)
Inseob Kim42882742019-07-30 17:55:33 +0900258 }
259
Justin Yunaf1fde42023-09-27 16:22:10 +0900260 // product variant of vendor-owned sysprop_library
261 for _, variant := range []string{
262 "android_product.29_arm_armv7-a-neon_shared",
263 "android_product.29_arm_armv7-a-neon_static",
264 "android_product.29_arm64_armv8-a_shared",
265 "android_product.29_arm64_armv8-a_static",
266 } {
267 result.ModuleForTests("libsysprop-vendor-on-product", variant)
268 }
269
Inseob Kimc0907f12019-02-08 21:00:45 +0900270 for _, variant := range []string{
Colin Cross7113d202019-11-20 16:39:12 -0800271 "android_arm_armv7-a-neon_shared",
272 "android_arm_armv7-a-neon_static",
273 "android_arm64_armv8-a_shared",
274 "android_arm64_armv8-a_static",
Inseob Kimc0907f12019-02-08 21:00:45 +0900275 } {
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000276 library := result.ModuleForTests("libsysprop-platform", variant).Module().(*cc.Module)
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100277 expectedApexAvailableOnLibrary := []string{"//apex_available:platform"}
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000278 android.AssertDeepEquals(t, "apex available property on libsysprop-platform", expectedApexAvailableOnLibrary, library.ApexProperties.Apex_available)
Inseob Kimc0907f12019-02-08 21:00:45 +0900279 }
280
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000281 result.ModuleForTests("sysprop-platform", "android_common")
282 result.ModuleForTests("sysprop-platform_public", "android_common")
283 result.ModuleForTests("sysprop-vendor", "android_common")
284 result.ModuleForTests("sysprop-vendor-on-product", "android_common")
Inseob Kimc0907f12019-02-08 21:00:45 +0900285
286 // Check for exported includes
Colin Cross7113d202019-11-20 16:39:12 -0800287 coreVariant := "android_arm64_armv8-a_static"
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900288 vendorVariant := "android_vendor.29_arm64_armv8-a_static"
Justin Yunaf1fde42023-09-27 16:22:10 +0900289 productVariant := "android_product.29_arm64_armv8-a_static"
Inseob Kimc0907f12019-02-08 21:00:45 +0900290
Colin Cross7113d202019-11-20 16:39:12 -0800291 platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/include"
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900292 platformPublicVendorPath := "libsysprop-platform/android_vendor.29_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900293
Justin Yunaf1fde42023-09-27 16:22:10 +0900294 platformOnProductPath := "libsysprop-platform-on-product/android_product.29_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900295
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900296 vendorInternalPath := "libsysprop-vendor/android_vendor.29_arm64_armv8-a_static/gen/sysprop/include"
Justin Yunaf1fde42023-09-27 16:22:10 +0900297 vendorOnProductPath := "libsysprop-vendor-on-product/android_product.29_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900298
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000299 platformClient := result.ModuleForTests("cc-client-platform", coreVariant)
Inseob Kimc0907f12019-02-08 21:00:45 +0900300 platformFlags := platformClient.Rule("cc").Args["cFlags"]
301
Jiyong Park5d1598f2019-02-25 22:14:17 +0900302 // platform should use platform's internal header
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000303 android.AssertStringDoesContain(t, "flags for platform", platformFlags, platformInternalPath)
Inseob Kimc0907f12019-02-08 21:00:45 +0900304
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000305 platformStaticClient := result.ModuleForTests("cc-client-platform-static", coreVariant)
Jiyong Park5d1598f2019-02-25 22:14:17 +0900306 platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"]
307
308 // platform-static should use platform's internal header
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000309 android.AssertStringDoesContain(t, "flags for platform-static", platformStaticFlags, platformInternalPath)
Jiyong Park5d1598f2019-02-25 22:14:17 +0900310
Justin Yunaf1fde42023-09-27 16:22:10 +0900311 productClient := result.ModuleForTests("cc-client-product", productVariant)
Inseob Kimc0907f12019-02-08 21:00:45 +0900312 productFlags := productClient.Rule("cc").Args["cFlags"]
313
Inseob Kim5cefbd22019-06-08 20:36:59 +0900314 // Product should use platform's and vendor's public headers
Inseob Kimc0907f12019-02-08 21:00:45 +0900315 if !strings.Contains(productFlags, platformOnProductPath) ||
Justin Yunaf1fde42023-09-27 16:22:10 +0900316 !strings.Contains(productFlags, vendorOnProductPath) {
Inseob Kimc0907f12019-02-08 21:00:45 +0900317 t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
Justin Yunaf1fde42023-09-27 16:22:10 +0900318 platformOnProductPath, vendorOnProductPath, productFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900319 }
320
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000321 vendorClient := result.ModuleForTests("cc-client-vendor", vendorVariant)
Inseob Kimc0907f12019-02-08 21:00:45 +0900322 vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
323
Inseob Kim5cefbd22019-06-08 20:36:59 +0900324 // Vendor should use platform's public header and vendor's internal header
325 if !strings.Contains(vendorFlags, platformPublicVendorPath) ||
Inseob Kimc0907f12019-02-08 21:00:45 +0900326 !strings.Contains(vendorFlags, vendorInternalPath) {
327 t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900328 platformPublicVendorPath, vendorInternalPath, vendorFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900329 }
Inseob Kimac1e9862019-12-09 18:15:47 +0900330
331 // Java modules linking against system API should use public stub
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000332 javaSystemApiClient := result.ModuleForTests("java-platform", "android_common").Rule("javac")
333 syspropPlatformPublic := result.ModuleForTests("sysprop-platform_public", "android_common").Description("for turbine")
Colin Cross75ce9ec2021-02-26 16:20:32 -0800334 if g, w := javaSystemApiClient.Implicits.Strings(), syspropPlatformPublic.Output.String(); !android.InList(w, g) {
335 t.Errorf("system api client should use public stub %q, got %q", w, g)
Inseob Kimac1e9862019-12-09 18:15:47 +0900336 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900337}
Jiyong Park5e914b22021-03-08 10:09:52 +0900338
339func TestApexAvailabilityIsForwarded(t *testing.T) {
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000340 result := test(t, `
Jiyong Park5e914b22021-03-08 10:09:52 +0900341 sysprop_library {
342 name: "sysprop-platform",
343 apex_available: ["//apex_available:platform"],
344 srcs: ["android/sysprop/PlatformProperties.sysprop"],
345 api_packages: ["android.sysprop"],
346 property_owner: "Platform",
347 }
348 `)
349
350 expected := []string{"//apex_available:platform"}
351
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000352 ccModule := result.ModuleForTests("libsysprop-platform", "android_arm64_armv8-a_shared").Module().(*cc.Module)
Jiyong Park5e914b22021-03-08 10:09:52 +0900353 propFromCc := ccModule.ApexProperties.Apex_available
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000354 android.AssertDeepEquals(t, "apex_available forwarding to cc module", expected, propFromCc)
Jiyong Park5e914b22021-03-08 10:09:52 +0900355
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000356 javaModule := result.ModuleForTests("sysprop-platform", "android_common").Module().(*java.Library)
Jiyong Park5e914b22021-03-08 10:09:52 +0900357 propFromJava := javaModule.ApexProperties.Apex_available
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000358 android.AssertDeepEquals(t, "apex_available forwarding to java module", expected, propFromJava)
Jiyong Park5e914b22021-03-08 10:09:52 +0900359}
360
361func TestMinSdkVersionIsForwarded(t *testing.T) {
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000362 result := test(t, `
Jiyong Park5e914b22021-03-08 10:09:52 +0900363 sysprop_library {
364 name: "sysprop-platform",
365 srcs: ["android/sysprop/PlatformProperties.sysprop"],
366 api_packages: ["android.sysprop"],
367 property_owner: "Platform",
368 cpp: {
369 min_sdk_version: "29",
370 },
371 java: {
372 min_sdk_version: "30",
373 },
374 }
375 `)
376
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000377 ccModule := result.ModuleForTests("libsysprop-platform", "android_arm64_armv8-a_shared").Module().(*cc.Module)
Jiyong Park5e914b22021-03-08 10:09:52 +0900378 propFromCc := proptools.String(ccModule.Properties.Min_sdk_version)
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000379 android.AssertStringEquals(t, "min_sdk_version forwarding to cc module", "29", propFromCc)
Jiyong Park5e914b22021-03-08 10:09:52 +0900380
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000381 javaModule := result.ModuleForTests("sysprop-platform", "android_common").Module().(*java.Library)
Jiyong Parkf1691d22021-03-29 20:11:58 +0900382 propFromJava := javaModule.MinSdkVersionString()
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000383 android.AssertStringEquals(t, "min_sdk_version forwarding to java module", "30", propFromJava)
Jiyong Park5e914b22021-03-08 10:09:52 +0900384}