Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1 | // 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 | |
| 15 | package sysprop |
| 16 | |
| 17 | import ( |
Paul Duffin | 7b3de8f | 2020-03-30 18:00:25 +0100 | [diff] [blame] | 18 | "reflect" |
| 19 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 20 | "android/soong/android" |
| 21 | "android/soong/cc" |
| 22 | "android/soong/java" |
| 23 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 24 | "io/ioutil" |
| 25 | "os" |
| 26 | "strings" |
| 27 | "testing" |
| 28 | |
| 29 | "github.com/google/blueprint/proptools" |
| 30 | ) |
| 31 | |
| 32 | var buildDir string |
| 33 | |
| 34 | func setUp() { |
| 35 | var err error |
| 36 | buildDir, err = ioutil.TempDir("", "soong_sysprop_test") |
| 37 | if err != nil { |
| 38 | panic(err) |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | func tearDown() { |
| 43 | os.RemoveAll(buildDir) |
| 44 | } |
| 45 | |
| 46 | func TestMain(m *testing.M) { |
| 47 | run := func() int { |
| 48 | setUp() |
| 49 | defer tearDown() |
| 50 | |
| 51 | return m.Run() |
| 52 | } |
| 53 | |
| 54 | os.Exit(run()) |
| 55 | } |
| 56 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 57 | func testContext(config android.Config) *android.TestContext { |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 58 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 59 | ctx := android.NewTestArchContext(config) |
Paul Duffin | c059c8c | 2021-01-20 17:13:52 +0000 | [diff] [blame] | 60 | java.RegisterRequiredBuildComponentsForTest(ctx) |
Paul Duffin | 43dc1cc | 2019-12-19 11:18:54 +0000 | [diff] [blame] | 61 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 62 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 63 | |
Paul Duffin | 021f4e5 | 2020-07-30 16:04:17 +0100 | [diff] [blame] | 64 | android.RegisterPrebuiltMutators(ctx) |
| 65 | |
Paul Duffin | 77980a8 | 2019-12-19 16:01:36 +0000 | [diff] [blame] | 66 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 67 | |
Colin Cross | 4b49b76 | 2019-11-22 15:25:03 -0800 | [diff] [blame] | 68 | ctx.RegisterModuleType("sysprop_library", syspropLibraryFactory) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 69 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 70 | ctx.Register() |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 71 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 72 | return ctx |
| 73 | } |
| 74 | |
| 75 | func run(t *testing.T, ctx *android.TestContext, config android.Config) { |
| 76 | t.Helper() |
| 77 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 78 | android.FailIfErrored(t, errs) |
| 79 | _, errs = ctx.PrepareBuildActions(config) |
| 80 | android.FailIfErrored(t, errs) |
| 81 | } |
| 82 | |
| 83 | func testConfig(env map[string]string, bp string, fs map[string][]byte) android.Config { |
Jiyong Park | 5e914b2 | 2021-03-08 10:09:52 +0900 | [diff] [blame] | 84 | bp += ` |
| 85 | cc_library { |
| 86 | name: "libbase", |
| 87 | host_supported: true, |
| 88 | } |
| 89 | |
| 90 | cc_library_headers { |
| 91 | name: "libbase_headers", |
| 92 | vendor_available: true, |
| 93 | recovery_available: true, |
| 94 | } |
| 95 | |
| 96 | cc_library { |
| 97 | name: "liblog", |
| 98 | no_libcrt: true, |
| 99 | nocrt: true, |
| 100 | system_shared_libs: [], |
| 101 | recovery_available: true, |
| 102 | host_supported: true, |
| 103 | llndk_stubs: "liblog.llndk", |
| 104 | } |
| 105 | |
| 106 | llndk_library { |
| 107 | name: "liblog.llndk", |
| 108 | symbol_file: "", |
| 109 | } |
| 110 | |
| 111 | java_library { |
| 112 | name: "sysprop-library-stub-platform", |
| 113 | sdk_version: "core_current", |
| 114 | } |
| 115 | |
| 116 | java_library { |
| 117 | name: "sysprop-library-stub-vendor", |
| 118 | soc_specific: true, |
| 119 | sdk_version: "core_current", |
| 120 | } |
| 121 | |
| 122 | java_library { |
| 123 | name: "sysprop-library-stub-product", |
| 124 | product_specific: true, |
| 125 | sdk_version: "core_current", |
| 126 | } |
| 127 | ` |
| 128 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 129 | bp += cc.GatherRequiredDepsForTest(android.Android) |
| 130 | |
| 131 | mockFS := map[string][]byte{ |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 132 | "a.java": nil, |
| 133 | "b.java": nil, |
| 134 | "c.java": nil, |
| 135 | "d.cpp": nil, |
| 136 | "api/sysprop-platform-current.txt": nil, |
| 137 | "api/sysprop-platform-latest.txt": nil, |
| 138 | "api/sysprop-platform-on-product-current.txt": nil, |
| 139 | "api/sysprop-platform-on-product-latest.txt": nil, |
| 140 | "api/sysprop-vendor-current.txt": nil, |
| 141 | "api/sysprop-vendor-latest.txt": nil, |
Inseob Kim | fe61218 | 2020-10-20 16:29:55 +0900 | [diff] [blame] | 142 | "api/sysprop-vendor-on-product-current.txt": nil, |
| 143 | "api/sysprop-vendor-on-product-latest.txt": nil, |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 144 | "api/sysprop-odm-current.txt": nil, |
| 145 | "api/sysprop-odm-latest.txt": nil, |
| 146 | "framework/aidl/a.aidl": nil, |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 147 | |
| 148 | // For framework-res, which is an implicit dependency for framework |
Dan Willemsen | 412160e | 2019-04-09 21:36:26 -0700 | [diff] [blame] | 149 | "AndroidManifest.xml": nil, |
| 150 | "build/make/target/product/security/testkey": nil, |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 151 | |
| 152 | "build/soong/scripts/jar-wrapper.sh": nil, |
| 153 | |
| 154 | "build/make/core/proguard.flags": nil, |
| 155 | "build/make/core/proguard_basic_keeps.flags": nil, |
| 156 | |
| 157 | "jdk8/jre/lib/jce.jar": nil, |
| 158 | "jdk8/jre/lib/rt.jar": nil, |
| 159 | "jdk8/lib/tools.jar": nil, |
| 160 | |
| 161 | "bar-doc/a.java": nil, |
| 162 | "bar-doc/b.java": nil, |
| 163 | "bar-doc/IFoo.aidl": nil, |
| 164 | "bar-doc/known_oj_tags.txt": nil, |
| 165 | "external/doclava/templates-sdk": nil, |
| 166 | |
| 167 | "cert/new_cert.x509.pem": nil, |
| 168 | "cert/new_cert.pk8": nil, |
| 169 | |
| 170 | "android/sysprop/PlatformProperties.sysprop": nil, |
| 171 | "com/android/VendorProperties.sysprop": nil, |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 172 | "com/android2/OdmProperties.sysprop": nil, |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | for k, v := range fs { |
| 176 | mockFS[k] = v |
| 177 | } |
| 178 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 179 | config := java.TestConfig(buildDir, env, bp, mockFS) |
Colin Cross | e4759b9 | 2019-02-15 10:37:39 -0800 | [diff] [blame] | 180 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 181 | config.TestProductVariables.DeviceSystemSdkVersions = []string{"28"} |
| 182 | config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current") |
| 183 | config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER") |
Colin Cross | e4759b9 | 2019-02-15 10:37:39 -0800 | [diff] [blame] | 184 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 185 | return config |
| 186 | |
| 187 | } |
| 188 | |
| 189 | func test(t *testing.T, bp string) *android.TestContext { |
| 190 | t.Helper() |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 191 | config := testConfig(nil, bp, nil) |
| 192 | ctx := testContext(config) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 193 | run(t, ctx, config) |
| 194 | |
| 195 | return ctx |
| 196 | } |
| 197 | |
| 198 | func TestSyspropLibrary(t *testing.T) { |
| 199 | ctx := test(t, ` |
| 200 | sysprop_library { |
| 201 | name: "sysprop-platform", |
Paul Duffin | 7b3de8f | 2020-03-30 18:00:25 +0100 | [diff] [blame] | 202 | apex_available: ["//apex_available:platform"], |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 203 | srcs: ["android/sysprop/PlatformProperties.sysprop"], |
| 204 | api_packages: ["android.sysprop"], |
| 205 | property_owner: "Platform", |
| 206 | vendor_available: true, |
Inseob Kim | 89db15d | 2020-02-03 18:06:46 +0900 | [diff] [blame] | 207 | host_supported: true, |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | sysprop_library { |
| 211 | name: "sysprop-platform-on-product", |
| 212 | srcs: ["android/sysprop/PlatformProperties.sysprop"], |
| 213 | api_packages: ["android.sysprop"], |
| 214 | property_owner: "Platform", |
| 215 | product_specific: true, |
| 216 | } |
| 217 | |
| 218 | sysprop_library { |
| 219 | name: "sysprop-vendor", |
| 220 | srcs: ["com/android/VendorProperties.sysprop"], |
| 221 | api_packages: ["com.android"], |
| 222 | property_owner: "Vendor", |
Inseob Kim | fe61218 | 2020-10-20 16:29:55 +0900 | [diff] [blame] | 223 | vendor: true, |
| 224 | } |
| 225 | |
| 226 | sysprop_library { |
| 227 | name: "sysprop-vendor-on-product", |
| 228 | srcs: ["com/android/VendorProperties.sysprop"], |
| 229 | api_packages: ["com.android"], |
| 230 | property_owner: "Vendor", |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 231 | product_specific: true, |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 232 | } |
| 233 | |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 234 | sysprop_library { |
| 235 | name: "sysprop-odm", |
| 236 | srcs: ["com/android2/OdmProperties.sysprop"], |
| 237 | api_packages: ["com.android2"], |
| 238 | property_owner: "Odm", |
| 239 | device_specific: true, |
| 240 | } |
| 241 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 242 | java_library { |
| 243 | name: "java-platform", |
| 244 | srcs: ["c.java"], |
| 245 | sdk_version: "system_current", |
| 246 | libs: ["sysprop-platform"], |
| 247 | } |
| 248 | |
| 249 | java_library { |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 250 | name: "java-platform-private", |
| 251 | srcs: ["c.java"], |
| 252 | platform_apis: true, |
| 253 | libs: ["sysprop-platform"], |
| 254 | } |
| 255 | |
| 256 | java_library { |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 257 | name: "java-product", |
| 258 | srcs: ["c.java"], |
| 259 | sdk_version: "system_current", |
| 260 | product_specific: true, |
Inseob Kim | fe61218 | 2020-10-20 16:29:55 +0900 | [diff] [blame] | 261 | libs: ["sysprop-platform", "sysprop-vendor-on-product"], |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | java_library { |
| 265 | name: "java-vendor", |
| 266 | srcs: ["c.java"], |
| 267 | sdk_version: "system_current", |
| 268 | soc_specific: true, |
| 269 | libs: ["sysprop-platform", "sysprop-vendor"], |
| 270 | } |
| 271 | |
| 272 | cc_library { |
| 273 | name: "cc-client-platform", |
| 274 | srcs: ["d.cpp"], |
| 275 | static_libs: ["sysprop-platform"], |
| 276 | } |
| 277 | |
Jiyong Park | 5d1598f | 2019-02-25 22:14:17 +0900 | [diff] [blame] | 278 | cc_library_static { |
| 279 | name: "cc-client-platform-static", |
| 280 | srcs: ["d.cpp"], |
| 281 | whole_static_libs: ["sysprop-platform"], |
| 282 | } |
| 283 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 284 | cc_library { |
| 285 | name: "cc-client-product", |
| 286 | srcs: ["d.cpp"], |
| 287 | product_specific: true, |
Inseob Kim | fe61218 | 2020-10-20 16:29:55 +0900 | [diff] [blame] | 288 | static_libs: ["sysprop-platform-on-product", "sysprop-vendor-on-product"], |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | cc_library { |
| 292 | name: "cc-client-vendor", |
| 293 | srcs: ["d.cpp"], |
| 294 | soc_specific: true, |
| 295 | static_libs: ["sysprop-platform", "sysprop-vendor"], |
| 296 | } |
Inseob Kim | 1f95976 | 2019-03-27 17:20:37 +0900 | [diff] [blame] | 297 | |
Inseob Kim | 89db15d | 2020-02-03 18:06:46 +0900 | [diff] [blame] | 298 | cc_binary_host { |
| 299 | name: "hostbin", |
| 300 | static_libs: ["sysprop-platform"], |
Inseob Kim | 1f95976 | 2019-03-27 17:20:37 +0900 | [diff] [blame] | 301 | } |
Jiyong Park | 5e914b2 | 2021-03-08 10:09:52 +0900 | [diff] [blame] | 302 | `) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 303 | |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 304 | // Check for generated cc_library |
| 305 | for _, variant := range []string{ |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 306 | "android_vendor.VER_arm_armv7-a-neon_shared", |
| 307 | "android_vendor.VER_arm_armv7-a-neon_static", |
| 308 | "android_vendor.VER_arm64_armv8-a_shared", |
| 309 | "android_vendor.VER_arm64_armv8-a_static", |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 310 | } { |
| 311 | ctx.ModuleForTests("libsysprop-platform", variant) |
| 312 | ctx.ModuleForTests("libsysprop-vendor", variant) |
| 313 | ctx.ModuleForTests("libsysprop-odm", variant) |
| 314 | } |
| 315 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 316 | for _, variant := range []string{ |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 317 | "android_arm_armv7-a-neon_shared", |
| 318 | "android_arm_armv7-a-neon_static", |
| 319 | "android_arm64_armv8-a_shared", |
| 320 | "android_arm64_armv8-a_static", |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 321 | } { |
Paul Duffin | 7b3de8f | 2020-03-30 18:00:25 +0100 | [diff] [blame] | 322 | library := ctx.ModuleForTests("libsysprop-platform", variant).Module().(*cc.Module) |
| 323 | expectedApexAvailableOnLibrary := []string{"//apex_available:platform"} |
| 324 | if !reflect.DeepEqual(library.ApexProperties.Apex_available, expectedApexAvailableOnLibrary) { |
| 325 | t.Errorf("apex available property on libsysprop-platform must be %#v, but was %#v.", |
| 326 | expectedApexAvailableOnLibrary, library.ApexProperties.Apex_available) |
| 327 | } |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 328 | |
Inseob Kim | fe61218 | 2020-10-20 16:29:55 +0900 | [diff] [blame] | 329 | // product variant of vendor-owned sysprop_library |
| 330 | ctx.ModuleForTests("libsysprop-vendor-on-product", variant) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | ctx.ModuleForTests("sysprop-platform", "android_common") |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 334 | ctx.ModuleForTests("sysprop-platform_public", "android_common") |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 335 | ctx.ModuleForTests("sysprop-vendor", "android_common") |
Inseob Kim | fe61218 | 2020-10-20 16:29:55 +0900 | [diff] [blame] | 336 | ctx.ModuleForTests("sysprop-vendor-on-product", "android_common") |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 337 | |
| 338 | // Check for exported includes |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 339 | coreVariant := "android_arm64_armv8-a_static" |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 340 | vendorVariant := "android_vendor.VER_arm64_armv8-a_static" |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 341 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 342 | platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/include" |
| 343 | platformPublicCorePath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/public/include" |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 344 | platformPublicVendorPath := "libsysprop-platform/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/public/include" |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 345 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 346 | platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include" |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 347 | |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 348 | vendorInternalPath := "libsysprop-vendor/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/include" |
Inseob Kim | fe61218 | 2020-10-20 16:29:55 +0900 | [diff] [blame] | 349 | vendorPublicPath := "libsysprop-vendor-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include" |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 350 | |
| 351 | platformClient := ctx.ModuleForTests("cc-client-platform", coreVariant) |
| 352 | platformFlags := platformClient.Rule("cc").Args["cFlags"] |
| 353 | |
Jiyong Park | 5d1598f | 2019-02-25 22:14:17 +0900 | [diff] [blame] | 354 | // platform should use platform's internal header |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 355 | if !strings.Contains(platformFlags, platformInternalPath) { |
| 356 | t.Errorf("flags for platform must contain %#v, but was %#v.", |
| 357 | platformInternalPath, platformFlags) |
| 358 | } |
| 359 | |
Jiyong Park | 5d1598f | 2019-02-25 22:14:17 +0900 | [diff] [blame] | 360 | platformStaticClient := ctx.ModuleForTests("cc-client-platform-static", coreVariant) |
| 361 | platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"] |
| 362 | |
| 363 | // platform-static should use platform's internal header |
| 364 | if !strings.Contains(platformStaticFlags, platformInternalPath) { |
| 365 | t.Errorf("flags for platform-static must contain %#v, but was %#v.", |
| 366 | platformInternalPath, platformStaticFlags) |
| 367 | } |
| 368 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 369 | productClient := ctx.ModuleForTests("cc-client-product", coreVariant) |
| 370 | productFlags := productClient.Rule("cc").Args["cFlags"] |
| 371 | |
Inseob Kim | 5cefbd2 | 2019-06-08 20:36:59 +0900 | [diff] [blame] | 372 | // Product should use platform's and vendor's public headers |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 373 | if !strings.Contains(productFlags, platformOnProductPath) || |
Inseob Kim | 5cefbd2 | 2019-06-08 20:36:59 +0900 | [diff] [blame] | 374 | !strings.Contains(productFlags, vendorPublicPath) { |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 375 | t.Errorf("flags for product must contain %#v and %#v, but was %#v.", |
Inseob Kim | 5cefbd2 | 2019-06-08 20:36:59 +0900 | [diff] [blame] | 376 | platformPublicCorePath, vendorPublicPath, productFlags) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | vendorClient := ctx.ModuleForTests("cc-client-vendor", vendorVariant) |
| 380 | vendorFlags := vendorClient.Rule("cc").Args["cFlags"] |
| 381 | |
Inseob Kim | 5cefbd2 | 2019-06-08 20:36:59 +0900 | [diff] [blame] | 382 | // Vendor should use platform's public header and vendor's internal header |
| 383 | if !strings.Contains(vendorFlags, platformPublicVendorPath) || |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 384 | !strings.Contains(vendorFlags, vendorInternalPath) { |
| 385 | t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.", |
Inseob Kim | 5cefbd2 | 2019-06-08 20:36:59 +0900 | [diff] [blame] | 386 | platformPublicVendorPath, vendorInternalPath, vendorFlags) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 387 | } |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 388 | |
| 389 | // Java modules linking against system API should use public stub |
Colin Cross | 75ce9ec | 2021-02-26 16:20:32 -0800 | [diff] [blame] | 390 | javaSystemApiClient := ctx.ModuleForTests("java-platform", "android_common").Rule("javac") |
| 391 | syspropPlatformPublic := ctx.ModuleForTests("sysprop-platform_public", "android_common").Description("for turbine") |
| 392 | if g, w := javaSystemApiClient.Implicits.Strings(), syspropPlatformPublic.Output.String(); !android.InList(w, g) { |
| 393 | t.Errorf("system api client should use public stub %q, got %q", w, g) |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 394 | } |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 395 | } |
Jiyong Park | 5e914b2 | 2021-03-08 10:09:52 +0900 | [diff] [blame] | 396 | |
| 397 | func TestApexAvailabilityIsForwarded(t *testing.T) { |
| 398 | ctx := test(t, ` |
| 399 | sysprop_library { |
| 400 | name: "sysprop-platform", |
| 401 | apex_available: ["//apex_available:platform"], |
| 402 | srcs: ["android/sysprop/PlatformProperties.sysprop"], |
| 403 | api_packages: ["android.sysprop"], |
| 404 | property_owner: "Platform", |
| 405 | } |
| 406 | `) |
| 407 | |
| 408 | expected := []string{"//apex_available:platform"} |
| 409 | |
| 410 | ccModule := ctx.ModuleForTests("libsysprop-platform", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 411 | propFromCc := ccModule.ApexProperties.Apex_available |
| 412 | if !reflect.DeepEqual(propFromCc, expected) { |
| 413 | t.Errorf("apex_available not forwarded to cc module. expected %#v, got %#v", |
| 414 | expected, propFromCc) |
| 415 | } |
| 416 | |
| 417 | javaModule := ctx.ModuleForTests("sysprop-platform", "android_common").Module().(*java.Library) |
| 418 | propFromJava := javaModule.ApexProperties.Apex_available |
| 419 | if !reflect.DeepEqual(propFromJava, expected) { |
| 420 | t.Errorf("apex_available not forwarded to java module. expected %#v, got %#v", |
| 421 | expected, propFromJava) |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | func TestMinSdkVersionIsForwarded(t *testing.T) { |
| 426 | ctx := test(t, ` |
| 427 | sysprop_library { |
| 428 | name: "sysprop-platform", |
| 429 | srcs: ["android/sysprop/PlatformProperties.sysprop"], |
| 430 | api_packages: ["android.sysprop"], |
| 431 | property_owner: "Platform", |
| 432 | cpp: { |
| 433 | min_sdk_version: "29", |
| 434 | }, |
| 435 | java: { |
| 436 | min_sdk_version: "30", |
| 437 | }, |
| 438 | } |
| 439 | `) |
| 440 | |
| 441 | ccModule := ctx.ModuleForTests("libsysprop-platform", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 442 | propFromCc := proptools.String(ccModule.Properties.Min_sdk_version) |
| 443 | if propFromCc != "29" { |
| 444 | t.Errorf("min_sdk_version not forwarded to cc module. expected %#v, got %#v", |
| 445 | "29", propFromCc) |
| 446 | } |
| 447 | |
| 448 | javaModule := ctx.ModuleForTests("sysprop-platform", "android_common").Module().(*java.Library) |
| 449 | propFromJava := javaModule.MinSdkVersion() |
| 450 | if propFromJava != "30" { |
| 451 | t.Errorf("min_sdk_version not forwarded to java module. expected %#v, got %#v", |
| 452 | "30", propFromJava) |
| 453 | } |
| 454 | } |