Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6a08d491 authored by Ronald Braunstein's avatar Ronald Braunstein
Browse files

Add test-only for test-per-src cc modules

When testing test-only validations, I noticed that some cc_test modules
where not reporting that they were test-only.

This happened because test-per-src variations were short-circuiting
writing out the provider.

The `all_teams` target is using the first variation for a module, but
it possibly should see if any variation is test-only.
For now, just making this fix to cc.

Test: m all_teams  && gqui from  "flatten(out/soong/ownership/all_teams.pb, teams)" proto build/soong/android/team_proto/team.proto:AllTeams ' where teams.kind = "cc_test" and teams.target_name="libnativebridge-tests"'
Test: go test ./cc
Change-Id: I6d44a521f5f2457527049399509d979559d7dc17
parent 935b4db4
Loading
Loading
Loading
Loading
+14 −13
Original line number Diff line number Diff line
@@ -1995,6 +1995,20 @@ func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
}

func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
	ctx := moduleContextFromAndroidModuleContext(actx, c)

	// If Test_only is set on a module in bp file, respect the setting, otherwise
	// see if is a known test module type.
	testOnly := c.testModule || c.testLibrary()
	if c.sourceProperties.Test_only != nil {
		testOnly = Bool(c.sourceProperties.Test_only)
	}
	// Keep before any early returns.
	android.SetProvider(ctx, android.TestOnlyProviderKey, android.TestModuleInformation{
		TestOnly:       testOnly,
		TopLevelTarget: c.testModule,
	})

	// Handle the case of a test module split by `test_per_src` mutator.
	//
	// The `test_per_src` mutator adds an extra variation named "", depending on all the other
@@ -2013,8 +2027,6 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {

	c.makeLinkType = GetMakeLinkType(actx, c)

	ctx := moduleContextFromAndroidModuleContext(actx, c)

	deps := c.depsToPaths(ctx)
	if ctx.Failed() {
		return
@@ -2141,17 +2153,6 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
		android.SetProvider(ctx, testing.TestModuleProviderKey, testing.TestModuleProviderData{})
	}

	// If Test_only is set on a module in bp file, respect the setting, otherwise
	// see if is a known test module type.
	testOnly := c.testModule || c.testLibrary()
	if c.sourceProperties.Test_only != nil {
		testOnly = Bool(c.sourceProperties.Test_only)
	}
	android.SetProvider(ctx, android.TestOnlyProviderKey, android.TestModuleInformation{
		TestOnly:       testOnly,
		TopLevelTarget: c.testModule,
	})

	android.SetProvider(ctx, blueprint.SrcsFileProviderKey, blueprint.SrcsFileProviderData{SrcPaths: deps.GeneratedSources.Strings()})

	android.CollectDependencyAconfigFiles(ctx, &c.mergedAconfigFiles)
+32 −0
Original line number Diff line number Diff line
@@ -78,6 +78,38 @@ func TestTestOnlyProvider(t *testing.T) {
	}
}

func TestTestOnlyValueWithTestPerSrcProp(t *testing.T) {
	t.Parallel()
	ctx := android.GroupFixturePreparers(
		prepareForCcTest,
	).RunTestWithBp(t, `
                // These should be test-only
                cc_test { name: "cc-test",
                          gtest: false,
                          test_per_src: true,
                          srcs: ["foo_test.cpp"],
                          test_options: { unit_test: false, },
                         }
	`)

	// Ensure all variation of test-per-src tests are marked test-only.
	ctx.VisitAllModules(func(m blueprint.Module) {
		testOnly := false
		if provider, ok := android.OtherModuleProvider(ctx.TestContext.OtherModuleProviderAdaptor(), m, android.TestOnlyProviderKey); ok {
			if provider.TestOnly {
				testOnly = true
			}
		}
		if module, ok := m.(*Module); ok {
			if testModule, ok := module.installer.(*testBinary); ok {
				if !testOnly && *testModule.Properties.Test_per_src {
					t.Errorf("%v is not test-only but should be", m)
				}
			}
		}
	})
}

func TestTestOnlyInTeamsProto(t *testing.T) {
	t.Parallel()
	ctx := android.GroupFixturePreparers(