Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1 | // Copyright 2015 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 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 15 | package android |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 16 | |
| 17 | import ( |
| 18 | "errors" |
| 19 | "fmt" |
| 20 | "reflect" |
Colin Cross | 27027c7 | 2020-02-28 15:34:17 -0800 | [diff] [blame] | 21 | "strconv" |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 22 | "strings" |
| 23 | "testing" |
Inseob Kim | d9580b8 | 2021-04-13 21:13:49 +0900 | [diff] [blame] | 24 | |
| 25 | "github.com/google/blueprint/proptools" |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 26 | ) |
| 27 | |
| 28 | type strsTestCase struct { |
| 29 | in []string |
| 30 | out string |
| 31 | err []error |
| 32 | } |
| 33 | |
| 34 | var commonValidatePathTestCases = []strsTestCase{ |
| 35 | { |
| 36 | in: []string{""}, |
| 37 | out: "", |
| 38 | }, |
| 39 | { |
| 40 | in: []string{"a/b"}, |
| 41 | out: "a/b", |
| 42 | }, |
| 43 | { |
| 44 | in: []string{"a/b", "c"}, |
| 45 | out: "a/b/c", |
| 46 | }, |
| 47 | { |
| 48 | in: []string{"a/.."}, |
| 49 | out: ".", |
| 50 | }, |
| 51 | { |
| 52 | in: []string{"."}, |
| 53 | out: ".", |
| 54 | }, |
| 55 | { |
| 56 | in: []string{".."}, |
| 57 | out: "", |
| 58 | err: []error{errors.New("Path is outside directory: ..")}, |
| 59 | }, |
| 60 | { |
| 61 | in: []string{"../a"}, |
| 62 | out: "", |
| 63 | err: []error{errors.New("Path is outside directory: ../a")}, |
| 64 | }, |
| 65 | { |
| 66 | in: []string{"b/../../a"}, |
| 67 | out: "", |
| 68 | err: []error{errors.New("Path is outside directory: ../a")}, |
| 69 | }, |
| 70 | { |
| 71 | in: []string{"/a"}, |
| 72 | out: "", |
| 73 | err: []error{errors.New("Path is outside directory: /a")}, |
| 74 | }, |
Dan Willemsen | 80a7c2a | 2015-12-21 14:57:11 -0800 | [diff] [blame] | 75 | { |
| 76 | in: []string{"a", "../b"}, |
| 77 | out: "", |
| 78 | err: []error{errors.New("Path is outside directory: ../b")}, |
| 79 | }, |
| 80 | { |
| 81 | in: []string{"a", "b/../../c"}, |
| 82 | out: "", |
| 83 | err: []error{errors.New("Path is outside directory: ../c")}, |
| 84 | }, |
| 85 | { |
| 86 | in: []string{"a", "./.."}, |
| 87 | out: "", |
| 88 | err: []error{errors.New("Path is outside directory: ..")}, |
| 89 | }, |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | var validateSafePathTestCases = append(commonValidatePathTestCases, []strsTestCase{ |
| 93 | { |
| 94 | in: []string{"$host/../$a"}, |
| 95 | out: "$a", |
| 96 | }, |
| 97 | }...) |
| 98 | |
| 99 | var validatePathTestCases = append(commonValidatePathTestCases, []strsTestCase{ |
| 100 | { |
| 101 | in: []string{"$host/../$a"}, |
| 102 | out: "", |
| 103 | err: []error{errors.New("Path contains invalid character($): $host/../$a")}, |
| 104 | }, |
| 105 | { |
| 106 | in: []string{"$host/.."}, |
| 107 | out: "", |
| 108 | err: []error{errors.New("Path contains invalid character($): $host/..")}, |
| 109 | }, |
| 110 | }...) |
| 111 | |
| 112 | func TestValidateSafePath(t *testing.T) { |
| 113 | for _, testCase := range validateSafePathTestCases { |
Colin Cross | dc75ae7 | 2018-02-22 13:48:13 -0800 | [diff] [blame] | 114 | t.Run(strings.Join(testCase.in, ","), func(t *testing.T) { |
| 115 | ctx := &configErrorWrapper{} |
Colin Cross | 1ccfcc3 | 2018-02-22 13:54:26 -0800 | [diff] [blame] | 116 | out, err := validateSafePath(testCase.in...) |
| 117 | if err != nil { |
| 118 | reportPathError(ctx, err) |
| 119 | } |
Colin Cross | dc75ae7 | 2018-02-22 13:48:13 -0800 | [diff] [blame] | 120 | check(t, "validateSafePath", p(testCase.in), out, ctx.errors, testCase.out, testCase.err) |
| 121 | }) |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | |
| 125 | func TestValidatePath(t *testing.T) { |
| 126 | for _, testCase := range validatePathTestCases { |
Colin Cross | dc75ae7 | 2018-02-22 13:48:13 -0800 | [diff] [blame] | 127 | t.Run(strings.Join(testCase.in, ","), func(t *testing.T) { |
| 128 | ctx := &configErrorWrapper{} |
Colin Cross | 1ccfcc3 | 2018-02-22 13:54:26 -0800 | [diff] [blame] | 129 | out, err := validatePath(testCase.in...) |
| 130 | if err != nil { |
| 131 | reportPathError(ctx, err) |
| 132 | } |
Colin Cross | dc75ae7 | 2018-02-22 13:48:13 -0800 | [diff] [blame] | 133 | check(t, "validatePath", p(testCase.in), out, ctx.errors, testCase.out, testCase.err) |
| 134 | }) |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | |
| 138 | func TestOptionalPath(t *testing.T) { |
| 139 | var path OptionalPath |
| 140 | checkInvalidOptionalPath(t, path) |
| 141 | |
| 142 | path = OptionalPathForPath(nil) |
| 143 | checkInvalidOptionalPath(t, path) |
| 144 | } |
| 145 | |
| 146 | func checkInvalidOptionalPath(t *testing.T, path OptionalPath) { |
Colin Cross | dc75ae7 | 2018-02-22 13:48:13 -0800 | [diff] [blame] | 147 | t.Helper() |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 148 | if path.Valid() { |
| 149 | t.Errorf("Uninitialized OptionalPath should not be valid") |
| 150 | } |
| 151 | if path.String() != "" { |
| 152 | t.Errorf("Uninitialized OptionalPath String() should return \"\", not %q", path.String()) |
| 153 | } |
| 154 | defer func() { |
| 155 | if r := recover(); r == nil { |
| 156 | t.Errorf("Expected a panic when calling Path() on an uninitialized OptionalPath") |
| 157 | } |
| 158 | }() |
| 159 | path.Path() |
| 160 | } |
| 161 | |
| 162 | func check(t *testing.T, testType, testString string, |
| 163 | got interface{}, err []error, |
| 164 | expected interface{}, expectedErr []error) { |
Colin Cross | dc75ae7 | 2018-02-22 13:48:13 -0800 | [diff] [blame] | 165 | t.Helper() |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 166 | |
| 167 | printedTestCase := false |
| 168 | e := func(s string, expected, got interface{}) { |
Colin Cross | dc75ae7 | 2018-02-22 13:48:13 -0800 | [diff] [blame] | 169 | t.Helper() |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 170 | if !printedTestCase { |
| 171 | t.Errorf("test case %s: %s", testType, testString) |
| 172 | printedTestCase = true |
| 173 | } |
| 174 | t.Errorf("incorrect %s", s) |
| 175 | t.Errorf(" expected: %s", p(expected)) |
| 176 | t.Errorf(" got: %s", p(got)) |
| 177 | } |
| 178 | |
| 179 | if !reflect.DeepEqual(expectedErr, err) { |
| 180 | e("errors:", expectedErr, err) |
| 181 | } |
| 182 | |
| 183 | if !reflect.DeepEqual(expected, got) { |
| 184 | e("output:", expected, got) |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | func p(in interface{}) string { |
| 189 | if v, ok := in.([]interface{}); ok { |
| 190 | s := make([]string, len(v)) |
| 191 | for i := range v { |
| 192 | s[i] = fmt.Sprintf("%#v", v[i]) |
| 193 | } |
| 194 | return "[" + strings.Join(s, ", ") + "]" |
| 195 | } else { |
| 196 | return fmt.Sprintf("%#v", in) |
| 197 | } |
| 198 | } |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 199 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 200 | func pathTestConfig(buildDir string) Config { |
| 201 | return TestConfig(buildDir, nil, "", nil) |
| 202 | } |
| 203 | |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 204 | func TestPathForModuleInstall(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 205 | testConfig := pathTestConfig("") |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 206 | |
Jiyong Park | 87788b5 | 2020-09-01 12:37:45 +0900 | [diff] [blame] | 207 | hostTarget := Target{Os: Linux, Arch: Arch{ArchType: X86}} |
| 208 | deviceTarget := Target{Os: Android, Arch: Arch{ArchType: Arm64}} |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 209 | |
| 210 | testCases := []struct { |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 211 | name string |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 212 | ctx *testModuleInstallPathContext |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 213 | in []string |
| 214 | out string |
| 215 | partitionDir string |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 216 | }{ |
| 217 | { |
| 218 | name: "host binary", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 219 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 220 | baseModuleContext: baseModuleContext{ |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 221 | os: hostTarget.Os, |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 222 | target: hostTarget, |
| 223 | }, |
| 224 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 225 | in: []string{"bin", "my_test"}, |
| 226 | out: "host/linux-x86/bin/my_test", |
| 227 | partitionDir: "host/linux-x86", |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 228 | }, |
| 229 | |
| 230 | { |
| 231 | name: "system binary", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 232 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 233 | baseModuleContext: baseModuleContext{ |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 234 | os: deviceTarget.Os, |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 235 | target: deviceTarget, |
| 236 | }, |
| 237 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 238 | in: []string{"bin", "my_test"}, |
| 239 | out: "target/product/test_device/system/bin/my_test", |
| 240 | partitionDir: "target/product/test_device/system", |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 241 | }, |
| 242 | { |
| 243 | name: "vendor binary", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 244 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 245 | baseModuleContext: baseModuleContext{ |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 246 | os: deviceTarget.Os, |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 247 | target: deviceTarget, |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 248 | earlyModuleContext: earlyModuleContext{ |
| 249 | kind: socSpecificModule, |
| 250 | }, |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 251 | }, |
| 252 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 253 | in: []string{"bin", "my_test"}, |
| 254 | out: "target/product/test_device/vendor/bin/my_test", |
| 255 | partitionDir: "target/product/test_device/vendor", |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 256 | }, |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 257 | { |
| 258 | name: "odm binary", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 259 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 260 | baseModuleContext: baseModuleContext{ |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 261 | os: deviceTarget.Os, |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 262 | target: deviceTarget, |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 263 | earlyModuleContext: earlyModuleContext{ |
| 264 | kind: deviceSpecificModule, |
| 265 | }, |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 266 | }, |
| 267 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 268 | in: []string{"bin", "my_test"}, |
| 269 | out: "target/product/test_device/odm/bin/my_test", |
| 270 | partitionDir: "target/product/test_device/odm", |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 271 | }, |
| 272 | { |
Jaekyun Seok | 5cfbfbb | 2018-01-10 19:00:15 +0900 | [diff] [blame] | 273 | name: "product binary", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 274 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 275 | baseModuleContext: baseModuleContext{ |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 276 | os: deviceTarget.Os, |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 277 | target: deviceTarget, |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 278 | earlyModuleContext: earlyModuleContext{ |
| 279 | kind: productSpecificModule, |
| 280 | }, |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 281 | }, |
| 282 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 283 | in: []string{"bin", "my_test"}, |
| 284 | out: "target/product/test_device/product/bin/my_test", |
| 285 | partitionDir: "target/product/test_device/product", |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 286 | }, |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 287 | { |
Justin Yun | d5f6c82 | 2019-06-25 16:47:17 +0900 | [diff] [blame] | 288 | name: "system_ext binary", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 289 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 290 | baseModuleContext: baseModuleContext{ |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 291 | os: deviceTarget.Os, |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 292 | target: deviceTarget, |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 293 | earlyModuleContext: earlyModuleContext{ |
| 294 | kind: systemExtSpecificModule, |
| 295 | }, |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 296 | }, |
| 297 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 298 | in: []string{"bin", "my_test"}, |
| 299 | out: "target/product/test_device/system_ext/bin/my_test", |
| 300 | partitionDir: "target/product/test_device/system_ext", |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 301 | }, |
Colin Cross | 90ba5f4 | 2019-10-02 11:10:58 -0700 | [diff] [blame] | 302 | { |
| 303 | name: "root binary", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 304 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 90ba5f4 | 2019-10-02 11:10:58 -0700 | [diff] [blame] | 305 | baseModuleContext: baseModuleContext{ |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 306 | os: deviceTarget.Os, |
Colin Cross | 90ba5f4 | 2019-10-02 11:10:58 -0700 | [diff] [blame] | 307 | target: deviceTarget, |
| 308 | }, |
| 309 | inRoot: true, |
| 310 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 311 | in: []string{"my_test"}, |
| 312 | out: "target/product/test_device/root/my_test", |
| 313 | partitionDir: "target/product/test_device/root", |
Colin Cross | 90ba5f4 | 2019-10-02 11:10:58 -0700 | [diff] [blame] | 314 | }, |
| 315 | { |
| 316 | name: "recovery binary", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 317 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 90ba5f4 | 2019-10-02 11:10:58 -0700 | [diff] [blame] | 318 | baseModuleContext: baseModuleContext{ |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 319 | os: deviceTarget.Os, |
Colin Cross | 90ba5f4 | 2019-10-02 11:10:58 -0700 | [diff] [blame] | 320 | target: deviceTarget, |
| 321 | }, |
| 322 | inRecovery: true, |
| 323 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 324 | in: []string{"bin/my_test"}, |
| 325 | out: "target/product/test_device/recovery/root/system/bin/my_test", |
| 326 | partitionDir: "target/product/test_device/recovery/root/system", |
Colin Cross | 90ba5f4 | 2019-10-02 11:10:58 -0700 | [diff] [blame] | 327 | }, |
| 328 | { |
| 329 | name: "recovery root binary", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 330 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 90ba5f4 | 2019-10-02 11:10:58 -0700 | [diff] [blame] | 331 | baseModuleContext: baseModuleContext{ |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 332 | os: deviceTarget.Os, |
Colin Cross | 90ba5f4 | 2019-10-02 11:10:58 -0700 | [diff] [blame] | 333 | target: deviceTarget, |
| 334 | }, |
| 335 | inRecovery: true, |
| 336 | inRoot: true, |
| 337 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 338 | in: []string{"my_test"}, |
| 339 | out: "target/product/test_device/recovery/root/my_test", |
| 340 | partitionDir: "target/product/test_device/recovery/root", |
Colin Cross | 90ba5f4 | 2019-10-02 11:10:58 -0700 | [diff] [blame] | 341 | }, |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 342 | |
| 343 | { |
Inseob Kim | d9580b8 | 2021-04-13 21:13:49 +0900 | [diff] [blame] | 344 | name: "ramdisk binary", |
| 345 | ctx: &testModuleInstallPathContext{ |
| 346 | baseModuleContext: baseModuleContext{ |
| 347 | os: deviceTarget.Os, |
| 348 | target: deviceTarget, |
| 349 | }, |
| 350 | inRamdisk: true, |
| 351 | }, |
| 352 | in: []string{"my_test"}, |
| 353 | out: "target/product/test_device/ramdisk/system/my_test", |
| 354 | partitionDir: "target/product/test_device/ramdisk/system", |
| 355 | }, |
| 356 | { |
| 357 | name: "ramdisk root binary", |
| 358 | ctx: &testModuleInstallPathContext{ |
| 359 | baseModuleContext: baseModuleContext{ |
| 360 | os: deviceTarget.Os, |
| 361 | target: deviceTarget, |
| 362 | }, |
| 363 | inRamdisk: true, |
| 364 | inRoot: true, |
| 365 | }, |
| 366 | in: []string{"my_test"}, |
| 367 | out: "target/product/test_device/ramdisk/my_test", |
| 368 | partitionDir: "target/product/test_device/ramdisk", |
| 369 | }, |
| 370 | { |
| 371 | name: "vendor_ramdisk binary", |
| 372 | ctx: &testModuleInstallPathContext{ |
| 373 | baseModuleContext: baseModuleContext{ |
| 374 | os: deviceTarget.Os, |
| 375 | target: deviceTarget, |
| 376 | }, |
| 377 | inVendorRamdisk: true, |
| 378 | }, |
| 379 | in: []string{"my_test"}, |
| 380 | out: "target/product/test_device/vendor_ramdisk/system/my_test", |
| 381 | partitionDir: "target/product/test_device/vendor_ramdisk/system", |
| 382 | }, |
| 383 | { |
| 384 | name: "vendor_ramdisk root binary", |
| 385 | ctx: &testModuleInstallPathContext{ |
| 386 | baseModuleContext: baseModuleContext{ |
| 387 | os: deviceTarget.Os, |
| 388 | target: deviceTarget, |
| 389 | }, |
| 390 | inVendorRamdisk: true, |
| 391 | inRoot: true, |
| 392 | }, |
| 393 | in: []string{"my_test"}, |
| 394 | out: "target/product/test_device/vendor_ramdisk/my_test", |
| 395 | partitionDir: "target/product/test_device/vendor_ramdisk", |
| 396 | }, |
| 397 | { |
Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame^] | 398 | name: "debug_ramdisk binary", |
| 399 | ctx: &testModuleInstallPathContext{ |
| 400 | baseModuleContext: baseModuleContext{ |
| 401 | os: deviceTarget.Os, |
| 402 | target: deviceTarget, |
| 403 | }, |
| 404 | inDebugRamdisk: true, |
| 405 | }, |
| 406 | in: []string{"my_test"}, |
| 407 | out: "target/product/test_device/debug_ramdisk/my_test", |
| 408 | partitionDir: "target/product/test_device/debug_ramdisk", |
| 409 | }, |
| 410 | { |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 411 | name: "system native test binary", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 412 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 413 | baseModuleContext: baseModuleContext{ |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 414 | os: deviceTarget.Os, |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 415 | target: deviceTarget, |
| 416 | }, |
| 417 | inData: true, |
| 418 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 419 | in: []string{"nativetest", "my_test"}, |
| 420 | out: "target/product/test_device/data/nativetest/my_test", |
| 421 | partitionDir: "target/product/test_device/data", |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 422 | }, |
| 423 | { |
| 424 | name: "vendor native test binary", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 425 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 426 | baseModuleContext: baseModuleContext{ |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 427 | os: deviceTarget.Os, |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 428 | target: deviceTarget, |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 429 | earlyModuleContext: earlyModuleContext{ |
| 430 | kind: socSpecificModule, |
| 431 | }, |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 432 | }, |
| 433 | inData: true, |
| 434 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 435 | in: []string{"nativetest", "my_test"}, |
| 436 | out: "target/product/test_device/data/nativetest/my_test", |
| 437 | partitionDir: "target/product/test_device/data", |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 438 | }, |
| 439 | { |
| 440 | name: "odm native test binary", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 441 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 442 | baseModuleContext: baseModuleContext{ |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 443 | os: deviceTarget.Os, |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 444 | target: deviceTarget, |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 445 | earlyModuleContext: earlyModuleContext{ |
| 446 | kind: deviceSpecificModule, |
| 447 | }, |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 448 | }, |
| 449 | inData: true, |
| 450 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 451 | in: []string{"nativetest", "my_test"}, |
| 452 | out: "target/product/test_device/data/nativetest/my_test", |
| 453 | partitionDir: "target/product/test_device/data", |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 454 | }, |
| 455 | { |
Jaekyun Seok | 5cfbfbb | 2018-01-10 19:00:15 +0900 | [diff] [blame] | 456 | name: "product native test binary", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 457 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 458 | baseModuleContext: baseModuleContext{ |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 459 | os: deviceTarget.Os, |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 460 | target: deviceTarget, |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 461 | earlyModuleContext: earlyModuleContext{ |
| 462 | kind: productSpecificModule, |
| 463 | }, |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 464 | }, |
| 465 | inData: true, |
| 466 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 467 | in: []string{"nativetest", "my_test"}, |
| 468 | out: "target/product/test_device/data/nativetest/my_test", |
| 469 | partitionDir: "target/product/test_device/data", |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 470 | }, |
| 471 | |
| 472 | { |
Justin Yun | d5f6c82 | 2019-06-25 16:47:17 +0900 | [diff] [blame] | 473 | name: "system_ext native test binary", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 474 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 475 | baseModuleContext: baseModuleContext{ |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 476 | os: deviceTarget.Os, |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 477 | target: deviceTarget, |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 478 | earlyModuleContext: earlyModuleContext{ |
| 479 | kind: systemExtSpecificModule, |
| 480 | }, |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 481 | }, |
| 482 | inData: true, |
| 483 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 484 | in: []string{"nativetest", "my_test"}, |
| 485 | out: "target/product/test_device/data/nativetest/my_test", |
| 486 | partitionDir: "target/product/test_device/data", |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 487 | }, |
| 488 | |
| 489 | { |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 490 | name: "sanitized system binary", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 491 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 492 | baseModuleContext: baseModuleContext{ |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 493 | os: deviceTarget.Os, |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 494 | target: deviceTarget, |
| 495 | }, |
| 496 | inSanitizerDir: true, |
| 497 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 498 | in: []string{"bin", "my_test"}, |
| 499 | out: "target/product/test_device/data/asan/system/bin/my_test", |
| 500 | partitionDir: "target/product/test_device/data/asan/system", |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 501 | }, |
| 502 | { |
| 503 | name: "sanitized vendor binary", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 504 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 505 | baseModuleContext: baseModuleContext{ |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 506 | os: deviceTarget.Os, |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 507 | target: deviceTarget, |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 508 | earlyModuleContext: earlyModuleContext{ |
| 509 | kind: socSpecificModule, |
| 510 | }, |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 511 | }, |
| 512 | inSanitizerDir: true, |
| 513 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 514 | in: []string{"bin", "my_test"}, |
| 515 | out: "target/product/test_device/data/asan/vendor/bin/my_test", |
| 516 | partitionDir: "target/product/test_device/data/asan/vendor", |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 517 | }, |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 518 | { |
| 519 | name: "sanitized odm binary", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 520 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 521 | baseModuleContext: baseModuleContext{ |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 522 | os: deviceTarget.Os, |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 523 | target: deviceTarget, |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 524 | earlyModuleContext: earlyModuleContext{ |
| 525 | kind: deviceSpecificModule, |
| 526 | }, |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 527 | }, |
| 528 | inSanitizerDir: true, |
| 529 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 530 | in: []string{"bin", "my_test"}, |
| 531 | out: "target/product/test_device/data/asan/odm/bin/my_test", |
| 532 | partitionDir: "target/product/test_device/data/asan/odm", |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 533 | }, |
| 534 | { |
Jaekyun Seok | 5cfbfbb | 2018-01-10 19:00:15 +0900 | [diff] [blame] | 535 | name: "sanitized product binary", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 536 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 537 | baseModuleContext: baseModuleContext{ |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 538 | os: deviceTarget.Os, |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 539 | target: deviceTarget, |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 540 | earlyModuleContext: earlyModuleContext{ |
| 541 | kind: productSpecificModule, |
| 542 | }, |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 543 | }, |
| 544 | inSanitizerDir: true, |
| 545 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 546 | in: []string{"bin", "my_test"}, |
| 547 | out: "target/product/test_device/data/asan/product/bin/my_test", |
| 548 | partitionDir: "target/product/test_device/data/asan/product", |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 549 | }, |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 550 | |
| 551 | { |
Justin Yun | d5f6c82 | 2019-06-25 16:47:17 +0900 | [diff] [blame] | 552 | name: "sanitized system_ext binary", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 553 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 554 | baseModuleContext: baseModuleContext{ |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 555 | os: deviceTarget.Os, |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 556 | target: deviceTarget, |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 557 | earlyModuleContext: earlyModuleContext{ |
| 558 | kind: systemExtSpecificModule, |
| 559 | }, |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 560 | }, |
| 561 | inSanitizerDir: true, |
| 562 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 563 | in: []string{"bin", "my_test"}, |
| 564 | out: "target/product/test_device/data/asan/system_ext/bin/my_test", |
| 565 | partitionDir: "target/product/test_device/data/asan/system_ext", |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 566 | }, |
| 567 | |
| 568 | { |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 569 | name: "sanitized system native test binary", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 570 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 571 | baseModuleContext: baseModuleContext{ |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 572 | os: deviceTarget.Os, |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 573 | target: deviceTarget, |
| 574 | }, |
| 575 | inData: true, |
| 576 | inSanitizerDir: true, |
| 577 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 578 | in: []string{"nativetest", "my_test"}, |
| 579 | out: "target/product/test_device/data/asan/data/nativetest/my_test", |
| 580 | partitionDir: "target/product/test_device/data/asan/data", |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 581 | }, |
| 582 | { |
| 583 | name: "sanitized vendor native test binary", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 584 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 585 | baseModuleContext: baseModuleContext{ |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 586 | os: deviceTarget.Os, |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 587 | target: deviceTarget, |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 588 | earlyModuleContext: earlyModuleContext{ |
| 589 | kind: socSpecificModule, |
| 590 | }, |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 591 | }, |
| 592 | inData: true, |
| 593 | inSanitizerDir: true, |
| 594 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 595 | in: []string{"nativetest", "my_test"}, |
| 596 | out: "target/product/test_device/data/asan/data/nativetest/my_test", |
| 597 | partitionDir: "target/product/test_device/data/asan/data", |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 598 | }, |
| 599 | { |
| 600 | name: "sanitized odm native test binary", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 601 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 602 | baseModuleContext: baseModuleContext{ |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 603 | os: deviceTarget.Os, |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 604 | target: deviceTarget, |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 605 | earlyModuleContext: earlyModuleContext{ |
| 606 | kind: deviceSpecificModule, |
| 607 | }, |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 608 | }, |
| 609 | inData: true, |
| 610 | inSanitizerDir: true, |
| 611 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 612 | in: []string{"nativetest", "my_test"}, |
| 613 | out: "target/product/test_device/data/asan/data/nativetest/my_test", |
| 614 | partitionDir: "target/product/test_device/data/asan/data", |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 615 | }, |
| 616 | { |
Jaekyun Seok | 5cfbfbb | 2018-01-10 19:00:15 +0900 | [diff] [blame] | 617 | name: "sanitized product native test binary", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 618 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 619 | baseModuleContext: baseModuleContext{ |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 620 | os: deviceTarget.Os, |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 621 | target: deviceTarget, |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 622 | earlyModuleContext: earlyModuleContext{ |
| 623 | kind: productSpecificModule, |
| 624 | }, |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 625 | }, |
| 626 | inData: true, |
| 627 | inSanitizerDir: true, |
| 628 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 629 | in: []string{"nativetest", "my_test"}, |
| 630 | out: "target/product/test_device/data/asan/data/nativetest/my_test", |
| 631 | partitionDir: "target/product/test_device/data/asan/data", |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 632 | }, |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 633 | { |
Justin Yun | d5f6c82 | 2019-06-25 16:47:17 +0900 | [diff] [blame] | 634 | name: "sanitized system_ext native test binary", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 635 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 636 | baseModuleContext: baseModuleContext{ |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 637 | os: deviceTarget.Os, |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 638 | target: deviceTarget, |
Colin Cross | 1184b64 | 2019-12-30 18:43:07 -0800 | [diff] [blame] | 639 | earlyModuleContext: earlyModuleContext{ |
| 640 | kind: systemExtSpecificModule, |
| 641 | }, |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 642 | }, |
| 643 | inData: true, |
| 644 | inSanitizerDir: true, |
| 645 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 646 | in: []string{"nativetest", "my_test"}, |
| 647 | out: "target/product/test_device/data/asan/data/nativetest/my_test", |
| 648 | partitionDir: "target/product/test_device/data/asan/data", |
Colin Cross | 6e35940 | 2020-02-10 15:29:54 -0800 | [diff] [blame] | 649 | }, { |
| 650 | name: "device testcases", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 651 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 6e35940 | 2020-02-10 15:29:54 -0800 | [diff] [blame] | 652 | baseModuleContext: baseModuleContext{ |
| 653 | os: deviceTarget.Os, |
| 654 | target: deviceTarget, |
| 655 | }, |
| 656 | inTestcases: true, |
| 657 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 658 | in: []string{"my_test", "my_test_bin"}, |
| 659 | out: "target/product/test_device/testcases/my_test/my_test_bin", |
| 660 | partitionDir: "target/product/test_device/testcases", |
Colin Cross | 6e35940 | 2020-02-10 15:29:54 -0800 | [diff] [blame] | 661 | }, { |
| 662 | name: "host testcases", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 663 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 6e35940 | 2020-02-10 15:29:54 -0800 | [diff] [blame] | 664 | baseModuleContext: baseModuleContext{ |
| 665 | os: hostTarget.Os, |
| 666 | target: hostTarget, |
| 667 | }, |
| 668 | inTestcases: true, |
| 669 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 670 | in: []string{"my_test", "my_test_bin"}, |
| 671 | out: "host/linux-x86/testcases/my_test/my_test_bin", |
| 672 | partitionDir: "host/linux-x86/testcases", |
Colin Cross | 6e35940 | 2020-02-10 15:29:54 -0800 | [diff] [blame] | 673 | }, { |
| 674 | name: "forced host testcases", |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 675 | ctx: &testModuleInstallPathContext{ |
Colin Cross | 6e35940 | 2020-02-10 15:29:54 -0800 | [diff] [blame] | 676 | baseModuleContext: baseModuleContext{ |
| 677 | os: deviceTarget.Os, |
| 678 | target: deviceTarget, |
| 679 | }, |
| 680 | inTestcases: true, |
| 681 | forceOS: &Linux, |
Jiyong Park | 87788b5 | 2020-09-01 12:37:45 +0900 | [diff] [blame] | 682 | forceArch: &X86, |
Colin Cross | 6e35940 | 2020-02-10 15:29:54 -0800 | [diff] [blame] | 683 | }, |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 684 | in: []string{"my_test", "my_test_bin"}, |
| 685 | out: "host/linux-x86/testcases/my_test/my_test_bin", |
| 686 | partitionDir: "host/linux-x86/testcases", |
Dario Freni | fd05a74 | 2018-05-29 13:28:54 +0100 | [diff] [blame] | 687 | }, |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | for _, tc := range testCases { |
| 691 | t.Run(tc.name, func(t *testing.T) { |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 692 | tc.ctx.baseModuleContext.config = testConfig |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 693 | output := PathForModuleInstall(tc.ctx, tc.in...) |
| 694 | if output.basePath.path != tc.out { |
| 695 | t.Errorf("unexpected path:\n got: %q\nwant: %q\n", |
| 696 | output.basePath.path, |
| 697 | tc.out) |
| 698 | } |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 699 | if output.partitionDir != tc.partitionDir { |
| 700 | t.Errorf("unexpected partitionDir:\n got: %q\nwant: %q\n", |
| 701 | output.partitionDir, tc.partitionDir) |
| 702 | } |
Dan Willemsen | 00269f2 | 2017-07-06 16:59:48 -0700 | [diff] [blame] | 703 | }) |
| 704 | } |
| 705 | } |
Colin Cross | 5e6cfbe | 2017-11-03 15:20:35 -0700 | [diff] [blame] | 706 | |
Inseob Kim | d9580b8 | 2021-04-13 21:13:49 +0900 | [diff] [blame] | 707 | func TestPathForModuleInstallRecoveryAsBoot(t *testing.T) { |
| 708 | testConfig := pathTestConfig("") |
| 709 | testConfig.TestProductVariables.BoardUsesRecoveryAsBoot = proptools.BoolPtr(true) |
| 710 | testConfig.TestProductVariables.BoardMoveRecoveryResourcesToVendorBoot = proptools.BoolPtr(true) |
| 711 | deviceTarget := Target{Os: Android, Arch: Arch{ArchType: Arm64}} |
| 712 | |
| 713 | testCases := []struct { |
| 714 | name string |
| 715 | ctx *testModuleInstallPathContext |
| 716 | in []string |
| 717 | out string |
| 718 | partitionDir string |
| 719 | }{ |
| 720 | { |
| 721 | name: "ramdisk binary", |
| 722 | ctx: &testModuleInstallPathContext{ |
| 723 | baseModuleContext: baseModuleContext{ |
| 724 | os: deviceTarget.Os, |
| 725 | target: deviceTarget, |
| 726 | }, |
| 727 | inRamdisk: true, |
| 728 | inRoot: true, |
| 729 | }, |
| 730 | in: []string{"my_test"}, |
| 731 | out: "target/product/test_device/recovery/root/first_stage_ramdisk/my_test", |
| 732 | partitionDir: "target/product/test_device/recovery/root/first_stage_ramdisk", |
| 733 | }, |
| 734 | |
| 735 | { |
| 736 | name: "vendor_ramdisk binary", |
| 737 | ctx: &testModuleInstallPathContext{ |
| 738 | baseModuleContext: baseModuleContext{ |
| 739 | os: deviceTarget.Os, |
| 740 | target: deviceTarget, |
| 741 | }, |
| 742 | inVendorRamdisk: true, |
| 743 | inRoot: true, |
| 744 | }, |
| 745 | in: []string{"my_test"}, |
| 746 | out: "target/product/test_device/vendor_ramdisk/first_stage_ramdisk/my_test", |
| 747 | partitionDir: "target/product/test_device/vendor_ramdisk/first_stage_ramdisk", |
| 748 | }, |
| 749 | } |
| 750 | |
| 751 | for _, tc := range testCases { |
| 752 | t.Run(tc.name, func(t *testing.T) { |
| 753 | tc.ctx.baseModuleContext.config = testConfig |
| 754 | output := PathForModuleInstall(tc.ctx, tc.in...) |
| 755 | if output.basePath.path != tc.out { |
| 756 | t.Errorf("unexpected path:\n got: %q\nwant: %q\n", |
| 757 | output.basePath.path, |
| 758 | tc.out) |
| 759 | } |
| 760 | if output.partitionDir != tc.partitionDir { |
| 761 | t.Errorf("unexpected partitionDir:\n got: %q\nwant: %q\n", |
| 762 | output.partitionDir, tc.partitionDir) |
| 763 | } |
| 764 | }) |
| 765 | } |
| 766 | } |
| 767 | |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 768 | func TestBaseDirForInstallPath(t *testing.T) { |
| 769 | testConfig := pathTestConfig("") |
| 770 | deviceTarget := Target{Os: Android, Arch: Arch{ArchType: Arm64}} |
| 771 | |
Ulya Trafimovich | ccc8c85 | 2020-10-14 11:29:07 +0100 | [diff] [blame] | 772 | ctx := &testModuleInstallPathContext{ |
Jiyong Park | 957bcd9 | 2020-10-20 18:23:33 +0900 | [diff] [blame] | 773 | baseModuleContext: baseModuleContext{ |
| 774 | os: deviceTarget.Os, |
| 775 | target: deviceTarget, |
| 776 | }, |
| 777 | } |
| 778 | ctx.baseModuleContext.config = testConfig |
| 779 | |
| 780 | actual := PathForModuleInstall(ctx, "foo", "bar") |
| 781 | expectedBaseDir := "target/product/test_device/system" |
| 782 | if actual.partitionDir != expectedBaseDir { |
| 783 | t.Errorf("unexpected partitionDir:\n got: %q\nwant: %q\n", actual.partitionDir, expectedBaseDir) |
| 784 | } |
| 785 | expectedRelPath := "foo/bar" |
| 786 | if actual.Rel() != expectedRelPath { |
| 787 | t.Errorf("unexpected Rel():\n got: %q\nwant: %q\n", actual.Rel(), expectedRelPath) |
| 788 | } |
| 789 | |
| 790 | actualAfterJoin := actual.Join(ctx, "baz") |
| 791 | // partitionDir is preserved even after joining |
| 792 | if actualAfterJoin.partitionDir != expectedBaseDir { |
| 793 | t.Errorf("unexpected partitionDir after joining:\n got: %q\nwant: %q\n", actualAfterJoin.partitionDir, expectedBaseDir) |
| 794 | } |
| 795 | // Rel() is updated though |
| 796 | expectedRelAfterJoin := "baz" |
| 797 | if actualAfterJoin.Rel() != expectedRelAfterJoin { |
| 798 | t.Errorf("unexpected Rel() after joining:\n got: %q\nwant: %q\n", actualAfterJoin.Rel(), expectedRelAfterJoin) |
| 799 | } |
| 800 | } |
| 801 | |
Colin Cross | 5e6cfbe | 2017-11-03 15:20:35 -0700 | [diff] [blame] | 802 | func TestDirectorySortedPaths(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 803 | config := TestConfig("out", nil, "", map[string][]byte{ |
| 804 | "Android.bp": nil, |
| 805 | "a.txt": nil, |
| 806 | "a/txt": nil, |
| 807 | "a/b/c": nil, |
| 808 | "a/b/d": nil, |
| 809 | "b": nil, |
| 810 | "b/b.txt": nil, |
| 811 | "a/a.txt": nil, |
Colin Cross | 07e5161 | 2019-03-05 12:46:40 -0800 | [diff] [blame] | 812 | }) |
| 813 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 814 | ctx := PathContextForTesting(config) |
| 815 | |
Colin Cross | 5e6cfbe | 2017-11-03 15:20:35 -0700 | [diff] [blame] | 816 | makePaths := func() Paths { |
| 817 | return Paths{ |
Colin Cross | 07e5161 | 2019-03-05 12:46:40 -0800 | [diff] [blame] | 818 | PathForSource(ctx, "a.txt"), |
| 819 | PathForSource(ctx, "a/txt"), |
| 820 | PathForSource(ctx, "a/b/c"), |
| 821 | PathForSource(ctx, "a/b/d"), |
| 822 | PathForSource(ctx, "b"), |
| 823 | PathForSource(ctx, "b/b.txt"), |
| 824 | PathForSource(ctx, "a/a.txt"), |
Colin Cross | 5e6cfbe | 2017-11-03 15:20:35 -0700 | [diff] [blame] | 825 | } |
| 826 | } |
| 827 | |
| 828 | expected := []string{ |
| 829 | "a.txt", |
| 830 | "a/a.txt", |
| 831 | "a/b/c", |
| 832 | "a/b/d", |
| 833 | "a/txt", |
| 834 | "b", |
| 835 | "b/b.txt", |
| 836 | } |
| 837 | |
| 838 | paths := makePaths() |
Colin Cross | a140bb0 | 2018-04-17 10:52:26 -0700 | [diff] [blame] | 839 | reversePaths := ReversePaths(paths) |
Colin Cross | 5e6cfbe | 2017-11-03 15:20:35 -0700 | [diff] [blame] | 840 | |
| 841 | sortedPaths := PathsToDirectorySortedPaths(paths) |
| 842 | reverseSortedPaths := PathsToDirectorySortedPaths(reversePaths) |
| 843 | |
| 844 | if !reflect.DeepEqual(Paths(sortedPaths).Strings(), expected) { |
| 845 | t.Fatalf("sorted paths:\n %#v\n != \n %#v", paths.Strings(), expected) |
| 846 | } |
| 847 | |
| 848 | if !reflect.DeepEqual(Paths(reverseSortedPaths).Strings(), expected) { |
| 849 | t.Fatalf("sorted reversed paths:\n %#v\n !=\n %#v", reversePaths.Strings(), expected) |
| 850 | } |
| 851 | |
| 852 | expectedA := []string{ |
| 853 | "a/a.txt", |
| 854 | "a/b/c", |
| 855 | "a/b/d", |
| 856 | "a/txt", |
| 857 | } |
| 858 | |
| 859 | inA := sortedPaths.PathsInDirectory("a") |
| 860 | if !reflect.DeepEqual(inA.Strings(), expectedA) { |
| 861 | t.Errorf("FilesInDirectory(a):\n %#v\n != \n %#v", inA.Strings(), expectedA) |
| 862 | } |
| 863 | |
| 864 | expectedA_B := []string{ |
| 865 | "a/b/c", |
| 866 | "a/b/d", |
| 867 | } |
| 868 | |
| 869 | inA_B := sortedPaths.PathsInDirectory("a/b") |
| 870 | if !reflect.DeepEqual(inA_B.Strings(), expectedA_B) { |
| 871 | t.Errorf("FilesInDirectory(a/b):\n %#v\n != \n %#v", inA_B.Strings(), expectedA_B) |
| 872 | } |
| 873 | |
| 874 | expectedB := []string{ |
| 875 | "b/b.txt", |
| 876 | } |
| 877 | |
| 878 | inB := sortedPaths.PathsInDirectory("b") |
| 879 | if !reflect.DeepEqual(inB.Strings(), expectedB) { |
| 880 | t.Errorf("FilesInDirectory(b):\n %#v\n != \n %#v", inA.Strings(), expectedA) |
| 881 | } |
| 882 | } |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 883 | |
| 884 | func TestMaybeRel(t *testing.T) { |
| 885 | testCases := []struct { |
| 886 | name string |
| 887 | base string |
| 888 | target string |
| 889 | out string |
| 890 | isRel bool |
| 891 | }{ |
| 892 | { |
| 893 | name: "normal", |
| 894 | base: "a/b/c", |
| 895 | target: "a/b/c/d", |
| 896 | out: "d", |
| 897 | isRel: true, |
| 898 | }, |
| 899 | { |
| 900 | name: "parent", |
| 901 | base: "a/b/c/d", |
| 902 | target: "a/b/c", |
| 903 | isRel: false, |
| 904 | }, |
| 905 | { |
| 906 | name: "not relative", |
| 907 | base: "a/b", |
| 908 | target: "c/d", |
| 909 | isRel: false, |
| 910 | }, |
| 911 | { |
| 912 | name: "abs1", |
| 913 | base: "/a", |
| 914 | target: "a", |
| 915 | isRel: false, |
| 916 | }, |
| 917 | { |
| 918 | name: "abs2", |
| 919 | base: "a", |
| 920 | target: "/a", |
| 921 | isRel: false, |
| 922 | }, |
| 923 | } |
| 924 | |
| 925 | for _, testCase := range testCases { |
| 926 | t.Run(testCase.name, func(t *testing.T) { |
| 927 | ctx := &configErrorWrapper{} |
| 928 | out, isRel := MaybeRel(ctx, testCase.base, testCase.target) |
| 929 | if len(ctx.errors) > 0 { |
| 930 | t.Errorf("MaybeRel(..., %s, %s) reported unexpected errors %v", |
| 931 | testCase.base, testCase.target, ctx.errors) |
| 932 | } |
| 933 | if isRel != testCase.isRel || out != testCase.out { |
| 934 | t.Errorf("MaybeRel(..., %s, %s) want %v, %v got %v, %v", |
| 935 | testCase.base, testCase.target, testCase.out, testCase.isRel, out, isRel) |
| 936 | } |
| 937 | }) |
| 938 | } |
| 939 | } |
Colin Cross | 7b3dcc3 | 2019-01-24 13:14:39 -0800 | [diff] [blame] | 940 | |
| 941 | func TestPathForSource(t *testing.T) { |
| 942 | testCases := []struct { |
| 943 | name string |
| 944 | buildDir string |
| 945 | src string |
| 946 | err string |
| 947 | }{ |
| 948 | { |
| 949 | name: "normal", |
| 950 | buildDir: "out", |
| 951 | src: "a/b/c", |
| 952 | }, |
| 953 | { |
| 954 | name: "abs", |
| 955 | buildDir: "out", |
| 956 | src: "/a/b/c", |
| 957 | err: "is outside directory", |
| 958 | }, |
| 959 | { |
| 960 | name: "in out dir", |
| 961 | buildDir: "out", |
| 962 | src: "out/a/b/c", |
| 963 | err: "is in output", |
| 964 | }, |
| 965 | } |
| 966 | |
| 967 | funcs := []struct { |
| 968 | name string |
| 969 | f func(ctx PathContext, pathComponents ...string) (SourcePath, error) |
| 970 | }{ |
| 971 | {"pathForSource", pathForSource}, |
| 972 | {"safePathForSource", safePathForSource}, |
| 973 | } |
| 974 | |
| 975 | for _, f := range funcs { |
| 976 | t.Run(f.name, func(t *testing.T) { |
| 977 | for _, test := range testCases { |
| 978 | t.Run(test.name, func(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 979 | testConfig := pathTestConfig(test.buildDir) |
Colin Cross | 7b3dcc3 | 2019-01-24 13:14:39 -0800 | [diff] [blame] | 980 | ctx := &configErrorWrapper{config: testConfig} |
| 981 | _, err := f.f(ctx, test.src) |
| 982 | if len(ctx.errors) > 0 { |
| 983 | t.Fatalf("unexpected errors %v", ctx.errors) |
| 984 | } |
| 985 | if err != nil { |
| 986 | if test.err == "" { |
| 987 | t.Fatalf("unexpected error %q", err.Error()) |
| 988 | } else if !strings.Contains(err.Error(), test.err) { |
| 989 | t.Fatalf("incorrect error, want substring %q got %q", test.err, err.Error()) |
| 990 | } |
| 991 | } else { |
| 992 | if test.err != "" { |
| 993 | t.Fatalf("missing error %q", test.err) |
| 994 | } |
| 995 | } |
| 996 | }) |
| 997 | } |
| 998 | }) |
| 999 | } |
| 1000 | } |
Colin Cross | 8854a5a | 2019-02-11 14:14:16 -0800 | [diff] [blame] | 1001 | |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1002 | type pathForModuleSrcTestModule struct { |
Colin Cross | 937664a | 2019-03-06 10:17:32 -0800 | [diff] [blame] | 1003 | ModuleBase |
| 1004 | props struct { |
| 1005 | Srcs []string `android:"path"` |
| 1006 | Exclude_srcs []string `android:"path"` |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1007 | |
| 1008 | Src *string `android:"path"` |
Colin Cross | ba71a3f | 2019-03-18 12:12:48 -0700 | [diff] [blame] | 1009 | |
| 1010 | Module_handles_missing_deps bool |
Colin Cross | 937664a | 2019-03-06 10:17:32 -0800 | [diff] [blame] | 1011 | } |
| 1012 | |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1013 | src string |
| 1014 | rel string |
| 1015 | |
| 1016 | srcs []string |
Colin Cross | 937664a | 2019-03-06 10:17:32 -0800 | [diff] [blame] | 1017 | rels []string |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1018 | |
| 1019 | missingDeps []string |
Colin Cross | 937664a | 2019-03-06 10:17:32 -0800 | [diff] [blame] | 1020 | } |
| 1021 | |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1022 | func pathForModuleSrcTestModuleFactory() Module { |
| 1023 | module := &pathForModuleSrcTestModule{} |
Colin Cross | 937664a | 2019-03-06 10:17:32 -0800 | [diff] [blame] | 1024 | module.AddProperties(&module.props) |
| 1025 | InitAndroidModule(module) |
| 1026 | return module |
| 1027 | } |
| 1028 | |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1029 | func (p *pathForModuleSrcTestModule) GenerateAndroidBuildActions(ctx ModuleContext) { |
Colin Cross | ba71a3f | 2019-03-18 12:12:48 -0700 | [diff] [blame] | 1030 | var srcs Paths |
| 1031 | if p.props.Module_handles_missing_deps { |
| 1032 | srcs, p.missingDeps = PathsAndMissingDepsForModuleSrcExcludes(ctx, p.props.Srcs, p.props.Exclude_srcs) |
| 1033 | } else { |
| 1034 | srcs = PathsForModuleSrcExcludes(ctx, p.props.Srcs, p.props.Exclude_srcs) |
| 1035 | } |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1036 | p.srcs = srcs.Strings() |
Colin Cross | 937664a | 2019-03-06 10:17:32 -0800 | [diff] [blame] | 1037 | |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1038 | for _, src := range srcs { |
Colin Cross | 937664a | 2019-03-06 10:17:32 -0800 | [diff] [blame] | 1039 | p.rels = append(p.rels, src.Rel()) |
| 1040 | } |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1041 | |
| 1042 | if p.props.Src != nil { |
| 1043 | src := PathForModuleSrc(ctx, *p.props.Src) |
| 1044 | if src != nil { |
| 1045 | p.src = src.String() |
| 1046 | p.rel = src.Rel() |
| 1047 | } |
| 1048 | } |
| 1049 | |
Colin Cross | ba71a3f | 2019-03-18 12:12:48 -0700 | [diff] [blame] | 1050 | if !p.props.Module_handles_missing_deps { |
| 1051 | p.missingDeps = ctx.GetMissingDependencies() |
| 1052 | } |
Colin Cross | 6c4f21f | 2019-06-06 15:41:36 -0700 | [diff] [blame] | 1053 | |
| 1054 | ctx.Build(pctx, BuildParams{ |
| 1055 | Rule: Touch, |
| 1056 | Output: PathForModuleOut(ctx, "output"), |
| 1057 | }) |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1058 | } |
| 1059 | |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 1060 | type pathForModuleSrcOutputFileProviderModule struct { |
| 1061 | ModuleBase |
| 1062 | props struct { |
| 1063 | Outs []string |
| 1064 | Tagged []string |
| 1065 | } |
| 1066 | |
| 1067 | outs Paths |
| 1068 | tagged Paths |
| 1069 | } |
| 1070 | |
| 1071 | func pathForModuleSrcOutputFileProviderModuleFactory() Module { |
| 1072 | module := &pathForModuleSrcOutputFileProviderModule{} |
| 1073 | module.AddProperties(&module.props) |
| 1074 | InitAndroidModule(module) |
| 1075 | return module |
| 1076 | } |
| 1077 | |
| 1078 | func (p *pathForModuleSrcOutputFileProviderModule) GenerateAndroidBuildActions(ctx ModuleContext) { |
| 1079 | for _, out := range p.props.Outs { |
| 1080 | p.outs = append(p.outs, PathForModuleOut(ctx, out)) |
| 1081 | } |
| 1082 | |
| 1083 | for _, tagged := range p.props.Tagged { |
| 1084 | p.tagged = append(p.tagged, PathForModuleOut(ctx, tagged)) |
| 1085 | } |
| 1086 | } |
| 1087 | |
| 1088 | func (p *pathForModuleSrcOutputFileProviderModule) OutputFiles(tag string) (Paths, error) { |
| 1089 | switch tag { |
| 1090 | case "": |
| 1091 | return p.outs, nil |
| 1092 | case ".tagged": |
| 1093 | return p.tagged, nil |
| 1094 | default: |
| 1095 | return nil, fmt.Errorf("unsupported tag %q", tag) |
| 1096 | } |
| 1097 | } |
| 1098 | |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1099 | type pathForModuleSrcTestCase struct { |
| 1100 | name string |
| 1101 | bp string |
| 1102 | srcs []string |
| 1103 | rels []string |
| 1104 | src string |
| 1105 | rel string |
| 1106 | } |
| 1107 | |
Paul Duffin | 5405468 | 2021-03-16 21:11:42 +0000 | [diff] [blame] | 1108 | func testPathForModuleSrc(t *testing.T, tests []pathForModuleSrcTestCase) { |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1109 | for _, test := range tests { |
| 1110 | t.Run(test.name, func(t *testing.T) { |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1111 | fgBp := ` |
| 1112 | filegroup { |
| 1113 | name: "a", |
| 1114 | srcs: ["src/a"], |
| 1115 | } |
| 1116 | ` |
| 1117 | |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 1118 | ofpBp := ` |
| 1119 | output_file_provider { |
| 1120 | name: "b", |
| 1121 | outs: ["gen/b"], |
| 1122 | tagged: ["gen/c"], |
| 1123 | } |
| 1124 | ` |
| 1125 | |
Paul Duffin | 5405468 | 2021-03-16 21:11:42 +0000 | [diff] [blame] | 1126 | mockFS := MockFS{ |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1127 | "fg/Android.bp": []byte(fgBp), |
| 1128 | "foo/Android.bp": []byte(test.bp), |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 1129 | "ofp/Android.bp": []byte(ofpBp), |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1130 | "fg/src/a": nil, |
| 1131 | "foo/src/b": nil, |
| 1132 | "foo/src/c": nil, |
| 1133 | "foo/src/d": nil, |
| 1134 | "foo/src/e/e": nil, |
| 1135 | "foo/src_special/$": nil, |
| 1136 | } |
| 1137 | |
Paul Duffin | 30ac3e7 | 2021-03-20 00:36:14 +0000 | [diff] [blame] | 1138 | result := GroupFixturePreparers( |
Paul Duffin | 5405468 | 2021-03-16 21:11:42 +0000 | [diff] [blame] | 1139 | FixtureRegisterWithContext(func(ctx RegistrationContext) { |
| 1140 | ctx.RegisterModuleType("test", pathForModuleSrcTestModuleFactory) |
| 1141 | ctx.RegisterModuleType("output_file_provider", pathForModuleSrcOutputFileProviderModuleFactory) |
| 1142 | ctx.RegisterModuleType("filegroup", FileGroupFactory) |
| 1143 | }), |
| 1144 | mockFS.AddToFixture(), |
Paul Duffin | 30ac3e7 | 2021-03-20 00:36:14 +0000 | [diff] [blame] | 1145 | ).RunTest(t) |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1146 | |
Paul Duffin | 5405468 | 2021-03-16 21:11:42 +0000 | [diff] [blame] | 1147 | m := result.ModuleForTests("foo", "").Module().(*pathForModuleSrcTestModule) |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 1148 | |
Paul Duffin | 5405468 | 2021-03-16 21:11:42 +0000 | [diff] [blame] | 1149 | AssertStringPathsRelativeToTopEquals(t, "srcs", result.Config, test.srcs, m.srcs) |
| 1150 | AssertStringPathsRelativeToTopEquals(t, "rels", result.Config, test.rels, m.rels) |
| 1151 | AssertStringPathRelativeToTopEquals(t, "src", result.Config, test.src, m.src) |
| 1152 | AssertStringPathRelativeToTopEquals(t, "rel", result.Config, test.rel, m.rel) |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1153 | }) |
| 1154 | } |
Colin Cross | 937664a | 2019-03-06 10:17:32 -0800 | [diff] [blame] | 1155 | } |
| 1156 | |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1157 | func TestPathsForModuleSrc(t *testing.T) { |
| 1158 | tests := []pathForModuleSrcTestCase{ |
Colin Cross | 937664a | 2019-03-06 10:17:32 -0800 | [diff] [blame] | 1159 | { |
| 1160 | name: "path", |
| 1161 | bp: ` |
| 1162 | test { |
| 1163 | name: "foo", |
| 1164 | srcs: ["src/b"], |
| 1165 | }`, |
| 1166 | srcs: []string{"foo/src/b"}, |
| 1167 | rels: []string{"src/b"}, |
| 1168 | }, |
| 1169 | { |
| 1170 | name: "glob", |
| 1171 | bp: ` |
| 1172 | test { |
| 1173 | name: "foo", |
| 1174 | srcs: [ |
| 1175 | "src/*", |
| 1176 | "src/e/*", |
| 1177 | ], |
| 1178 | }`, |
| 1179 | srcs: []string{"foo/src/b", "foo/src/c", "foo/src/d", "foo/src/e/e"}, |
| 1180 | rels: []string{"src/b", "src/c", "src/d", "src/e/e"}, |
| 1181 | }, |
| 1182 | { |
| 1183 | name: "recursive glob", |
| 1184 | bp: ` |
| 1185 | test { |
| 1186 | name: "foo", |
| 1187 | srcs: ["src/**/*"], |
| 1188 | }`, |
| 1189 | srcs: []string{"foo/src/b", "foo/src/c", "foo/src/d", "foo/src/e/e"}, |
| 1190 | rels: []string{"src/b", "src/c", "src/d", "src/e/e"}, |
| 1191 | }, |
| 1192 | { |
| 1193 | name: "filegroup", |
| 1194 | bp: ` |
| 1195 | test { |
| 1196 | name: "foo", |
| 1197 | srcs: [":a"], |
| 1198 | }`, |
| 1199 | srcs: []string{"fg/src/a"}, |
| 1200 | rels: []string{"src/a"}, |
| 1201 | }, |
| 1202 | { |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 1203 | name: "output file provider", |
| 1204 | bp: ` |
| 1205 | test { |
| 1206 | name: "foo", |
| 1207 | srcs: [":b"], |
| 1208 | }`, |
Paul Duffin | 5405468 | 2021-03-16 21:11:42 +0000 | [diff] [blame] | 1209 | srcs: []string{"out/soong/.intermediates/ofp/b/gen/b"}, |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 1210 | rels: []string{"gen/b"}, |
| 1211 | }, |
| 1212 | { |
| 1213 | name: "output file provider tagged", |
| 1214 | bp: ` |
| 1215 | test { |
| 1216 | name: "foo", |
| 1217 | srcs: [":b{.tagged}"], |
| 1218 | }`, |
Paul Duffin | 5405468 | 2021-03-16 21:11:42 +0000 | [diff] [blame] | 1219 | srcs: []string{"out/soong/.intermediates/ofp/b/gen/c"}, |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 1220 | rels: []string{"gen/c"}, |
| 1221 | }, |
| 1222 | { |
Jooyung Han | 7607dd3 | 2020-07-05 10:23:14 +0900 | [diff] [blame] | 1223 | name: "output file provider with exclude", |
| 1224 | bp: ` |
| 1225 | test { |
| 1226 | name: "foo", |
| 1227 | srcs: [":b", ":c"], |
| 1228 | exclude_srcs: [":c"] |
| 1229 | } |
| 1230 | output_file_provider { |
| 1231 | name: "c", |
| 1232 | outs: ["gen/c"], |
| 1233 | }`, |
Paul Duffin | 5405468 | 2021-03-16 21:11:42 +0000 | [diff] [blame] | 1234 | srcs: []string{"out/soong/.intermediates/ofp/b/gen/b"}, |
Jooyung Han | 7607dd3 | 2020-07-05 10:23:14 +0900 | [diff] [blame] | 1235 | rels: []string{"gen/b"}, |
| 1236 | }, |
| 1237 | { |
Colin Cross | 937664a | 2019-03-06 10:17:32 -0800 | [diff] [blame] | 1238 | name: "special characters glob", |
| 1239 | bp: ` |
| 1240 | test { |
| 1241 | name: "foo", |
| 1242 | srcs: ["src_special/*"], |
| 1243 | }`, |
| 1244 | srcs: []string{"foo/src_special/$"}, |
| 1245 | rels: []string{"src_special/$"}, |
| 1246 | }, |
| 1247 | } |
| 1248 | |
Paul Duffin | 5405468 | 2021-03-16 21:11:42 +0000 | [diff] [blame] | 1249 | testPathForModuleSrc(t, tests) |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | func TestPathForModuleSrc(t *testing.T) { |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1253 | tests := []pathForModuleSrcTestCase{ |
| 1254 | { |
| 1255 | name: "path", |
| 1256 | bp: ` |
| 1257 | test { |
| 1258 | name: "foo", |
| 1259 | src: "src/b", |
| 1260 | }`, |
| 1261 | src: "foo/src/b", |
| 1262 | rel: "src/b", |
| 1263 | }, |
| 1264 | { |
| 1265 | name: "glob", |
| 1266 | bp: ` |
| 1267 | test { |
| 1268 | name: "foo", |
| 1269 | src: "src/e/*", |
| 1270 | }`, |
| 1271 | src: "foo/src/e/e", |
| 1272 | rel: "src/e/e", |
| 1273 | }, |
| 1274 | { |
| 1275 | name: "filegroup", |
| 1276 | bp: ` |
| 1277 | test { |
| 1278 | name: "foo", |
| 1279 | src: ":a", |
| 1280 | }`, |
| 1281 | src: "fg/src/a", |
| 1282 | rel: "src/a", |
| 1283 | }, |
| 1284 | { |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 1285 | name: "output file provider", |
| 1286 | bp: ` |
| 1287 | test { |
| 1288 | name: "foo", |
| 1289 | src: ":b", |
| 1290 | }`, |
Paul Duffin | 5405468 | 2021-03-16 21:11:42 +0000 | [diff] [blame] | 1291 | src: "out/soong/.intermediates/ofp/b/gen/b", |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 1292 | rel: "gen/b", |
| 1293 | }, |
| 1294 | { |
| 1295 | name: "output file provider tagged", |
| 1296 | bp: ` |
| 1297 | test { |
| 1298 | name: "foo", |
| 1299 | src: ":b{.tagged}", |
| 1300 | }`, |
Paul Duffin | 5405468 | 2021-03-16 21:11:42 +0000 | [diff] [blame] | 1301 | src: "out/soong/.intermediates/ofp/b/gen/c", |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 1302 | rel: "gen/c", |
| 1303 | }, |
| 1304 | { |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1305 | name: "special characters glob", |
| 1306 | bp: ` |
| 1307 | test { |
| 1308 | name: "foo", |
| 1309 | src: "src_special/*", |
| 1310 | }`, |
| 1311 | src: "foo/src_special/$", |
| 1312 | rel: "src_special/$", |
| 1313 | }, |
| 1314 | } |
| 1315 | |
Paul Duffin | 5405468 | 2021-03-16 21:11:42 +0000 | [diff] [blame] | 1316 | testPathForModuleSrc(t, tests) |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1317 | } |
Colin Cross | 937664a | 2019-03-06 10:17:32 -0800 | [diff] [blame] | 1318 | |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1319 | func TestPathsForModuleSrc_AllowMissingDependencies(t *testing.T) { |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1320 | bp := ` |
| 1321 | test { |
| 1322 | name: "foo", |
| 1323 | srcs: [":a"], |
| 1324 | exclude_srcs: [":b"], |
| 1325 | src: ":c", |
| 1326 | } |
Colin Cross | ba71a3f | 2019-03-18 12:12:48 -0700 | [diff] [blame] | 1327 | |
| 1328 | test { |
| 1329 | name: "bar", |
| 1330 | srcs: [":d"], |
| 1331 | exclude_srcs: [":e"], |
| 1332 | module_handles_missing_deps: true, |
| 1333 | } |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1334 | ` |
| 1335 | |
Paul Duffin | 30ac3e7 | 2021-03-20 00:36:14 +0000 | [diff] [blame] | 1336 | result := GroupFixturePreparers( |
Paul Duffin | 5405468 | 2021-03-16 21:11:42 +0000 | [diff] [blame] | 1337 | PrepareForTestWithAllowMissingDependencies, |
| 1338 | FixtureRegisterWithContext(func(ctx RegistrationContext) { |
| 1339 | ctx.RegisterModuleType("test", pathForModuleSrcTestModuleFactory) |
| 1340 | }), |
| 1341 | FixtureWithRootAndroidBp(bp), |
Paul Duffin | 30ac3e7 | 2021-03-20 00:36:14 +0000 | [diff] [blame] | 1342 | ).RunTest(t) |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1343 | |
Paul Duffin | 5405468 | 2021-03-16 21:11:42 +0000 | [diff] [blame] | 1344 | foo := result.ModuleForTests("foo", "").Module().(*pathForModuleSrcTestModule) |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1345 | |
Paul Duffin | 5405468 | 2021-03-16 21:11:42 +0000 | [diff] [blame] | 1346 | AssertArrayString(t, "foo missing deps", []string{"a", "b", "c"}, foo.missingDeps) |
| 1347 | AssertArrayString(t, "foo srcs", []string{}, foo.srcs) |
| 1348 | AssertStringEquals(t, "foo src", "", foo.src) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 1349 | |
Paul Duffin | 5405468 | 2021-03-16 21:11:42 +0000 | [diff] [blame] | 1350 | bar := result.ModuleForTests("bar", "").Module().(*pathForModuleSrcTestModule) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 1351 | |
Paul Duffin | 5405468 | 2021-03-16 21:11:42 +0000 | [diff] [blame] | 1352 | AssertArrayString(t, "bar missing deps", []string{"d", "e"}, bar.missingDeps) |
| 1353 | AssertArrayString(t, "bar srcs", []string{}, bar.srcs) |
Colin Cross | 937664a | 2019-03-06 10:17:32 -0800 | [diff] [blame] | 1354 | } |
| 1355 | |
Paul Duffin | 567465d | 2021-03-16 01:21:34 +0000 | [diff] [blame] | 1356 | func TestPathRelativeToTop(t *testing.T) { |
| 1357 | testConfig := pathTestConfig("/tmp/build/top") |
| 1358 | deviceTarget := Target{Os: Android, Arch: Arch{ArchType: Arm64}} |
| 1359 | |
| 1360 | ctx := &testModuleInstallPathContext{ |
| 1361 | baseModuleContext: baseModuleContext{ |
| 1362 | os: deviceTarget.Os, |
| 1363 | target: deviceTarget, |
| 1364 | }, |
| 1365 | } |
| 1366 | ctx.baseModuleContext.config = testConfig |
| 1367 | |
| 1368 | t.Run("install for soong", func(t *testing.T) { |
| 1369 | p := PathForModuleInstall(ctx, "install/path") |
| 1370 | AssertPathRelativeToTopEquals(t, "install path for soong", "out/soong/target/product/test_device/system/install/path", p) |
| 1371 | }) |
| 1372 | t.Run("install for make", func(t *testing.T) { |
| 1373 | p := PathForModuleInstall(ctx, "install/path").ToMakePath() |
| 1374 | AssertPathRelativeToTopEquals(t, "install path for make", "out/target/product/test_device/system/install/path", p) |
| 1375 | }) |
| 1376 | t.Run("output", func(t *testing.T) { |
| 1377 | p := PathForOutput(ctx, "output/path") |
| 1378 | AssertPathRelativeToTopEquals(t, "output path", "out/soong/output/path", p) |
| 1379 | }) |
| 1380 | t.Run("source", func(t *testing.T) { |
| 1381 | p := PathForSource(ctx, "source/path") |
| 1382 | AssertPathRelativeToTopEquals(t, "source path", "source/path", p) |
| 1383 | }) |
| 1384 | t.Run("mixture", func(t *testing.T) { |
| 1385 | paths := Paths{ |
| 1386 | PathForModuleInstall(ctx, "install/path"), |
| 1387 | PathForModuleInstall(ctx, "install/path").ToMakePath(), |
| 1388 | PathForOutput(ctx, "output/path"), |
| 1389 | PathForSource(ctx, "source/path"), |
| 1390 | } |
| 1391 | |
| 1392 | expected := []string{ |
| 1393 | "out/soong/target/product/test_device/system/install/path", |
| 1394 | "out/target/product/test_device/system/install/path", |
| 1395 | "out/soong/output/path", |
| 1396 | "source/path", |
| 1397 | } |
| 1398 | AssertPathsRelativeToTopEquals(t, "mixture", expected, paths) |
| 1399 | }) |
| 1400 | } |
| 1401 | |
Colin Cross | 8854a5a | 2019-02-11 14:14:16 -0800 | [diff] [blame] | 1402 | func ExampleOutputPath_ReplaceExtension() { |
| 1403 | ctx := &configErrorWrapper{ |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 1404 | config: TestConfig("out", nil, "", nil), |
Colin Cross | 8854a5a | 2019-02-11 14:14:16 -0800 | [diff] [blame] | 1405 | } |
Colin Cross | 2cdd5df | 2019-02-25 10:25:24 -0800 | [diff] [blame] | 1406 | p := PathForOutput(ctx, "system/framework").Join(ctx, "boot.art") |
Colin Cross | 8854a5a | 2019-02-11 14:14:16 -0800 | [diff] [blame] | 1407 | p2 := p.ReplaceExtension(ctx, "oat") |
| 1408 | fmt.Println(p, p2) |
Colin Cross | 2cdd5df | 2019-02-25 10:25:24 -0800 | [diff] [blame] | 1409 | fmt.Println(p.Rel(), p2.Rel()) |
Colin Cross | 8854a5a | 2019-02-11 14:14:16 -0800 | [diff] [blame] | 1410 | |
| 1411 | // Output: |
| 1412 | // out/system/framework/boot.art out/system/framework/boot.oat |
Colin Cross | 2cdd5df | 2019-02-25 10:25:24 -0800 | [diff] [blame] | 1413 | // boot.art boot.oat |
Colin Cross | 8854a5a | 2019-02-11 14:14:16 -0800 | [diff] [blame] | 1414 | } |
Colin Cross | 40e3373 | 2019-02-15 11:08:35 -0800 | [diff] [blame] | 1415 | |
Colin Cross | 41b4676 | 2020-10-09 19:26:32 -0700 | [diff] [blame] | 1416 | func ExampleOutputPath_InSameDir() { |
Colin Cross | 40e3373 | 2019-02-15 11:08:35 -0800 | [diff] [blame] | 1417 | ctx := &configErrorWrapper{ |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 1418 | config: TestConfig("out", nil, "", nil), |
Colin Cross | 40e3373 | 2019-02-15 11:08:35 -0800 | [diff] [blame] | 1419 | } |
Colin Cross | 2cdd5df | 2019-02-25 10:25:24 -0800 | [diff] [blame] | 1420 | p := PathForOutput(ctx, "system/framework").Join(ctx, "boot.art") |
Colin Cross | 40e3373 | 2019-02-15 11:08:35 -0800 | [diff] [blame] | 1421 | p2 := p.InSameDir(ctx, "oat", "arm", "boot.vdex") |
| 1422 | fmt.Println(p, p2) |
Colin Cross | 2cdd5df | 2019-02-25 10:25:24 -0800 | [diff] [blame] | 1423 | fmt.Println(p.Rel(), p2.Rel()) |
Colin Cross | 40e3373 | 2019-02-15 11:08:35 -0800 | [diff] [blame] | 1424 | |
| 1425 | // Output: |
| 1426 | // out/system/framework/boot.art out/system/framework/oat/arm/boot.vdex |
Colin Cross | 2cdd5df | 2019-02-25 10:25:24 -0800 | [diff] [blame] | 1427 | // boot.art oat/arm/boot.vdex |
Colin Cross | 40e3373 | 2019-02-15 11:08:35 -0800 | [diff] [blame] | 1428 | } |
Colin Cross | 27027c7 | 2020-02-28 15:34:17 -0800 | [diff] [blame] | 1429 | |
| 1430 | func BenchmarkFirstUniquePaths(b *testing.B) { |
| 1431 | implementations := []struct { |
| 1432 | name string |
| 1433 | f func(Paths) Paths |
| 1434 | }{ |
| 1435 | { |
| 1436 | name: "list", |
| 1437 | f: firstUniquePathsList, |
| 1438 | }, |
| 1439 | { |
| 1440 | name: "map", |
| 1441 | f: firstUniquePathsMap, |
| 1442 | }, |
| 1443 | } |
| 1444 | const maxSize = 1024 |
| 1445 | uniquePaths := make(Paths, maxSize) |
| 1446 | for i := range uniquePaths { |
| 1447 | uniquePaths[i] = PathForTesting(strconv.Itoa(i)) |
| 1448 | } |
| 1449 | samePath := make(Paths, maxSize) |
| 1450 | for i := range samePath { |
| 1451 | samePath[i] = uniquePaths[0] |
| 1452 | } |
| 1453 | |
| 1454 | f := func(b *testing.B, imp func(Paths) Paths, paths Paths) { |
| 1455 | for i := 0; i < b.N; i++ { |
| 1456 | b.ReportAllocs() |
| 1457 | paths = append(Paths(nil), paths...) |
| 1458 | imp(paths) |
| 1459 | } |
| 1460 | } |
| 1461 | |
| 1462 | for n := 1; n <= maxSize; n <<= 1 { |
| 1463 | b.Run(strconv.Itoa(n), func(b *testing.B) { |
| 1464 | for _, implementation := range implementations { |
| 1465 | b.Run(implementation.name, func(b *testing.B) { |
| 1466 | b.Run("same", func(b *testing.B) { |
| 1467 | f(b, implementation.f, samePath[:n]) |
| 1468 | }) |
| 1469 | b.Run("unique", func(b *testing.B) { |
| 1470 | f(b, implementation.f, uniquePaths[:n]) |
| 1471 | }) |
| 1472 | }) |
| 1473 | } |
| 1474 | }) |
| 1475 | } |
| 1476 | } |