Merge "Prefer variants test-only:true attribute when grouping." into main

This commit is contained in:
Treehugger Robot
2024-04-19 03:15:30 +00:00
committed by Gerrit Code Review
2 changed files with 71 additions and 17 deletions

View File

@@ -79,11 +79,6 @@ func (t *allTeamsSingleton) GenerateBuildActions(ctx SingletonContext) {
ctx.VisitAllModules(func(module Module) { ctx.VisitAllModules(func(module Module) {
bpFile := ctx.BlueprintFile(module) bpFile := ctx.BlueprintFile(module)
testModInfo := TestModuleInformation{}
if tmi, ok := SingletonModuleProvider(ctx, module, TestOnlyProviderKey); ok {
testModInfo = tmi
}
// Package Modules and Team Modules are stored in a map so we can look them up by name for // Package Modules and Team Modules are stored in a map so we can look them up by name for
// modules without a team. // modules without a team.
if pack, ok := module.(*packageModule); ok { if pack, ok := module.(*packageModule); ok {
@@ -97,6 +92,23 @@ func (t *allTeamsSingleton) GenerateBuildActions(ctx SingletonContext) {
return return
} }
testModInfo := TestModuleInformation{}
if tmi, ok := SingletonModuleProvider(ctx, module, TestOnlyProviderKey); ok {
testModInfo = tmi
}
// Some modules, like java_test_host don't set the provider when the module isn't enabled:
// test_only, top_level
// AVFHostTestCases{os:linux_glibc,arch:common} {true true}
// AVFHostTestCases{os:windows,arch:common} {false false}
// Generally variant information of true override false or unset.
if testModInfo.TestOnly == false {
if prevValue, exists := t.teams_for_mods[module.Name()]; exists {
if prevValue.testOnly == true {
return
}
}
}
entry := moduleTeamAndTestInfo{ entry := moduleTeamAndTestInfo{
bpFile: bpFile, bpFile: bpFile,
testOnly: testModInfo.TestOnly, testOnly: testModInfo.TestOnly,

View File

@@ -25,6 +25,8 @@ func TestAllTeams(t *testing.T) {
t.Parallel() t.Parallel()
ctx := GroupFixturePreparers( ctx := GroupFixturePreparers(
prepareForTestWithTeamAndFakes, prepareForTestWithTeamAndFakes,
// This adds two variants, one armv7-a-neon, one armv8-a
PrepareForTestWithArchMutator,
FixtureRegisterWithContext(func(ctx RegistrationContext) { FixtureRegisterWithContext(func(ctx RegistrationContext) {
ctx.RegisterParallelSingletonType("all_teams", AllTeamsFactory) ctx.RegisterParallelSingletonType("all_teams", AllTeamsFactory)
}), }),
@@ -52,10 +54,35 @@ func TestAllTeams(t *testing.T) {
name: "noteam", name: "noteam",
test_only: true, test_only: true,
} }
// write the test-only provider value once
fake { fake {
name: "test-and-team-and-top", name: "test-and-team-and-top1",
test_only: true, test_only: true,
team: "team2", team: "team2",
arch: {arm: { skip: false},
arm64: { skip: true}},
}
// write the test-only provider once, but on the other arch
fake {
name: "test-and-team-and-top2",
test_only: true,
team: "team2",
arch: {arm: { skip: true},
arm64: { skip: false}},
}
// write the test-only provider value twice
fake {
name: "test-and-team-and-top3",
test_only: true,
team: "team2",
}
// Don't write the test-only provider value
fake {
name: "test-and-team-and-top4",
test_only: true,
team: "team2",
arch: {arm: { skip: true},
arm64: { skip: true}},
} }
`) `)
@@ -63,12 +90,16 @@ func TestAllTeams(t *testing.T) {
teams = getTeamProtoOutput(t, ctx) teams = getTeamProtoOutput(t, ctx)
// map of module name -> trendy team name. // map of module name -> trendy team name.
actualTeams := make(map[string]*string) actualTeams := make(map[string]string)
actualTests := []string{} actualTests := []string{}
actualTopLevelTests := []string{} actualTopLevelTests := []string{}
for _, teamProto := range teams.Teams { for _, teamProto := range teams.Teams {
actualTeams[teamProto.GetTargetName()] = teamProto.TrendyTeamId if teamProto.TrendyTeamId != nil {
actualTeams[teamProto.GetTargetName()] = *teamProto.TrendyTeamId
} else {
actualTeams[teamProto.GetTargetName()] = ""
}
if teamProto.GetTestOnly() { if teamProto.GetTestOnly() {
actualTests = append(actualTests, teamProto.GetTargetName()) actualTests = append(actualTests, teamProto.GetTargetName())
} }
@@ -76,16 +107,23 @@ func TestAllTeams(t *testing.T) {
actualTopLevelTests = append(actualTopLevelTests, teamProto.GetTargetName()) actualTopLevelTests = append(actualTopLevelTests, teamProto.GetTargetName())
} }
} }
expectedTeams := map[string]*string{ expectedTeams := map[string]string{
"main_test": proto.String("cool_team"), "main_test": "cool_team",
"tool": proto.String("22222"), "tool": "22222",
"test-and-team-and-top": proto.String("22222"), "test-and-team-and-top1": "22222",
"noteam": nil, "test-and-team-and-top2": "22222",
"test-and-team-and-top3": "22222",
"test-and-team-and-top4": "22222",
"noteam": "",
} }
expectedTests := []string{ expectedTests := []string{
"noteam", "noteam",
"test-and-team-and-top", "test-and-team-and-top1",
"test-and-team-and-top2",
"test-and-team-and-top3",
// There should be no test-and-team-top4 as we skip writing all variants
// test-only for all variants
} }
AssertDeepEquals(t, "compare maps", expectedTeams, actualTeams) AssertDeepEquals(t, "compare maps", expectedTeams, actualTeams)
AssertDeepEquals(t, "test matchup", expectedTests, actualTests) AssertDeepEquals(t, "test matchup", expectedTests, actualTests)
@@ -230,12 +268,16 @@ type fakeForTests struct {
ModuleBase ModuleBase
sourceProperties SourceProperties sourceProperties SourceProperties
props struct {
// If true, don't write test-only value in provider
Skip bool `android:"arch_variant"`
}
} }
func fakeFactory() Module { func fakeFactory() Module {
module := &fakeForTests{} module := &fakeForTests{}
module.AddProperties(&module.sourceProperties) module.AddProperties(&module.sourceProperties, &module.props)
InitAndroidModule(module) InitAndroidArchModule(module, HostAndDeviceSupported, MultilibBoth)
return module return module
} }
@@ -250,7 +292,7 @@ var prepareForTestWithTeamAndFakes = GroupFixturePreparers(
func (f *fakeForTests) GenerateAndroidBuildActions(ctx ModuleContext) { func (f *fakeForTests) GenerateAndroidBuildActions(ctx ModuleContext) {
if Bool(f.sourceProperties.Test_only) { if Bool(f.sourceProperties.Test_only) {
SetProvider(ctx, TestOnlyProviderKey, TestModuleInformation{ SetProvider(ctx, TestOnlyProviderKey, TestModuleInformation{
TestOnly: Bool(f.sourceProperties.Test_only), TestOnly: Bool(f.sourceProperties.Test_only) && !f.props.Skip,
TopLevelTarget: false, TopLevelTarget: false,
}) })
} }