blob: d44f4cf2fcb622dd001b033c3ce7586e7e5f2d43 [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)
Colin Cross4b49b762019-11-22 15:25:03 -080061 ctx.RegisterModuleType("java_system_modules", java.SystemModulesFactory)
Inseob Kimc0907f12019-02-08 21:00:45 +090062 ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators)
63 ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators)
64 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
Colin Cross4b49b762019-11-22 15:25:03 -080069 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
70 ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
71 ctx.RegisterModuleType("cc_library_static", cc.LibraryFactory)
72 ctx.RegisterModuleType("cc_object", cc.ObjectFactory)
73 ctx.RegisterModuleType("llndk_library", cc.LlndkLibraryFactory)
74 ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory)
Inseob Kimc0907f12019-02-08 21:00:45 +090075 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Inseob Kimc0907f12019-02-08 21:00:45 +090076 ctx.BottomUp("link", cc.LinkageMutator).Parallel()
77 ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
78 ctx.BottomUp("version", cc.VersionMutator).Parallel()
79 ctx.BottomUp("begin", cc.BeginMutator).Parallel()
Inseob Kimac1e9862019-12-09 18:15:47 +090080 ctx.BottomUp("sysprop_cc", cc.SyspropMutator).Parallel()
81 ctx.BottomUp("sysprop_java", java.SyspropMutator).Parallel()
Inseob Kimc0907f12019-02-08 21:00:45 +090082 })
83
Colin Cross4b49b762019-11-22 15:25:03 -080084 ctx.RegisterModuleType("sysprop_library", syspropLibraryFactory)
Inseob Kimc0907f12019-02-08 21:00:45 +090085
Colin Cross98be1bb2019-12-13 20:41:13 -080086 ctx.Register(config)
Inseob Kimc0907f12019-02-08 21:00:45 +090087
Colin Cross98be1bb2019-12-13 20:41:13 -080088 return ctx
89}
90
91func run(t *testing.T, ctx *android.TestContext, config android.Config) {
92 t.Helper()
93 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
94 android.FailIfErrored(t, errs)
95 _, errs = ctx.PrepareBuildActions(config)
96 android.FailIfErrored(t, errs)
97}
98
99func testConfig(env map[string]string, bp string, fs map[string][]byte) android.Config {
Inseob Kimc0907f12019-02-08 21:00:45 +0900100 bp += cc.GatherRequiredDepsForTest(android.Android)
101
102 mockFS := map[string][]byte{
Inseob Kim42882742019-07-30 17:55:33 +0900103 "a.java": nil,
104 "b.java": nil,
105 "c.java": nil,
106 "d.cpp": nil,
107 "api/sysprop-platform-current.txt": nil,
108 "api/sysprop-platform-latest.txt": nil,
109 "api/sysprop-platform-on-product-current.txt": nil,
110 "api/sysprop-platform-on-product-latest.txt": nil,
111 "api/sysprop-vendor-current.txt": nil,
112 "api/sysprop-vendor-latest.txt": nil,
113 "api/sysprop-odm-current.txt": nil,
114 "api/sysprop-odm-latest.txt": nil,
115 "framework/aidl/a.aidl": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900116
117 // For framework-res, which is an implicit dependency for framework
Dan Willemsen412160e2019-04-09 21:36:26 -0700118 "AndroidManifest.xml": nil,
119 "build/make/target/product/security/testkey": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900120
121 "build/soong/scripts/jar-wrapper.sh": nil,
122
123 "build/make/core/proguard.flags": nil,
124 "build/make/core/proguard_basic_keeps.flags": nil,
125
126 "jdk8/jre/lib/jce.jar": nil,
127 "jdk8/jre/lib/rt.jar": nil,
128 "jdk8/lib/tools.jar": nil,
129
130 "bar-doc/a.java": nil,
131 "bar-doc/b.java": nil,
132 "bar-doc/IFoo.aidl": nil,
133 "bar-doc/known_oj_tags.txt": nil,
134 "external/doclava/templates-sdk": nil,
135
136 "cert/new_cert.x509.pem": nil,
137 "cert/new_cert.pk8": nil,
138
139 "android/sysprop/PlatformProperties.sysprop": nil,
140 "com/android/VendorProperties.sysprop": nil,
Inseob Kim42882742019-07-30 17:55:33 +0900141 "com/android2/OdmProperties.sysprop": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900142 }
143
144 for k, v := range fs {
145 mockFS[k] = v
146 }
147
Colin Cross98be1bb2019-12-13 20:41:13 -0800148 config := java.TestConfig(buildDir, env, bp, mockFS)
Colin Crosse4759b92019-02-15 10:37:39 -0800149
Inseob Kimc0907f12019-02-08 21:00:45 +0900150 config.TestProductVariables.DeviceSystemSdkVersions = []string{"28"}
151 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
152 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
Colin Crosse4759b92019-02-15 10:37:39 -0800153
Inseob Kimc0907f12019-02-08 21:00:45 +0900154 return config
155
156}
157
158func test(t *testing.T, bp string) *android.TestContext {
159 t.Helper()
Colin Cross98be1bb2019-12-13 20:41:13 -0800160 config := testConfig(nil, bp, nil)
161 ctx := testContext(config)
Inseob Kimc0907f12019-02-08 21:00:45 +0900162 run(t, ctx, config)
163
164 return ctx
165}
166
167func TestSyspropLibrary(t *testing.T) {
168 ctx := test(t, `
169 sysprop_library {
170 name: "sysprop-platform",
171 srcs: ["android/sysprop/PlatformProperties.sysprop"],
172 api_packages: ["android.sysprop"],
173 property_owner: "Platform",
174 vendor_available: true,
175 }
176
177 sysprop_library {
178 name: "sysprop-platform-on-product",
179 srcs: ["android/sysprop/PlatformProperties.sysprop"],
180 api_packages: ["android.sysprop"],
181 property_owner: "Platform",
182 product_specific: true,
183 }
184
185 sysprop_library {
186 name: "sysprop-vendor",
187 srcs: ["com/android/VendorProperties.sysprop"],
188 api_packages: ["com.android"],
189 property_owner: "Vendor",
190 product_specific: true,
191 vendor_available: true,
192 }
193
Inseob Kim42882742019-07-30 17:55:33 +0900194 sysprop_library {
195 name: "sysprop-odm",
196 srcs: ["com/android2/OdmProperties.sysprop"],
197 api_packages: ["com.android2"],
198 property_owner: "Odm",
199 device_specific: true,
200 }
201
Inseob Kimc0907f12019-02-08 21:00:45 +0900202 java_library {
203 name: "java-platform",
204 srcs: ["c.java"],
205 sdk_version: "system_current",
206 libs: ["sysprop-platform"],
207 }
208
209 java_library {
Inseob Kimac1e9862019-12-09 18:15:47 +0900210 name: "java-platform-private",
211 srcs: ["c.java"],
212 platform_apis: true,
213 libs: ["sysprop-platform"],
214 }
215
216 java_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900217 name: "java-product",
218 srcs: ["c.java"],
219 sdk_version: "system_current",
220 product_specific: true,
221 libs: ["sysprop-platform", "sysprop-vendor"],
222 }
223
224 java_library {
225 name: "java-vendor",
226 srcs: ["c.java"],
227 sdk_version: "system_current",
228 soc_specific: true,
229 libs: ["sysprop-platform", "sysprop-vendor"],
230 }
231
232 cc_library {
233 name: "cc-client-platform",
234 srcs: ["d.cpp"],
235 static_libs: ["sysprop-platform"],
236 }
237
Jiyong Park5d1598f2019-02-25 22:14:17 +0900238 cc_library_static {
239 name: "cc-client-platform-static",
240 srcs: ["d.cpp"],
241 whole_static_libs: ["sysprop-platform"],
242 }
243
Inseob Kimc0907f12019-02-08 21:00:45 +0900244 cc_library {
245 name: "cc-client-product",
246 srcs: ["d.cpp"],
247 product_specific: true,
248 static_libs: ["sysprop-platform-on-product", "sysprop-vendor"],
249 }
250
251 cc_library {
252 name: "cc-client-vendor",
253 srcs: ["d.cpp"],
254 soc_specific: true,
255 static_libs: ["sysprop-platform", "sysprop-vendor"],
256 }
Inseob Kim1f959762019-03-27 17:20:37 +0900257
258 cc_library_headers {
259 name: "libbase_headers",
260 vendor_available: true,
261 recovery_available: true,
262 }
263
264 cc_library {
265 name: "liblog",
Yi Konge7fe9912019-06-02 00:53:50 -0700266 no_libcrt: true,
Inseob Kim1f959762019-03-27 17:20:37 +0900267 nocrt: true,
268 system_shared_libs: [],
269 recovery_available: true,
270 }
271
272 llndk_library {
273 name: "liblog",
274 symbol_file: "",
275 }
Inseob Kim42882742019-07-30 17:55:33 +0900276
277 java_library {
278 name: "sysprop-library-stub-platform",
279 sdk_version: "core_current",
280 }
281
282 java_library {
283 name: "sysprop-library-stub-vendor",
284 soc_specific: true,
285 sdk_version: "core_current",
286 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900287 `)
288
Inseob Kim42882742019-07-30 17:55:33 +0900289 // Check for generated cc_library
290 for _, variant := range []string{
Colin Crossfb0c16e2019-11-20 17:12:35 -0800291 "android_vendor.VER_arm_armv7-a-neon_shared",
292 "android_vendor.VER_arm_armv7-a-neon_static",
293 "android_vendor.VER_arm64_armv8-a_shared",
294 "android_vendor.VER_arm64_armv8-a_static",
Inseob Kim42882742019-07-30 17:55:33 +0900295 } {
296 ctx.ModuleForTests("libsysprop-platform", variant)
297 ctx.ModuleForTests("libsysprop-vendor", variant)
298 ctx.ModuleForTests("libsysprop-odm", variant)
299 }
300
Inseob Kimc0907f12019-02-08 21:00:45 +0900301 for _, variant := range []string{
Colin Cross7113d202019-11-20 16:39:12 -0800302 "android_arm_armv7-a-neon_shared",
303 "android_arm_armv7-a-neon_static",
304 "android_arm64_armv8-a_shared",
305 "android_arm64_armv8-a_static",
Inseob Kimc0907f12019-02-08 21:00:45 +0900306 } {
Inseob Kimc0907f12019-02-08 21:00:45 +0900307 ctx.ModuleForTests("libsysprop-platform", variant)
Inseob Kim42882742019-07-30 17:55:33 +0900308
309 // core variant of vendor-owned sysprop_library is for product
Inseob Kimc0907f12019-02-08 21:00:45 +0900310 ctx.ModuleForTests("libsysprop-vendor", variant)
311 }
312
313 ctx.ModuleForTests("sysprop-platform", "android_common")
Inseob Kimac1e9862019-12-09 18:15:47 +0900314 ctx.ModuleForTests("sysprop-platform_public", "android_common")
Inseob Kimc0907f12019-02-08 21:00:45 +0900315 ctx.ModuleForTests("sysprop-vendor", "android_common")
316
317 // Check for exported includes
Colin Cross7113d202019-11-20 16:39:12 -0800318 coreVariant := "android_arm64_armv8-a_static"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800319 vendorVariant := "android_vendor.VER_arm64_armv8-a_static"
Inseob Kimc0907f12019-02-08 21:00:45 +0900320
Colin Cross7113d202019-11-20 16:39:12 -0800321 platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/include"
322 platformPublicCorePath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/public/include"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800323 platformPublicVendorPath := "libsysprop-platform/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900324
Colin Cross7113d202019-11-20 16:39:12 -0800325 platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900326
Colin Crossfb0c16e2019-11-20 17:12:35 -0800327 vendorInternalPath := "libsysprop-vendor/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/include"
Colin Cross7113d202019-11-20 16:39:12 -0800328 vendorPublicPath := "libsysprop-vendor/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900329
330 platformClient := ctx.ModuleForTests("cc-client-platform", coreVariant)
331 platformFlags := platformClient.Rule("cc").Args["cFlags"]
332
Jiyong Park5d1598f2019-02-25 22:14:17 +0900333 // platform should use platform's internal header
Inseob Kimc0907f12019-02-08 21:00:45 +0900334 if !strings.Contains(platformFlags, platformInternalPath) {
335 t.Errorf("flags for platform must contain %#v, but was %#v.",
336 platformInternalPath, platformFlags)
337 }
338
Jiyong Park5d1598f2019-02-25 22:14:17 +0900339 platformStaticClient := ctx.ModuleForTests("cc-client-platform-static", coreVariant)
340 platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"]
341
342 // platform-static should use platform's internal header
343 if !strings.Contains(platformStaticFlags, platformInternalPath) {
344 t.Errorf("flags for platform-static must contain %#v, but was %#v.",
345 platformInternalPath, platformStaticFlags)
346 }
347
Inseob Kimc0907f12019-02-08 21:00:45 +0900348 productClient := ctx.ModuleForTests("cc-client-product", coreVariant)
349 productFlags := productClient.Rule("cc").Args["cFlags"]
350
Inseob Kim5cefbd22019-06-08 20:36:59 +0900351 // Product should use platform's and vendor's public headers
Inseob Kimc0907f12019-02-08 21:00:45 +0900352 if !strings.Contains(productFlags, platformOnProductPath) ||
Inseob Kim5cefbd22019-06-08 20:36:59 +0900353 !strings.Contains(productFlags, vendorPublicPath) {
Inseob Kimc0907f12019-02-08 21:00:45 +0900354 t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900355 platformPublicCorePath, vendorPublicPath, productFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900356 }
357
358 vendorClient := ctx.ModuleForTests("cc-client-vendor", vendorVariant)
359 vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
360
Inseob Kim5cefbd22019-06-08 20:36:59 +0900361 // Vendor should use platform's public header and vendor's internal header
362 if !strings.Contains(vendorFlags, platformPublicVendorPath) ||
Inseob Kimc0907f12019-02-08 21:00:45 +0900363 !strings.Contains(vendorFlags, vendorInternalPath) {
364 t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900365 platformPublicVendorPath, vendorInternalPath, vendorFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900366 }
Inseob Kimac1e9862019-12-09 18:15:47 +0900367
368 // Java modules linking against system API should use public stub
369 javaSystemApiClient := ctx.ModuleForTests("java-platform", "android_common")
370 publicStubFound := false
371 ctx.VisitDirectDeps(javaSystemApiClient.Module(), func(dep blueprint.Module) {
372 if dep.Name() == "sysprop-platform_public" {
373 publicStubFound = true
374 }
375 })
376 if !publicStubFound {
377 t.Errorf("system api client should use public stub")
378 }
379
Inseob Kimc0907f12019-02-08 21:00:45 +0900380}