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

@@ -17,7 +17,6 @@ package sh
import (
"fmt"
"path/filepath"
"sort"
"strings"
"android/soong/testing"
@@ -174,7 +173,7 @@ type ShTest struct {
installDir android.InstallPath
data android.Paths
data []android.DataPath
testConfig android.Path
dataModules map[string]android.Path
@@ -360,10 +359,21 @@ func (s *ShTest) addToDataModules(ctx android.ModuleContext, relPath string, pat
return
}
s.dataModules[relPath] = path
s.data = append(s.data, android.DataPath{SrcPath: path})
}
func (s *ShTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
s.ShBinary.generateAndroidBuildActions(ctx)
expandedData := android.PathsForModuleSrc(ctx, s.testProperties.Data)
// Emulate the data property for java_data dependencies.
for _, javaData := range ctx.GetDirectDepsWithTag(shTestJavaDataTag) {
expandedData = append(expandedData, android.OutputFilesForModule(ctx, javaData, "")...)
}
for _, d := range expandedData {
s.data = append(s.data, android.DataPath{SrcPath: d})
}
testDir := "nativetest"
if ctx.Target().Arch.ArchType.Multilib == "lib64" {
testDir = "nativetest64"
@@ -380,15 +390,6 @@ func (s *ShTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
} else {
s.installDir = android.PathForModuleInstall(ctx, testDir, s.Name())
}
s.installedFile = ctx.InstallExecutable(s.installDir, s.outputFilePath.Base(), s.outputFilePath)
expandedData := android.PathsForModuleSrc(ctx, s.testProperties.Data)
// Emulate the data property for java_data dependencies.
for _, javaData := range ctx.GetDirectDepsWithTag(shTestJavaDataTag) {
expandedData = append(expandedData, android.OutputFilesForModule(ctx, javaData, "")...)
}
s.data = expandedData
var configs []tradefed.Config
if Bool(s.testProperties.Require_root) {
@@ -437,7 +438,7 @@ func (s *ShTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
if _, exist := s.dataModules[relPath]; exist {
return
}
relocatedLib := android.PathForModuleOut(ctx, "relocated", relPath)
relocatedLib := android.PathForModuleOut(ctx, "relocated").Join(ctx, relPath)
ctx.Build(pctx, android.BuildParams{
Rule: android.Cp,
Input: cc.OutputFile().Path(),
@@ -453,6 +454,10 @@ func (s *ShTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
ctx.PropertyErrorf(property, "%q of type %q is not supported", dep.Name(), ctx.OtherModuleType(dep))
}
})
installedData := ctx.InstallTestData(s.installDir, s.data)
s.installedFile = ctx.InstallExecutable(s.installDir, s.outputFilePath.Base(), s.outputFilePath, installedData...)
ctx.SetProvider(testing.TestModuleProviderKey, testing.TestModuleProviderData{})
}
@@ -473,24 +478,6 @@ func (s *ShTest) AndroidMkEntries() []android.AndroidMkEntries {
if s.testConfig != nil {
entries.SetPath("LOCAL_FULL_TEST_CONFIG", s.testConfig)
}
for _, d := range s.data {
rel := d.Rel()
path := d.String()
if !strings.HasSuffix(path, rel) {
panic(fmt.Errorf("path %q does not end with %q", path, rel))
}
path = strings.TrimSuffix(path, rel)
entries.AddStrings("LOCAL_TEST_DATA", path+":"+rel)
}
relPaths := make([]string, 0)
for relPath, _ := range s.dataModules {
relPaths = append(relPaths, relPath)
}
sort.Strings(relPaths)
for _, relPath := range relPaths {
dir := strings.TrimSuffix(s.dataModules[relPath].String(), relPath)
entries.AddStrings("LOCAL_TEST_DATA", dir+":"+relPath)
}
if s.testProperties.Data_bins != nil {
entries.AddStrings("LOCAL_TEST_DATA_BINS", s.testProperties.Data_bins...)
}

View File

@@ -135,7 +135,7 @@ func TestShTest_dataModules(t *testing.T) {
if arch == "darwin_x86_64" {
libExt = ".dylib"
}
relocated := variant.Output("relocated/lib64/libbar" + libExt)
relocated := variant.Output(filepath.Join("out/soong/.intermediates/foo", arch, "relocated/lib64/libbar"+libExt))
expectedInput := "out/soong/.intermediates/libbar/" + arch + "_shared/libbar" + libExt
android.AssertPathRelativeToTopEquals(t, "relocation input", expectedInput, relocated.Input)
@@ -204,18 +204,19 @@ func TestShTestHost_dataDeviceModules(t *testing.T) {
`)
buildOS := config.BuildOS.String()
variant := ctx.ModuleForTests("foo", buildOS+"_x86_64")
variant := buildOS + "_x86_64"
foo := ctx.ModuleForTests("foo", variant)
relocated := variant.Output("relocated/lib64/libbar.so")
relocated := foo.Output(filepath.Join("out/soong/.intermediates/foo", variant, "relocated/lib64/libbar.so"))
expectedInput := "out/soong/.intermediates/libbar/android_arm64_armv8-a_shared/libbar.so"
android.AssertPathRelativeToTopEquals(t, "relocation input", expectedInput, relocated.Input)
mod := variant.Module().(*ShTest)
mod := foo.Module().(*ShTest)
entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0]
expectedData := []string{
"out/soong/.intermediates/bar/android_arm64_armv8-a/:bar",
// libbar has been relocated, and so has a variant that matches the host arch.
"out/soong/.intermediates/foo/" + buildOS + "_x86_64/relocated/:lib64/libbar.so",
"out/soong/.intermediates/foo/" + variant + "/relocated/:lib64/libbar.so",
}
actualData := entries.EntryMap["LOCAL_TEST_DATA"]
android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_TEST_DATA", config, expectedData, actualData)