blob: 80dcb72170c11acd6856294f329eb4fb8f24f7ad [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) {
76 ctx.BottomUp("image", cc.ImageMutator).Parallel()
77 ctx.BottomUp("link", cc.LinkageMutator).Parallel()
78 ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
79 ctx.BottomUp("version", cc.VersionMutator).Parallel()
80 ctx.BottomUp("begin", cc.BeginMutator).Parallel()
81 ctx.BottomUp("sysprop", cc.SyspropMutator).Parallel()
82 })
83
Colin Cross4b49b762019-11-22 15:25:03 -080084 ctx.RegisterModuleType("sysprop_library", syspropLibraryFactory)
Inseob Kimc0907f12019-02-08 21:00:45 +090085
86 ctx.Register()
87
Colin Crosse4759b92019-02-15 10:37:39 -080088 bp += java.GatherRequiredDepsForTest()
Inseob Kimc0907f12019-02-08 21:00:45 +090089 bp += cc.GatherRequiredDepsForTest(android.Android)
90
91 mockFS := map[string][]byte{
Inseob Kim42882742019-07-30 17:55:33 +090092 "Android.bp": []byte(bp),
93 "a.java": nil,
94 "b.java": nil,
95 "c.java": nil,
96 "d.cpp": nil,
97 "api/sysprop-platform-current.txt": nil,
98 "api/sysprop-platform-latest.txt": nil,
99 "api/sysprop-platform-on-product-current.txt": nil,
100 "api/sysprop-platform-on-product-latest.txt": nil,
101 "api/sysprop-vendor-current.txt": nil,
102 "api/sysprop-vendor-latest.txt": nil,
103 "api/sysprop-odm-current.txt": nil,
104 "api/sysprop-odm-latest.txt": nil,
105 "framework/aidl/a.aidl": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900106
107 // For framework-res, which is an implicit dependency for framework
Dan Willemsen412160e2019-04-09 21:36:26 -0700108 "AndroidManifest.xml": nil,
109 "build/make/target/product/security/testkey": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900110
111 "build/soong/scripts/jar-wrapper.sh": nil,
112
113 "build/make/core/proguard.flags": nil,
114 "build/make/core/proguard_basic_keeps.flags": nil,
115
116 "jdk8/jre/lib/jce.jar": nil,
117 "jdk8/jre/lib/rt.jar": nil,
118 "jdk8/lib/tools.jar": nil,
119
120 "bar-doc/a.java": nil,
121 "bar-doc/b.java": nil,
122 "bar-doc/IFoo.aidl": nil,
123 "bar-doc/known_oj_tags.txt": nil,
124 "external/doclava/templates-sdk": nil,
125
126 "cert/new_cert.x509.pem": nil,
127 "cert/new_cert.pk8": nil,
128
129 "android/sysprop/PlatformProperties.sysprop": nil,
130 "com/android/VendorProperties.sysprop": nil,
Inseob Kim42882742019-07-30 17:55:33 +0900131 "com/android2/OdmProperties.sysprop": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900132 }
133
134 for k, v := range fs {
135 mockFS[k] = v
136 }
137
138 ctx.MockFileSystem(mockFS)
139
140 return ctx
141}
142
143func run(t *testing.T, ctx *android.TestContext, config android.Config) {
144 t.Helper()
Inseob Kim42882742019-07-30 17:55:33 +0900145 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
Inseob Kimc0907f12019-02-08 21:00:45 +0900146 android.FailIfErrored(t, errs)
147 _, errs = ctx.PrepareBuildActions(config)
148 android.FailIfErrored(t, errs)
149}
150
151func testConfig(env map[string]string) android.Config {
Colin Crosse4759b92019-02-15 10:37:39 -0800152 config := java.TestConfig(buildDir, env)
153
Inseob Kimc0907f12019-02-08 21:00:45 +0900154 config.TestProductVariables.DeviceSystemSdkVersions = []string{"28"}
155 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
156 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
Colin Crosse4759b92019-02-15 10:37:39 -0800157
Inseob Kimc0907f12019-02-08 21:00:45 +0900158 return config
159
160}
161
162func test(t *testing.T, bp string) *android.TestContext {
163 t.Helper()
164 config := testConfig(nil)
165 ctx := testContext(config, bp, nil)
166 run(t, ctx, config)
167
168 return ctx
169}
170
171func TestSyspropLibrary(t *testing.T) {
172 ctx := test(t, `
173 sysprop_library {
174 name: "sysprop-platform",
175 srcs: ["android/sysprop/PlatformProperties.sysprop"],
176 api_packages: ["android.sysprop"],
177 property_owner: "Platform",
178 vendor_available: true,
179 }
180
181 sysprop_library {
182 name: "sysprop-platform-on-product",
183 srcs: ["android/sysprop/PlatformProperties.sysprop"],
184 api_packages: ["android.sysprop"],
185 property_owner: "Platform",
186 product_specific: true,
187 }
188
189 sysprop_library {
190 name: "sysprop-vendor",
191 srcs: ["com/android/VendorProperties.sysprop"],
192 api_packages: ["com.android"],
193 property_owner: "Vendor",
194 product_specific: true,
195 vendor_available: true,
196 }
197
Inseob Kim42882742019-07-30 17:55:33 +0900198 sysprop_library {
199 name: "sysprop-odm",
200 srcs: ["com/android2/OdmProperties.sysprop"],
201 api_packages: ["com.android2"],
202 property_owner: "Odm",
203 device_specific: true,
204 }
205
Inseob Kimc0907f12019-02-08 21:00:45 +0900206 java_library {
207 name: "java-platform",
208 srcs: ["c.java"],
209 sdk_version: "system_current",
210 libs: ["sysprop-platform"],
211 }
212
213 java_library {
214 name: "java-product",
215 srcs: ["c.java"],
216 sdk_version: "system_current",
217 product_specific: true,
218 libs: ["sysprop-platform", "sysprop-vendor"],
219 }
220
221 java_library {
222 name: "java-vendor",
223 srcs: ["c.java"],
224 sdk_version: "system_current",
225 soc_specific: true,
226 libs: ["sysprop-platform", "sysprop-vendor"],
227 }
228
229 cc_library {
230 name: "cc-client-platform",
231 srcs: ["d.cpp"],
232 static_libs: ["sysprop-platform"],
233 }
234
Jiyong Park5d1598f2019-02-25 22:14:17 +0900235 cc_library_static {
236 name: "cc-client-platform-static",
237 srcs: ["d.cpp"],
238 whole_static_libs: ["sysprop-platform"],
239 }
240
Inseob Kimc0907f12019-02-08 21:00:45 +0900241 cc_library {
242 name: "cc-client-product",
243 srcs: ["d.cpp"],
244 product_specific: true,
245 static_libs: ["sysprop-platform-on-product", "sysprop-vendor"],
246 }
247
248 cc_library {
249 name: "cc-client-vendor",
250 srcs: ["d.cpp"],
251 soc_specific: true,
252 static_libs: ["sysprop-platform", "sysprop-vendor"],
253 }
Inseob Kim1f959762019-03-27 17:20:37 +0900254
255 cc_library_headers {
256 name: "libbase_headers",
257 vendor_available: true,
258 recovery_available: true,
259 }
260
261 cc_library {
262 name: "liblog",
Yi Konge7fe9912019-06-02 00:53:50 -0700263 no_libcrt: true,
Inseob Kim1f959762019-03-27 17:20:37 +0900264 nocrt: true,
265 system_shared_libs: [],
266 recovery_available: true,
267 }
268
269 llndk_library {
270 name: "liblog",
271 symbol_file: "",
272 }
Inseob Kim42882742019-07-30 17:55:33 +0900273
274 java_library {
275 name: "sysprop-library-stub-platform",
276 sdk_version: "core_current",
277 }
278
279 java_library {
280 name: "sysprop-library-stub-vendor",
281 soc_specific: true,
282 sdk_version: "core_current",
283 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900284 `)
285
Inseob Kim42882742019-07-30 17:55:33 +0900286 // Check for generated cc_library
287 for _, variant := range []string{
Inseob Kim64c43952019-08-26 16:52:35 +0900288 "android_arm_armv7-a-neon_vendor.VER_shared",
289 "android_arm_armv7-a-neon_vendor.VER_static",
290 "android_arm64_armv8-a_vendor.VER_shared",
291 "android_arm64_armv8-a_vendor.VER_static",
Inseob Kim42882742019-07-30 17:55:33 +0900292 } {
293 ctx.ModuleForTests("libsysprop-platform", variant)
294 ctx.ModuleForTests("libsysprop-vendor", variant)
295 ctx.ModuleForTests("libsysprop-odm", variant)
296 }
297
Inseob Kimc0907f12019-02-08 21:00:45 +0900298 for _, variant := range []string{
299 "android_arm_armv7-a-neon_core_shared",
300 "android_arm_armv7-a-neon_core_static",
Inseob Kimc0907f12019-02-08 21:00:45 +0900301 "android_arm64_armv8-a_core_shared",
302 "android_arm64_armv8-a_core_static",
Inseob Kimc0907f12019-02-08 21:00:45 +0900303 } {
Inseob Kimc0907f12019-02-08 21:00:45 +0900304 ctx.ModuleForTests("libsysprop-platform", variant)
Inseob Kim42882742019-07-30 17:55:33 +0900305
306 // core variant of vendor-owned sysprop_library is for product
Inseob Kimc0907f12019-02-08 21:00:45 +0900307 ctx.ModuleForTests("libsysprop-vendor", variant)
308 }
309
310 ctx.ModuleForTests("sysprop-platform", "android_common")
311 ctx.ModuleForTests("sysprop-vendor", "android_common")
312
313 // Check for exported includes
314 coreVariant := "android_arm64_armv8-a_core_static"
Inseob Kim64c43952019-08-26 16:52:35 +0900315 vendorVariant := "android_arm64_armv8-a_vendor.VER_static"
Inseob Kimc0907f12019-02-08 21:00:45 +0900316
317 platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_core_static/gen/sysprop/include"
Inseob Kim5cefbd22019-06-08 20:36:59 +0900318 platformPublicCorePath := "libsysprop-platform/android_arm64_armv8-a_core_static/gen/sysprop/public/include"
Inseob Kim64c43952019-08-26 16:52:35 +0900319 platformPublicVendorPath := "libsysprop-platform/android_arm64_armv8-a_vendor.VER_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900320
Inseob Kim5cefbd22019-06-08 20:36:59 +0900321 platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_core_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900322
Inseob Kim64c43952019-08-26 16:52:35 +0900323 vendorInternalPath := "libsysprop-vendor/android_arm64_armv8-a_vendor.VER_static/gen/sysprop/include"
Inseob Kim5cefbd22019-06-08 20:36:59 +0900324 vendorPublicPath := "libsysprop-vendor/android_arm64_armv8-a_core_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900325
326 platformClient := ctx.ModuleForTests("cc-client-platform", coreVariant)
327 platformFlags := platformClient.Rule("cc").Args["cFlags"]
328
Jiyong Park5d1598f2019-02-25 22:14:17 +0900329 // platform should use platform's internal header
Inseob Kimc0907f12019-02-08 21:00:45 +0900330 if !strings.Contains(platformFlags, platformInternalPath) {
331 t.Errorf("flags for platform must contain %#v, but was %#v.",
332 platformInternalPath, platformFlags)
333 }
334
Jiyong Park5d1598f2019-02-25 22:14:17 +0900335 platformStaticClient := ctx.ModuleForTests("cc-client-platform-static", coreVariant)
336 platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"]
337
338 // platform-static should use platform's internal header
339 if !strings.Contains(platformStaticFlags, platformInternalPath) {
340 t.Errorf("flags for platform-static must contain %#v, but was %#v.",
341 platformInternalPath, platformStaticFlags)
342 }
343
Inseob Kimc0907f12019-02-08 21:00:45 +0900344 productClient := ctx.ModuleForTests("cc-client-product", coreVariant)
345 productFlags := productClient.Rule("cc").Args["cFlags"]
346
Inseob Kim5cefbd22019-06-08 20:36:59 +0900347 // Product should use platform's and vendor's public headers
Inseob Kimc0907f12019-02-08 21:00:45 +0900348 if !strings.Contains(productFlags, platformOnProductPath) ||
Inseob Kim5cefbd22019-06-08 20:36:59 +0900349 !strings.Contains(productFlags, vendorPublicPath) {
Inseob Kimc0907f12019-02-08 21:00:45 +0900350 t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900351 platformPublicCorePath, vendorPublicPath, productFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900352 }
353
354 vendorClient := ctx.ModuleForTests("cc-client-vendor", vendorVariant)
355 vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
356
Inseob Kim5cefbd22019-06-08 20:36:59 +0900357 // Vendor should use platform's public header and vendor's internal header
358 if !strings.Contains(vendorFlags, platformPublicVendorPath) ||
Inseob Kimc0907f12019-02-08 21:00:45 +0900359 !strings.Contains(vendorFlags, vendorInternalPath) {
360 t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900361 platformPublicVendorPath, vendorInternalPath, vendorFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900362 }
363}