blob: 9d914e3175e094b2698c1ece08bb81263e1b30d1 [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
29 "github.com/google/blueprint/proptools"
30)
31
32var buildDir string
33
34func setUp() {
35 var err error
36 buildDir, err = ioutil.TempDir("", "soong_sysprop_test")
37 if err != nil {
38 panic(err)
39 }
40}
41
42func tearDown() {
43 os.RemoveAll(buildDir)
44}
45
46func TestMain(m *testing.M) {
47 run := func() int {
48 setUp()
49 defer tearDown()
50
51 return m.Run()
52 }
53
54 os.Exit(run())
55}
56
Colin Cross98be1bb2019-12-13 20:41:13 -080057func testContext(config android.Config) *android.TestContext {
Inseob Kimc0907f12019-02-08 21:00:45 +090058
Colin Crossae8600b2020-10-29 17:09:13 -070059 ctx := android.NewTestArchContext(config)
Paul Duffinc059c8c2021-01-20 17:13:52 +000060 java.RegisterRequiredBuildComponentsForTest(ctx)
Paul Duffin43dc1cc2019-12-19 11:18:54 +000061
Inseob Kimc0907f12019-02-08 21:00:45 +090062 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Inseob Kimc0907f12019-02-08 21:00:45 +090063
Paul Duffin021f4e52020-07-30 16:04:17 +010064 android.RegisterPrebuiltMutators(ctx)
65
Paul Duffin77980a82019-12-19 16:01:36 +000066 cc.RegisterRequiredBuildComponentsForTest(ctx)
Inseob Kimc0907f12019-02-08 21:00:45 +090067
Colin Cross4b49b762019-11-22 15:25:03 -080068 ctx.RegisterModuleType("sysprop_library", syspropLibraryFactory)
Inseob Kimc0907f12019-02-08 21:00:45 +090069
Colin Crossae8600b2020-10-29 17:09:13 -070070 ctx.Register()
Inseob Kimc0907f12019-02-08 21:00:45 +090071
Colin Cross98be1bb2019-12-13 20:41:13 -080072 return ctx
73}
74
75func run(t *testing.T, ctx *android.TestContext, config android.Config) {
76 t.Helper()
77 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
78 android.FailIfErrored(t, errs)
79 _, errs = ctx.PrepareBuildActions(config)
80 android.FailIfErrored(t, errs)
81}
82
83func testConfig(env map[string]string, bp string, fs map[string][]byte) android.Config {
Inseob Kimc0907f12019-02-08 21:00:45 +090084 bp += cc.GatherRequiredDepsForTest(android.Android)
85
86 mockFS := map[string][]byte{
Inseob Kim42882742019-07-30 17:55:33 +090087 "a.java": nil,
88 "b.java": nil,
89 "c.java": nil,
90 "d.cpp": nil,
91 "api/sysprop-platform-current.txt": nil,
92 "api/sysprop-platform-latest.txt": nil,
93 "api/sysprop-platform-on-product-current.txt": nil,
94 "api/sysprop-platform-on-product-latest.txt": nil,
95 "api/sysprop-vendor-current.txt": nil,
96 "api/sysprop-vendor-latest.txt": nil,
Inseob Kimfe612182020-10-20 16:29:55 +090097 "api/sysprop-vendor-on-product-current.txt": nil,
98 "api/sysprop-vendor-on-product-latest.txt": nil,
Inseob Kim42882742019-07-30 17:55:33 +090099 "api/sysprop-odm-current.txt": nil,
100 "api/sysprop-odm-latest.txt": nil,
101 "framework/aidl/a.aidl": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900102
103 // For framework-res, which is an implicit dependency for framework
Dan Willemsen412160e2019-04-09 21:36:26 -0700104 "AndroidManifest.xml": nil,
105 "build/make/target/product/security/testkey": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900106
107 "build/soong/scripts/jar-wrapper.sh": nil,
108
109 "build/make/core/proguard.flags": nil,
110 "build/make/core/proguard_basic_keeps.flags": nil,
111
112 "jdk8/jre/lib/jce.jar": nil,
113 "jdk8/jre/lib/rt.jar": nil,
114 "jdk8/lib/tools.jar": nil,
115
116 "bar-doc/a.java": nil,
117 "bar-doc/b.java": nil,
118 "bar-doc/IFoo.aidl": nil,
119 "bar-doc/known_oj_tags.txt": nil,
120 "external/doclava/templates-sdk": nil,
121
122 "cert/new_cert.x509.pem": nil,
123 "cert/new_cert.pk8": nil,
124
125 "android/sysprop/PlatformProperties.sysprop": nil,
126 "com/android/VendorProperties.sysprop": nil,
Inseob Kim42882742019-07-30 17:55:33 +0900127 "com/android2/OdmProperties.sysprop": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900128 }
129
130 for k, v := range fs {
131 mockFS[k] = v
132 }
133
Colin Cross98be1bb2019-12-13 20:41:13 -0800134 config := java.TestConfig(buildDir, env, bp, mockFS)
Colin Crosse4759b92019-02-15 10:37:39 -0800135
Inseob Kimc0907f12019-02-08 21:00:45 +0900136 config.TestProductVariables.DeviceSystemSdkVersions = []string{"28"}
137 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
138 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
Colin Crosse4759b92019-02-15 10:37:39 -0800139
Inseob Kimc0907f12019-02-08 21:00:45 +0900140 return config
141
142}
143
144func test(t *testing.T, bp string) *android.TestContext {
145 t.Helper()
Colin Cross98be1bb2019-12-13 20:41:13 -0800146 config := testConfig(nil, bp, nil)
147 ctx := testContext(config)
Inseob Kimc0907f12019-02-08 21:00:45 +0900148 run(t, ctx, config)
149
150 return ctx
151}
152
153func TestSyspropLibrary(t *testing.T) {
154 ctx := test(t, `
155 sysprop_library {
156 name: "sysprop-platform",
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100157 apex_available: ["//apex_available:platform"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900158 srcs: ["android/sysprop/PlatformProperties.sysprop"],
159 api_packages: ["android.sysprop"],
160 property_owner: "Platform",
161 vendor_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900162 host_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900163 }
164
165 sysprop_library {
166 name: "sysprop-platform-on-product",
167 srcs: ["android/sysprop/PlatformProperties.sysprop"],
168 api_packages: ["android.sysprop"],
169 property_owner: "Platform",
170 product_specific: true,
171 }
172
173 sysprop_library {
174 name: "sysprop-vendor",
175 srcs: ["com/android/VendorProperties.sysprop"],
176 api_packages: ["com.android"],
177 property_owner: "Vendor",
Inseob Kimfe612182020-10-20 16:29:55 +0900178 vendor: true,
179 }
180
181 sysprop_library {
182 name: "sysprop-vendor-on-product",
183 srcs: ["com/android/VendorProperties.sysprop"],
184 api_packages: ["com.android"],
185 property_owner: "Vendor",
Inseob Kimc0907f12019-02-08 21:00:45 +0900186 product_specific: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900187 }
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,
Inseob Kimfe612182020-10-20 16:29:55 +0900216 libs: ["sysprop-platform", "sysprop-vendor-on-product"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900217 }
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,
Inseob Kimfe612182020-10-20 16:29:55 +0900243 static_libs: ["sysprop-platform-on-product", "sysprop-vendor-on-product"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900244 }
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 Kimfe612182020-10-20 16:29:55 +0900294
295 java_library {
296 name: "sysprop-library-stub-product",
297 product_specific: true,
298 sdk_version: "core_current",
299 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900300 `)
301
Inseob Kim42882742019-07-30 17:55:33 +0900302 // Check for generated cc_library
303 for _, variant := range []string{
Colin Crossfb0c16e2019-11-20 17:12:35 -0800304 "android_vendor.VER_arm_armv7-a-neon_shared",
305 "android_vendor.VER_arm_armv7-a-neon_static",
306 "android_vendor.VER_arm64_armv8-a_shared",
307 "android_vendor.VER_arm64_armv8-a_static",
Inseob Kim42882742019-07-30 17:55:33 +0900308 } {
309 ctx.ModuleForTests("libsysprop-platform", variant)
310 ctx.ModuleForTests("libsysprop-vendor", variant)
311 ctx.ModuleForTests("libsysprop-odm", variant)
312 }
313
Inseob Kimc0907f12019-02-08 21:00:45 +0900314 for _, variant := range []string{
Colin Cross7113d202019-11-20 16:39:12 -0800315 "android_arm_armv7-a-neon_shared",
316 "android_arm_armv7-a-neon_static",
317 "android_arm64_armv8-a_shared",
318 "android_arm64_armv8-a_static",
Inseob Kimc0907f12019-02-08 21:00:45 +0900319 } {
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100320 library := ctx.ModuleForTests("libsysprop-platform", variant).Module().(*cc.Module)
321 expectedApexAvailableOnLibrary := []string{"//apex_available:platform"}
322 if !reflect.DeepEqual(library.ApexProperties.Apex_available, expectedApexAvailableOnLibrary) {
323 t.Errorf("apex available property on libsysprop-platform must be %#v, but was %#v.",
324 expectedApexAvailableOnLibrary, library.ApexProperties.Apex_available)
325 }
Inseob Kim42882742019-07-30 17:55:33 +0900326
Inseob Kimfe612182020-10-20 16:29:55 +0900327 // product variant of vendor-owned sysprop_library
328 ctx.ModuleForTests("libsysprop-vendor-on-product", variant)
Inseob Kimc0907f12019-02-08 21:00:45 +0900329 }
330
331 ctx.ModuleForTests("sysprop-platform", "android_common")
Inseob Kimac1e9862019-12-09 18:15:47 +0900332 ctx.ModuleForTests("sysprop-platform_public", "android_common")
Inseob Kimc0907f12019-02-08 21:00:45 +0900333 ctx.ModuleForTests("sysprop-vendor", "android_common")
Inseob Kimfe612182020-10-20 16:29:55 +0900334 ctx.ModuleForTests("sysprop-vendor-on-product", "android_common")
Inseob Kimc0907f12019-02-08 21:00:45 +0900335
336 // Check for exported includes
Colin Cross7113d202019-11-20 16:39:12 -0800337 coreVariant := "android_arm64_armv8-a_static"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800338 vendorVariant := "android_vendor.VER_arm64_armv8-a_static"
Inseob Kimc0907f12019-02-08 21:00:45 +0900339
Colin Cross7113d202019-11-20 16:39:12 -0800340 platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/include"
341 platformPublicCorePath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/public/include"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800342 platformPublicVendorPath := "libsysprop-platform/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900343
Colin Cross7113d202019-11-20 16:39:12 -0800344 platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900345
Colin Crossfb0c16e2019-11-20 17:12:35 -0800346 vendorInternalPath := "libsysprop-vendor/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/include"
Inseob Kimfe612182020-10-20 16:29:55 +0900347 vendorPublicPath := "libsysprop-vendor-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900348
349 platformClient := ctx.ModuleForTests("cc-client-platform", coreVariant)
350 platformFlags := platformClient.Rule("cc").Args["cFlags"]
351
Jiyong Park5d1598f2019-02-25 22:14:17 +0900352 // platform should use platform's internal header
Inseob Kimc0907f12019-02-08 21:00:45 +0900353 if !strings.Contains(platformFlags, platformInternalPath) {
354 t.Errorf("flags for platform must contain %#v, but was %#v.",
355 platformInternalPath, platformFlags)
356 }
357
Jiyong Park5d1598f2019-02-25 22:14:17 +0900358 platformStaticClient := ctx.ModuleForTests("cc-client-platform-static", coreVariant)
359 platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"]
360
361 // platform-static should use platform's internal header
362 if !strings.Contains(platformStaticFlags, platformInternalPath) {
363 t.Errorf("flags for platform-static must contain %#v, but was %#v.",
364 platformInternalPath, platformStaticFlags)
365 }
366
Inseob Kimc0907f12019-02-08 21:00:45 +0900367 productClient := ctx.ModuleForTests("cc-client-product", coreVariant)
368 productFlags := productClient.Rule("cc").Args["cFlags"]
369
Inseob Kim5cefbd22019-06-08 20:36:59 +0900370 // Product should use platform's and vendor's public headers
Inseob Kimc0907f12019-02-08 21:00:45 +0900371 if !strings.Contains(productFlags, platformOnProductPath) ||
Inseob Kim5cefbd22019-06-08 20:36:59 +0900372 !strings.Contains(productFlags, vendorPublicPath) {
Inseob Kimc0907f12019-02-08 21:00:45 +0900373 t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900374 platformPublicCorePath, vendorPublicPath, productFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900375 }
376
377 vendorClient := ctx.ModuleForTests("cc-client-vendor", vendorVariant)
378 vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
379
Inseob Kim5cefbd22019-06-08 20:36:59 +0900380 // Vendor should use platform's public header and vendor's internal header
381 if !strings.Contains(vendorFlags, platformPublicVendorPath) ||
Inseob Kimc0907f12019-02-08 21:00:45 +0900382 !strings.Contains(vendorFlags, vendorInternalPath) {
383 t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900384 platformPublicVendorPath, vendorInternalPath, vendorFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900385 }
Inseob Kimac1e9862019-12-09 18:15:47 +0900386
387 // Java modules linking against system API should use public stub
Colin Cross75ce9ec2021-02-26 16:20:32 -0800388 javaSystemApiClient := ctx.ModuleForTests("java-platform", "android_common").Rule("javac")
389 syspropPlatformPublic := ctx.ModuleForTests("sysprop-platform_public", "android_common").Description("for turbine")
390 if g, w := javaSystemApiClient.Implicits.Strings(), syspropPlatformPublic.Output.String(); !android.InList(w, g) {
391 t.Errorf("system api client should use public stub %q, got %q", w, g)
Inseob Kimac1e9862019-12-09 18:15:47 +0900392 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900393}