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