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