blob: a7aff59ece0c6cee6df5454b7e72e39e5225a0ee [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,
109
110 "prebuilts/sdk/current/core/android.jar": nil,
111 "prebuilts/sdk/current/public/android.jar": nil,
112 "prebuilts/sdk/current/public/framework.aidl": nil,
113 "prebuilts/sdk/current/public/core.jar": nil,
114 "prebuilts/sdk/current/system/android.jar": nil,
115 "prebuilts/sdk/current/test/android.jar": nil,
116 "prebuilts/sdk/28/public/api/sysprop-platform.txt": nil,
117 "prebuilts/sdk/28/system/api/sysprop-platform.txt": nil,
118 "prebuilts/sdk/28/test/api/sysprop-platform.txt": nil,
119 "prebuilts/sdk/28/public/api/sysprop-platform-removed.txt": nil,
120 "prebuilts/sdk/28/system/api/sysprop-platform-removed.txt": nil,
121 "prebuilts/sdk/28/test/api/sysprop-platform-removed.txt": nil,
122 "prebuilts/sdk/28/public/api/sysprop-platform-on-product.txt": nil,
123 "prebuilts/sdk/28/system/api/sysprop-platform-on-product.txt": nil,
124 "prebuilts/sdk/28/test/api/sysprop-platform-on-product.txt": nil,
125 "prebuilts/sdk/28/public/api/sysprop-platform-on-product-removed.txt": nil,
126 "prebuilts/sdk/28/system/api/sysprop-platform-on-product-removed.txt": nil,
127 "prebuilts/sdk/28/test/api/sysprop-platform-on-product-removed.txt": nil,
128 "prebuilts/sdk/28/public/api/sysprop-vendor.txt": nil,
129 "prebuilts/sdk/28/system/api/sysprop-vendor.txt": nil,
130 "prebuilts/sdk/28/test/api/sysprop-vendor.txt": nil,
131 "prebuilts/sdk/28/public/api/sysprop-vendor-removed.txt": nil,
132 "prebuilts/sdk/28/system/api/sysprop-vendor-removed.txt": nil,
133 "prebuilts/sdk/28/test/api/sysprop-vendor-removed.txt": nil,
134 "prebuilts/sdk/tools/core-lambda-stubs.jar": nil,
135 "prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "sdk", api_dirs: ["28", "current"],}`),
136
137 // For framework-res, which is an implicit dependency for framework
138 "AndroidManifest.xml": nil,
139 "build/target/product/security/testkey": nil,
140
141 "build/soong/scripts/jar-wrapper.sh": nil,
142
143 "build/make/core/proguard.flags": nil,
144 "build/make/core/proguard_basic_keeps.flags": nil,
145
146 "jdk8/jre/lib/jce.jar": nil,
147 "jdk8/jre/lib/rt.jar": nil,
148 "jdk8/lib/tools.jar": nil,
149
150 "bar-doc/a.java": nil,
151 "bar-doc/b.java": nil,
152 "bar-doc/IFoo.aidl": nil,
153 "bar-doc/known_oj_tags.txt": nil,
154 "external/doclava/templates-sdk": nil,
155
156 "cert/new_cert.x509.pem": nil,
157 "cert/new_cert.pk8": nil,
158
159 "android/sysprop/PlatformProperties.sysprop": nil,
160 "com/android/VendorProperties.sysprop": nil,
161 }
162
163 for k, v := range fs {
164 mockFS[k] = v
165 }
166
167 ctx.MockFileSystem(mockFS)
168
169 return ctx
170}
171
172func run(t *testing.T, ctx *android.TestContext, config android.Config) {
173 t.Helper()
174 _, errs := ctx.ParseFileList(".", []string{"Android.bp", "prebuilts/sdk/Android.bp"})
175 android.FailIfErrored(t, errs)
176 _, errs = ctx.PrepareBuildActions(config)
177 android.FailIfErrored(t, errs)
178}
179
180func testConfig(env map[string]string) android.Config {
Colin Crosse4759b92019-02-15 10:37:39 -0800181 config := java.TestConfig(buildDir, env)
182
Inseob Kimc0907f12019-02-08 21:00:45 +0900183 config.TestProductVariables.DeviceSystemSdkVersions = []string{"28"}
184 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
185 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
Colin Crosse4759b92019-02-15 10:37:39 -0800186
Inseob Kimc0907f12019-02-08 21:00:45 +0900187 return config
188
189}
190
191func test(t *testing.T, bp string) *android.TestContext {
192 t.Helper()
193 config := testConfig(nil)
194 ctx := testContext(config, bp, nil)
195 run(t, ctx, config)
196
197 return ctx
198}
199
200func TestSyspropLibrary(t *testing.T) {
201 ctx := test(t, `
202 sysprop_library {
203 name: "sysprop-platform",
204 srcs: ["android/sysprop/PlatformProperties.sysprop"],
205 api_packages: ["android.sysprop"],
206 property_owner: "Platform",
207 vendor_available: true,
208 }
209
210 sysprop_library {
211 name: "sysprop-platform-on-product",
212 srcs: ["android/sysprop/PlatformProperties.sysprop"],
213 api_packages: ["android.sysprop"],
214 property_owner: "Platform",
215 product_specific: true,
216 }
217
218 sysprop_library {
219 name: "sysprop-vendor",
220 srcs: ["com/android/VendorProperties.sysprop"],
221 api_packages: ["com.android"],
222 property_owner: "Vendor",
223 product_specific: true,
224 vendor_available: true,
225 }
226
227 java_library {
228 name: "java-platform",
229 srcs: ["c.java"],
230 sdk_version: "system_current",
231 libs: ["sysprop-platform"],
232 }
233
234 java_library {
235 name: "java-product",
236 srcs: ["c.java"],
237 sdk_version: "system_current",
238 product_specific: true,
239 libs: ["sysprop-platform", "sysprop-vendor"],
240 }
241
242 java_library {
243 name: "java-vendor",
244 srcs: ["c.java"],
245 sdk_version: "system_current",
246 soc_specific: true,
247 libs: ["sysprop-platform", "sysprop-vendor"],
248 }
249
250 cc_library {
251 name: "cc-client-platform",
252 srcs: ["d.cpp"],
253 static_libs: ["sysprop-platform"],
254 }
255
Jiyong Park5d1598f2019-02-25 22:14:17 +0900256 cc_library_static {
257 name: "cc-client-platform-static",
258 srcs: ["d.cpp"],
259 whole_static_libs: ["sysprop-platform"],
260 }
261
Inseob Kimc0907f12019-02-08 21:00:45 +0900262 cc_library {
263 name: "cc-client-product",
264 srcs: ["d.cpp"],
265 product_specific: true,
266 static_libs: ["sysprop-platform-on-product", "sysprop-vendor"],
267 }
268
269 cc_library {
270 name: "cc-client-vendor",
271 srcs: ["d.cpp"],
272 soc_specific: true,
273 static_libs: ["sysprop-platform", "sysprop-vendor"],
274 }
Inseob Kim1f959762019-03-27 17:20:37 +0900275
276 cc_library_headers {
277 name: "libbase_headers",
278 vendor_available: true,
279 recovery_available: true,
280 }
281
282 cc_library {
283 name: "liblog",
284 no_libgcc: true,
285 nocrt: true,
286 system_shared_libs: [],
287 recovery_available: true,
288 }
289
290 llndk_library {
291 name: "liblog",
292 symbol_file: "",
293 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900294 `)
295
296 for _, variant := range []string{
297 "android_arm_armv7-a-neon_core_shared",
298 "android_arm_armv7-a-neon_core_static",
299 "android_arm_armv7-a-neon_vendor_shared",
300 "android_arm_armv7-a-neon_vendor_static",
301 "android_arm64_armv8-a_core_shared",
302 "android_arm64_armv8-a_core_static",
303 "android_arm64_armv8-a_vendor_shared",
304 "android_arm64_armv8-a_vendor_static",
305 } {
306 // Check for generated cc_library
307 ctx.ModuleForTests("libsysprop-platform", variant)
308 ctx.ModuleForTests("libsysprop-vendor", variant)
309 }
310
311 ctx.ModuleForTests("sysprop-platform", "android_common")
312 ctx.ModuleForTests("sysprop-vendor", "android_common")
313
314 // Check for exported includes
315 coreVariant := "android_arm64_armv8-a_core_static"
316 vendorVariant := "android_arm64_armv8-a_vendor_static"
317
318 platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_core_static/gen/sysprop/include"
319 platformSystemCorePath := "libsysprop-platform/android_arm64_armv8-a_core_static/gen/sysprop/system/include"
320 platformSystemVendorPath := "libsysprop-platform/android_arm64_armv8-a_vendor_static/gen/sysprop/system/include"
321
322 platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_core_static/gen/sysprop/system/include"
323
324 vendorInternalPath := "libsysprop-vendor/android_arm64_armv8-a_vendor_static/gen/sysprop/include"
325 vendorSystemPath := "libsysprop-vendor/android_arm64_armv8-a_core_static/gen/sysprop/system/include"
326
327 platformClient := ctx.ModuleForTests("cc-client-platform", coreVariant)
328 platformFlags := platformClient.Rule("cc").Args["cFlags"]
329
Jiyong Park5d1598f2019-02-25 22:14:17 +0900330 // platform should use platform's internal header
Inseob Kimc0907f12019-02-08 21:00:45 +0900331 if !strings.Contains(platformFlags, platformInternalPath) {
332 t.Errorf("flags for platform must contain %#v, but was %#v.",
333 platformInternalPath, platformFlags)
334 }
335
Jiyong Park5d1598f2019-02-25 22:14:17 +0900336 platformStaticClient := ctx.ModuleForTests("cc-client-platform-static", coreVariant)
337 platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"]
338
339 // platform-static should use platform's internal header
340 if !strings.Contains(platformStaticFlags, platformInternalPath) {
341 t.Errorf("flags for platform-static must contain %#v, but was %#v.",
342 platformInternalPath, platformStaticFlags)
343 }
344
Inseob Kimc0907f12019-02-08 21:00:45 +0900345 productClient := ctx.ModuleForTests("cc-client-product", coreVariant)
346 productFlags := productClient.Rule("cc").Args["cFlags"]
347
348 // Product should use platform's and vendor's system headers
349 if !strings.Contains(productFlags, platformOnProductPath) ||
350 !strings.Contains(productFlags, vendorSystemPath) {
351 t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
352 platformSystemCorePath, vendorSystemPath, productFlags)
353 }
354
355 vendorClient := ctx.ModuleForTests("cc-client-vendor", vendorVariant)
356 vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
357
358 // Vendor should use platform's system header and vendor's internal header
359 if !strings.Contains(vendorFlags, platformSystemVendorPath) ||
360 !strings.Contains(vendorFlags, vendorInternalPath) {
361 t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
362 platformSystemVendorPath, vendorInternalPath, vendorFlags)
363 }
364}