blob: f42f9e9021e689bf42c66e098c482dd8092dafc8 [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,
45 recovery_available: true,
46 }
47
48 cc_library {
49 name: "liblog",
50 no_libcrt: true,
51 nocrt: true,
52 system_shared_libs: [],
53 recovery_available: true,
54 host_supported: true,
55 llndk_stubs: "liblog.llndk",
56 }
57
58 llndk_library {
59 name: "liblog.llndk",
60 symbol_file: "",
61 }
62
63 java_library {
64 name: "sysprop-library-stub-platform",
65 sdk_version: "core_current",
66 }
67
68 java_library {
69 name: "sysprop-library-stub-vendor",
70 soc_specific: true,
71 sdk_version: "core_current",
72 }
73
74 java_library {
75 name: "sysprop-library-stub-product",
76 product_specific: true,
77 sdk_version: "core_current",
78 }
79 `
80
Paul Duffin9cbbbb82021-03-18 00:21:03 +000081 mockFS := android.MockFS{
Inseob Kim42882742019-07-30 17:55:33 +090082 "a.java": nil,
83 "b.java": nil,
84 "c.java": nil,
85 "d.cpp": nil,
86 "api/sysprop-platform-current.txt": nil,
87 "api/sysprop-platform-latest.txt": nil,
88 "api/sysprop-platform-on-product-current.txt": nil,
89 "api/sysprop-platform-on-product-latest.txt": nil,
90 "api/sysprop-vendor-current.txt": nil,
91 "api/sysprop-vendor-latest.txt": nil,
Inseob Kimfe612182020-10-20 16:29:55 +090092 "api/sysprop-vendor-on-product-current.txt": nil,
93 "api/sysprop-vendor-on-product-latest.txt": nil,
Inseob Kim42882742019-07-30 17:55:33 +090094 "api/sysprop-odm-current.txt": nil,
95 "api/sysprop-odm-latest.txt": nil,
96 "framework/aidl/a.aidl": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +090097
98 // For framework-res, which is an implicit dependency for framework
Dan Willemsen412160e2019-04-09 21:36:26 -070099 "AndroidManifest.xml": nil,
100 "build/make/target/product/security/testkey": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900101
102 "build/soong/scripts/jar-wrapper.sh": nil,
103
104 "build/make/core/proguard.flags": nil,
105 "build/make/core/proguard_basic_keeps.flags": nil,
106
107 "jdk8/jre/lib/jce.jar": nil,
108 "jdk8/jre/lib/rt.jar": nil,
109 "jdk8/lib/tools.jar": nil,
110
111 "bar-doc/a.java": nil,
112 "bar-doc/b.java": nil,
113 "bar-doc/IFoo.aidl": nil,
114 "bar-doc/known_oj_tags.txt": nil,
115 "external/doclava/templates-sdk": nil,
116
117 "cert/new_cert.x509.pem": nil,
118 "cert/new_cert.pk8": nil,
119
120 "android/sysprop/PlatformProperties.sysprop": nil,
121 "com/android/VendorProperties.sysprop": nil,
Inseob Kim42882742019-07-30 17:55:33 +0900122 "com/android2/OdmProperties.sysprop": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900123 }
124
Paul Duffin89648f92021-03-20 00:36:55 +0000125 result := android.GroupFixturePreparers(
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000126 cc.PrepareForTestWithCcDefaultModules,
127 java.PrepareForTestWithJavaDefaultModules,
128 PrepareForTestWithSyspropBuildComponents,
129 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
130 variables.DeviceSystemSdkVersions = []string{"28"}
131 variables.DeviceVndkVersion = proptools.StringPtr("current")
132 variables.Platform_vndk_version = proptools.StringPtr("VER")
133 }),
134 mockFS.AddToFixture(),
135 android.FixtureWithRootAndroidBp(bp),
Paul Duffin89648f92021-03-20 00:36:55 +0000136 ).RunTest(t)
Inseob Kimc0907f12019-02-08 21:00:45 +0900137
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000138 return result
Inseob Kimc0907f12019-02-08 21:00:45 +0900139}
140
141func TestSyspropLibrary(t *testing.T) {
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000142 result := test(t, `
Inseob Kimc0907f12019-02-08 21:00:45 +0900143 sysprop_library {
144 name: "sysprop-platform",
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100145 apex_available: ["//apex_available:platform"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900146 srcs: ["android/sysprop/PlatformProperties.sysprop"],
147 api_packages: ["android.sysprop"],
148 property_owner: "Platform",
149 vendor_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900150 host_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900151 }
152
153 sysprop_library {
154 name: "sysprop-platform-on-product",
155 srcs: ["android/sysprop/PlatformProperties.sysprop"],
156 api_packages: ["android.sysprop"],
157 property_owner: "Platform",
158 product_specific: true,
159 }
160
161 sysprop_library {
162 name: "sysprop-vendor",
163 srcs: ["com/android/VendorProperties.sysprop"],
164 api_packages: ["com.android"],
165 property_owner: "Vendor",
Inseob Kimfe612182020-10-20 16:29:55 +0900166 vendor: true,
167 }
168
169 sysprop_library {
170 name: "sysprop-vendor-on-product",
171 srcs: ["com/android/VendorProperties.sysprop"],
172 api_packages: ["com.android"],
173 property_owner: "Vendor",
Inseob Kimc0907f12019-02-08 21:00:45 +0900174 product_specific: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900175 }
176
Inseob Kim42882742019-07-30 17:55:33 +0900177 sysprop_library {
178 name: "sysprop-odm",
179 srcs: ["com/android2/OdmProperties.sysprop"],
180 api_packages: ["com.android2"],
181 property_owner: "Odm",
182 device_specific: true,
183 }
184
Inseob Kimc0907f12019-02-08 21:00:45 +0900185 java_library {
186 name: "java-platform",
187 srcs: ["c.java"],
188 sdk_version: "system_current",
189 libs: ["sysprop-platform"],
190 }
191
192 java_library {
Inseob Kimac1e9862019-12-09 18:15:47 +0900193 name: "java-platform-private",
194 srcs: ["c.java"],
195 platform_apis: true,
196 libs: ["sysprop-platform"],
197 }
198
199 java_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900200 name: "java-product",
201 srcs: ["c.java"],
202 sdk_version: "system_current",
203 product_specific: true,
Inseob Kimfe612182020-10-20 16:29:55 +0900204 libs: ["sysprop-platform", "sysprop-vendor-on-product"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900205 }
206
207 java_library {
208 name: "java-vendor",
209 srcs: ["c.java"],
210 sdk_version: "system_current",
211 soc_specific: true,
212 libs: ["sysprop-platform", "sysprop-vendor"],
213 }
214
215 cc_library {
216 name: "cc-client-platform",
217 srcs: ["d.cpp"],
218 static_libs: ["sysprop-platform"],
219 }
220
Jiyong Park5d1598f2019-02-25 22:14:17 +0900221 cc_library_static {
222 name: "cc-client-platform-static",
223 srcs: ["d.cpp"],
224 whole_static_libs: ["sysprop-platform"],
225 }
226
Inseob Kimc0907f12019-02-08 21:00:45 +0900227 cc_library {
228 name: "cc-client-product",
229 srcs: ["d.cpp"],
230 product_specific: true,
Inseob Kimfe612182020-10-20 16:29:55 +0900231 static_libs: ["sysprop-platform-on-product", "sysprop-vendor-on-product"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900232 }
233
234 cc_library {
235 name: "cc-client-vendor",
236 srcs: ["d.cpp"],
237 soc_specific: true,
238 static_libs: ["sysprop-platform", "sysprop-vendor"],
239 }
Inseob Kim1f959762019-03-27 17:20:37 +0900240
Inseob Kim89db15d2020-02-03 18:06:46 +0900241 cc_binary_host {
242 name: "hostbin",
243 static_libs: ["sysprop-platform"],
Inseob Kim1f959762019-03-27 17:20:37 +0900244 }
Jiyong Park5e914b22021-03-08 10:09:52 +0900245 `)
Inseob Kimc0907f12019-02-08 21:00:45 +0900246
Inseob Kim42882742019-07-30 17:55:33 +0900247 // Check for generated cc_library
248 for _, variant := range []string{
Colin Crossfb0c16e2019-11-20 17:12:35 -0800249 "android_vendor.VER_arm_armv7-a-neon_shared",
250 "android_vendor.VER_arm_armv7-a-neon_static",
251 "android_vendor.VER_arm64_armv8-a_shared",
252 "android_vendor.VER_arm64_armv8-a_static",
Inseob Kim42882742019-07-30 17:55:33 +0900253 } {
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000254 result.ModuleForTests("libsysprop-platform", variant)
255 result.ModuleForTests("libsysprop-vendor", variant)
256 result.ModuleForTests("libsysprop-odm", variant)
Inseob Kim42882742019-07-30 17:55:33 +0900257 }
258
Inseob Kimc0907f12019-02-08 21:00:45 +0900259 for _, variant := range []string{
Colin Cross7113d202019-11-20 16:39:12 -0800260 "android_arm_armv7-a-neon_shared",
261 "android_arm_armv7-a-neon_static",
262 "android_arm64_armv8-a_shared",
263 "android_arm64_armv8-a_static",
Inseob Kimc0907f12019-02-08 21:00:45 +0900264 } {
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000265 library := result.ModuleForTests("libsysprop-platform", variant).Module().(*cc.Module)
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100266 expectedApexAvailableOnLibrary := []string{"//apex_available:platform"}
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000267 android.AssertDeepEquals(t, "apex available property on libsysprop-platform", expectedApexAvailableOnLibrary, library.ApexProperties.Apex_available)
Inseob Kim42882742019-07-30 17:55:33 +0900268
Inseob Kimfe612182020-10-20 16:29:55 +0900269 // product variant of vendor-owned sysprop_library
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000270 result.ModuleForTests("libsysprop-vendor-on-product", variant)
Inseob Kimc0907f12019-02-08 21:00:45 +0900271 }
272
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000273 result.ModuleForTests("sysprop-platform", "android_common")
274 result.ModuleForTests("sysprop-platform_public", "android_common")
275 result.ModuleForTests("sysprop-vendor", "android_common")
276 result.ModuleForTests("sysprop-vendor-on-product", "android_common")
Inseob Kimc0907f12019-02-08 21:00:45 +0900277
278 // Check for exported includes
Colin Cross7113d202019-11-20 16:39:12 -0800279 coreVariant := "android_arm64_armv8-a_static"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800280 vendorVariant := "android_vendor.VER_arm64_armv8-a_static"
Inseob Kimc0907f12019-02-08 21:00:45 +0900281
Colin Cross7113d202019-11-20 16:39:12 -0800282 platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/include"
283 platformPublicCorePath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/public/include"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800284 platformPublicVendorPath := "libsysprop-platform/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900285
Colin Cross7113d202019-11-20 16:39:12 -0800286 platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900287
Colin Crossfb0c16e2019-11-20 17:12:35 -0800288 vendorInternalPath := "libsysprop-vendor/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/include"
Inseob Kimfe612182020-10-20 16:29:55 +0900289 vendorPublicPath := "libsysprop-vendor-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900290
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000291 platformClient := result.ModuleForTests("cc-client-platform", coreVariant)
Inseob Kimc0907f12019-02-08 21:00:45 +0900292 platformFlags := platformClient.Rule("cc").Args["cFlags"]
293
Jiyong Park5d1598f2019-02-25 22:14:17 +0900294 // platform should use platform's internal header
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000295 android.AssertStringDoesContain(t, "flags for platform", platformFlags, platformInternalPath)
Inseob Kimc0907f12019-02-08 21:00:45 +0900296
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000297 platformStaticClient := result.ModuleForTests("cc-client-platform-static", coreVariant)
Jiyong Park5d1598f2019-02-25 22:14:17 +0900298 platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"]
299
300 // platform-static should use platform's internal header
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000301 android.AssertStringDoesContain(t, "flags for platform-static", platformStaticFlags, platformInternalPath)
Jiyong Park5d1598f2019-02-25 22:14:17 +0900302
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000303 productClient := result.ModuleForTests("cc-client-product", coreVariant)
Inseob Kimc0907f12019-02-08 21:00:45 +0900304 productFlags := productClient.Rule("cc").Args["cFlags"]
305
Inseob Kim5cefbd22019-06-08 20:36:59 +0900306 // Product should use platform's and vendor's public headers
Inseob Kimc0907f12019-02-08 21:00:45 +0900307 if !strings.Contains(productFlags, platformOnProductPath) ||
Inseob Kim5cefbd22019-06-08 20:36:59 +0900308 !strings.Contains(productFlags, vendorPublicPath) {
Inseob Kimc0907f12019-02-08 21:00:45 +0900309 t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900310 platformPublicCorePath, vendorPublicPath, productFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900311 }
312
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000313 vendorClient := result.ModuleForTests("cc-client-vendor", vendorVariant)
Inseob Kimc0907f12019-02-08 21:00:45 +0900314 vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
315
Inseob Kim5cefbd22019-06-08 20:36:59 +0900316 // Vendor should use platform's public header and vendor's internal header
317 if !strings.Contains(vendorFlags, platformPublicVendorPath) ||
Inseob Kimc0907f12019-02-08 21:00:45 +0900318 !strings.Contains(vendorFlags, vendorInternalPath) {
319 t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900320 platformPublicVendorPath, vendorInternalPath, vendorFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900321 }
Inseob Kimac1e9862019-12-09 18:15:47 +0900322
323 // Java modules linking against system API should use public stub
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000324 javaSystemApiClient := result.ModuleForTests("java-platform", "android_common").Rule("javac")
325 syspropPlatformPublic := result.ModuleForTests("sysprop-platform_public", "android_common").Description("for turbine")
Colin Cross75ce9ec2021-02-26 16:20:32 -0800326 if g, w := javaSystemApiClient.Implicits.Strings(), syspropPlatformPublic.Output.String(); !android.InList(w, g) {
327 t.Errorf("system api client should use public stub %q, got %q", w, g)
Inseob Kimac1e9862019-12-09 18:15:47 +0900328 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900329}
Jiyong Park5e914b22021-03-08 10:09:52 +0900330
331func TestApexAvailabilityIsForwarded(t *testing.T) {
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000332 result := test(t, `
Jiyong Park5e914b22021-03-08 10:09:52 +0900333 sysprop_library {
334 name: "sysprop-platform",
335 apex_available: ["//apex_available:platform"],
336 srcs: ["android/sysprop/PlatformProperties.sysprop"],
337 api_packages: ["android.sysprop"],
338 property_owner: "Platform",
339 }
340 `)
341
342 expected := []string{"//apex_available:platform"}
343
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000344 ccModule := result.ModuleForTests("libsysprop-platform", "android_arm64_armv8-a_shared").Module().(*cc.Module)
Jiyong Park5e914b22021-03-08 10:09:52 +0900345 propFromCc := ccModule.ApexProperties.Apex_available
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000346 android.AssertDeepEquals(t, "apex_available forwarding to cc module", expected, propFromCc)
Jiyong Park5e914b22021-03-08 10:09:52 +0900347
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000348 javaModule := result.ModuleForTests("sysprop-platform", "android_common").Module().(*java.Library)
Jiyong Park5e914b22021-03-08 10:09:52 +0900349 propFromJava := javaModule.ApexProperties.Apex_available
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000350 android.AssertDeepEquals(t, "apex_available forwarding to java module", expected, propFromJava)
Jiyong Park5e914b22021-03-08 10:09:52 +0900351}
352
353func TestMinSdkVersionIsForwarded(t *testing.T) {
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000354 result := test(t, `
Jiyong Park5e914b22021-03-08 10:09:52 +0900355 sysprop_library {
356 name: "sysprop-platform",
357 srcs: ["android/sysprop/PlatformProperties.sysprop"],
358 api_packages: ["android.sysprop"],
359 property_owner: "Platform",
360 cpp: {
361 min_sdk_version: "29",
362 },
363 java: {
364 min_sdk_version: "30",
365 },
366 }
367 `)
368
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000369 ccModule := result.ModuleForTests("libsysprop-platform", "android_arm64_armv8-a_shared").Module().(*cc.Module)
Jiyong Park5e914b22021-03-08 10:09:52 +0900370 propFromCc := proptools.String(ccModule.Properties.Min_sdk_version)
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000371 android.AssertStringEquals(t, "min_sdk_version forwarding to cc module", "29", propFromCc)
Jiyong Park5e914b22021-03-08 10:09:52 +0900372
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000373 javaModule := result.ModuleForTests("sysprop-platform", "android_common").Module().(*java.Library)
Jiyong Parkf1691d22021-03-29 20:11:58 +0900374 propFromJava := javaModule.MinSdkVersionString()
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000375 android.AssertStringEquals(t, "min_sdk_version forwarding to java module", "30", propFromJava)
Jiyong Park5e914b22021-03-08 10:09:52 +0900376}