blob: 090768206379706a0993af4158978b83ecb61bec [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
27 "github.com/google/blueprint/proptools"
28)
29
30var buildDir string
31
32func setUp() {
33 var err error
34 buildDir, err = ioutil.TempDir("", "soong_sysprop_test")
35 if err != nil {
36 panic(err)
37 }
38}
39
40func tearDown() {
41 os.RemoveAll(buildDir)
42}
43
44func TestMain(m *testing.M) {
45 run := func() int {
46 setUp()
47 defer tearDown()
48
49 return m.Run()
50 }
51
52 os.Exit(run())
53}
54
55func testContext(config android.Config, bp string,
56 fs map[string][]byte) *android.TestContext {
57
58 ctx := android.NewTestArchContext()
59 ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(java.AndroidAppFactory))
60 ctx.RegisterModuleType("droiddoc_template", android.ModuleFactoryAdaptor(java.ExportedDroiddocDirFactory))
61 ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(java.LibraryFactory))
62 ctx.RegisterModuleType("java_system_modules", android.ModuleFactoryAdaptor(java.SystemModulesFactory))
63 ctx.RegisterModuleType("prebuilt_apis", android.ModuleFactoryAdaptor(java.PrebuiltApisFactory))
64 ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
65 ctx.TopDown("load_hooks", android.LoadHookMutator).Parallel()
66 })
67 ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators)
68 ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators)
69 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
70 ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
71 ctx.TopDown("prebuilt_apis", java.PrebuiltApisMutator).Parallel()
72 ctx.TopDown("java_sdk_library", java.SdkLibraryMutator).Parallel()
73 })
74
75 ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))
Inseob Kim1f959762019-03-27 17:20:37 +090076 ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(cc.LibraryHeaderFactory))
Jiyong Park5d1598f2019-02-25 22:14:17 +090077 ctx.RegisterModuleType("cc_library_static", android.ModuleFactoryAdaptor(cc.LibraryFactory))
Inseob Kimc0907f12019-02-08 21:00:45 +090078 ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory))
79 ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory))
80 ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory))
81 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
82 ctx.BottomUp("image", cc.ImageMutator).Parallel()
83 ctx.BottomUp("link", cc.LinkageMutator).Parallel()
84 ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
85 ctx.BottomUp("version", cc.VersionMutator).Parallel()
86 ctx.BottomUp("begin", cc.BeginMutator).Parallel()
87 ctx.BottomUp("sysprop", cc.SyspropMutator).Parallel()
88 })
89
90 ctx.RegisterModuleType("sysprop_library", android.ModuleFactoryAdaptor(syspropLibraryFactory))
91
92 ctx.Register()
93
Colin Crosse4759b92019-02-15 10:37:39 -080094 bp += java.GatherRequiredDepsForTest()
Inseob Kimc0907f12019-02-08 21:00:45 +090095 bp += cc.GatherRequiredDepsForTest(android.Android)
96
97 mockFS := map[string][]byte{
98 "Android.bp": []byte(bp),
99 "a.java": nil,
100 "b.java": nil,
101 "c.java": nil,
102 "d.cpp": nil,
103 "api/current.txt": nil,
104 "api/removed.txt": nil,
105 "api/system-current.txt": nil,
106 "api/system-removed.txt": nil,
107 "api/test-current.txt": nil,
108 "api/test-removed.txt": nil,
Colin Cross9bdfaf02019-04-18 10:56:44 -0700109 "framework/aidl/a.aidl": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900110
111 "prebuilts/sdk/current/core/android.jar": nil,
112 "prebuilts/sdk/current/public/android.jar": nil,
113 "prebuilts/sdk/current/public/framework.aidl": nil,
114 "prebuilts/sdk/current/public/core.jar": nil,
115 "prebuilts/sdk/current/system/android.jar": nil,
116 "prebuilts/sdk/current/test/android.jar": nil,
117 "prebuilts/sdk/28/public/api/sysprop-platform.txt": nil,
118 "prebuilts/sdk/28/system/api/sysprop-platform.txt": nil,
119 "prebuilts/sdk/28/test/api/sysprop-platform.txt": nil,
120 "prebuilts/sdk/28/public/api/sysprop-platform-removed.txt": nil,
121 "prebuilts/sdk/28/system/api/sysprop-platform-removed.txt": nil,
122 "prebuilts/sdk/28/test/api/sysprop-platform-removed.txt": nil,
123 "prebuilts/sdk/28/public/api/sysprop-platform-on-product.txt": nil,
124 "prebuilts/sdk/28/system/api/sysprop-platform-on-product.txt": nil,
125 "prebuilts/sdk/28/test/api/sysprop-platform-on-product.txt": nil,
126 "prebuilts/sdk/28/public/api/sysprop-platform-on-product-removed.txt": nil,
127 "prebuilts/sdk/28/system/api/sysprop-platform-on-product-removed.txt": nil,
128 "prebuilts/sdk/28/test/api/sysprop-platform-on-product-removed.txt": nil,
129 "prebuilts/sdk/28/public/api/sysprop-vendor.txt": nil,
130 "prebuilts/sdk/28/system/api/sysprop-vendor.txt": nil,
131 "prebuilts/sdk/28/test/api/sysprop-vendor.txt": nil,
132 "prebuilts/sdk/28/public/api/sysprop-vendor-removed.txt": nil,
133 "prebuilts/sdk/28/system/api/sysprop-vendor-removed.txt": nil,
134 "prebuilts/sdk/28/test/api/sysprop-vendor-removed.txt": nil,
135 "prebuilts/sdk/tools/core-lambda-stubs.jar": nil,
136 "prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "sdk", api_dirs: ["28", "current"],}`),
137
138 // For framework-res, which is an implicit dependency for framework
Dan Willemsenadbfc492019-04-09 21:36:26 -0700139 "AndroidManifest.xml": nil,
140 "build/make/target/product/security/testkey": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900141
142 "build/soong/scripts/jar-wrapper.sh": nil,
143
144 "build/make/core/proguard.flags": nil,
145 "build/make/core/proguard_basic_keeps.flags": nil,
146
147 "jdk8/jre/lib/jce.jar": nil,
148 "jdk8/jre/lib/rt.jar": nil,
149 "jdk8/lib/tools.jar": nil,
150
151 "bar-doc/a.java": nil,
152 "bar-doc/b.java": nil,
153 "bar-doc/IFoo.aidl": nil,
154 "bar-doc/known_oj_tags.txt": nil,
155 "external/doclava/templates-sdk": nil,
156
157 "cert/new_cert.x509.pem": nil,
158 "cert/new_cert.pk8": nil,
159
160 "android/sysprop/PlatformProperties.sysprop": nil,
161 "com/android/VendorProperties.sysprop": nil,
162 }
163
164 for k, v := range fs {
165 mockFS[k] = v
166 }
167
168 ctx.MockFileSystem(mockFS)
169
170 return ctx
171}
172
173func run(t *testing.T, ctx *android.TestContext, config android.Config) {
174 t.Helper()
175 _, errs := ctx.ParseFileList(".", []string{"Android.bp", "prebuilts/sdk/Android.bp"})
176 android.FailIfErrored(t, errs)
177 _, errs = ctx.PrepareBuildActions(config)
178 android.FailIfErrored(t, errs)
179}
180
181func testConfig(env map[string]string) android.Config {
Colin Crosse4759b92019-02-15 10:37:39 -0800182 config := java.TestConfig(buildDir, env)
183
Inseob Kimc0907f12019-02-08 21:00:45 +0900184 config.TestProductVariables.DeviceSystemSdkVersions = []string{"28"}
185 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
186 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
Colin Crosse4759b92019-02-15 10:37:39 -0800187
Inseob Kimc0907f12019-02-08 21:00:45 +0900188 return config
189
190}
191
192func test(t *testing.T, bp string) *android.TestContext {
193 t.Helper()
194 config := testConfig(nil)
195 ctx := testContext(config, bp, nil)
196 run(t, ctx, config)
197
198 return ctx
199}
200
201func TestSyspropLibrary(t *testing.T) {
202 ctx := test(t, `
203 sysprop_library {
204 name: "sysprop-platform",
205 srcs: ["android/sysprop/PlatformProperties.sysprop"],
206 api_packages: ["android.sysprop"],
207 property_owner: "Platform",
208 vendor_available: true,
209 }
210
211 sysprop_library {
212 name: "sysprop-platform-on-product",
213 srcs: ["android/sysprop/PlatformProperties.sysprop"],
214 api_packages: ["android.sysprop"],
215 property_owner: "Platform",
216 product_specific: true,
217 }
218
219 sysprop_library {
220 name: "sysprop-vendor",
221 srcs: ["com/android/VendorProperties.sysprop"],
222 api_packages: ["com.android"],
223 property_owner: "Vendor",
224 product_specific: true,
225 vendor_available: true,
226 }
227
228 java_library {
229 name: "java-platform",
230 srcs: ["c.java"],
231 sdk_version: "system_current",
232 libs: ["sysprop-platform"],
233 }
234
235 java_library {
236 name: "java-product",
237 srcs: ["c.java"],
238 sdk_version: "system_current",
239 product_specific: true,
240 libs: ["sysprop-platform", "sysprop-vendor"],
241 }
242
243 java_library {
244 name: "java-vendor",
245 srcs: ["c.java"],
246 sdk_version: "system_current",
247 soc_specific: true,
248 libs: ["sysprop-platform", "sysprop-vendor"],
249 }
250
251 cc_library {
252 name: "cc-client-platform",
253 srcs: ["d.cpp"],
254 static_libs: ["sysprop-platform"],
255 }
256
Jiyong Park5d1598f2019-02-25 22:14:17 +0900257 cc_library_static {
258 name: "cc-client-platform-static",
259 srcs: ["d.cpp"],
260 whole_static_libs: ["sysprop-platform"],
261 }
262
Inseob Kimc0907f12019-02-08 21:00:45 +0900263 cc_library {
264 name: "cc-client-product",
265 srcs: ["d.cpp"],
266 product_specific: true,
267 static_libs: ["sysprop-platform-on-product", "sysprop-vendor"],
268 }
269
270 cc_library {
271 name: "cc-client-vendor",
272 srcs: ["d.cpp"],
273 soc_specific: true,
274 static_libs: ["sysprop-platform", "sysprop-vendor"],
275 }
Inseob Kim1f959762019-03-27 17:20:37 +0900276
277 cc_library_headers {
278 name: "libbase_headers",
279 vendor_available: true,
280 recovery_available: true,
281 }
282
283 cc_library {
284 name: "liblog",
285 no_libgcc: true,
286 nocrt: true,
287 system_shared_libs: [],
288 recovery_available: true,
289 }
290
291 llndk_library {
292 name: "liblog",
293 symbol_file: "",
294 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900295 `)
296
297 for _, variant := range []string{
298 "android_arm_armv7-a-neon_core_shared",
299 "android_arm_armv7-a-neon_core_static",
300 "android_arm_armv7-a-neon_vendor_shared",
301 "android_arm_armv7-a-neon_vendor_static",
302 "android_arm64_armv8-a_core_shared",
303 "android_arm64_armv8-a_core_static",
304 "android_arm64_armv8-a_vendor_shared",
305 "android_arm64_armv8-a_vendor_static",
306 } {
307 // Check for generated cc_library
308 ctx.ModuleForTests("libsysprop-platform", variant)
309 ctx.ModuleForTests("libsysprop-vendor", variant)
310 }
311
312 ctx.ModuleForTests("sysprop-platform", "android_common")
313 ctx.ModuleForTests("sysprop-vendor", "android_common")
314
315 // Check for exported includes
316 coreVariant := "android_arm64_armv8-a_core_static"
317 vendorVariant := "android_arm64_armv8-a_vendor_static"
318
319 platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_core_static/gen/sysprop/include"
320 platformSystemCorePath := "libsysprop-platform/android_arm64_armv8-a_core_static/gen/sysprop/system/include"
321 platformSystemVendorPath := "libsysprop-platform/android_arm64_armv8-a_vendor_static/gen/sysprop/system/include"
322
323 platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_core_static/gen/sysprop/system/include"
324
325 vendorInternalPath := "libsysprop-vendor/android_arm64_armv8-a_vendor_static/gen/sysprop/include"
326 vendorSystemPath := "libsysprop-vendor/android_arm64_armv8-a_core_static/gen/sysprop/system/include"
327
328 platformClient := ctx.ModuleForTests("cc-client-platform", coreVariant)
329 platformFlags := platformClient.Rule("cc").Args["cFlags"]
330
Jiyong Park5d1598f2019-02-25 22:14:17 +0900331 // platform should use platform's internal header
Inseob Kimc0907f12019-02-08 21:00:45 +0900332 if !strings.Contains(platformFlags, platformInternalPath) {
333 t.Errorf("flags for platform must contain %#v, but was %#v.",
334 platformInternalPath, platformFlags)
335 }
336
Jiyong Park5d1598f2019-02-25 22:14:17 +0900337 platformStaticClient := ctx.ModuleForTests("cc-client-platform-static", coreVariant)
338 platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"]
339
340 // platform-static should use platform's internal header
341 if !strings.Contains(platformStaticFlags, platformInternalPath) {
342 t.Errorf("flags for platform-static must contain %#v, but was %#v.",
343 platformInternalPath, platformStaticFlags)
344 }
345
Inseob Kimc0907f12019-02-08 21:00:45 +0900346 productClient := ctx.ModuleForTests("cc-client-product", coreVariant)
347 productFlags := productClient.Rule("cc").Args["cFlags"]
348
349 // Product should use platform's and vendor's system headers
350 if !strings.Contains(productFlags, platformOnProductPath) ||
351 !strings.Contains(productFlags, vendorSystemPath) {
352 t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
353 platformSystemCorePath, vendorSystemPath, productFlags)
354 }
355
356 vendorClient := ctx.ModuleForTests("cc-client-vendor", vendorVariant)
357 vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
358
359 // Vendor should use platform's system header and vendor's internal header
360 if !strings.Contains(vendorFlags, platformSystemVendorPath) ||
361 !strings.Contains(vendorFlags, vendorInternalPath) {
362 t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
363 platformSystemVendorPath, vendorInternalPath, vendorFlags)
364 }
365}