blob: 88ef615244548f1a0481ddb4fca18a96f984a9dc [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,
Colin Cross203b4212021-04-26 17:19:41 -070055 llndk: {
56 symbol_file: "liblog.map.txt",
57 }
Jiyong Park5e914b22021-03-08 10:09:52 +090058 }
59
60 java_library {
61 name: "sysprop-library-stub-platform",
62 sdk_version: "core_current",
63 }
64
65 java_library {
66 name: "sysprop-library-stub-vendor",
67 soc_specific: true,
68 sdk_version: "core_current",
69 }
70
71 java_library {
72 name: "sysprop-library-stub-product",
73 product_specific: true,
74 sdk_version: "core_current",
75 }
76 `
77
Paul Duffin9cbbbb82021-03-18 00:21:03 +000078 mockFS := android.MockFS{
Inseob Kim42882742019-07-30 17:55:33 +090079 "a.java": nil,
80 "b.java": nil,
81 "c.java": nil,
82 "d.cpp": nil,
83 "api/sysprop-platform-current.txt": nil,
84 "api/sysprop-platform-latest.txt": nil,
85 "api/sysprop-platform-on-product-current.txt": nil,
86 "api/sysprop-platform-on-product-latest.txt": nil,
87 "api/sysprop-vendor-current.txt": nil,
88 "api/sysprop-vendor-latest.txt": nil,
Inseob Kimfe612182020-10-20 16:29:55 +090089 "api/sysprop-vendor-on-product-current.txt": nil,
90 "api/sysprop-vendor-on-product-latest.txt": nil,
Inseob Kim42882742019-07-30 17:55:33 +090091 "api/sysprop-odm-current.txt": nil,
92 "api/sysprop-odm-latest.txt": nil,
93 "framework/aidl/a.aidl": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +090094
95 // For framework-res, which is an implicit dependency for framework
Dan Willemsen412160e2019-04-09 21:36:26 -070096 "AndroidManifest.xml": nil,
97 "build/make/target/product/security/testkey": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +090098
99 "build/soong/scripts/jar-wrapper.sh": nil,
100
Inseob Kimc0907f12019-02-08 21:00:45 +0900101 "jdk8/jre/lib/jce.jar": nil,
102 "jdk8/jre/lib/rt.jar": nil,
103 "jdk8/lib/tools.jar": nil,
104
105 "bar-doc/a.java": nil,
106 "bar-doc/b.java": nil,
107 "bar-doc/IFoo.aidl": nil,
108 "bar-doc/known_oj_tags.txt": nil,
109 "external/doclava/templates-sdk": nil,
110
111 "cert/new_cert.x509.pem": nil,
112 "cert/new_cert.pk8": nil,
113
114 "android/sysprop/PlatformProperties.sysprop": nil,
115 "com/android/VendorProperties.sysprop": nil,
Inseob Kim42882742019-07-30 17:55:33 +0900116 "com/android2/OdmProperties.sysprop": 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,
122 PrepareForTestWithSyspropBuildComponents,
123 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
124 variables.DeviceSystemSdkVersions = []string{"28"}
125 variables.DeviceVndkVersion = proptools.StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900126 variables.Platform_vndk_version = proptools.StringPtr("29")
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000127 }),
128 mockFS.AddToFixture(),
129 android.FixtureWithRootAndroidBp(bp),
Paul Duffin89648f92021-03-20 00:36:55 +0000130 ).RunTest(t)
Inseob Kimc0907f12019-02-08 21:00:45 +0900131
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000132 return result
Inseob Kimc0907f12019-02-08 21:00:45 +0900133}
134
135func TestSyspropLibrary(t *testing.T) {
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000136 result := test(t, `
Inseob Kimc0907f12019-02-08 21:00:45 +0900137 sysprop_library {
138 name: "sysprop-platform",
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100139 apex_available: ["//apex_available:platform"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900140 srcs: ["android/sysprop/PlatformProperties.sysprop"],
141 api_packages: ["android.sysprop"],
142 property_owner: "Platform",
143 vendor_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900144 host_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900145 }
146
147 sysprop_library {
148 name: "sysprop-platform-on-product",
149 srcs: ["android/sysprop/PlatformProperties.sysprop"],
150 api_packages: ["android.sysprop"],
151 property_owner: "Platform",
152 product_specific: true,
153 }
154
155 sysprop_library {
156 name: "sysprop-vendor",
157 srcs: ["com/android/VendorProperties.sysprop"],
158 api_packages: ["com.android"],
159 property_owner: "Vendor",
Inseob Kimfe612182020-10-20 16:29:55 +0900160 vendor: true,
161 }
162
163 sysprop_library {
164 name: "sysprop-vendor-on-product",
165 srcs: ["com/android/VendorProperties.sysprop"],
166 api_packages: ["com.android"],
167 property_owner: "Vendor",
Inseob Kimc0907f12019-02-08 21:00:45 +0900168 product_specific: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900169 }
170
Inseob Kim42882742019-07-30 17:55:33 +0900171 sysprop_library {
172 name: "sysprop-odm",
173 srcs: ["com/android2/OdmProperties.sysprop"],
174 api_packages: ["com.android2"],
175 property_owner: "Odm",
176 device_specific: true,
177 }
178
Inseob Kimc0907f12019-02-08 21:00:45 +0900179 java_library {
180 name: "java-platform",
181 srcs: ["c.java"],
182 sdk_version: "system_current",
183 libs: ["sysprop-platform"],
184 }
185
186 java_library {
Inseob Kimac1e9862019-12-09 18:15:47 +0900187 name: "java-platform-private",
188 srcs: ["c.java"],
189 platform_apis: true,
190 libs: ["sysprop-platform"],
191 }
192
193 java_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900194 name: "java-product",
195 srcs: ["c.java"],
196 sdk_version: "system_current",
197 product_specific: true,
Inseob Kimfe612182020-10-20 16:29:55 +0900198 libs: ["sysprop-platform", "sysprop-vendor-on-product"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900199 }
200
201 java_library {
202 name: "java-vendor",
203 srcs: ["c.java"],
204 sdk_version: "system_current",
205 soc_specific: true,
206 libs: ["sysprop-platform", "sysprop-vendor"],
207 }
208
209 cc_library {
210 name: "cc-client-platform",
211 srcs: ["d.cpp"],
212 static_libs: ["sysprop-platform"],
213 }
214
Jiyong Park5d1598f2019-02-25 22:14:17 +0900215 cc_library_static {
216 name: "cc-client-platform-static",
217 srcs: ["d.cpp"],
218 whole_static_libs: ["sysprop-platform"],
219 }
220
Inseob Kimc0907f12019-02-08 21:00:45 +0900221 cc_library {
222 name: "cc-client-product",
223 srcs: ["d.cpp"],
224 product_specific: true,
Inseob Kimfe612182020-10-20 16:29:55 +0900225 static_libs: ["sysprop-platform-on-product", "sysprop-vendor-on-product"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900226 }
227
228 cc_library {
229 name: "cc-client-vendor",
230 srcs: ["d.cpp"],
231 soc_specific: true,
232 static_libs: ["sysprop-platform", "sysprop-vendor"],
233 }
Inseob Kim1f959762019-03-27 17:20:37 +0900234
Inseob Kim89db15d2020-02-03 18:06:46 +0900235 cc_binary_host {
236 name: "hostbin",
237 static_libs: ["sysprop-platform"],
Inseob Kim1f959762019-03-27 17:20:37 +0900238 }
Jiyong Park5e914b22021-03-08 10:09:52 +0900239 `)
Inseob Kimc0907f12019-02-08 21:00:45 +0900240
Inseob Kim42882742019-07-30 17:55:33 +0900241 // Check for generated cc_library
242 for _, variant := range []string{
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900243 "android_vendor.29_arm_armv7-a-neon_shared",
244 "android_vendor.29_arm_armv7-a-neon_static",
245 "android_vendor.29_arm64_armv8-a_shared",
246 "android_vendor.29_arm64_armv8-a_static",
Inseob Kim42882742019-07-30 17:55:33 +0900247 } {
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000248 result.ModuleForTests("libsysprop-platform", variant)
249 result.ModuleForTests("libsysprop-vendor", variant)
250 result.ModuleForTests("libsysprop-odm", variant)
Inseob Kim42882742019-07-30 17:55:33 +0900251 }
252
Inseob Kimc0907f12019-02-08 21:00:45 +0900253 for _, variant := range []string{
Colin Cross7113d202019-11-20 16:39:12 -0800254 "android_arm_armv7-a-neon_shared",
255 "android_arm_armv7-a-neon_static",
256 "android_arm64_armv8-a_shared",
257 "android_arm64_armv8-a_static",
Inseob Kimc0907f12019-02-08 21:00:45 +0900258 } {
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000259 library := result.ModuleForTests("libsysprop-platform", variant).Module().(*cc.Module)
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100260 expectedApexAvailableOnLibrary := []string{"//apex_available:platform"}
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000261 android.AssertDeepEquals(t, "apex available property on libsysprop-platform", expectedApexAvailableOnLibrary, library.ApexProperties.Apex_available)
Inseob Kim42882742019-07-30 17:55:33 +0900262
Inseob Kimfe612182020-10-20 16:29:55 +0900263 // product variant of vendor-owned sysprop_library
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000264 result.ModuleForTests("libsysprop-vendor-on-product", variant)
Inseob Kimc0907f12019-02-08 21:00:45 +0900265 }
266
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000267 result.ModuleForTests("sysprop-platform", "android_common")
268 result.ModuleForTests("sysprop-platform_public", "android_common")
269 result.ModuleForTests("sysprop-vendor", "android_common")
270 result.ModuleForTests("sysprop-vendor-on-product", "android_common")
Inseob Kimc0907f12019-02-08 21:00:45 +0900271
272 // Check for exported includes
Colin Cross7113d202019-11-20 16:39:12 -0800273 coreVariant := "android_arm64_armv8-a_static"
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900274 vendorVariant := "android_vendor.29_arm64_armv8-a_static"
Inseob Kimc0907f12019-02-08 21:00:45 +0900275
Colin Cross7113d202019-11-20 16:39:12 -0800276 platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/include"
277 platformPublicCorePath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/public/include"
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900278 platformPublicVendorPath := "libsysprop-platform/android_vendor.29_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900279
Colin Cross7113d202019-11-20 16:39:12 -0800280 platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900281
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900282 vendorInternalPath := "libsysprop-vendor/android_vendor.29_arm64_armv8-a_static/gen/sysprop/include"
Inseob Kimfe612182020-10-20 16:29:55 +0900283 vendorPublicPath := "libsysprop-vendor-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900284
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000285 platformClient := result.ModuleForTests("cc-client-platform", coreVariant)
Inseob Kimc0907f12019-02-08 21:00:45 +0900286 platformFlags := platformClient.Rule("cc").Args["cFlags"]
287
Jiyong Park5d1598f2019-02-25 22:14:17 +0900288 // platform should use platform's internal header
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000289 android.AssertStringDoesContain(t, "flags for platform", platformFlags, platformInternalPath)
Inseob Kimc0907f12019-02-08 21:00:45 +0900290
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000291 platformStaticClient := result.ModuleForTests("cc-client-platform-static", coreVariant)
Jiyong Park5d1598f2019-02-25 22:14:17 +0900292 platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"]
293
294 // platform-static should use platform's internal header
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000295 android.AssertStringDoesContain(t, "flags for platform-static", platformStaticFlags, platformInternalPath)
Jiyong Park5d1598f2019-02-25 22:14:17 +0900296
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000297 productClient := result.ModuleForTests("cc-client-product", coreVariant)
Inseob Kimc0907f12019-02-08 21:00:45 +0900298 productFlags := productClient.Rule("cc").Args["cFlags"]
299
Inseob Kim5cefbd22019-06-08 20:36:59 +0900300 // Product should use platform's and vendor's public headers
Inseob Kimc0907f12019-02-08 21:00:45 +0900301 if !strings.Contains(productFlags, platformOnProductPath) ||
Inseob Kim5cefbd22019-06-08 20:36:59 +0900302 !strings.Contains(productFlags, vendorPublicPath) {
Inseob Kimc0907f12019-02-08 21:00:45 +0900303 t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900304 platformPublicCorePath, vendorPublicPath, productFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900305 }
306
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000307 vendorClient := result.ModuleForTests("cc-client-vendor", vendorVariant)
Inseob Kimc0907f12019-02-08 21:00:45 +0900308 vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
309
Inseob Kim5cefbd22019-06-08 20:36:59 +0900310 // Vendor should use platform's public header and vendor's internal header
311 if !strings.Contains(vendorFlags, platformPublicVendorPath) ||
Inseob Kimc0907f12019-02-08 21:00:45 +0900312 !strings.Contains(vendorFlags, vendorInternalPath) {
313 t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900314 platformPublicVendorPath, vendorInternalPath, vendorFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900315 }
Inseob Kimac1e9862019-12-09 18:15:47 +0900316
317 // Java modules linking against system API should use public stub
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000318 javaSystemApiClient := result.ModuleForTests("java-platform", "android_common").Rule("javac")
319 syspropPlatformPublic := result.ModuleForTests("sysprop-platform_public", "android_common").Description("for turbine")
Colin Cross75ce9ec2021-02-26 16:20:32 -0800320 if g, w := javaSystemApiClient.Implicits.Strings(), syspropPlatformPublic.Output.String(); !android.InList(w, g) {
321 t.Errorf("system api client should use public stub %q, got %q", w, g)
Inseob Kimac1e9862019-12-09 18:15:47 +0900322 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900323}
Jiyong Park5e914b22021-03-08 10:09:52 +0900324
325func TestApexAvailabilityIsForwarded(t *testing.T) {
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000326 result := test(t, `
Jiyong Park5e914b22021-03-08 10:09:52 +0900327 sysprop_library {
328 name: "sysprop-platform",
329 apex_available: ["//apex_available:platform"],
330 srcs: ["android/sysprop/PlatformProperties.sysprop"],
331 api_packages: ["android.sysprop"],
332 property_owner: "Platform",
333 }
334 `)
335
336 expected := []string{"//apex_available:platform"}
337
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000338 ccModule := result.ModuleForTests("libsysprop-platform", "android_arm64_armv8-a_shared").Module().(*cc.Module)
Jiyong Park5e914b22021-03-08 10:09:52 +0900339 propFromCc := ccModule.ApexProperties.Apex_available
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000340 android.AssertDeepEquals(t, "apex_available forwarding to cc module", expected, propFromCc)
Jiyong Park5e914b22021-03-08 10:09:52 +0900341
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000342 javaModule := result.ModuleForTests("sysprop-platform", "android_common").Module().(*java.Library)
Jiyong Park5e914b22021-03-08 10:09:52 +0900343 propFromJava := javaModule.ApexProperties.Apex_available
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000344 android.AssertDeepEquals(t, "apex_available forwarding to java module", expected, propFromJava)
Jiyong Park5e914b22021-03-08 10:09:52 +0900345}
346
347func TestMinSdkVersionIsForwarded(t *testing.T) {
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000348 result := test(t, `
Jiyong Park5e914b22021-03-08 10:09:52 +0900349 sysprop_library {
350 name: "sysprop-platform",
351 srcs: ["android/sysprop/PlatformProperties.sysprop"],
352 api_packages: ["android.sysprop"],
353 property_owner: "Platform",
354 cpp: {
355 min_sdk_version: "29",
356 },
357 java: {
358 min_sdk_version: "30",
359 },
360 }
361 `)
362
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000363 ccModule := result.ModuleForTests("libsysprop-platform", "android_arm64_armv8-a_shared").Module().(*cc.Module)
Jiyong Park5e914b22021-03-08 10:09:52 +0900364 propFromCc := proptools.String(ccModule.Properties.Min_sdk_version)
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000365 android.AssertStringEquals(t, "min_sdk_version forwarding to cc module", "29", propFromCc)
Jiyong Park5e914b22021-03-08 10:09:52 +0900366
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000367 javaModule := result.ModuleForTests("sysprop-platform", "android_common").Module().(*java.Library)
Jiyong Parkf1691d22021-03-29 20:11:58 +0900368 propFromJava := javaModule.MinSdkVersionString()
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000369 android.AssertStringEquals(t, "min_sdk_version forwarding to java module", "30", propFromJava)
Jiyong Park5e914b22021-03-08 10:09:52 +0900370}