blob: 9d4c1aa838383322964ac6c93f489144ca232175 [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
27 "github.com/google/blueprint/proptools"
28)
29
30var buildDir string
31
32func setUp() {
33 var err error
34 buildDir, err = ioutil.TempDir("", "soong_sysprop_test")
35 if err != nil {
36 panic(err)
37 }
38}
39
40func tearDown() {
41 os.RemoveAll(buildDir)
42}
43
44func TestMain(m *testing.M) {
45 run := func() int {
46 setUp()
47 defer tearDown()
48
49 return m.Run()
50 }
51
52 os.Exit(run())
53}
54
Colin Cross98be1bb2019-12-13 20:41:13 -080055func testContext(config android.Config) *android.TestContext {
Inseob Kimc0907f12019-02-08 21:00:45 +090056
57 ctx := android.NewTestArchContext()
Colin Cross4b49b762019-11-22 15:25:03 -080058 ctx.RegisterModuleType("android_app", java.AndroidAppFactory)
59 ctx.RegisterModuleType("java_library", java.LibraryFactory)
60 ctx.RegisterModuleType("java_system_modules", java.SystemModulesFactory)
Inseob Kimc0907f12019-02-08 21:00:45 +090061 ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators)
62 ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators)
63 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
Colin Cross4b49b762019-11-22 15:25:03 -080068 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
69 ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
70 ctx.RegisterModuleType("cc_library_static", cc.LibraryFactory)
71 ctx.RegisterModuleType("cc_object", cc.ObjectFactory)
72 ctx.RegisterModuleType("llndk_library", cc.LlndkLibraryFactory)
73 ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory)
Inseob Kimc0907f12019-02-08 21:00:45 +090074 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Inseob Kimc0907f12019-02-08 21:00:45 +090075 ctx.BottomUp("link", cc.LinkageMutator).Parallel()
76 ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
77 ctx.BottomUp("version", cc.VersionMutator).Parallel()
78 ctx.BottomUp("begin", cc.BeginMutator).Parallel()
79 ctx.BottomUp("sysprop", cc.SyspropMutator).Parallel()
80 })
81
Colin Cross4b49b762019-11-22 15:25:03 -080082 ctx.RegisterModuleType("sysprop_library", syspropLibraryFactory)
Inseob Kimc0907f12019-02-08 21:00:45 +090083
Colin Cross98be1bb2019-12-13 20:41:13 -080084 ctx.Register(config)
Inseob Kimc0907f12019-02-08 21:00:45 +090085
Colin Cross98be1bb2019-12-13 20:41:13 -080086 return ctx
87}
88
89func run(t *testing.T, ctx *android.TestContext, config android.Config) {
90 t.Helper()
91 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
92 android.FailIfErrored(t, errs)
93 _, errs = ctx.PrepareBuildActions(config)
94 android.FailIfErrored(t, errs)
95}
96
97func testConfig(env map[string]string, bp string, fs map[string][]byte) android.Config {
Inseob Kimc0907f12019-02-08 21:00:45 +090098 bp += cc.GatherRequiredDepsForTest(android.Android)
99
100 mockFS := map[string][]byte{
Inseob Kim42882742019-07-30 17:55:33 +0900101 "a.java": nil,
102 "b.java": nil,
103 "c.java": nil,
104 "d.cpp": nil,
105 "api/sysprop-platform-current.txt": nil,
106 "api/sysprop-platform-latest.txt": nil,
107 "api/sysprop-platform-on-product-current.txt": nil,
108 "api/sysprop-platform-on-product-latest.txt": nil,
109 "api/sysprop-vendor-current.txt": nil,
110 "api/sysprop-vendor-latest.txt": nil,
111 "api/sysprop-odm-current.txt": nil,
112 "api/sysprop-odm-latest.txt": nil,
113 "framework/aidl/a.aidl": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900114
115 // For framework-res, which is an implicit dependency for framework
Dan Willemsen412160e2019-04-09 21:36:26 -0700116 "AndroidManifest.xml": nil,
117 "build/make/target/product/security/testkey": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900118
119 "build/soong/scripts/jar-wrapper.sh": nil,
120
121 "build/make/core/proguard.flags": nil,
122 "build/make/core/proguard_basic_keeps.flags": nil,
123
124 "jdk8/jre/lib/jce.jar": nil,
125 "jdk8/jre/lib/rt.jar": nil,
126 "jdk8/lib/tools.jar": nil,
127
128 "bar-doc/a.java": nil,
129 "bar-doc/b.java": nil,
130 "bar-doc/IFoo.aidl": nil,
131 "bar-doc/known_oj_tags.txt": nil,
132 "external/doclava/templates-sdk": nil,
133
134 "cert/new_cert.x509.pem": nil,
135 "cert/new_cert.pk8": nil,
136
137 "android/sysprop/PlatformProperties.sysprop": nil,
138 "com/android/VendorProperties.sysprop": nil,
Inseob Kim42882742019-07-30 17:55:33 +0900139 "com/android2/OdmProperties.sysprop": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900140 }
141
142 for k, v := range fs {
143 mockFS[k] = v
144 }
145
Colin Cross98be1bb2019-12-13 20:41:13 -0800146 config := java.TestConfig(buildDir, env, bp, mockFS)
Colin Crosse4759b92019-02-15 10:37:39 -0800147
Inseob Kimc0907f12019-02-08 21:00:45 +0900148 config.TestProductVariables.DeviceSystemSdkVersions = []string{"28"}
149 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
150 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
Colin Crosse4759b92019-02-15 10:37:39 -0800151
Inseob Kimc0907f12019-02-08 21:00:45 +0900152 return config
153
154}
155
156func test(t *testing.T, bp string) *android.TestContext {
157 t.Helper()
Colin Cross98be1bb2019-12-13 20:41:13 -0800158 config := testConfig(nil, bp, nil)
159 ctx := testContext(config)
Inseob Kimc0907f12019-02-08 21:00:45 +0900160 run(t, ctx, config)
161
162 return ctx
163}
164
165func TestSyspropLibrary(t *testing.T) {
166 ctx := test(t, `
167 sysprop_library {
168 name: "sysprop-platform",
169 srcs: ["android/sysprop/PlatformProperties.sysprop"],
170 api_packages: ["android.sysprop"],
171 property_owner: "Platform",
172 vendor_available: true,
173 }
174
175 sysprop_library {
176 name: "sysprop-platform-on-product",
177 srcs: ["android/sysprop/PlatformProperties.sysprop"],
178 api_packages: ["android.sysprop"],
179 property_owner: "Platform",
180 product_specific: true,
181 }
182
183 sysprop_library {
184 name: "sysprop-vendor",
185 srcs: ["com/android/VendorProperties.sysprop"],
186 api_packages: ["com.android"],
187 property_owner: "Vendor",
188 product_specific: true,
189 vendor_available: true,
190 }
191
Inseob Kim42882742019-07-30 17:55:33 +0900192 sysprop_library {
193 name: "sysprop-odm",
194 srcs: ["com/android2/OdmProperties.sysprop"],
195 api_packages: ["com.android2"],
196 property_owner: "Odm",
197 device_specific: true,
198 }
199
Inseob Kimc0907f12019-02-08 21:00:45 +0900200 java_library {
201 name: "java-platform",
202 srcs: ["c.java"],
203 sdk_version: "system_current",
204 libs: ["sysprop-platform"],
205 }
206
207 java_library {
208 name: "java-product",
209 srcs: ["c.java"],
210 sdk_version: "system_current",
211 product_specific: true,
212 libs: ["sysprop-platform", "sysprop-vendor"],
213 }
214
215 java_library {
216 name: "java-vendor",
217 srcs: ["c.java"],
218 sdk_version: "system_current",
219 soc_specific: true,
220 libs: ["sysprop-platform", "sysprop-vendor"],
221 }
222
223 cc_library {
224 name: "cc-client-platform",
225 srcs: ["d.cpp"],
226 static_libs: ["sysprop-platform"],
227 }
228
Jiyong Park5d1598f2019-02-25 22:14:17 +0900229 cc_library_static {
230 name: "cc-client-platform-static",
231 srcs: ["d.cpp"],
232 whole_static_libs: ["sysprop-platform"],
233 }
234
Inseob Kimc0907f12019-02-08 21:00:45 +0900235 cc_library {
236 name: "cc-client-product",
237 srcs: ["d.cpp"],
238 product_specific: true,
239 static_libs: ["sysprop-platform-on-product", "sysprop-vendor"],
240 }
241
242 cc_library {
243 name: "cc-client-vendor",
244 srcs: ["d.cpp"],
245 soc_specific: true,
246 static_libs: ["sysprop-platform", "sysprop-vendor"],
247 }
Inseob Kim1f959762019-03-27 17:20:37 +0900248
249 cc_library_headers {
250 name: "libbase_headers",
251 vendor_available: true,
252 recovery_available: true,
253 }
254
255 cc_library {
256 name: "liblog",
Yi Konge7fe9912019-06-02 00:53:50 -0700257 no_libcrt: true,
Inseob Kim1f959762019-03-27 17:20:37 +0900258 nocrt: true,
259 system_shared_libs: [],
260 recovery_available: true,
261 }
262
263 llndk_library {
264 name: "liblog",
265 symbol_file: "",
266 }
Inseob Kim42882742019-07-30 17:55:33 +0900267
268 java_library {
269 name: "sysprop-library-stub-platform",
270 sdk_version: "core_current",
271 }
272
273 java_library {
274 name: "sysprop-library-stub-vendor",
275 soc_specific: true,
276 sdk_version: "core_current",
277 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900278 `)
279
Inseob Kim42882742019-07-30 17:55:33 +0900280 // Check for generated cc_library
281 for _, variant := range []string{
Colin Crossfb0c16e2019-11-20 17:12:35 -0800282 "android_vendor.VER_arm_armv7-a-neon_shared",
283 "android_vendor.VER_arm_armv7-a-neon_static",
284 "android_vendor.VER_arm64_armv8-a_shared",
285 "android_vendor.VER_arm64_armv8-a_static",
Inseob Kim42882742019-07-30 17:55:33 +0900286 } {
287 ctx.ModuleForTests("libsysprop-platform", variant)
288 ctx.ModuleForTests("libsysprop-vendor", variant)
289 ctx.ModuleForTests("libsysprop-odm", variant)
290 }
291
Inseob Kimc0907f12019-02-08 21:00:45 +0900292 for _, variant := range []string{
Colin Cross7113d202019-11-20 16:39:12 -0800293 "android_arm_armv7-a-neon_shared",
294 "android_arm_armv7-a-neon_static",
295 "android_arm64_armv8-a_shared",
296 "android_arm64_armv8-a_static",
Inseob Kimc0907f12019-02-08 21:00:45 +0900297 } {
Inseob Kimc0907f12019-02-08 21:00:45 +0900298 ctx.ModuleForTests("libsysprop-platform", variant)
Inseob Kim42882742019-07-30 17:55:33 +0900299
300 // core variant of vendor-owned sysprop_library is for product
Inseob Kimc0907f12019-02-08 21:00:45 +0900301 ctx.ModuleForTests("libsysprop-vendor", variant)
302 }
303
304 ctx.ModuleForTests("sysprop-platform", "android_common")
305 ctx.ModuleForTests("sysprop-vendor", "android_common")
306
307 // Check for exported includes
Colin Cross7113d202019-11-20 16:39:12 -0800308 coreVariant := "android_arm64_armv8-a_static"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800309 vendorVariant := "android_vendor.VER_arm64_armv8-a_static"
Inseob Kimc0907f12019-02-08 21:00:45 +0900310
Colin Cross7113d202019-11-20 16:39:12 -0800311 platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/include"
312 platformPublicCorePath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/public/include"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800313 platformPublicVendorPath := "libsysprop-platform/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900314
Colin Cross7113d202019-11-20 16:39:12 -0800315 platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900316
Colin Crossfb0c16e2019-11-20 17:12:35 -0800317 vendorInternalPath := "libsysprop-vendor/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/include"
Colin Cross7113d202019-11-20 16:39:12 -0800318 vendorPublicPath := "libsysprop-vendor/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900319
320 platformClient := ctx.ModuleForTests("cc-client-platform", coreVariant)
321 platformFlags := platformClient.Rule("cc").Args["cFlags"]
322
Jiyong Park5d1598f2019-02-25 22:14:17 +0900323 // platform should use platform's internal header
Inseob Kimc0907f12019-02-08 21:00:45 +0900324 if !strings.Contains(platformFlags, platformInternalPath) {
325 t.Errorf("flags for platform must contain %#v, but was %#v.",
326 platformInternalPath, platformFlags)
327 }
328
Jiyong Park5d1598f2019-02-25 22:14:17 +0900329 platformStaticClient := ctx.ModuleForTests("cc-client-platform-static", coreVariant)
330 platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"]
331
332 // platform-static should use platform's internal header
333 if !strings.Contains(platformStaticFlags, platformInternalPath) {
334 t.Errorf("flags for platform-static must contain %#v, but was %#v.",
335 platformInternalPath, platformStaticFlags)
336 }
337
Inseob Kimc0907f12019-02-08 21:00:45 +0900338 productClient := ctx.ModuleForTests("cc-client-product", coreVariant)
339 productFlags := productClient.Rule("cc").Args["cFlags"]
340
Inseob Kim5cefbd22019-06-08 20:36:59 +0900341 // Product should use platform's and vendor's public headers
Inseob Kimc0907f12019-02-08 21:00:45 +0900342 if !strings.Contains(productFlags, platformOnProductPath) ||
Inseob Kim5cefbd22019-06-08 20:36:59 +0900343 !strings.Contains(productFlags, vendorPublicPath) {
Inseob Kimc0907f12019-02-08 21:00:45 +0900344 t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900345 platformPublicCorePath, vendorPublicPath, productFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900346 }
347
348 vendorClient := ctx.ModuleForTests("cc-client-vendor", vendorVariant)
349 vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
350
Inseob Kim5cefbd22019-06-08 20:36:59 +0900351 // Vendor should use platform's public header and vendor's internal header
352 if !strings.Contains(vendorFlags, platformPublicVendorPath) ||
Inseob Kimc0907f12019-02-08 21:00:45 +0900353 !strings.Contains(vendorFlags, vendorInternalPath) {
354 t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900355 platformPublicVendorPath, vendorInternalPath, vendorFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900356 }
357}