| Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 1 | // Copyright 2018 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 |  | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 15 | package etc | 
| Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 16 |  | 
|  | 17 | import ( | 
| Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 18 | "fmt" | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 19 | "os" | 
| Patrice Arruda | 300cef9 | 2019-02-22 15:47:57 -0800 | [diff] [blame] | 20 | "path/filepath" | 
| Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 21 | "testing" | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 22 |  | 
| Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 23 | "github.com/google/blueprint/proptools" | 
|  | 24 |  | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 25 | "android/soong/android" | 
| Spandan Das | 756d340 | 2023-06-05 22:49:50 +0000 | [diff] [blame] | 26 | "android/soong/bazel/cquery" | 
| Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 27 | "android/soong/snapshot" | 
| Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 28 | ) | 
|  | 29 |  | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 30 | func TestMain(m *testing.M) { | 
| Paul Duffin | 5f9f771 | 2021-03-15 15:35:49 +0000 | [diff] [blame] | 31 | os.Exit(m.Run()) | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 32 | } | 
|  | 33 |  | 
| Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 34 | var prepareForPrebuiltEtcTest = android.GroupFixturePreparers( | 
| Paul Duffin | 1172fed | 2021-03-08 11:28:18 +0000 | [diff] [blame] | 35 | android.PrepareForTestWithArchMutator, | 
|  | 36 | PrepareForTestWithPrebuiltEtc, | 
|  | 37 | android.FixtureMergeMockFs(android.MockFS{ | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 38 | "foo.conf": nil, | 
|  | 39 | "bar.conf": nil, | 
|  | 40 | "baz.conf": nil, | 
| Paul Duffin | 1172fed | 2021-03-08 11:28:18 +0000 | [diff] [blame] | 41 | }), | 
|  | 42 | ) | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 43 |  | 
| Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 44 | var prepareForPrebuiltEtcSnapshotTest = android.GroupFixturePreparers( | 
|  | 45 | prepareForPrebuiltEtcTest, | 
|  | 46 | android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) { | 
|  | 47 | snapshot.VendorSnapshotImageSingleton.Init(ctx) | 
|  | 48 | snapshot.RecoverySnapshotImageSingleton.Init(ctx) | 
|  | 49 | }), | 
|  | 50 | android.FixtureModifyConfig(func(config android.Config) { | 
|  | 51 | config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current") | 
|  | 52 | config.TestProductVariables.RecoverySnapshotVersion = proptools.StringPtr("current") | 
|  | 53 | }), | 
|  | 54 | ) | 
|  | 55 |  | 
| Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 56 | func TestPrebuiltEtcVariants(t *testing.T) { | 
| Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 57 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` | 
| Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 58 | prebuilt_etc { | 
|  | 59 | name: "foo.conf", | 
|  | 60 | src: "foo.conf", | 
|  | 61 | } | 
|  | 62 | prebuilt_etc { | 
|  | 63 | name: "bar.conf", | 
|  | 64 | src: "bar.conf", | 
|  | 65 | recovery_available: true, | 
|  | 66 | } | 
|  | 67 | prebuilt_etc { | 
|  | 68 | name: "baz.conf", | 
|  | 69 | src: "baz.conf", | 
|  | 70 | recovery: true, | 
|  | 71 | } | 
|  | 72 | `) | 
|  | 73 |  | 
| Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 74 | foo_variants := result.ModuleVariantsForTests("foo.conf") | 
| Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 75 | if len(foo_variants) != 1 { | 
|  | 76 | t.Errorf("expected 1, got %#v", foo_variants) | 
|  | 77 | } | 
|  | 78 |  | 
| Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 79 | bar_variants := result.ModuleVariantsForTests("bar.conf") | 
| Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 80 | if len(bar_variants) != 2 { | 
|  | 81 | t.Errorf("expected 2, got %#v", bar_variants) | 
|  | 82 | } | 
|  | 83 |  | 
| Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 84 | baz_variants := result.ModuleVariantsForTests("baz.conf") | 
| Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 85 | if len(baz_variants) != 1 { | 
| Cole Faust | dff9c14 | 2023-09-01 16:11:47 -0700 | [diff] [blame] | 86 | t.Errorf("expected 1, got %#v", baz_variants) | 
| Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 87 | } | 
|  | 88 | } | 
| Jiyong Park | 139a2e6 | 2018-10-26 21:49:39 +0900 | [diff] [blame] | 89 |  | 
|  | 90 | func TestPrebuiltEtcOutputPath(t *testing.T) { | 
| Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 91 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` | 
| Jiyong Park | 139a2e6 | 2018-10-26 21:49:39 +0900 | [diff] [blame] | 92 | prebuilt_etc { | 
|  | 93 | name: "foo.conf", | 
|  | 94 | src: "foo.conf", | 
|  | 95 | filename: "foo.installed.conf", | 
|  | 96 | } | 
|  | 97 | `) | 
|  | 98 |  | 
| Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 99 | p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc) | 
| Paul Duffin | e84b133 | 2021-03-12 11:59:43 +0000 | [diff] [blame] | 100 | android.AssertStringEquals(t, "output file path", "foo.installed.conf", p.outputFilePath.Base()) | 
| Jiyong Park | 139a2e6 | 2018-10-26 21:49:39 +0900 | [diff] [blame] | 101 | } | 
| Jiyong Park | 1a7cf08 | 2018-11-13 11:59:12 +0900 | [diff] [blame] | 102 |  | 
|  | 103 | func TestPrebuiltEtcGlob(t *testing.T) { | 
| Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 104 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` | 
| Jiyong Park | 1a7cf08 | 2018-11-13 11:59:12 +0900 | [diff] [blame] | 105 | prebuilt_etc { | 
|  | 106 | name: "my_foo", | 
|  | 107 | src: "foo.*", | 
|  | 108 | } | 
|  | 109 | prebuilt_etc { | 
|  | 110 | name: "my_bar", | 
|  | 111 | src: "bar.*", | 
|  | 112 | filename_from_src: true, | 
|  | 113 | } | 
|  | 114 | `) | 
|  | 115 |  | 
| Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 116 | p := result.Module("my_foo", "android_arm64_armv8-a").(*PrebuiltEtc) | 
| Paul Duffin | e84b133 | 2021-03-12 11:59:43 +0000 | [diff] [blame] | 117 | android.AssertStringEquals(t, "my_foo output file path", "my_foo", p.outputFilePath.Base()) | 
| Jiyong Park | 1a7cf08 | 2018-11-13 11:59:12 +0900 | [diff] [blame] | 118 |  | 
| Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 119 | p = result.Module("my_bar", "android_arm64_armv8-a").(*PrebuiltEtc) | 
| Paul Duffin | e84b133 | 2021-03-12 11:59:43 +0000 | [diff] [blame] | 120 | android.AssertStringEquals(t, "my_bar output file path", "bar.conf", p.outputFilePath.Base()) | 
| Jiyong Park | 1a7cf08 | 2018-11-13 11:59:12 +0900 | [diff] [blame] | 121 | } | 
| Anton Hansson | ce0e258 | 2019-02-04 14:19:27 +0000 | [diff] [blame] | 122 |  | 
|  | 123 | func TestPrebuiltEtcAndroidMk(t *testing.T) { | 
| Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 124 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` | 
| Anton Hansson | ce0e258 | 2019-02-04 14:19:27 +0000 | [diff] [blame] | 125 | prebuilt_etc { | 
|  | 126 | name: "foo", | 
|  | 127 | src: "foo.conf", | 
|  | 128 | owner: "abc", | 
|  | 129 | filename_from_src: true, | 
| Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 130 | required: ["modA", "moduleB"], | 
|  | 131 | host_required: ["hostModA", "hostModB"], | 
|  | 132 | target_required: ["targetModA"], | 
| Anton Hansson | ce0e258 | 2019-02-04 14:19:27 +0000 | [diff] [blame] | 133 | } | 
|  | 134 | `) | 
|  | 135 |  | 
| Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 136 | expected := map[string][]string{ | 
|  | 137 | "LOCAL_MODULE":                  {"foo"}, | 
|  | 138 | "LOCAL_MODULE_CLASS":            {"ETC"}, | 
|  | 139 | "LOCAL_MODULE_OWNER":            {"abc"}, | 
|  | 140 | "LOCAL_INSTALLED_MODULE_STEM":   {"foo.conf"}, | 
|  | 141 | "LOCAL_REQUIRED_MODULES":        {"modA", "moduleB"}, | 
|  | 142 | "LOCAL_HOST_REQUIRED_MODULES":   {"hostModA", "hostModB"}, | 
|  | 143 | "LOCAL_TARGET_REQUIRED_MODULES": {"targetModA"}, | 
| Wei Li | 598f92d | 2023-01-04 17:12:24 -0800 | [diff] [blame] | 144 | "LOCAL_SOONG_MODULE_TYPE":       {"prebuilt_etc"}, | 
| Anton Hansson | ce0e258 | 2019-02-04 14:19:27 +0000 | [diff] [blame] | 145 | } | 
|  | 146 |  | 
| Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 147 | mod := result.Module("foo", "android_arm64_armv8-a").(*PrebuiltEtc) | 
|  | 148 | entries := android.AndroidMkEntriesForTest(t, result.TestContext, mod)[0] | 
| Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 149 | for k, expectedValue := range expected { | 
|  | 150 | if value, ok := entries.EntryMap[k]; ok { | 
| Paul Duffin | e84b133 | 2021-03-12 11:59:43 +0000 | [diff] [blame] | 151 | android.AssertDeepEquals(t, k, expectedValue, value) | 
| Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 152 | } else { | 
|  | 153 | t.Errorf("No %s defined, saw %q", k, entries.EntryMap) | 
| Anton Hansson | ce0e258 | 2019-02-04 14:19:27 +0000 | [diff] [blame] | 154 | } | 
|  | 155 | } | 
|  | 156 | } | 
| Jaewoong Jung | 2478818 | 2019-02-04 14:34:10 -0800 | [diff] [blame] | 157 |  | 
| Liz Kammer | 0449a63 | 2020-06-26 10:12:36 -0700 | [diff] [blame] | 158 | func TestPrebuiltEtcRelativeInstallPathInstallDirPath(t *testing.T) { | 
| Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 159 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` | 
| Liz Kammer | 0449a63 | 2020-06-26 10:12:36 -0700 | [diff] [blame] | 160 | prebuilt_etc { | 
|  | 161 | name: "foo.conf", | 
|  | 162 | src: "foo.conf", | 
|  | 163 | relative_install_path: "bar", | 
|  | 164 | } | 
|  | 165 | `) | 
|  | 166 |  | 
| Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 167 | p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc) | 
| Paul Duffin | 5f9f771 | 2021-03-15 15:35:49 +0000 | [diff] [blame] | 168 | expected := "out/soong/target/product/test_device/system/etc/bar" | 
|  | 169 | android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath) | 
| Liz Kammer | 0449a63 | 2020-06-26 10:12:36 -0700 | [diff] [blame] | 170 | } | 
|  | 171 |  | 
|  | 172 | func TestPrebuiltEtcCannotSetRelativeInstallPathAndSubDir(t *testing.T) { | 
| Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 173 | prepareForPrebuiltEtcTest. | 
| Paul Duffin | 1172fed | 2021-03-08 11:28:18 +0000 | [diff] [blame] | 174 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern("relative_install_path is set. Cannot set sub_dir")). | 
|  | 175 | RunTestWithBp(t, ` | 
|  | 176 | prebuilt_etc { | 
|  | 177 | name: "foo.conf", | 
|  | 178 | src: "foo.conf", | 
|  | 179 | sub_dir: "bar", | 
|  | 180 | relative_install_path: "bar", | 
|  | 181 | } | 
|  | 182 | `) | 
| Liz Kammer | 0449a63 | 2020-06-26 10:12:36 -0700 | [diff] [blame] | 183 | } | 
|  | 184 |  | 
| Jaewoong Jung | 2478818 | 2019-02-04 14:34:10 -0800 | [diff] [blame] | 185 | func TestPrebuiltEtcHost(t *testing.T) { | 
| Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 186 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` | 
| Jaewoong Jung | 2478818 | 2019-02-04 14:34:10 -0800 | [diff] [blame] | 187 | prebuilt_etc_host { | 
|  | 188 | name: "foo.conf", | 
|  | 189 | src: "foo.conf", | 
|  | 190 | } | 
|  | 191 | `) | 
|  | 192 |  | 
| Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 193 | buildOS := result.Config.BuildOS.String() | 
| Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 194 | p := result.Module("foo.conf", buildOS+"_common").(*PrebuiltEtc) | 
| Jaewoong Jung | 2478818 | 2019-02-04 14:34:10 -0800 | [diff] [blame] | 195 | if !p.Host() { | 
|  | 196 | t.Errorf("host bit is not set for a prebuilt_etc_host module.") | 
|  | 197 | } | 
|  | 198 | } | 
| Jaewoong Jung | c3fcdb4 | 2019-02-13 05:50:33 -0800 | [diff] [blame] | 199 |  | 
| Colin Cross | 725eac6 | 2022-10-03 15:31:29 -0700 | [diff] [blame] | 200 | func TestPrebuiltEtcAllowMissingDependencies(t *testing.T) { | 
|  | 201 | result := android.GroupFixturePreparers( | 
|  | 202 | prepareForPrebuiltEtcTest, | 
|  | 203 | android.PrepareForTestDisallowNonExistentPaths, | 
|  | 204 | android.FixtureModifyConfig( | 
|  | 205 | func(config android.Config) { | 
|  | 206 | config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true) | 
|  | 207 | }), | 
|  | 208 | ).RunTestWithBp(t, ` | 
|  | 209 | prebuilt_etc { | 
|  | 210 | name: "foo.conf", | 
|  | 211 | filename_from_src: true, | 
|  | 212 | arch: { | 
|  | 213 | x86: { | 
|  | 214 | src: "x86.conf", | 
|  | 215 | }, | 
|  | 216 | }, | 
|  | 217 | } | 
|  | 218 | `) | 
|  | 219 |  | 
|  | 220 | android.AssertStringEquals(t, "expected error rule", "android/soong/android.Error", | 
|  | 221 | result.ModuleForTests("foo.conf", "android_arm64_armv8-a").Output("foo.conf").Rule.String()) | 
|  | 222 | } | 
|  | 223 |  | 
| Inseob Kim | 27408bf | 2021-04-06 21:00:17 +0900 | [diff] [blame] | 224 | func TestPrebuiltRootInstallDirPath(t *testing.T) { | 
|  | 225 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` | 
|  | 226 | prebuilt_root { | 
|  | 227 | name: "foo.conf", | 
|  | 228 | src: "foo.conf", | 
|  | 229 | filename: "foo.conf", | 
|  | 230 | } | 
|  | 231 | `) | 
|  | 232 |  | 
|  | 233 | p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc) | 
|  | 234 | expected := "out/soong/target/product/test_device/system" | 
|  | 235 | android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath) | 
|  | 236 | } | 
|  | 237 |  | 
|  | 238 | func TestPrebuiltRootInstallDirPathValidate(t *testing.T) { | 
|  | 239 | prepareForPrebuiltEtcTest.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern("filename cannot contain separator")).RunTestWithBp(t, ` | 
|  | 240 | prebuilt_root { | 
|  | 241 | name: "foo.conf", | 
|  | 242 | src: "foo.conf", | 
|  | 243 | filename: "foo/bar.conf", | 
|  | 244 | } | 
|  | 245 | `) | 
|  | 246 | } | 
|  | 247 |  | 
| Jaewoong Jung | c3fcdb4 | 2019-02-13 05:50:33 -0800 | [diff] [blame] | 248 | func TestPrebuiltUserShareInstallDirPath(t *testing.T) { | 
| Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 249 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` | 
| Jaewoong Jung | c3fcdb4 | 2019-02-13 05:50:33 -0800 | [diff] [blame] | 250 | prebuilt_usr_share { | 
|  | 251 | name: "foo.conf", | 
|  | 252 | src: "foo.conf", | 
|  | 253 | sub_dir: "bar", | 
|  | 254 | } | 
|  | 255 | `) | 
|  | 256 |  | 
| Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 257 | p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc) | 
| Paul Duffin | 5f9f771 | 2021-03-15 15:35:49 +0000 | [diff] [blame] | 258 | expected := "out/soong/target/product/test_device/system/usr/share/bar" | 
|  | 259 | android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath) | 
| Jaewoong Jung | c3fcdb4 | 2019-02-13 05:50:33 -0800 | [diff] [blame] | 260 | } | 
| Patrice Arruda | 300cef9 | 2019-02-22 15:47:57 -0800 | [diff] [blame] | 261 |  | 
|  | 262 | func TestPrebuiltUserShareHostInstallDirPath(t *testing.T) { | 
| Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 263 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` | 
| Patrice Arruda | 300cef9 | 2019-02-22 15:47:57 -0800 | [diff] [blame] | 264 | prebuilt_usr_share_host { | 
|  | 265 | name: "foo.conf", | 
|  | 266 | src: "foo.conf", | 
|  | 267 | sub_dir: "bar", | 
|  | 268 | } | 
|  | 269 | `) | 
|  | 270 |  | 
| Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 271 | buildOS := result.Config.BuildOS.String() | 
| Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 272 | p := result.Module("foo.conf", buildOS+"_common").(*PrebuiltEtc) | 
| Paul Duffin | 5f9f771 | 2021-03-15 15:35:49 +0000 | [diff] [blame] | 273 | expected := filepath.Join("out/soong/host", result.Config.PrebuiltOS(), "usr", "share", "bar") | 
|  | 274 | android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath) | 
| Patrice Arruda | 300cef9 | 2019-02-22 15:47:57 -0800 | [diff] [blame] | 275 | } | 
| Patrice Arruda | 61583eb | 2019-05-14 08:20:45 -0700 | [diff] [blame] | 276 |  | 
|  | 277 | func TestPrebuiltFontInstallDirPath(t *testing.T) { | 
| Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 278 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` | 
| Patrice Arruda | 61583eb | 2019-05-14 08:20:45 -0700 | [diff] [blame] | 279 | prebuilt_font { | 
|  | 280 | name: "foo.conf", | 
|  | 281 | src: "foo.conf", | 
|  | 282 | } | 
|  | 283 | `) | 
|  | 284 |  | 
| Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 285 | p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc) | 
| Paul Duffin | 5f9f771 | 2021-03-15 15:35:49 +0000 | [diff] [blame] | 286 | expected := "out/soong/target/product/test_device/system/fonts" | 
|  | 287 | android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath) | 
| Patrice Arruda | 61583eb | 2019-05-14 08:20:45 -0700 | [diff] [blame] | 288 | } | 
| Patrice Arruda | 057a8b1 | 2019-06-03 15:29:27 -0700 | [diff] [blame] | 289 |  | 
|  | 290 | func TestPrebuiltFirmwareDirPath(t *testing.T) { | 
| Paul Duffin | 5f9f771 | 2021-03-15 15:35:49 +0000 | [diff] [blame] | 291 | targetPath := "out/soong/target/product/test_device" | 
| Patrice Arruda | 057a8b1 | 2019-06-03 15:29:27 -0700 | [diff] [blame] | 292 | tests := []struct { | 
|  | 293 | description  string | 
|  | 294 | config       string | 
|  | 295 | expectedPath string | 
|  | 296 | }{{ | 
|  | 297 | description: "prebuilt: system firmware", | 
|  | 298 | config: ` | 
|  | 299 | prebuilt_firmware { | 
|  | 300 | name: "foo.conf", | 
|  | 301 | src: "foo.conf", | 
|  | 302 | }`, | 
|  | 303 | expectedPath: filepath.Join(targetPath, "system/etc/firmware"), | 
|  | 304 | }, { | 
|  | 305 | description: "prebuilt: vendor firmware", | 
|  | 306 | config: ` | 
|  | 307 | prebuilt_firmware { | 
|  | 308 | name: "foo.conf", | 
|  | 309 | src: "foo.conf", | 
|  | 310 | soc_specific: true, | 
|  | 311 | sub_dir: "sub_dir", | 
|  | 312 | }`, | 
|  | 313 | expectedPath: filepath.Join(targetPath, "vendor/firmware/sub_dir"), | 
|  | 314 | }} | 
|  | 315 | for _, tt := range tests { | 
|  | 316 | t.Run(tt.description, func(t *testing.T) { | 
| Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 317 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, tt.config) | 
| Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 318 | p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc) | 
| Paul Duffin | 5f9f771 | 2021-03-15 15:35:49 +0000 | [diff] [blame] | 319 | android.AssertPathRelativeToTopEquals(t, "install dir", tt.expectedPath, p.installDirPath) | 
| Patrice Arruda | 057a8b1 | 2019-06-03 15:29:27 -0700 | [diff] [blame] | 320 | }) | 
|  | 321 | } | 
|  | 322 | } | 
| Patrice Arruda | 0f68800 | 2020-06-08 21:40:25 +0000 | [diff] [blame] | 323 |  | 
|  | 324 | func TestPrebuiltDSPDirPath(t *testing.T) { | 
| Paul Duffin | 5f9f771 | 2021-03-15 15:35:49 +0000 | [diff] [blame] | 325 | targetPath := "out/soong/target/product/test_device" | 
| Patrice Arruda | 0f68800 | 2020-06-08 21:40:25 +0000 | [diff] [blame] | 326 | tests := []struct { | 
|  | 327 | description  string | 
|  | 328 | config       string | 
|  | 329 | expectedPath string | 
|  | 330 | }{{ | 
|  | 331 | description: "prebuilt: system dsp", | 
|  | 332 | config: ` | 
|  | 333 | prebuilt_dsp { | 
|  | 334 | name: "foo.conf", | 
|  | 335 | src: "foo.conf", | 
|  | 336 | }`, | 
|  | 337 | expectedPath: filepath.Join(targetPath, "system/etc/dsp"), | 
|  | 338 | }, { | 
|  | 339 | description: "prebuilt: vendor dsp", | 
|  | 340 | config: ` | 
|  | 341 | prebuilt_dsp { | 
|  | 342 | name: "foo.conf", | 
|  | 343 | src: "foo.conf", | 
|  | 344 | soc_specific: true, | 
|  | 345 | sub_dir: "sub_dir", | 
|  | 346 | }`, | 
|  | 347 | expectedPath: filepath.Join(targetPath, "vendor/dsp/sub_dir"), | 
|  | 348 | }} | 
|  | 349 | for _, tt := range tests { | 
|  | 350 | t.Run(tt.description, func(t *testing.T) { | 
| Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 351 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, tt.config) | 
| Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 352 | p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc) | 
| Paul Duffin | 5f9f771 | 2021-03-15 15:35:49 +0000 | [diff] [blame] | 353 | android.AssertPathRelativeToTopEquals(t, "install dir", tt.expectedPath, p.installDirPath) | 
| Patrice Arruda | 0f68800 | 2020-06-08 21:40:25 +0000 | [diff] [blame] | 354 | }) | 
|  | 355 | } | 
|  | 356 | } | 
| Colin Cross | 83ebf23 | 2021-04-09 09:41:23 -0700 | [diff] [blame] | 357 |  | 
|  | 358 | func TestPrebuiltRFSADirPath(t *testing.T) { | 
|  | 359 | targetPath := "out/soong/target/product/test_device" | 
|  | 360 | tests := []struct { | 
|  | 361 | description  string | 
|  | 362 | config       string | 
|  | 363 | expectedPath string | 
|  | 364 | }{{ | 
|  | 365 | description: "prebuilt: system rfsa", | 
|  | 366 | config: ` | 
|  | 367 | prebuilt_rfsa { | 
|  | 368 | name: "foo.conf", | 
|  | 369 | src: "foo.conf", | 
|  | 370 | }`, | 
|  | 371 | expectedPath: filepath.Join(targetPath, "system/lib/rfsa"), | 
|  | 372 | }, { | 
|  | 373 | description: "prebuilt: vendor rfsa", | 
|  | 374 | config: ` | 
|  | 375 | prebuilt_rfsa { | 
|  | 376 | name: "foo.conf", | 
|  | 377 | src: "foo.conf", | 
|  | 378 | soc_specific: true, | 
|  | 379 | sub_dir: "sub_dir", | 
|  | 380 | }`, | 
|  | 381 | expectedPath: filepath.Join(targetPath, "vendor/lib/rfsa/sub_dir"), | 
|  | 382 | }} | 
|  | 383 | for _, tt := range tests { | 
|  | 384 | t.Run(tt.description, func(t *testing.T) { | 
|  | 385 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, tt.config) | 
|  | 386 | p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc) | 
|  | 387 | android.AssertPathRelativeToTopEquals(t, "install dir", tt.expectedPath, p.installDirPath) | 
|  | 388 | }) | 
|  | 389 | } | 
|  | 390 | } | 
| Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 391 |  | 
|  | 392 | func checkIfSnapshotTaken(t *testing.T, result *android.TestResult, image string, moduleName string) { | 
|  | 393 | checkIfSnapshotExistAsExpected(t, result, image, moduleName, true) | 
|  | 394 | } | 
|  | 395 |  | 
|  | 396 | func checkIfSnapshotNotTaken(t *testing.T, result *android.TestResult, image string, moduleName string) { | 
|  | 397 | checkIfSnapshotExistAsExpected(t, result, image, moduleName, false) | 
|  | 398 | } | 
|  | 399 |  | 
|  | 400 | func checkIfSnapshotExistAsExpected(t *testing.T, result *android.TestResult, image string, moduleName string, expectToExist bool) { | 
|  | 401 | snapshotSingleton := result.SingletonForTests(image + "-snapshot") | 
|  | 402 | archType := "arm64" | 
|  | 403 | archVariant := "armv8-a" | 
|  | 404 | archDir := fmt.Sprintf("arch-%s", archType) | 
|  | 405 |  | 
|  | 406 | snapshotDir := fmt.Sprintf("%s-snapshot", image) | 
|  | 407 | snapshotVariantPath := filepath.Join(snapshotDir, archType) | 
|  | 408 | outputDir := filepath.Join(snapshotVariantPath, archDir, "etc") | 
|  | 409 | imageVariant := "" | 
|  | 410 | if image == "recovery" { | 
|  | 411 | imageVariant = "recovery_" | 
|  | 412 | } | 
|  | 413 | mod := result.ModuleForTests(moduleName, fmt.Sprintf("android_%s%s_%s", imageVariant, archType, archVariant)) | 
|  | 414 | outputFiles := mod.OutputFiles(t, "") | 
|  | 415 | if len(outputFiles) != 1 { | 
|  | 416 | t.Errorf("%q must have single output\n", moduleName) | 
|  | 417 | return | 
|  | 418 | } | 
|  | 419 | snapshotPath := filepath.Join(outputDir, moduleName) | 
|  | 420 |  | 
|  | 421 | if expectToExist { | 
|  | 422 | out := snapshotSingleton.Output(snapshotPath) | 
|  | 423 |  | 
|  | 424 | if out.Input.String() != outputFiles[0].String() { | 
|  | 425 | t.Errorf("The input of snapshot %q must be %q, but %q", "prebuilt_vendor", out.Input.String(), outputFiles[0]) | 
|  | 426 | } | 
|  | 427 |  | 
|  | 428 | snapshotJsonPath := snapshotPath + ".json" | 
|  | 429 |  | 
|  | 430 | if snapshotSingleton.MaybeOutput(snapshotJsonPath).Rule == nil { | 
|  | 431 | t.Errorf("%q expected but not found", snapshotJsonPath) | 
|  | 432 | } | 
|  | 433 | } else { | 
|  | 434 | out := snapshotSingleton.MaybeOutput(snapshotPath) | 
|  | 435 | if out.Rule != nil { | 
|  | 436 | t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0]) | 
|  | 437 | } | 
|  | 438 | } | 
|  | 439 | } | 
|  | 440 |  | 
|  | 441 | func TestPrebuiltTakeSnapshot(t *testing.T) { | 
|  | 442 | var testBp = ` | 
|  | 443 | prebuilt_etc { | 
|  | 444 | name: "prebuilt_vendor", | 
|  | 445 | src: "foo.conf", | 
|  | 446 | vendor: true, | 
|  | 447 | } | 
|  | 448 |  | 
|  | 449 | prebuilt_etc { | 
|  | 450 | name: "prebuilt_vendor_indirect", | 
|  | 451 | src: "foo.conf", | 
|  | 452 | vendor: true, | 
|  | 453 | } | 
|  | 454 |  | 
|  | 455 | prebuilt_etc { | 
|  | 456 | name: "prebuilt_recovery", | 
|  | 457 | src: "bar.conf", | 
|  | 458 | recovery: true, | 
|  | 459 | } | 
|  | 460 |  | 
|  | 461 | prebuilt_etc { | 
|  | 462 | name: "prebuilt_recovery_indirect", | 
|  | 463 | src: "bar.conf", | 
|  | 464 | recovery: true, | 
|  | 465 | } | 
|  | 466 | ` | 
|  | 467 |  | 
|  | 468 | t.Run("prebuilt: vendor and recovery snapshot", func(t *testing.T) { | 
|  | 469 | result := prepareForPrebuiltEtcSnapshotTest.RunTestWithBp(t, testBp) | 
|  | 470 |  | 
|  | 471 | checkIfSnapshotTaken(t, result, "vendor", "prebuilt_vendor") | 
|  | 472 | checkIfSnapshotTaken(t, result, "vendor", "prebuilt_vendor_indirect") | 
|  | 473 | checkIfSnapshotTaken(t, result, "recovery", "prebuilt_recovery") | 
|  | 474 | checkIfSnapshotTaken(t, result, "recovery", "prebuilt_recovery_indirect") | 
|  | 475 | }) | 
|  | 476 |  | 
|  | 477 | t.Run("prebuilt: directed snapshot", func(t *testing.T) { | 
|  | 478 | prepareForPrebuiltEtcDirectedSnapshotTest := android.GroupFixturePreparers( | 
|  | 479 | prepareForPrebuiltEtcSnapshotTest, | 
|  | 480 | android.FixtureModifyConfig(func(config android.Config) { | 
|  | 481 | config.TestProductVariables.DirectedVendorSnapshot = true | 
|  | 482 | config.TestProductVariables.VendorSnapshotModules = make(map[string]bool) | 
|  | 483 | config.TestProductVariables.VendorSnapshotModules["prebuilt_vendor"] = true | 
|  | 484 | config.TestProductVariables.DirectedRecoverySnapshot = true | 
|  | 485 | config.TestProductVariables.RecoverySnapshotModules = make(map[string]bool) | 
|  | 486 | config.TestProductVariables.RecoverySnapshotModules["prebuilt_recovery"] = true | 
|  | 487 | }), | 
|  | 488 | ) | 
|  | 489 |  | 
|  | 490 | result := prepareForPrebuiltEtcDirectedSnapshotTest.RunTestWithBp(t, testBp) | 
|  | 491 |  | 
|  | 492 | checkIfSnapshotTaken(t, result, "vendor", "prebuilt_vendor") | 
|  | 493 | checkIfSnapshotNotTaken(t, result, "vendor", "prebuilt_vendor_indirect") | 
|  | 494 | checkIfSnapshotTaken(t, result, "recovery", "prebuilt_recovery") | 
|  | 495 | checkIfSnapshotNotTaken(t, result, "recovery", "prebuilt_recovery_indirect") | 
|  | 496 | }) | 
|  | 497 | } | 
| Spandan Das | 756d340 | 2023-06-05 22:49:50 +0000 | [diff] [blame] | 498 |  | 
|  | 499 | func TestPrebuiltEtcAndroidMkEntriesWithBazel(t *testing.T) { | 
|  | 500 | t.Parallel() | 
|  | 501 | bp := ` | 
|  | 502 | prebuilt_etc { | 
|  | 503 | name: "myetc", | 
|  | 504 | src: "prebuilt_etc.rc", // filename in src tree | 
|  | 505 | filename: "init.rc", // target filename on device | 
|  | 506 | sub_dir: "subdir", // relative subdir for installation | 
|  | 507 | bazel_module: { label: "//foo/bar:myetc" }, | 
|  | 508 | } | 
|  | 509 | ` | 
|  | 510 | res := android.GroupFixturePreparers( | 
|  | 511 | prepareForPrebuiltEtcTest, | 
|  | 512 | android.FixtureModifyConfig(func(cfg android.Config) { | 
|  | 513 | cfg.BazelContext = android.MockBazelContext{ | 
|  | 514 | LabelToPrebuiltFileInfo: map[string]cquery.PrebuiltFileInfo{ | 
|  | 515 | "//foo/bar:myetc": cquery.PrebuiltFileInfo{ | 
|  | 516 | Src:         "foo/bar/prebuilt_etc.rc", | 
|  | 517 | Dir:         "etc/subdir", | 
|  | 518 | Filename:    "init.rc", | 
|  | 519 | Installable: true, | 
|  | 520 | }, | 
|  | 521 | }, | 
|  | 522 | } | 
|  | 523 | }), | 
|  | 524 | ).RunTestWithBp(t, bp) | 
|  | 525 | ctx := res.ModuleForTests("myetc", "android_arm64_armv8-a") | 
|  | 526 | mod := ctx.Module() | 
|  | 527 | entries := android.AndroidMkEntriesForTest(t, res.TestContext, mod)[0] | 
|  | 528 | // verify androidmk entries | 
|  | 529 | android.AssertStringDoesContain(t, "LOCAL_MODULE_PATH should contain", entries.EntryMap["LOCAL_MODULE_PATH"][0], "etc/subdir") | 
|  | 530 | android.AssertStringEquals(t, "LOCAL_INSTALLED_MODULE_STEM is incorrect", "init.rc", entries.EntryMap["LOCAL_INSTALLED_MODULE_STEM"][0]) | 
|  | 531 | // verify installation rules | 
|  | 532 | install := ctx.Description("install") | 
|  | 533 | android.AssertStringEquals(t, "Source location of prebuilt_etc installation", "out/soong/.intermediates/myetc/android_arm64_armv8-a/init.rc", install.Input.String()) | 
|  | 534 | android.AssertStringEquals(t, "Target location of prebuilt_etc installation", "out/soong/target/product/test_device/system/etc/subdir/init.rc", install.Output.String()) | 
|  | 535 | } |