Create test build dir only once for apex_test.

Test: apex_test.go
Change-Id: Ib96ea4ec5d5ff0d8e8cf4a9eb479099cf2b1977c
This commit is contained in:
Jaewoong Jung
2019-06-25 11:20:53 -07:00
parent 50c744e916
commit c1001ec0c5

View File

@@ -30,9 +30,12 @@ import (
var buildDir string var buildDir string
func testApex(t *testing.T, bp string) *android.TestContext { func testApex(t *testing.T, bp string) *android.TestContext {
var config android.Config config := android.TestArchConfig(buildDir, nil)
config, buildDir = setup(t) config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
defer teardown(buildDir) 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 := android.NewTestArchContext()
ctx.RegisterModuleType("apex", android.ModuleFactoryAdaptor(apexBundleFactory)) ctx.RegisterModuleType("apex", android.ModuleFactoryAdaptor(apexBundleFactory))
@@ -191,22 +194,15 @@ func testApex(t *testing.T, bp string) *android.TestContext {
return ctx return ctx
} }
func setup(t *testing.T) (config android.Config, buildDir string) { func setUp() {
buildDir, err := ioutil.TempDir("", "soong_apex_test") var err error
buildDir, err = ioutil.TempDir("", "soong_apex_test")
if err != nil { 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) os.RemoveAll(buildDir)
} }
@@ -1288,3 +1284,14 @@ func TestPrebuiltFilenameOverride(t *testing.T) {
t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename) 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())
}