blob: b8b93f631ced6e46f8d95d3edc805fbb40ce3767 [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 Duffin7b3de8f2020-03-30 18:00:25 +010018 "reflect"
19
Inseob Kimc0907f12019-02-08 21:00:45 +090020 "android/soong/android"
21 "android/soong/cc"
22 "android/soong/java"
23
Inseob Kimc0907f12019-02-08 21:00:45 +090024 "io/ioutil"
25 "os"
26 "strings"
27 "testing"
28
Inseob Kimac1e9862019-12-09 18:15:47 +090029 "github.com/google/blueprint"
Inseob Kimc0907f12019-02-08 21:00:45 +090030 "github.com/google/blueprint/proptools"
31)
32
33var buildDir string
34
35func setUp() {
36 var err error
37 buildDir, err = ioutil.TempDir("", "soong_sysprop_test")
38 if err != nil {
39 panic(err)
40 }
41}
42
43func tearDown() {
44 os.RemoveAll(buildDir)
45}
46
47func TestMain(m *testing.M) {
48 run := func() int {
49 setUp()
50 defer tearDown()
51
52 return m.Run()
53 }
54
55 os.Exit(run())
56}
57
Colin Cross98be1bb2019-12-13 20:41:13 -080058func testContext(config android.Config) *android.TestContext {
Inseob Kimc0907f12019-02-08 21:00:45 +090059
Colin Crossae8600b2020-10-29 17:09:13 -070060 ctx := android.NewTestArchContext(config)
Paul Duffinf9b1da02019-12-18 19:51:55 +000061 java.RegisterJavaBuildComponents(ctx)
62 java.RegisterAppBuildComponents(ctx)
Paul Duffin43dc1cc2019-12-19 11:18:54 +000063 java.RegisterSystemModulesBuildComponents(ctx)
64
Inseob Kimc0907f12019-02-08 21:00:45 +090065 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Inseob Kim988f53c2019-09-16 15:59:01 +090066 ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
67 ctx.BottomUp("sysprop_deps", syspropDepsMutator).Parallel()
68 })
Inseob Kimc0907f12019-02-08 21:00:45 +090069
Paul Duffin021f4e52020-07-30 16:04:17 +010070 android.RegisterPrebuiltMutators(ctx)
71
Paul Duffin77980a82019-12-19 16:01:36 +000072 cc.RegisterRequiredBuildComponentsForTest(ctx)
Inseob Kimc0907f12019-02-08 21:00:45 +090073 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Inseob Kimac1e9862019-12-09 18:15:47 +090074 ctx.BottomUp("sysprop_java", java.SyspropMutator).Parallel()
Inseob Kimc0907f12019-02-08 21:00:45 +090075 })
76
Colin Cross4b49b762019-11-22 15:25:03 -080077 ctx.RegisterModuleType("sysprop_library", syspropLibraryFactory)
Inseob Kimc0907f12019-02-08 21:00:45 +090078
Colin Crossae8600b2020-10-29 17:09:13 -070079 ctx.Register()
Inseob Kimc0907f12019-02-08 21:00:45 +090080
Colin Cross98be1bb2019-12-13 20:41:13 -080081 return ctx
82}
83
84func run(t *testing.T, ctx *android.TestContext, config android.Config) {
85 t.Helper()
86 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
87 android.FailIfErrored(t, errs)
88 _, errs = ctx.PrepareBuildActions(config)
89 android.FailIfErrored(t, errs)
90}
91
92func testConfig(env map[string]string, bp string, fs map[string][]byte) android.Config {
Inseob Kimc0907f12019-02-08 21:00:45 +090093 bp += cc.GatherRequiredDepsForTest(android.Android)
94
95 mockFS := map[string][]byte{
Inseob Kim42882742019-07-30 17:55:33 +090096 "a.java": nil,
97 "b.java": nil,
98 "c.java": nil,
99 "d.cpp": nil,
100 "api/sysprop-platform-current.txt": nil,
101 "api/sysprop-platform-latest.txt": nil,
102 "api/sysprop-platform-on-product-current.txt": nil,
103 "api/sysprop-platform-on-product-latest.txt": nil,
104 "api/sysprop-vendor-current.txt": nil,
105 "api/sysprop-vendor-latest.txt": nil,
Inseob Kimfe612182020-10-20 16:29:55 +0900106 "api/sysprop-vendor-on-product-current.txt": nil,
107 "api/sysprop-vendor-on-product-latest.txt": nil,
Inseob Kim42882742019-07-30 17:55:33 +0900108 "api/sysprop-odm-current.txt": nil,
109 "api/sysprop-odm-latest.txt": nil,
110 "framework/aidl/a.aidl": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900111
112 // For framework-res, which is an implicit dependency for framework
Dan Willemsen412160e2019-04-09 21:36:26 -0700113 "AndroidManifest.xml": nil,
114 "build/make/target/product/security/testkey": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900115
116 "build/soong/scripts/jar-wrapper.sh": nil,
117
118 "build/make/core/proguard.flags": nil,
119 "build/make/core/proguard_basic_keeps.flags": nil,
120
121 "jdk8/jre/lib/jce.jar": nil,
122 "jdk8/jre/lib/rt.jar": nil,
123 "jdk8/lib/tools.jar": nil,
124
125 "bar-doc/a.java": nil,
126 "bar-doc/b.java": nil,
127 "bar-doc/IFoo.aidl": nil,
128 "bar-doc/known_oj_tags.txt": nil,
129 "external/doclava/templates-sdk": nil,
130
131 "cert/new_cert.x509.pem": nil,
132 "cert/new_cert.pk8": nil,
133
134 "android/sysprop/PlatformProperties.sysprop": nil,
135 "com/android/VendorProperties.sysprop": nil,
Inseob Kim42882742019-07-30 17:55:33 +0900136 "com/android2/OdmProperties.sysprop": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900137 }
138
139 for k, v := range fs {
140 mockFS[k] = v
141 }
142
Colin Cross98be1bb2019-12-13 20:41:13 -0800143 config := java.TestConfig(buildDir, env, bp, mockFS)
Colin Crosse4759b92019-02-15 10:37:39 -0800144
Inseob Kimc0907f12019-02-08 21:00:45 +0900145 config.TestProductVariables.DeviceSystemSdkVersions = []string{"28"}
146 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
147 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
Colin Crosse4759b92019-02-15 10:37:39 -0800148
Inseob Kimc0907f12019-02-08 21:00:45 +0900149 return config
150
151}
152
153func test(t *testing.T, bp string) *android.TestContext {
154 t.Helper()
Colin Cross98be1bb2019-12-13 20:41:13 -0800155 config := testConfig(nil, bp, nil)
156 ctx := testContext(config)
Inseob Kimc0907f12019-02-08 21:00:45 +0900157 run(t, ctx, config)
158
159 return ctx
160}
161
162func TestSyspropLibrary(t *testing.T) {
163 ctx := test(t, `
164 sysprop_library {
165 name: "sysprop-platform",
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100166 apex_available: ["//apex_available:platform"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900167 srcs: ["android/sysprop/PlatformProperties.sysprop"],
168 api_packages: ["android.sysprop"],
169 property_owner: "Platform",
170 vendor_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900171 host_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900172 }
173
174 sysprop_library {
175 name: "sysprop-platform-on-product",
176 srcs: ["android/sysprop/PlatformProperties.sysprop"],
177 api_packages: ["android.sysprop"],
178 property_owner: "Platform",
179 product_specific: true,
180 }
181
182 sysprop_library {
183 name: "sysprop-vendor",
184 srcs: ["com/android/VendorProperties.sysprop"],
185 api_packages: ["com.android"],
186 property_owner: "Vendor",
Inseob Kimfe612182020-10-20 16:29:55 +0900187 vendor: true,
188 }
189
190 sysprop_library {
191 name: "sysprop-vendor-on-product",
192 srcs: ["com/android/VendorProperties.sysprop"],
193 api_packages: ["com.android"],
194 property_owner: "Vendor",
Inseob Kimc0907f12019-02-08 21:00:45 +0900195 product_specific: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900196 }
197
Inseob Kim42882742019-07-30 17:55:33 +0900198 sysprop_library {
199 name: "sysprop-odm",
200 srcs: ["com/android2/OdmProperties.sysprop"],
201 api_packages: ["com.android2"],
202 property_owner: "Odm",
203 device_specific: true,
204 }
205
Inseob Kimc0907f12019-02-08 21:00:45 +0900206 java_library {
207 name: "java-platform",
208 srcs: ["c.java"],
209 sdk_version: "system_current",
210 libs: ["sysprop-platform"],
211 }
212
213 java_library {
Inseob Kimac1e9862019-12-09 18:15:47 +0900214 name: "java-platform-private",
215 srcs: ["c.java"],
216 platform_apis: true,
217 libs: ["sysprop-platform"],
218 }
219
220 java_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900221 name: "java-product",
222 srcs: ["c.java"],
223 sdk_version: "system_current",
224 product_specific: true,
Inseob Kimfe612182020-10-20 16:29:55 +0900225 libs: ["sysprop-platform", "sysprop-vendor-on-product"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900226 }
227
228 java_library {
229 name: "java-vendor",
230 srcs: ["c.java"],
231 sdk_version: "system_current",
232 soc_specific: true,
233 libs: ["sysprop-platform", "sysprop-vendor"],
234 }
235
236 cc_library {
237 name: "cc-client-platform",
238 srcs: ["d.cpp"],
239 static_libs: ["sysprop-platform"],
240 }
241
Jiyong Park5d1598f2019-02-25 22:14:17 +0900242 cc_library_static {
243 name: "cc-client-platform-static",
244 srcs: ["d.cpp"],
245 whole_static_libs: ["sysprop-platform"],
246 }
247
Inseob Kimc0907f12019-02-08 21:00:45 +0900248 cc_library {
249 name: "cc-client-product",
250 srcs: ["d.cpp"],
251 product_specific: true,
Inseob Kimfe612182020-10-20 16:29:55 +0900252 static_libs: ["sysprop-platform-on-product", "sysprop-vendor-on-product"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900253 }
254
255 cc_library {
256 name: "cc-client-vendor",
257 srcs: ["d.cpp"],
258 soc_specific: true,
259 static_libs: ["sysprop-platform", "sysprop-vendor"],
260 }
Inseob Kim1f959762019-03-27 17:20:37 +0900261
Inseob Kim89db15d2020-02-03 18:06:46 +0900262 cc_library {
263 name: "libbase",
264 host_supported: true,
265 }
266
Inseob Kim1f959762019-03-27 17:20:37 +0900267 cc_library_headers {
268 name: "libbase_headers",
269 vendor_available: true,
270 recovery_available: true,
271 }
272
273 cc_library {
274 name: "liblog",
Yi Konge7fe9912019-06-02 00:53:50 -0700275 no_libcrt: true,
Inseob Kim1f959762019-03-27 17:20:37 +0900276 nocrt: true,
277 system_shared_libs: [],
278 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900279 host_supported: true,
Colin Cross0477b422020-10-13 18:43:54 -0700280 llndk_stubs: "liblog.llndk",
Inseob Kim89db15d2020-02-03 18:06:46 +0900281 }
282
283 cc_binary_host {
284 name: "hostbin",
285 static_libs: ["sysprop-platform"],
Inseob Kim1f959762019-03-27 17:20:37 +0900286 }
287
288 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -0700289 name: "liblog.llndk",
Inseob Kim1f959762019-03-27 17:20:37 +0900290 symbol_file: "",
291 }
Inseob Kim42882742019-07-30 17:55:33 +0900292
293 java_library {
294 name: "sysprop-library-stub-platform",
295 sdk_version: "core_current",
296 }
297
298 java_library {
299 name: "sysprop-library-stub-vendor",
300 soc_specific: true,
301 sdk_version: "core_current",
302 }
Inseob Kimfe612182020-10-20 16:29:55 +0900303
304 java_library {
305 name: "sysprop-library-stub-product",
306 product_specific: true,
307 sdk_version: "core_current",
308 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900309 `)
310
Inseob Kim42882742019-07-30 17:55:33 +0900311 // Check for generated cc_library
312 for _, variant := range []string{
Colin Crossfb0c16e2019-11-20 17:12:35 -0800313 "android_vendor.VER_arm_armv7-a-neon_shared",
314 "android_vendor.VER_arm_armv7-a-neon_static",
315 "android_vendor.VER_arm64_armv8-a_shared",
316 "android_vendor.VER_arm64_armv8-a_static",
Inseob Kim42882742019-07-30 17:55:33 +0900317 } {
318 ctx.ModuleForTests("libsysprop-platform", variant)
319 ctx.ModuleForTests("libsysprop-vendor", variant)
320 ctx.ModuleForTests("libsysprop-odm", variant)
321 }
322
Inseob Kimc0907f12019-02-08 21:00:45 +0900323 for _, variant := range []string{
Colin Cross7113d202019-11-20 16:39:12 -0800324 "android_arm_armv7-a-neon_shared",
325 "android_arm_armv7-a-neon_static",
326 "android_arm64_armv8-a_shared",
327 "android_arm64_armv8-a_static",
Inseob Kimc0907f12019-02-08 21:00:45 +0900328 } {
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100329 library := ctx.ModuleForTests("libsysprop-platform", variant).Module().(*cc.Module)
330 expectedApexAvailableOnLibrary := []string{"//apex_available:platform"}
331 if !reflect.DeepEqual(library.ApexProperties.Apex_available, expectedApexAvailableOnLibrary) {
332 t.Errorf("apex available property on libsysprop-platform must be %#v, but was %#v.",
333 expectedApexAvailableOnLibrary, library.ApexProperties.Apex_available)
334 }
Inseob Kim42882742019-07-30 17:55:33 +0900335
Inseob Kimfe612182020-10-20 16:29:55 +0900336 // product variant of vendor-owned sysprop_library
337 ctx.ModuleForTests("libsysprop-vendor-on-product", variant)
Inseob Kimc0907f12019-02-08 21:00:45 +0900338 }
339
340 ctx.ModuleForTests("sysprop-platform", "android_common")
Inseob Kimac1e9862019-12-09 18:15:47 +0900341 ctx.ModuleForTests("sysprop-platform_public", "android_common")
Inseob Kimc0907f12019-02-08 21:00:45 +0900342 ctx.ModuleForTests("sysprop-vendor", "android_common")
Inseob Kimfe612182020-10-20 16:29:55 +0900343 ctx.ModuleForTests("sysprop-vendor-on-product", "android_common")
Inseob Kimc0907f12019-02-08 21:00:45 +0900344
345 // Check for exported includes
Colin Cross7113d202019-11-20 16:39:12 -0800346 coreVariant := "android_arm64_armv8-a_static"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800347 vendorVariant := "android_vendor.VER_arm64_armv8-a_static"
Inseob Kimc0907f12019-02-08 21:00:45 +0900348
Colin Cross7113d202019-11-20 16:39:12 -0800349 platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/include"
350 platformPublicCorePath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/public/include"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800351 platformPublicVendorPath := "libsysprop-platform/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900352
Colin Cross7113d202019-11-20 16:39:12 -0800353 platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900354
Colin Crossfb0c16e2019-11-20 17:12:35 -0800355 vendorInternalPath := "libsysprop-vendor/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/include"
Inseob Kimfe612182020-10-20 16:29:55 +0900356 vendorPublicPath := "libsysprop-vendor-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900357
358 platformClient := ctx.ModuleForTests("cc-client-platform", coreVariant)
359 platformFlags := platformClient.Rule("cc").Args["cFlags"]
360
Jiyong Park5d1598f2019-02-25 22:14:17 +0900361 // platform should use platform's internal header
Inseob Kimc0907f12019-02-08 21:00:45 +0900362 if !strings.Contains(platformFlags, platformInternalPath) {
363 t.Errorf("flags for platform must contain %#v, but was %#v.",
364 platformInternalPath, platformFlags)
365 }
366
Jiyong Park5d1598f2019-02-25 22:14:17 +0900367 platformStaticClient := ctx.ModuleForTests("cc-client-platform-static", coreVariant)
368 platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"]
369
370 // platform-static should use platform's internal header
371 if !strings.Contains(platformStaticFlags, platformInternalPath) {
372 t.Errorf("flags for platform-static must contain %#v, but was %#v.",
373 platformInternalPath, platformStaticFlags)
374 }
375
Inseob Kimc0907f12019-02-08 21:00:45 +0900376 productClient := ctx.ModuleForTests("cc-client-product", coreVariant)
377 productFlags := productClient.Rule("cc").Args["cFlags"]
378
Inseob Kim5cefbd22019-06-08 20:36:59 +0900379 // Product should use platform's and vendor's public headers
Inseob Kimc0907f12019-02-08 21:00:45 +0900380 if !strings.Contains(productFlags, platformOnProductPath) ||
Inseob Kim5cefbd22019-06-08 20:36:59 +0900381 !strings.Contains(productFlags, vendorPublicPath) {
Inseob Kimc0907f12019-02-08 21:00:45 +0900382 t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900383 platformPublicCorePath, vendorPublicPath, productFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900384 }
385
386 vendorClient := ctx.ModuleForTests("cc-client-vendor", vendorVariant)
387 vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
388
Inseob Kim5cefbd22019-06-08 20:36:59 +0900389 // Vendor should use platform's public header and vendor's internal header
390 if !strings.Contains(vendorFlags, platformPublicVendorPath) ||
Inseob Kimc0907f12019-02-08 21:00:45 +0900391 !strings.Contains(vendorFlags, vendorInternalPath) {
392 t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900393 platformPublicVendorPath, vendorInternalPath, vendorFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900394 }
Inseob Kimac1e9862019-12-09 18:15:47 +0900395
396 // Java modules linking against system API should use public stub
397 javaSystemApiClient := ctx.ModuleForTests("java-platform", "android_common")
398 publicStubFound := false
399 ctx.VisitDirectDeps(javaSystemApiClient.Module(), func(dep blueprint.Module) {
400 if dep.Name() == "sysprop-platform_public" {
401 publicStubFound = true
402 }
403 })
404 if !publicStubFound {
405 t.Errorf("system api client should use public stub")
406 }
407
Inseob Kimc0907f12019-02-08 21:00:45 +0900408}