Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 1 | // Copyright 2020 Google Inc. All rights reserved. |
| 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 java |
| 16 | |
| 17 | import ( |
| 18 | "reflect" |
| 19 | "strings" |
| 20 | "testing" |
| 21 | |
| 22 | "android/soong/android" |
Lukacs T. Berki | 7690c09 | 2021-02-26 14:27:36 +0100 | [diff] [blame] | 23 | "android/soong/shared" |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 24 | ) |
| 25 | |
| 26 | func TestRuntimeResourceOverlay(t *testing.T) { |
Paul Duffin | 0342dc9 | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 27 | fs := android.MockFS{ |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 28 | "baz/res/res/values/strings.xml": nil, |
| 29 | "bar/res/res/values/strings.xml": nil, |
| 30 | } |
| 31 | bp := ` |
| 32 | runtime_resource_overlay { |
| 33 | name: "foo", |
| 34 | certificate: "platform", |
| 35 | lineage: "lineage.bin", |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 36 | rotationMinSdkVersion: "32", |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 37 | product_specific: true, |
| 38 | static_libs: ["bar"], |
| 39 | resource_libs: ["baz"], |
| 40 | aaptflags: ["--keep-raw-values"], |
| 41 | } |
| 42 | |
| 43 | runtime_resource_overlay { |
| 44 | name: "foo_themed", |
| 45 | certificate: "platform", |
| 46 | product_specific: true, |
| 47 | theme: "faza", |
| 48 | overrides: ["foo"], |
| 49 | } |
| 50 | |
| 51 | android_library { |
| 52 | name: "bar", |
| 53 | resource_dirs: ["bar/res"], |
| 54 | } |
| 55 | |
| 56 | android_app { |
| 57 | name: "baz", |
| 58 | sdk_version: "current", |
| 59 | resource_dirs: ["baz/res"], |
| 60 | } |
Paul Duffin | 0342dc9 | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 61 | ` |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 62 | |
Paul Duffin | 0342dc9 | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 63 | result := android.GroupFixturePreparers( |
| 64 | PrepareForTestWithJavaDefaultModules, |
| 65 | PrepareForTestWithOverlayBuildComponents, |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 66 | android.FixtureModifyConfig(android.SetKatiEnabledForTests), |
Paul Duffin | 0342dc9 | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 67 | fs.AddToFixture(), |
| 68 | ).RunTestWithBp(t, bp) |
| 69 | |
| 70 | m := result.ModuleForTests("foo", "android_common") |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 71 | |
| 72 | // Check AAPT2 link flags. |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 73 | aapt2Flags := m.Output("package-res.apk").Args["flags"] |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 74 | expectedFlags := []string{"--keep-raw-values", "--no-resource-deduping", "--no-resource-removal"} |
| 75 | absentFlags := android.RemoveListFromList(expectedFlags, strings.Split(aapt2Flags, " ")) |
| 76 | if len(absentFlags) > 0 { |
| 77 | t.Errorf("expected values, %q are missing in aapt2 link flags, %q", absentFlags, aapt2Flags) |
| 78 | } |
| 79 | |
| 80 | // Check overlay.list output for static_libs dependency. |
Paul Duffin | 0342dc9 | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 81 | overlayList := android.PathsRelativeToTop(m.Output("aapt2/overlay.list").Inputs) |
| 82 | staticLibPackage := "out/soong/.intermediates/bar/android_common/package-res.apk" |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 83 | if !inList(staticLibPackage, overlayList) { |
| 84 | t.Errorf("Stactic lib res package %q missing in overlay list: %q", staticLibPackage, overlayList) |
| 85 | } |
| 86 | |
| 87 | // Check AAPT2 link flags for resource_libs dependency. |
Paul Duffin | 0342dc9 | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 88 | resourceLibFlag := "-I " + "out/soong/.intermediates/baz/android_common/package-res.apk" |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 89 | if !strings.Contains(aapt2Flags, resourceLibFlag) { |
| 90 | t.Errorf("Resource lib flag %q missing in aapt2 link flags: %q", resourceLibFlag, aapt2Flags) |
| 91 | } |
| 92 | |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 93 | // Check cert signing flags. |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 94 | signedApk := m.Output("signed/foo.apk") |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 95 | actualCertSigningFlags := signedApk.Args["flags"] |
| 96 | expectedCertSigningFlags := "--lineage lineage.bin --rotation-min-sdk-version 32" |
| 97 | if expectedCertSigningFlags != actualCertSigningFlags { |
| 98 | t.Errorf("Incorrect cert signing flags, expected: %q, got: %q", expectedCertSigningFlags, actualCertSigningFlags) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 99 | } |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 100 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 101 | signingFlag := signedApk.Args["certificates"] |
| 102 | expected := "build/make/target/product/security/platform.x509.pem build/make/target/product/security/platform.pk8" |
| 103 | if expected != signingFlag { |
| 104 | t.Errorf("Incorrect signing flags, expected: %q, got: %q", expected, signingFlag) |
| 105 | } |
Paul Duffin | 0342dc9 | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 106 | androidMkEntries := android.AndroidMkEntriesForTest(t, result.TestContext, m.Module())[0] |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 107 | path := androidMkEntries.EntryMap["LOCAL_CERTIFICATE"] |
| 108 | expectedPath := []string{"build/make/target/product/security/platform.x509.pem"} |
| 109 | if !reflect.DeepEqual(path, expectedPath) { |
| 110 | t.Errorf("Unexpected LOCAL_CERTIFICATE value: %v, expected: %v", path, expectedPath) |
| 111 | } |
| 112 | |
| 113 | // Check device location. |
| 114 | path = androidMkEntries.EntryMap["LOCAL_MODULE_PATH"] |
Paul Duffin | 0342dc9 | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 115 | expectedPath = []string{shared.JoinPath("out/target/product/test_device/product/overlay")} |
| 116 | android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_MODULE_PATH", result.Config, expectedPath, path) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 117 | |
| 118 | // A themed module has a different device location |
Paul Duffin | 0342dc9 | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 119 | m = result.ModuleForTests("foo_themed", "android_common") |
| 120 | androidMkEntries = android.AndroidMkEntriesForTest(t, result.TestContext, m.Module())[0] |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 121 | path = androidMkEntries.EntryMap["LOCAL_MODULE_PATH"] |
Paul Duffin | 0342dc9 | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 122 | expectedPath = []string{shared.JoinPath("out/target/product/test_device/product/overlay/faza")} |
| 123 | android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_MODULE_PATH", result.Config, expectedPath, path) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 124 | |
| 125 | overrides := androidMkEntries.EntryMap["LOCAL_OVERRIDES_PACKAGES"] |
| 126 | expectedOverrides := []string{"foo"} |
| 127 | if !reflect.DeepEqual(overrides, expectedOverrides) { |
| 128 | t.Errorf("Unexpected LOCAL_OVERRIDES_PACKAGES value: %v, expected: %v", overrides, expectedOverrides) |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | func TestRuntimeResourceOverlay_JavaDefaults(t *testing.T) { |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 133 | result := android.GroupFixturePreparers( |
| 134 | PrepareForTestWithJavaDefaultModules, |
| 135 | android.FixtureModifyConfig(android.SetKatiEnabledForTests), |
| 136 | ).RunTestWithBp(t, ` |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 137 | java_defaults { |
| 138 | name: "rro_defaults", |
| 139 | theme: "default_theme", |
| 140 | product_specific: true, |
| 141 | aaptflags: ["--keep-raw-values"], |
| 142 | } |
| 143 | |
| 144 | runtime_resource_overlay { |
| 145 | name: "foo_with_defaults", |
| 146 | defaults: ["rro_defaults"], |
| 147 | } |
| 148 | |
| 149 | runtime_resource_overlay { |
| 150 | name: "foo_barebones", |
| 151 | } |
| 152 | `) |
| 153 | |
| 154 | // |
| 155 | // RRO module with defaults |
| 156 | // |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 157 | m := result.ModuleForTests("foo_with_defaults", "android_common") |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 158 | |
| 159 | // Check AAPT2 link flags. |
| 160 | aapt2Flags := strings.Split(m.Output("package-res.apk").Args["flags"], " ") |
| 161 | expectedFlags := []string{"--keep-raw-values", "--no-resource-deduping", "--no-resource-removal"} |
| 162 | absentFlags := android.RemoveListFromList(expectedFlags, aapt2Flags) |
| 163 | if len(absentFlags) > 0 { |
| 164 | t.Errorf("expected values, %q are missing in aapt2 link flags, %q", absentFlags, aapt2Flags) |
| 165 | } |
| 166 | |
| 167 | // Check device location. |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 168 | path := android.AndroidMkEntriesForTest(t, result.TestContext, m.Module())[0].EntryMap["LOCAL_MODULE_PATH"] |
Paul Duffin | 0342dc9 | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 169 | expectedPath := []string{shared.JoinPath("out/target/product/test_device/product/overlay/default_theme")} |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 170 | android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_MODULE_PATH", result.Config, expectedPath, path) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 171 | |
| 172 | // |
| 173 | // RRO module without defaults |
| 174 | // |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 175 | m = result.ModuleForTests("foo_barebones", "android_common") |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 176 | |
| 177 | // Check AAPT2 link flags. |
| 178 | aapt2Flags = strings.Split(m.Output("package-res.apk").Args["flags"], " ") |
| 179 | unexpectedFlags := "--keep-raw-values" |
| 180 | if inList(unexpectedFlags, aapt2Flags) { |
| 181 | t.Errorf("unexpected value, %q is present in aapt2 link flags, %q", unexpectedFlags, aapt2Flags) |
| 182 | } |
| 183 | |
| 184 | // Check device location. |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 185 | path = android.AndroidMkEntriesForTest(t, result.TestContext, m.Module())[0].EntryMap["LOCAL_MODULE_PATH"] |
Spandan Das | 5d1b929 | 2021-06-03 19:36:41 +0000 | [diff] [blame] | 186 | expectedPath = []string{shared.JoinPath("out/target/product/test_device/product/overlay")} |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 187 | android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_MODULE_PATH", result.Config, expectedPath, path) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | func TestOverrideRuntimeResourceOverlay(t *testing.T) { |
| 191 | ctx, _ := testJava(t, ` |
| 192 | runtime_resource_overlay { |
| 193 | name: "foo_overlay", |
| 194 | certificate: "platform", |
| 195 | product_specific: true, |
| 196 | sdk_version: "current", |
| 197 | } |
| 198 | |
| 199 | override_runtime_resource_overlay { |
| 200 | name: "bar_overlay", |
| 201 | base: "foo_overlay", |
| 202 | package_name: "com.android.bar.overlay", |
| 203 | target_package_name: "com.android.bar", |
| 204 | } |
| 205 | `) |
| 206 | |
| 207 | expectedVariants := []struct { |
| 208 | moduleName string |
| 209 | variantName string |
| 210 | apkPath string |
| 211 | overrides []string |
| 212 | targetVariant string |
| 213 | packageFlag string |
| 214 | targetPackageFlag string |
| 215 | }{ |
| 216 | { |
| 217 | variantName: "android_common", |
Paul Duffin | 0342dc9 | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 218 | apkPath: "out/soong/target/product/test_device/product/overlay/foo_overlay.apk", |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 219 | overrides: nil, |
| 220 | targetVariant: "android_common", |
| 221 | packageFlag: "", |
| 222 | targetPackageFlag: "", |
| 223 | }, |
| 224 | { |
| 225 | variantName: "android_common_bar_overlay", |
Paul Duffin | 0342dc9 | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 226 | apkPath: "out/soong/target/product/test_device/product/overlay/bar_overlay.apk", |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 227 | overrides: []string{"foo_overlay"}, |
| 228 | targetVariant: "android_common_bar", |
| 229 | packageFlag: "com.android.bar.overlay", |
| 230 | targetPackageFlag: "com.android.bar", |
| 231 | }, |
| 232 | } |
| 233 | for _, expected := range expectedVariants { |
| 234 | variant := ctx.ModuleForTests("foo_overlay", expected.variantName) |
| 235 | |
| 236 | // Check the final apk name |
Paul Duffin | 0342dc9 | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 237 | variant.Output(expected.apkPath) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 238 | |
| 239 | // Check if the overrides field values are correctly aggregated. |
| 240 | mod := variant.Module().(*RuntimeResourceOverlay) |
| 241 | if !reflect.DeepEqual(expected.overrides, mod.properties.Overrides) { |
| 242 | t.Errorf("Incorrect overrides property value, expected: %q, got: %q", |
| 243 | expected.overrides, mod.properties.Overrides) |
| 244 | } |
| 245 | |
| 246 | // Check aapt2 flags. |
| 247 | res := variant.Output("package-res.apk") |
| 248 | aapt2Flags := res.Args["flags"] |
| 249 | checkAapt2LinkFlag(t, aapt2Flags, "rename-manifest-package", expected.packageFlag) |
| 250 | checkAapt2LinkFlag(t, aapt2Flags, "rename-resources-package", "") |
| 251 | checkAapt2LinkFlag(t, aapt2Flags, "rename-overlay-target-package", expected.targetPackageFlag) |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | func TestEnforceRRO_propagatesToDependencies(t *testing.T) { |
| 256 | testCases := []struct { |
Jeongik Cha | cee5ba9 | 2021-02-19 12:11:51 +0900 | [diff] [blame] | 257 | name string |
| 258 | enforceRROTargets []string |
| 259 | rroDirs map[string][]string |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 260 | }{ |
| 261 | { |
Jeongik Cha | cee5ba9 | 2021-02-19 12:11:51 +0900 | [diff] [blame] | 262 | name: "no RRO", |
| 263 | enforceRROTargets: nil, |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 264 | rroDirs: map[string][]string{ |
| 265 | "foo": nil, |
| 266 | "bar": nil, |
| 267 | }, |
| 268 | }, |
| 269 | { |
Jeongik Cha | cee5ba9 | 2021-02-19 12:11:51 +0900 | [diff] [blame] | 270 | name: "enforce RRO on all", |
| 271 | enforceRROTargets: []string{"*"}, |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 272 | rroDirs: map[string][]string{ |
| 273 | "foo": {"product/vendor/blah/overlay/lib2/res"}, |
| 274 | "bar": {"product/vendor/blah/overlay/lib2/res"}, |
| 275 | }, |
| 276 | }, |
| 277 | { |
Jeongik Cha | cee5ba9 | 2021-02-19 12:11:51 +0900 | [diff] [blame] | 278 | name: "enforce RRO on foo", |
| 279 | enforceRROTargets: []string{"foo"}, |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 280 | rroDirs: map[string][]string{ |
| 281 | "foo": {"product/vendor/blah/overlay/lib2/res"}, |
| 282 | "bar": {"product/vendor/blah/overlay/lib2/res"}, |
| 283 | }, |
| 284 | }, |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | productResourceOverlays := []string{ |
| 288 | "product/vendor/blah/overlay", |
| 289 | } |
| 290 | |
Paul Duffin | 0342dc9 | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 291 | fs := android.MockFS{ |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 292 | "lib2/res/values/strings.xml": nil, |
| 293 | "product/vendor/blah/overlay/lib2/res/values/strings.xml": nil, |
| 294 | } |
| 295 | |
| 296 | bp := ` |
| 297 | android_app { |
| 298 | name: "foo", |
| 299 | sdk_version: "current", |
| 300 | resource_dirs: [], |
| 301 | static_libs: ["lib"], |
| 302 | } |
| 303 | |
| 304 | android_app { |
| 305 | name: "bar", |
| 306 | sdk_version: "current", |
| 307 | resource_dirs: [], |
| 308 | static_libs: ["lib"], |
| 309 | } |
| 310 | |
| 311 | android_library { |
| 312 | name: "lib", |
| 313 | sdk_version: "current", |
| 314 | resource_dirs: [], |
| 315 | static_libs: ["lib2"], |
| 316 | } |
| 317 | |
| 318 | android_library { |
| 319 | name: "lib2", |
| 320 | sdk_version: "current", |
| 321 | resource_dirs: ["lib2/res"], |
| 322 | } |
| 323 | ` |
| 324 | |
| 325 | for _, testCase := range testCases { |
| 326 | t.Run(testCase.name, func(t *testing.T) { |
Paul Duffin | 0342dc9 | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 327 | result := android.GroupFixturePreparers( |
| 328 | PrepareForTestWithJavaDefaultModules, |
| 329 | PrepareForTestWithOverlayBuildComponents, |
| 330 | fs.AddToFixture(), |
| 331 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 332 | variables.ProductResourceOverlays = productResourceOverlays |
| 333 | if testCase.enforceRROTargets != nil { |
| 334 | variables.EnforceRROTargets = testCase.enforceRROTargets |
| 335 | } |
| 336 | }), |
| 337 | ).RunTestWithBp(t, bp) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 338 | |
| 339 | modules := []string{"foo", "bar"} |
| 340 | for _, moduleName := range modules { |
Paul Duffin | 0342dc9 | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 341 | module := result.ModuleForTests(moduleName, "android_common") |
| 342 | mkEntries := android.AndroidMkEntriesForTest(t, result.TestContext, module.Module())[0] |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 343 | actualRRODirs := mkEntries.EntryMap["LOCAL_SOONG_PRODUCT_RRO_DIRS"] |
| 344 | if !reflect.DeepEqual(actualRRODirs, testCase.rroDirs[moduleName]) { |
| 345 | t.Errorf("exected %s LOCAL_SOONG_PRODUCT_RRO_DIRS entry: %v\ngot:%q", |
| 346 | moduleName, testCase.rroDirs[moduleName], actualRRODirs) |
| 347 | } |
| 348 | } |
| 349 | }) |
| 350 | } |
| 351 | } |
Spandan Das | 5d1b929 | 2021-06-03 19:36:41 +0000 | [diff] [blame] | 352 | |
| 353 | func TestRuntimeResourceOverlayPartition(t *testing.T) { |
| 354 | bp := ` |
| 355 | runtime_resource_overlay { |
| 356 | name: "device_specific", |
| 357 | device_specific: true, |
| 358 | } |
| 359 | runtime_resource_overlay { |
| 360 | name: "soc_specific", |
| 361 | soc_specific: true, |
| 362 | } |
| 363 | runtime_resource_overlay { |
| 364 | name: "system_ext_specific", |
| 365 | system_ext_specific: true, |
| 366 | } |
| 367 | runtime_resource_overlay { |
| 368 | name: "product_specific", |
| 369 | product_specific: true, |
| 370 | } |
| 371 | runtime_resource_overlay { |
| 372 | name: "default" |
| 373 | } |
| 374 | ` |
| 375 | testCases := []struct { |
| 376 | name string |
| 377 | expectedPath string |
| 378 | }{ |
| 379 | { |
| 380 | name: "device_specific", |
| 381 | expectedPath: "out/soong/target/product/test_device/odm/overlay", |
| 382 | }, |
| 383 | { |
| 384 | name: "soc_specific", |
| 385 | expectedPath: "out/soong/target/product/test_device/vendor/overlay", |
| 386 | }, |
| 387 | { |
| 388 | name: "system_ext_specific", |
| 389 | expectedPath: "out/soong/target/product/test_device/system_ext/overlay", |
| 390 | }, |
| 391 | { |
| 392 | name: "product_specific", |
| 393 | expectedPath: "out/soong/target/product/test_device/product/overlay", |
| 394 | }, |
| 395 | { |
| 396 | name: "default", |
| 397 | expectedPath: "out/soong/target/product/test_device/product/overlay", |
| 398 | }, |
| 399 | } |
| 400 | for _, testCase := range testCases { |
| 401 | ctx, _ := testJava(t, bp) |
| 402 | mod := ctx.ModuleForTests(testCase.name, "android_common").Module().(*RuntimeResourceOverlay) |
| 403 | android.AssertPathRelativeToTopEquals(t, "Install dir is not correct for "+testCase.name, testCase.expectedPath, mod.installDir) |
| 404 | } |
| 405 | } |