From c1001ec0c53a38c45ea4f621d7ca4366f19e63f2 Mon Sep 17 00:00:00 2001 From: Jaewoong Jung Date: Tue, 25 Jun 2019 11:20:53 -0700 Subject: [PATCH] Create test build dir only once for apex_test. Test: apex_test.go Change-Id: Ib96ea4ec5d5ff0d8e8cf4a9eb479099cf2b1977c --- apex/apex_test.go | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/apex/apex_test.go b/apex/apex_test.go index 5332f6b2a..2e44db7c7 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -30,9 +30,12 @@ import ( var buildDir string func testApex(t *testing.T, bp string) *android.TestContext { - var config android.Config - config, buildDir = setup(t) - defer teardown(buildDir) + config := android.TestArchConfig(buildDir, nil) + config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current") + config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test") + config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"} + config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q") + config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false) ctx := android.NewTestArchContext() ctx.RegisterModuleType("apex", android.ModuleFactoryAdaptor(apexBundleFactory)) @@ -191,22 +194,15 @@ func testApex(t *testing.T, bp string) *android.TestContext { return ctx } -func setup(t *testing.T) (config android.Config, buildDir string) { - buildDir, err := ioutil.TempDir("", "soong_apex_test") +func setUp() { + var err error + buildDir, err = ioutil.TempDir("", "soong_apex_test") if err != nil { - t.Fatal(err) + panic(err) } - - config = android.TestArchConfig(buildDir, nil) - config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current") - config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test") - config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"} - config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q") - config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false) - return } -func teardown(buildDir string) { +func tearDown() { os.RemoveAll(buildDir) } @@ -1288,3 +1284,14 @@ func TestPrebuiltFilenameOverride(t *testing.T) { t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename) } } + +func TestMain(m *testing.M) { + run := func() int { + setUp() + defer tearDown() + + return m.Run() + } + + os.Exit(run()) +}