blob: c7f840158def911f2df009dfbdee1b80c07c1dfa [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
Inseob Kimac1e9862019-12-09 18:15:47 +090027 "github.com/google/blueprint"
Inseob Kimc0907f12019-02-08 21:00:45 +090028 "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()
Colin Cross4b49b762019-11-22 15:25:03 -080060 ctx.RegisterModuleType("android_app", java.AndroidAppFactory)
61 ctx.RegisterModuleType("java_library", java.LibraryFactory)
62 ctx.RegisterModuleType("java_system_modules", java.SystemModulesFactory)
Inseob Kimc0907f12019-02-08 21:00:45 +090063 ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators)
64 ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators)
65 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Inseob Kim988f53c2019-09-16 15:59:01 +090066 ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
67 ctx.BottomUp("sysprop_deps", syspropDepsMutator).Parallel()
68 })
Inseob Kimc0907f12019-02-08 21:00:45 +090069
Colin Cross4b49b762019-11-22 15:25:03 -080070 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
71 ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
72 ctx.RegisterModuleType("cc_library_static", cc.LibraryFactory)
73 ctx.RegisterModuleType("cc_object", cc.ObjectFactory)
74 ctx.RegisterModuleType("llndk_library", cc.LlndkLibraryFactory)
75 ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory)
Inseob Kimc0907f12019-02-08 21:00:45 +090076 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Inseob Kimc0907f12019-02-08 21:00:45 +090077 ctx.BottomUp("link", cc.LinkageMutator).Parallel()
78 ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
79 ctx.BottomUp("version", cc.VersionMutator).Parallel()
80 ctx.BottomUp("begin", cc.BeginMutator).Parallel()
Inseob Kimac1e9862019-12-09 18:15:47 +090081 ctx.BottomUp("sysprop_cc", cc.SyspropMutator).Parallel()
82 ctx.BottomUp("sysprop_java", java.SyspropMutator).Parallel()
Inseob Kimc0907f12019-02-08 21:00:45 +090083 })
84
Colin Cross4b49b762019-11-22 15:25:03 -080085 ctx.RegisterModuleType("sysprop_library", syspropLibraryFactory)
Inseob Kimc0907f12019-02-08 21:00:45 +090086
87 ctx.Register()
88
Colin Crosse4759b92019-02-15 10:37:39 -080089 bp += java.GatherRequiredDepsForTest()
Inseob Kimc0907f12019-02-08 21:00:45 +090090 bp += cc.GatherRequiredDepsForTest(android.Android)
91
92 mockFS := map[string][]byte{
Inseob Kim42882742019-07-30 17:55:33 +090093 "Android.bp": []byte(bp),
94 "a.java": nil,
95 "b.java": nil,
96 "c.java": nil,
97 "d.cpp": nil,
98 "api/sysprop-platform-current.txt": nil,
99 "api/sysprop-platform-latest.txt": nil,
100 "api/sysprop-platform-on-product-current.txt": nil,
101 "api/sysprop-platform-on-product-latest.txt": nil,
102 "api/sysprop-vendor-current.txt": nil,
103 "api/sysprop-vendor-latest.txt": nil,
104 "api/sysprop-odm-current.txt": nil,
105 "api/sysprop-odm-latest.txt": nil,
106 "framework/aidl/a.aidl": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900107
108 // For framework-res, which is an implicit dependency for framework
Dan Willemsen412160e2019-04-09 21:36:26 -0700109 "AndroidManifest.xml": nil,
110 "build/make/target/product/security/testkey": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900111
112 "build/soong/scripts/jar-wrapper.sh": nil,
113
114 "build/make/core/proguard.flags": nil,
115 "build/make/core/proguard_basic_keeps.flags": nil,
116
117 "jdk8/jre/lib/jce.jar": nil,
118 "jdk8/jre/lib/rt.jar": nil,
119 "jdk8/lib/tools.jar": nil,
120
121 "bar-doc/a.java": nil,
122 "bar-doc/b.java": nil,
123 "bar-doc/IFoo.aidl": nil,
124 "bar-doc/known_oj_tags.txt": nil,
125 "external/doclava/templates-sdk": nil,
126
127 "cert/new_cert.x509.pem": nil,
128 "cert/new_cert.pk8": nil,
129
130 "android/sysprop/PlatformProperties.sysprop": nil,
131 "com/android/VendorProperties.sysprop": nil,
Inseob Kim42882742019-07-30 17:55:33 +0900132 "com/android2/OdmProperties.sysprop": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900133 }
134
135 for k, v := range fs {
136 mockFS[k] = v
137 }
138
139 ctx.MockFileSystem(mockFS)
140
141 return ctx
142}
143
144func run(t *testing.T, ctx *android.TestContext, config android.Config) {
145 t.Helper()
Inseob Kim42882742019-07-30 17:55:33 +0900146 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
Inseob Kimc0907f12019-02-08 21:00:45 +0900147 android.FailIfErrored(t, errs)
148 _, errs = ctx.PrepareBuildActions(config)
149 android.FailIfErrored(t, errs)
150}
151
152func testConfig(env map[string]string) android.Config {
Colin Crosse4759b92019-02-15 10:37:39 -0800153 config := java.TestConfig(buildDir, env)
154
Inseob Kimc0907f12019-02-08 21:00:45 +0900155 config.TestProductVariables.DeviceSystemSdkVersions = []string{"28"}
156 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
157 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
Colin Crosse4759b92019-02-15 10:37:39 -0800158
Inseob Kimc0907f12019-02-08 21:00:45 +0900159 return config
160
161}
162
163func test(t *testing.T, bp string) *android.TestContext {
164 t.Helper()
165 config := testConfig(nil)
166 ctx := testContext(config, bp, nil)
167 run(t, ctx, config)
168
169 return ctx
170}
171
172func TestSyspropLibrary(t *testing.T) {
173 ctx := test(t, `
174 sysprop_library {
175 name: "sysprop-platform",
176 srcs: ["android/sysprop/PlatformProperties.sysprop"],
177 api_packages: ["android.sysprop"],
178 property_owner: "Platform",
179 vendor_available: true,
180 }
181
182 sysprop_library {
183 name: "sysprop-platform-on-product",
184 srcs: ["android/sysprop/PlatformProperties.sysprop"],
185 api_packages: ["android.sysprop"],
186 property_owner: "Platform",
187 product_specific: true,
188 }
189
190 sysprop_library {
191 name: "sysprop-vendor",
192 srcs: ["com/android/VendorProperties.sysprop"],
193 api_packages: ["com.android"],
194 property_owner: "Vendor",
195 product_specific: true,
196 vendor_available: true,
197 }
198
Inseob Kim42882742019-07-30 17:55:33 +0900199 sysprop_library {
200 name: "sysprop-odm",
201 srcs: ["com/android2/OdmProperties.sysprop"],
202 api_packages: ["com.android2"],
203 property_owner: "Odm",
204 device_specific: true,
205 }
206
Inseob Kimc0907f12019-02-08 21:00:45 +0900207 java_library {
208 name: "java-platform",
209 srcs: ["c.java"],
210 sdk_version: "system_current",
211 libs: ["sysprop-platform"],
212 }
213
214 java_library {
Inseob Kimac1e9862019-12-09 18:15:47 +0900215 name: "java-platform-private",
216 srcs: ["c.java"],
217 platform_apis: true,
218 libs: ["sysprop-platform"],
219 }
220
221 java_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900222 name: "java-product",
223 srcs: ["c.java"],
224 sdk_version: "system_current",
225 product_specific: true,
226 libs: ["sysprop-platform", "sysprop-vendor"],
227 }
228
229 java_library {
230 name: "java-vendor",
231 srcs: ["c.java"],
232 sdk_version: "system_current",
233 soc_specific: true,
234 libs: ["sysprop-platform", "sysprop-vendor"],
235 }
236
237 cc_library {
238 name: "cc-client-platform",
239 srcs: ["d.cpp"],
240 static_libs: ["sysprop-platform"],
241 }
242
Jiyong Park5d1598f2019-02-25 22:14:17 +0900243 cc_library_static {
244 name: "cc-client-platform-static",
245 srcs: ["d.cpp"],
246 whole_static_libs: ["sysprop-platform"],
247 }
248
Inseob Kimc0907f12019-02-08 21:00:45 +0900249 cc_library {
250 name: "cc-client-product",
251 srcs: ["d.cpp"],
252 product_specific: true,
253 static_libs: ["sysprop-platform-on-product", "sysprop-vendor"],
254 }
255
256 cc_library {
257 name: "cc-client-vendor",
258 srcs: ["d.cpp"],
259 soc_specific: true,
260 static_libs: ["sysprop-platform", "sysprop-vendor"],
261 }
Inseob Kim1f959762019-03-27 17:20:37 +0900262
263 cc_library_headers {
264 name: "libbase_headers",
265 vendor_available: true,
266 recovery_available: true,
267 }
268
269 cc_library {
270 name: "liblog",
Yi Konge7fe9912019-06-02 00:53:50 -0700271 no_libcrt: true,
Inseob Kim1f959762019-03-27 17:20:37 +0900272 nocrt: true,
273 system_shared_libs: [],
274 recovery_available: true,
275 }
276
277 llndk_library {
278 name: "liblog",
279 symbol_file: "",
280 }
Inseob Kim42882742019-07-30 17:55:33 +0900281
282 java_library {
283 name: "sysprop-library-stub-platform",
284 sdk_version: "core_current",
285 }
286
287 java_library {
288 name: "sysprop-library-stub-vendor",
289 soc_specific: true,
290 sdk_version: "core_current",
291 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900292 `)
293
Inseob Kim42882742019-07-30 17:55:33 +0900294 // Check for generated cc_library
295 for _, variant := range []string{
Inseob Kim64c43952019-08-26 16:52:35 +0900296 "android_arm_armv7-a-neon_vendor.VER_shared",
297 "android_arm_armv7-a-neon_vendor.VER_static",
298 "android_arm64_armv8-a_vendor.VER_shared",
299 "android_arm64_armv8-a_vendor.VER_static",
Inseob Kim42882742019-07-30 17:55:33 +0900300 } {
301 ctx.ModuleForTests("libsysprop-platform", variant)
302 ctx.ModuleForTests("libsysprop-vendor", variant)
303 ctx.ModuleForTests("libsysprop-odm", variant)
304 }
305
Inseob Kimc0907f12019-02-08 21:00:45 +0900306 for _, variant := range []string{
Colin Cross7113d202019-11-20 16:39:12 -0800307 "android_arm_armv7-a-neon_shared",
308 "android_arm_armv7-a-neon_static",
309 "android_arm64_armv8-a_shared",
310 "android_arm64_armv8-a_static",
Inseob Kimc0907f12019-02-08 21:00:45 +0900311 } {
Inseob Kimc0907f12019-02-08 21:00:45 +0900312 ctx.ModuleForTests("libsysprop-platform", variant)
Inseob Kim42882742019-07-30 17:55:33 +0900313
314 // core variant of vendor-owned sysprop_library is for product
Inseob Kimc0907f12019-02-08 21:00:45 +0900315 ctx.ModuleForTests("libsysprop-vendor", variant)
316 }
317
318 ctx.ModuleForTests("sysprop-platform", "android_common")
Inseob Kimac1e9862019-12-09 18:15:47 +0900319 ctx.ModuleForTests("sysprop-platform_public", "android_common")
Inseob Kimc0907f12019-02-08 21:00:45 +0900320 ctx.ModuleForTests("sysprop-vendor", "android_common")
321
322 // Check for exported includes
Colin Cross7113d202019-11-20 16:39:12 -0800323 coreVariant := "android_arm64_armv8-a_static"
Inseob Kim64c43952019-08-26 16:52:35 +0900324 vendorVariant := "android_arm64_armv8-a_vendor.VER_static"
Inseob Kimc0907f12019-02-08 21:00:45 +0900325
Colin Cross7113d202019-11-20 16:39:12 -0800326 platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/include"
327 platformPublicCorePath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kim64c43952019-08-26 16:52:35 +0900328 platformPublicVendorPath := "libsysprop-platform/android_arm64_armv8-a_vendor.VER_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900329
Colin Cross7113d202019-11-20 16:39:12 -0800330 platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900331
Inseob Kim64c43952019-08-26 16:52:35 +0900332 vendorInternalPath := "libsysprop-vendor/android_arm64_armv8-a_vendor.VER_static/gen/sysprop/include"
Colin Cross7113d202019-11-20 16:39:12 -0800333 vendorPublicPath := "libsysprop-vendor/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900334
335 platformClient := ctx.ModuleForTests("cc-client-platform", coreVariant)
336 platformFlags := platformClient.Rule("cc").Args["cFlags"]
337
Jiyong Park5d1598f2019-02-25 22:14:17 +0900338 // platform should use platform's internal header
Inseob Kimc0907f12019-02-08 21:00:45 +0900339 if !strings.Contains(platformFlags, platformInternalPath) {
340 t.Errorf("flags for platform must contain %#v, but was %#v.",
341 platformInternalPath, platformFlags)
342 }
343
Jiyong Park5d1598f2019-02-25 22:14:17 +0900344 platformStaticClient := ctx.ModuleForTests("cc-client-platform-static", coreVariant)
345 platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"]
346
347 // platform-static should use platform's internal header
348 if !strings.Contains(platformStaticFlags, platformInternalPath) {
349 t.Errorf("flags for platform-static must contain %#v, but was %#v.",
350 platformInternalPath, platformStaticFlags)
351 }
352
Inseob Kimc0907f12019-02-08 21:00:45 +0900353 productClient := ctx.ModuleForTests("cc-client-product", coreVariant)
354 productFlags := productClient.Rule("cc").Args["cFlags"]
355
Inseob Kim5cefbd22019-06-08 20:36:59 +0900356 // Product should use platform's and vendor's public headers
Inseob Kimc0907f12019-02-08 21:00:45 +0900357 if !strings.Contains(productFlags, platformOnProductPath) ||
Inseob Kim5cefbd22019-06-08 20:36:59 +0900358 !strings.Contains(productFlags, vendorPublicPath) {
Inseob Kimc0907f12019-02-08 21:00:45 +0900359 t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900360 platformPublicCorePath, vendorPublicPath, productFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900361 }
362
363 vendorClient := ctx.ModuleForTests("cc-client-vendor", vendorVariant)
364 vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
365
Inseob Kim5cefbd22019-06-08 20:36:59 +0900366 // Vendor should use platform's public header and vendor's internal header
367 if !strings.Contains(vendorFlags, platformPublicVendorPath) ||
Inseob Kimc0907f12019-02-08 21:00:45 +0900368 !strings.Contains(vendorFlags, vendorInternalPath) {
369 t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900370 platformPublicVendorPath, vendorInternalPath, vendorFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900371 }
Inseob Kimac1e9862019-12-09 18:15:47 +0900372
373 // Java modules linking against system API should use public stub
374 javaSystemApiClient := ctx.ModuleForTests("java-platform", "android_common")
375 publicStubFound := false
376 ctx.VisitDirectDeps(javaSystemApiClient.Module(), func(dep blueprint.Module) {
377 if dep.Name() == "sysprop-platform_public" {
378 publicStubFound = true
379 }
380 })
381 if !publicStubFound {
382 t.Errorf("system api client should use public stub")
383 }
384
Inseob Kimc0907f12019-02-08 21:00:45 +0900385}