blob: bdb9915ffc658b14fc286b74aaf914990a6df4f4 [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
Paul Duffin0c4979b2019-12-19 15:11:53 +000063 android.RegisterPrebuiltMutators(ctx)
Inseob Kimc0907f12019-02-08 21:00:45 +090064 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Inseob Kim988f53c2019-09-16 15:59:01 +090065 ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
66 ctx.BottomUp("sysprop_deps", syspropDepsMutator).Parallel()
67 })
Inseob Kimc0907f12019-02-08 21:00:45 +090068
Paul Duffin77980a82019-12-19 16:01:36 +000069 cc.RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross4b49b762019-11-22 15:25:03 -080070 ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
71 ctx.RegisterModuleType("cc_library_static", cc.LibraryFactory)
Inseob Kimc0907f12019-02-08 21:00:45 +090072 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Inseob Kimac1e9862019-12-09 18:15:47 +090073 ctx.BottomUp("sysprop_java", java.SyspropMutator).Parallel()
Inseob Kimc0907f12019-02-08 21:00:45 +090074 })
75
Colin Cross4b49b762019-11-22 15:25:03 -080076 ctx.RegisterModuleType("sysprop_library", syspropLibraryFactory)
Inseob Kimc0907f12019-02-08 21:00:45 +090077
Colin Cross98be1bb2019-12-13 20:41:13 -080078 ctx.Register(config)
Inseob Kimc0907f12019-02-08 21:00:45 +090079
Colin Cross98be1bb2019-12-13 20:41:13 -080080 return ctx
81}
82
83func run(t *testing.T, ctx *android.TestContext, config android.Config) {
84 t.Helper()
85 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
86 android.FailIfErrored(t, errs)
87 _, errs = ctx.PrepareBuildActions(config)
88 android.FailIfErrored(t, errs)
89}
90
91func testConfig(env map[string]string, bp string, fs map[string][]byte) android.Config {
Inseob Kimc0907f12019-02-08 21:00:45 +090092 bp += cc.GatherRequiredDepsForTest(android.Android)
93
94 mockFS := map[string][]byte{
Inseob Kim42882742019-07-30 17:55:33 +090095 "a.java": nil,
96 "b.java": nil,
97 "c.java": nil,
98 "d.cpp": nil,
99 "api/sysprop-platform-current.txt": nil,
100 "api/sysprop-platform-latest.txt": nil,
101 "api/sysprop-platform-on-product-current.txt": nil,
102 "api/sysprop-platform-on-product-latest.txt": nil,
103 "api/sysprop-vendor-current.txt": nil,
104 "api/sysprop-vendor-latest.txt": nil,
105 "api/sysprop-odm-current.txt": nil,
106 "api/sysprop-odm-latest.txt": nil,
107 "framework/aidl/a.aidl": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900108
109 // For framework-res, which is an implicit dependency for framework
Dan Willemsen412160e2019-04-09 21:36:26 -0700110 "AndroidManifest.xml": nil,
111 "build/make/target/product/security/testkey": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900112
113 "build/soong/scripts/jar-wrapper.sh": nil,
114
115 "build/make/core/proguard.flags": nil,
116 "build/make/core/proguard_basic_keeps.flags": nil,
117
118 "jdk8/jre/lib/jce.jar": nil,
119 "jdk8/jre/lib/rt.jar": nil,
120 "jdk8/lib/tools.jar": nil,
121
122 "bar-doc/a.java": nil,
123 "bar-doc/b.java": nil,
124 "bar-doc/IFoo.aidl": nil,
125 "bar-doc/known_oj_tags.txt": nil,
126 "external/doclava/templates-sdk": nil,
127
128 "cert/new_cert.x509.pem": nil,
129 "cert/new_cert.pk8": nil,
130
131 "android/sysprop/PlatformProperties.sysprop": nil,
132 "com/android/VendorProperties.sysprop": nil,
Inseob Kim42882742019-07-30 17:55:33 +0900133 "com/android2/OdmProperties.sysprop": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900134 }
135
136 for k, v := range fs {
137 mockFS[k] = v
138 }
139
Colin Cross98be1bb2019-12-13 20:41:13 -0800140 config := java.TestConfig(buildDir, env, bp, mockFS)
Colin Crosse4759b92019-02-15 10:37:39 -0800141
Inseob Kimc0907f12019-02-08 21:00:45 +0900142 config.TestProductVariables.DeviceSystemSdkVersions = []string{"28"}
143 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
144 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
Colin Crosse4759b92019-02-15 10:37:39 -0800145
Inseob Kimc0907f12019-02-08 21:00:45 +0900146 return config
147
148}
149
150func test(t *testing.T, bp string) *android.TestContext {
151 t.Helper()
Colin Cross98be1bb2019-12-13 20:41:13 -0800152 config := testConfig(nil, bp, nil)
153 ctx := testContext(config)
Inseob Kimc0907f12019-02-08 21:00:45 +0900154 run(t, ctx, config)
155
156 return ctx
157}
158
159func TestSyspropLibrary(t *testing.T) {
160 ctx := test(t, `
161 sysprop_library {
162 name: "sysprop-platform",
163 srcs: ["android/sysprop/PlatformProperties.sysprop"],
164 api_packages: ["android.sysprop"],
165 property_owner: "Platform",
166 vendor_available: true,
167 }
168
169 sysprop_library {
170 name: "sysprop-platform-on-product",
171 srcs: ["android/sysprop/PlatformProperties.sysprop"],
172 api_packages: ["android.sysprop"],
173 property_owner: "Platform",
174 product_specific: true,
175 }
176
177 sysprop_library {
178 name: "sysprop-vendor",
179 srcs: ["com/android/VendorProperties.sysprop"],
180 api_packages: ["com.android"],
181 property_owner: "Vendor",
182 product_specific: true,
183 vendor_available: true,
184 }
185
Inseob Kim42882742019-07-30 17:55:33 +0900186 sysprop_library {
187 name: "sysprop-odm",
188 srcs: ["com/android2/OdmProperties.sysprop"],
189 api_packages: ["com.android2"],
190 property_owner: "Odm",
191 device_specific: true,
192 }
193
Inseob Kimc0907f12019-02-08 21:00:45 +0900194 java_library {
195 name: "java-platform",
196 srcs: ["c.java"],
197 sdk_version: "system_current",
198 libs: ["sysprop-platform"],
199 }
200
201 java_library {
Inseob Kimac1e9862019-12-09 18:15:47 +0900202 name: "java-platform-private",
203 srcs: ["c.java"],
204 platform_apis: true,
205 libs: ["sysprop-platform"],
206 }
207
208 java_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900209 name: "java-product",
210 srcs: ["c.java"],
211 sdk_version: "system_current",
212 product_specific: true,
213 libs: ["sysprop-platform", "sysprop-vendor"],
214 }
215
216 java_library {
217 name: "java-vendor",
218 srcs: ["c.java"],
219 sdk_version: "system_current",
220 soc_specific: true,
221 libs: ["sysprop-platform", "sysprop-vendor"],
222 }
223
224 cc_library {
225 name: "cc-client-platform",
226 srcs: ["d.cpp"],
227 static_libs: ["sysprop-platform"],
228 }
229
Jiyong Park5d1598f2019-02-25 22:14:17 +0900230 cc_library_static {
231 name: "cc-client-platform-static",
232 srcs: ["d.cpp"],
233 whole_static_libs: ["sysprop-platform"],
234 }
235
Inseob Kimc0907f12019-02-08 21:00:45 +0900236 cc_library {
237 name: "cc-client-product",
238 srcs: ["d.cpp"],
239 product_specific: true,
240 static_libs: ["sysprop-platform-on-product", "sysprop-vendor"],
241 }
242
243 cc_library {
244 name: "cc-client-vendor",
245 srcs: ["d.cpp"],
246 soc_specific: true,
247 static_libs: ["sysprop-platform", "sysprop-vendor"],
248 }
Inseob Kim1f959762019-03-27 17:20:37 +0900249
250 cc_library_headers {
251 name: "libbase_headers",
252 vendor_available: true,
253 recovery_available: true,
254 }
255
256 cc_library {
257 name: "liblog",
Yi Konge7fe9912019-06-02 00:53:50 -0700258 no_libcrt: true,
Inseob Kim1f959762019-03-27 17:20:37 +0900259 nocrt: true,
260 system_shared_libs: [],
261 recovery_available: true,
262 }
263
264 llndk_library {
265 name: "liblog",
266 symbol_file: "",
267 }
Inseob Kim42882742019-07-30 17:55:33 +0900268
269 java_library {
270 name: "sysprop-library-stub-platform",
271 sdk_version: "core_current",
272 }
273
274 java_library {
275 name: "sysprop-library-stub-vendor",
276 soc_specific: true,
277 sdk_version: "core_current",
278 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900279 `)
280
Inseob Kim42882742019-07-30 17:55:33 +0900281 // Check for generated cc_library
282 for _, variant := range []string{
Colin Crossfb0c16e2019-11-20 17:12:35 -0800283 "android_vendor.VER_arm_armv7-a-neon_shared",
284 "android_vendor.VER_arm_armv7-a-neon_static",
285 "android_vendor.VER_arm64_armv8-a_shared",
286 "android_vendor.VER_arm64_armv8-a_static",
Inseob Kim42882742019-07-30 17:55:33 +0900287 } {
288 ctx.ModuleForTests("libsysprop-platform", variant)
289 ctx.ModuleForTests("libsysprop-vendor", variant)
290 ctx.ModuleForTests("libsysprop-odm", variant)
291 }
292
Inseob Kimc0907f12019-02-08 21:00:45 +0900293 for _, variant := range []string{
Colin Cross7113d202019-11-20 16:39:12 -0800294 "android_arm_armv7-a-neon_shared",
295 "android_arm_armv7-a-neon_static",
296 "android_arm64_armv8-a_shared",
297 "android_arm64_armv8-a_static",
Inseob Kimc0907f12019-02-08 21:00:45 +0900298 } {
Inseob Kimc0907f12019-02-08 21:00:45 +0900299 ctx.ModuleForTests("libsysprop-platform", variant)
Inseob Kim42882742019-07-30 17:55:33 +0900300
301 // core variant of vendor-owned sysprop_library is for product
Inseob Kimc0907f12019-02-08 21:00:45 +0900302 ctx.ModuleForTests("libsysprop-vendor", variant)
303 }
304
305 ctx.ModuleForTests("sysprop-platform", "android_common")
Inseob Kimac1e9862019-12-09 18:15:47 +0900306 ctx.ModuleForTests("sysprop-platform_public", "android_common")
Inseob Kimc0907f12019-02-08 21:00:45 +0900307 ctx.ModuleForTests("sysprop-vendor", "android_common")
308
309 // Check for exported includes
Colin Cross7113d202019-11-20 16:39:12 -0800310 coreVariant := "android_arm64_armv8-a_static"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800311 vendorVariant := "android_vendor.VER_arm64_armv8-a_static"
Inseob Kimc0907f12019-02-08 21:00:45 +0900312
Colin Cross7113d202019-11-20 16:39:12 -0800313 platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/include"
314 platformPublicCorePath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/public/include"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800315 platformPublicVendorPath := "libsysprop-platform/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900316
Colin Cross7113d202019-11-20 16:39:12 -0800317 platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900318
Colin Crossfb0c16e2019-11-20 17:12:35 -0800319 vendorInternalPath := "libsysprop-vendor/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/include"
Colin Cross7113d202019-11-20 16:39:12 -0800320 vendorPublicPath := "libsysprop-vendor/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900321
322 platformClient := ctx.ModuleForTests("cc-client-platform", coreVariant)
323 platformFlags := platformClient.Rule("cc").Args["cFlags"]
324
Jiyong Park5d1598f2019-02-25 22:14:17 +0900325 // platform should use platform's internal header
Inseob Kimc0907f12019-02-08 21:00:45 +0900326 if !strings.Contains(platformFlags, platformInternalPath) {
327 t.Errorf("flags for platform must contain %#v, but was %#v.",
328 platformInternalPath, platformFlags)
329 }
330
Jiyong Park5d1598f2019-02-25 22:14:17 +0900331 platformStaticClient := ctx.ModuleForTests("cc-client-platform-static", coreVariant)
332 platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"]
333
334 // platform-static should use platform's internal header
335 if !strings.Contains(platformStaticFlags, platformInternalPath) {
336 t.Errorf("flags for platform-static must contain %#v, but was %#v.",
337 platformInternalPath, platformStaticFlags)
338 }
339
Inseob Kimc0907f12019-02-08 21:00:45 +0900340 productClient := ctx.ModuleForTests("cc-client-product", coreVariant)
341 productFlags := productClient.Rule("cc").Args["cFlags"]
342
Inseob Kim5cefbd22019-06-08 20:36:59 +0900343 // Product should use platform's and vendor's public headers
Inseob Kimc0907f12019-02-08 21:00:45 +0900344 if !strings.Contains(productFlags, platformOnProductPath) ||
Inseob Kim5cefbd22019-06-08 20:36:59 +0900345 !strings.Contains(productFlags, vendorPublicPath) {
Inseob Kimc0907f12019-02-08 21:00:45 +0900346 t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900347 platformPublicCorePath, vendorPublicPath, productFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900348 }
349
350 vendorClient := ctx.ModuleForTests("cc-client-vendor", vendorVariant)
351 vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
352
Inseob Kim5cefbd22019-06-08 20:36:59 +0900353 // Vendor should use platform's public header and vendor's internal header
354 if !strings.Contains(vendorFlags, platformPublicVendorPath) ||
Inseob Kimc0907f12019-02-08 21:00:45 +0900355 !strings.Contains(vendorFlags, vendorInternalPath) {
356 t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900357 platformPublicVendorPath, vendorInternalPath, vendorFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900358 }
Inseob Kimac1e9862019-12-09 18:15:47 +0900359
360 // Java modules linking against system API should use public stub
361 javaSystemApiClient := ctx.ModuleForTests("java-platform", "android_common")
362 publicStubFound := false
363 ctx.VisitDirectDeps(javaSystemApiClient.Module(), func(dep blueprint.Module) {
364 if dep.Name() == "sysprop-platform_public" {
365 publicStubFound = true
366 }
367 })
368 if !publicStubFound {
369 t.Errorf("system api client should use public stub")
370 }
371
Inseob Kimc0907f12019-02-08 21:00:45 +0900372}