Share buildDir for android/soong/android tests
There is no need to create a separate buildDir for each test file, use TestMain to create a global one for the package. Test: all soong tests Change-Id: I435ee7aa88b7e0bb8ccc1ba79f82833a7accf3e9
This commit is contained in:
@@ -78,6 +78,7 @@ bootstrap_go_package {
|
|||||||
"android/env.go",
|
"android/env.go",
|
||||||
],
|
],
|
||||||
testSrcs: [
|
testSrcs: [
|
||||||
|
"android/android_test.go",
|
||||||
"android/arch_test.go",
|
"android/arch_test.go",
|
||||||
"android/config_test.go",
|
"android/config_test.go",
|
||||||
"android/expand_test.go",
|
"android/expand_test.go",
|
||||||
|
46
android/android_test.go
Normal file
46
android/android_test.go
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
// Copyright 2019 Google Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package android
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
var buildDir string
|
||||||
|
|
||||||
|
func setUp() {
|
||||||
|
var err error
|
||||||
|
buildDir, err = ioutil.TempDir("", "soong_android_test")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func tearDown() {
|
||||||
|
os.RemoveAll(buildDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
run := func() int {
|
||||||
|
setUp()
|
||||||
|
defer tearDown()
|
||||||
|
|
||||||
|
return m.Run()
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Exit(run())
|
||||||
|
}
|
@@ -16,8 +16,6 @@ package android
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -613,12 +611,6 @@ func mockFiles(bps map[string]string) (files map[string][]byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setupTestFromFiles(bps map[string][]byte) (ctx *TestContext, errs []error) {
|
func setupTestFromFiles(bps map[string][]byte) (ctx *TestContext, errs []error) {
|
||||||
buildDir, err := ioutil.TempDir("", "soong_namespace_test")
|
|
||||||
if err != nil {
|
|
||||||
return nil, []error{err}
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(buildDir)
|
|
||||||
|
|
||||||
config := TestConfig(buildDir, nil)
|
config := TestConfig(buildDir, nil)
|
||||||
|
|
||||||
ctx = NewTestContext()
|
ctx = NewTestContext()
|
||||||
|
@@ -15,8 +15,6 @@
|
|||||||
package android
|
package android
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -151,12 +149,6 @@ var neverallowTests = []struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNeverallow(t *testing.T) {
|
func TestNeverallow(t *testing.T) {
|
||||||
buildDir, err := ioutil.TempDir("", "soong_neverallow_test")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(buildDir)
|
|
||||||
|
|
||||||
config := TestConfig(buildDir, nil)
|
config := TestConfig(buildDir, nil)
|
||||||
|
|
||||||
for _, test := range neverallowTests {
|
for _, test := range neverallowTests {
|
||||||
|
@@ -17,8 +17,6 @@ package android
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -880,12 +878,6 @@ func testPathForModuleSrc(t *testing.T, buildDir string, tests []pathForModuleSr
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPathsForModuleSrc(t *testing.T) {
|
func TestPathsForModuleSrc(t *testing.T) {
|
||||||
buildDir, err := ioutil.TempDir("", "soong_paths_for_module_src_test")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(buildDir)
|
|
||||||
|
|
||||||
tests := []pathForModuleSrcTestCase{
|
tests := []pathForModuleSrcTestCase{
|
||||||
{
|
{
|
||||||
name: "path",
|
name: "path",
|
||||||
@@ -966,12 +958,6 @@ func TestPathsForModuleSrc(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPathForModuleSrc(t *testing.T) {
|
func TestPathForModuleSrc(t *testing.T) {
|
||||||
buildDir, err := ioutil.TempDir("", "soong_path_for_module_src_test")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(buildDir)
|
|
||||||
|
|
||||||
tests := []pathForModuleSrcTestCase{
|
tests := []pathForModuleSrcTestCase{
|
||||||
{
|
{
|
||||||
name: "path",
|
name: "path",
|
||||||
@@ -1039,12 +1025,6 @@ func TestPathForModuleSrc(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPathsForModuleSrc_AllowMissingDependencies(t *testing.T) {
|
func TestPathsForModuleSrc_AllowMissingDependencies(t *testing.T) {
|
||||||
buildDir, err := ioutil.TempDir("", "soong_paths_for_module_src_allow_missing_dependencies_test")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(buildDir)
|
|
||||||
|
|
||||||
config := TestConfig(buildDir, nil)
|
config := TestConfig(buildDir, nil)
|
||||||
config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
|
config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
|
||||||
|
|
||||||
|
@@ -15,16 +15,13 @@
|
|||||||
package android
|
package android
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testPrebuiltEtc(t *testing.T, bp string) (*TestContext, Config) {
|
func testPrebuiltEtc(t *testing.T, bp string) (*TestContext, Config) {
|
||||||
config, buildDir := setUp(t)
|
config := TestArchConfig(buildDir, nil)
|
||||||
defer tearDown(buildDir)
|
|
||||||
ctx := NewTestArchContext()
|
ctx := NewTestArchContext()
|
||||||
ctx.RegisterModuleType("prebuilt_etc", ModuleFactoryAdaptor(PrebuiltEtcFactory))
|
ctx.RegisterModuleType("prebuilt_etc", ModuleFactoryAdaptor(PrebuiltEtcFactory))
|
||||||
ctx.RegisterModuleType("prebuilt_etc_host", ModuleFactoryAdaptor(PrebuiltEtcHostFactory))
|
ctx.RegisterModuleType("prebuilt_etc_host", ModuleFactoryAdaptor(PrebuiltEtcHostFactory))
|
||||||
@@ -51,20 +48,6 @@ func testPrebuiltEtc(t *testing.T, bp string) (*TestContext, Config) {
|
|||||||
return ctx, config
|
return ctx, config
|
||||||
}
|
}
|
||||||
|
|
||||||
func setUp(t *testing.T) (config Config, buildDir string) {
|
|
||||||
buildDir, err := ioutil.TempDir("", "soong_prebuilt_etc_test")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
config = TestArchConfig(buildDir, nil)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func tearDown(buildDir string) {
|
|
||||||
os.RemoveAll(buildDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPrebuiltEtcVariants(t *testing.T) {
|
func TestPrebuiltEtcVariants(t *testing.T) {
|
||||||
ctx, _ := testPrebuiltEtc(t, `
|
ctx, _ := testPrebuiltEtc(t, `
|
||||||
prebuilt_etc {
|
prebuilt_etc {
|
||||||
|
@@ -16,8 +16,6 @@ package android
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/google/blueprint"
|
"github.com/google/blueprint"
|
||||||
@@ -127,12 +125,6 @@ var prebuiltsTests = []struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPrebuilts(t *testing.T) {
|
func TestPrebuilts(t *testing.T) {
|
||||||
buildDir, err := ioutil.TempDir("", "soong_prebuilt_test")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(buildDir)
|
|
||||||
|
|
||||||
config := TestConfig(buildDir, nil)
|
config := TestConfig(buildDir, nil)
|
||||||
|
|
||||||
for _, test := range prebuiltsTests {
|
for _, test := range prebuiltsTests {
|
||||||
|
@@ -16,8 +16,6 @@ package android
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -418,12 +416,6 @@ func testRuleBuilder_Build(ctx BuilderContext, in Path, out, outDep, outDir Writ
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRuleBuilder_Build(t *testing.T) {
|
func TestRuleBuilder_Build(t *testing.T) {
|
||||||
buildDir, err := ioutil.TempDir("", "soong_test_rule_builder")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(buildDir)
|
|
||||||
|
|
||||||
bp := `
|
bp := `
|
||||||
rule_builder_test {
|
rule_builder_test {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
|
@@ -1,19 +1,11 @@
|
|||||||
package android
|
package android
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testShBinary(t *testing.T, bp string) (*TestContext, Config) {
|
func testShBinary(t *testing.T, bp string) (*TestContext, Config) {
|
||||||
buildDir, err := ioutil.TempDir("", "soong_sh_binary_test")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(buildDir)
|
|
||||||
|
|
||||||
config := TestArchConfig(buildDir, nil)
|
config := TestArchConfig(buildDir, nil)
|
||||||
|
|
||||||
ctx := NewTestArchContext()
|
ctx := NewTestArchContext()
|
||||||
|
@@ -1,8 +1,6 @@
|
|||||||
package android
|
package android
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/google/blueprint"
|
"github.com/google/blueprint"
|
||||||
@@ -663,12 +661,6 @@ var visibilityTests = []struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestVisibility(t *testing.T) {
|
func TestVisibility(t *testing.T) {
|
||||||
buildDir, err := ioutil.TempDir("", "soong_neverallow_test")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(buildDir)
|
|
||||||
|
|
||||||
for _, test := range visibilityTests {
|
for _, test := range visibilityTests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
_, errs := testVisibility(buildDir, test.fs)
|
_, errs := testVisibility(buildDir, test.fs)
|
||||||
|
@@ -15,19 +15,11 @@
|
|||||||
package android
|
package android
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testVtsConfig(test *testing.T, bpFileContents string) *TestContext {
|
func testVtsConfig(test *testing.T, bpFileContents string) *TestContext {
|
||||||
buildDir, err := ioutil.TempDir("", "soong_vts_config_test")
|
|
||||||
if err != nil {
|
|
||||||
test.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
config := TestArchConfig(buildDir, nil)
|
config := TestArchConfig(buildDir, nil)
|
||||||
defer func() { os.RemoveAll(buildDir) }()
|
|
||||||
|
|
||||||
ctx := NewTestArchContext()
|
ctx := NewTestArchContext()
|
||||||
ctx.RegisterModuleType("vts_config", ModuleFactoryAdaptor(VtsConfigFactory))
|
ctx.RegisterModuleType("vts_config", ModuleFactoryAdaptor(VtsConfigFactory))
|
||||||
|
Reference in New Issue
Block a user