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