rust: Allow rust_tests to include data files.
Adds the ability to define data files that should be installed alongside the test. This also fixes a bug wherein rust_test properties were duplicated. Bug: 171710847 Test: rust_test module with "data" property installs files to device. Change-Id: I091489afaf7e76b751a33a28049590d9fb39fe5f
This commit is contained in:
parent
9436be4321
commit
9da4aa8166
5 changed files with 32 additions and 6 deletions
|
@ -168,7 +168,7 @@ func androidMkWriteExtraTestConfigs(extraTestConfigs android.Paths, entries *and
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func androidMkWriteTestData(data []android.DataPath, ctx AndroidMkContext, entries *android.AndroidMkEntries) {
|
func AndroidMkWriteTestData(data []android.DataPath, entries *android.AndroidMkEntries) {
|
||||||
testFiles := android.AndroidMkDataPaths(data)
|
testFiles := android.AndroidMkDataPaths(data)
|
||||||
if len(testFiles) > 0 {
|
if len(testFiles) > 0 {
|
||||||
entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
|
entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
|
||||||
|
@ -353,7 +353,7 @@ func (benchmark *benchmarkDecorator) AndroidMkEntries(ctx AndroidMkContext, entr
|
||||||
for _, srcPath := range benchmark.data {
|
for _, srcPath := range benchmark.data {
|
||||||
dataPaths = append(dataPaths, android.DataPath{SrcPath: srcPath})
|
dataPaths = append(dataPaths, android.DataPath{SrcPath: srcPath})
|
||||||
}
|
}
|
||||||
androidMkWriteTestData(dataPaths, ctx, entries)
|
AndroidMkWriteTestData(dataPaths, entries)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (test *testBinary) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
|
func (test *testBinary) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
|
||||||
|
@ -378,7 +378,7 @@ func (test *testBinary) AndroidMkEntries(ctx AndroidMkContext, entries *android.
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
androidMkWriteTestData(test.data, ctx, entries)
|
AndroidMkWriteTestData(test.data, entries)
|
||||||
androidMkWriteExtraTestConfigs(test.extraTestConfigs, entries)
|
androidMkWriteExtraTestConfigs(test.extraTestConfigs, entries)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
|
"android/soong/cc"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AndroidMkContext interface {
|
type AndroidMkContext interface {
|
||||||
|
@ -85,7 +86,8 @@ func (binary *binaryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.Andr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (test *testDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
|
func (test *testDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
|
||||||
test.binaryDecorator.AndroidMk(ctx, ret)
|
ctx.SubAndroidMk(ret, test.binaryDecorator)
|
||||||
|
|
||||||
ret.Class = "NATIVE_TESTS"
|
ret.Class = "NATIVE_TESTS"
|
||||||
ret.ExtraEntries = append(ret.ExtraEntries, func(entries *android.AndroidMkEntries) {
|
ret.ExtraEntries = append(ret.ExtraEntries, func(entries *android.AndroidMkEntries) {
|
||||||
entries.AddCompatibilityTestSuites(test.Properties.Test_suites...)
|
entries.AddCompatibilityTestSuites(test.Properties.Test_suites...)
|
||||||
|
@ -95,7 +97,8 @@ func (test *testDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidM
|
||||||
entries.SetBoolIfTrue("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", !BoolDefault(test.Properties.Auto_gen_config, true))
|
entries.SetBoolIfTrue("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", !BoolDefault(test.Properties.Auto_gen_config, true))
|
||||||
entries.SetBoolIfTrue("LOCAL_IS_UNIT_TEST", Bool(test.Properties.Test_options.Unit_test))
|
entries.SetBoolIfTrue("LOCAL_IS_UNIT_TEST", Bool(test.Properties.Test_options.Unit_test))
|
||||||
})
|
})
|
||||||
// TODO(chh): add test data with androidMkWriteTestData(test.data, ctx, ret)
|
|
||||||
|
cc.AndroidMkWriteTestData(test.data, ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
|
func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
|
||||||
|
|
|
@ -116,6 +116,7 @@ func (tctx *testRustCtx) useMockedFs() {
|
||||||
"foo.proto": nil,
|
"foo.proto": nil,
|
||||||
"liby.so": nil,
|
"liby.so": nil,
|
||||||
"libz.so": nil,
|
"libz.so": nil,
|
||||||
|
"data.txt": nil,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
17
rust/test.go
17
rust/test.go
|
@ -43,6 +43,10 @@ type TestProperties struct {
|
||||||
// installed into.
|
// installed into.
|
||||||
Test_suites []string `android:"arch_variant"`
|
Test_suites []string `android:"arch_variant"`
|
||||||
|
|
||||||
|
// list of files or filegroup modules that provide data that should be installed alongside
|
||||||
|
// the test
|
||||||
|
Data []string `android:"path,arch_variant"`
|
||||||
|
|
||||||
// Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
|
// Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
|
||||||
// doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
|
// doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
|
||||||
// explicitly.
|
// explicitly.
|
||||||
|
@ -62,6 +66,12 @@ type testDecorator struct {
|
||||||
*binaryDecorator
|
*binaryDecorator
|
||||||
Properties TestProperties
|
Properties TestProperties
|
||||||
testConfig android.Path
|
testConfig android.Path
|
||||||
|
|
||||||
|
data []android.DataPath
|
||||||
|
}
|
||||||
|
|
||||||
|
func (test *testDecorator) dataPaths() []android.DataPath {
|
||||||
|
return test.data
|
||||||
}
|
}
|
||||||
|
|
||||||
func (test *testDecorator) nativeCoverage() bool {
|
func (test *testDecorator) nativeCoverage() bool {
|
||||||
|
@ -89,7 +99,6 @@ func NewRustTest(hod android.HostOrDeviceSupported) (*Module, *testDecorator) {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.compiler = test
|
module.compiler = test
|
||||||
module.AddProperties(&test.Properties)
|
|
||||||
return module, test
|
return module, test
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,6 +114,12 @@ func (test *testDecorator) install(ctx ModuleContext) {
|
||||||
nil,
|
nil,
|
||||||
test.Properties.Auto_gen_config)
|
test.Properties.Auto_gen_config)
|
||||||
|
|
||||||
|
dataSrcPaths := android.PathsForModuleSrc(ctx, test.Properties.Data)
|
||||||
|
|
||||||
|
for _, dataSrcPath := range dataSrcPaths {
|
||||||
|
test.data = append(test.data, android.DataPath{SrcPath: dataSrcPath})
|
||||||
|
}
|
||||||
|
|
||||||
// default relative install path is module name
|
// default relative install path is module name
|
||||||
if !Bool(test.Properties.No_named_install_directory) {
|
if !Bool(test.Properties.No_named_install_directory) {
|
||||||
test.baseCompiler.relative = ctx.ModuleName()
|
test.baseCompiler.relative = ctx.ModuleName()
|
||||||
|
|
|
@ -26,6 +26,7 @@ func TestRustTest(t *testing.T) {
|
||||||
rust_test_host {
|
rust_test_host {
|
||||||
name: "my_test",
|
name: "my_test",
|
||||||
srcs: ["foo.rs"],
|
srcs: ["foo.rs"],
|
||||||
|
data: ["data.txt"],
|
||||||
}`)
|
}`)
|
||||||
|
|
||||||
testingModule := ctx.ModuleForTests("my_test", "linux_glibc_x86_64")
|
testingModule := ctx.ModuleForTests("my_test", "linux_glibc_x86_64")
|
||||||
|
@ -34,6 +35,12 @@ func TestRustTest(t *testing.T) {
|
||||||
if !strings.Contains(outPath, expectedOut) {
|
if !strings.Contains(outPath, expectedOut) {
|
||||||
t.Errorf("wrong output path: %v; expected: %v", outPath, expectedOut)
|
t.Errorf("wrong output path: %v; expected: %v", outPath, expectedOut)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dataPaths := testingModule.Module().(*Module).compiler.(*testDecorator).dataPaths()
|
||||||
|
if len(dataPaths) != 1 {
|
||||||
|
t.Errorf("expected exactly one test data file. test data files: [%s]", dataPaths)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRustTestLinkage(t *testing.T) {
|
func TestRustTestLinkage(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue