blob: d24262dde056c25c9f0162e966b0afe4a17587f4 [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
Colin Cross4b49b762019-11-22 15:25:03 -080070 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
71 ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
72 ctx.RegisterModuleType("cc_library_static", cc.LibraryFactory)
73 ctx.RegisterModuleType("cc_object", cc.ObjectFactory)
74 ctx.RegisterModuleType("llndk_library", cc.LlndkLibraryFactory)
75 ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory)
Inseob Kimc0907f12019-02-08 21:00:45 +090076 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Inseob Kimc0907f12019-02-08 21:00:45 +090077 ctx.BottomUp("link", cc.LinkageMutator).Parallel()
78 ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
79 ctx.BottomUp("version", cc.VersionMutator).Parallel()
80 ctx.BottomUp("begin", cc.BeginMutator).Parallel()
Inseob Kimac1e9862019-12-09 18:15:47 +090081 ctx.BottomUp("sysprop_cc", cc.SyspropMutator).Parallel()
82 ctx.BottomUp("sysprop_java", java.SyspropMutator).Parallel()
Inseob Kimc0907f12019-02-08 21:00:45 +090083 })
84
Colin Cross4b49b762019-11-22 15:25:03 -080085 ctx.RegisterModuleType("sysprop_library", syspropLibraryFactory)
Inseob Kimc0907f12019-02-08 21:00:45 +090086
Colin Cross98be1bb2019-12-13 20:41:13 -080087 ctx.Register(config)
Inseob Kimc0907f12019-02-08 21:00:45 +090088
Colin Cross98be1bb2019-12-13 20:41:13 -080089 return ctx
90}
91
92func run(t *testing.T, ctx *android.TestContext, config android.Config) {
93 t.Helper()
94 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
95 android.FailIfErrored(t, errs)
96 _, errs = ctx.PrepareBuildActions(config)
97 android.FailIfErrored(t, errs)
98}
99
100func testConfig(env map[string]string, bp string, fs map[string][]byte) android.Config {
Inseob Kimc0907f12019-02-08 21:00:45 +0900101 bp += cc.GatherRequiredDepsForTest(android.Android)
102
103 mockFS := map[string][]byte{
Inseob Kim42882742019-07-30 17:55:33 +0900104 "a.java": nil,
105 "b.java": nil,
106 "c.java": nil,
107 "d.cpp": nil,
108 "api/sysprop-platform-current.txt": nil,
109 "api/sysprop-platform-latest.txt": nil,
110 "api/sysprop-platform-on-product-current.txt": nil,
111 "api/sysprop-platform-on-product-latest.txt": nil,
112 "api/sysprop-vendor-current.txt": nil,
113 "api/sysprop-vendor-latest.txt": nil,
114 "api/sysprop-odm-current.txt": nil,
115 "api/sysprop-odm-latest.txt": nil,
116 "framework/aidl/a.aidl": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900117
118 // For framework-res, which is an implicit dependency for framework
Dan Willemsen412160e2019-04-09 21:36:26 -0700119 "AndroidManifest.xml": nil,
120 "build/make/target/product/security/testkey": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900121
122 "build/soong/scripts/jar-wrapper.sh": nil,
123
124 "build/make/core/proguard.flags": nil,
125 "build/make/core/proguard_basic_keeps.flags": nil,
126
127 "jdk8/jre/lib/jce.jar": nil,
128 "jdk8/jre/lib/rt.jar": nil,
129 "jdk8/lib/tools.jar": nil,
130
131 "bar-doc/a.java": nil,
132 "bar-doc/b.java": nil,
133 "bar-doc/IFoo.aidl": nil,
134 "bar-doc/known_oj_tags.txt": nil,
135 "external/doclava/templates-sdk": nil,
136
137 "cert/new_cert.x509.pem": nil,
138 "cert/new_cert.pk8": nil,
139
140 "android/sysprop/PlatformProperties.sysprop": nil,
141 "com/android/VendorProperties.sysprop": nil,
Inseob Kim42882742019-07-30 17:55:33 +0900142 "com/android2/OdmProperties.sysprop": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900143 }
144
145 for k, v := range fs {
146 mockFS[k] = v
147 }
148
Colin Cross98be1bb2019-12-13 20:41:13 -0800149 config := java.TestConfig(buildDir, env, bp, mockFS)
Colin Crosse4759b92019-02-15 10:37:39 -0800150
Inseob Kimc0907f12019-02-08 21:00:45 +0900151 config.TestProductVariables.DeviceSystemSdkVersions = []string{"28"}
152 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
153 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
Colin Crosse4759b92019-02-15 10:37:39 -0800154
Inseob Kimc0907f12019-02-08 21:00:45 +0900155 return config
156
157}
158
159func test(t *testing.T, bp string) *android.TestContext {
160 t.Helper()
Colin Cross98be1bb2019-12-13 20:41:13 -0800161 config := testConfig(nil, bp, nil)
162 ctx := testContext(config)
Inseob Kimc0907f12019-02-08 21:00:45 +0900163 run(t, ctx, config)
164
165 return ctx
166}
167
168func TestSyspropLibrary(t *testing.T) {
169 ctx := test(t, `
170 sysprop_library {
171 name: "sysprop-platform",
172 srcs: ["android/sysprop/PlatformProperties.sysprop"],
173 api_packages: ["android.sysprop"],
174 property_owner: "Platform",
175 vendor_available: true,
176 }
177
178 sysprop_library {
179 name: "sysprop-platform-on-product",
180 srcs: ["android/sysprop/PlatformProperties.sysprop"],
181 api_packages: ["android.sysprop"],
182 property_owner: "Platform",
183 product_specific: true,
184 }
185
186 sysprop_library {
187 name: "sysprop-vendor",
188 srcs: ["com/android/VendorProperties.sysprop"],
189 api_packages: ["com.android"],
190 property_owner: "Vendor",
191 product_specific: true,
192 vendor_available: true,
193 }
194
Inseob Kim42882742019-07-30 17:55:33 +0900195 sysprop_library {
196 name: "sysprop-odm",
197 srcs: ["com/android2/OdmProperties.sysprop"],
198 api_packages: ["com.android2"],
199 property_owner: "Odm",
200 device_specific: true,
201 }
202
Inseob Kimc0907f12019-02-08 21:00:45 +0900203 java_library {
204 name: "java-platform",
205 srcs: ["c.java"],
206 sdk_version: "system_current",
207 libs: ["sysprop-platform"],
208 }
209
210 java_library {
Inseob Kimac1e9862019-12-09 18:15:47 +0900211 name: "java-platform-private",
212 srcs: ["c.java"],
213 platform_apis: true,
214 libs: ["sysprop-platform"],
215 }
216
217 java_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900218 name: "java-product",
219 srcs: ["c.java"],
220 sdk_version: "system_current",
221 product_specific: true,
222 libs: ["sysprop-platform", "sysprop-vendor"],
223 }
224
225 java_library {
226 name: "java-vendor",
227 srcs: ["c.java"],
228 sdk_version: "system_current",
229 soc_specific: true,
230 libs: ["sysprop-platform", "sysprop-vendor"],
231 }
232
233 cc_library {
234 name: "cc-client-platform",
235 srcs: ["d.cpp"],
236 static_libs: ["sysprop-platform"],
237 }
238
Jiyong Park5d1598f2019-02-25 22:14:17 +0900239 cc_library_static {
240 name: "cc-client-platform-static",
241 srcs: ["d.cpp"],
242 whole_static_libs: ["sysprop-platform"],
243 }
244
Inseob Kimc0907f12019-02-08 21:00:45 +0900245 cc_library {
246 name: "cc-client-product",
247 srcs: ["d.cpp"],
248 product_specific: true,
249 static_libs: ["sysprop-platform-on-product", "sysprop-vendor"],
250 }
251
252 cc_library {
253 name: "cc-client-vendor",
254 srcs: ["d.cpp"],
255 soc_specific: true,
256 static_libs: ["sysprop-platform", "sysprop-vendor"],
257 }
Inseob Kim1f959762019-03-27 17:20:37 +0900258
259 cc_library_headers {
260 name: "libbase_headers",
261 vendor_available: true,
262 recovery_available: true,
263 }
264
265 cc_library {
266 name: "liblog",
Yi Konge7fe9912019-06-02 00:53:50 -0700267 no_libcrt: true,
Inseob Kim1f959762019-03-27 17:20:37 +0900268 nocrt: true,
269 system_shared_libs: [],
270 recovery_available: true,
271 }
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}