blob: e6464a7bd8fb053f5b6512b421f12342a6557c89 [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"
Andrew Walbranac0c8732024-02-14 10:25:55 +000025 "android/soong/rust"
Inseob Kimc0907f12019-02-08 21:00:45 +090026
Inseob Kimc0907f12019-02-08 21:00:45 +090027 "github.com/google/blueprint/proptools"
28)
29
Inseob Kimc0907f12019-02-08 21:00:45 +090030func TestMain(m *testing.M) {
Paul Duffin9cbbbb82021-03-18 00:21:03 +000031 os.Exit(m.Run())
Inseob Kimc0907f12019-02-08 21:00:45 +090032}
33
Paul Duffin9cbbbb82021-03-18 00:21:03 +000034func test(t *testing.T, bp string) *android.TestResult {
Colin Cross98be1bb2019-12-13 20:41:13 -080035 t.Helper()
Colin Cross98be1bb2019-12-13 20:41:13 -080036
Jiyong Park5e914b22021-03-08 10:09:52 +090037 bp += `
38 cc_library {
39 name: "libbase",
40 host_supported: true,
41 }
42
43 cc_library_headers {
44 name: "libbase_headers",
45 vendor_available: true,
46 recovery_available: true,
47 }
48
Jiyong Park5e914b22021-03-08 10:09:52 +090049 java_library {
50 name: "sysprop-library-stub-platform",
51 sdk_version: "core_current",
52 }
53
54 java_library {
55 name: "sysprop-library-stub-vendor",
56 soc_specific: true,
57 sdk_version: "core_current",
58 }
59
60 java_library {
61 name: "sysprop-library-stub-product",
62 product_specific: true,
63 sdk_version: "core_current",
64 }
Andrew Walbranac0c8732024-02-14 10:25:55 +000065
66 rust_library {
67 name: "librustutils",
68 crate_name: "rustutils",
69 srcs: ["librustutils/lib.rs"],
70 product_available: true,
71 vendor_available: true,
72 min_sdk_version: "29",
73 }
Jiyong Park5e914b22021-03-08 10:09:52 +090074 `
75
Paul Duffin9cbbbb82021-03-18 00:21:03 +000076 mockFS := android.MockFS{
Inseob Kim42882742019-07-30 17:55:33 +090077 "a.java": nil,
78 "b.java": nil,
79 "c.java": nil,
80 "d.cpp": nil,
81 "api/sysprop-platform-current.txt": nil,
82 "api/sysprop-platform-latest.txt": nil,
83 "api/sysprop-platform-on-product-current.txt": nil,
84 "api/sysprop-platform-on-product-latest.txt": nil,
85 "api/sysprop-vendor-current.txt": nil,
86 "api/sysprop-vendor-latest.txt": nil,
Inseob Kimfe612182020-10-20 16:29:55 +090087 "api/sysprop-vendor-on-product-current.txt": nil,
88 "api/sysprop-vendor-on-product-latest.txt": nil,
Inseob Kim42882742019-07-30 17:55:33 +090089 "api/sysprop-odm-current.txt": nil,
90 "api/sysprop-odm-latest.txt": nil,
91 "framework/aidl/a.aidl": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +090092
93 // For framework-res, which is an implicit dependency for framework
Dan Willemsen412160e2019-04-09 21:36:26 -070094 "AndroidManifest.xml": nil,
95 "build/make/target/product/security/testkey": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +090096
97 "build/soong/scripts/jar-wrapper.sh": nil,
98
Inseob Kimc0907f12019-02-08 21:00:45 +090099 "jdk8/jre/lib/jce.jar": nil,
100 "jdk8/jre/lib/rt.jar": nil,
101 "jdk8/lib/tools.jar": nil,
102
103 "bar-doc/a.java": nil,
104 "bar-doc/b.java": nil,
105 "bar-doc/IFoo.aidl": nil,
106 "bar-doc/known_oj_tags.txt": nil,
107 "external/doclava/templates-sdk": nil,
108
109 "cert/new_cert.x509.pem": nil,
110 "cert/new_cert.pk8": nil,
111
112 "android/sysprop/PlatformProperties.sysprop": nil,
113 "com/android/VendorProperties.sysprop": nil,
Inseob Kim42882742019-07-30 17:55:33 +0900114 "com/android2/OdmProperties.sysprop": nil,
Andrew Walbranac0c8732024-02-14 10:25:55 +0000115
116 "librustutils/lib.rs": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900117 }
118
Paul Duffin89648f92021-03-20 00:36:55 +0000119 result := android.GroupFixturePreparers(
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000120 cc.PrepareForTestWithCcDefaultModules,
121 java.PrepareForTestWithJavaDefaultModules,
Andrew Walbranac0c8732024-02-14 10:25:55 +0000122 rust.PrepareForTestWithRustDefaultModules,
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000123 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")
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000128 }),
129 mockFS.AddToFixture(),
130 android.FixtureWithRootAndroidBp(bp),
Paul Duffin89648f92021-03-20 00:36:55 +0000131 ).RunTest(t)
Inseob Kimc0907f12019-02-08 21:00:45 +0900132
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000133 return result
Inseob Kimc0907f12019-02-08 21:00:45 +0900134}
135
136func TestSyspropLibrary(t *testing.T) {
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000137 result := test(t, `
Inseob Kimc0907f12019-02-08 21:00:45 +0900138 sysprop_library {
139 name: "sysprop-platform",
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100140 apex_available: ["//apex_available:platform"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900141 srcs: ["android/sysprop/PlatformProperties.sysprop"],
142 api_packages: ["android.sysprop"],
143 property_owner: "Platform",
144 vendor_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900145 host_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900146 }
147
148 sysprop_library {
149 name: "sysprop-platform-on-product",
150 srcs: ["android/sysprop/PlatformProperties.sysprop"],
151 api_packages: ["android.sysprop"],
152 property_owner: "Platform",
153 product_specific: true,
154 }
155
156 sysprop_library {
157 name: "sysprop-vendor",
158 srcs: ["com/android/VendorProperties.sysprop"],
159 api_packages: ["com.android"],
160 property_owner: "Vendor",
Inseob Kimfe612182020-10-20 16:29:55 +0900161 vendor: true,
162 }
163
164 sysprop_library {
165 name: "sysprop-vendor-on-product",
166 srcs: ["com/android/VendorProperties.sysprop"],
167 api_packages: ["com.android"],
168 property_owner: "Vendor",
Inseob Kimc0907f12019-02-08 21:00:45 +0900169 product_specific: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900170 }
171
Inseob Kim42882742019-07-30 17:55:33 +0900172 sysprop_library {
173 name: "sysprop-odm",
174 srcs: ["com/android2/OdmProperties.sysprop"],
175 api_packages: ["com.android2"],
176 property_owner: "Odm",
177 device_specific: true,
178 }
179
Inseob Kimc0907f12019-02-08 21:00:45 +0900180 java_library {
181 name: "java-platform",
182 srcs: ["c.java"],
183 sdk_version: "system_current",
184 libs: ["sysprop-platform"],
185 }
186
187 java_library {
Inseob Kimac1e9862019-12-09 18:15:47 +0900188 name: "java-platform-private",
189 srcs: ["c.java"],
190 platform_apis: true,
191 libs: ["sysprop-platform"],
192 }
193
194 java_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900195 name: "java-product",
196 srcs: ["c.java"],
197 sdk_version: "system_current",
198 product_specific: true,
Inseob Kimfe612182020-10-20 16:29:55 +0900199 libs: ["sysprop-platform", "sysprop-vendor-on-product"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900200 }
201
202 java_library {
203 name: "java-vendor",
204 srcs: ["c.java"],
205 sdk_version: "system_current",
206 soc_specific: true,
207 libs: ["sysprop-platform", "sysprop-vendor"],
208 }
209
210 cc_library {
211 name: "cc-client-platform",
212 srcs: ["d.cpp"],
Trevor Radcliffed82e8f62022-06-08 16:16:31 +0000213 static_libs: ["libsysprop-platform"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900214 }
215
Jiyong Park5d1598f2019-02-25 22:14:17 +0900216 cc_library_static {
217 name: "cc-client-platform-static",
218 srcs: ["d.cpp"],
Trevor Radcliffed82e8f62022-06-08 16:16:31 +0000219 whole_static_libs: ["libsysprop-platform"],
Jiyong Park5d1598f2019-02-25 22:14:17 +0900220 }
221
Inseob Kimc0907f12019-02-08 21:00:45 +0900222 cc_library {
223 name: "cc-client-product",
224 srcs: ["d.cpp"],
225 product_specific: true,
Trevor Radcliffed82e8f62022-06-08 16:16:31 +0000226 static_libs: ["libsysprop-platform-on-product", "libsysprop-vendor-on-product"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900227 }
228
229 cc_library {
230 name: "cc-client-vendor",
231 srcs: ["d.cpp"],
232 soc_specific: true,
Trevor Radcliffed82e8f62022-06-08 16:16:31 +0000233 static_libs: ["libsysprop-platform", "libsysprop-vendor"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900234 }
Inseob Kim1f959762019-03-27 17:20:37 +0900235
Inseob Kim89db15d2020-02-03 18:06:46 +0900236 cc_binary_host {
237 name: "hostbin",
Trevor Radcliffed82e8f62022-06-08 16:16:31 +0000238 static_libs: ["libsysprop-platform"],
Inseob Kim1f959762019-03-27 17:20:37 +0900239 }
Jiyong Park5e914b22021-03-08 10:09:52 +0900240 `)
Inseob Kimc0907f12019-02-08 21:00:45 +0900241
Inseob Kim42882742019-07-30 17:55:33 +0900242 // Check for generated cc_library
243 for _, variant := range []string{
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900244 "android_vendor.29_arm_armv7-a-neon_shared",
245 "android_vendor.29_arm_armv7-a-neon_static",
246 "android_vendor.29_arm64_armv8-a_shared",
247 "android_vendor.29_arm64_armv8-a_static",
Inseob Kim42882742019-07-30 17:55:33 +0900248 } {
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000249 result.ModuleForTests("libsysprop-platform", variant)
250 result.ModuleForTests("libsysprop-vendor", variant)
251 result.ModuleForTests("libsysprop-odm", variant)
Inseob Kim42882742019-07-30 17:55:33 +0900252 }
253
Inseob Kimc0907f12019-02-08 21:00:45 +0900254 for _, variant := range []string{
Colin Cross7113d202019-11-20 16:39:12 -0800255 "android_arm_armv7-a-neon_shared",
256 "android_arm_armv7-a-neon_static",
257 "android_arm64_armv8-a_shared",
258 "android_arm64_armv8-a_static",
Inseob Kimc0907f12019-02-08 21:00:45 +0900259 } {
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000260 library := result.ModuleForTests("libsysprop-platform", variant).Module().(*cc.Module)
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100261 expectedApexAvailableOnLibrary := []string{"//apex_available:platform"}
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000262 android.AssertDeepEquals(t, "apex available property on libsysprop-platform", expectedApexAvailableOnLibrary, library.ApexProperties.Apex_available)
Inseob Kim42882742019-07-30 17:55:33 +0900263
Inseob Kimfe612182020-10-20 16:29:55 +0900264 // product variant of vendor-owned sysprop_library
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000265 result.ModuleForTests("libsysprop-vendor-on-product", variant)
Inseob Kimc0907f12019-02-08 21:00:45 +0900266 }
267
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000268 result.ModuleForTests("sysprop-platform", "android_common")
269 result.ModuleForTests("sysprop-platform_public", "android_common")
270 result.ModuleForTests("sysprop-vendor", "android_common")
271 result.ModuleForTests("sysprop-vendor-on-product", "android_common")
Inseob Kimc0907f12019-02-08 21:00:45 +0900272
273 // Check for exported includes
Colin Cross7113d202019-11-20 16:39:12 -0800274 coreVariant := "android_arm64_armv8-a_static"
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900275 vendorVariant := "android_vendor.29_arm64_armv8-a_static"
Inseob Kimc0907f12019-02-08 21:00:45 +0900276
Colin Cross7113d202019-11-20 16:39:12 -0800277 platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/include"
278 platformPublicCorePath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/public/include"
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900279 platformPublicVendorPath := "libsysprop-platform/android_vendor.29_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900280
Colin Cross7113d202019-11-20 16:39:12 -0800281 platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900282
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900283 vendorInternalPath := "libsysprop-vendor/android_vendor.29_arm64_armv8-a_static/gen/sysprop/include"
Inseob Kimfe612182020-10-20 16:29:55 +0900284 vendorPublicPath := "libsysprop-vendor-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900285
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000286 platformClient := result.ModuleForTests("cc-client-platform", coreVariant)
Inseob Kimc0907f12019-02-08 21:00:45 +0900287 platformFlags := platformClient.Rule("cc").Args["cFlags"]
288
Jiyong Park5d1598f2019-02-25 22:14:17 +0900289 // platform should use platform's internal header
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000290 android.AssertStringDoesContain(t, "flags for platform", platformFlags, platformInternalPath)
Inseob Kimc0907f12019-02-08 21:00:45 +0900291
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000292 platformStaticClient := result.ModuleForTests("cc-client-platform-static", coreVariant)
Jiyong Park5d1598f2019-02-25 22:14:17 +0900293 platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"]
294
295 // platform-static should use platform's internal header
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000296 android.AssertStringDoesContain(t, "flags for platform-static", platformStaticFlags, platformInternalPath)
Jiyong Park5d1598f2019-02-25 22:14:17 +0900297
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000298 productClient := result.ModuleForTests("cc-client-product", coreVariant)
Inseob Kimc0907f12019-02-08 21:00:45 +0900299 productFlags := productClient.Rule("cc").Args["cFlags"]
300
Inseob Kim5cefbd22019-06-08 20:36:59 +0900301 // Product should use platform's and vendor's public headers
Inseob Kimc0907f12019-02-08 21:00:45 +0900302 if !strings.Contains(productFlags, platformOnProductPath) ||
Inseob Kim5cefbd22019-06-08 20:36:59 +0900303 !strings.Contains(productFlags, vendorPublicPath) {
Inseob Kimc0907f12019-02-08 21:00:45 +0900304 t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900305 platformPublicCorePath, vendorPublicPath, productFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900306 }
307
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000308 vendorClient := result.ModuleForTests("cc-client-vendor", vendorVariant)
Inseob Kimc0907f12019-02-08 21:00:45 +0900309 vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
310
Inseob Kim5cefbd22019-06-08 20:36:59 +0900311 // Vendor should use platform's public header and vendor's internal header
312 if !strings.Contains(vendorFlags, platformPublicVendorPath) ||
Inseob Kimc0907f12019-02-08 21:00:45 +0900313 !strings.Contains(vendorFlags, vendorInternalPath) {
314 t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900315 platformPublicVendorPath, vendorInternalPath, vendorFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900316 }
Inseob Kimac1e9862019-12-09 18:15:47 +0900317
318 // Java modules linking against system API should use public stub
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000319 javaSystemApiClient := result.ModuleForTests("java-platform", "android_common").Rule("javac")
320 syspropPlatformPublic := result.ModuleForTests("sysprop-platform_public", "android_common").Description("for turbine")
Colin Cross75ce9ec2021-02-26 16:20:32 -0800321 if g, w := javaSystemApiClient.Implicits.Strings(), syspropPlatformPublic.Output.String(); !android.InList(w, g) {
322 t.Errorf("system api client should use public stub %q, got %q", w, g)
Inseob Kimac1e9862019-12-09 18:15:47 +0900323 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900324}
Jiyong Park5e914b22021-03-08 10:09:52 +0900325
326func TestApexAvailabilityIsForwarded(t *testing.T) {
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000327 result := test(t, `
Jiyong Park5e914b22021-03-08 10:09:52 +0900328 sysprop_library {
329 name: "sysprop-platform",
330 apex_available: ["//apex_available:platform"],
331 srcs: ["android/sysprop/PlatformProperties.sysprop"],
332 api_packages: ["android.sysprop"],
333 property_owner: "Platform",
334 }
335 `)
336
337 expected := []string{"//apex_available:platform"}
338
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000339 ccModule := result.ModuleForTests("libsysprop-platform", "android_arm64_armv8-a_shared").Module().(*cc.Module)
Jiyong Park5e914b22021-03-08 10:09:52 +0900340 propFromCc := ccModule.ApexProperties.Apex_available
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000341 android.AssertDeepEquals(t, "apex_available forwarding to cc module", expected, propFromCc)
Jiyong Park5e914b22021-03-08 10:09:52 +0900342
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000343 javaModule := result.ModuleForTests("sysprop-platform", "android_common").Module().(*java.Library)
Jiyong Park5e914b22021-03-08 10:09:52 +0900344 propFromJava := javaModule.ApexProperties.Apex_available
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000345 android.AssertDeepEquals(t, "apex_available forwarding to java module", expected, propFromJava)
Andrew Walbranac0c8732024-02-14 10:25:55 +0000346
347 rustModule := result.ModuleForTests("libsysprop_platform_rust", "android_arm64_armv8-a_rlib_rlib-std").Module().(*rust.Module)
348 propFromRust := rustModule.ApexProperties.Apex_available
349 android.AssertDeepEquals(t, "apex_available forwarding to rust module", expected, propFromRust)
Jiyong Park5e914b22021-03-08 10:09:52 +0900350}
351
352func TestMinSdkVersionIsForwarded(t *testing.T) {
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000353 result := test(t, `
Jiyong Park5e914b22021-03-08 10:09:52 +0900354 sysprop_library {
355 name: "sysprop-platform",
356 srcs: ["android/sysprop/PlatformProperties.sysprop"],
357 api_packages: ["android.sysprop"],
358 property_owner: "Platform",
359 cpp: {
360 min_sdk_version: "29",
361 },
362 java: {
363 min_sdk_version: "30",
364 },
Andrew Walbranac0c8732024-02-14 10:25:55 +0000365 rust: {
366 min_sdk_version: "29",
367 }
Jiyong Park5e914b22021-03-08 10:09:52 +0900368 }
369 `)
370
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000371 ccModule := result.ModuleForTests("libsysprop-platform", "android_arm64_armv8-a_shared").Module().(*cc.Module)
Jiyong Park5e914b22021-03-08 10:09:52 +0900372 propFromCc := proptools.String(ccModule.Properties.Min_sdk_version)
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000373 android.AssertStringEquals(t, "min_sdk_version forwarding to cc module", "29", propFromCc)
Jiyong Park5e914b22021-03-08 10:09:52 +0900374
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000375 javaModule := result.ModuleForTests("sysprop-platform", "android_common").Module().(*java.Library)
Jiyong Parkf1691d22021-03-29 20:11:58 +0900376 propFromJava := javaModule.MinSdkVersionString()
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000377 android.AssertStringEquals(t, "min_sdk_version forwarding to java module", "30", propFromJava)
Andrew Walbranac0c8732024-02-14 10:25:55 +0000378
379 rustModule := result.ModuleForTests("libsysprop_platform_rust", "android_arm64_armv8-a_rlib_rlib-std").Module().(*rust.Module)
380 propFromRust := proptools.String(rustModule.Properties.Min_sdk_version)
381 android.AssertStringEquals(t, "min_sdk_version forwarding to rust module", "29", propFromRust)
Jiyong Park5e914b22021-03-08 10:09:52 +0900382}