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