blob: 5cb9e64eeb3dd98a0d8abc19a73fca3aa1a17a16 [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
Colin Crossae8600b2020-10-29 17:09:13 -070060 ctx := android.NewTestArchContext(config)
Paul Duffinc059c8c2021-01-20 17:13:52 +000061 java.RegisterRequiredBuildComponentsForTest(ctx)
Paul Duffin43dc1cc2019-12-19 11:18:54 +000062
Inseob Kimc0907f12019-02-08 21:00:45 +090063 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Inseob Kim988f53c2019-09-16 15:59:01 +090064 ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
65 ctx.BottomUp("sysprop_deps", syspropDepsMutator).Parallel()
66 })
Inseob Kimc0907f12019-02-08 21:00:45 +090067
Paul Duffin021f4e52020-07-30 16:04:17 +010068 android.RegisterPrebuiltMutators(ctx)
69
Paul Duffin77980a82019-12-19 16:01:36 +000070 cc.RegisterRequiredBuildComponentsForTest(ctx)
Inseob Kimc0907f12019-02-08 21:00:45 +090071 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Inseob Kimac1e9862019-12-09 18:15:47 +090072 ctx.BottomUp("sysprop_java", java.SyspropMutator).Parallel()
Inseob Kimc0907f12019-02-08 21:00:45 +090073 })
74
Colin Cross4b49b762019-11-22 15:25:03 -080075 ctx.RegisterModuleType("sysprop_library", syspropLibraryFactory)
Inseob Kimc0907f12019-02-08 21:00:45 +090076
Colin Crossae8600b2020-10-29 17:09:13 -070077 ctx.Register()
Inseob Kimc0907f12019-02-08 21:00:45 +090078
Colin Cross98be1bb2019-12-13 20:41:13 -080079 return ctx
80}
81
82func run(t *testing.T, ctx *android.TestContext, config android.Config) {
83 t.Helper()
84 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
85 android.FailIfErrored(t, errs)
86 _, errs = ctx.PrepareBuildActions(config)
87 android.FailIfErrored(t, errs)
88}
89
90func testConfig(env map[string]string, bp string, fs map[string][]byte) android.Config {
Inseob Kimc0907f12019-02-08 21:00:45 +090091 bp += cc.GatherRequiredDepsForTest(android.Android)
92
93 mockFS := map[string][]byte{
Inseob Kim42882742019-07-30 17:55:33 +090094 "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,
Inseob Kimfe612182020-10-20 16:29:55 +0900104 "api/sysprop-vendor-on-product-current.txt": nil,
105 "api/sysprop-vendor-on-product-latest.txt": nil,
Inseob Kim42882742019-07-30 17:55:33 +0900106 "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",
Inseob Kimfe612182020-10-20 16:29:55 +0900185 vendor: true,
186 }
187
188 sysprop_library {
189 name: "sysprop-vendor-on-product",
190 srcs: ["com/android/VendorProperties.sysprop"],
191 api_packages: ["com.android"],
192 property_owner: "Vendor",
Inseob Kimc0907f12019-02-08 21:00:45 +0900193 product_specific: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900194 }
195
Inseob Kim42882742019-07-30 17:55:33 +0900196 sysprop_library {
197 name: "sysprop-odm",
198 srcs: ["com/android2/OdmProperties.sysprop"],
199 api_packages: ["com.android2"],
200 property_owner: "Odm",
201 device_specific: true,
202 }
203
Inseob Kimc0907f12019-02-08 21:00:45 +0900204 java_library {
205 name: "java-platform",
206 srcs: ["c.java"],
207 sdk_version: "system_current",
208 libs: ["sysprop-platform"],
209 }
210
211 java_library {
Inseob Kimac1e9862019-12-09 18:15:47 +0900212 name: "java-platform-private",
213 srcs: ["c.java"],
214 platform_apis: true,
215 libs: ["sysprop-platform"],
216 }
217
218 java_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900219 name: "java-product",
220 srcs: ["c.java"],
221 sdk_version: "system_current",
222 product_specific: true,
Inseob Kimfe612182020-10-20 16:29:55 +0900223 libs: ["sysprop-platform", "sysprop-vendor-on-product"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900224 }
225
226 java_library {
227 name: "java-vendor",
228 srcs: ["c.java"],
229 sdk_version: "system_current",
230 soc_specific: true,
231 libs: ["sysprop-platform", "sysprop-vendor"],
232 }
233
234 cc_library {
235 name: "cc-client-platform",
236 srcs: ["d.cpp"],
237 static_libs: ["sysprop-platform"],
238 }
239
Jiyong Park5d1598f2019-02-25 22:14:17 +0900240 cc_library_static {
241 name: "cc-client-platform-static",
242 srcs: ["d.cpp"],
243 whole_static_libs: ["sysprop-platform"],
244 }
245
Inseob Kimc0907f12019-02-08 21:00:45 +0900246 cc_library {
247 name: "cc-client-product",
248 srcs: ["d.cpp"],
249 product_specific: true,
Inseob Kimfe612182020-10-20 16:29:55 +0900250 static_libs: ["sysprop-platform-on-product", "sysprop-vendor-on-product"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900251 }
252
253 cc_library {
254 name: "cc-client-vendor",
255 srcs: ["d.cpp"],
256 soc_specific: true,
257 static_libs: ["sysprop-platform", "sysprop-vendor"],
258 }
Inseob Kim1f959762019-03-27 17:20:37 +0900259
Inseob Kim89db15d2020-02-03 18:06:46 +0900260 cc_library {
261 name: "libbase",
262 host_supported: true,
263 }
264
Inseob Kim1f959762019-03-27 17:20:37 +0900265 cc_library_headers {
266 name: "libbase_headers",
267 vendor_available: true,
268 recovery_available: true,
269 }
270
271 cc_library {
272 name: "liblog",
Yi Konge7fe9912019-06-02 00:53:50 -0700273 no_libcrt: true,
Inseob Kim1f959762019-03-27 17:20:37 +0900274 nocrt: true,
275 system_shared_libs: [],
276 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900277 host_supported: true,
Colin Cross0477b422020-10-13 18:43:54 -0700278 llndk_stubs: "liblog.llndk",
Inseob Kim89db15d2020-02-03 18:06:46 +0900279 }
280
281 cc_binary_host {
282 name: "hostbin",
283 static_libs: ["sysprop-platform"],
Inseob Kim1f959762019-03-27 17:20:37 +0900284 }
285
286 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -0700287 name: "liblog.llndk",
Inseob Kim1f959762019-03-27 17:20:37 +0900288 symbol_file: "",
289 }
Inseob Kim42882742019-07-30 17:55:33 +0900290
291 java_library {
292 name: "sysprop-library-stub-platform",
293 sdk_version: "core_current",
294 }
295
296 java_library {
297 name: "sysprop-library-stub-vendor",
298 soc_specific: true,
299 sdk_version: "core_current",
300 }
Inseob Kimfe612182020-10-20 16:29:55 +0900301
302 java_library {
303 name: "sysprop-library-stub-product",
304 product_specific: true,
305 sdk_version: "core_current",
306 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900307 `)
308
Inseob Kim42882742019-07-30 17:55:33 +0900309 // Check for generated cc_library
310 for _, variant := range []string{
Colin Crossfb0c16e2019-11-20 17:12:35 -0800311 "android_vendor.VER_arm_armv7-a-neon_shared",
312 "android_vendor.VER_arm_armv7-a-neon_static",
313 "android_vendor.VER_arm64_armv8-a_shared",
314 "android_vendor.VER_arm64_armv8-a_static",
Inseob Kim42882742019-07-30 17:55:33 +0900315 } {
316 ctx.ModuleForTests("libsysprop-platform", variant)
317 ctx.ModuleForTests("libsysprop-vendor", variant)
318 ctx.ModuleForTests("libsysprop-odm", variant)
319 }
320
Inseob Kimc0907f12019-02-08 21:00:45 +0900321 for _, variant := range []string{
Colin Cross7113d202019-11-20 16:39:12 -0800322 "android_arm_armv7-a-neon_shared",
323 "android_arm_armv7-a-neon_static",
324 "android_arm64_armv8-a_shared",
325 "android_arm64_armv8-a_static",
Inseob Kimc0907f12019-02-08 21:00:45 +0900326 } {
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100327 library := ctx.ModuleForTests("libsysprop-platform", variant).Module().(*cc.Module)
328 expectedApexAvailableOnLibrary := []string{"//apex_available:platform"}
329 if !reflect.DeepEqual(library.ApexProperties.Apex_available, expectedApexAvailableOnLibrary) {
330 t.Errorf("apex available property on libsysprop-platform must be %#v, but was %#v.",
331 expectedApexAvailableOnLibrary, library.ApexProperties.Apex_available)
332 }
Inseob Kim42882742019-07-30 17:55:33 +0900333
Inseob Kimfe612182020-10-20 16:29:55 +0900334 // product variant of vendor-owned sysprop_library
335 ctx.ModuleForTests("libsysprop-vendor-on-product", variant)
Inseob Kimc0907f12019-02-08 21:00:45 +0900336 }
337
338 ctx.ModuleForTests("sysprop-platform", "android_common")
Inseob Kimac1e9862019-12-09 18:15:47 +0900339 ctx.ModuleForTests("sysprop-platform_public", "android_common")
Inseob Kimc0907f12019-02-08 21:00:45 +0900340 ctx.ModuleForTests("sysprop-vendor", "android_common")
Inseob Kimfe612182020-10-20 16:29:55 +0900341 ctx.ModuleForTests("sysprop-vendor-on-product", "android_common")
Inseob Kimc0907f12019-02-08 21:00:45 +0900342
343 // Check for exported includes
Colin Cross7113d202019-11-20 16:39:12 -0800344 coreVariant := "android_arm64_armv8-a_static"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800345 vendorVariant := "android_vendor.VER_arm64_armv8-a_static"
Inseob Kimc0907f12019-02-08 21:00:45 +0900346
Colin Cross7113d202019-11-20 16:39:12 -0800347 platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/include"
348 platformPublicCorePath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/public/include"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800349 platformPublicVendorPath := "libsysprop-platform/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900350
Colin Cross7113d202019-11-20 16:39:12 -0800351 platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900352
Colin Crossfb0c16e2019-11-20 17:12:35 -0800353 vendorInternalPath := "libsysprop-vendor/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/include"
Inseob Kimfe612182020-10-20 16:29:55 +0900354 vendorPublicPath := "libsysprop-vendor-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900355
356 platformClient := ctx.ModuleForTests("cc-client-platform", coreVariant)
357 platformFlags := platformClient.Rule("cc").Args["cFlags"]
358
Jiyong Park5d1598f2019-02-25 22:14:17 +0900359 // platform should use platform's internal header
Inseob Kimc0907f12019-02-08 21:00:45 +0900360 if !strings.Contains(platformFlags, platformInternalPath) {
361 t.Errorf("flags for platform must contain %#v, but was %#v.",
362 platformInternalPath, platformFlags)
363 }
364
Jiyong Park5d1598f2019-02-25 22:14:17 +0900365 platformStaticClient := ctx.ModuleForTests("cc-client-platform-static", coreVariant)
366 platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"]
367
368 // platform-static should use platform's internal header
369 if !strings.Contains(platformStaticFlags, platformInternalPath) {
370 t.Errorf("flags for platform-static must contain %#v, but was %#v.",
371 platformInternalPath, platformStaticFlags)
372 }
373
Inseob Kimc0907f12019-02-08 21:00:45 +0900374 productClient := ctx.ModuleForTests("cc-client-product", coreVariant)
375 productFlags := productClient.Rule("cc").Args["cFlags"]
376
Inseob Kim5cefbd22019-06-08 20:36:59 +0900377 // Product should use platform's and vendor's public headers
Inseob Kimc0907f12019-02-08 21:00:45 +0900378 if !strings.Contains(productFlags, platformOnProductPath) ||
Inseob Kim5cefbd22019-06-08 20:36:59 +0900379 !strings.Contains(productFlags, vendorPublicPath) {
Inseob Kimc0907f12019-02-08 21:00:45 +0900380 t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900381 platformPublicCorePath, vendorPublicPath, productFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900382 }
383
384 vendorClient := ctx.ModuleForTests("cc-client-vendor", vendorVariant)
385 vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
386
Inseob Kim5cefbd22019-06-08 20:36:59 +0900387 // Vendor should use platform's public header and vendor's internal header
388 if !strings.Contains(vendorFlags, platformPublicVendorPath) ||
Inseob Kimc0907f12019-02-08 21:00:45 +0900389 !strings.Contains(vendorFlags, vendorInternalPath) {
390 t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900391 platformPublicVendorPath, vendorInternalPath, vendorFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900392 }
Inseob Kimac1e9862019-12-09 18:15:47 +0900393
394 // Java modules linking against system API should use public stub
395 javaSystemApiClient := ctx.ModuleForTests("java-platform", "android_common")
396 publicStubFound := false
397 ctx.VisitDirectDeps(javaSystemApiClient.Module(), func(dep blueprint.Module) {
398 if dep.Name() == "sysprop-platform_public" {
399 publicStubFound = true
400 }
401 })
402 if !publicStubFound {
403 t.Errorf("system api client should use public stub")
404 }
405
Inseob Kimc0907f12019-02-08 21:00:45 +0900406}