blob: 745e42412b8a3485495a027cad00289437f76439 [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))
60 ctx.RegisterModuleType("droiddoc_template", android.ModuleFactoryAdaptor(java.ExportedDroiddocDirFactory))
61 ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(java.LibraryFactory))
62 ctx.RegisterModuleType("java_system_modules", android.ModuleFactoryAdaptor(java.SystemModulesFactory))
63 ctx.RegisterModuleType("prebuilt_apis", android.ModuleFactoryAdaptor(java.PrebuiltApisFactory))
64 ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
65 ctx.TopDown("load_hooks", android.LoadHookMutator).Parallel()
66 })
67 ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators)
68 ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators)
69 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
70 ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
71 ctx.TopDown("prebuilt_apis", java.PrebuiltApisMutator).Parallel()
72 ctx.TopDown("java_sdk_library", java.SdkLibraryMutator).Parallel()
73 })
74
75 ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))
76 ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory))
77 ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory))
78 ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory))
79 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
80 ctx.BottomUp("image", cc.ImageMutator).Parallel()
81 ctx.BottomUp("link", cc.LinkageMutator).Parallel()
82 ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
83 ctx.BottomUp("version", cc.VersionMutator).Parallel()
84 ctx.BottomUp("begin", cc.BeginMutator).Parallel()
85 ctx.BottomUp("sysprop", cc.SyspropMutator).Parallel()
86 })
87
88 ctx.RegisterModuleType("sysprop_library", android.ModuleFactoryAdaptor(syspropLibraryFactory))
89
90 ctx.Register()
91
Colin Crosse4759b92019-02-15 10:37:39 -080092 bp += java.GatherRequiredDepsForTest()
Inseob Kimc0907f12019-02-08 21:00:45 +090093 bp += cc.GatherRequiredDepsForTest(android.Android)
94
95 mockFS := map[string][]byte{
96 "Android.bp": []byte(bp),
97 "a.java": nil,
98 "b.java": nil,
99 "c.java": nil,
100 "d.cpp": nil,
101 "api/current.txt": nil,
102 "api/removed.txt": nil,
103 "api/system-current.txt": nil,
104 "api/system-removed.txt": nil,
105 "api/test-current.txt": nil,
106 "api/test-removed.txt": nil,
107
108 "prebuilts/sdk/current/core/android.jar": nil,
109 "prebuilts/sdk/current/public/android.jar": nil,
110 "prebuilts/sdk/current/public/framework.aidl": nil,
111 "prebuilts/sdk/current/public/core.jar": nil,
112 "prebuilts/sdk/current/system/android.jar": nil,
113 "prebuilts/sdk/current/test/android.jar": nil,
114 "prebuilts/sdk/28/public/api/sysprop-platform.txt": nil,
115 "prebuilts/sdk/28/system/api/sysprop-platform.txt": nil,
116 "prebuilts/sdk/28/test/api/sysprop-platform.txt": nil,
117 "prebuilts/sdk/28/public/api/sysprop-platform-removed.txt": nil,
118 "prebuilts/sdk/28/system/api/sysprop-platform-removed.txt": nil,
119 "prebuilts/sdk/28/test/api/sysprop-platform-removed.txt": nil,
120 "prebuilts/sdk/28/public/api/sysprop-platform-on-product.txt": nil,
121 "prebuilts/sdk/28/system/api/sysprop-platform-on-product.txt": nil,
122 "prebuilts/sdk/28/test/api/sysprop-platform-on-product.txt": nil,
123 "prebuilts/sdk/28/public/api/sysprop-platform-on-product-removed.txt": nil,
124 "prebuilts/sdk/28/system/api/sysprop-platform-on-product-removed.txt": nil,
125 "prebuilts/sdk/28/test/api/sysprop-platform-on-product-removed.txt": nil,
126 "prebuilts/sdk/28/public/api/sysprop-vendor.txt": nil,
127 "prebuilts/sdk/28/system/api/sysprop-vendor.txt": nil,
128 "prebuilts/sdk/28/test/api/sysprop-vendor.txt": nil,
129 "prebuilts/sdk/28/public/api/sysprop-vendor-removed.txt": nil,
130 "prebuilts/sdk/28/system/api/sysprop-vendor-removed.txt": nil,
131 "prebuilts/sdk/28/test/api/sysprop-vendor-removed.txt": nil,
132 "prebuilts/sdk/tools/core-lambda-stubs.jar": nil,
133 "prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "sdk", api_dirs: ["28", "current"],}`),
134
135 // For framework-res, which is an implicit dependency for framework
136 "AndroidManifest.xml": nil,
137 "build/target/product/security/testkey": nil,
138
139 "build/soong/scripts/jar-wrapper.sh": nil,
140
141 "build/make/core/proguard.flags": nil,
142 "build/make/core/proguard_basic_keeps.flags": nil,
143
144 "jdk8/jre/lib/jce.jar": nil,
145 "jdk8/jre/lib/rt.jar": nil,
146 "jdk8/lib/tools.jar": nil,
147
148 "bar-doc/a.java": nil,
149 "bar-doc/b.java": nil,
150 "bar-doc/IFoo.aidl": nil,
151 "bar-doc/known_oj_tags.txt": nil,
152 "external/doclava/templates-sdk": nil,
153
154 "cert/new_cert.x509.pem": nil,
155 "cert/new_cert.pk8": nil,
156
157 "android/sysprop/PlatformProperties.sysprop": nil,
158 "com/android/VendorProperties.sysprop": nil,
159 }
160
161 for k, v := range fs {
162 mockFS[k] = v
163 }
164
165 ctx.MockFileSystem(mockFS)
166
167 return ctx
168}
169
170func run(t *testing.T, ctx *android.TestContext, config android.Config) {
171 t.Helper()
172 _, errs := ctx.ParseFileList(".", []string{"Android.bp", "prebuilts/sdk/Android.bp"})
173 android.FailIfErrored(t, errs)
174 _, errs = ctx.PrepareBuildActions(config)
175 android.FailIfErrored(t, errs)
176}
177
178func testConfig(env map[string]string) android.Config {
Colin Crosse4759b92019-02-15 10:37:39 -0800179 config := java.TestConfig(buildDir, env)
180
Inseob Kimc0907f12019-02-08 21:00:45 +0900181 config.TestProductVariables.DeviceSystemSdkVersions = []string{"28"}
182 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
183 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
Colin Crosse4759b92019-02-15 10:37:39 -0800184
Inseob Kimc0907f12019-02-08 21:00:45 +0900185 return config
186
187}
188
189func test(t *testing.T, bp string) *android.TestContext {
190 t.Helper()
191 config := testConfig(nil)
192 ctx := testContext(config, bp, nil)
193 run(t, ctx, config)
194
195 return ctx
196}
197
198func TestSyspropLibrary(t *testing.T) {
199 ctx := test(t, `
200 sysprop_library {
201 name: "sysprop-platform",
202 srcs: ["android/sysprop/PlatformProperties.sysprop"],
203 api_packages: ["android.sysprop"],
204 property_owner: "Platform",
205 vendor_available: true,
206 }
207
208 sysprop_library {
209 name: "sysprop-platform-on-product",
210 srcs: ["android/sysprop/PlatformProperties.sysprop"],
211 api_packages: ["android.sysprop"],
212 property_owner: "Platform",
213 product_specific: true,
214 }
215
216 sysprop_library {
217 name: "sysprop-vendor",
218 srcs: ["com/android/VendorProperties.sysprop"],
219 api_packages: ["com.android"],
220 property_owner: "Vendor",
221 product_specific: true,
222 vendor_available: true,
223 }
224
225 java_library {
226 name: "java-platform",
227 srcs: ["c.java"],
228 sdk_version: "system_current",
229 libs: ["sysprop-platform"],
230 }
231
232 java_library {
233 name: "java-product",
234 srcs: ["c.java"],
235 sdk_version: "system_current",
236 product_specific: true,
237 libs: ["sysprop-platform", "sysprop-vendor"],
238 }
239
240 java_library {
241 name: "java-vendor",
242 srcs: ["c.java"],
243 sdk_version: "system_current",
244 soc_specific: true,
245 libs: ["sysprop-platform", "sysprop-vendor"],
246 }
247
248 cc_library {
249 name: "cc-client-platform",
250 srcs: ["d.cpp"],
251 static_libs: ["sysprop-platform"],
252 }
253
254 cc_library {
255 name: "cc-client-product",
256 srcs: ["d.cpp"],
257 product_specific: true,
258 static_libs: ["sysprop-platform-on-product", "sysprop-vendor"],
259 }
260
261 cc_library {
262 name: "cc-client-vendor",
263 srcs: ["d.cpp"],
264 soc_specific: true,
265 static_libs: ["sysprop-platform", "sysprop-vendor"],
266 }
267 `)
268
269 for _, variant := range []string{
270 "android_arm_armv7-a-neon_core_shared",
271 "android_arm_armv7-a-neon_core_static",
272 "android_arm_armv7-a-neon_vendor_shared",
273 "android_arm_armv7-a-neon_vendor_static",
274 "android_arm64_armv8-a_core_shared",
275 "android_arm64_armv8-a_core_static",
276 "android_arm64_armv8-a_vendor_shared",
277 "android_arm64_armv8-a_vendor_static",
278 } {
279 // Check for generated cc_library
280 ctx.ModuleForTests("libsysprop-platform", variant)
281 ctx.ModuleForTests("libsysprop-vendor", variant)
282 }
283
284 ctx.ModuleForTests("sysprop-platform", "android_common")
285 ctx.ModuleForTests("sysprop-vendor", "android_common")
286
287 // Check for exported includes
288 coreVariant := "android_arm64_armv8-a_core_static"
289 vendorVariant := "android_arm64_armv8-a_vendor_static"
290
291 platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_core_static/gen/sysprop/include"
292 platformSystemCorePath := "libsysprop-platform/android_arm64_armv8-a_core_static/gen/sysprop/system/include"
293 platformSystemVendorPath := "libsysprop-platform/android_arm64_armv8-a_vendor_static/gen/sysprop/system/include"
294
295 platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_core_static/gen/sysprop/system/include"
296
297 vendorInternalPath := "libsysprop-vendor/android_arm64_armv8-a_vendor_static/gen/sysprop/include"
298 vendorSystemPath := "libsysprop-vendor/android_arm64_armv8-a_core_static/gen/sysprop/system/include"
299
300 platformClient := ctx.ModuleForTests("cc-client-platform", coreVariant)
301 platformFlags := platformClient.Rule("cc").Args["cFlags"]
302
303 // Platform should use platform's internal header
304 if !strings.Contains(platformFlags, platformInternalPath) {
305 t.Errorf("flags for platform must contain %#v, but was %#v.",
306 platformInternalPath, platformFlags)
307 }
308
309 productClient := ctx.ModuleForTests("cc-client-product", coreVariant)
310 productFlags := productClient.Rule("cc").Args["cFlags"]
311
312 // Product should use platform's and vendor's system headers
313 if !strings.Contains(productFlags, platformOnProductPath) ||
314 !strings.Contains(productFlags, vendorSystemPath) {
315 t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
316 platformSystemCorePath, vendorSystemPath, productFlags)
317 }
318
319 vendorClient := ctx.ModuleForTests("cc-client-vendor", vendorVariant)
320 vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
321
322 // Vendor should use platform's system header and vendor's internal header
323 if !strings.Contains(vendorFlags, platformSystemVendorPath) ||
324 !strings.Contains(vendorFlags, vendorInternalPath) {
325 t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
326 platformSystemVendorPath, vendorInternalPath, vendorFlags)
327 }
328}