blob: e90519ed0c13004bd9093a652cae9feb9490c71d [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))
Inseob Kimc0907f12019-02-08 21:00:45 +090064 ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators)
65 ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators)
66 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
67 ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
68 ctx.TopDown("prebuilt_apis", java.PrebuiltApisMutator).Parallel()
Inseob Kimc0907f12019-02-08 21:00:45 +090069 })
70
71 ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))
Inseob Kim1f959762019-03-27 17:20:37 +090072 ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(cc.LibraryHeaderFactory))
Jiyong Park5d1598f2019-02-25 22:14:17 +090073 ctx.RegisterModuleType("cc_library_static", android.ModuleFactoryAdaptor(cc.LibraryFactory))
Inseob Kimc0907f12019-02-08 21:00:45 +090074 ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory))
75 ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory))
76 ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory))
77 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
78 ctx.BottomUp("image", cc.ImageMutator).Parallel()
79 ctx.BottomUp("link", cc.LinkageMutator).Parallel()
80 ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
81 ctx.BottomUp("version", cc.VersionMutator).Parallel()
82 ctx.BottomUp("begin", cc.BeginMutator).Parallel()
83 ctx.BottomUp("sysprop", cc.SyspropMutator).Parallel()
84 })
85
86 ctx.RegisterModuleType("sysprop_library", android.ModuleFactoryAdaptor(syspropLibraryFactory))
87
88 ctx.Register()
89
Colin Crosse4759b92019-02-15 10:37:39 -080090 bp += java.GatherRequiredDepsForTest()
Inseob Kimc0907f12019-02-08 21:00:45 +090091 bp += cc.GatherRequiredDepsForTest(android.Android)
92
93 mockFS := map[string][]byte{
94 "Android.bp": []byte(bp),
95 "a.java": nil,
96 "b.java": nil,
97 "c.java": nil,
98 "d.cpp": nil,
99 "api/current.txt": nil,
100 "api/removed.txt": nil,
101 "api/system-current.txt": nil,
102 "api/system-removed.txt": nil,
103 "api/test-current.txt": nil,
104 "api/test-removed.txt": nil,
105
106 "prebuilts/sdk/current/core/android.jar": nil,
107 "prebuilts/sdk/current/public/android.jar": nil,
108 "prebuilts/sdk/current/public/framework.aidl": nil,
109 "prebuilts/sdk/current/public/core.jar": nil,
110 "prebuilts/sdk/current/system/android.jar": nil,
111 "prebuilts/sdk/current/test/android.jar": nil,
112 "prebuilts/sdk/28/public/api/sysprop-platform.txt": nil,
113 "prebuilts/sdk/28/system/api/sysprop-platform.txt": nil,
114 "prebuilts/sdk/28/test/api/sysprop-platform.txt": nil,
115 "prebuilts/sdk/28/public/api/sysprop-platform-removed.txt": nil,
116 "prebuilts/sdk/28/system/api/sysprop-platform-removed.txt": nil,
117 "prebuilts/sdk/28/test/api/sysprop-platform-removed.txt": nil,
118 "prebuilts/sdk/28/public/api/sysprop-platform-on-product.txt": nil,
119 "prebuilts/sdk/28/system/api/sysprop-platform-on-product.txt": nil,
120 "prebuilts/sdk/28/test/api/sysprop-platform-on-product.txt": nil,
121 "prebuilts/sdk/28/public/api/sysprop-platform-on-product-removed.txt": nil,
122 "prebuilts/sdk/28/system/api/sysprop-platform-on-product-removed.txt": nil,
123 "prebuilts/sdk/28/test/api/sysprop-platform-on-product-removed.txt": nil,
124 "prebuilts/sdk/28/public/api/sysprop-vendor.txt": nil,
125 "prebuilts/sdk/28/system/api/sysprop-vendor.txt": nil,
126 "prebuilts/sdk/28/test/api/sysprop-vendor.txt": nil,
127 "prebuilts/sdk/28/public/api/sysprop-vendor-removed.txt": nil,
128 "prebuilts/sdk/28/system/api/sysprop-vendor-removed.txt": nil,
129 "prebuilts/sdk/28/test/api/sysprop-vendor-removed.txt": nil,
130 "prebuilts/sdk/tools/core-lambda-stubs.jar": nil,
131 "prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "sdk", api_dirs: ["28", "current"],}`),
132
133 // For framework-res, which is an implicit dependency for framework
Dan Willemsen412160e2019-04-09 21:36:26 -0700134 "AndroidManifest.xml": nil,
135 "build/make/target/product/security/testkey": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900136
137 "build/soong/scripts/jar-wrapper.sh": nil,
138
139 "build/make/core/proguard.flags": nil,
140 "build/make/core/proguard_basic_keeps.flags": nil,
141
142 "jdk8/jre/lib/jce.jar": nil,
143 "jdk8/jre/lib/rt.jar": nil,
144 "jdk8/lib/tools.jar": nil,
145
146 "bar-doc/a.java": nil,
147 "bar-doc/b.java": nil,
148 "bar-doc/IFoo.aidl": nil,
149 "bar-doc/known_oj_tags.txt": nil,
150 "external/doclava/templates-sdk": nil,
151
152 "cert/new_cert.x509.pem": nil,
153 "cert/new_cert.pk8": nil,
154
155 "android/sysprop/PlatformProperties.sysprop": nil,
156 "com/android/VendorProperties.sysprop": nil,
157 }
158
159 for k, v := range fs {
160 mockFS[k] = v
161 }
162
163 ctx.MockFileSystem(mockFS)
164
165 return ctx
166}
167
168func run(t *testing.T, ctx *android.TestContext, config android.Config) {
169 t.Helper()
170 _, errs := ctx.ParseFileList(".", []string{"Android.bp", "prebuilts/sdk/Android.bp"})
171 android.FailIfErrored(t, errs)
172 _, errs = ctx.PrepareBuildActions(config)
173 android.FailIfErrored(t, errs)
174}
175
176func testConfig(env map[string]string) android.Config {
Colin Crosse4759b92019-02-15 10:37:39 -0800177 config := java.TestConfig(buildDir, env)
178
Inseob Kimc0907f12019-02-08 21:00:45 +0900179 config.TestProductVariables.DeviceSystemSdkVersions = []string{"28"}
180 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
181 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
Colin Crosse4759b92019-02-15 10:37:39 -0800182
Inseob Kimc0907f12019-02-08 21:00:45 +0900183 return config
184
185}
186
187func test(t *testing.T, bp string) *android.TestContext {
188 t.Helper()
189 config := testConfig(nil)
190 ctx := testContext(config, bp, nil)
191 run(t, ctx, config)
192
193 return ctx
194}
195
196func TestSyspropLibrary(t *testing.T) {
197 ctx := test(t, `
198 sysprop_library {
199 name: "sysprop-platform",
200 srcs: ["android/sysprop/PlatformProperties.sysprop"],
201 api_packages: ["android.sysprop"],
202 property_owner: "Platform",
203 vendor_available: true,
204 }
205
206 sysprop_library {
207 name: "sysprop-platform-on-product",
208 srcs: ["android/sysprop/PlatformProperties.sysprop"],
209 api_packages: ["android.sysprop"],
210 property_owner: "Platform",
211 product_specific: true,
212 }
213
214 sysprop_library {
215 name: "sysprop-vendor",
216 srcs: ["com/android/VendorProperties.sysprop"],
217 api_packages: ["com.android"],
218 property_owner: "Vendor",
219 product_specific: true,
220 vendor_available: true,
221 }
222
223 java_library {
224 name: "java-platform",
225 srcs: ["c.java"],
226 sdk_version: "system_current",
227 libs: ["sysprop-platform"],
228 }
229
230 java_library {
231 name: "java-product",
232 srcs: ["c.java"],
233 sdk_version: "system_current",
234 product_specific: true,
235 libs: ["sysprop-platform", "sysprop-vendor"],
236 }
237
238 java_library {
239 name: "java-vendor",
240 srcs: ["c.java"],
241 sdk_version: "system_current",
242 soc_specific: true,
243 libs: ["sysprop-platform", "sysprop-vendor"],
244 }
245
246 cc_library {
247 name: "cc-client-platform",
248 srcs: ["d.cpp"],
249 static_libs: ["sysprop-platform"],
250 }
251
Jiyong Park5d1598f2019-02-25 22:14:17 +0900252 cc_library_static {
253 name: "cc-client-platform-static",
254 srcs: ["d.cpp"],
255 whole_static_libs: ["sysprop-platform"],
256 }
257
Inseob Kimc0907f12019-02-08 21:00:45 +0900258 cc_library {
259 name: "cc-client-product",
260 srcs: ["d.cpp"],
261 product_specific: true,
262 static_libs: ["sysprop-platform-on-product", "sysprop-vendor"],
263 }
264
265 cc_library {
266 name: "cc-client-vendor",
267 srcs: ["d.cpp"],
268 soc_specific: true,
269 static_libs: ["sysprop-platform", "sysprop-vendor"],
270 }
Inseob Kim1f959762019-03-27 17:20:37 +0900271
272 cc_library_headers {
273 name: "libbase_headers",
274 vendor_available: true,
275 recovery_available: true,
276 }
277
278 cc_library {
279 name: "liblog",
280 no_libgcc: true,
281 nocrt: true,
282 system_shared_libs: [],
283 recovery_available: true,
284 }
285
286 llndk_library {
287 name: "liblog",
288 symbol_file: "",
289 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900290 `)
291
292 for _, variant := range []string{
293 "android_arm_armv7-a-neon_core_shared",
294 "android_arm_armv7-a-neon_core_static",
295 "android_arm_armv7-a-neon_vendor_shared",
296 "android_arm_armv7-a-neon_vendor_static",
297 "android_arm64_armv8-a_core_shared",
298 "android_arm64_armv8-a_core_static",
299 "android_arm64_armv8-a_vendor_shared",
300 "android_arm64_armv8-a_vendor_static",
301 } {
302 // Check for generated cc_library
303 ctx.ModuleForTests("libsysprop-platform", variant)
304 ctx.ModuleForTests("libsysprop-vendor", variant)
305 }
306
307 ctx.ModuleForTests("sysprop-platform", "android_common")
308 ctx.ModuleForTests("sysprop-vendor", "android_common")
309
310 // Check for exported includes
311 coreVariant := "android_arm64_armv8-a_core_static"
312 vendorVariant := "android_arm64_armv8-a_vendor_static"
313
314 platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_core_static/gen/sysprop/include"
315 platformSystemCorePath := "libsysprop-platform/android_arm64_armv8-a_core_static/gen/sysprop/system/include"
316 platformSystemVendorPath := "libsysprop-platform/android_arm64_armv8-a_vendor_static/gen/sysprop/system/include"
317
318 platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_core_static/gen/sysprop/system/include"
319
320 vendorInternalPath := "libsysprop-vendor/android_arm64_armv8-a_vendor_static/gen/sysprop/include"
321 vendorSystemPath := "libsysprop-vendor/android_arm64_armv8-a_core_static/gen/sysprop/system/include"
322
323 platformClient := ctx.ModuleForTests("cc-client-platform", coreVariant)
324 platformFlags := platformClient.Rule("cc").Args["cFlags"]
325
Jiyong Park5d1598f2019-02-25 22:14:17 +0900326 // platform should use platform's internal header
Inseob Kimc0907f12019-02-08 21:00:45 +0900327 if !strings.Contains(platformFlags, platformInternalPath) {
328 t.Errorf("flags for platform must contain %#v, but was %#v.",
329 platformInternalPath, platformFlags)
330 }
331
Jiyong Park5d1598f2019-02-25 22:14:17 +0900332 platformStaticClient := ctx.ModuleForTests("cc-client-platform-static", coreVariant)
333 platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"]
334
335 // platform-static should use platform's internal header
336 if !strings.Contains(platformStaticFlags, platformInternalPath) {
337 t.Errorf("flags for platform-static must contain %#v, but was %#v.",
338 platformInternalPath, platformStaticFlags)
339 }
340
Inseob Kimc0907f12019-02-08 21:00:45 +0900341 productClient := ctx.ModuleForTests("cc-client-product", coreVariant)
342 productFlags := productClient.Rule("cc").Args["cFlags"]
343
344 // Product should use platform's and vendor's system headers
345 if !strings.Contains(productFlags, platformOnProductPath) ||
346 !strings.Contains(productFlags, vendorSystemPath) {
347 t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
348 platformSystemCorePath, vendorSystemPath, productFlags)
349 }
350
351 vendorClient := ctx.ModuleForTests("cc-client-vendor", vendorVariant)
352 vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
353
354 // Vendor should use platform's system header and vendor's internal header
355 if !strings.Contains(vendorFlags, platformSystemVendorPath) ||
356 !strings.Contains(vendorFlags, vendorInternalPath) {
357 t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
358 platformSystemVendorPath, vendorInternalPath, vendorFlags)
359 }
360}