blob: 5345770a8641f1764906616c5fe02a192deb629a [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()
59 ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(java.AndroidAppFactory))
Inseob Kimc0907f12019-02-08 21:00:45 +090060 ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(java.LibraryFactory))
61 ctx.RegisterModuleType("java_system_modules", android.ModuleFactoryAdaptor(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 Kimc0907f12019-02-08 21:00:45 +090065
66 ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))
Inseob Kim1f959762019-03-27 17:20:37 +090067 ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(cc.LibraryHeaderFactory))
Jiyong Park5d1598f2019-02-25 22:14:17 +090068 ctx.RegisterModuleType("cc_library_static", android.ModuleFactoryAdaptor(cc.LibraryFactory))
Inseob Kimc0907f12019-02-08 21:00:45 +090069 ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory))
70 ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory))
71 ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory))
72 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
73 ctx.BottomUp("image", cc.ImageMutator).Parallel()
74 ctx.BottomUp("link", cc.LinkageMutator).Parallel()
75 ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
76 ctx.BottomUp("version", cc.VersionMutator).Parallel()
77 ctx.BottomUp("begin", cc.BeginMutator).Parallel()
78 ctx.BottomUp("sysprop", cc.SyspropMutator).Parallel()
79 })
80
81 ctx.RegisterModuleType("sysprop_library", android.ModuleFactoryAdaptor(syspropLibraryFactory))
82
83 ctx.Register()
84
Colin Crosse4759b92019-02-15 10:37:39 -080085 bp += java.GatherRequiredDepsForTest()
Inseob Kimc0907f12019-02-08 21:00:45 +090086 bp += cc.GatherRequiredDepsForTest(android.Android)
87
88 mockFS := map[string][]byte{
Inseob Kim42882742019-07-30 17:55:33 +090089 "Android.bp": []byte(bp),
90 "a.java": nil,
91 "b.java": nil,
92 "c.java": nil,
93 "d.cpp": nil,
94 "api/sysprop-platform-current.txt": nil,
95 "api/sysprop-platform-latest.txt": nil,
96 "api/sysprop-platform-on-product-current.txt": nil,
97 "api/sysprop-platform-on-product-latest.txt": nil,
98 "api/sysprop-vendor-current.txt": nil,
99 "api/sysprop-vendor-latest.txt": nil,
100 "api/sysprop-odm-current.txt": nil,
101 "api/sysprop-odm-latest.txt": nil,
102 "framework/aidl/a.aidl": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900103
104 // For framework-res, which is an implicit dependency for framework
Dan Willemsen412160e2019-04-09 21:36:26 -0700105 "AndroidManifest.xml": nil,
106 "build/make/target/product/security/testkey": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900107
108 "build/soong/scripts/jar-wrapper.sh": nil,
109
110 "build/make/core/proguard.flags": nil,
111 "build/make/core/proguard_basic_keeps.flags": nil,
112
113 "jdk8/jre/lib/jce.jar": nil,
114 "jdk8/jre/lib/rt.jar": nil,
115 "jdk8/lib/tools.jar": nil,
116
117 "bar-doc/a.java": nil,
118 "bar-doc/b.java": nil,
119 "bar-doc/IFoo.aidl": nil,
120 "bar-doc/known_oj_tags.txt": nil,
121 "external/doclava/templates-sdk": nil,
122
123 "cert/new_cert.x509.pem": nil,
124 "cert/new_cert.pk8": nil,
125
126 "android/sysprop/PlatformProperties.sysprop": nil,
127 "com/android/VendorProperties.sysprop": nil,
Inseob Kim42882742019-07-30 17:55:33 +0900128 "com/android2/OdmProperties.sysprop": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900129 }
130
131 for k, v := range fs {
132 mockFS[k] = v
133 }
134
135 ctx.MockFileSystem(mockFS)
136
137 return ctx
138}
139
140func run(t *testing.T, ctx *android.TestContext, config android.Config) {
141 t.Helper()
Inseob Kim42882742019-07-30 17:55:33 +0900142 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
Inseob Kimc0907f12019-02-08 21:00:45 +0900143 android.FailIfErrored(t, errs)
144 _, errs = ctx.PrepareBuildActions(config)
145 android.FailIfErrored(t, errs)
146}
147
148func testConfig(env map[string]string) android.Config {
Colin Crosse4759b92019-02-15 10:37:39 -0800149 config := java.TestConfig(buildDir, env)
150
Inseob Kimc0907f12019-02-08 21:00:45 +0900151 config.TestProductVariables.DeviceSystemSdkVersions = []string{"28"}
152 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
153 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
Colin Crosse4759b92019-02-15 10:37:39 -0800154
Inseob Kimc0907f12019-02-08 21:00:45 +0900155 return config
156
157}
158
159func test(t *testing.T, bp string) *android.TestContext {
160 t.Helper()
161 config := testConfig(nil)
162 ctx := testContext(config, bp, nil)
163 run(t, ctx, config)
164
165 return ctx
166}
167
168func TestSyspropLibrary(t *testing.T) {
169 ctx := test(t, `
170 sysprop_library {
171 name: "sysprop-platform",
172 srcs: ["android/sysprop/PlatformProperties.sysprop"],
173 api_packages: ["android.sysprop"],
174 property_owner: "Platform",
175 vendor_available: true,
176 }
177
178 sysprop_library {
179 name: "sysprop-platform-on-product",
180 srcs: ["android/sysprop/PlatformProperties.sysprop"],
181 api_packages: ["android.sysprop"],
182 property_owner: "Platform",
183 product_specific: true,
184 }
185
186 sysprop_library {
187 name: "sysprop-vendor",
188 srcs: ["com/android/VendorProperties.sysprop"],
189 api_packages: ["com.android"],
190 property_owner: "Vendor",
191 product_specific: true,
192 vendor_available: true,
193 }
194
Inseob Kim42882742019-07-30 17:55:33 +0900195 sysprop_library {
196 name: "sysprop-odm",
197 srcs: ["com/android2/OdmProperties.sysprop"],
198 api_packages: ["com.android2"],
199 property_owner: "Odm",
200 device_specific: true,
201 }
202
Inseob Kimc0907f12019-02-08 21:00:45 +0900203 java_library {
204 name: "java-platform",
205 srcs: ["c.java"],
206 sdk_version: "system_current",
207 libs: ["sysprop-platform"],
208 }
209
210 java_library {
211 name: "java-product",
212 srcs: ["c.java"],
213 sdk_version: "system_current",
214 product_specific: true,
215 libs: ["sysprop-platform", "sysprop-vendor"],
216 }
217
218 java_library {
219 name: "java-vendor",
220 srcs: ["c.java"],
221 sdk_version: "system_current",
222 soc_specific: true,
223 libs: ["sysprop-platform", "sysprop-vendor"],
224 }
225
226 cc_library {
227 name: "cc-client-platform",
228 srcs: ["d.cpp"],
229 static_libs: ["sysprop-platform"],
230 }
231
Jiyong Park5d1598f2019-02-25 22:14:17 +0900232 cc_library_static {
233 name: "cc-client-platform-static",
234 srcs: ["d.cpp"],
235 whole_static_libs: ["sysprop-platform"],
236 }
237
Inseob Kimc0907f12019-02-08 21:00:45 +0900238 cc_library {
239 name: "cc-client-product",
240 srcs: ["d.cpp"],
241 product_specific: true,
242 static_libs: ["sysprop-platform-on-product", "sysprop-vendor"],
243 }
244
245 cc_library {
246 name: "cc-client-vendor",
247 srcs: ["d.cpp"],
248 soc_specific: true,
249 static_libs: ["sysprop-platform", "sysprop-vendor"],
250 }
Inseob Kim1f959762019-03-27 17:20:37 +0900251
252 cc_library_headers {
253 name: "libbase_headers",
254 vendor_available: true,
255 recovery_available: true,
256 }
257
258 cc_library {
259 name: "liblog",
Yi Konge7fe9912019-06-02 00:53:50 -0700260 no_libcrt: true,
Inseob Kim1f959762019-03-27 17:20:37 +0900261 nocrt: true,
262 system_shared_libs: [],
263 recovery_available: true,
264 }
265
266 llndk_library {
267 name: "liblog",
268 symbol_file: "",
269 }
Inseob Kim42882742019-07-30 17:55:33 +0900270
271 java_library {
272 name: "sysprop-library-stub-platform",
273 sdk_version: "core_current",
274 }
275
276 java_library {
277 name: "sysprop-library-stub-vendor",
278 soc_specific: true,
279 sdk_version: "core_current",
280 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900281 `)
282
Inseob Kim42882742019-07-30 17:55:33 +0900283 // Check for generated cc_library
284 for _, variant := range []string{
285 "android_arm_armv7-a-neon_vendor_shared",
286 "android_arm_armv7-a-neon_vendor_static",
287 "android_arm64_armv8-a_vendor_shared",
288 "android_arm64_armv8-a_vendor_static",
289 } {
290 ctx.ModuleForTests("libsysprop-platform", variant)
291 ctx.ModuleForTests("libsysprop-vendor", variant)
292 ctx.ModuleForTests("libsysprop-odm", variant)
293 }
294
Inseob Kimc0907f12019-02-08 21:00:45 +0900295 for _, variant := range []string{
296 "android_arm_armv7-a-neon_core_shared",
297 "android_arm_armv7-a-neon_core_static",
Inseob Kimc0907f12019-02-08 21:00:45 +0900298 "android_arm64_armv8-a_core_shared",
299 "android_arm64_armv8-a_core_static",
Inseob Kimc0907f12019-02-08 21:00:45 +0900300 } {
Inseob Kimc0907f12019-02-08 21:00:45 +0900301 ctx.ModuleForTests("libsysprop-platform", variant)
Inseob Kim42882742019-07-30 17:55:33 +0900302
303 // core variant of vendor-owned sysprop_library is for product
Inseob Kimc0907f12019-02-08 21:00:45 +0900304 ctx.ModuleForTests("libsysprop-vendor", variant)
305 }
306
307 ctx.ModuleForTests("sysprop-platform", "android_common")
308 ctx.ModuleForTests("sysprop-vendor", "android_common")
309
310 // Check for exported includes
311 coreVariant := "android_arm64_armv8-a_core_static"
312 vendorVariant := "android_arm64_armv8-a_vendor_static"
313
314 platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_core_static/gen/sysprop/include"
Inseob Kim5cefbd22019-06-08 20:36:59 +0900315 platformPublicCorePath := "libsysprop-platform/android_arm64_armv8-a_core_static/gen/sysprop/public/include"
316 platformPublicVendorPath := "libsysprop-platform/android_arm64_armv8-a_vendor_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900317
Inseob Kim5cefbd22019-06-08 20:36:59 +0900318 platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_core_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900319
320 vendorInternalPath := "libsysprop-vendor/android_arm64_armv8-a_vendor_static/gen/sysprop/include"
Inseob Kim5cefbd22019-06-08 20:36:59 +0900321 vendorPublicPath := "libsysprop-vendor/android_arm64_armv8-a_core_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900322
323 platformClient := ctx.ModuleForTests("cc-client-platform", coreVariant)
324 platformFlags := platformClient.Rule("cc").Args["cFlags"]
325
Jiyong Park5d1598f2019-02-25 22:14:17 +0900326 // platform should use platform's internal header
Inseob Kimc0907f12019-02-08 21:00:45 +0900327 if !strings.Contains(platformFlags, platformInternalPath) {
328 t.Errorf("flags for platform must contain %#v, but was %#v.",
329 platformInternalPath, platformFlags)
330 }
331
Jiyong Park5d1598f2019-02-25 22:14:17 +0900332 platformStaticClient := ctx.ModuleForTests("cc-client-platform-static", coreVariant)
333 platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"]
334
335 // platform-static should use platform's internal header
336 if !strings.Contains(platformStaticFlags, platformInternalPath) {
337 t.Errorf("flags for platform-static must contain %#v, but was %#v.",
338 platformInternalPath, platformStaticFlags)
339 }
340
Inseob Kimc0907f12019-02-08 21:00:45 +0900341 productClient := ctx.ModuleForTests("cc-client-product", coreVariant)
342 productFlags := productClient.Rule("cc").Args["cFlags"]
343
Inseob Kim5cefbd22019-06-08 20:36:59 +0900344 // Product should use platform's and vendor's public headers
Inseob Kimc0907f12019-02-08 21:00:45 +0900345 if !strings.Contains(productFlags, platformOnProductPath) ||
Inseob Kim5cefbd22019-06-08 20:36:59 +0900346 !strings.Contains(productFlags, vendorPublicPath) {
Inseob Kimc0907f12019-02-08 21:00:45 +0900347 t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900348 platformPublicCorePath, vendorPublicPath, productFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900349 }
350
351 vendorClient := ctx.ModuleForTests("cc-client-vendor", vendorVariant)
352 vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
353
Inseob Kim5cefbd22019-06-08 20:36:59 +0900354 // Vendor should use platform's public header and vendor's internal header
355 if !strings.Contains(vendorFlags, platformPublicVendorPath) ||
Inseob Kimc0907f12019-02-08 21:00:45 +0900356 !strings.Contains(vendorFlags, vendorInternalPath) {
357 t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900358 platformPublicVendorPath, vendorInternalPath, vendorFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900359 }
360}