blob: 711129c84e796da88fc51d36fc46778057d5371f [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
60 ctx := android.NewTestArchContext()
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 Cross98be1bb2019-12-13 20:41:13 -080079 ctx.Register(config)
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,
106 "api/sysprop-odm-current.txt": nil,
107 "api/sysprop-odm-latest.txt": nil,
108 "framework/aidl/a.aidl": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900109
110 // For framework-res, which is an implicit dependency for framework
Dan Willemsen412160e2019-04-09 21:36:26 -0700111 "AndroidManifest.xml": nil,
112 "build/make/target/product/security/testkey": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900113
114 "build/soong/scripts/jar-wrapper.sh": nil,
115
116 "build/make/core/proguard.flags": nil,
117 "build/make/core/proguard_basic_keeps.flags": nil,
118
119 "jdk8/jre/lib/jce.jar": nil,
120 "jdk8/jre/lib/rt.jar": nil,
121 "jdk8/lib/tools.jar": nil,
122
123 "bar-doc/a.java": nil,
124 "bar-doc/b.java": nil,
125 "bar-doc/IFoo.aidl": nil,
126 "bar-doc/known_oj_tags.txt": nil,
127 "external/doclava/templates-sdk": nil,
128
129 "cert/new_cert.x509.pem": nil,
130 "cert/new_cert.pk8": nil,
131
132 "android/sysprop/PlatformProperties.sysprop": nil,
133 "com/android/VendorProperties.sysprop": nil,
Inseob Kim42882742019-07-30 17:55:33 +0900134 "com/android2/OdmProperties.sysprop": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900135 }
136
137 for k, v := range fs {
138 mockFS[k] = v
139 }
140
Colin Cross98be1bb2019-12-13 20:41:13 -0800141 config := java.TestConfig(buildDir, env, bp, mockFS)
Colin Crosse4759b92019-02-15 10:37:39 -0800142
Inseob Kimc0907f12019-02-08 21:00:45 +0900143 config.TestProductVariables.DeviceSystemSdkVersions = []string{"28"}
144 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
145 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
Colin Crosse4759b92019-02-15 10:37:39 -0800146
Inseob Kimc0907f12019-02-08 21:00:45 +0900147 return config
148
149}
150
151func test(t *testing.T, bp string) *android.TestContext {
152 t.Helper()
Colin Cross98be1bb2019-12-13 20:41:13 -0800153 config := testConfig(nil, bp, nil)
154 ctx := testContext(config)
Inseob Kimc0907f12019-02-08 21:00:45 +0900155 run(t, ctx, config)
156
157 return ctx
158}
159
160func TestSyspropLibrary(t *testing.T) {
161 ctx := test(t, `
162 sysprop_library {
163 name: "sysprop-platform",
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100164 apex_available: ["//apex_available:platform"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900165 srcs: ["android/sysprop/PlatformProperties.sysprop"],
166 api_packages: ["android.sysprop"],
167 property_owner: "Platform",
168 vendor_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900169 host_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900170 }
171
172 sysprop_library {
173 name: "sysprop-platform-on-product",
174 srcs: ["android/sysprop/PlatformProperties.sysprop"],
175 api_packages: ["android.sysprop"],
176 property_owner: "Platform",
177 product_specific: true,
178 }
179
180 sysprop_library {
181 name: "sysprop-vendor",
182 srcs: ["com/android/VendorProperties.sysprop"],
183 api_packages: ["com.android"],
184 property_owner: "Vendor",
185 product_specific: true,
186 vendor_available: true,
187 }
188
Inseob Kim42882742019-07-30 17:55:33 +0900189 sysprop_library {
190 name: "sysprop-odm",
191 srcs: ["com/android2/OdmProperties.sysprop"],
192 api_packages: ["com.android2"],
193 property_owner: "Odm",
194 device_specific: true,
195 }
196
Inseob Kimc0907f12019-02-08 21:00:45 +0900197 java_library {
198 name: "java-platform",
199 srcs: ["c.java"],
200 sdk_version: "system_current",
201 libs: ["sysprop-platform"],
202 }
203
204 java_library {
Inseob Kimac1e9862019-12-09 18:15:47 +0900205 name: "java-platform-private",
206 srcs: ["c.java"],
207 platform_apis: true,
208 libs: ["sysprop-platform"],
209 }
210
211 java_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900212 name: "java-product",
213 srcs: ["c.java"],
214 sdk_version: "system_current",
215 product_specific: true,
216 libs: ["sysprop-platform", "sysprop-vendor"],
217 }
218
219 java_library {
220 name: "java-vendor",
221 srcs: ["c.java"],
222 sdk_version: "system_current",
223 soc_specific: true,
224 libs: ["sysprop-platform", "sysprop-vendor"],
225 }
226
227 cc_library {
228 name: "cc-client-platform",
229 srcs: ["d.cpp"],
230 static_libs: ["sysprop-platform"],
231 }
232
Jiyong Park5d1598f2019-02-25 22:14:17 +0900233 cc_library_static {
234 name: "cc-client-platform-static",
235 srcs: ["d.cpp"],
236 whole_static_libs: ["sysprop-platform"],
237 }
238
Inseob Kimc0907f12019-02-08 21:00:45 +0900239 cc_library {
240 name: "cc-client-product",
241 srcs: ["d.cpp"],
242 product_specific: true,
243 static_libs: ["sysprop-platform-on-product", "sysprop-vendor"],
244 }
245
246 cc_library {
247 name: "cc-client-vendor",
248 srcs: ["d.cpp"],
249 soc_specific: true,
250 static_libs: ["sysprop-platform", "sysprop-vendor"],
251 }
Inseob Kim1f959762019-03-27 17:20:37 +0900252
Inseob Kim89db15d2020-02-03 18:06:46 +0900253 cc_library {
254 name: "libbase",
255 host_supported: true,
256 }
257
Inseob Kim1f959762019-03-27 17:20:37 +0900258 cc_library_headers {
259 name: "libbase_headers",
260 vendor_available: true,
261 recovery_available: true,
262 }
263
264 cc_library {
265 name: "liblog",
Yi Konge7fe9912019-06-02 00:53:50 -0700266 no_libcrt: true,
Inseob Kim1f959762019-03-27 17:20:37 +0900267 nocrt: true,
268 system_shared_libs: [],
269 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900270 host_supported: true,
271 }
272
273 cc_binary_host {
274 name: "hostbin",
275 static_libs: ["sysprop-platform"],
Inseob Kim1f959762019-03-27 17:20:37 +0900276 }
277
278 llndk_library {
279 name: "liblog",
280 symbol_file: "",
281 }
Inseob Kim42882742019-07-30 17:55:33 +0900282
283 java_library {
284 name: "sysprop-library-stub-platform",
285 sdk_version: "core_current",
286 }
287
288 java_library {
289 name: "sysprop-library-stub-vendor",
290 soc_specific: true,
291 sdk_version: "core_current",
292 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900293 `)
294
Inseob Kim42882742019-07-30 17:55:33 +0900295 // Check for generated cc_library
296 for _, variant := range []string{
Colin Crossfb0c16e2019-11-20 17:12:35 -0800297 "android_vendor.VER_arm_armv7-a-neon_shared",
298 "android_vendor.VER_arm_armv7-a-neon_static",
299 "android_vendor.VER_arm64_armv8-a_shared",
300 "android_vendor.VER_arm64_armv8-a_static",
Inseob Kim42882742019-07-30 17:55:33 +0900301 } {
302 ctx.ModuleForTests("libsysprop-platform", variant)
303 ctx.ModuleForTests("libsysprop-vendor", variant)
304 ctx.ModuleForTests("libsysprop-odm", variant)
305 }
306
Inseob Kimc0907f12019-02-08 21:00:45 +0900307 for _, variant := range []string{
Colin Cross7113d202019-11-20 16:39:12 -0800308 "android_arm_armv7-a-neon_shared",
309 "android_arm_armv7-a-neon_static",
310 "android_arm64_armv8-a_shared",
311 "android_arm64_armv8-a_static",
Inseob Kimc0907f12019-02-08 21:00:45 +0900312 } {
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100313 library := ctx.ModuleForTests("libsysprop-platform", variant).Module().(*cc.Module)
314 expectedApexAvailableOnLibrary := []string{"//apex_available:platform"}
315 if !reflect.DeepEqual(library.ApexProperties.Apex_available, expectedApexAvailableOnLibrary) {
316 t.Errorf("apex available property on libsysprop-platform must be %#v, but was %#v.",
317 expectedApexAvailableOnLibrary, library.ApexProperties.Apex_available)
318 }
Inseob Kim42882742019-07-30 17:55:33 +0900319
320 // core variant of vendor-owned sysprop_library is for product
Inseob Kimc0907f12019-02-08 21:00:45 +0900321 ctx.ModuleForTests("libsysprop-vendor", variant)
322 }
323
324 ctx.ModuleForTests("sysprop-platform", "android_common")
Inseob Kimac1e9862019-12-09 18:15:47 +0900325 ctx.ModuleForTests("sysprop-platform_public", "android_common")
Inseob Kimc0907f12019-02-08 21:00:45 +0900326 ctx.ModuleForTests("sysprop-vendor", "android_common")
327
328 // Check for exported includes
Colin Cross7113d202019-11-20 16:39:12 -0800329 coreVariant := "android_arm64_armv8-a_static"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800330 vendorVariant := "android_vendor.VER_arm64_armv8-a_static"
Inseob Kimc0907f12019-02-08 21:00:45 +0900331
Colin Cross7113d202019-11-20 16:39:12 -0800332 platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/include"
333 platformPublicCorePath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/public/include"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800334 platformPublicVendorPath := "libsysprop-platform/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900335
Colin Cross7113d202019-11-20 16:39:12 -0800336 platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900337
Colin Crossfb0c16e2019-11-20 17:12:35 -0800338 vendorInternalPath := "libsysprop-vendor/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/include"
Colin Cross7113d202019-11-20 16:39:12 -0800339 vendorPublicPath := "libsysprop-vendor/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900340
341 platformClient := ctx.ModuleForTests("cc-client-platform", coreVariant)
342 platformFlags := platformClient.Rule("cc").Args["cFlags"]
343
Jiyong Park5d1598f2019-02-25 22:14:17 +0900344 // platform should use platform's internal header
Inseob Kimc0907f12019-02-08 21:00:45 +0900345 if !strings.Contains(platformFlags, platformInternalPath) {
346 t.Errorf("flags for platform must contain %#v, but was %#v.",
347 platformInternalPath, platformFlags)
348 }
349
Jiyong Park5d1598f2019-02-25 22:14:17 +0900350 platformStaticClient := ctx.ModuleForTests("cc-client-platform-static", coreVariant)
351 platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"]
352
353 // platform-static should use platform's internal header
354 if !strings.Contains(platformStaticFlags, platformInternalPath) {
355 t.Errorf("flags for platform-static must contain %#v, but was %#v.",
356 platformInternalPath, platformStaticFlags)
357 }
358
Inseob Kimc0907f12019-02-08 21:00:45 +0900359 productClient := ctx.ModuleForTests("cc-client-product", coreVariant)
360 productFlags := productClient.Rule("cc").Args["cFlags"]
361
Inseob Kim5cefbd22019-06-08 20:36:59 +0900362 // Product should use platform's and vendor's public headers
Inseob Kimc0907f12019-02-08 21:00:45 +0900363 if !strings.Contains(productFlags, platformOnProductPath) ||
Inseob Kim5cefbd22019-06-08 20:36:59 +0900364 !strings.Contains(productFlags, vendorPublicPath) {
Inseob Kimc0907f12019-02-08 21:00:45 +0900365 t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900366 platformPublicCorePath, vendorPublicPath, productFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900367 }
368
369 vendorClient := ctx.ModuleForTests("cc-client-vendor", vendorVariant)
370 vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
371
Inseob Kim5cefbd22019-06-08 20:36:59 +0900372 // Vendor should use platform's public header and vendor's internal header
373 if !strings.Contains(vendorFlags, platformPublicVendorPath) ||
Inseob Kimc0907f12019-02-08 21:00:45 +0900374 !strings.Contains(vendorFlags, vendorInternalPath) {
375 t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900376 platformPublicVendorPath, vendorInternalPath, vendorFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900377 }
Inseob Kimac1e9862019-12-09 18:15:47 +0900378
379 // Java modules linking against system API should use public stub
380 javaSystemApiClient := ctx.ModuleForTests("java-platform", "android_common")
381 publicStubFound := false
382 ctx.VisitDirectDeps(javaSystemApiClient.Module(), func(dep blueprint.Module) {
383 if dep.Name() == "sysprop-platform_public" {
384 publicStubFound = true
385 }
386 })
387 if !publicStubFound {
388 t.Errorf("system api client should use public stub")
389 }
390
Inseob Kimc0907f12019-02-08 21:00:45 +0900391}