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 ( |
| 18 | "android/soong/android" |
| 19 | "android/soong/cc" |
| 20 | "android/soong/java" |
| 21 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 22 | "io/ioutil" |
| 23 | "os" |
| 24 | "strings" |
| 25 | "testing" |
| 26 | |
| 27 | "github.com/google/blueprint/proptools" |
| 28 | ) |
| 29 | |
| 30 | var buildDir string |
| 31 | |
| 32 | func setUp() { |
| 33 | var err error |
| 34 | buildDir, err = ioutil.TempDir("", "soong_sysprop_test") |
| 35 | if err != nil { |
| 36 | panic(err) |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | func tearDown() { |
| 41 | os.RemoveAll(buildDir) |
| 42 | } |
| 43 | |
| 44 | func 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 | |
| 55 | func testContext(config android.Config, bp string, |
| 56 | fs map[string][]byte) *android.TestContext { |
| 57 | |
| 58 | ctx := android.NewTestArchContext() |
Colin Cross | 4b49b76 | 2019-11-22 15:25:03 -0800 | [diff] [blame] | 59 | ctx.RegisterModuleType("android_app", java.AndroidAppFactory) |
| 60 | ctx.RegisterModuleType("java_library", java.LibraryFactory) |
| 61 | ctx.RegisterModuleType("java_system_modules", java.SystemModulesFactory) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 62 | ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators) |
| 63 | ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators) |
| 64 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 65 | ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) { |
| 66 | ctx.BottomUp("sysprop_deps", syspropDepsMutator).Parallel() |
| 67 | }) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 68 | |
Colin Cross | 4b49b76 | 2019-11-22 15:25:03 -0800 | [diff] [blame] | 69 | 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 Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 75 | ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 76 | ctx.BottomUp("link", cc.LinkageMutator).Parallel() |
| 77 | ctx.BottomUp("vndk", cc.VndkMutator).Parallel() |
| 78 | ctx.BottomUp("version", cc.VersionMutator).Parallel() |
| 79 | ctx.BottomUp("begin", cc.BeginMutator).Parallel() |
| 80 | ctx.BottomUp("sysprop", cc.SyspropMutator).Parallel() |
| 81 | }) |
| 82 | |
Colin Cross | 4b49b76 | 2019-11-22 15:25:03 -0800 | [diff] [blame] | 83 | ctx.RegisterModuleType("sysprop_library", syspropLibraryFactory) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 84 | |
| 85 | ctx.Register() |
| 86 | |
Colin Cross | e4759b9 | 2019-02-15 10:37:39 -0800 | [diff] [blame] | 87 | bp += java.GatherRequiredDepsForTest() |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 88 | bp += cc.GatherRequiredDepsForTest(android.Android) |
| 89 | |
| 90 | mockFS := map[string][]byte{ |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 91 | "Android.bp": []byte(bp), |
| 92 | "a.java": nil, |
| 93 | "b.java": nil, |
| 94 | "c.java": nil, |
| 95 | "d.cpp": nil, |
| 96 | "api/sysprop-platform-current.txt": nil, |
| 97 | "api/sysprop-platform-latest.txt": nil, |
| 98 | "api/sysprop-platform-on-product-current.txt": nil, |
| 99 | "api/sysprop-platform-on-product-latest.txt": nil, |
| 100 | "api/sysprop-vendor-current.txt": nil, |
| 101 | "api/sysprop-vendor-latest.txt": nil, |
| 102 | "api/sysprop-odm-current.txt": nil, |
| 103 | "api/sysprop-odm-latest.txt": nil, |
| 104 | "framework/aidl/a.aidl": nil, |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 105 | |
| 106 | // For framework-res, which is an implicit dependency for framework |
Dan Willemsen | 412160e | 2019-04-09 21:36:26 -0700 | [diff] [blame] | 107 | "AndroidManifest.xml": nil, |
| 108 | "build/make/target/product/security/testkey": nil, |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 109 | |
| 110 | "build/soong/scripts/jar-wrapper.sh": nil, |
| 111 | |
| 112 | "build/make/core/proguard.flags": nil, |
| 113 | "build/make/core/proguard_basic_keeps.flags": nil, |
| 114 | |
| 115 | "jdk8/jre/lib/jce.jar": nil, |
| 116 | "jdk8/jre/lib/rt.jar": nil, |
| 117 | "jdk8/lib/tools.jar": nil, |
| 118 | |
| 119 | "bar-doc/a.java": nil, |
| 120 | "bar-doc/b.java": nil, |
| 121 | "bar-doc/IFoo.aidl": nil, |
| 122 | "bar-doc/known_oj_tags.txt": nil, |
| 123 | "external/doclava/templates-sdk": nil, |
| 124 | |
| 125 | "cert/new_cert.x509.pem": nil, |
| 126 | "cert/new_cert.pk8": nil, |
| 127 | |
| 128 | "android/sysprop/PlatformProperties.sysprop": nil, |
| 129 | "com/android/VendorProperties.sysprop": nil, |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 130 | "com/android2/OdmProperties.sysprop": nil, |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | for k, v := range fs { |
| 134 | mockFS[k] = v |
| 135 | } |
| 136 | |
| 137 | ctx.MockFileSystem(mockFS) |
| 138 | |
| 139 | return ctx |
| 140 | } |
| 141 | |
| 142 | func run(t *testing.T, ctx *android.TestContext, config android.Config) { |
| 143 | t.Helper() |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 144 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 145 | android.FailIfErrored(t, errs) |
| 146 | _, errs = ctx.PrepareBuildActions(config) |
| 147 | android.FailIfErrored(t, errs) |
| 148 | } |
| 149 | |
| 150 | func testConfig(env map[string]string) android.Config { |
Colin Cross | e4759b9 | 2019-02-15 10:37:39 -0800 | [diff] [blame] | 151 | config := java.TestConfig(buildDir, env) |
| 152 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 153 | config.TestProductVariables.DeviceSystemSdkVersions = []string{"28"} |
| 154 | config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current") |
| 155 | config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER") |
Colin Cross | e4759b9 | 2019-02-15 10:37:39 -0800 | [diff] [blame] | 156 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 157 | return config |
| 158 | |
| 159 | } |
| 160 | |
| 161 | func test(t *testing.T, bp string) *android.TestContext { |
| 162 | t.Helper() |
| 163 | config := testConfig(nil) |
| 164 | ctx := testContext(config, bp, nil) |
| 165 | run(t, ctx, config) |
| 166 | |
| 167 | return ctx |
| 168 | } |
| 169 | |
| 170 | func TestSyspropLibrary(t *testing.T) { |
| 171 | ctx := test(t, ` |
| 172 | sysprop_library { |
| 173 | name: "sysprop-platform", |
| 174 | srcs: ["android/sysprop/PlatformProperties.sysprop"], |
| 175 | api_packages: ["android.sysprop"], |
| 176 | property_owner: "Platform", |
| 177 | vendor_available: true, |
| 178 | } |
| 179 | |
| 180 | sysprop_library { |
| 181 | name: "sysprop-platform-on-product", |
| 182 | srcs: ["android/sysprop/PlatformProperties.sysprop"], |
| 183 | api_packages: ["android.sysprop"], |
| 184 | property_owner: "Platform", |
| 185 | product_specific: true, |
| 186 | } |
| 187 | |
| 188 | sysprop_library { |
| 189 | name: "sysprop-vendor", |
| 190 | srcs: ["com/android/VendorProperties.sysprop"], |
| 191 | api_packages: ["com.android"], |
| 192 | property_owner: "Vendor", |
| 193 | product_specific: true, |
| 194 | vendor_available: true, |
| 195 | } |
| 196 | |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 197 | sysprop_library { |
| 198 | name: "sysprop-odm", |
| 199 | srcs: ["com/android2/OdmProperties.sysprop"], |
| 200 | api_packages: ["com.android2"], |
| 201 | property_owner: "Odm", |
| 202 | device_specific: true, |
| 203 | } |
| 204 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 205 | java_library { |
| 206 | name: "java-platform", |
| 207 | srcs: ["c.java"], |
| 208 | sdk_version: "system_current", |
| 209 | libs: ["sysprop-platform"], |
| 210 | } |
| 211 | |
| 212 | java_library { |
| 213 | name: "java-product", |
| 214 | srcs: ["c.java"], |
| 215 | sdk_version: "system_current", |
| 216 | product_specific: true, |
| 217 | libs: ["sysprop-platform", "sysprop-vendor"], |
| 218 | } |
| 219 | |
| 220 | java_library { |
| 221 | name: "java-vendor", |
| 222 | srcs: ["c.java"], |
| 223 | sdk_version: "system_current", |
| 224 | soc_specific: true, |
| 225 | libs: ["sysprop-platform", "sysprop-vendor"], |
| 226 | } |
| 227 | |
| 228 | cc_library { |
| 229 | name: "cc-client-platform", |
| 230 | srcs: ["d.cpp"], |
| 231 | static_libs: ["sysprop-platform"], |
| 232 | } |
| 233 | |
Jiyong Park | 5d1598f | 2019-02-25 22:14:17 +0900 | [diff] [blame] | 234 | cc_library_static { |
| 235 | name: "cc-client-platform-static", |
| 236 | srcs: ["d.cpp"], |
| 237 | whole_static_libs: ["sysprop-platform"], |
| 238 | } |
| 239 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 240 | cc_library { |
| 241 | name: "cc-client-product", |
| 242 | srcs: ["d.cpp"], |
| 243 | product_specific: true, |
| 244 | static_libs: ["sysprop-platform-on-product", "sysprop-vendor"], |
| 245 | } |
| 246 | |
| 247 | cc_library { |
| 248 | name: "cc-client-vendor", |
| 249 | srcs: ["d.cpp"], |
| 250 | soc_specific: true, |
| 251 | static_libs: ["sysprop-platform", "sysprop-vendor"], |
| 252 | } |
Inseob Kim | 1f95976 | 2019-03-27 17:20:37 +0900 | [diff] [blame] | 253 | |
| 254 | cc_library_headers { |
| 255 | name: "libbase_headers", |
| 256 | vendor_available: true, |
| 257 | recovery_available: true, |
| 258 | } |
| 259 | |
| 260 | cc_library { |
| 261 | name: "liblog", |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 262 | no_libcrt: true, |
Inseob Kim | 1f95976 | 2019-03-27 17:20:37 +0900 | [diff] [blame] | 263 | nocrt: true, |
| 264 | system_shared_libs: [], |
| 265 | recovery_available: true, |
| 266 | } |
| 267 | |
| 268 | llndk_library { |
| 269 | name: "liblog", |
| 270 | symbol_file: "", |
| 271 | } |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 272 | |
| 273 | java_library { |
| 274 | name: "sysprop-library-stub-platform", |
| 275 | sdk_version: "core_current", |
| 276 | } |
| 277 | |
| 278 | java_library { |
| 279 | name: "sysprop-library-stub-vendor", |
| 280 | soc_specific: true, |
| 281 | sdk_version: "core_current", |
| 282 | } |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 283 | `) |
| 284 | |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 285 | // Check for generated cc_library |
| 286 | for _, variant := range []string{ |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 287 | "android_arm_armv7-a-neon_vendor.VER_shared", |
| 288 | "android_arm_armv7-a-neon_vendor.VER_static", |
| 289 | "android_arm64_armv8-a_vendor.VER_shared", |
| 290 | "android_arm64_armv8-a_vendor.VER_static", |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 291 | } { |
| 292 | ctx.ModuleForTests("libsysprop-platform", variant) |
| 293 | ctx.ModuleForTests("libsysprop-vendor", variant) |
| 294 | ctx.ModuleForTests("libsysprop-odm", variant) |
| 295 | } |
| 296 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 297 | for _, variant := range []string{ |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame^] | 298 | "android_arm_armv7-a-neon_shared", |
| 299 | "android_arm_armv7-a-neon_static", |
| 300 | "android_arm64_armv8-a_shared", |
| 301 | "android_arm64_armv8-a_static", |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 302 | } { |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 303 | ctx.ModuleForTests("libsysprop-platform", variant) |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 304 | |
| 305 | // core variant of vendor-owned sysprop_library is for product |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 306 | ctx.ModuleForTests("libsysprop-vendor", variant) |
| 307 | } |
| 308 | |
| 309 | ctx.ModuleForTests("sysprop-platform", "android_common") |
| 310 | ctx.ModuleForTests("sysprop-vendor", "android_common") |
| 311 | |
| 312 | // Check for exported includes |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame^] | 313 | coreVariant := "android_arm64_armv8-a_static" |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 314 | vendorVariant := "android_arm64_armv8-a_vendor.VER_static" |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 315 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame^] | 316 | platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/include" |
| 317 | platformPublicCorePath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/public/include" |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 318 | platformPublicVendorPath := "libsysprop-platform/android_arm64_armv8-a_vendor.VER_static/gen/sysprop/public/include" |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 319 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame^] | 320 | 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] | 321 | |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 322 | vendorInternalPath := "libsysprop-vendor/android_arm64_armv8-a_vendor.VER_static/gen/sysprop/include" |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame^] | 323 | vendorPublicPath := "libsysprop-vendor/android_arm64_armv8-a_static/gen/sysprop/public/include" |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 324 | |
| 325 | platformClient := ctx.ModuleForTests("cc-client-platform", coreVariant) |
| 326 | platformFlags := platformClient.Rule("cc").Args["cFlags"] |
| 327 | |
Jiyong Park | 5d1598f | 2019-02-25 22:14:17 +0900 | [diff] [blame] | 328 | // platform should use platform's internal header |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 329 | if !strings.Contains(platformFlags, platformInternalPath) { |
| 330 | t.Errorf("flags for platform must contain %#v, but was %#v.", |
| 331 | platformInternalPath, platformFlags) |
| 332 | } |
| 333 | |
Jiyong Park | 5d1598f | 2019-02-25 22:14:17 +0900 | [diff] [blame] | 334 | platformStaticClient := ctx.ModuleForTests("cc-client-platform-static", coreVariant) |
| 335 | platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"] |
| 336 | |
| 337 | // platform-static should use platform's internal header |
| 338 | if !strings.Contains(platformStaticFlags, platformInternalPath) { |
| 339 | t.Errorf("flags for platform-static must contain %#v, but was %#v.", |
| 340 | platformInternalPath, platformStaticFlags) |
| 341 | } |
| 342 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 343 | productClient := ctx.ModuleForTests("cc-client-product", coreVariant) |
| 344 | productFlags := productClient.Rule("cc").Args["cFlags"] |
| 345 | |
Inseob Kim | 5cefbd2 | 2019-06-08 20:36:59 +0900 | [diff] [blame] | 346 | // Product should use platform's and vendor's public headers |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 347 | if !strings.Contains(productFlags, platformOnProductPath) || |
Inseob Kim | 5cefbd2 | 2019-06-08 20:36:59 +0900 | [diff] [blame] | 348 | !strings.Contains(productFlags, vendorPublicPath) { |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 349 | 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] | 350 | platformPublicCorePath, vendorPublicPath, productFlags) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | vendorClient := ctx.ModuleForTests("cc-client-vendor", vendorVariant) |
| 354 | vendorFlags := vendorClient.Rule("cc").Args["cFlags"] |
| 355 | |
Inseob Kim | 5cefbd2 | 2019-06-08 20:36:59 +0900 | [diff] [blame] | 356 | // Vendor should use platform's public header and vendor's internal header |
| 357 | if !strings.Contains(vendorFlags, platformPublicVendorPath) || |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 358 | !strings.Contains(vendorFlags, vendorInternalPath) { |
| 359 | 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] | 360 | platformPublicVendorPath, vendorInternalPath, vendorFlags) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 361 | } |
| 362 | } |