blob: 92e0af4b63c068b1940e6a9191c7188f833df244 [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
22 "fmt"
23 "io/ioutil"
24 "os"
25 "strings"
26 "testing"
27
28 "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
56func testContext(config android.Config, bp string,
57 fs map[string][]byte) *android.TestContext {
58
59 ctx := android.NewTestArchContext()
60 ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(java.AndroidAppFactory))
61 ctx.RegisterModuleType("droiddoc_template", android.ModuleFactoryAdaptor(java.ExportedDroiddocDirFactory))
62 ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(java.LibraryFactory))
63 ctx.RegisterModuleType("java_system_modules", android.ModuleFactoryAdaptor(java.SystemModulesFactory))
64 ctx.RegisterModuleType("prebuilt_apis", android.ModuleFactoryAdaptor(java.PrebuiltApisFactory))
65 ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
66 ctx.TopDown("load_hooks", android.LoadHookMutator).Parallel()
67 })
68 ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators)
69 ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators)
70 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
71 ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
72 ctx.TopDown("prebuilt_apis", java.PrebuiltApisMutator).Parallel()
73 ctx.TopDown("java_sdk_library", java.SdkLibraryMutator).Parallel()
74 })
75
76 ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))
77 ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory))
78 ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory))
79 ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory))
80 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
81 ctx.BottomUp("image", cc.ImageMutator).Parallel()
82 ctx.BottomUp("link", cc.LinkageMutator).Parallel()
83 ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
84 ctx.BottomUp("version", cc.VersionMutator).Parallel()
85 ctx.BottomUp("begin", cc.BeginMutator).Parallel()
86 ctx.BottomUp("sysprop", cc.SyspropMutator).Parallel()
87 })
88
89 ctx.RegisterModuleType("sysprop_library", android.ModuleFactoryAdaptor(syspropLibraryFactory))
90
91 ctx.Register()
92
93 extraModules := []string{
94 "core-lambda-stubs",
95 "framework",
96 "ext",
97 "updatable_media_stubs",
98
99 "android_stubs_current",
100 "android_system_stubs_current",
101 "android_test_stubs_current",
102 "core.current.stubs",
103 "core.platform.api.stubs",
104 }
105
106 for _, extra := range extraModules {
107 bp += fmt.Sprintf(`
108 java_library {
109 name: "%s",
110 srcs: ["a.java"],
111 no_standard_libs: true,
112 sdk_version: "core_current",
113 system_modules: "core-platform-api-stubs-system-modules",
114 }
115 `, extra)
116 }
117
118 bp += `
119 android_app {
120 name: "framework-res",
121 no_framework_libs: true,
122 }
123 `
124
125 systemModules := []string{
126 "core-system-modules",
127 "core-platform-api-stubs-system-modules",
128 "android_stubs_current_system_modules",
129 "android_system_stubs_current_system_modules",
130 "android_test_stubs_current_system_modules",
131 }
132
133 for _, extra := range systemModules {
134 bp += fmt.Sprintf(`
135 java_system_modules {
136 name: "%s",
137 }
138 `, extra)
139 }
140
141 bp += cc.GatherRequiredDepsForTest(android.Android)
142
143 mockFS := map[string][]byte{
144 "Android.bp": []byte(bp),
145 "a.java": nil,
146 "b.java": nil,
147 "c.java": nil,
148 "d.cpp": nil,
149 "api/current.txt": nil,
150 "api/removed.txt": nil,
151 "api/system-current.txt": nil,
152 "api/system-removed.txt": nil,
153 "api/test-current.txt": nil,
154 "api/test-removed.txt": nil,
155
156 "prebuilts/sdk/current/core/android.jar": nil,
157 "prebuilts/sdk/current/public/android.jar": nil,
158 "prebuilts/sdk/current/public/framework.aidl": nil,
159 "prebuilts/sdk/current/public/core.jar": nil,
160 "prebuilts/sdk/current/system/android.jar": nil,
161 "prebuilts/sdk/current/test/android.jar": nil,
162 "prebuilts/sdk/28/public/api/sysprop-platform.txt": nil,
163 "prebuilts/sdk/28/system/api/sysprop-platform.txt": nil,
164 "prebuilts/sdk/28/test/api/sysprop-platform.txt": nil,
165 "prebuilts/sdk/28/public/api/sysprop-platform-removed.txt": nil,
166 "prebuilts/sdk/28/system/api/sysprop-platform-removed.txt": nil,
167 "prebuilts/sdk/28/test/api/sysprop-platform-removed.txt": nil,
168 "prebuilts/sdk/28/public/api/sysprop-platform-on-product.txt": nil,
169 "prebuilts/sdk/28/system/api/sysprop-platform-on-product.txt": nil,
170 "prebuilts/sdk/28/test/api/sysprop-platform-on-product.txt": nil,
171 "prebuilts/sdk/28/public/api/sysprop-platform-on-product-removed.txt": nil,
172 "prebuilts/sdk/28/system/api/sysprop-platform-on-product-removed.txt": nil,
173 "prebuilts/sdk/28/test/api/sysprop-platform-on-product-removed.txt": nil,
174 "prebuilts/sdk/28/public/api/sysprop-vendor.txt": nil,
175 "prebuilts/sdk/28/system/api/sysprop-vendor.txt": nil,
176 "prebuilts/sdk/28/test/api/sysprop-vendor.txt": nil,
177 "prebuilts/sdk/28/public/api/sysprop-vendor-removed.txt": nil,
178 "prebuilts/sdk/28/system/api/sysprop-vendor-removed.txt": nil,
179 "prebuilts/sdk/28/test/api/sysprop-vendor-removed.txt": nil,
180 "prebuilts/sdk/tools/core-lambda-stubs.jar": nil,
181 "prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "sdk", api_dirs: ["28", "current"],}`),
182
183 // For framework-res, which is an implicit dependency for framework
184 "AndroidManifest.xml": nil,
185 "build/target/product/security/testkey": nil,
186
187 "build/soong/scripts/jar-wrapper.sh": nil,
188
189 "build/make/core/proguard.flags": nil,
190 "build/make/core/proguard_basic_keeps.flags": nil,
191
192 "jdk8/jre/lib/jce.jar": nil,
193 "jdk8/jre/lib/rt.jar": nil,
194 "jdk8/lib/tools.jar": nil,
195
196 "bar-doc/a.java": nil,
197 "bar-doc/b.java": nil,
198 "bar-doc/IFoo.aidl": nil,
199 "bar-doc/known_oj_tags.txt": nil,
200 "external/doclava/templates-sdk": nil,
201
202 "cert/new_cert.x509.pem": nil,
203 "cert/new_cert.pk8": nil,
204
205 "android/sysprop/PlatformProperties.sysprop": nil,
206 "com/android/VendorProperties.sysprop": nil,
207 }
208
209 for k, v := range fs {
210 mockFS[k] = v
211 }
212
213 ctx.MockFileSystem(mockFS)
214
215 return ctx
216}
217
218func run(t *testing.T, ctx *android.TestContext, config android.Config) {
219 t.Helper()
220 _, errs := ctx.ParseFileList(".", []string{"Android.bp", "prebuilts/sdk/Android.bp"})
221 android.FailIfErrored(t, errs)
222 _, errs = ctx.PrepareBuildActions(config)
223 android.FailIfErrored(t, errs)
224}
225
226func testConfig(env map[string]string) android.Config {
227 if env == nil {
228 env = make(map[string]string)
229 }
230 if env["ANDROID_JAVA8_HOME"] == "" {
231 env["ANDROID_JAVA8_HOME"] = "jdk8"
232 }
233 config := android.TestArchConfig(buildDir, env)
234 config.TestProductVariables.DeviceSystemSdkVersions = []string{"28"}
235 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
236 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
237 return config
238
239}
240
241func test(t *testing.T, bp string) *android.TestContext {
242 t.Helper()
243 config := testConfig(nil)
244 ctx := testContext(config, bp, nil)
245 run(t, ctx, config)
246
247 return ctx
248}
249
250func TestSyspropLibrary(t *testing.T) {
251 ctx := test(t, `
252 sysprop_library {
253 name: "sysprop-platform",
254 srcs: ["android/sysprop/PlatformProperties.sysprop"],
255 api_packages: ["android.sysprop"],
256 property_owner: "Platform",
257 vendor_available: true,
258 }
259
260 sysprop_library {
261 name: "sysprop-platform-on-product",
262 srcs: ["android/sysprop/PlatformProperties.sysprop"],
263 api_packages: ["android.sysprop"],
264 property_owner: "Platform",
265 product_specific: true,
266 }
267
268 sysprop_library {
269 name: "sysprop-vendor",
270 srcs: ["com/android/VendorProperties.sysprop"],
271 api_packages: ["com.android"],
272 property_owner: "Vendor",
273 product_specific: true,
274 vendor_available: true,
275 }
276
277 java_library {
278 name: "java-platform",
279 srcs: ["c.java"],
280 sdk_version: "system_current",
281 libs: ["sysprop-platform"],
282 }
283
284 java_library {
285 name: "java-product",
286 srcs: ["c.java"],
287 sdk_version: "system_current",
288 product_specific: true,
289 libs: ["sysprop-platform", "sysprop-vendor"],
290 }
291
292 java_library {
293 name: "java-vendor",
294 srcs: ["c.java"],
295 sdk_version: "system_current",
296 soc_specific: true,
297 libs: ["sysprop-platform", "sysprop-vendor"],
298 }
299
300 cc_library {
301 name: "cc-client-platform",
302 srcs: ["d.cpp"],
303 static_libs: ["sysprop-platform"],
304 }
305
306 cc_library {
307 name: "cc-client-product",
308 srcs: ["d.cpp"],
309 product_specific: true,
310 static_libs: ["sysprop-platform-on-product", "sysprop-vendor"],
311 }
312
313 cc_library {
314 name: "cc-client-vendor",
315 srcs: ["d.cpp"],
316 soc_specific: true,
317 static_libs: ["sysprop-platform", "sysprop-vendor"],
318 }
319 `)
320
321 for _, variant := range []string{
322 "android_arm_armv7-a-neon_core_shared",
323 "android_arm_armv7-a-neon_core_static",
324 "android_arm_armv7-a-neon_vendor_shared",
325 "android_arm_armv7-a-neon_vendor_static",
326 "android_arm64_armv8-a_core_shared",
327 "android_arm64_armv8-a_core_static",
328 "android_arm64_armv8-a_vendor_shared",
329 "android_arm64_armv8-a_vendor_static",
330 } {
331 // Check for generated cc_library
332 ctx.ModuleForTests("libsysprop-platform", variant)
333 ctx.ModuleForTests("libsysprop-vendor", variant)
334 }
335
336 ctx.ModuleForTests("sysprop-platform", "android_common")
337 ctx.ModuleForTests("sysprop-vendor", "android_common")
338
339 // Check for exported includes
340 coreVariant := "android_arm64_armv8-a_core_static"
341 vendorVariant := "android_arm64_armv8-a_vendor_static"
342
343 platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_core_static/gen/sysprop/include"
344 platformSystemCorePath := "libsysprop-platform/android_arm64_armv8-a_core_static/gen/sysprop/system/include"
345 platformSystemVendorPath := "libsysprop-platform/android_arm64_armv8-a_vendor_static/gen/sysprop/system/include"
346
347 platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_core_static/gen/sysprop/system/include"
348
349 vendorInternalPath := "libsysprop-vendor/android_arm64_armv8-a_vendor_static/gen/sysprop/include"
350 vendorSystemPath := "libsysprop-vendor/android_arm64_armv8-a_core_static/gen/sysprop/system/include"
351
352 platformClient := ctx.ModuleForTests("cc-client-platform", coreVariant)
353 platformFlags := platformClient.Rule("cc").Args["cFlags"]
354
355 // Platform should use platform's internal header
356 if !strings.Contains(platformFlags, platformInternalPath) {
357 t.Errorf("flags for platform must contain %#v, but was %#v.",
358 platformInternalPath, platformFlags)
359 }
360
361 productClient := ctx.ModuleForTests("cc-client-product", coreVariant)
362 productFlags := productClient.Rule("cc").Args["cFlags"]
363
364 // Product should use platform's and vendor's system headers
365 if !strings.Contains(productFlags, platformOnProductPath) ||
366 !strings.Contains(productFlags, vendorSystemPath) {
367 t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
368 platformSystemCorePath, vendorSystemPath, productFlags)
369 }
370
371 vendorClient := ctx.ModuleForTests("cc-client-vendor", vendorVariant)
372 vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
373
374 // Vendor should use platform's system header and vendor's internal header
375 if !strings.Contains(vendorFlags, platformSystemVendorPath) ||
376 !strings.Contains(vendorFlags, vendorInternalPath) {
377 t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
378 platformSystemVendorPath, vendorInternalPath, vendorFlags)
379 }
380}