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 ( |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 18 | "os" |
Patrice Arruda | 300cef9 | 2019-02-22 15:47:57 -0800 | [diff] [blame] | 19 | "path/filepath" |
Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 20 | "testing" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 21 | |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 22 | "github.com/google/blueprint/proptools" |
| 23 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 24 | "android/soong/android" |
Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 25 | ) |
| 26 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 27 | func TestMain(m *testing.M) { |
Paul Duffin | 5f9f771 | 2021-03-15 15:35:49 +0000 | [diff] [blame] | 28 | os.Exit(m.Run()) |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 29 | } |
| 30 | |
Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 31 | var prepareForPrebuiltEtcTest = android.GroupFixturePreparers( |
Paul Duffin | 1172fed | 2021-03-08 11:28:18 +0000 | [diff] [blame] | 32 | android.PrepareForTestWithArchMutator, |
| 33 | PrepareForTestWithPrebuiltEtc, |
| 34 | android.FixtureMergeMockFs(android.MockFS{ |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 35 | "foo.conf": nil, |
| 36 | "bar.conf": nil, |
| 37 | "baz.conf": nil, |
Paul Duffin | 1172fed | 2021-03-08 11:28:18 +0000 | [diff] [blame] | 38 | }), |
| 39 | ) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 40 | |
Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 41 | func TestPrebuiltEtcVariants(t *testing.T) { |
Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 42 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` |
Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 43 | prebuilt_etc { |
| 44 | name: "foo.conf", |
| 45 | src: "foo.conf", |
| 46 | } |
| 47 | prebuilt_etc { |
| 48 | name: "bar.conf", |
| 49 | src: "bar.conf", |
| 50 | recovery_available: true, |
| 51 | } |
| 52 | prebuilt_etc { |
| 53 | name: "baz.conf", |
| 54 | src: "baz.conf", |
| 55 | recovery: true, |
| 56 | } |
| 57 | `) |
| 58 | |
Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 59 | foo_variants := result.ModuleVariantsForTests("foo.conf") |
Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 60 | if len(foo_variants) != 1 { |
| 61 | t.Errorf("expected 1, got %#v", foo_variants) |
| 62 | } |
| 63 | |
Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 64 | bar_variants := result.ModuleVariantsForTests("bar.conf") |
Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 65 | if len(bar_variants) != 2 { |
| 66 | t.Errorf("expected 2, got %#v", bar_variants) |
| 67 | } |
| 68 | |
Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 69 | baz_variants := result.ModuleVariantsForTests("baz.conf") |
Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 70 | if len(baz_variants) != 1 { |
Cole Faust | dff9c14 | 2023-09-01 16:11:47 -0700 | [diff] [blame] | 71 | t.Errorf("expected 1, got %#v", baz_variants) |
Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 72 | } |
| 73 | } |
Jiyong Park | 139a2e6 | 2018-10-26 21:49:39 +0900 | [diff] [blame] | 74 | |
| 75 | func TestPrebuiltEtcOutputPath(t *testing.T) { |
Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 76 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` |
Jiyong Park | 139a2e6 | 2018-10-26 21:49:39 +0900 | [diff] [blame] | 77 | prebuilt_etc { |
| 78 | name: "foo.conf", |
| 79 | src: "foo.conf", |
| 80 | filename: "foo.installed.conf", |
| 81 | } |
| 82 | `) |
| 83 | |
Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 84 | p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc) |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 85 | android.AssertStringEquals(t, "output file path", "foo.installed.conf", p.outputFilePaths[0].Base()) |
Jiyong Park | 139a2e6 | 2018-10-26 21:49:39 +0900 | [diff] [blame] | 86 | } |
Jiyong Park | 1a7cf08 | 2018-11-13 11:59:12 +0900 | [diff] [blame] | 87 | |
| 88 | func TestPrebuiltEtcGlob(t *testing.T) { |
Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 89 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` |
Jiyong Park | 1a7cf08 | 2018-11-13 11:59:12 +0900 | [diff] [blame] | 90 | prebuilt_etc { |
| 91 | name: "my_foo", |
| 92 | src: "foo.*", |
| 93 | } |
| 94 | prebuilt_etc { |
| 95 | name: "my_bar", |
| 96 | src: "bar.*", |
| 97 | filename_from_src: true, |
| 98 | } |
| 99 | `) |
| 100 | |
Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 101 | p := result.Module("my_foo", "android_arm64_armv8-a").(*PrebuiltEtc) |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 102 | android.AssertStringEquals(t, "my_foo output file path", "my_foo", p.outputFilePaths[0].Base()) |
Jiyong Park | 1a7cf08 | 2018-11-13 11:59:12 +0900 | [diff] [blame] | 103 | |
Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 104 | p = result.Module("my_bar", "android_arm64_armv8-a").(*PrebuiltEtc) |
Thiébaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 105 | android.AssertStringEquals(t, "my_bar output file path", "bar.conf", p.outputFilePaths[0].Base()) |
| 106 | } |
| 107 | |
| 108 | func TestPrebuiltEtcMultipleSrcs(t *testing.T) { |
| 109 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` |
| 110 | prebuilt_etc { |
| 111 | name: "foo", |
| 112 | srcs: ["*.conf"], |
| 113 | } |
| 114 | `) |
| 115 | |
| 116 | p := result.Module("foo", "android_arm64_armv8-a").(*PrebuiltEtc) |
| 117 | android.AssertStringEquals(t, "output file path", "bar.conf", p.outputFilePaths[0].Base()) |
| 118 | android.AssertStringEquals(t, "output file path", "baz.conf", p.outputFilePaths[1].Base()) |
| 119 | android.AssertStringEquals(t, "output file path", "foo.conf", p.outputFilePaths[2].Base()) |
Jiyong Park | 1a7cf08 | 2018-11-13 11:59:12 +0900 | [diff] [blame] | 120 | } |
Anton Hansson | ce0e258 | 2019-02-04 14:19:27 +0000 | [diff] [blame] | 121 | |
Douglas Anderson | 79688ff | 2024-09-27 15:08:33 -0700 | [diff] [blame] | 122 | func TestPrebuiltEtcDsts(t *testing.T) { |
| 123 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` |
| 124 | prebuilt_etc { |
| 125 | name: "foo", |
| 126 | srcs: ["foo.conf", "bar.conf"], |
| 127 | dsts: ["foodir/foo.conf", "bardir/extradir/different.name"], |
| 128 | } |
| 129 | `) |
| 130 | |
| 131 | p := result.Module("foo", "android_arm64_armv8-a").(*PrebuiltEtc) |
| 132 | android.AssertStringEquals(t, "output file path", "foo.conf", p.outputFilePaths[0].Base()) |
| 133 | android.AssertStringEquals(t, "output file path", "different.name", p.outputFilePaths[1].Base()) |
| 134 | |
| 135 | expectedPaths := [...]string{ |
| 136 | "out/soong/target/product/test_device/system/etc/foodir", |
| 137 | "out/soong/target/product/test_device/system/etc/bardir/extradir", |
| 138 | } |
| 139 | android.AssertPathRelativeToTopEquals(t, "install dir", expectedPaths[0], p.installDirPaths[0]) |
| 140 | android.AssertPathRelativeToTopEquals(t, "install dir", expectedPaths[1], p.installDirPaths[1]) |
| 141 | } |
| 142 | |
| 143 | func TestPrebuiltEtcDstsPlusRelativeInstallPath(t *testing.T) { |
| 144 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` |
| 145 | prebuilt_etc { |
| 146 | name: "foo", |
| 147 | srcs: ["foo.conf", "bar.conf"], |
| 148 | dsts: ["foodir/foo.conf", "bardir/extradir/different.name"], |
| 149 | relative_install_path: "somewhere", |
| 150 | } |
| 151 | `) |
| 152 | |
| 153 | p := result.Module("foo", "android_arm64_armv8-a").(*PrebuiltEtc) |
| 154 | android.AssertStringEquals(t, "output file path", "foo.conf", p.outputFilePaths[0].Base()) |
| 155 | android.AssertStringEquals(t, "output file path", "different.name", p.outputFilePaths[1].Base()) |
| 156 | |
| 157 | expectedPaths := [...]string{ |
| 158 | "out/soong/target/product/test_device/system/etc/somewhere/foodir", |
| 159 | "out/soong/target/product/test_device/system/etc/somewhere/bardir/extradir", |
| 160 | } |
| 161 | android.AssertPathRelativeToTopEquals(t, "install dir", expectedPaths[0], p.installDirPaths[0]) |
| 162 | android.AssertPathRelativeToTopEquals(t, "install dir", expectedPaths[1], p.installDirPaths[1]) |
| 163 | } |
| 164 | |
| 165 | func TestPrebuiltEtcDstsSrcGlob(t *testing.T) { |
| 166 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` |
| 167 | prebuilt_etc { |
| 168 | name: "foo", |
| 169 | srcs: ["*.conf"], |
| 170 | dsts: ["a.conf", "b.conf", "c.conf"], |
| 171 | } |
| 172 | `) |
| 173 | |
| 174 | p := result.Module("foo", "android_arm64_armv8-a").(*PrebuiltEtc) |
| 175 | android.AssertStringEquals(t, "output file path", "a.conf", p.outputFilePaths[0].Base()) |
| 176 | android.AssertStringEquals(t, "output file path", "b.conf", p.outputFilePaths[1].Base()) |
| 177 | android.AssertStringEquals(t, "output file path", "c.conf", p.outputFilePaths[2].Base()) |
| 178 | } |
| 179 | |
| 180 | func TestPrebuiltEtcDstsSrcGlobDstsTooShort(t *testing.T) { |
| 181 | prepareForPrebuiltEtcTest. |
| 182 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern("Must have one entry in dsts per source file")). |
| 183 | RunTestWithBp(t, ` |
| 184 | prebuilt_etc { |
| 185 | name: "foo", |
| 186 | srcs: ["*.conf"], |
| 187 | dsts: ["a.conf", "b.conf"], |
| 188 | } |
| 189 | `) |
| 190 | } |
| 191 | |
| 192 | func TestPrebuiltEtcDstsSrcGlobDstsTooLong(t *testing.T) { |
| 193 | prepareForPrebuiltEtcTest. |
| 194 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern("Must have one entry in dsts per source file")). |
| 195 | RunTestWithBp(t, ` |
| 196 | prebuilt_etc { |
| 197 | name: "foo", |
| 198 | srcs: ["*.conf"], |
| 199 | dsts: ["a.conf", "b.conf", "c.conf", "d.conf"], |
| 200 | } |
| 201 | `) |
| 202 | } |
| 203 | |
| 204 | func TestPrebuiltEtcCannotDstsWithSrc(t *testing.T) { |
| 205 | prepareForPrebuiltEtcTest. |
| 206 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern("dsts is set. Must use srcs")). |
| 207 | RunTestWithBp(t, ` |
| 208 | prebuilt_etc { |
| 209 | name: "foo.conf", |
| 210 | src: "foo.conf", |
| 211 | dsts: ["a.conf"], |
| 212 | } |
| 213 | `) |
| 214 | } |
| 215 | |
| 216 | func TestPrebuiltEtcCannotDstsWithFilenameFromSrc(t *testing.T) { |
| 217 | prepareForPrebuiltEtcTest. |
| 218 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern("dsts is set. Cannot set filename_from_src")). |
| 219 | RunTestWithBp(t, ` |
| 220 | prebuilt_etc { |
| 221 | name: "foo.conf", |
| 222 | srcs: ["foo.conf"], |
| 223 | dsts: ["a.conf"], |
| 224 | filename_from_src: true, |
| 225 | } |
| 226 | `) |
| 227 | } |
| 228 | |
Anton Hansson | ce0e258 | 2019-02-04 14:19:27 +0000 | [diff] [blame] | 229 | func TestPrebuiltEtcAndroidMk(t *testing.T) { |
Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 230 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` |
Anton Hansson | ce0e258 | 2019-02-04 14:19:27 +0000 | [diff] [blame] | 231 | prebuilt_etc { |
| 232 | name: "foo", |
| 233 | src: "foo.conf", |
| 234 | owner: "abc", |
| 235 | filename_from_src: true, |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 236 | required: ["modA", "moduleB"], |
| 237 | host_required: ["hostModA", "hostModB"], |
| 238 | target_required: ["targetModA"], |
Anton Hansson | ce0e258 | 2019-02-04 14:19:27 +0000 | [diff] [blame] | 239 | } |
| 240 | `) |
| 241 | |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 242 | expected := map[string][]string{ |
| 243 | "LOCAL_MODULE": {"foo"}, |
| 244 | "LOCAL_MODULE_CLASS": {"ETC"}, |
| 245 | "LOCAL_MODULE_OWNER": {"abc"}, |
| 246 | "LOCAL_INSTALLED_MODULE_STEM": {"foo.conf"}, |
| 247 | "LOCAL_REQUIRED_MODULES": {"modA", "moduleB"}, |
| 248 | "LOCAL_HOST_REQUIRED_MODULES": {"hostModA", "hostModB"}, |
| 249 | "LOCAL_TARGET_REQUIRED_MODULES": {"targetModA"}, |
Wei Li | 598f92d | 2023-01-04 17:12:24 -0800 | [diff] [blame] | 250 | "LOCAL_SOONG_MODULE_TYPE": {"prebuilt_etc"}, |
Anton Hansson | ce0e258 | 2019-02-04 14:19:27 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 253 | mod := result.Module("foo", "android_arm64_armv8-a").(*PrebuiltEtc) |
| 254 | entries := android.AndroidMkEntriesForTest(t, result.TestContext, mod)[0] |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 255 | for k, expectedValue := range expected { |
| 256 | if value, ok := entries.EntryMap[k]; ok { |
Paul Duffin | e84b133 | 2021-03-12 11:59:43 +0000 | [diff] [blame] | 257 | android.AssertDeepEquals(t, k, expectedValue, value) |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 258 | } else { |
| 259 | t.Errorf("No %s defined, saw %q", k, entries.EntryMap) |
Anton Hansson | ce0e258 | 2019-02-04 14:19:27 +0000 | [diff] [blame] | 260 | } |
| 261 | } |
| 262 | } |
Jaewoong Jung | 2478818 | 2019-02-04 14:34:10 -0800 | [diff] [blame] | 263 | |
Liz Kammer | 0449a63 | 2020-06-26 10:12:36 -0700 | [diff] [blame] | 264 | func TestPrebuiltEtcRelativeInstallPathInstallDirPath(t *testing.T) { |
Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 265 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` |
Liz Kammer | 0449a63 | 2020-06-26 10:12:36 -0700 | [diff] [blame] | 266 | prebuilt_etc { |
| 267 | name: "foo.conf", |
| 268 | src: "foo.conf", |
| 269 | relative_install_path: "bar", |
| 270 | } |
| 271 | `) |
| 272 | |
Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 273 | p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc) |
Paul Duffin | 5f9f771 | 2021-03-15 15:35:49 +0000 | [diff] [blame] | 274 | expected := "out/soong/target/product/test_device/system/etc/bar" |
Douglas Anderson | 79688ff | 2024-09-27 15:08:33 -0700 | [diff] [blame] | 275 | android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPaths[0]) |
Liz Kammer | 0449a63 | 2020-06-26 10:12:36 -0700 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | func TestPrebuiltEtcCannotSetRelativeInstallPathAndSubDir(t *testing.T) { |
Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 279 | prepareForPrebuiltEtcTest. |
Paul Duffin | 1172fed | 2021-03-08 11:28:18 +0000 | [diff] [blame] | 280 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern("relative_install_path is set. Cannot set sub_dir")). |
| 281 | RunTestWithBp(t, ` |
| 282 | prebuilt_etc { |
| 283 | name: "foo.conf", |
| 284 | src: "foo.conf", |
| 285 | sub_dir: "bar", |
| 286 | relative_install_path: "bar", |
| 287 | } |
| 288 | `) |
Liz Kammer | 0449a63 | 2020-06-26 10:12:36 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Jaewoong Jung | 2478818 | 2019-02-04 14:34:10 -0800 | [diff] [blame] | 291 | func TestPrebuiltEtcHost(t *testing.T) { |
Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 292 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` |
Jaewoong Jung | 2478818 | 2019-02-04 14:34:10 -0800 | [diff] [blame] | 293 | prebuilt_etc_host { |
| 294 | name: "foo.conf", |
| 295 | src: "foo.conf", |
| 296 | } |
| 297 | `) |
| 298 | |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 299 | buildOS := result.Config.BuildOS.String() |
Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 300 | p := result.Module("foo.conf", buildOS+"_common").(*PrebuiltEtc) |
Jaewoong Jung | 2478818 | 2019-02-04 14:34:10 -0800 | [diff] [blame] | 301 | if !p.Host() { |
| 302 | t.Errorf("host bit is not set for a prebuilt_etc_host module.") |
| 303 | } |
| 304 | } |
Jaewoong Jung | c3fcdb4 | 2019-02-13 05:50:33 -0800 | [diff] [blame] | 305 | |
Colin Cross | 725eac6 | 2022-10-03 15:31:29 -0700 | [diff] [blame] | 306 | func TestPrebuiltEtcAllowMissingDependencies(t *testing.T) { |
| 307 | result := android.GroupFixturePreparers( |
| 308 | prepareForPrebuiltEtcTest, |
| 309 | android.PrepareForTestDisallowNonExistentPaths, |
| 310 | android.FixtureModifyConfig( |
| 311 | func(config android.Config) { |
| 312 | config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true) |
| 313 | }), |
| 314 | ).RunTestWithBp(t, ` |
| 315 | prebuilt_etc { |
| 316 | name: "foo.conf", |
| 317 | filename_from_src: true, |
| 318 | arch: { |
| 319 | x86: { |
| 320 | src: "x86.conf", |
| 321 | }, |
| 322 | }, |
| 323 | } |
| 324 | `) |
| 325 | |
| 326 | android.AssertStringEquals(t, "expected error rule", "android/soong/android.Error", |
| 327 | result.ModuleForTests("foo.conf", "android_arm64_armv8-a").Output("foo.conf").Rule.String()) |
| 328 | } |
| 329 | |
Inseob Kim | 27408bf | 2021-04-06 21:00:17 +0900 | [diff] [blame] | 330 | func TestPrebuiltRootInstallDirPath(t *testing.T) { |
| 331 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` |
| 332 | prebuilt_root { |
| 333 | name: "foo.conf", |
| 334 | src: "foo.conf", |
| 335 | filename: "foo.conf", |
| 336 | } |
| 337 | `) |
| 338 | |
| 339 | p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc) |
| 340 | expected := "out/soong/target/product/test_device/system" |
Douglas Anderson | 79688ff | 2024-09-27 15:08:33 -0700 | [diff] [blame] | 341 | android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPaths[0]) |
Inseob Kim | 27408bf | 2021-04-06 21:00:17 +0900 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | func TestPrebuiltRootInstallDirPathValidate(t *testing.T) { |
| 345 | prepareForPrebuiltEtcTest.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern("filename cannot contain separator")).RunTestWithBp(t, ` |
| 346 | prebuilt_root { |
| 347 | name: "foo.conf", |
| 348 | src: "foo.conf", |
| 349 | filename: "foo/bar.conf", |
| 350 | } |
| 351 | `) |
| 352 | } |
| 353 | |
Nelson Li | 1fb94b2 | 2024-07-09 17:04:52 +0800 | [diff] [blame] | 354 | func TestPrebuiltAvbInstallDirPath(t *testing.T) { |
| 355 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` |
| 356 | prebuilt_avb { |
| 357 | name: "foo.conf", |
| 358 | src: "foo.conf", |
| 359 | filename: "foo.conf", |
| 360 | //recovery: true, |
| 361 | } |
| 362 | `) |
| 363 | |
| 364 | p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc) |
| 365 | expected := "out/soong/target/product/test_device/root/avb" |
Douglas Anderson | 79688ff | 2024-09-27 15:08:33 -0700 | [diff] [blame] | 366 | android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPaths[0]) |
Nelson Li | 1fb94b2 | 2024-07-09 17:04:52 +0800 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | func TestPrebuiltAvdInstallDirPathValidate(t *testing.T) { |
| 370 | prepareForPrebuiltEtcTest.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern("filename cannot contain separator")).RunTestWithBp(t, ` |
| 371 | prebuilt_avb { |
| 372 | name: "foo.conf", |
| 373 | src: "foo.conf", |
| 374 | filename: "foo/bar.conf", |
| 375 | } |
| 376 | `) |
| 377 | } |
| 378 | |
Jaewoong Jung | c3fcdb4 | 2019-02-13 05:50:33 -0800 | [diff] [blame] | 379 | func TestPrebuiltUserShareInstallDirPath(t *testing.T) { |
Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 380 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` |
Jaewoong Jung | c3fcdb4 | 2019-02-13 05:50:33 -0800 | [diff] [blame] | 381 | prebuilt_usr_share { |
| 382 | name: "foo.conf", |
| 383 | src: "foo.conf", |
| 384 | sub_dir: "bar", |
| 385 | } |
| 386 | `) |
| 387 | |
Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 388 | p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc) |
Paul Duffin | 5f9f771 | 2021-03-15 15:35:49 +0000 | [diff] [blame] | 389 | expected := "out/soong/target/product/test_device/system/usr/share/bar" |
Douglas Anderson | 79688ff | 2024-09-27 15:08:33 -0700 | [diff] [blame] | 390 | android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPaths[0]) |
Jaewoong Jung | c3fcdb4 | 2019-02-13 05:50:33 -0800 | [diff] [blame] | 391 | } |
Patrice Arruda | 300cef9 | 2019-02-22 15:47:57 -0800 | [diff] [blame] | 392 | |
| 393 | func TestPrebuiltUserShareHostInstallDirPath(t *testing.T) { |
Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 394 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` |
Patrice Arruda | 300cef9 | 2019-02-22 15:47:57 -0800 | [diff] [blame] | 395 | prebuilt_usr_share_host { |
| 396 | name: "foo.conf", |
| 397 | src: "foo.conf", |
| 398 | sub_dir: "bar", |
| 399 | } |
| 400 | `) |
| 401 | |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 402 | buildOS := result.Config.BuildOS.String() |
Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 403 | p := result.Module("foo.conf", buildOS+"_common").(*PrebuiltEtc) |
Paul Duffin | 5f9f771 | 2021-03-15 15:35:49 +0000 | [diff] [blame] | 404 | expected := filepath.Join("out/soong/host", result.Config.PrebuiltOS(), "usr", "share", "bar") |
Douglas Anderson | 79688ff | 2024-09-27 15:08:33 -0700 | [diff] [blame] | 405 | android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPaths[0]) |
Patrice Arruda | 300cef9 | 2019-02-22 15:47:57 -0800 | [diff] [blame] | 406 | } |
Patrice Arruda | 61583eb | 2019-05-14 08:20:45 -0700 | [diff] [blame] | 407 | |
yangbill | 63c5e19 | 2024-03-27 09:02:12 +0000 | [diff] [blame] | 408 | func TestPrebuiltPrebuiltUserHyphenDataInstallDirPath(t *testing.T) { |
| 409 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` |
| 410 | prebuilt_usr_hyphendata { |
| 411 | name: "foo.conf", |
| 412 | src: "foo.conf", |
| 413 | sub_dir: "bar", |
| 414 | } |
| 415 | `) |
| 416 | |
| 417 | p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc) |
| 418 | expected := "out/soong/target/product/test_device/system/usr/hyphen-data/bar" |
Douglas Anderson | 79688ff | 2024-09-27 15:08:33 -0700 | [diff] [blame] | 419 | android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPaths[0]) |
yangbill | 63c5e19 | 2024-03-27 09:02:12 +0000 | [diff] [blame] | 420 | } |
| 421 | |
yangbill | 85527e6 | 2024-04-30 08:24:50 +0000 | [diff] [blame] | 422 | func TestPrebuiltPrebuiltUserKeyLayoutInstallDirPath(t *testing.T) { |
| 423 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` |
| 424 | prebuilt_usr_keylayout { |
| 425 | name: "foo.conf", |
| 426 | src: "foo.conf", |
| 427 | sub_dir: "bar", |
| 428 | } |
| 429 | `) |
| 430 | |
| 431 | p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc) |
| 432 | expected := "out/soong/target/product/test_device/system/usr/keylayout/bar" |
Douglas Anderson | 79688ff | 2024-09-27 15:08:33 -0700 | [diff] [blame] | 433 | android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPaths[0]) |
yangbill | 85527e6 | 2024-04-30 08:24:50 +0000 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | func TestPrebuiltPrebuiltUserKeyCharsInstallDirPath(t *testing.T) { |
| 437 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` |
| 438 | prebuilt_usr_keychars { |
| 439 | name: "foo.conf", |
| 440 | src: "foo.conf", |
| 441 | sub_dir: "bar", |
| 442 | } |
| 443 | `) |
| 444 | |
| 445 | p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc) |
| 446 | expected := "out/soong/target/product/test_device/system/usr/keychars/bar" |
Douglas Anderson | 79688ff | 2024-09-27 15:08:33 -0700 | [diff] [blame] | 447 | android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPaths[0]) |
yangbill | 85527e6 | 2024-04-30 08:24:50 +0000 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | func TestPrebuiltPrebuiltUserIdcInstallDirPath(t *testing.T) { |
| 451 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` |
| 452 | prebuilt_usr_idc { |
| 453 | name: "foo.conf", |
| 454 | src: "foo.conf", |
| 455 | sub_dir: "bar", |
| 456 | } |
| 457 | `) |
| 458 | |
| 459 | p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc) |
| 460 | expected := "out/soong/target/product/test_device/system/usr/idc/bar" |
Douglas Anderson | 79688ff | 2024-09-27 15:08:33 -0700 | [diff] [blame] | 461 | android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPaths[0]) |
yangbill | 85527e6 | 2024-04-30 08:24:50 +0000 | [diff] [blame] | 462 | } |
| 463 | |
Patrice Arruda | 61583eb | 2019-05-14 08:20:45 -0700 | [diff] [blame] | 464 | func TestPrebuiltFontInstallDirPath(t *testing.T) { |
Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 465 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` |
Patrice Arruda | 61583eb | 2019-05-14 08:20:45 -0700 | [diff] [blame] | 466 | prebuilt_font { |
| 467 | name: "foo.conf", |
| 468 | src: "foo.conf", |
| 469 | } |
| 470 | `) |
| 471 | |
Cole Faust | c49443e | 2024-10-29 11:15:34 -0700 | [diff] [blame^] | 472 | p := result.Module("foo.conf", "android_common").(*PrebuiltEtc) |
Paul Duffin | 5f9f771 | 2021-03-15 15:35:49 +0000 | [diff] [blame] | 473 | expected := "out/soong/target/product/test_device/system/fonts" |
Douglas Anderson | 79688ff | 2024-09-27 15:08:33 -0700 | [diff] [blame] | 474 | android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPaths[0]) |
Patrice Arruda | 61583eb | 2019-05-14 08:20:45 -0700 | [diff] [blame] | 475 | } |
Patrice Arruda | 057a8b1 | 2019-06-03 15:29:27 -0700 | [diff] [blame] | 476 | |
Kevin | 93f7cd8 | 2024-05-02 12:37:59 +0200 | [diff] [blame] | 477 | func TestPrebuiltOverlayInstallDirPath(t *testing.T) { |
| 478 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` |
| 479 | prebuilt_overlay { |
| 480 | name: "foo.conf", |
| 481 | src: "foo.conf", |
| 482 | } |
| 483 | `) |
| 484 | |
| 485 | p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc) |
| 486 | expected := "out/soong/target/product/test_device/system/overlay" |
Douglas Anderson | 79688ff | 2024-09-27 15:08:33 -0700 | [diff] [blame] | 487 | android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPaths[0]) |
Kevin | 93f7cd8 | 2024-05-02 12:37:59 +0200 | [diff] [blame] | 488 | } |
| 489 | |
Patrice Arruda | 057a8b1 | 2019-06-03 15:29:27 -0700 | [diff] [blame] | 490 | func TestPrebuiltFirmwareDirPath(t *testing.T) { |
Paul Duffin | 5f9f771 | 2021-03-15 15:35:49 +0000 | [diff] [blame] | 491 | targetPath := "out/soong/target/product/test_device" |
Patrice Arruda | 057a8b1 | 2019-06-03 15:29:27 -0700 | [diff] [blame] | 492 | tests := []struct { |
| 493 | description string |
| 494 | config string |
| 495 | expectedPath string |
| 496 | }{{ |
| 497 | description: "prebuilt: system firmware", |
| 498 | config: ` |
| 499 | prebuilt_firmware { |
| 500 | name: "foo.conf", |
| 501 | src: "foo.conf", |
| 502 | }`, |
| 503 | expectedPath: filepath.Join(targetPath, "system/etc/firmware"), |
| 504 | }, { |
| 505 | description: "prebuilt: vendor firmware", |
| 506 | config: ` |
| 507 | prebuilt_firmware { |
| 508 | name: "foo.conf", |
| 509 | src: "foo.conf", |
| 510 | soc_specific: true, |
| 511 | sub_dir: "sub_dir", |
| 512 | }`, |
| 513 | expectedPath: filepath.Join(targetPath, "vendor/firmware/sub_dir"), |
| 514 | }} |
| 515 | for _, tt := range tests { |
| 516 | t.Run(tt.description, func(t *testing.T) { |
Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 517 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, tt.config) |
Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 518 | p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc) |
Douglas Anderson | 79688ff | 2024-09-27 15:08:33 -0700 | [diff] [blame] | 519 | android.AssertPathRelativeToTopEquals(t, "install dir", tt.expectedPath, p.installDirPaths[0]) |
Patrice Arruda | 057a8b1 | 2019-06-03 15:29:27 -0700 | [diff] [blame] | 520 | }) |
| 521 | } |
| 522 | } |
Patrice Arruda | 0f68800 | 2020-06-08 21:40:25 +0000 | [diff] [blame] | 523 | |
| 524 | func TestPrebuiltDSPDirPath(t *testing.T) { |
Paul Duffin | 5f9f771 | 2021-03-15 15:35:49 +0000 | [diff] [blame] | 525 | targetPath := "out/soong/target/product/test_device" |
Patrice Arruda | 0f68800 | 2020-06-08 21:40:25 +0000 | [diff] [blame] | 526 | tests := []struct { |
| 527 | description string |
| 528 | config string |
| 529 | expectedPath string |
| 530 | }{{ |
| 531 | description: "prebuilt: system dsp", |
| 532 | config: ` |
| 533 | prebuilt_dsp { |
| 534 | name: "foo.conf", |
| 535 | src: "foo.conf", |
| 536 | }`, |
| 537 | expectedPath: filepath.Join(targetPath, "system/etc/dsp"), |
| 538 | }, { |
| 539 | description: "prebuilt: vendor dsp", |
| 540 | config: ` |
| 541 | prebuilt_dsp { |
| 542 | name: "foo.conf", |
| 543 | src: "foo.conf", |
| 544 | soc_specific: true, |
| 545 | sub_dir: "sub_dir", |
| 546 | }`, |
| 547 | expectedPath: filepath.Join(targetPath, "vendor/dsp/sub_dir"), |
| 548 | }} |
| 549 | for _, tt := range tests { |
| 550 | t.Run(tt.description, func(t *testing.T) { |
Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 551 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, tt.config) |
Paul Duffin | 921fac7 | 2021-03-10 09:00:58 +0000 | [diff] [blame] | 552 | p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc) |
Douglas Anderson | 79688ff | 2024-09-27 15:08:33 -0700 | [diff] [blame] | 553 | android.AssertPathRelativeToTopEquals(t, "install dir", tt.expectedPath, p.installDirPaths[0]) |
Patrice Arruda | 0f68800 | 2020-06-08 21:40:25 +0000 | [diff] [blame] | 554 | }) |
| 555 | } |
| 556 | } |
Colin Cross | 83ebf23 | 2021-04-09 09:41:23 -0700 | [diff] [blame] | 557 | |
| 558 | func TestPrebuiltRFSADirPath(t *testing.T) { |
| 559 | targetPath := "out/soong/target/product/test_device" |
| 560 | tests := []struct { |
| 561 | description string |
| 562 | config string |
| 563 | expectedPath string |
| 564 | }{{ |
| 565 | description: "prebuilt: system rfsa", |
| 566 | config: ` |
| 567 | prebuilt_rfsa { |
| 568 | name: "foo.conf", |
| 569 | src: "foo.conf", |
| 570 | }`, |
| 571 | expectedPath: filepath.Join(targetPath, "system/lib/rfsa"), |
| 572 | }, { |
| 573 | description: "prebuilt: vendor rfsa", |
| 574 | config: ` |
| 575 | prebuilt_rfsa { |
| 576 | name: "foo.conf", |
| 577 | src: "foo.conf", |
| 578 | soc_specific: true, |
| 579 | sub_dir: "sub_dir", |
| 580 | }`, |
| 581 | expectedPath: filepath.Join(targetPath, "vendor/lib/rfsa/sub_dir"), |
| 582 | }} |
| 583 | for _, tt := range tests { |
| 584 | t.Run(tt.description, func(t *testing.T) { |
| 585 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, tt.config) |
| 586 | p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc) |
Douglas Anderson | 79688ff | 2024-09-27 15:08:33 -0700 | [diff] [blame] | 587 | android.AssertPathRelativeToTopEquals(t, "install dir", tt.expectedPath, p.installDirPaths[0]) |
Colin Cross | 83ebf23 | 2021-04-09 09:41:23 -0700 | [diff] [blame] | 588 | }) |
| 589 | } |
| 590 | } |
Jihoon Kang | 2ecf862 | 2024-10-23 21:20:30 +0000 | [diff] [blame] | 591 | |
| 592 | func TestPrebuiltMediaAutoDirPath(t *testing.T) { |
| 593 | result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` |
| 594 | prebuilt_media_audio { |
| 595 | name: "foo", |
| 596 | src: "Alarm_Beep_01.ogg", |
| 597 | product_specific: true, |
| 598 | relative_install_path: "alarms" |
| 599 | } |
| 600 | `) |
| 601 | |
| 602 | p := result.Module("foo", "android_common").(*PrebuiltEtc) |
| 603 | expected := "out/soong/target/product/test_device/product/media/audio/alarms" |
| 604 | android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPaths[0]) |
| 605 | } |