blob: 4e31b04634147a15b06f916da1569216e257d449 [file] [log] [blame]
Paul Duffin82d90432019-11-30 09:24:33 +00001// 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
15package sdk
16
17import (
Paul Duffinc3c5d5e2019-11-29 20:45:22 +000018 "fmt"
Paul Duffin82d90432019-11-30 09:24:33 +000019 "io/ioutil"
20 "os"
Paul Duffinc3c5d5e2019-11-29 20:45:22 +000021 "path/filepath"
Paul Duffinb07fa512020-03-10 22:17:04 +000022 "reflect"
Paul Duffin82d90432019-11-30 09:24:33 +000023 "strings"
24 "testing"
25
26 "android/soong/android"
27 "android/soong/apex"
28 "android/soong/cc"
Paul Duffind6ceb862021-03-04 23:02:31 +000029 "android/soong/genrule"
Paul Duffin82d90432019-11-30 09:24:33 +000030 "android/soong/java"
31)
32
Martin Stjernholm7feceb22020-07-11 04:33:29 +010033func testSdkContext(bp string, fs map[string][]byte, extraOsTypes []android.OsType) (*android.TestContext, android.Config) {
34 extraOsTypes = append(extraOsTypes, android.Android, android.Windows)
35
Colin Cross98be1bb2019-12-13 20:41:13 -080036 bp = bp + `
37 apex_key {
38 name: "myapex.key",
39 public_key: "myapex.avbpubkey",
40 private_key: "myapex.pem",
41 }
42
43 android_app_certificate {
44 name: "myapex.cert",
45 certificate: "myapex",
46 }
Martin Stjernholm7feceb22020-07-11 04:33:29 +010047 ` + cc.GatherRequiredDepsForTest(extraOsTypes...)
Colin Cross98be1bb2019-12-13 20:41:13 -080048
49 mockFS := map[string][]byte{
Martin Stjernholmcc776012020-07-07 03:22:21 +010050 "build/make/target/product/security": nil,
51 "apex_manifest.json": nil,
52 "system/sepolicy/apex/myapex-file_contexts": nil,
53 "system/sepolicy/apex/myapex2-file_contexts": nil,
54 "system/sepolicy/apex/mysdkapex-file_contexts": nil,
55 "myapex.avbpubkey": nil,
56 "myapex.pem": nil,
57 "myapex.x509.pem": nil,
58 "myapex.pk8": nil,
Colin Cross98be1bb2019-12-13 20:41:13 -080059 }
60
Colin Crossf28329d2020-02-15 11:00:10 -080061 cc.GatherRequiredFilesForTest(mockFS)
62
Colin Cross98be1bb2019-12-13 20:41:13 -080063 for k, v := range fs {
64 mockFS[k] = v
65 }
66
67 config := android.TestArchConfig(buildDir, nil, bp, mockFS)
68
Paul Duffin08798aa2020-02-27 13:12:46 +000069 // Add windows as a default disable OS to test behavior when some OS variants
70 // are disabled.
71 config.Targets[android.Windows] = []android.Target{
Jiyong Park1613e552020-09-14 19:43:17 +090072 {android.Windows, android.Arch{ArchType: android.X86_64}, android.NativeBridgeDisabled, "", "", true},
Paul Duffin08798aa2020-02-27 13:12:46 +000073 }
74
Martin Stjernholm7feceb22020-07-11 04:33:29 +010075 for _, extraOsType := range extraOsTypes {
76 switch extraOsType {
77 case android.LinuxBionic:
78 config.Targets[android.LinuxBionic] = []android.Target{
Jiyong Park1613e552020-09-14 19:43:17 +090079 {android.LinuxBionic, android.Arch{ArchType: android.X86_64}, android.NativeBridgeDisabled, "", "", false},
Martin Stjernholm7feceb22020-07-11 04:33:29 +010080 }
81 }
82 }
83
Colin Crossae8600b2020-10-29 17:09:13 -070084 ctx := android.NewTestArchContext(config)
Paul Duffin82d90432019-11-30 09:24:33 +000085
Paul Duffin8c3fec42020-03-04 20:15:08 +000086 // Enable androidmk support.
87 // * Register the singleton
88 // * Configure that we are inside make
89 // * Add CommonOS to ensure that androidmk processing works.
90 android.RegisterAndroidMkBuildComponents(ctx)
Jingwen Chencda22c92020-11-23 00:22:30 -050091 android.SetKatiEnabledForTests(config)
Paul Duffin8c3fec42020-03-04 20:15:08 +000092 config.Targets[android.CommonOS] = []android.Target{
Jiyong Park1613e552020-09-14 19:43:17 +090093 {android.CommonOS, android.Arch{ArchType: android.Common}, android.NativeBridgeDisabled, "", "", true},
Paul Duffin8c3fec42020-03-04 20:15:08 +000094 }
95
Paul Duffin82d90432019-11-30 09:24:33 +000096 // from android package
Paul Duffinc1327422020-01-14 12:15:29 +000097 android.RegisterPackageBuildComponents(ctx)
Paul Duffina2ae7e02020-09-11 11:55:00 +010098 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
Paul Duffin593b3c92019-12-05 14:31:48 +000099 ctx.PreArchMutators(android.RegisterVisibilityRuleChecker)
Paul Duffin82d90432019-11-30 09:24:33 +0000100 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin44f1d842020-06-26 20:17:02 +0100101 ctx.PreArchMutators(android.RegisterComponentsMutator)
Paul Duffin021f4e52020-07-30 16:04:17 +0100102
103 android.RegisterPrebuiltMutators(ctx)
104
105 // Register these after the prebuilt mutators have been registered to match what
106 // happens at runtime.
Paul Duffin593b3c92019-12-05 14:31:48 +0000107 ctx.PreArchMutators(android.RegisterVisibilityRuleGatherer)
108 ctx.PostDepsMutators(android.RegisterVisibilityRuleEnforcer)
109
Paul Duffin82d90432019-11-30 09:24:33 +0000110 // from java package
Paul Duffinc059c8c2021-01-20 17:13:52 +0000111 java.RegisterRequiredBuildComponentsForTest(ctx)
Paul Duffin82d90432019-11-30 09:24:33 +0000112
Paul Duffind6ceb862021-03-04 23:02:31 +0000113 // from genrule package
114 genrule.RegisterGenruleBuildComponents(ctx)
115
Paul Duffin82d90432019-11-30 09:24:33 +0000116 // from cc package
Paul Duffin77980a82019-12-19 16:01:36 +0000117 cc.RegisterRequiredBuildComponentsForTest(ctx)
Paul Duffin82d90432019-11-30 09:24:33 +0000118
119 // from apex package
120 ctx.RegisterModuleType("apex", apex.BundleFactory)
121 ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory)
122 ctx.PostDepsMutators(apex.RegisterPostDepsMutators)
123
124 // from this package
Paul Duffin6d9108f02021-03-09 22:59:28 +0000125 registerModuleExportsBuildComponents(ctx)
126 registerSdkBuildComponents(ctx)
Paul Duffin82d90432019-11-30 09:24:33 +0000127
Colin Crossae8600b2020-10-29 17:09:13 -0700128 ctx.Register()
Paul Duffin82d90432019-11-30 09:24:33 +0000129
130 return ctx, config
131}
132
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100133func runTests(t *testing.T, ctx *android.TestContext, config android.Config) *testSdkResult {
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000134 t.Helper()
Paul Duffin593b3c92019-12-05 14:31:48 +0000135 _, errs := ctx.ParseBlueprintsFiles(".")
Paul Duffin82d90432019-11-30 09:24:33 +0000136 android.FailIfErrored(t, errs)
137 _, errs = ctx.PrepareBuildActions(config)
138 android.FailIfErrored(t, errs)
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000139 return &testSdkResult{
140 TestHelper: TestHelper{t: t},
141 ctx: ctx,
142 config: config,
143 }
Paul Duffin82d90432019-11-30 09:24:33 +0000144}
145
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100146func testSdkWithFs(t *testing.T, bp string, fs map[string][]byte) *testSdkResult {
147 t.Helper()
148 ctx, config := testSdkContext(bp, fs, nil)
149 return runTests(t, ctx, config)
150}
151
Paul Duffin82d90432019-11-30 09:24:33 +0000152func testSdkError(t *testing.T, pattern, bp string) {
153 t.Helper()
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100154 ctx, config := testSdkContext(bp, nil, nil)
Paul Duffin82d90432019-11-30 09:24:33 +0000155 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
156 if len(errs) > 0 {
157 android.FailIfNoMatchingErrors(t, pattern, errs)
158 return
159 }
160 _, errs = ctx.PrepareBuildActions(config)
161 if len(errs) > 0 {
162 android.FailIfNoMatchingErrors(t, pattern, errs)
163 return
164 }
165
166 t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
167}
168
169func ensureListContains(t *testing.T, result []string, expected string) {
170 t.Helper()
171 if !android.InList(expected, result) {
172 t.Errorf("%q is not found in %v", expected, result)
173 }
174}
175
176func pathsToStrings(paths android.Paths) []string {
177 var ret []string
178 for _, p := range paths {
179 ret = append(ret, p.String())
180 }
181 return ret
182}
183
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000184// Provides general test support.
185type TestHelper struct {
186 t *testing.T
187}
188
189func (h *TestHelper) AssertStringEquals(message string, expected string, actual string) {
190 h.t.Helper()
191 if actual != expected {
192 h.t.Errorf("%s: expected %s, actual %s", message, expected, actual)
Paul Duffin82d90432019-11-30 09:24:33 +0000193 }
194}
195
Paul Duffin4b8b7932020-05-06 12:35:38 +0100196func (h *TestHelper) AssertErrorMessageEquals(message string, expected string, actual error) {
197 h.t.Helper()
198 if actual == nil {
199 h.t.Errorf("Expected error but was nil")
200 } else if actual.Error() != expected {
201 h.t.Errorf("%s: expected %s, actual %s", message, expected, actual.Error())
202 }
203}
204
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000205func (h *TestHelper) AssertTrimmedStringEquals(message string, expected string, actual string) {
206 h.t.Helper()
Paul Duffin42dd4e62021-02-22 11:35:24 +0000207 expected = strings.TrimSpace(expected)
208 actual = strings.TrimSpace(actual)
209 if actual != expected {
210 h.t.Errorf("%s: expected:\n%s\nactual:\n%s\n", message, expected, actual)
211 }
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000212}
213
Paul Duffinb07fa512020-03-10 22:17:04 +0000214func (h *TestHelper) AssertDeepEquals(message string, expected interface{}, actual interface{}) {
215 h.t.Helper()
216 if !reflect.DeepEqual(actual, expected) {
217 h.t.Errorf("%s: expected %#v, actual %#v", message, expected, actual)
218 }
219}
220
Martin Stjernholm191c25f2020-09-10 00:40:37 +0100221func (h *TestHelper) AssertPanic(message string, funcThatShouldPanic func()) {
222 h.t.Helper()
223 panicked := false
224 func() {
225 defer func() {
226 if x := recover(); x != nil {
227 panicked = true
228 }
229 }()
230 funcThatShouldPanic()
231 }()
232 if !panicked {
233 h.t.Error(message)
234 }
235}
236
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000237// Encapsulates result of processing an SDK definition. Provides support for
238// checking the state of the build structures.
239type testSdkResult struct {
240 TestHelper
241 ctx *android.TestContext
242 config android.Config
243}
244
245// Analyse the sdk build rules to extract information about what it is doing.
246
247// e.g. find the src/dest pairs from each cp command, the various zip files
248// generated, etc.
249func (r *testSdkResult) getSdkSnapshotBuildInfo(sdk *sdk) *snapshotBuildInfo {
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000250 info := &snapshotBuildInfo{
Paul Duffind0759072021-02-17 11:23:00 +0000251 r: r,
252 androidBpContents: sdk.GetAndroidBpContentsForTests(),
253 androidUnversionedBpContents: sdk.GetUnversionedAndroidBpContentsForTests(),
254 androidVersionedBpContents: sdk.GetVersionedAndroidBpContentsForTests(),
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000255 }
256
257 buildParams := sdk.BuildParamsForTests()
258 copyRules := &strings.Builder{}
Nicolas Geoffray1228e9c2020-02-27 13:45:35 +0000259 otherCopyRules := &strings.Builder{}
Paul Duffine1ddcc92020-03-03 16:01:26 +0000260 snapshotDirPrefix := sdk.builderForTests.snapshotDir.String() + "/"
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000261 for _, bp := range buildParams {
262 switch bp.Rule.String() {
263 case android.Cp.String():
Paul Duffine1ddcc92020-03-03 16:01:26 +0000264 output := bp.Output
Nicolas Geoffray1228e9c2020-02-27 13:45:35 +0000265 // Get destination relative to the snapshot root
266 dest := output.Rel()
267 src := android.NormalizePathForTesting(bp.Input)
268 // We differentiate between copy rules for the snapshot, and copy rules for the install file.
Paul Duffine1ddcc92020-03-03 16:01:26 +0000269 if strings.HasPrefix(output.String(), snapshotDirPrefix) {
270 // Get source relative to build directory.
Paul Duffine1ddcc92020-03-03 16:01:26 +0000271 _, _ = fmt.Fprintf(copyRules, "%s -> %s\n", src, dest)
272 info.snapshotContents = append(info.snapshotContents, dest)
Nicolas Geoffray1228e9c2020-02-27 13:45:35 +0000273 } else {
274 _, _ = fmt.Fprintf(otherCopyRules, "%s -> %s\n", src, dest)
Paul Duffine1ddcc92020-03-03 16:01:26 +0000275 }
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000276
277 case repackageZip.String():
278 // Add the destdir to the snapshot contents as that is effectively where
279 // the content of the repackaged zip is copied.
280 dest := bp.Args["destdir"]
281 info.snapshotContents = append(info.snapshotContents, dest)
282
283 case zipFiles.String():
284 // This could be an intermediate zip file and not the actual output zip.
285 // In that case this will be overridden when the rule to merge the zips
286 // is processed.
Paul Duffin9b478b02019-12-10 13:41:51 +0000287 info.outputZip = android.NormalizePathForTesting(bp.Output)
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000288
289 case mergeZips.String():
290 // Copy the current outputZip to the intermediateZip.
291 info.intermediateZip = info.outputZip
Paul Duffin9b478b02019-12-10 13:41:51 +0000292 mergeInput := android.NormalizePathForTesting(bp.Input)
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000293 if info.intermediateZip != mergeInput {
294 r.t.Errorf("Expected intermediate zip %s to be an input to merge zips but found %s instead",
295 info.intermediateZip, mergeInput)
296 }
297
298 // Override output zip (which was actually the intermediate zip file) with the actual
299 // output zip.
Paul Duffin9b478b02019-12-10 13:41:51 +0000300 info.outputZip = android.NormalizePathForTesting(bp.Output)
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000301
302 // Save the zips to be merged into the intermediate zip.
Paul Duffin9b478b02019-12-10 13:41:51 +0000303 info.mergeZips = android.NormalizePathsForTesting(bp.Inputs)
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000304 }
305 }
306
307 info.copyRules = copyRules.String()
Nicolas Geoffray1228e9c2020-02-27 13:45:35 +0000308 info.otherCopyRules = otherCopyRules.String()
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000309
310 return info
311}
312
313func (r *testSdkResult) Module(name string, variant string) android.Module {
314 return r.ctx.ModuleForTests(name, variant).Module()
315}
316
317func (r *testSdkResult) ModuleForTests(name string, variant string) android.TestingModule {
318 return r.ctx.ModuleForTests(name, variant)
319}
320
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000321// Check the snapshot build rules.
322//
323// Takes a list of functions which check different facets of the snapshot build rules.
324// Allows each test to customize what is checked without duplicating lots of code
325// or proliferating check methods of different flavors.
Paul Duffin1356d8c2020-02-25 19:26:33 +0000326func (r *testSdkResult) CheckSnapshot(name string, dir string, checkers ...snapshotBuildInfoChecker) {
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000327 r.t.Helper()
328
Paul Duffin1356d8c2020-02-25 19:26:33 +0000329 // The sdk CommonOS variant is always responsible for generating the snapshot.
330 variant := android.CommonOS.Name
331
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000332 sdk := r.Module(name, variant).(*sdk)
333
334 snapshotBuildInfo := r.getSdkSnapshotBuildInfo(sdk)
335
336 // Check state of the snapshot build.
337 for _, checker := range checkers {
338 checker(snapshotBuildInfo)
339 }
340
341 // Make sure that the generated zip file is in the correct place.
342 actual := snapshotBuildInfo.outputZip
Paul Duffin593b3c92019-12-05 14:31:48 +0000343 if dir != "" {
344 dir = filepath.Clean(dir) + "/"
345 }
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000346 r.AssertStringEquals("Snapshot zip file in wrong place",
Paul Duffin593b3c92019-12-05 14:31:48 +0000347 fmt.Sprintf(".intermediates/%s%s/%s/%s-current.zip", dir, name, variant, name), actual)
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000348
349 // Populate a mock filesystem with the files that would have been copied by
350 // the rules.
351 fs := make(map[string][]byte)
352 for _, dest := range snapshotBuildInfo.snapshotContents {
353 fs[dest] = nil
354 }
355
356 // Process the generated bp file to make sure it is valid.
357 testSdkWithFs(r.t, snapshotBuildInfo.androidBpContents, fs)
358}
359
360type snapshotBuildInfoChecker func(info *snapshotBuildInfo)
361
362// Check that the snapshot's generated Android.bp is correct.
363//
364// Both the expected and actual string are both trimmed before comparing.
365func checkAndroidBpContents(expected string) snapshotBuildInfoChecker {
366 return func(info *snapshotBuildInfo) {
367 info.r.t.Helper()
368 info.r.AssertTrimmedStringEquals("Android.bp contents do not match", expected, info.androidBpContents)
369 }
370}
371
Paul Duffind0759072021-02-17 11:23:00 +0000372// Check that the snapshot's unversioned generated Android.bp is correct.
373//
374// This func should be used to check the general snapshot generation code.
375//
376// Both the expected and actual string are both trimmed before comparing.
377func checkUnversionedAndroidBpContents(expected string) snapshotBuildInfoChecker {
378 return func(info *snapshotBuildInfo) {
379 info.r.t.Helper()
380 info.r.AssertTrimmedStringEquals("unversioned Android.bp contents do not match", expected, info.androidUnversionedBpContents)
381 }
382}
383
384// Check that the snapshot's versioned generated Android.bp is correct.
385//
386// This func should only be used to check the version specific snapshot generation code,
387// i.e. the encoding of version into module names and the generation of the _snapshot module. The
388// general snapshot generation code should be checked using the checkUnversionedAndroidBpContents()
389// func.
390//
391// Both the expected and actual string are both trimmed before comparing.
392func checkVersionedAndroidBpContents(expected string) snapshotBuildInfoChecker {
393 return func(info *snapshotBuildInfo) {
394 info.r.t.Helper()
395 info.r.AssertTrimmedStringEquals("versioned Android.bp contents do not match", expected, info.androidVersionedBpContents)
396 }
397}
398
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000399// Check that the snapshot's copy rules are correct.
400//
401// The copy rules are formatted as <src> -> <dest>, one per line and then compared
402// to the supplied expected string. Both the expected and actual string are trimmed
403// before comparing.
404func checkAllCopyRules(expected string) snapshotBuildInfoChecker {
405 return func(info *snapshotBuildInfo) {
406 info.r.t.Helper()
407 info.r.AssertTrimmedStringEquals("Incorrect copy rules", expected, info.copyRules)
408 }
409}
410
Nicolas Geoffray1228e9c2020-02-27 13:45:35 +0000411func checkAllOtherCopyRules(expected string) snapshotBuildInfoChecker {
412 return func(info *snapshotBuildInfo) {
413 info.r.t.Helper()
414 info.r.AssertTrimmedStringEquals("Incorrect copy rules", expected, info.otherCopyRules)
415 }
416}
417
Paul Duffin3d1248c2020-04-09 00:10:17 +0100418// Check that the specified paths match the list of zips to merge with the intermediate zip.
419func checkMergeZips(expected ...string) snapshotBuildInfoChecker {
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000420 return func(info *snapshotBuildInfo) {
421 info.r.t.Helper()
422 if info.intermediateZip == "" {
423 info.r.t.Errorf("No intermediate zip file was created")
424 }
Paul Duffin3d1248c2020-04-09 00:10:17 +0100425
426 info.r.AssertDeepEquals("mismatching merge zip files", expected, info.mergeZips)
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000427 }
428}
429
430// Encapsulates information about the snapshot build structure in order to insulate tests from
431// knowing too much about internal structures.
432//
433// All source/input paths are relative either the build directory. All dest/output paths are
434// relative to the snapshot root directory.
435type snapshotBuildInfo struct {
436 r *testSdkResult
437
438 // The contents of the generated Android.bp file
439 androidBpContents string
440
Paul Duffind0759072021-02-17 11:23:00 +0000441 // The contents of the unversioned Android.bp file
442 androidUnversionedBpContents string
443
444 // The contents of the versioned Android.bp file
445 androidVersionedBpContents string
446
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000447 // The paths, relative to the snapshot root, of all files and directories copied into the
448 // snapshot.
449 snapshotContents []string
450
Nicolas Geoffray1228e9c2020-02-27 13:45:35 +0000451 // A formatted representation of the src/dest pairs for a snapshot, one pair per line,
452 // of the format src -> dest
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000453 copyRules string
454
Nicolas Geoffray1228e9c2020-02-27 13:45:35 +0000455 // A formatted representation of the src/dest pairs for files not in a snapshot, one pair
456 // per line, of the format src -> dest
457 otherCopyRules string
458
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000459 // The path to the intermediate zip, which is a zip created from the source files copied
460 // into the snapshot directory and which will be merged with other zips to form the final output.
461 // Is am empty string if there is no intermediate zip because there are no zips to merge in.
462 intermediateZip string
463
464 // The paths to the zips to merge into the output zip, does not include the intermediate
465 // zip.
466 mergeZips []string
467
468 // The final output zip.
469 outputZip string
470}
471
Paul Duffin82d90432019-11-30 09:24:33 +0000472var buildDir string
473
474func setUp() {
475 var err error
476 buildDir, err = ioutil.TempDir("", "soong_sdk_test")
477 if err != nil {
478 panic(err)
479 }
480}
481
482func tearDown() {
483 _ = os.RemoveAll(buildDir)
484}
485
486func runTestWithBuildDir(m *testing.M) {
487 run := func() int {
488 setUp()
489 defer tearDown()
490
491 return m.Run()
492 }
493
494 os.Exit(run())
495}