blob: 7cad3da94c74bccad9d4620c4aa2915358022961 [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,
164 }
165
166 sysprop_library {
167 name: "sysprop-platform-on-product",
168 srcs: ["android/sysprop/PlatformProperties.sysprop"],
169 api_packages: ["android.sysprop"],
170 property_owner: "Platform",
171 product_specific: true,
172 }
173
174 sysprop_library {
175 name: "sysprop-vendor",
176 srcs: ["com/android/VendorProperties.sysprop"],
177 api_packages: ["com.android"],
178 property_owner: "Vendor",
179 product_specific: true,
180 vendor_available: true,
181 }
182
Inseob Kim42882742019-07-30 17:55:33 +0900183 sysprop_library {
184 name: "sysprop-odm",
185 srcs: ["com/android2/OdmProperties.sysprop"],
186 api_packages: ["com.android2"],
187 property_owner: "Odm",
188 device_specific: true,
189 }
190
Inseob Kimc0907f12019-02-08 21:00:45 +0900191 java_library {
192 name: "java-platform",
193 srcs: ["c.java"],
194 sdk_version: "system_current",
195 libs: ["sysprop-platform"],
196 }
197
198 java_library {
Inseob Kimac1e9862019-12-09 18:15:47 +0900199 name: "java-platform-private",
200 srcs: ["c.java"],
201 platform_apis: true,
202 libs: ["sysprop-platform"],
203 }
204
205 java_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900206 name: "java-product",
207 srcs: ["c.java"],
208 sdk_version: "system_current",
209 product_specific: true,
210 libs: ["sysprop-platform", "sysprop-vendor"],
211 }
212
213 java_library {
214 name: "java-vendor",
215 srcs: ["c.java"],
216 sdk_version: "system_current",
217 soc_specific: true,
218 libs: ["sysprop-platform", "sysprop-vendor"],
219 }
220
221 cc_library {
222 name: "cc-client-platform",
223 srcs: ["d.cpp"],
224 static_libs: ["sysprop-platform"],
225 }
226
Jiyong Park5d1598f2019-02-25 22:14:17 +0900227 cc_library_static {
228 name: "cc-client-platform-static",
229 srcs: ["d.cpp"],
230 whole_static_libs: ["sysprop-platform"],
231 }
232
Inseob Kimc0907f12019-02-08 21:00:45 +0900233 cc_library {
234 name: "cc-client-product",
235 srcs: ["d.cpp"],
236 product_specific: true,
237 static_libs: ["sysprop-platform-on-product", "sysprop-vendor"],
238 }
239
240 cc_library {
241 name: "cc-client-vendor",
242 srcs: ["d.cpp"],
243 soc_specific: true,
244 static_libs: ["sysprop-platform", "sysprop-vendor"],
245 }
Inseob Kim1f959762019-03-27 17:20:37 +0900246
247 cc_library_headers {
248 name: "libbase_headers",
249 vendor_available: true,
250 recovery_available: true,
251 }
252
253 cc_library {
254 name: "liblog",
Yi Konge7fe9912019-06-02 00:53:50 -0700255 no_libcrt: true,
Inseob Kim1f959762019-03-27 17:20:37 +0900256 nocrt: true,
257 system_shared_libs: [],
258 recovery_available: true,
259 }
260
261 llndk_library {
262 name: "liblog",
263 symbol_file: "",
264 }
Inseob Kim42882742019-07-30 17:55:33 +0900265
266 java_library {
267 name: "sysprop-library-stub-platform",
268 sdk_version: "core_current",
269 }
270
271 java_library {
272 name: "sysprop-library-stub-vendor",
273 soc_specific: true,
274 sdk_version: "core_current",
275 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900276 `)
277
Inseob Kim42882742019-07-30 17:55:33 +0900278 // Check for generated cc_library
279 for _, variant := range []string{
Colin Crossfb0c16e2019-11-20 17:12:35 -0800280 "android_vendor.VER_arm_armv7-a-neon_shared",
281 "android_vendor.VER_arm_armv7-a-neon_static",
282 "android_vendor.VER_arm64_armv8-a_shared",
283 "android_vendor.VER_arm64_armv8-a_static",
Inseob Kim42882742019-07-30 17:55:33 +0900284 } {
285 ctx.ModuleForTests("libsysprop-platform", variant)
286 ctx.ModuleForTests("libsysprop-vendor", variant)
287 ctx.ModuleForTests("libsysprop-odm", variant)
288 }
289
Inseob Kimc0907f12019-02-08 21:00:45 +0900290 for _, variant := range []string{
Colin Cross7113d202019-11-20 16:39:12 -0800291 "android_arm_armv7-a-neon_shared",
292 "android_arm_armv7-a-neon_static",
293 "android_arm64_armv8-a_shared",
294 "android_arm64_armv8-a_static",
Inseob Kimc0907f12019-02-08 21:00:45 +0900295 } {
Inseob Kimc0907f12019-02-08 21:00:45 +0900296 ctx.ModuleForTests("libsysprop-platform", variant)
Inseob Kim42882742019-07-30 17:55:33 +0900297
298 // core variant of vendor-owned sysprop_library is for product
Inseob Kimc0907f12019-02-08 21:00:45 +0900299 ctx.ModuleForTests("libsysprop-vendor", variant)
300 }
301
302 ctx.ModuleForTests("sysprop-platform", "android_common")
Inseob Kimac1e9862019-12-09 18:15:47 +0900303 ctx.ModuleForTests("sysprop-platform_public", "android_common")
Inseob Kimc0907f12019-02-08 21:00:45 +0900304 ctx.ModuleForTests("sysprop-vendor", "android_common")
305
306 // Check for exported includes
Colin Cross7113d202019-11-20 16:39:12 -0800307 coreVariant := "android_arm64_armv8-a_static"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800308 vendorVariant := "android_vendor.VER_arm64_armv8-a_static"
Inseob Kimc0907f12019-02-08 21:00:45 +0900309
Colin Cross7113d202019-11-20 16:39:12 -0800310 platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/include"
311 platformPublicCorePath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/public/include"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800312 platformPublicVendorPath := "libsysprop-platform/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900313
Colin Cross7113d202019-11-20 16:39:12 -0800314 platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900315
Colin Crossfb0c16e2019-11-20 17:12:35 -0800316 vendorInternalPath := "libsysprop-vendor/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/include"
Colin Cross7113d202019-11-20 16:39:12 -0800317 vendorPublicPath := "libsysprop-vendor/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900318
319 platformClient := ctx.ModuleForTests("cc-client-platform", coreVariant)
320 platformFlags := platformClient.Rule("cc").Args["cFlags"]
321
Jiyong Park5d1598f2019-02-25 22:14:17 +0900322 // platform should use platform's internal header
Inseob Kimc0907f12019-02-08 21:00:45 +0900323 if !strings.Contains(platformFlags, platformInternalPath) {
324 t.Errorf("flags for platform must contain %#v, but was %#v.",
325 platformInternalPath, platformFlags)
326 }
327
Jiyong Park5d1598f2019-02-25 22:14:17 +0900328 platformStaticClient := ctx.ModuleForTests("cc-client-platform-static", coreVariant)
329 platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"]
330
331 // platform-static should use platform's internal header
332 if !strings.Contains(platformStaticFlags, platformInternalPath) {
333 t.Errorf("flags for platform-static must contain %#v, but was %#v.",
334 platformInternalPath, platformStaticFlags)
335 }
336
Inseob Kimc0907f12019-02-08 21:00:45 +0900337 productClient := ctx.ModuleForTests("cc-client-product", coreVariant)
338 productFlags := productClient.Rule("cc").Args["cFlags"]
339
Inseob Kim5cefbd22019-06-08 20:36:59 +0900340 // Product should use platform's and vendor's public headers
Inseob Kimc0907f12019-02-08 21:00:45 +0900341 if !strings.Contains(productFlags, platformOnProductPath) ||
Inseob Kim5cefbd22019-06-08 20:36:59 +0900342 !strings.Contains(productFlags, vendorPublicPath) {
Inseob Kimc0907f12019-02-08 21:00:45 +0900343 t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900344 platformPublicCorePath, vendorPublicPath, productFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900345 }
346
347 vendorClient := ctx.ModuleForTests("cc-client-vendor", vendorVariant)
348 vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
349
Inseob Kim5cefbd22019-06-08 20:36:59 +0900350 // Vendor should use platform's public header and vendor's internal header
351 if !strings.Contains(vendorFlags, platformPublicVendorPath) ||
Inseob Kimc0907f12019-02-08 21:00:45 +0900352 !strings.Contains(vendorFlags, vendorInternalPath) {
353 t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900354 platformPublicVendorPath, vendorInternalPath, vendorFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900355 }
Inseob Kimac1e9862019-12-09 18:15:47 +0900356
357 // Java modules linking against system API should use public stub
358 javaSystemApiClient := ctx.ModuleForTests("java-platform", "android_common")
359 publicStubFound := false
360 ctx.VisitDirectDeps(javaSystemApiClient.Module(), func(dep blueprint.Module) {
361 if dep.Name() == "sysprop-platform_public" {
362 publicStubFound = true
363 }
364 })
365 if !publicStubFound {
366 t.Errorf("system api client should use public stub")
367 }
368
Inseob Kimc0907f12019-02-08 21:00:45 +0900369}