Paul Duffin | 82d9043 | 2019-11-30 09:24:33 +0000 | [diff] [blame] | 1 | // Copyright 2019 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package sdk |
| 16 | |
| 17 | import ( |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 18 | "fmt" |
Paul Duffin | 82d9043 | 2019-11-30 09:24:33 +0000 | [diff] [blame] | 19 | "io/ioutil" |
| 20 | "os" |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 21 | "path/filepath" |
Paul Duffin | 82d9043 | 2019-11-30 09:24:33 +0000 | [diff] [blame] | 22 | "strings" |
| 23 | "testing" |
| 24 | |
| 25 | "android/soong/android" |
| 26 | "android/soong/apex" |
| 27 | "android/soong/cc" |
Paul Duffin | d6ceb86 | 2021-03-04 23:02:31 +0000 | [diff] [blame] | 28 | "android/soong/genrule" |
Paul Duffin | 82d9043 | 2019-11-30 09:24:33 +0000 | [diff] [blame] | 29 | "android/soong/java" |
| 30 | ) |
| 31 | |
Paul Duffin | 4a2a29c | 2021-03-09 22:27:13 +0000 | [diff] [blame] | 32 | var sdkFixtureFactory = android.NewFixtureFactory( |
| 33 | &buildDir, |
| 34 | apex.PrepareForTestWithApexBuildComponents, |
| 35 | cc.PrepareForTestWithCcDefaultModules, |
| 36 | genrule.PrepareForTestWithGenRuleBuildComponents, |
| 37 | java.PrepareForTestWithJavaBuildComponents, |
| 38 | PrepareForTestWithSdkBuildComponents, |
Martin Stjernholm | 7feceb2 | 2020-07-11 04:33:29 +0100 | [diff] [blame] | 39 | |
Paul Duffin | 4a2a29c | 2021-03-09 22:27:13 +0000 | [diff] [blame] | 40 | android.FixtureAddTextFile("sdk/tests/Android.bp", ` |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 41 | apex_key { |
| 42 | name: "myapex.key", |
| 43 | public_key: "myapex.avbpubkey", |
| 44 | private_key: "myapex.pem", |
| 45 | } |
| 46 | |
| 47 | android_app_certificate { |
| 48 | name: "myapex.cert", |
| 49 | certificate: "myapex", |
| 50 | } |
Paul Duffin | 4a2a29c | 2021-03-09 22:27:13 +0000 | [diff] [blame] | 51 | `), |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 52 | |
Paul Duffin | 4a2a29c | 2021-03-09 22:27:13 +0000 | [diff] [blame] | 53 | android.FixtureMergeMockFs(map[string][]byte{ |
Martin Stjernholm | cc77601 | 2020-07-07 03:22:21 +0100 | [diff] [blame] | 54 | "build/make/target/product/security": nil, |
| 55 | "apex_manifest.json": nil, |
| 56 | "system/sepolicy/apex/myapex-file_contexts": nil, |
| 57 | "system/sepolicy/apex/myapex2-file_contexts": nil, |
| 58 | "system/sepolicy/apex/mysdkapex-file_contexts": nil, |
| 59 | "myapex.avbpubkey": nil, |
| 60 | "myapex.pem": nil, |
| 61 | "myapex.x509.pem": nil, |
| 62 | "myapex.pk8": nil, |
Paul Duffin | 4a2a29c | 2021-03-09 22:27:13 +0000 | [diff] [blame] | 63 | }), |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 64 | |
Paul Duffin | 4a2a29c | 2021-03-09 22:27:13 +0000 | [diff] [blame] | 65 | cc.PrepareForTestOnWindows, |
| 66 | android.FixtureModifyConfig(func(config android.Config) { |
| 67 | // Add windows as a default disable OS to test behavior when some OS variants |
| 68 | // are disabled. |
| 69 | config.Targets[android.Windows] = []android.Target{ |
| 70 | {android.Windows, android.Arch{ArchType: android.X86_64}, android.NativeBridgeDisabled, "", "", true}, |
Martin Stjernholm | 7feceb2 | 2020-07-11 04:33:29 +0100 | [diff] [blame] | 71 | } |
Paul Duffin | 4a2a29c | 2021-03-09 22:27:13 +0000 | [diff] [blame] | 72 | }), |
| 73 | ) |
Martin Stjernholm | 7feceb2 | 2020-07-11 04:33:29 +0100 | [diff] [blame] | 74 | |
Paul Duffin | 4a2a29c | 2021-03-09 22:27:13 +0000 | [diff] [blame] | 75 | var PrepareForTestWithSdkBuildComponents = android.GroupFixturePreparers( |
| 76 | android.FixtureRegisterWithContext(registerModuleExportsBuildComponents), |
| 77 | android.FixtureRegisterWithContext(registerSdkBuildComponents), |
| 78 | ) |
Paul Duffin | 82d9043 | 2019-11-30 09:24:33 +0000 | [diff] [blame] | 79 | |
Paul Duffin | 4a2a29c | 2021-03-09 22:27:13 +0000 | [diff] [blame] | 80 | func testSdkWithFs(t *testing.T, bp string, fs android.MockFS) *android.TestResult { |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 81 | t.Helper() |
Paul Duffin | 4a2a29c | 2021-03-09 22:27:13 +0000 | [diff] [blame] | 82 | return sdkFixtureFactory.RunTest(t, fs.AddToFixture(), android.FixtureWithRootAndroidBp(bp)) |
Martin Stjernholm | 7feceb2 | 2020-07-11 04:33:29 +0100 | [diff] [blame] | 83 | } |
| 84 | |
Paul Duffin | 82d9043 | 2019-11-30 09:24:33 +0000 | [diff] [blame] | 85 | func testSdkError(t *testing.T, pattern, bp string) { |
| 86 | t.Helper() |
Paul Duffin | 4a2a29c | 2021-03-09 22:27:13 +0000 | [diff] [blame] | 87 | sdkFixtureFactory. |
| 88 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)). |
| 89 | RunTestWithBp(t, bp) |
Paul Duffin | 82d9043 | 2019-11-30 09:24:33 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | func ensureListContains(t *testing.T, result []string, expected string) { |
| 93 | t.Helper() |
| 94 | if !android.InList(expected, result) { |
| 95 | t.Errorf("%q is not found in %v", expected, result) |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | func pathsToStrings(paths android.Paths) []string { |
| 100 | var ret []string |
| 101 | for _, p := range paths { |
| 102 | ret = append(ret, p.String()) |
| 103 | } |
| 104 | return ret |
| 105 | } |
| 106 | |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 107 | // Analyse the sdk build rules to extract information about what it is doing. |
Paul Duffin | fe9a9e3 | 2021-03-11 17:41:01 +0000 | [diff] [blame] | 108 | // |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 109 | // e.g. find the src/dest pairs from each cp command, the various zip files |
| 110 | // generated, etc. |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame^] | 111 | func getSdkSnapshotBuildInfo(t *testing.T, result *android.TestResult, sdk *sdk) *snapshotBuildInfo { |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 112 | info := &snapshotBuildInfo{ |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame^] | 113 | t: t, |
Paul Duffin | 981b94b | 2021-03-11 12:32:12 +0000 | [diff] [blame] | 114 | r: result, |
Paul Duffin | d075907 | 2021-02-17 11:23:00 +0000 | [diff] [blame] | 115 | androidBpContents: sdk.GetAndroidBpContentsForTests(), |
| 116 | androidUnversionedBpContents: sdk.GetUnversionedAndroidBpContentsForTests(), |
| 117 | androidVersionedBpContents: sdk.GetVersionedAndroidBpContentsForTests(), |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | buildParams := sdk.BuildParamsForTests() |
| 121 | copyRules := &strings.Builder{} |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 122 | otherCopyRules := &strings.Builder{} |
Paul Duffin | e1ddcc9 | 2020-03-03 16:01:26 +0000 | [diff] [blame] | 123 | snapshotDirPrefix := sdk.builderForTests.snapshotDir.String() + "/" |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 124 | for _, bp := range buildParams { |
| 125 | switch bp.Rule.String() { |
| 126 | case android.Cp.String(): |
Paul Duffin | e1ddcc9 | 2020-03-03 16:01:26 +0000 | [diff] [blame] | 127 | output := bp.Output |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 128 | // Get destination relative to the snapshot root |
| 129 | dest := output.Rel() |
| 130 | src := android.NormalizePathForTesting(bp.Input) |
| 131 | // We differentiate between copy rules for the snapshot, and copy rules for the install file. |
Paul Duffin | e1ddcc9 | 2020-03-03 16:01:26 +0000 | [diff] [blame] | 132 | if strings.HasPrefix(output.String(), snapshotDirPrefix) { |
| 133 | // Get source relative to build directory. |
Paul Duffin | e1ddcc9 | 2020-03-03 16:01:26 +0000 | [diff] [blame] | 134 | _, _ = fmt.Fprintf(copyRules, "%s -> %s\n", src, dest) |
| 135 | info.snapshotContents = append(info.snapshotContents, dest) |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 136 | } else { |
| 137 | _, _ = fmt.Fprintf(otherCopyRules, "%s -> %s\n", src, dest) |
Paul Duffin | e1ddcc9 | 2020-03-03 16:01:26 +0000 | [diff] [blame] | 138 | } |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 139 | |
| 140 | case repackageZip.String(): |
| 141 | // Add the destdir to the snapshot contents as that is effectively where |
| 142 | // the content of the repackaged zip is copied. |
| 143 | dest := bp.Args["destdir"] |
| 144 | info.snapshotContents = append(info.snapshotContents, dest) |
| 145 | |
| 146 | case zipFiles.String(): |
| 147 | // This could be an intermediate zip file and not the actual output zip. |
| 148 | // In that case this will be overridden when the rule to merge the zips |
| 149 | // is processed. |
Paul Duffin | 9b478b0 | 2019-12-10 13:41:51 +0000 | [diff] [blame] | 150 | info.outputZip = android.NormalizePathForTesting(bp.Output) |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 151 | |
| 152 | case mergeZips.String(): |
| 153 | // Copy the current outputZip to the intermediateZip. |
| 154 | info.intermediateZip = info.outputZip |
Paul Duffin | 9b478b0 | 2019-12-10 13:41:51 +0000 | [diff] [blame] | 155 | mergeInput := android.NormalizePathForTesting(bp.Input) |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 156 | if info.intermediateZip != mergeInput { |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame^] | 157 | t.Errorf("Expected intermediate zip %s to be an input to merge zips but found %s instead", |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 158 | info.intermediateZip, mergeInput) |
| 159 | } |
| 160 | |
| 161 | // Override output zip (which was actually the intermediate zip file) with the actual |
| 162 | // output zip. |
Paul Duffin | 9b478b0 | 2019-12-10 13:41:51 +0000 | [diff] [blame] | 163 | info.outputZip = android.NormalizePathForTesting(bp.Output) |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 164 | |
| 165 | // Save the zips to be merged into the intermediate zip. |
Paul Duffin | 9b478b0 | 2019-12-10 13:41:51 +0000 | [diff] [blame] | 166 | info.mergeZips = android.NormalizePathsForTesting(bp.Inputs) |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 167 | } |
| 168 | } |
| 169 | |
| 170 | info.copyRules = copyRules.String() |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 171 | info.otherCopyRules = otherCopyRules.String() |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 172 | |
| 173 | return info |
| 174 | } |
| 175 | |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 176 | // Check the snapshot build rules. |
| 177 | // |
| 178 | // Takes a list of functions which check different facets of the snapshot build rules. |
| 179 | // Allows each test to customize what is checked without duplicating lots of code |
| 180 | // or proliferating check methods of different flavors. |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame^] | 181 | func CheckSnapshot(t *testing.T, result *android.TestResult, name string, dir string, checkers ...snapshotBuildInfoChecker) { |
| 182 | t.Helper() |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 183 | |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 184 | // The sdk CommonOS variant is always responsible for generating the snapshot. |
| 185 | variant := android.CommonOS.Name |
| 186 | |
Paul Duffin | 981b94b | 2021-03-11 12:32:12 +0000 | [diff] [blame] | 187 | sdk := result.Module(name, variant).(*sdk) |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 188 | |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame^] | 189 | snapshotBuildInfo := getSdkSnapshotBuildInfo(t, result, sdk) |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 190 | |
| 191 | // Check state of the snapshot build. |
| 192 | for _, checker := range checkers { |
| 193 | checker(snapshotBuildInfo) |
| 194 | } |
| 195 | |
| 196 | // Make sure that the generated zip file is in the correct place. |
| 197 | actual := snapshotBuildInfo.outputZip |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 198 | if dir != "" { |
| 199 | dir = filepath.Clean(dir) + "/" |
| 200 | } |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame^] | 201 | android.AssertStringEquals(t, "Snapshot zip file in wrong place", |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 202 | fmt.Sprintf(".intermediates/%s%s/%s/%s-current.zip", dir, name, variant, name), actual) |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 203 | |
| 204 | // Populate a mock filesystem with the files that would have been copied by |
| 205 | // the rules. |
| 206 | fs := make(map[string][]byte) |
| 207 | for _, dest := range snapshotBuildInfo.snapshotContents { |
| 208 | fs[dest] = nil |
| 209 | } |
| 210 | |
| 211 | // Process the generated bp file to make sure it is valid. |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame^] | 212 | testSdkWithFs(t, snapshotBuildInfo.androidBpContents, fs) |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | type snapshotBuildInfoChecker func(info *snapshotBuildInfo) |
| 216 | |
| 217 | // Check that the snapshot's generated Android.bp is correct. |
| 218 | // |
| 219 | // Both the expected and actual string are both trimmed before comparing. |
| 220 | func checkAndroidBpContents(expected string) snapshotBuildInfoChecker { |
| 221 | return func(info *snapshotBuildInfo) { |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame^] | 222 | info.t.Helper() |
| 223 | android.AssertTrimmedStringEquals(info.t, "Android.bp contents do not match", expected, info.androidBpContents) |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | |
Paul Duffin | d075907 | 2021-02-17 11:23:00 +0000 | [diff] [blame] | 227 | // Check that the snapshot's unversioned generated Android.bp is correct. |
| 228 | // |
| 229 | // This func should be used to check the general snapshot generation code. |
| 230 | // |
| 231 | // Both the expected and actual string are both trimmed before comparing. |
| 232 | func checkUnversionedAndroidBpContents(expected string) snapshotBuildInfoChecker { |
| 233 | return func(info *snapshotBuildInfo) { |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame^] | 234 | info.t.Helper() |
| 235 | android.AssertTrimmedStringEquals(info.t, "unversioned Android.bp contents do not match", expected, info.androidUnversionedBpContents) |
Paul Duffin | d075907 | 2021-02-17 11:23:00 +0000 | [diff] [blame] | 236 | } |
| 237 | } |
| 238 | |
| 239 | // Check that the snapshot's versioned generated Android.bp is correct. |
| 240 | // |
| 241 | // This func should only be used to check the version specific snapshot generation code, |
| 242 | // i.e. the encoding of version into module names and the generation of the _snapshot module. The |
| 243 | // general snapshot generation code should be checked using the checkUnversionedAndroidBpContents() |
| 244 | // func. |
| 245 | // |
| 246 | // Both the expected and actual string are both trimmed before comparing. |
| 247 | func checkVersionedAndroidBpContents(expected string) snapshotBuildInfoChecker { |
| 248 | return func(info *snapshotBuildInfo) { |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame^] | 249 | info.t.Helper() |
| 250 | android.AssertTrimmedStringEquals(info.t, "versioned Android.bp contents do not match", expected, info.androidVersionedBpContents) |
Paul Duffin | d075907 | 2021-02-17 11:23:00 +0000 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 254 | // Check that the snapshot's copy rules are correct. |
| 255 | // |
| 256 | // The copy rules are formatted as <src> -> <dest>, one per line and then compared |
| 257 | // to the supplied expected string. Both the expected and actual string are trimmed |
| 258 | // before comparing. |
| 259 | func checkAllCopyRules(expected string) snapshotBuildInfoChecker { |
| 260 | return func(info *snapshotBuildInfo) { |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame^] | 261 | info.t.Helper() |
| 262 | android.AssertTrimmedStringEquals(info.t, "Incorrect copy rules", expected, info.copyRules) |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 266 | func checkAllOtherCopyRules(expected string) snapshotBuildInfoChecker { |
| 267 | return func(info *snapshotBuildInfo) { |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame^] | 268 | info.t.Helper() |
| 269 | android.AssertTrimmedStringEquals(info.t, "Incorrect copy rules", expected, info.otherCopyRules) |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 273 | // Check that the specified paths match the list of zips to merge with the intermediate zip. |
| 274 | func checkMergeZips(expected ...string) snapshotBuildInfoChecker { |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 275 | return func(info *snapshotBuildInfo) { |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame^] | 276 | info.t.Helper() |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 277 | if info.intermediateZip == "" { |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame^] | 278 | info.t.Errorf("No intermediate zip file was created") |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 279 | } |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 280 | |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame^] | 281 | android.AssertDeepEquals(info.t, "mismatching merge zip files", expected, info.mergeZips) |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
| 285 | // Encapsulates information about the snapshot build structure in order to insulate tests from |
| 286 | // knowing too much about internal structures. |
| 287 | // |
| 288 | // All source/input paths are relative either the build directory. All dest/output paths are |
| 289 | // relative to the snapshot root directory. |
| 290 | type snapshotBuildInfo struct { |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame^] | 291 | t *testing.T |
| 292 | |
| 293 | // The result from RunTest() |
Paul Duffin | 4a2a29c | 2021-03-09 22:27:13 +0000 | [diff] [blame] | 294 | r *android.TestResult |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 295 | |
| 296 | // The contents of the generated Android.bp file |
| 297 | androidBpContents string |
| 298 | |
Paul Duffin | d075907 | 2021-02-17 11:23:00 +0000 | [diff] [blame] | 299 | // The contents of the unversioned Android.bp file |
| 300 | androidUnversionedBpContents string |
| 301 | |
| 302 | // The contents of the versioned Android.bp file |
| 303 | androidVersionedBpContents string |
| 304 | |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 305 | // The paths, relative to the snapshot root, of all files and directories copied into the |
| 306 | // snapshot. |
| 307 | snapshotContents []string |
| 308 | |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 309 | // A formatted representation of the src/dest pairs for a snapshot, one pair per line, |
| 310 | // of the format src -> dest |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 311 | copyRules string |
| 312 | |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 313 | // A formatted representation of the src/dest pairs for files not in a snapshot, one pair |
| 314 | // per line, of the format src -> dest |
| 315 | otherCopyRules string |
| 316 | |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 317 | // The path to the intermediate zip, which is a zip created from the source files copied |
| 318 | // into the snapshot directory and which will be merged with other zips to form the final output. |
| 319 | // Is am empty string if there is no intermediate zip because there are no zips to merge in. |
| 320 | intermediateZip string |
| 321 | |
| 322 | // The paths to the zips to merge into the output zip, does not include the intermediate |
| 323 | // zip. |
| 324 | mergeZips []string |
| 325 | |
| 326 | // The final output zip. |
| 327 | outputZip string |
| 328 | } |
| 329 | |
Paul Duffin | 82d9043 | 2019-11-30 09:24:33 +0000 | [diff] [blame] | 330 | var buildDir string |
| 331 | |
| 332 | func setUp() { |
| 333 | var err error |
| 334 | buildDir, err = ioutil.TempDir("", "soong_sdk_test") |
| 335 | if err != nil { |
| 336 | panic(err) |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | func tearDown() { |
| 341 | _ = os.RemoveAll(buildDir) |
| 342 | } |
| 343 | |
| 344 | func runTestWithBuildDir(m *testing.M) { |
| 345 | run := func() int { |
| 346 | setUp() |
| 347 | defer tearDown() |
| 348 | |
| 349 | return m.Run() |
| 350 | } |
| 351 | |
| 352 | os.Exit(run()) |
| 353 | } |