Install rust tests under nativetest(64)

* Now the installation directories match those for C/C++ tests:
  * The relative_install_path refers to path under nativetest(64).
  * Device test files are installed in data/nativetest(64).
  * Automatically generated configuration files and copied test binaries
    are still in the "testcases" directory.
* Change host test configuration to run test binary files
  in testcases/<mutated_module_name>/<arch_type>/<stem_name>

Bug: 140938178
Test: atest --include-subdirs under external/rust/crates
Change-Id: I4b29afb897f4ba8749e87f79857c5b1a959bb2b0
This commit is contained in:
Chih-Hung Hsieh 2019-12-12 19:36:05 -08:00
parent edb4e21de5
commit 9a4a7bab41
6 changed files with 39 additions and 15 deletions

View file

@ -57,7 +57,7 @@ func NewRustBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator
module := newModule(hod, android.MultilibFirst) module := newModule(hod, android.MultilibFirst)
binary := &binaryDecorator{ binary := &binaryDecorator{
baseCompiler: NewBaseCompiler("bin", ""), baseCompiler: NewBaseCompiler("bin", "", InstallInSystem),
} }
module.compiler = binary module.compiler = binary

View file

@ -36,14 +36,22 @@ func (compiler *baseCompiler) setNoStdlibs() {
compiler.Properties.No_stdlibs = proptools.BoolPtr(true) compiler.Properties.No_stdlibs = proptools.BoolPtr(true)
} }
func NewBaseCompiler(dir, dir64 string) *baseCompiler { func NewBaseCompiler(dir, dir64 string, location installLocation) *baseCompiler {
return &baseCompiler{ return &baseCompiler{
Properties: BaseCompilerProperties{}, Properties: BaseCompilerProperties{},
dir: dir, dir: dir,
dir64: dir64, dir64: dir64,
location: location,
} }
} }
type installLocation int
const (
InstallInSystem installLocation = 0
InstallInData = iota
)
type BaseCompilerProperties struct { type BaseCompilerProperties struct {
// whether to pass "-D warnings" to rustc. Defaults to true. // whether to pass "-D warnings" to rustc. Defaults to true.
Deny_warnings *bool Deny_warnings *bool
@ -109,10 +117,15 @@ type baseCompiler struct {
subDir string subDir string
relative string relative string
path android.InstallPath path android.InstallPath
location installLocation
} }
var _ compiler = (*baseCompiler)(nil) var _ compiler = (*baseCompiler)(nil)
func (compiler *baseCompiler) inData() bool {
return compiler.location == InstallInData
}
func (compiler *baseCompiler) compilerProps() []interface{} { func (compiler *baseCompiler) compilerProps() []interface{} {
return []interface{}{&compiler.Properties} return []interface{}{&compiler.Properties}
} }

View file

@ -290,7 +290,7 @@ func NewRustLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorat
BuildShared: true, BuildShared: true,
BuildStatic: true, BuildStatic: true,
}, },
baseCompiler: NewBaseCompiler("lib", "lib64"), baseCompiler: NewBaseCompiler("lib", "lib64", InstallInSystem),
} }
module.compiler = library module.compiler = library

View file

@ -53,7 +53,7 @@ func NewProcMacro(hod android.HostOrDeviceSupported) (*Module, *procMacroDecorat
module := newModule(hod, android.MultilibFirst) module := newModule(hod, android.MultilibFirst)
procMacro := &procMacroDecorator{ procMacro := &procMacroDecorator{
baseCompiler: NewBaseCompiler("lib", "lib64"), baseCompiler: NewBaseCompiler("lib", "lib64", InstallInSystem),
} }
module.compiler = procMacro module.compiler = procMacro

View file

@ -226,6 +226,7 @@ type compiler interface {
compilerDeps(ctx DepsContext, deps Deps) Deps compilerDeps(ctx DepsContext, deps Deps) Deps
crateName() string crateName() string
inData() bool
install(ctx ModuleContext, path android.Path) install(ctx ModuleContext, path android.Path)
relativeInstallPath() string relativeInstallPath() string
} }
@ -681,6 +682,13 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
return depPaths return depPaths
} }
func (mod *Module) InstallInData() bool {
if mod.compiler == nil {
return false
}
return mod.compiler.inData()
}
func linkPathFromFilePath(filepath android.Path) string { func linkPathFromFilePath(filepath android.Path) string {
return strings.Split(filepath.String(), filepath.Base())[0] return strings.Split(filepath.String(), filepath.Base())[0]
} }

View file

@ -55,8 +55,7 @@ func NewRustTest(hod android.HostOrDeviceSupported) (*Module, *testDecorator) {
test := &testDecorator{ test := &testDecorator{
binaryDecorator: &binaryDecorator{ binaryDecorator: &binaryDecorator{
// TODO(chh): set up dir64? baseCompiler: NewBaseCompiler("nativetest", "nativetest64", InstallInData),
baseCompiler: NewBaseCompiler("testcases", ""),
}, },
} }
@ -79,22 +78,26 @@ func (test *testDecorator) getMutatedModuleSubName(moduleName string) string {
} }
func (test *testDecorator) install(ctx ModuleContext, file android.Path) { func (test *testDecorator) install(ctx ModuleContext, file android.Path) {
name := ctx.ModuleName() // default executable name name := ctx.ModuleName()
if ctx.Device() { // on device, use mutated module name path := test.baseCompiler.relativeInstallPath()
name = name + test.getMutatedModuleSubName(name) // on device, use mutated module name
} else { // on host, use stem name in relative_install_path name = name + test.getMutatedModuleSubName(name)
if stem := String(test.baseCompiler.Properties.Stem); stem != "" { if !ctx.Device() { // on host, use mutated module name + arch type + stem name
name = stem stem := String(test.baseCompiler.Properties.Stem)
} if stem == "" {
if path := test.baseCompiler.relativeInstallPath(); path != "" { stem = name
name = path + "/" + name
} }
name = filepath.Join(name, ctx.Arch().ArchType.String(), stem)
} }
test.testConfig = tradefed.AutoGenRustTestConfig(ctx, name, test.testConfig = tradefed.AutoGenRustTestConfig(ctx, name,
test.Properties.Test_config, test.Properties.Test_config,
test.Properties.Test_config_template, test.Properties.Test_config_template,
test.Properties.Test_suites, test.Properties.Test_suites,
test.Properties.Auto_gen_config) test.Properties.Auto_gen_config)
// default relative install path is module name
if path == "" {
test.baseCompiler.relative = ctx.ModuleName()
}
test.binaryDecorator.install(ctx, file) test.binaryDecorator.install(ctx, file)
} }