blob: cb1e362305208c1ec718ddd29efd0b350decff42 [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 (
Paul Duffin9cbbbb82021-03-18 00:21:03 +000018 "os"
19 "strings"
20 "testing"
Paul Duffin7b3de8f2020-03-30 18:00:25 +010021
Inseob Kimc0907f12019-02-08 21:00:45 +090022 "android/soong/android"
23 "android/soong/cc"
24 "android/soong/java"
25
Inseob Kimc0907f12019-02-08 21:00:45 +090026 "github.com/google/blueprint/proptools"
27)
28
Inseob Kimc0907f12019-02-08 21:00:45 +090029func TestMain(m *testing.M) {
Paul Duffin9cbbbb82021-03-18 00:21:03 +000030 os.Exit(m.Run())
Inseob Kimc0907f12019-02-08 21:00:45 +090031}
32
Paul Duffin9cbbbb82021-03-18 00:21:03 +000033var emptyFixtureFactory = android.NewFixtureFactory(nil)
Inseob Kimc0907f12019-02-08 21:00:45 +090034
Paul Duffin9cbbbb82021-03-18 00:21:03 +000035func test(t *testing.T, bp string) *android.TestResult {
Colin Cross98be1bb2019-12-13 20:41:13 -080036 t.Helper()
Colin Cross98be1bb2019-12-13 20:41:13 -080037
Jiyong Park5e914b22021-03-08 10:09:52 +090038 bp += `
39 cc_library {
40 name: "libbase",
41 host_supported: true,
42 }
43
44 cc_library_headers {
45 name: "libbase_headers",
46 vendor_available: true,
47 recovery_available: true,
48 }
49
50 cc_library {
51 name: "liblog",
52 no_libcrt: true,
53 nocrt: true,
54 system_shared_libs: [],
55 recovery_available: true,
56 host_supported: true,
57 llndk_stubs: "liblog.llndk",
58 }
59
60 llndk_library {
61 name: "liblog.llndk",
62 symbol_file: "",
63 }
64
65 java_library {
66 name: "sysprop-library-stub-platform",
67 sdk_version: "core_current",
68 }
69
70 java_library {
71 name: "sysprop-library-stub-vendor",
72 soc_specific: true,
73 sdk_version: "core_current",
74 }
75
76 java_library {
77 name: "sysprop-library-stub-product",
78 product_specific: true,
79 sdk_version: "core_current",
80 }
81 `
82
Paul Duffin9cbbbb82021-03-18 00:21:03 +000083 mockFS := android.MockFS{
Inseob Kim42882742019-07-30 17:55:33 +090084 "a.java": nil,
85 "b.java": nil,
86 "c.java": nil,
87 "d.cpp": nil,
88 "api/sysprop-platform-current.txt": nil,
89 "api/sysprop-platform-latest.txt": nil,
90 "api/sysprop-platform-on-product-current.txt": nil,
91 "api/sysprop-platform-on-product-latest.txt": nil,
92 "api/sysprop-vendor-current.txt": nil,
93 "api/sysprop-vendor-latest.txt": nil,
Inseob Kimfe612182020-10-20 16:29:55 +090094 "api/sysprop-vendor-on-product-current.txt": nil,
95 "api/sysprop-vendor-on-product-latest.txt": nil,
Inseob Kim42882742019-07-30 17:55:33 +090096 "api/sysprop-odm-current.txt": nil,
97 "api/sysprop-odm-latest.txt": nil,
98 "framework/aidl/a.aidl": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +090099
100 // For framework-res, which is an implicit dependency for framework
Dan Willemsen412160e2019-04-09 21:36:26 -0700101 "AndroidManifest.xml": nil,
102 "build/make/target/product/security/testkey": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900103
104 "build/soong/scripts/jar-wrapper.sh": nil,
105
106 "build/make/core/proguard.flags": nil,
107 "build/make/core/proguard_basic_keeps.flags": nil,
108
109 "jdk8/jre/lib/jce.jar": nil,
110 "jdk8/jre/lib/rt.jar": nil,
111 "jdk8/lib/tools.jar": nil,
112
113 "bar-doc/a.java": nil,
114 "bar-doc/b.java": nil,
115 "bar-doc/IFoo.aidl": nil,
116 "bar-doc/known_oj_tags.txt": nil,
117 "external/doclava/templates-sdk": nil,
118
119 "cert/new_cert.x509.pem": nil,
120 "cert/new_cert.pk8": nil,
121
122 "android/sysprop/PlatformProperties.sysprop": nil,
123 "com/android/VendorProperties.sysprop": nil,
Inseob Kim42882742019-07-30 17:55:33 +0900124 "com/android2/OdmProperties.sysprop": nil,
Inseob Kimc0907f12019-02-08 21:00:45 +0900125 }
126
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000127 result := emptyFixtureFactory.RunTest(t,
128 cc.PrepareForTestWithCcDefaultModules,
129 java.PrepareForTestWithJavaDefaultModules,
130 PrepareForTestWithSyspropBuildComponents,
131 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
132 variables.DeviceSystemSdkVersions = []string{"28"}
133 variables.DeviceVndkVersion = proptools.StringPtr("current")
134 variables.Platform_vndk_version = proptools.StringPtr("VER")
135 }),
136 mockFS.AddToFixture(),
137 android.FixtureWithRootAndroidBp(bp),
138 )
Inseob Kimc0907f12019-02-08 21:00:45 +0900139
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000140 return result
Inseob Kimc0907f12019-02-08 21:00:45 +0900141}
142
143func TestSyspropLibrary(t *testing.T) {
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000144 result := test(t, `
Inseob Kimc0907f12019-02-08 21:00:45 +0900145 sysprop_library {
146 name: "sysprop-platform",
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100147 apex_available: ["//apex_available:platform"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900148 srcs: ["android/sysprop/PlatformProperties.sysprop"],
149 api_packages: ["android.sysprop"],
150 property_owner: "Platform",
151 vendor_available: true,
Inseob Kim89db15d2020-02-03 18:06:46 +0900152 host_supported: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900153 }
154
155 sysprop_library {
156 name: "sysprop-platform-on-product",
157 srcs: ["android/sysprop/PlatformProperties.sysprop"],
158 api_packages: ["android.sysprop"],
159 property_owner: "Platform",
160 product_specific: true,
161 }
162
163 sysprop_library {
164 name: "sysprop-vendor",
165 srcs: ["com/android/VendorProperties.sysprop"],
166 api_packages: ["com.android"],
167 property_owner: "Vendor",
Inseob Kimfe612182020-10-20 16:29:55 +0900168 vendor: true,
169 }
170
171 sysprop_library {
172 name: "sysprop-vendor-on-product",
173 srcs: ["com/android/VendorProperties.sysprop"],
174 api_packages: ["com.android"],
175 property_owner: "Vendor",
Inseob Kimc0907f12019-02-08 21:00:45 +0900176 product_specific: true,
Inseob Kimc0907f12019-02-08 21:00:45 +0900177 }
178
Inseob Kim42882742019-07-30 17:55:33 +0900179 sysprop_library {
180 name: "sysprop-odm",
181 srcs: ["com/android2/OdmProperties.sysprop"],
182 api_packages: ["com.android2"],
183 property_owner: "Odm",
184 device_specific: true,
185 }
186
Inseob Kimc0907f12019-02-08 21:00:45 +0900187 java_library {
188 name: "java-platform",
189 srcs: ["c.java"],
190 sdk_version: "system_current",
191 libs: ["sysprop-platform"],
192 }
193
194 java_library {
Inseob Kimac1e9862019-12-09 18:15:47 +0900195 name: "java-platform-private",
196 srcs: ["c.java"],
197 platform_apis: true,
198 libs: ["sysprop-platform"],
199 }
200
201 java_library {
Inseob Kimc0907f12019-02-08 21:00:45 +0900202 name: "java-product",
203 srcs: ["c.java"],
204 sdk_version: "system_current",
205 product_specific: true,
Inseob Kimfe612182020-10-20 16:29:55 +0900206 libs: ["sysprop-platform", "sysprop-vendor-on-product"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900207 }
208
209 java_library {
210 name: "java-vendor",
211 srcs: ["c.java"],
212 sdk_version: "system_current",
213 soc_specific: true,
214 libs: ["sysprop-platform", "sysprop-vendor"],
215 }
216
217 cc_library {
218 name: "cc-client-platform",
219 srcs: ["d.cpp"],
220 static_libs: ["sysprop-platform"],
221 }
222
Jiyong Park5d1598f2019-02-25 22:14:17 +0900223 cc_library_static {
224 name: "cc-client-platform-static",
225 srcs: ["d.cpp"],
226 whole_static_libs: ["sysprop-platform"],
227 }
228
Inseob Kimc0907f12019-02-08 21:00:45 +0900229 cc_library {
230 name: "cc-client-product",
231 srcs: ["d.cpp"],
232 product_specific: true,
Inseob Kimfe612182020-10-20 16:29:55 +0900233 static_libs: ["sysprop-platform-on-product", "sysprop-vendor-on-product"],
Inseob Kimc0907f12019-02-08 21:00:45 +0900234 }
235
236 cc_library {
237 name: "cc-client-vendor",
238 srcs: ["d.cpp"],
239 soc_specific: true,
240 static_libs: ["sysprop-platform", "sysprop-vendor"],
241 }
Inseob Kim1f959762019-03-27 17:20:37 +0900242
Inseob Kim89db15d2020-02-03 18:06:46 +0900243 cc_binary_host {
244 name: "hostbin",
245 static_libs: ["sysprop-platform"],
Inseob Kim1f959762019-03-27 17:20:37 +0900246 }
Jiyong Park5e914b22021-03-08 10:09:52 +0900247 `)
Inseob Kimc0907f12019-02-08 21:00:45 +0900248
Inseob Kim42882742019-07-30 17:55:33 +0900249 // Check for generated cc_library
250 for _, variant := range []string{
Colin Crossfb0c16e2019-11-20 17:12:35 -0800251 "android_vendor.VER_arm_armv7-a-neon_shared",
252 "android_vendor.VER_arm_armv7-a-neon_static",
253 "android_vendor.VER_arm64_armv8-a_shared",
254 "android_vendor.VER_arm64_armv8-a_static",
Inseob Kim42882742019-07-30 17:55:33 +0900255 } {
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000256 result.ModuleForTests("libsysprop-platform", variant)
257 result.ModuleForTests("libsysprop-vendor", variant)
258 result.ModuleForTests("libsysprop-odm", variant)
Inseob Kim42882742019-07-30 17:55:33 +0900259 }
260
Inseob Kimc0907f12019-02-08 21:00:45 +0900261 for _, variant := range []string{
Colin Cross7113d202019-11-20 16:39:12 -0800262 "android_arm_armv7-a-neon_shared",
263 "android_arm_armv7-a-neon_static",
264 "android_arm64_armv8-a_shared",
265 "android_arm64_armv8-a_static",
Inseob Kimc0907f12019-02-08 21:00:45 +0900266 } {
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000267 library := result.ModuleForTests("libsysprop-platform", variant).Module().(*cc.Module)
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100268 expectedApexAvailableOnLibrary := []string{"//apex_available:platform"}
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000269 android.AssertDeepEquals(t, "apex available property on libsysprop-platform", expectedApexAvailableOnLibrary, library.ApexProperties.Apex_available)
Inseob Kim42882742019-07-30 17:55:33 +0900270
Inseob Kimfe612182020-10-20 16:29:55 +0900271 // product variant of vendor-owned sysprop_library
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000272 result.ModuleForTests("libsysprop-vendor-on-product", variant)
Inseob Kimc0907f12019-02-08 21:00:45 +0900273 }
274
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000275 result.ModuleForTests("sysprop-platform", "android_common")
276 result.ModuleForTests("sysprop-platform_public", "android_common")
277 result.ModuleForTests("sysprop-vendor", "android_common")
278 result.ModuleForTests("sysprop-vendor-on-product", "android_common")
Inseob Kimc0907f12019-02-08 21:00:45 +0900279
280 // Check for exported includes
Colin Cross7113d202019-11-20 16:39:12 -0800281 coreVariant := "android_arm64_armv8-a_static"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800282 vendorVariant := "android_vendor.VER_arm64_armv8-a_static"
Inseob Kimc0907f12019-02-08 21:00:45 +0900283
Colin Cross7113d202019-11-20 16:39:12 -0800284 platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/include"
285 platformPublicCorePath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/public/include"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800286 platformPublicVendorPath := "libsysprop-platform/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900287
Colin Cross7113d202019-11-20 16:39:12 -0800288 platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900289
Colin Crossfb0c16e2019-11-20 17:12:35 -0800290 vendorInternalPath := "libsysprop-vendor/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/include"
Inseob Kimfe612182020-10-20 16:29:55 +0900291 vendorPublicPath := "libsysprop-vendor-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
Inseob Kimc0907f12019-02-08 21:00:45 +0900292
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000293 platformClient := result.ModuleForTests("cc-client-platform", coreVariant)
Inseob Kimc0907f12019-02-08 21:00:45 +0900294 platformFlags := platformClient.Rule("cc").Args["cFlags"]
295
Jiyong Park5d1598f2019-02-25 22:14:17 +0900296 // platform should use platform's internal header
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000297 android.AssertStringDoesContain(t, "flags for platform", platformFlags, platformInternalPath)
Inseob Kimc0907f12019-02-08 21:00:45 +0900298
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000299 platformStaticClient := result.ModuleForTests("cc-client-platform-static", coreVariant)
Jiyong Park5d1598f2019-02-25 22:14:17 +0900300 platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"]
301
302 // platform-static should use platform's internal header
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000303 android.AssertStringDoesContain(t, "flags for platform-static", platformStaticFlags, platformInternalPath)
Jiyong Park5d1598f2019-02-25 22:14:17 +0900304
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000305 productClient := result.ModuleForTests("cc-client-product", coreVariant)
Inseob Kimc0907f12019-02-08 21:00:45 +0900306 productFlags := productClient.Rule("cc").Args["cFlags"]
307
Inseob Kim5cefbd22019-06-08 20:36:59 +0900308 // Product should use platform's and vendor's public headers
Inseob Kimc0907f12019-02-08 21:00:45 +0900309 if !strings.Contains(productFlags, platformOnProductPath) ||
Inseob Kim5cefbd22019-06-08 20:36:59 +0900310 !strings.Contains(productFlags, vendorPublicPath) {
Inseob Kimc0907f12019-02-08 21:00:45 +0900311 t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900312 platformPublicCorePath, vendorPublicPath, productFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900313 }
314
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000315 vendorClient := result.ModuleForTests("cc-client-vendor", vendorVariant)
Inseob Kimc0907f12019-02-08 21:00:45 +0900316 vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
317
Inseob Kim5cefbd22019-06-08 20:36:59 +0900318 // Vendor should use platform's public header and vendor's internal header
319 if !strings.Contains(vendorFlags, platformPublicVendorPath) ||
Inseob Kimc0907f12019-02-08 21:00:45 +0900320 !strings.Contains(vendorFlags, vendorInternalPath) {
321 t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
Inseob Kim5cefbd22019-06-08 20:36:59 +0900322 platformPublicVendorPath, vendorInternalPath, vendorFlags)
Inseob Kimc0907f12019-02-08 21:00:45 +0900323 }
Inseob Kimac1e9862019-12-09 18:15:47 +0900324
325 // Java modules linking against system API should use public stub
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000326 javaSystemApiClient := result.ModuleForTests("java-platform", "android_common").Rule("javac")
327 syspropPlatformPublic := result.ModuleForTests("sysprop-platform_public", "android_common").Description("for turbine")
Colin Cross75ce9ec2021-02-26 16:20:32 -0800328 if g, w := javaSystemApiClient.Implicits.Strings(), syspropPlatformPublic.Output.String(); !android.InList(w, g) {
329 t.Errorf("system api client should use public stub %q, got %q", w, g)
Inseob Kimac1e9862019-12-09 18:15:47 +0900330 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900331}
Jiyong Park5e914b22021-03-08 10:09:52 +0900332
333func TestApexAvailabilityIsForwarded(t *testing.T) {
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000334 result := test(t, `
Jiyong Park5e914b22021-03-08 10:09:52 +0900335 sysprop_library {
336 name: "sysprop-platform",
337 apex_available: ["//apex_available:platform"],
338 srcs: ["android/sysprop/PlatformProperties.sysprop"],
339 api_packages: ["android.sysprop"],
340 property_owner: "Platform",
341 }
342 `)
343
344 expected := []string{"//apex_available:platform"}
345
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000346 ccModule := result.ModuleForTests("libsysprop-platform", "android_arm64_armv8-a_shared").Module().(*cc.Module)
Jiyong Park5e914b22021-03-08 10:09:52 +0900347 propFromCc := ccModule.ApexProperties.Apex_available
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000348 android.AssertDeepEquals(t, "apex_available forwarding to cc module", expected, propFromCc)
Jiyong Park5e914b22021-03-08 10:09:52 +0900349
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000350 javaModule := result.ModuleForTests("sysprop-platform", "android_common").Module().(*java.Library)
Jiyong Park5e914b22021-03-08 10:09:52 +0900351 propFromJava := javaModule.ApexProperties.Apex_available
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000352 android.AssertDeepEquals(t, "apex_available forwarding to java module", expected, propFromJava)
Jiyong Park5e914b22021-03-08 10:09:52 +0900353}
354
355func TestMinSdkVersionIsForwarded(t *testing.T) {
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000356 result := test(t, `
Jiyong Park5e914b22021-03-08 10:09:52 +0900357 sysprop_library {
358 name: "sysprop-platform",
359 srcs: ["android/sysprop/PlatformProperties.sysprop"],
360 api_packages: ["android.sysprop"],
361 property_owner: "Platform",
362 cpp: {
363 min_sdk_version: "29",
364 },
365 java: {
366 min_sdk_version: "30",
367 },
368 }
369 `)
370
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000371 ccModule := result.ModuleForTests("libsysprop-platform", "android_arm64_armv8-a_shared").Module().(*cc.Module)
Jiyong Park5e914b22021-03-08 10:09:52 +0900372 propFromCc := proptools.String(ccModule.Properties.Min_sdk_version)
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000373 android.AssertStringEquals(t, "min_sdk_version forwarding to cc module", "29", propFromCc)
Jiyong Park5e914b22021-03-08 10:09:52 +0900374
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000375 javaModule := result.ModuleForTests("sysprop-platform", "android_common").Module().(*java.Library)
Jiyong Park5e914b22021-03-08 10:09:52 +0900376 propFromJava := javaModule.MinSdkVersion()
Paul Duffin9cbbbb82021-03-18 00:21:03 +0000377 android.AssertStringEquals(t, "min_sdk_version forwarding to java module", "30", propFromJava)
Jiyong Park5e914b22021-03-08 10:09:52 +0900378}