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