blob: 7b906731faa42ce93a0fc68376a7d742055d4947 [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
55func testContext(config android.Config, bp string,
56 fs map[string][]byte) *android.TestContext {
57
58 ctx := android.NewTestArchContext()
Colin Cross4b49b762019-11-22 15:25:03 -080059 ctx.RegisterModuleType("android_app", java.AndroidAppFactory)
60 ctx.RegisterModuleType("java_library", java.LibraryFactory)
61 ctx.RegisterModuleType("java_system_modules", java.SystemModulesFactory)
Inseob Kimc0907f12019-02-08 21:00:45 +090062 ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators)
63 ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators)
64 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Inseob Kim988f53c2019-09-16 15:59:01 +090065 ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
66 ctx.BottomUp("sysprop_deps", syspropDepsMutator).Parallel()
67 })
Inseob Kimc0907f12019-02-08 21:00:45 +090068
Colin Cross4b49b762019-11-22 15:25:03 -080069 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
70 ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
71 ctx.RegisterModuleType("cc_library_static", cc.LibraryFactory)
72 ctx.RegisterModuleType("cc_object", cc.ObjectFactory)
73 ctx.RegisterModuleType("llndk_library", cc.LlndkLibraryFactory)
74 ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory)
Inseob Kimc0907f12019-02-08 21:00:45 +090075 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Inseob Kimc0907f12019-02-08 21:00:45 +090076 ctx.BottomUp("link", cc.LinkageMutator).Parallel()
77 ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
78 ctx.BottomUp("version", cc.VersionMutator).Parallel()
79 ctx.BottomUp("begin", cc.BeginMutator).Parallel()
80 ctx.BottomUp("sysprop", cc.SyspropMutator).Parallel()
81 })
82
Colin Cross4b49b762019-11-22 15:25:03 -080083 ctx.RegisterModuleType("sysprop_library", syspropLibraryFactory)
Inseob Kimc0907f12019-02-08 21:00:45 +090084
85 ctx.Register()
86
Colin Crosse4759b92019-02-15 10:37:39 -080087 bp += java.GatherRequiredDepsForTest()
Inseob Kimc0907f12019-02-08 21:00:45 +090088 bp += cc.GatherRequiredDepsForTest(android.Android)
89
90 mockFS := map[string][]byte{
Inseob Kim42882742019-07-30 17:55:33 +090091 "Android.bp": []byte(bp),
92 "a.java": nil,
93 "b.java": nil,
94 "c.java": nil,
95 "d.cpp": nil,
96 "api/sysprop-platform-current.txt": nil,
97 "api/sysprop-platform-latest.txt": nil,
98 "api/sysprop-platform-on-product-current.txt": nil,
99 "api/sysprop-platform-on-product-latest.txt": nil,
100 "api/sysprop-vendor-current.txt": nil,
101 "api/sysprop-vendor-latest.txt": nil,
102 "api/sysprop-odm-current.txt": nil,
103 "api/sysprop-odm-latest.txt": nil,
104 "framework/aidl/a.aidl": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900105
106 // For framework-res, which is an implicit dependency for framework
Dan Willemsen412160e2019-04-09 21:36:26 -0700107 "AndroidManifest.xml": nil,
108 "build/make/target/product/security/testkey": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900109
110 "build/soong/scripts/jar-wrapper.sh": nil,
111
112 "build/make/core/proguard.flags": nil,
113 "build/make/core/proguard_basic_keeps.flags": nil,
114
115 "jdk8/jre/lib/jce.jar": nil,
116 "jdk8/jre/lib/rt.jar": nil,
117 "jdk8/lib/tools.jar": nil,
118
119 "bar-doc/a.java": nil,
120 "bar-doc/b.java": nil,
121 "bar-doc/IFoo.aidl": nil,
122 "bar-doc/known_oj_tags.txt": nil,
123 "external/doclava/templates-sdk": nil,
124
125 "cert/new_cert.x509.pem": nil,
126 "cert/new_cert.pk8": nil,
127
128 "android/sysprop/PlatformProperties.sysprop": nil,
129 "com/android/VendorProperties.sysprop": nil,
Inseob Kim42882742019-07-30 17:55:33 +0900130 "com/android2/OdmProperties.sysprop": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900131 }
132
133 for k, v := range fs {
134 mockFS[k] = v
135 }
136
137 ctx.MockFileSystem(mockFS)
138
139 return ctx
140}
141
142func run(t *testing.T, ctx *android.TestContext, config android.Config) {
143 t.Helper()
Inseob Kim42882742019-07-30 17:55:33 +0900144 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
Inseob Kimc0907f12019-02-08 21:00:45 +0900145 android.FailIfErrored(t, errs)
146 _, errs = ctx.PrepareBuildActions(config)
147 android.FailIfErrored(t, errs)
148}
149
150func testConfig(env map[string]string) android.Config {
Colin Crosse4759b92019-02-15 10:37:39 -0800151 config := java.TestConfig(buildDir, env)
152
Inseob Kimc0907f12019-02-08 21:00:45 +0900153 config.TestProductVariables.DeviceSystemSdkVersions = []string{"28"}
154 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
155 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
Colin Crosse4759b92019-02-15 10:37:39 -0800156
Inseob Kimc0907f12019-02-08 21:00:45 +0900157 return config
158
159}
160
161func test(t *testing.T, bp string) *android.TestContext {
162 t.Helper()
163 config := testConfig(nil)
164 ctx := testContext(config, bp, nil)
165 run(t, ctx, config)
166
167 return ctx
168}
169
170func TestSyspropLibrary(t *testing.T) {
171 ctx := test(t, `
172 sysprop_library {
173 name: "sysprop-platform",
174 srcs: ["android/sysprop/PlatformProperties.sysprop"],
175 api_packages: ["android.sysprop"],
176 property_owner: "Platform",
177 vendor_available: true,
178 }
179
180 sysprop_library {
181 name: "sysprop-platform-on-product",
182 srcs: ["android/sysprop/PlatformProperties.sysprop"],
183 api_packages: ["android.sysprop"],
184 property_owner: "Platform",
185 product_specific: true,
186 }
187
188 sysprop_library {
189 name: "sysprop-vendor",
190 srcs: ["com/android/VendorProperties.sysprop"],
191 api_packages: ["com.android"],
192 property_owner: "Vendor",
193 product_specific: true,
194 vendor_available: true,
195 }
196
Inseob Kim42882742019-07-30 17:55:33 +0900197 sysprop_library {
198 name: "sysprop-odm",
199 srcs: ["com/android2/OdmProperties.sysprop"],
200 api_packages: ["com.android2"],
201 property_owner: "Odm",
202 device_specific: true,
203 }
204
Inseob Kimc0907f12019-02-08 21:00:45 +0900205 java_library {
206 name: "java-platform",
207 srcs: ["c.java"],
208 sdk_version: "system_current",
209 libs: ["sysprop-platform"],
210 }
211
212 java_library {
213 name: "java-product",
214 srcs: ["c.java"],
215 sdk_version: "system_current",
216 product_specific: true,
217 libs: ["sysprop-platform", "sysprop-vendor"],
218 }
219
220 java_library {
221 name: "java-vendor",
222 srcs: ["c.java"],
223 sdk_version: "system_current",
224 soc_specific: true,
225 libs: ["sysprop-platform", "sysprop-vendor"],
226 }
227
228 cc_library {
229 name: "cc-client-platform",
230 srcs: ["d.cpp"],
231 static_libs: ["sysprop-platform"],
232 }
233
Jiyong Park5d1598f2019-02-25 22:14:17 +0900234 cc_library_static {
235 name: "cc-client-platform-static",
236 srcs: ["d.cpp"],
237 whole_static_libs: ["sysprop-platform"],
238 }
239
Inseob Kimc0907f12019-02-08 21:00:45 +0900240 cc_library {
241 name: "cc-client-product",
242 srcs: ["d.cpp"],
243 product_specific: true,
244 static_libs: ["sysprop-platform-on-product", "sysprop-vendor"],
245 }
246
247 cc_library {
248 name: "cc-client-vendor",
249 srcs: ["d.cpp"],
250 soc_specific: true,
251 static_libs: ["sysprop-platform", "sysprop-vendor"],
252 }
Inseob Kim1f959762019-03-27 17:20:37 +0900253
254 cc_library_headers {
255 name: "libbase_headers",
256 vendor_available: true,
257 recovery_available: true,
258 }
259
260 cc_library {
261 name: "liblog",
Yi Konge7fe9912019-06-02 00:53:50 -0700262 no_libcrt: true,
Inseob Kim1f959762019-03-27 17:20:37 +0900263 nocrt: true,
264 system_shared_libs: [],
265 recovery_available: true,
266 }
267
268 llndk_library {
269 name: "liblog",
270 symbol_file: "",
271 }
Inseob Kim42882742019-07-30 17:55:33 +0900272
273 java_library {
274 name: "sysprop-library-stub-platform",
275 sdk_version: "core_current",
276 }
277
278 java_library {
279 name: "sysprop-library-stub-vendor",
280 soc_specific: true,
281 sdk_version: "core_current",
282 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900283 `)
284
Inseob Kim42882742019-07-30 17:55:33 +0900285 // Check for generated cc_library
286 for _, variant := range []string{
Inseob Kim64c43952019-08-26 16:52:35 +0900287 "android_arm_armv7-a-neon_vendor.VER_shared",
288 "android_arm_armv7-a-neon_vendor.VER_static",
289 "android_arm64_armv8-a_vendor.VER_shared",
290 "android_arm64_armv8-a_vendor.VER_static",
Inseob Kim42882742019-07-30 17:55:33 +0900291 } {
292 ctx.ModuleForTests("libsysprop-platform", variant)
293 ctx.ModuleForTests("libsysprop-vendor", variant)
294 ctx.ModuleForTests("libsysprop-odm", variant)
295 }
296
Inseob Kimc0907f12019-02-08 21:00:45 +0900297 for _, variant := range []string{
Colin Cross7113d202019-11-20 16:39:12 -0800298 "android_arm_armv7-a-neon_shared",
299 "android_arm_armv7-a-neon_static",
300 "android_arm64_armv8-a_shared",
301 "android_arm64_armv8-a_static",
Inseob Kimc0907f12019-02-08 21:00:45 +0900302 } {
Inseob Kimc0907f12019-02-08 21:00:45 +0900303 ctx.ModuleForTests("libsysprop-platform", variant)
Inseob Kim42882742019-07-30 17:55:33 +0900304
305 // core variant of vendor-owned sysprop_library is for product
Inseob Kimc0907f12019-02-08 21:00:45 +0900306 ctx.ModuleForTests("libsysprop-vendor", variant)
307 }
308
309 ctx.ModuleForTests("sysprop-platform", "android_common")
310 ctx.ModuleForTests("sysprop-vendor", "android_common")
311
312 // Check for exported includes
Colin Cross7113d202019-11-20 16:39:12 -0800313 coreVariant := "android_arm64_armv8-a_static"
Inseob Kim64c43952019-08-26 16:52:35 +0900314 vendorVariant := "android_arm64_armv8-a_vendor.VER_static"
Inseob Kimc0907f12019-02-08 21:00:45 +0900315
Colin Cross7113d202019-11-20 16:39:12 -0800316 platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/include"
317 platformPublicCorePath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kim64c43952019-08-26 16:52:35 +0900318 platformPublicVendorPath := "libsysprop-platform/android_arm64_armv8-a_vendor.VER_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900319
Colin Cross7113d202019-11-20 16:39:12 -0800320 platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900321
Inseob Kim64c43952019-08-26 16:52:35 +0900322 vendorInternalPath := "libsysprop-vendor/android_arm64_armv8-a_vendor.VER_static/gen/sysprop/include"
Colin Cross7113d202019-11-20 16:39:12 -0800323 vendorPublicPath := "libsysprop-vendor/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900324
325 platformClient := ctx.ModuleForTests("cc-client-platform", coreVariant)
326 platformFlags := platformClient.Rule("cc").Args["cFlags"]
327
Jiyong Park5d1598f2019-02-25 22:14:17 +0900328 // platform should use platform's internal header
Inseob Kimc0907f12019-02-08 21:00:45 +0900329 if !strings.Contains(platformFlags, platformInternalPath) {
330 t.Errorf("flags for platform must contain %#v, but was %#v.",
331 platformInternalPath, platformFlags)
332 }
333
Jiyong Park5d1598f2019-02-25 22:14:17 +0900334 platformStaticClient := ctx.ModuleForTests("cc-client-platform-static", coreVariant)
335 platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"]
336
337 // platform-static should use platform's internal header
338 if !strings.Contains(platformStaticFlags, platformInternalPath) {
339 t.Errorf("flags for platform-static must contain %#v, but was %#v.",
340 platformInternalPath, platformStaticFlags)
341 }
342
Inseob Kimc0907f12019-02-08 21:00:45 +0900343 productClient := ctx.ModuleForTests("cc-client-product", coreVariant)
344 productFlags := productClient.Rule("cc").Args["cFlags"]
345
Inseob Kim5cefbd22019-06-08 20:36:59 +0900346 // Product should use platform's and vendor's public headers
Inseob Kimc0907f12019-02-08 21:00:45 +0900347 if !strings.Contains(productFlags, platformOnProductPath) ||
Inseob Kim5cefbd22019-06-08 20:36:59 +0900348 !strings.Contains(productFlags, vendorPublicPath) {
Inseob Kimc0907f12019-02-08 21:00:45 +0900349 t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900350 platformPublicCorePath, vendorPublicPath, productFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900351 }
352
353 vendorClient := ctx.ModuleForTests("cc-client-vendor", vendorVariant)
354 vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
355
Inseob Kim5cefbd22019-06-08 20:36:59 +0900356 // Vendor should use platform's public header and vendor's internal header
357 if !strings.Contains(vendorFlags, platformPublicVendorPath) ||
Inseob Kimc0907f12019-02-08 21:00:45 +0900358 !strings.Contains(vendorFlags, vendorInternalPath) {
359 t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900360 platformPublicVendorPath, vendorInternalPath, vendorFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900361 }
362}