Move test data installation to Soong

To generate module-info.json in Soong for b/309006256 Soong needs to
know the test data paths. Moving test data installation into Soong will
also help later for test suite packaging.

Add ModuleContext.InstallTestData that installs the files listed in a
[]DataPath alongside the test.  The files will also be passed to Make
to allow it to continue packaging them into the test suites for now.

Update the module types that are producing LOCAL_TEST_DATA entries
in their Android.mk files to go through InstallTestData instead.

Bug: 311428265
Test: atest --host toybox-gtests --test-timeout=120000
Change-Id: Ia8b964f86e584ea464667fd86a48d754d118bead
This commit is contained in:
Colin Cross
2023-11-15 12:39:40 -08:00
parent 312634eb0f
commit 5c1d5fb21b
17 changed files with 165 additions and 161 deletions

View File

@@ -175,15 +175,6 @@ func androidMkWriteExtraTestConfigs(extraTestConfigs android.Paths, entries *and
}
}
func AndroidMkWriteTestData(data []android.DataPath, entries *android.AndroidMkEntries) {
testFiles := android.AndroidMkDataPaths(data)
if len(testFiles) > 0 {
entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
entries.AddStrings("LOCAL_TEST_DATA", testFiles...)
})
}
}
func makeOverrideModuleNames(ctx AndroidMkContext, overrides []string) []string {
if ctx.Target().NativeBridge == android.NativeBridgeEnabled {
var result []string
@@ -379,11 +370,6 @@ func (benchmark *benchmarkDecorator) AndroidMkEntries(ctx AndroidMkContext, entr
entries.SetBool("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", true)
}
})
dataPaths := []android.DataPath{}
for _, srcPath := range benchmark.data {
dataPaths = append(dataPaths, android.DataPath{SrcPath: srcPath})
}
AndroidMkWriteTestData(dataPaths, entries)
}
func (test *testBinary) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
@@ -411,40 +397,16 @@ func (test *testBinary) AndroidMkEntries(ctx AndroidMkContext, entries *android.
test.Properties.Test_options.CommonTestOptions.SetAndroidMkEntries(entries)
})
AndroidMkWriteTestData(test.data, entries)
androidMkWriteExtraTestConfigs(test.extraTestConfigs, entries)
}
func (fuzz *fuzzBinary) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
ctx.subAndroidMk(entries, fuzz.binaryDecorator)
var fuzzFiles []string
for _, d := range fuzz.fuzzPackagedModule.Corpus {
fuzzFiles = append(fuzzFiles,
filepath.Dir(fuzz.fuzzPackagedModule.CorpusIntermediateDir.String())+":corpus/"+d.Base())
}
for _, d := range fuzz.fuzzPackagedModule.Data {
fuzzFiles = append(fuzzFiles,
filepath.Dir(fuzz.fuzzPackagedModule.DataIntermediateDir.String())+":data/"+d.Rel())
}
if fuzz.fuzzPackagedModule.Dictionary != nil {
fuzzFiles = append(fuzzFiles,
filepath.Dir(fuzz.fuzzPackagedModule.Dictionary.String())+":"+fuzz.fuzzPackagedModule.Dictionary.Base())
}
if fuzz.fuzzPackagedModule.Config != nil {
fuzzFiles = append(fuzzFiles,
filepath.Dir(fuzz.fuzzPackagedModule.Config.String())+":config.json")
}
entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
entries.SetBool("LOCAL_IS_FUZZ_TARGET", true)
if len(fuzzFiles) > 0 {
entries.AddStrings("LOCAL_TEST_DATA", fuzzFiles...)
}
if fuzz.installedSharedDeps != nil {
// TOOD: move to install dep
entries.AddStrings("LOCAL_FUZZ_INSTALLED_SHARED_DEPS", fuzz.installedSharedDeps...)
}
})

View File

@@ -106,6 +106,7 @@ type fuzzBinary struct {
fuzzPackagedModule fuzz.FuzzPackagedModule
installedSharedDeps []string
sharedLibraries android.RuleBuilderInstalls
data []android.DataPath
}
func (fuzz *fuzzBinary) fuzzBinary() bool {
@@ -231,16 +232,10 @@ func SharedLibrarySymbolsInstallLocation(libraryBase string, fuzzDir string, arc
}
func (fuzzBin *fuzzBinary) install(ctx ModuleContext, file android.Path) {
installBase := "fuzz"
fuzzBin.binaryDecorator.baseInstaller.dir = filepath.Join(
installBase, ctx.Target().Arch.ArchType.String(), ctx.ModuleName())
fuzzBin.binaryDecorator.baseInstaller.dir64 = filepath.Join(
installBase, ctx.Target().Arch.ArchType.String(), ctx.ModuleName())
fuzzBin.binaryDecorator.baseInstaller.install(ctx, file)
fuzzBin.fuzzPackagedModule = PackageFuzzModule(ctx, fuzzBin.fuzzPackagedModule, pctx)
installBase := "fuzz"
// Grab the list of required shared libraries.
fuzzBin.sharedLibraries, _ = CollectAllSharedDependencies(ctx)
@@ -256,34 +251,35 @@ func (fuzzBin *fuzzBinary) install(ctx ModuleContext, file android.Path) {
SharedLibrarySymbolsInstallLocation(install, installBase, ctx.Arch().ArchType.String()))
}
}
for _, d := range fuzzBin.fuzzPackagedModule.Corpus {
fuzzBin.data = append(fuzzBin.data, android.DataPath{SrcPath: d, RelativeInstallPath: "corpus", WithoutRel: true})
}
for _, d := range fuzzBin.fuzzPackagedModule.Data {
fuzzBin.data = append(fuzzBin.data, android.DataPath{SrcPath: d, RelativeInstallPath: "data"})
}
if d := fuzzBin.fuzzPackagedModule.Dictionary; d != nil {
fuzzBin.data = append(fuzzBin.data, android.DataPath{SrcPath: d, WithoutRel: true})
}
if d := fuzzBin.fuzzPackagedModule.Config; d != nil {
fuzzBin.data = append(fuzzBin.data, android.DataPath{SrcPath: d, WithoutRel: true})
}
fuzzBin.binaryDecorator.baseInstaller.dir = filepath.Join(
installBase, ctx.Target().Arch.ArchType.String(), ctx.ModuleName())
fuzzBin.binaryDecorator.baseInstaller.dir64 = filepath.Join(
installBase, ctx.Target().Arch.ArchType.String(), ctx.ModuleName())
fuzzBin.binaryDecorator.baseInstaller.installTestData(ctx, fuzzBin.data)
fuzzBin.binaryDecorator.baseInstaller.install(ctx, file)
}
func PackageFuzzModule(ctx android.ModuleContext, fuzzPackagedModule fuzz.FuzzPackagedModule, pctx android.PackageContext) fuzz.FuzzPackagedModule {
fuzzPackagedModule.Corpus = android.PathsForModuleSrc(ctx, fuzzPackagedModule.FuzzProperties.Corpus)
intermediateDir := android.PathForModuleOut(ctx, "corpus")
// Create one rule per file to avoid MAX_ARG_STRLEN hardlimit.
for _, entry := range fuzzPackagedModule.Corpus {
ctx.Build(pctx, android.BuildParams{
Rule: android.Cp,
Output: intermediateDir.Join(ctx, entry.Base()),
Input: entry,
})
}
fuzzPackagedModule.CorpusIntermediateDir = intermediateDir
fuzzPackagedModule.Data = android.PathsForModuleSrc(ctx, fuzzPackagedModule.FuzzProperties.Data)
intermediateDir = android.PathForModuleOut(ctx, "data")
// Create one rule per file to avoid MAX_ARG_STRLEN hardlimit.
for _, entry := range fuzzPackagedModule.Data {
ctx.Build(pctx, android.BuildParams{
Rule: android.Cp,
Output: intermediateDir.Join(ctx, entry.Rel()),
Input: entry,
})
}
fuzzPackagedModule.DataIntermediateDir = intermediateDir
if fuzzPackagedModule.FuzzProperties.Dictionary != nil {
fuzzPackagedModule.Dictionary = android.PathForModuleSrc(ctx, *fuzzPackagedModule.FuzzProperties.Dictionary)

View File

@@ -59,6 +59,8 @@ type baseInstaller struct {
relative string
location installLocation
installDeps android.InstallPaths
path android.InstallPath
}
@@ -97,7 +99,12 @@ func (installer *baseInstaller) installDir(ctx ModuleContext) android.InstallPat
}
func (installer *baseInstaller) install(ctx ModuleContext, file android.Path) {
installer.path = ctx.InstallFile(installer.installDir(ctx), file.Base(), file)
installer.path = ctx.InstallFile(installer.installDir(ctx), file.Base(), file, installer.installDeps...)
}
func (installer *baseInstaller) installTestData(ctx ModuleContext, data []android.DataPath) {
installedData := ctx.InstallTestData(installer.installDir(ctx), data)
installer.installDeps = append(installer.installDeps, installedData...)
}
func (installer *baseInstaller) everInstallable() bool {

View File

@@ -424,6 +424,8 @@ func (test *testBinary) install(ctx ModuleContext, file android.Path) {
if ctx.Host() && test.gtest() && test.Properties.Test_options.Unit_test == nil {
test.Properties.Test_options.Unit_test = proptools.BoolPtr(true)
}
test.binaryDecorator.baseInstaller.installTestData(ctx, test.data)
test.binaryDecorator.baseInstaller.install(ctx, file)
}
@@ -584,7 +586,7 @@ type BenchmarkProperties struct {
type benchmarkDecorator struct {
*binaryDecorator
Properties BenchmarkProperties
data android.Paths
data []android.DataPath
testConfig android.Path
}
@@ -605,7 +607,9 @@ func (benchmark *benchmarkDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps
}
func (benchmark *benchmarkDecorator) install(ctx ModuleContext, file android.Path) {
benchmark.data = android.PathsForModuleSrc(ctx, benchmark.Properties.Data)
for _, d := range android.PathsForModuleSrc(ctx, benchmark.Properties.Data) {
benchmark.data = append(benchmark.data, android.DataPath{SrcPath: d})
}
var configs []tradefed.Config
if Bool(benchmark.Properties.Require_root) {
@@ -623,6 +627,7 @@ func (benchmark *benchmarkDecorator) install(ctx ModuleContext, file android.Pat
benchmark.binaryDecorator.baseInstaller.dir = filepath.Join("benchmarktest", ctx.ModuleName())
benchmark.binaryDecorator.baseInstaller.dir64 = filepath.Join("benchmarktest64", ctx.ModuleName())
benchmark.binaryDecorator.baseInstaller.installTestData(ctx, benchmark.data)
benchmark.binaryDecorator.baseInstaller.install(ctx, file)
}