Merge changes I0f516efd,I668f083b,Ifa70acad
* changes: Migrate etc package to a per test build directory Migrate genrule package to a per test build directory Use test specific build dir when needed
This commit is contained in:
@@ -221,7 +221,8 @@ type FixtureFactory interface {
|
|||||||
//
|
//
|
||||||
// The buildDirSupplier is a pointer to the package level buildDir variable that is initialized by
|
// The buildDirSupplier is a pointer to the package level buildDir variable that is initialized by
|
||||||
// the package level setUp method. It has to be a pointer to the variable as the variable will not
|
// the package level setUp method. It has to be a pointer to the variable as the variable will not
|
||||||
// have been initialized at the time the factory is created.
|
// have been initialized at the time the factory is created. If it is nil then a test specific
|
||||||
|
// temporary directory will be created instead.
|
||||||
func NewFixtureFactory(buildDirSupplier *string, preparers ...FixturePreparer) FixtureFactory {
|
func NewFixtureFactory(buildDirSupplier *string, preparers ...FixturePreparer) FixtureFactory {
|
||||||
return &fixtureFactory{
|
return &fixtureFactory{
|
||||||
buildDirSupplier: buildDirSupplier,
|
buildDirSupplier: buildDirSupplier,
|
||||||
@@ -585,7 +586,16 @@ func (f *fixtureFactory) Extend(preparers ...FixturePreparer) FixtureFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *fixtureFactory) Fixture(t *testing.T, preparers ...FixturePreparer) Fixture {
|
func (f *fixtureFactory) Fixture(t *testing.T, preparers ...FixturePreparer) Fixture {
|
||||||
config := TestConfig(*f.buildDirSupplier, nil, "", nil)
|
var buildDir string
|
||||||
|
if f.buildDirSupplier == nil {
|
||||||
|
// Create a new temporary directory for this run. It will be automatically cleaned up when the
|
||||||
|
// test finishes.
|
||||||
|
buildDir = t.TempDir()
|
||||||
|
} else {
|
||||||
|
// Retrieve the buildDir from the supplier.
|
||||||
|
buildDir = *f.buildDirSupplier
|
||||||
|
}
|
||||||
|
config := TestConfig(buildDir, nil, "", nil)
|
||||||
ctx := NewTestContext(config)
|
ctx := NewTestContext(config)
|
||||||
fixture := &fixture{
|
fixture := &fixture{
|
||||||
factory: f,
|
factory: f,
|
||||||
|
@@ -15,7 +15,6 @@
|
|||||||
package etc
|
package etc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -23,33 +22,12 @@ import (
|
|||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
)
|
)
|
||||||
|
|
||||||
var buildDir string
|
|
||||||
|
|
||||||
func setUp() {
|
|
||||||
var err error
|
|
||||||
buildDir, err = ioutil.TempDir("", "soong_etc_test")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func tearDown() {
|
|
||||||
os.RemoveAll(buildDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
run := func() int {
|
os.Exit(m.Run())
|
||||||
setUp()
|
|
||||||
defer tearDown()
|
|
||||||
|
|
||||||
return m.Run()
|
|
||||||
}
|
|
||||||
|
|
||||||
os.Exit(run())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var prebuiltEtcFixtureFactory = android.NewFixtureFactory(
|
var prebuiltEtcFixtureFactory = android.NewFixtureFactory(
|
||||||
&buildDir,
|
nil,
|
||||||
android.PrepareForTestWithArchMutator,
|
android.PrepareForTestWithArchMutator,
|
||||||
PrepareForTestWithPrebuiltEtc,
|
PrepareForTestWithPrebuiltEtc,
|
||||||
android.FixtureMergeMockFs(android.MockFS{
|
android.FixtureMergeMockFs(android.MockFS{
|
||||||
@@ -170,8 +148,8 @@ func TestPrebuiltEtcRelativeInstallPathInstallDirPath(t *testing.T) {
|
|||||||
`)
|
`)
|
||||||
|
|
||||||
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
||||||
expected := buildDir + "/target/product/test_device/system/etc/bar"
|
expected := "out/soong/target/product/test_device/system/etc/bar"
|
||||||
android.AssertStringEquals(t, "install dir", expected, p.installDirPath.String())
|
android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrebuiltEtcCannotSetRelativeInstallPathAndSubDir(t *testing.T) {
|
func TestPrebuiltEtcCannotSetRelativeInstallPathAndSubDir(t *testing.T) {
|
||||||
@@ -212,8 +190,8 @@ func TestPrebuiltUserShareInstallDirPath(t *testing.T) {
|
|||||||
`)
|
`)
|
||||||
|
|
||||||
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
||||||
expected := buildDir + "/target/product/test_device/system/usr/share/bar"
|
expected := "out/soong/target/product/test_device/system/usr/share/bar"
|
||||||
android.AssertStringEquals(t, "install dir", expected, p.installDirPath.String())
|
android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrebuiltUserShareHostInstallDirPath(t *testing.T) {
|
func TestPrebuiltUserShareHostInstallDirPath(t *testing.T) {
|
||||||
@@ -227,8 +205,8 @@ func TestPrebuiltUserShareHostInstallDirPath(t *testing.T) {
|
|||||||
|
|
||||||
buildOS := android.BuildOs.String()
|
buildOS := android.BuildOs.String()
|
||||||
p := result.Module("foo.conf", buildOS+"_common").(*PrebuiltEtc)
|
p := result.Module("foo.conf", buildOS+"_common").(*PrebuiltEtc)
|
||||||
expected := filepath.Join(buildDir, "host", result.Config.PrebuiltOS(), "usr", "share", "bar")
|
expected := filepath.Join("out/soong/host", result.Config.PrebuiltOS(), "usr", "share", "bar")
|
||||||
android.AssertStringEquals(t, "install dir", expected, p.installDirPath.String())
|
android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrebuiltFontInstallDirPath(t *testing.T) {
|
func TestPrebuiltFontInstallDirPath(t *testing.T) {
|
||||||
@@ -240,12 +218,12 @@ func TestPrebuiltFontInstallDirPath(t *testing.T) {
|
|||||||
`)
|
`)
|
||||||
|
|
||||||
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
||||||
expected := buildDir + "/target/product/test_device/system/fonts"
|
expected := "out/soong/target/product/test_device/system/fonts"
|
||||||
android.AssertStringEquals(t, "install dir", expected, p.installDirPath.String())
|
android.AssertPathRelativeToTopEquals(t, "install dir", expected, p.installDirPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrebuiltFirmwareDirPath(t *testing.T) {
|
func TestPrebuiltFirmwareDirPath(t *testing.T) {
|
||||||
targetPath := buildDir + "/target/product/test_device"
|
targetPath := "out/soong/target/product/test_device"
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
description string
|
description string
|
||||||
config string
|
config string
|
||||||
@@ -273,13 +251,13 @@ func TestPrebuiltFirmwareDirPath(t *testing.T) {
|
|||||||
t.Run(tt.description, func(t *testing.T) {
|
t.Run(tt.description, func(t *testing.T) {
|
||||||
result := prebuiltEtcFixtureFactory.RunTestWithBp(t, tt.config)
|
result := prebuiltEtcFixtureFactory.RunTestWithBp(t, tt.config)
|
||||||
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
||||||
android.AssertStringEquals(t, "install dir", tt.expectedPath, p.installDirPath.String())
|
android.AssertPathRelativeToTopEquals(t, "install dir", tt.expectedPath, p.installDirPath)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrebuiltDSPDirPath(t *testing.T) {
|
func TestPrebuiltDSPDirPath(t *testing.T) {
|
||||||
targetPath := filepath.Join(buildDir, "/target/product/test_device")
|
targetPath := "out/soong/target/product/test_device"
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
description string
|
description string
|
||||||
config string
|
config string
|
||||||
@@ -307,7 +285,7 @@ func TestPrebuiltDSPDirPath(t *testing.T) {
|
|||||||
t.Run(tt.description, func(t *testing.T) {
|
t.Run(tt.description, func(t *testing.T) {
|
||||||
result := prebuiltEtcFixtureFactory.RunTestWithBp(t, tt.config)
|
result := prebuiltEtcFixtureFactory.RunTestWithBp(t, tt.config)
|
||||||
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
||||||
android.AssertStringEquals(t, "install dir", tt.expectedPath, p.installDirPath.String())
|
android.AssertPathRelativeToTopEquals(t, "install dir", tt.expectedPath, p.installDirPath)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,7 +15,6 @@
|
|||||||
package genrule
|
package genrule
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -25,33 +24,12 @@ import (
|
|||||||
"github.com/google/blueprint/proptools"
|
"github.com/google/blueprint/proptools"
|
||||||
)
|
)
|
||||||
|
|
||||||
var buildDir string
|
|
||||||
|
|
||||||
func setUp() {
|
|
||||||
var err error
|
|
||||||
buildDir, err = ioutil.TempDir("", "genrule_test")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func tearDown() {
|
|
||||||
os.RemoveAll(buildDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
run := func() int {
|
os.Exit(m.Run())
|
||||||
setUp()
|
|
||||||
defer tearDown()
|
|
||||||
|
|
||||||
return m.Run()
|
|
||||||
}
|
|
||||||
|
|
||||||
os.Exit(run())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var genruleFixtureFactory = android.NewFixtureFactory(
|
var genruleFixtureFactory = android.NewFixtureFactory(
|
||||||
&buildDir,
|
nil,
|
||||||
android.PrepareForTestWithArchMutator,
|
android.PrepareForTestWithArchMutator,
|
||||||
android.PrepareForTestWithDefaults,
|
android.PrepareForTestWithDefaults,
|
||||||
|
|
||||||
@@ -572,8 +550,14 @@ func TestGenSrcs(t *testing.T) {
|
|||||||
cmds: []string{
|
cmds: []string{
|
||||||
"bash -c '__SBOX_SANDBOX_DIR__/tools/out/bin/tool in1.txt > __SBOX_SANDBOX_DIR__/out/in1.h' && bash -c '__SBOX_SANDBOX_DIR__/tools/out/bin/tool in2.txt > __SBOX_SANDBOX_DIR__/out/in2.h'",
|
"bash -c '__SBOX_SANDBOX_DIR__/tools/out/bin/tool in1.txt > __SBOX_SANDBOX_DIR__/out/in1.h' && bash -c '__SBOX_SANDBOX_DIR__/tools/out/bin/tool in2.txt > __SBOX_SANDBOX_DIR__/out/in2.h'",
|
||||||
},
|
},
|
||||||
deps: []string{buildDir + "/.intermediates/gen/gen/gensrcs/in1.h", buildDir + "/.intermediates/gen/gen/gensrcs/in2.h"},
|
deps: []string{
|
||||||
files: []string{buildDir + "/.intermediates/gen/gen/gensrcs/in1.h", buildDir + "/.intermediates/gen/gen/gensrcs/in2.h"},
|
"out/soong/.intermediates/gen/gen/gensrcs/in1.h",
|
||||||
|
"out/soong/.intermediates/gen/gen/gensrcs/in2.h",
|
||||||
|
},
|
||||||
|
files: []string{
|
||||||
|
"out/soong/.intermediates/gen/gen/gensrcs/in1.h",
|
||||||
|
"out/soong/.intermediates/gen/gen/gensrcs/in2.h",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "shards",
|
name: "shards",
|
||||||
@@ -587,8 +571,16 @@ func TestGenSrcs(t *testing.T) {
|
|||||||
"bash -c '__SBOX_SANDBOX_DIR__/tools/out/bin/tool in1.txt > __SBOX_SANDBOX_DIR__/out/in1.h' && bash -c '__SBOX_SANDBOX_DIR__/tools/out/bin/tool in2.txt > __SBOX_SANDBOX_DIR__/out/in2.h'",
|
"bash -c '__SBOX_SANDBOX_DIR__/tools/out/bin/tool in1.txt > __SBOX_SANDBOX_DIR__/out/in1.h' && bash -c '__SBOX_SANDBOX_DIR__/tools/out/bin/tool in2.txt > __SBOX_SANDBOX_DIR__/out/in2.h'",
|
||||||
"bash -c '__SBOX_SANDBOX_DIR__/tools/out/bin/tool in3.txt > __SBOX_SANDBOX_DIR__/out/in3.h'",
|
"bash -c '__SBOX_SANDBOX_DIR__/tools/out/bin/tool in3.txt > __SBOX_SANDBOX_DIR__/out/in3.h'",
|
||||||
},
|
},
|
||||||
deps: []string{buildDir + "/.intermediates/gen/gen/gensrcs/in1.h", buildDir + "/.intermediates/gen/gen/gensrcs/in2.h", buildDir + "/.intermediates/gen/gen/gensrcs/in3.h"},
|
deps: []string{
|
||||||
files: []string{buildDir + "/.intermediates/gen/gen/gensrcs/in1.h", buildDir + "/.intermediates/gen/gen/gensrcs/in2.h", buildDir + "/.intermediates/gen/gen/gensrcs/in3.h"},
|
"out/soong/.intermediates/gen/gen/gensrcs/in1.h",
|
||||||
|
"out/soong/.intermediates/gen/gen/gensrcs/in2.h",
|
||||||
|
"out/soong/.intermediates/gen/gen/gensrcs/in3.h",
|
||||||
|
},
|
||||||
|
files: []string{
|
||||||
|
"out/soong/.intermediates/gen/gen/gensrcs/in1.h",
|
||||||
|
"out/soong/.intermediates/gen/gen/gensrcs/in2.h",
|
||||||
|
"out/soong/.intermediates/gen/gen/gensrcs/in3.h",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -616,9 +608,9 @@ func TestGenSrcs(t *testing.T) {
|
|||||||
gen := result.Module("gen", "").(*Module)
|
gen := result.Module("gen", "").(*Module)
|
||||||
android.AssertDeepEquals(t, "cmd", test.cmds, gen.rawCommands)
|
android.AssertDeepEquals(t, "cmd", test.cmds, gen.rawCommands)
|
||||||
|
|
||||||
android.AssertDeepEquals(t, "deps", test.deps, gen.outputDeps.Strings())
|
android.AssertPathsRelativeToTopEquals(t, "deps", test.deps, gen.outputDeps)
|
||||||
|
|
||||||
android.AssertDeepEquals(t, "files", test.files, gen.outputFiles.Strings())
|
android.AssertPathsRelativeToTopEquals(t, "files", test.files, gen.outputFiles)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user