blob: 51da22205a6cd4ac8ddd16f068209e0fb6a099f3 [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 (
18 "android/soong/android"
19 "android/soong/cc"
20 "android/soong/java"
21
Inseob Kimc0907f12019-02-08 21:00:45 +090022 "io/ioutil"
23 "os"
24 "strings"
25 "testing"
26
Inseob Kimac1e9862019-12-09 18:15:47 +090027 "github.com/google/blueprint"
Inseob Kimc0907f12019-02-08 21:00:45 +090028 "github.com/google/blueprint/proptools"
29)
30
31var buildDir string
32
33func setUp() {
34 var err error
35 buildDir, err = ioutil.TempDir("", "soong_sysprop_test")
36 if err != nil {
37 panic(err)
38 }
39}
40
41func tearDown() {
42 os.RemoveAll(buildDir)
43}
44
45func TestMain(m *testing.M) {
46 run := func() int {
47 setUp()
48 defer tearDown()
49
50 return m.Run()
51 }
52
53 os.Exit(run())
54}
55
Colin Cross98be1bb2019-12-13 20:41:13 -080056func testContext(config android.Config) *android.TestContext {
Inseob Kimc0907f12019-02-08 21:00:45 +090057
58 ctx := android.NewTestArchContext()
Paul Duffinf9b1da02019-12-18 19:51:55 +000059 java.RegisterJavaBuildComponents(ctx)
60 java.RegisterAppBuildComponents(ctx)
Paul Duffin43dc1cc2019-12-19 11:18:54 +000061 java.RegisterSystemModulesBuildComponents(ctx)
62
Inseob Kimc0907f12019-02-08 21:00:45 +090063 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Inseob Kim988f53c2019-09-16 15:59:01 +090064 ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
65 ctx.BottomUp("sysprop_deps", syspropDepsMutator).Parallel()
66 })
Inseob Kimc0907f12019-02-08 21:00:45 +090067
Paul Duffin77980a82019-12-19 16:01:36 +000068 cc.RegisterRequiredBuildComponentsForTest(ctx)
Inseob Kimc0907f12019-02-08 21:00:45 +090069 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Inseob Kimac1e9862019-12-09 18:15:47 +090070 ctx.BottomUp("sysprop_java", java.SyspropMutator).Parallel()
Inseob Kimc0907f12019-02-08 21:00:45 +090071 })
72
Colin Cross4b49b762019-11-22 15:25:03 -080073 ctx.RegisterModuleType("sysprop_library", syspropLibraryFactory)
Inseob Kimc0907f12019-02-08 21:00:45 +090074
Colin Cross98be1bb2019-12-13 20:41:13 -080075 ctx.Register(config)
Inseob Kimc0907f12019-02-08 21:00:45 +090076
Colin Cross98be1bb2019-12-13 20:41:13 -080077 return ctx
78}
79
80func run(t *testing.T, ctx *android.TestContext, config android.Config) {
81 t.Helper()
82 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
83 android.FailIfErrored(t, errs)
84 _, errs = ctx.PrepareBuildActions(config)
85 android.FailIfErrored(t, errs)
86}
87
88func testConfig(env map[string]string, bp string, fs map[string][]byte) android.Config {
Inseob Kimc0907f12019-02-08 21:00:45 +090089 bp += cc.GatherRequiredDepsForTest(android.Android)
90
91 mockFS := map[string][]byte{
Inseob Kim42882742019-07-30 17:55:33 +090092 "a.java": nil,
93 "b.java": nil,
94 "c.java": nil,
95 "d.cpp": nil,
96 "api/sysprop-platform-current.txt": nil,
97 "api/sysprop-platform-latest.txt": nil,
98 "api/sysprop-platform-on-product-current.txt": nil,
99 "api/sysprop-platform-on-product-latest.txt": nil,
100 "api/sysprop-vendor-current.txt": nil,
101 "api/sysprop-vendor-latest.txt": nil,
102 "api/sysprop-odm-current.txt": nil,
103 "api/sysprop-odm-latest.txt": nil,
104 "framework/aidl/a.aidl": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900105
106 // For framework-res, which is an implicit dependency for framework
Dan Willemsen412160e2019-04-09 21:36:26 -0700107 "AndroidManifest.xml": nil,
108 "build/make/target/product/security/testkey": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900109
110 "build/soong/scripts/jar-wrapper.sh": nil,
111
112 "build/make/core/proguard.flags": nil,
113 "build/make/core/proguard_basic_keeps.flags": nil,
114
115 "jdk8/jre/lib/jce.jar": nil,
116 "jdk8/jre/lib/rt.jar": nil,
117 "jdk8/lib/tools.jar": nil,
118
119 "bar-doc/a.java": nil,
120 "bar-doc/b.java": nil,
121 "bar-doc/IFoo.aidl": nil,
122 "bar-doc/known_oj_tags.txt": nil,
123 "external/doclava/templates-sdk": nil,
124
125 "cert/new_cert.x509.pem": nil,
126 "cert/new_cert.pk8": nil,
127
128 "android/sysprop/PlatformProperties.sysprop": nil,
129 "com/android/VendorProperties.sysprop": nil,
Inseob Kim42882742019-07-30 17:55:33 +0900130 "com/android2/OdmProperties.sysprop": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900131 }
132
133 for k, v := range fs {
134 mockFS[k] = v
135 }
136
Colin Cross98be1bb2019-12-13 20:41:13 -0800137 config := java.TestConfig(buildDir, env, bp, mockFS)
Colin Crosse4759b92019-02-15 10:37:39 -0800138
Inseob Kimc0907f12019-02-08 21:00:45 +0900139 config.TestProductVariables.DeviceSystemSdkVersions = []string{"28"}
140 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
141 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
Colin Crosse4759b92019-02-15 10:37:39 -0800142
Inseob Kimc0907f12019-02-08 21:00:45 +0900143 return config
144
145}
146
147func test(t *testing.T, bp string) *android.TestContext {
148 t.Helper()
Colin Cross98be1bb2019-12-13 20:41:13 -0800149 config := testConfig(nil, bp, nil)
150 ctx := testContext(config)
Inseob Kimc0907f12019-02-08 21:00:45 +0900151 run(t, ctx, config)
152
153 return ctx
154}
155
156func TestSyspropLibrary(t *testing.T) {
157 ctx := test(t, `
158 sysprop_library {
159 name: "sysprop-platform",
160 srcs: ["android/sysprop/PlatformProperties.sysprop"],
161 api_packages: ["android.sysprop"],
162 property_owner: "Platform",
163 vendor_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900164 host_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900165 }
166
167 sysprop_library {
168 name: "sysprop-platform-on-product",
169 srcs: ["android/sysprop/PlatformProperties.sysprop"],
170 api_packages: ["android.sysprop"],
171 property_owner: "Platform",
172 product_specific: true,
173 }
174
175 sysprop_library {
176 name: "sysprop-vendor",
177 srcs: ["com/android/VendorProperties.sysprop"],
178 api_packages: ["com.android"],
179 property_owner: "Vendor",
180 product_specific: true,
181 vendor_available: true,
182 }
183
Inseob Kim42882742019-07-30 17:55:33 +0900184 sysprop_library {
185 name: "sysprop-odm",
186 srcs: ["com/android2/OdmProperties.sysprop"],
187 api_packages: ["com.android2"],
188 property_owner: "Odm",
189 device_specific: true,
190 }
191
Inseob Kimc0907f12019-02-08 21:00:45 +0900192 java_library {
193 name: "java-platform",
194 srcs: ["c.java"],
195 sdk_version: "system_current",
196 libs: ["sysprop-platform"],
197 }
198
199 java_library {
Inseob Kimac1e9862019-12-09 18:15:47 +0900200 name: "java-platform-private",
201 srcs: ["c.java"],
202 platform_apis: true,
203 libs: ["sysprop-platform"],
204 }
205
206 java_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900207 name: "java-product",
208 srcs: ["c.java"],
209 sdk_version: "system_current",
210 product_specific: true,
211 libs: ["sysprop-platform", "sysprop-vendor"],
212 }
213
214 java_library {
215 name: "java-vendor",
216 srcs: ["c.java"],
217 sdk_version: "system_current",
218 soc_specific: true,
219 libs: ["sysprop-platform", "sysprop-vendor"],
220 }
221
222 cc_library {
223 name: "cc-client-platform",
224 srcs: ["d.cpp"],
225 static_libs: ["sysprop-platform"],
226 }
227
Jiyong Park5d1598f2019-02-25 22:14:17 +0900228 cc_library_static {
229 name: "cc-client-platform-static",
230 srcs: ["d.cpp"],
231 whole_static_libs: ["sysprop-platform"],
232 }
233
Inseob Kimc0907f12019-02-08 21:00:45 +0900234 cc_library {
235 name: "cc-client-product",
236 srcs: ["d.cpp"],
237 product_specific: true,
238 static_libs: ["sysprop-platform-on-product", "sysprop-vendor"],
239 }
240
241 cc_library {
242 name: "cc-client-vendor",
243 srcs: ["d.cpp"],
244 soc_specific: true,
245 static_libs: ["sysprop-platform", "sysprop-vendor"],
246 }
Inseob Kim1f959762019-03-27 17:20:37 +0900247
Inseob Kim89db15d2020-02-03 18:06:46 +0900248 cc_library {
249 name: "libbase",
250 host_supported: true,
251 }
252
Inseob Kim1f959762019-03-27 17:20:37 +0900253 cc_library_headers {
254 name: "libbase_headers",
255 vendor_available: true,
256 recovery_available: true,
257 }
258
259 cc_library {
260 name: "liblog",
Yi Konge7fe9912019-06-02 00:53:50 -0700261 no_libcrt: true,
Inseob Kim1f959762019-03-27 17:20:37 +0900262 nocrt: true,
263 system_shared_libs: [],
264 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900265 host_supported: true,
266 }
267
268 cc_binary_host {
269 name: "hostbin",
270 static_libs: ["sysprop-platform"],
Inseob Kim1f959762019-03-27 17:20:37 +0900271 }
272
273 llndk_library {
274 name: "liblog",
275 symbol_file: "",
276 }
Inseob Kim42882742019-07-30 17:55:33 +0900277
278 java_library {
279 name: "sysprop-library-stub-platform",
280 sdk_version: "core_current",
281 }
282
283 java_library {
284 name: "sysprop-library-stub-vendor",
285 soc_specific: true,
286 sdk_version: "core_current",
287 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900288 `)
289
Inseob Kim42882742019-07-30 17:55:33 +0900290 // Check for generated cc_library
291 for _, variant := range []string{
Colin Crossfb0c16e2019-11-20 17:12:35 -0800292 "android_vendor.VER_arm_armv7-a-neon_shared",
293 "android_vendor.VER_arm_armv7-a-neon_static",
294 "android_vendor.VER_arm64_armv8-a_shared",
295 "android_vendor.VER_arm64_armv8-a_static",
Inseob Kim42882742019-07-30 17:55:33 +0900296 } {
297 ctx.ModuleForTests("libsysprop-platform", variant)
298 ctx.ModuleForTests("libsysprop-vendor", variant)
299 ctx.ModuleForTests("libsysprop-odm", variant)
300 }
301
Inseob Kimc0907f12019-02-08 21:00:45 +0900302 for _, variant := range []string{
Colin Cross7113d202019-11-20 16:39:12 -0800303 "android_arm_armv7-a-neon_shared",
304 "android_arm_armv7-a-neon_static",
305 "android_arm64_armv8-a_shared",
306 "android_arm64_armv8-a_static",
Inseob Kimc0907f12019-02-08 21:00:45 +0900307 } {
Inseob Kimc0907f12019-02-08 21:00:45 +0900308 ctx.ModuleForTests("libsysprop-platform", variant)
Inseob Kim42882742019-07-30 17:55:33 +0900309
310 // core variant of vendor-owned sysprop_library is for product
Inseob Kimc0907f12019-02-08 21:00:45 +0900311 ctx.ModuleForTests("libsysprop-vendor", variant)
312 }
313
314 ctx.ModuleForTests("sysprop-platform", "android_common")
Inseob Kimac1e9862019-12-09 18:15:47 +0900315 ctx.ModuleForTests("sysprop-platform_public", "android_common")
Inseob Kimc0907f12019-02-08 21:00:45 +0900316 ctx.ModuleForTests("sysprop-vendor", "android_common")
317
318 // Check for exported includes
Colin Cross7113d202019-11-20 16:39:12 -0800319 coreVariant := "android_arm64_armv8-a_static"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800320 vendorVariant := "android_vendor.VER_arm64_armv8-a_static"
Inseob Kimc0907f12019-02-08 21:00:45 +0900321
Colin Cross7113d202019-11-20 16:39:12 -0800322 platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/include"
323 platformPublicCorePath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/public/include"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800324 platformPublicVendorPath := "libsysprop-platform/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900325
Colin Cross7113d202019-11-20 16:39:12 -0800326 platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900327
Colin Crossfb0c16e2019-11-20 17:12:35 -0800328 vendorInternalPath := "libsysprop-vendor/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/include"
Colin Cross7113d202019-11-20 16:39:12 -0800329 vendorPublicPath := "libsysprop-vendor/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900330
331 platformClient := ctx.ModuleForTests("cc-client-platform", coreVariant)
332 platformFlags := platformClient.Rule("cc").Args["cFlags"]
333
Jiyong Park5d1598f2019-02-25 22:14:17 +0900334 // platform should use platform's internal header
Inseob Kimc0907f12019-02-08 21:00:45 +0900335 if !strings.Contains(platformFlags, platformInternalPath) {
336 t.Errorf("flags for platform must contain %#v, but was %#v.",
337 platformInternalPath, platformFlags)
338 }
339
Jiyong Park5d1598f2019-02-25 22:14:17 +0900340 platformStaticClient := ctx.ModuleForTests("cc-client-platform-static", coreVariant)
341 platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"]
342
343 // platform-static should use platform's internal header
344 if !strings.Contains(platformStaticFlags, platformInternalPath) {
345 t.Errorf("flags for platform-static must contain %#v, but was %#v.",
346 platformInternalPath, platformStaticFlags)
347 }
348
Inseob Kimc0907f12019-02-08 21:00:45 +0900349 productClient := ctx.ModuleForTests("cc-client-product", coreVariant)
350 productFlags := productClient.Rule("cc").Args["cFlags"]
351
Inseob Kim5cefbd22019-06-08 20:36:59 +0900352 // Product should use platform's and vendor's public headers
Inseob Kimc0907f12019-02-08 21:00:45 +0900353 if !strings.Contains(productFlags, platformOnProductPath) ||
Inseob Kim5cefbd22019-06-08 20:36:59 +0900354 !strings.Contains(productFlags, vendorPublicPath) {
Inseob Kimc0907f12019-02-08 21:00:45 +0900355 t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900356 platformPublicCorePath, vendorPublicPath, productFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900357 }
358
359 vendorClient := ctx.ModuleForTests("cc-client-vendor", vendorVariant)
360 vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
361
Inseob Kim5cefbd22019-06-08 20:36:59 +0900362 // Vendor should use platform's public header and vendor's internal header
363 if !strings.Contains(vendorFlags, platformPublicVendorPath) ||
Inseob Kimc0907f12019-02-08 21:00:45 +0900364 !strings.Contains(vendorFlags, vendorInternalPath) {
365 t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900366 platformPublicVendorPath, vendorInternalPath, vendorFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900367 }
Inseob Kimac1e9862019-12-09 18:15:47 +0900368
369 // Java modules linking against system API should use public stub
370 javaSystemApiClient := ctx.ModuleForTests("java-platform", "android_common")
371 publicStubFound := false
372 ctx.VisitDirectDeps(javaSystemApiClient.Module(), func(dep blueprint.Module) {
373 if dep.Name() == "sysprop-platform_public" {
374 publicStubFound = true
375 }
376 })
377 if !publicStubFound {
378 t.Errorf("system api client should use public stub")
379 }
380
Inseob Kimc0907f12019-02-08 21:00:45 +0900381}