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