blob: fe9e82a59aa0a83bd42a7693a611866fa876c2e2 [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.RegisterPrebuiltsPreArchMutators)
64 ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators)
65 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 Duffin77980a82019-12-19 16:01:36 +000070 cc.RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross4b49b762019-11-22 15:25:03 -080071 ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
72 ctx.RegisterModuleType("cc_library_static", cc.LibraryFactory)
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",
164 srcs: ["android/sysprop/PlatformProperties.sysprop"],
165 api_packages: ["android.sysprop"],
166 property_owner: "Platform",
167 vendor_available: true,
168 }
169
170 sysprop_library {
171 name: "sysprop-platform-on-product",
172 srcs: ["android/sysprop/PlatformProperties.sysprop"],
173 api_packages: ["android.sysprop"],
174 property_owner: "Platform",
175 product_specific: true,
176 }
177
178 sysprop_library {
179 name: "sysprop-vendor",
180 srcs: ["com/android/VendorProperties.sysprop"],
181 api_packages: ["com.android"],
182 property_owner: "Vendor",
183 product_specific: true,
184 vendor_available: true,
185 }
186
Inseob Kim42882742019-07-30 17:55:33 +0900187 sysprop_library {
188 name: "sysprop-odm",
189 srcs: ["com/android2/OdmProperties.sysprop"],
190 api_packages: ["com.android2"],
191 property_owner: "Odm",
192 device_specific: true,
193 }
194
Inseob Kimc0907f12019-02-08 21:00:45 +0900195 java_library {
196 name: "java-platform",
197 srcs: ["c.java"],
198 sdk_version: "system_current",
199 libs: ["sysprop-platform"],
200 }
201
202 java_library {
Inseob Kimac1e9862019-12-09 18:15:47 +0900203 name: "java-platform-private",
204 srcs: ["c.java"],
205 platform_apis: true,
206 libs: ["sysprop-platform"],
207 }
208
209 java_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900210 name: "java-product",
211 srcs: ["c.java"],
212 sdk_version: "system_current",
213 product_specific: true,
214 libs: ["sysprop-platform", "sysprop-vendor"],
215 }
216
217 java_library {
218 name: "java-vendor",
219 srcs: ["c.java"],
220 sdk_version: "system_current",
221 soc_specific: true,
222 libs: ["sysprop-platform", "sysprop-vendor"],
223 }
224
225 cc_library {
226 name: "cc-client-platform",
227 srcs: ["d.cpp"],
228 static_libs: ["sysprop-platform"],
229 }
230
Jiyong Park5d1598f2019-02-25 22:14:17 +0900231 cc_library_static {
232 name: "cc-client-platform-static",
233 srcs: ["d.cpp"],
234 whole_static_libs: ["sysprop-platform"],
235 }
236
Inseob Kimc0907f12019-02-08 21:00:45 +0900237 cc_library {
238 name: "cc-client-product",
239 srcs: ["d.cpp"],
240 product_specific: true,
241 static_libs: ["sysprop-platform-on-product", "sysprop-vendor"],
242 }
243
244 cc_library {
245 name: "cc-client-vendor",
246 srcs: ["d.cpp"],
247 soc_specific: true,
248 static_libs: ["sysprop-platform", "sysprop-vendor"],
249 }
Inseob Kim1f959762019-03-27 17:20:37 +0900250
251 cc_library_headers {
252 name: "libbase_headers",
253 vendor_available: true,
254 recovery_available: true,
255 }
256
257 cc_library {
258 name: "liblog",
Yi Konge7fe9912019-06-02 00:53:50 -0700259 no_libcrt: true,
Inseob Kim1f959762019-03-27 17:20:37 +0900260 nocrt: true,
261 system_shared_libs: [],
262 recovery_available: true,
263 }
264
265 llndk_library {
266 name: "liblog",
267 symbol_file: "",
268 }
Inseob Kim42882742019-07-30 17:55:33 +0900269
270 java_library {
271 name: "sysprop-library-stub-platform",
272 sdk_version: "core_current",
273 }
274
275 java_library {
276 name: "sysprop-library-stub-vendor",
277 soc_specific: true,
278 sdk_version: "core_current",
279 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900280 `)
281
Inseob Kim42882742019-07-30 17:55:33 +0900282 // Check for generated cc_library
283 for _, variant := range []string{
Colin Crossfb0c16e2019-11-20 17:12:35 -0800284 "android_vendor.VER_arm_armv7-a-neon_shared",
285 "android_vendor.VER_arm_armv7-a-neon_static",
286 "android_vendor.VER_arm64_armv8-a_shared",
287 "android_vendor.VER_arm64_armv8-a_static",
Inseob Kim42882742019-07-30 17:55:33 +0900288 } {
289 ctx.ModuleForTests("libsysprop-platform", variant)
290 ctx.ModuleForTests("libsysprop-vendor", variant)
291 ctx.ModuleForTests("libsysprop-odm", variant)
292 }
293
Inseob Kimc0907f12019-02-08 21:00:45 +0900294 for _, variant := range []string{
Colin Cross7113d202019-11-20 16:39:12 -0800295 "android_arm_armv7-a-neon_shared",
296 "android_arm_armv7-a-neon_static",
297 "android_arm64_armv8-a_shared",
298 "android_arm64_armv8-a_static",
Inseob Kimc0907f12019-02-08 21:00:45 +0900299 } {
Inseob Kimc0907f12019-02-08 21:00:45 +0900300 ctx.ModuleForTests("libsysprop-platform", variant)
Inseob Kim42882742019-07-30 17:55:33 +0900301
302 // core variant of vendor-owned sysprop_library is for product
Inseob Kimc0907f12019-02-08 21:00:45 +0900303 ctx.ModuleForTests("libsysprop-vendor", variant)
304 }
305
306 ctx.ModuleForTests("sysprop-platform", "android_common")
Inseob Kimac1e9862019-12-09 18:15:47 +0900307 ctx.ModuleForTests("sysprop-platform_public", "android_common")
Inseob Kimc0907f12019-02-08 21:00:45 +0900308 ctx.ModuleForTests("sysprop-vendor", "android_common")
309
310 // Check for exported includes
Colin Cross7113d202019-11-20 16:39:12 -0800311 coreVariant := "android_arm64_armv8-a_static"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800312 vendorVariant := "android_vendor.VER_arm64_armv8-a_static"
Inseob Kimc0907f12019-02-08 21:00:45 +0900313
Colin Cross7113d202019-11-20 16:39:12 -0800314 platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/include"
315 platformPublicCorePath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/public/include"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800316 platformPublicVendorPath := "libsysprop-platform/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900317
Colin Cross7113d202019-11-20 16:39:12 -0800318 platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900319
Colin Crossfb0c16e2019-11-20 17:12:35 -0800320 vendorInternalPath := "libsysprop-vendor/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/include"
Colin Cross7113d202019-11-20 16:39:12 -0800321 vendorPublicPath := "libsysprop-vendor/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900322
323 platformClient := ctx.ModuleForTests("cc-client-platform", coreVariant)
324 platformFlags := platformClient.Rule("cc").Args["cFlags"]
325
Jiyong Park5d1598f2019-02-25 22:14:17 +0900326 // platform should use platform's internal header
Inseob Kimc0907f12019-02-08 21:00:45 +0900327 if !strings.Contains(platformFlags, platformInternalPath) {
328 t.Errorf("flags for platform must contain %#v, but was %#v.",
329 platformInternalPath, platformFlags)
330 }
331
Jiyong Park5d1598f2019-02-25 22:14:17 +0900332 platformStaticClient := ctx.ModuleForTests("cc-client-platform-static", coreVariant)
333 platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"]
334
335 // platform-static should use platform's internal header
336 if !strings.Contains(platformStaticFlags, platformInternalPath) {
337 t.Errorf("flags for platform-static must contain %#v, but was %#v.",
338 platformInternalPath, platformStaticFlags)
339 }
340
Inseob Kimc0907f12019-02-08 21:00:45 +0900341 productClient := ctx.ModuleForTests("cc-client-product", coreVariant)
342 productFlags := productClient.Rule("cc").Args["cFlags"]
343
Inseob Kim5cefbd22019-06-08 20:36:59 +0900344 // Product should use platform's and vendor's public headers
Inseob Kimc0907f12019-02-08 21:00:45 +0900345 if !strings.Contains(productFlags, platformOnProductPath) ||
Inseob Kim5cefbd22019-06-08 20:36:59 +0900346 !strings.Contains(productFlags, vendorPublicPath) {
Inseob Kimc0907f12019-02-08 21:00:45 +0900347 t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900348 platformPublicCorePath, vendorPublicPath, productFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900349 }
350
351 vendorClient := ctx.ModuleForTests("cc-client-vendor", vendorVariant)
352 vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
353
Inseob Kim5cefbd22019-06-08 20:36:59 +0900354 // Vendor should use platform's public header and vendor's internal header
355 if !strings.Contains(vendorFlags, platformPublicVendorPath) ||
Inseob Kimc0907f12019-02-08 21:00:45 +0900356 !strings.Contains(vendorFlags, vendorInternalPath) {
357 t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900358 platformPublicVendorPath, vendorInternalPath, vendorFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900359 }
Inseob Kimac1e9862019-12-09 18:15:47 +0900360
361 // Java modules linking against system API should use public stub
362 javaSystemApiClient := ctx.ModuleForTests("java-platform", "android_common")
363 publicStubFound := false
364 ctx.VisitDirectDeps(javaSystemApiClient.Module(), func(dep blueprint.Module) {
365 if dep.Name() == "sysprop-platform_public" {
366 publicStubFound = true
367 }
368 })
369 if !publicStubFound {
370 t.Errorf("system api client should use public stub")
371 }
372
Inseob Kimc0907f12019-02-08 21:00:45 +0900373}