blob: c8b16cb62f03025fc1049ff52f9757a5047d2e7e [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 (
Paul Duffin7b3de8f2020-03-30 18:00:25 +010018 "reflect"
19
Inseob Kimc0907f12019-02-08 21:00:45 +090020 "android/soong/android"
21 "android/soong/cc"
22 "android/soong/java"
23
Inseob Kimc0907f12019-02-08 21:00:45 +090024 "io/ioutil"
25 "os"
26 "strings"
27 "testing"
28
Inseob Kimac1e9862019-12-09 18:15:47 +090029 "github.com/google/blueprint"
Inseob Kimc0907f12019-02-08 21:00:45 +090030 "github.com/google/blueprint/proptools"
31)
32
33var buildDir string
34
35func setUp() {
36 var err error
37 buildDir, err = ioutil.TempDir("", "soong_sysprop_test")
38 if err != nil {
39 panic(err)
40 }
41}
42
43func tearDown() {
44 os.RemoveAll(buildDir)
45}
46
47func TestMain(m *testing.M) {
48 run := func() int {
49 setUp()
50 defer tearDown()
51
52 return m.Run()
53 }
54
55 os.Exit(run())
56}
57
Colin Cross98be1bb2019-12-13 20:41:13 -080058func testContext(config android.Config) *android.TestContext {
Inseob Kimc0907f12019-02-08 21:00:45 +090059
60 ctx := android.NewTestArchContext()
Paul Duffinf9b1da02019-12-18 19:51:55 +000061 java.RegisterJavaBuildComponents(ctx)
62 java.RegisterAppBuildComponents(ctx)
Paul Duffin43dc1cc2019-12-19 11:18:54 +000063 java.RegisterSystemModulesBuildComponents(ctx)
64
Inseob Kimc0907f12019-02-08 21:00:45 +090065 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
Paul Duffin021f4e52020-07-30 16:04:17 +010070 android.RegisterPrebuiltMutators(ctx)
71
Paul Duffin77980a82019-12-19 16:01:36 +000072 cc.RegisterRequiredBuildComponentsForTest(ctx)
Inseob Kimc0907f12019-02-08 21:00:45 +090073 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Inseob Kimac1e9862019-12-09 18:15:47 +090074 ctx.BottomUp("sysprop_java", java.SyspropMutator).Parallel()
Inseob Kimc0907f12019-02-08 21:00:45 +090075 })
76
Colin Cross4b49b762019-11-22 15:25:03 -080077 ctx.RegisterModuleType("sysprop_library", syspropLibraryFactory)
Inseob Kimc0907f12019-02-08 21:00:45 +090078
Colin Cross98be1bb2019-12-13 20:41:13 -080079 ctx.Register(config)
Inseob Kimc0907f12019-02-08 21:00:45 +090080
Colin Cross98be1bb2019-12-13 20:41:13 -080081 return ctx
82}
83
84func run(t *testing.T, ctx *android.TestContext, config android.Config) {
85 t.Helper()
86 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
87 android.FailIfErrored(t, errs)
88 _, errs = ctx.PrepareBuildActions(config)
89 android.FailIfErrored(t, errs)
90}
91
92func testConfig(env map[string]string, bp string, fs map[string][]byte) android.Config {
Inseob Kimc0907f12019-02-08 21:00:45 +090093 bp += cc.GatherRequiredDepsForTest(android.Android)
94
95 mockFS := map[string][]byte{
Inseob Kim42882742019-07-30 17:55:33 +090096 "a.java": nil,
97 "b.java": nil,
98 "c.java": nil,
99 "d.cpp": nil,
100 "api/sysprop-platform-current.txt": nil,
101 "api/sysprop-platform-latest.txt": nil,
102 "api/sysprop-platform-on-product-current.txt": nil,
103 "api/sysprop-platform-on-product-latest.txt": nil,
104 "api/sysprop-vendor-current.txt": nil,
105 "api/sysprop-vendor-latest.txt": nil,
106 "api/sysprop-odm-current.txt": nil,
107 "api/sysprop-odm-latest.txt": nil,
108 "framework/aidl/a.aidl": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900109
110 // For framework-res, which is an implicit dependency for framework
Dan Willemsen412160e2019-04-09 21:36:26 -0700111 "AndroidManifest.xml": nil,
112 "build/make/target/product/security/testkey": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900113
114 "build/soong/scripts/jar-wrapper.sh": nil,
115
116 "build/make/core/proguard.flags": nil,
117 "build/make/core/proguard_basic_keeps.flags": nil,
118
119 "jdk8/jre/lib/jce.jar": nil,
120 "jdk8/jre/lib/rt.jar": nil,
121 "jdk8/lib/tools.jar": nil,
122
123 "bar-doc/a.java": nil,
124 "bar-doc/b.java": nil,
125 "bar-doc/IFoo.aidl": nil,
126 "bar-doc/known_oj_tags.txt": nil,
127 "external/doclava/templates-sdk": nil,
128
129 "cert/new_cert.x509.pem": nil,
130 "cert/new_cert.pk8": nil,
131
132 "android/sysprop/PlatformProperties.sysprop": nil,
133 "com/android/VendorProperties.sysprop": nil,
Inseob Kim42882742019-07-30 17:55:33 +0900134 "com/android2/OdmProperties.sysprop": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900135 }
136
137 for k, v := range fs {
138 mockFS[k] = v
139 }
140
Colin Cross98be1bb2019-12-13 20:41:13 -0800141 config := java.TestConfig(buildDir, env, bp, mockFS)
Colin Crosse4759b92019-02-15 10:37:39 -0800142
Inseob Kimc0907f12019-02-08 21:00:45 +0900143 config.TestProductVariables.DeviceSystemSdkVersions = []string{"28"}
144 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
145 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
Colin Crosse4759b92019-02-15 10:37:39 -0800146
Inseob Kimc0907f12019-02-08 21:00:45 +0900147 return config
148
149}
150
151func test(t *testing.T, bp string) *android.TestContext {
152 t.Helper()
Colin Cross98be1bb2019-12-13 20:41:13 -0800153 config := testConfig(nil, bp, nil)
154 ctx := testContext(config)
Inseob Kimc0907f12019-02-08 21:00:45 +0900155 run(t, ctx, config)
156
157 return ctx
158}
159
160func TestSyspropLibrary(t *testing.T) {
161 ctx := test(t, `
162 sysprop_library {
163 name: "sysprop-platform",
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100164 apex_available: ["//apex_available:platform"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900165 srcs: ["android/sysprop/PlatformProperties.sysprop"],
166 api_packages: ["android.sysprop"],
167 property_owner: "Platform",
168 vendor_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900169 host_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900170 }
171
172 sysprop_library {
173 name: "sysprop-platform-on-product",
174 srcs: ["android/sysprop/PlatformProperties.sysprop"],
175 api_packages: ["android.sysprop"],
176 property_owner: "Platform",
177 product_specific: true,
178 }
179
180 sysprop_library {
181 name: "sysprop-vendor",
182 srcs: ["com/android/VendorProperties.sysprop"],
183 api_packages: ["com.android"],
184 property_owner: "Vendor",
185 product_specific: true,
186 vendor_available: true,
187 }
188
Inseob Kim42882742019-07-30 17:55:33 +0900189 sysprop_library {
190 name: "sysprop-odm",
191 srcs: ["com/android2/OdmProperties.sysprop"],
192 api_packages: ["com.android2"],
193 property_owner: "Odm",
194 device_specific: true,
195 }
196
Inseob Kimc0907f12019-02-08 21:00:45 +0900197 java_library {
198 name: "java-platform",
199 srcs: ["c.java"],
200 sdk_version: "system_current",
201 libs: ["sysprop-platform"],
202 }
203
204 java_library {
Inseob Kimac1e9862019-12-09 18:15:47 +0900205 name: "java-platform-private",
206 srcs: ["c.java"],
207 platform_apis: true,
208 libs: ["sysprop-platform"],
209 }
210
211 java_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900212 name: "java-product",
213 srcs: ["c.java"],
214 sdk_version: "system_current",
215 product_specific: true,
216 libs: ["sysprop-platform", "sysprop-vendor"],
217 }
218
219 java_library {
220 name: "java-vendor",
221 srcs: ["c.java"],
222 sdk_version: "system_current",
223 soc_specific: true,
224 libs: ["sysprop-platform", "sysprop-vendor"],
225 }
226
227 cc_library {
228 name: "cc-client-platform",
229 srcs: ["d.cpp"],
230 static_libs: ["sysprop-platform"],
231 }
232
Jiyong Park5d1598f2019-02-25 22:14:17 +0900233 cc_library_static {
234 name: "cc-client-platform-static",
235 srcs: ["d.cpp"],
236 whole_static_libs: ["sysprop-platform"],
237 }
238
Inseob Kimc0907f12019-02-08 21:00:45 +0900239 cc_library {
240 name: "cc-client-product",
241 srcs: ["d.cpp"],
242 product_specific: true,
243 static_libs: ["sysprop-platform-on-product", "sysprop-vendor"],
244 }
245
246 cc_library {
247 name: "cc-client-vendor",
248 srcs: ["d.cpp"],
249 soc_specific: true,
250 static_libs: ["sysprop-platform", "sysprop-vendor"],
251 }
Inseob Kim1f959762019-03-27 17:20:37 +0900252
Inseob Kim89db15d2020-02-03 18:06:46 +0900253 cc_library {
254 name: "libbase",
255 host_supported: true,
256 }
257
Inseob Kim1f959762019-03-27 17:20:37 +0900258 cc_library_headers {
259 name: "libbase_headers",
260 vendor_available: true,
261 recovery_available: true,
262 }
263
264 cc_library {
265 name: "liblog",
Yi Konge7fe9912019-06-02 00:53:50 -0700266 no_libcrt: true,
Inseob Kim1f959762019-03-27 17:20:37 +0900267 nocrt: true,
268 system_shared_libs: [],
269 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900270 host_supported: true,
Colin Cross0477b422020-10-13 18:43:54 -0700271 llndk_stubs: "liblog.llndk",
Inseob Kim89db15d2020-02-03 18:06:46 +0900272 }
273
274 cc_binary_host {
275 name: "hostbin",
276 static_libs: ["sysprop-platform"],
Inseob Kim1f959762019-03-27 17:20:37 +0900277 }
278
279 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -0700280 name: "liblog.llndk",
Inseob Kim1f959762019-03-27 17:20:37 +0900281 symbol_file: "",
282 }
Inseob Kim42882742019-07-30 17:55:33 +0900283
284 java_library {
285 name: "sysprop-library-stub-platform",
286 sdk_version: "core_current",
287 }
288
289 java_library {
290 name: "sysprop-library-stub-vendor",
291 soc_specific: true,
292 sdk_version: "core_current",
293 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900294 `)
295
Inseob Kim42882742019-07-30 17:55:33 +0900296 // Check for generated cc_library
297 for _, variant := range []string{
Colin Crossfb0c16e2019-11-20 17:12:35 -0800298 "android_vendor.VER_arm_armv7-a-neon_shared",
299 "android_vendor.VER_arm_armv7-a-neon_static",
300 "android_vendor.VER_arm64_armv8-a_shared",
301 "android_vendor.VER_arm64_armv8-a_static",
Inseob Kim42882742019-07-30 17:55:33 +0900302 } {
303 ctx.ModuleForTests("libsysprop-platform", variant)
304 ctx.ModuleForTests("libsysprop-vendor", variant)
305 ctx.ModuleForTests("libsysprop-odm", variant)
306 }
307
Inseob Kimc0907f12019-02-08 21:00:45 +0900308 for _, variant := range []string{
Colin Cross7113d202019-11-20 16:39:12 -0800309 "android_arm_armv7-a-neon_shared",
310 "android_arm_armv7-a-neon_static",
311 "android_arm64_armv8-a_shared",
312 "android_arm64_armv8-a_static",
Inseob Kimc0907f12019-02-08 21:00:45 +0900313 } {
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100314 library := ctx.ModuleForTests("libsysprop-platform", variant).Module().(*cc.Module)
315 expectedApexAvailableOnLibrary := []string{"//apex_available:platform"}
316 if !reflect.DeepEqual(library.ApexProperties.Apex_available, expectedApexAvailableOnLibrary) {
317 t.Errorf("apex available property on libsysprop-platform must be %#v, but was %#v.",
318 expectedApexAvailableOnLibrary, library.ApexProperties.Apex_available)
319 }
Inseob Kim42882742019-07-30 17:55:33 +0900320
321 // core variant of vendor-owned sysprop_library is for product
Inseob Kimc0907f12019-02-08 21:00:45 +0900322 ctx.ModuleForTests("libsysprop-vendor", variant)
323 }
324
325 ctx.ModuleForTests("sysprop-platform", "android_common")
Inseob Kimac1e9862019-12-09 18:15:47 +0900326 ctx.ModuleForTests("sysprop-platform_public", "android_common")
Inseob Kimc0907f12019-02-08 21:00:45 +0900327 ctx.ModuleForTests("sysprop-vendor", "android_common")
328
329 // Check for exported includes
Colin Cross7113d202019-11-20 16:39:12 -0800330 coreVariant := "android_arm64_armv8-a_static"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800331 vendorVariant := "android_vendor.VER_arm64_armv8-a_static"
Inseob Kimc0907f12019-02-08 21:00:45 +0900332
Colin Cross7113d202019-11-20 16:39:12 -0800333 platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/include"
334 platformPublicCorePath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/public/include"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800335 platformPublicVendorPath := "libsysprop-platform/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900336
Colin Cross7113d202019-11-20 16:39:12 -0800337 platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900338
Colin Crossfb0c16e2019-11-20 17:12:35 -0800339 vendorInternalPath := "libsysprop-vendor/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/include"
Colin Cross7113d202019-11-20 16:39:12 -0800340 vendorPublicPath := "libsysprop-vendor/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900341
342 platformClient := ctx.ModuleForTests("cc-client-platform", coreVariant)
343 platformFlags := platformClient.Rule("cc").Args["cFlags"]
344
Jiyong Park5d1598f2019-02-25 22:14:17 +0900345 // platform should use platform's internal header
Inseob Kimc0907f12019-02-08 21:00:45 +0900346 if !strings.Contains(platformFlags, platformInternalPath) {
347 t.Errorf("flags for platform must contain %#v, but was %#v.",
348 platformInternalPath, platformFlags)
349 }
350
Jiyong Park5d1598f2019-02-25 22:14:17 +0900351 platformStaticClient := ctx.ModuleForTests("cc-client-platform-static", coreVariant)
352 platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"]
353
354 // platform-static should use platform's internal header
355 if !strings.Contains(platformStaticFlags, platformInternalPath) {
356 t.Errorf("flags for platform-static must contain %#v, but was %#v.",
357 platformInternalPath, platformStaticFlags)
358 }
359
Inseob Kimc0907f12019-02-08 21:00:45 +0900360 productClient := ctx.ModuleForTests("cc-client-product", coreVariant)
361 productFlags := productClient.Rule("cc").Args["cFlags"]
362
Inseob Kim5cefbd22019-06-08 20:36:59 +0900363 // Product should use platform's and vendor's public headers
Inseob Kimc0907f12019-02-08 21:00:45 +0900364 if !strings.Contains(productFlags, platformOnProductPath) ||
Inseob Kim5cefbd22019-06-08 20:36:59 +0900365 !strings.Contains(productFlags, vendorPublicPath) {
Inseob Kimc0907f12019-02-08 21:00:45 +0900366 t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900367 platformPublicCorePath, vendorPublicPath, productFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900368 }
369
370 vendorClient := ctx.ModuleForTests("cc-client-vendor", vendorVariant)
371 vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
372
Inseob Kim5cefbd22019-06-08 20:36:59 +0900373 // Vendor should use platform's public header and vendor's internal header
374 if !strings.Contains(vendorFlags, platformPublicVendorPath) ||
Inseob Kimc0907f12019-02-08 21:00:45 +0900375 !strings.Contains(vendorFlags, vendorInternalPath) {
376 t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900377 platformPublicVendorPath, vendorInternalPath, vendorFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900378 }
Inseob Kimac1e9862019-12-09 18:15:47 +0900379
380 // Java modules linking against system API should use public stub
381 javaSystemApiClient := ctx.ModuleForTests("java-platform", "android_common")
382 publicStubFound := false
383 ctx.VisitDirectDeps(javaSystemApiClient.Module(), func(dep blueprint.Module) {
384 if dep.Name() == "sysprop-platform_public" {
385 publicStubFound = true
386 }
387 })
388 if !publicStubFound {
389 t.Errorf("system api client should use public stub")
390 }
391
Inseob Kimc0907f12019-02-08 21:00:45 +0900392}