blob: 8503386756c7776f03f7ec8a5484813d6694b866 [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 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 Cross98be1bb2019-12-13 20:41:13 -080077 ctx.Register(config)
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,
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
Colin Cross98be1bb2019-12-13 20:41:13 -0800139 config := java.TestConfig(buildDir, env, bp, mockFS)
Colin Crosse4759b92019-02-15 10:37:39 -0800140
Inseob Kimc0907f12019-02-08 21:00:45 +0900141 config.TestProductVariables.DeviceSystemSdkVersions = []string{"28"}
142 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
143 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
Colin Crosse4759b92019-02-15 10:37:39 -0800144
Inseob Kimc0907f12019-02-08 21:00:45 +0900145 return config
146
147}
148
149func test(t *testing.T, bp string) *android.TestContext {
150 t.Helper()
Colin Cross98be1bb2019-12-13 20:41:13 -0800151 config := testConfig(nil, bp, nil)
152 ctx := testContext(config)
Inseob Kimc0907f12019-02-08 21:00:45 +0900153 run(t, ctx, config)
154
155 return ctx
156}
157
158func TestSyspropLibrary(t *testing.T) {
159 ctx := test(t, `
160 sysprop_library {
161 name: "sysprop-platform",
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100162 apex_available: ["//apex_available:platform"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900163 srcs: ["android/sysprop/PlatformProperties.sysprop"],
164 api_packages: ["android.sysprop"],
165 property_owner: "Platform",
166 vendor_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900167 host_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900168 }
169
170 sysprop_library {
171 name: "sysprop-platform-on-product",
172 srcs: ["android/sysprop/PlatformProperties.sysprop"],
173 api_packages: ["android.sysprop"],
174 property_owner: "Platform",
175 product_specific: true,
176 }
177
178 sysprop_library {
179 name: "sysprop-vendor",
180 srcs: ["com/android/VendorProperties.sysprop"],
181 api_packages: ["com.android"],
182 property_owner: "Vendor",
183 product_specific: true,
184 vendor_available: true,
185 }
186
Inseob Kim42882742019-07-30 17:55:33 +0900187 sysprop_library {
188 name: "sysprop-odm",
189 srcs: ["com/android2/OdmProperties.sysprop"],
190 api_packages: ["com.android2"],
191 property_owner: "Odm",
192 device_specific: true,
193 }
194
Inseob Kimc0907f12019-02-08 21:00:45 +0900195 java_library {
196 name: "java-platform",
197 srcs: ["c.java"],
198 sdk_version: "system_current",
199 libs: ["sysprop-platform"],
200 }
201
202 java_library {
Inseob Kimac1e9862019-12-09 18:15:47 +0900203 name: "java-platform-private",
204 srcs: ["c.java"],
205 platform_apis: true,
206 libs: ["sysprop-platform"],
207 }
208
209 java_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900210 name: "java-product",
211 srcs: ["c.java"],
212 sdk_version: "system_current",
213 product_specific: true,
214 libs: ["sysprop-platform", "sysprop-vendor"],
215 }
216
217 java_library {
218 name: "java-vendor",
219 srcs: ["c.java"],
220 sdk_version: "system_current",
221 soc_specific: true,
222 libs: ["sysprop-platform", "sysprop-vendor"],
223 }
224
225 cc_library {
226 name: "cc-client-platform",
227 srcs: ["d.cpp"],
228 static_libs: ["sysprop-platform"],
229 }
230
Jiyong Park5d1598f2019-02-25 22:14:17 +0900231 cc_library_static {
232 name: "cc-client-platform-static",
233 srcs: ["d.cpp"],
234 whole_static_libs: ["sysprop-platform"],
235 }
236
Inseob Kimc0907f12019-02-08 21:00:45 +0900237 cc_library {
238 name: "cc-client-product",
239 srcs: ["d.cpp"],
240 product_specific: true,
241 static_libs: ["sysprop-platform-on-product", "sysprop-vendor"],
242 }
243
244 cc_library {
245 name: "cc-client-vendor",
246 srcs: ["d.cpp"],
247 soc_specific: true,
248 static_libs: ["sysprop-platform", "sysprop-vendor"],
249 }
Inseob Kim1f959762019-03-27 17:20:37 +0900250
Inseob Kim89db15d2020-02-03 18:06:46 +0900251 cc_library {
252 name: "libbase",
253 host_supported: true,
254 }
255
Inseob Kim1f959762019-03-27 17:20:37 +0900256 cc_library_headers {
257 name: "libbase_headers",
258 vendor_available: true,
259 recovery_available: true,
260 }
261
262 cc_library {
263 name: "liblog",
Yi Konge7fe9912019-06-02 00:53:50 -0700264 no_libcrt: true,
Inseob Kim1f959762019-03-27 17:20:37 +0900265 nocrt: true,
266 system_shared_libs: [],
267 recovery_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900268 host_supported: true,
269 }
270
271 cc_binary_host {
272 name: "hostbin",
273 static_libs: ["sysprop-platform"],
Inseob Kim1f959762019-03-27 17:20:37 +0900274 }
275
276 llndk_library {
277 name: "liblog",
278 symbol_file: "",
279 }
Inseob Kim42882742019-07-30 17:55:33 +0900280
281 java_library {
282 name: "sysprop-library-stub-platform",
283 sdk_version: "core_current",
284 }
285
286 java_library {
287 name: "sysprop-library-stub-vendor",
288 soc_specific: true,
289 sdk_version: "core_current",
290 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900291 `)
292
Inseob Kim42882742019-07-30 17:55:33 +0900293 // Check for generated cc_library
294 for _, variant := range []string{
Colin Crossfb0c16e2019-11-20 17:12:35 -0800295 "android_vendor.VER_arm_armv7-a-neon_shared",
296 "android_vendor.VER_arm_armv7-a-neon_static",
297 "android_vendor.VER_arm64_armv8-a_shared",
298 "android_vendor.VER_arm64_armv8-a_static",
Inseob Kim42882742019-07-30 17:55:33 +0900299 } {
300 ctx.ModuleForTests("libsysprop-platform", variant)
301 ctx.ModuleForTests("libsysprop-vendor", variant)
302 ctx.ModuleForTests("libsysprop-odm", variant)
303 }
304
Inseob Kimc0907f12019-02-08 21:00:45 +0900305 for _, variant := range []string{
Colin Cross7113d202019-11-20 16:39:12 -0800306 "android_arm_armv7-a-neon_shared",
307 "android_arm_armv7-a-neon_static",
308 "android_arm64_armv8-a_shared",
309 "android_arm64_armv8-a_static",
Inseob Kimc0907f12019-02-08 21:00:45 +0900310 } {
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100311 library := ctx.ModuleForTests("libsysprop-platform", variant).Module().(*cc.Module)
312 expectedApexAvailableOnLibrary := []string{"//apex_available:platform"}
313 if !reflect.DeepEqual(library.ApexProperties.Apex_available, expectedApexAvailableOnLibrary) {
314 t.Errorf("apex available property on libsysprop-platform must be %#v, but was %#v.",
315 expectedApexAvailableOnLibrary, library.ApexProperties.Apex_available)
316 }
Inseob Kim42882742019-07-30 17:55:33 +0900317
318 // core variant of vendor-owned sysprop_library is for product
Inseob Kimc0907f12019-02-08 21:00:45 +0900319 ctx.ModuleForTests("libsysprop-vendor", variant)
320 }
321
322 ctx.ModuleForTests("sysprop-platform", "android_common")
Inseob Kimac1e9862019-12-09 18:15:47 +0900323 ctx.ModuleForTests("sysprop-platform_public", "android_common")
Inseob Kimc0907f12019-02-08 21:00:45 +0900324 ctx.ModuleForTests("sysprop-vendor", "android_common")
325
326 // Check for exported includes
Colin Cross7113d202019-11-20 16:39:12 -0800327 coreVariant := "android_arm64_armv8-a_static"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800328 vendorVariant := "android_vendor.VER_arm64_armv8-a_static"
Inseob Kimc0907f12019-02-08 21:00:45 +0900329
Colin Cross7113d202019-11-20 16:39:12 -0800330 platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/include"
331 platformPublicCorePath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/public/include"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800332 platformPublicVendorPath := "libsysprop-platform/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900333
Colin Cross7113d202019-11-20 16:39:12 -0800334 platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900335
Colin Crossfb0c16e2019-11-20 17:12:35 -0800336 vendorInternalPath := "libsysprop-vendor/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/include"
Colin Cross7113d202019-11-20 16:39:12 -0800337 vendorPublicPath := "libsysprop-vendor/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900338
339 platformClient := ctx.ModuleForTests("cc-client-platform", coreVariant)
340 platformFlags := platformClient.Rule("cc").Args["cFlags"]
341
Jiyong Park5d1598f2019-02-25 22:14:17 +0900342 // platform should use platform's internal header
Inseob Kimc0907f12019-02-08 21:00:45 +0900343 if !strings.Contains(platformFlags, platformInternalPath) {
344 t.Errorf("flags for platform must contain %#v, but was %#v.",
345 platformInternalPath, platformFlags)
346 }
347
Jiyong Park5d1598f2019-02-25 22:14:17 +0900348 platformStaticClient := ctx.ModuleForTests("cc-client-platform-static", coreVariant)
349 platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"]
350
351 // platform-static should use platform's internal header
352 if !strings.Contains(platformStaticFlags, platformInternalPath) {
353 t.Errorf("flags for platform-static must contain %#v, but was %#v.",
354 platformInternalPath, platformStaticFlags)
355 }
356
Inseob Kimc0907f12019-02-08 21:00:45 +0900357 productClient := ctx.ModuleForTests("cc-client-product", coreVariant)
358 productFlags := productClient.Rule("cc").Args["cFlags"]
359
Inseob Kim5cefbd22019-06-08 20:36:59 +0900360 // Product should use platform's and vendor's public headers
Inseob Kimc0907f12019-02-08 21:00:45 +0900361 if !strings.Contains(productFlags, platformOnProductPath) ||
Inseob Kim5cefbd22019-06-08 20:36:59 +0900362 !strings.Contains(productFlags, vendorPublicPath) {
Inseob Kimc0907f12019-02-08 21:00:45 +0900363 t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900364 platformPublicCorePath, vendorPublicPath, productFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900365 }
366
367 vendorClient := ctx.ModuleForTests("cc-client-vendor", vendorVariant)
368 vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
369
Inseob Kim5cefbd22019-06-08 20:36:59 +0900370 // Vendor should use platform's public header and vendor's internal header
371 if !strings.Contains(vendorFlags, platformPublicVendorPath) ||
Inseob Kimc0907f12019-02-08 21:00:45 +0900372 !strings.Contains(vendorFlags, vendorInternalPath) {
373 t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900374 platformPublicVendorPath, vendorInternalPath, vendorFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900375 }
Inseob Kimac1e9862019-12-09 18:15:47 +0900376
377 // Java modules linking against system API should use public stub
378 javaSystemApiClient := ctx.ModuleForTests("java-platform", "android_common")
379 publicStubFound := false
380 ctx.VisitDirectDeps(javaSystemApiClient.Module(), func(dep blueprint.Module) {
381 if dep.Name() == "sysprop-platform_public" {
382 publicStubFound = true
383 }
384 })
385 if !publicStubFound {
386 t.Errorf("system api client should use public stub")
387 }
388
Inseob Kimc0907f12019-02-08 21:00:45 +0900389}