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

Commit 387f4ce1 authored by Paul Duffin's avatar Paul Duffin Committed by Gerrit Code Review
Browse files

Merge changes Iccba8caf,I1eb49f25,Id77575f8,I5679cb51,I7f9f3eb6, ...

* changes:
  Convert android/ninja_deps_test.go to test fixtures
  Add NinjaDeps to TestResult
  Convert android/singleton_module_test.go to test fixtures
  Convert android/neverallow_test.go to test fixtures
  Convert android/singleton_module_test.go to test fixtures
  Convert android/variable_test.go to test fixtures
  Convert android/soong_config_modules_test.go to test fixtures
  Convert android/mutator_test.go to test fixtures
  Convert android/deptag_test.go to test fixtures
parents 000ae662 d9ec7d26
Loading
Loading
Loading
Loading
+16 −17
Original line number Diff line number Diff line
@@ -80,21 +80,20 @@ func TestInstallDependencyTag(t *testing.T) {
		}
	`

	config := TestArchConfig(buildDir, nil, bp, nil)
	ctx := NewTestArchContext(config)

	result := emptyTestFixtureFactory.RunTest(t,
		PrepareForTestWithArchMutator,
		FixtureWithRootAndroidBp(bp),
		FixtureRegisterWithContext(func(ctx RegistrationContext) {
			ctx.RegisterModuleType("test_module", testInstallDependencyTagModuleFactory)
		}),
	)

	ctx.Register()
	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
	FailIfErrored(t, errs)
	_, errs = ctx.PrepareBuildActions(config)
	FailIfErrored(t, errs)
	config := result.Config

	hostFoo := ctx.ModuleForTests("foo", config.BuildOSCommonTarget.String()).Description("install")
	hostInstallDep := ctx.ModuleForTests("install_dep", config.BuildOSCommonTarget.String()).Description("install")
	hostTransitive := ctx.ModuleForTests("transitive", config.BuildOSCommonTarget.String()).Description("install")
	hostDep := ctx.ModuleForTests("dep", config.BuildOSCommonTarget.String()).Description("install")
	hostFoo := result.ModuleForTests("foo", config.BuildOSCommonTarget.String()).Description("install")
	hostInstallDep := result.ModuleForTests("install_dep", config.BuildOSCommonTarget.String()).Description("install")
	hostTransitive := result.ModuleForTests("transitive", config.BuildOSCommonTarget.String()).Description("install")
	hostDep := result.ModuleForTests("dep", config.BuildOSCommonTarget.String()).Description("install")

	if g, w := hostFoo.Implicits.Strings(), hostInstallDep.Output.String(); !InList(w, g) {
		t.Errorf("expected host dependency %q, got %q", w, g)
@@ -112,10 +111,10 @@ func TestInstallDependencyTag(t *testing.T) {
		t.Errorf("expected no host dependency %q, got %q", w, g)
	}

	deviceFoo := ctx.ModuleForTests("foo", "android_common").Description("install")
	deviceInstallDep := ctx.ModuleForTests("install_dep", "android_common").Description("install")
	deviceTransitive := ctx.ModuleForTests("transitive", "android_common").Description("install")
	deviceDep := ctx.ModuleForTests("dep", "android_common").Description("install")
	deviceFoo := result.ModuleForTests("foo", "android_common").Description("install")
	deviceInstallDep := result.ModuleForTests("install_dep", "android_common").Description("install")
	deviceTransitive := result.ModuleForTests("transitive", "android_common").Description("install")
	deviceDep := result.ModuleForTests("dep", "android_common").Description("install")

	if g, w := deviceFoo.OrderOnly.Strings(), deviceInstallDep.Output.String(); !InList(w, g) {
		t.Errorf("expected device dependency %q, got %q", w, g)
+12 −2
Original line number Diff line number Diff line
@@ -582,6 +582,10 @@ type TestResult struct {

	// The errors that were reported during the test.
	Errs []error

	// The ninja deps is a list of the ninja files dependencies that were added by the modules and
	// singletons via the *.AddNinjaFileDeps() methods.
	NinjaDeps []string
}

var _ FixtureFactory = (*fixtureFactory)(nil)
@@ -722,9 +726,14 @@ func (f *fixture) RunTest() *TestResult {
	}

	ctx.Register()
	_, errs := ctx.ParseBlueprintsFiles("ignored")
	var ninjaDeps []string
	extraNinjaDeps, errs := ctx.ParseBlueprintsFiles("ignored")
	if len(errs) == 0 {
		ninjaDeps = append(ninjaDeps, extraNinjaDeps...)
		extraNinjaDeps, errs = ctx.PrepareBuildActions(f.config)
		if len(errs) == 0 {
		_, errs = ctx.PrepareBuildActions(f.config)
			ninjaDeps = append(ninjaDeps, extraNinjaDeps...)
		}
	}

	result := &TestResult{
@@ -732,6 +741,7 @@ func (f *fixture) RunTest() *TestResult {
		fixture:     f,
		Config:      f.config,
		Errs:        errs,
		NinjaDeps:   ninjaDeps,
	}

	f.errorHandler.CheckErrors(f.t, result)
+101 −130
Original line number Diff line number Diff line
@@ -16,12 +16,10 @@ package android

import (
	"fmt"
	"reflect"
	"strings"
	"testing"

	"github.com/google/blueprint"
	"github.com/google/blueprint/proptools"
)

type mutatorTestModule struct {
@@ -67,28 +65,20 @@ func TestMutatorAddMissingDependencies(t *testing.T) {
		}
	`

	config := TestConfig(buildDir, nil, bp, nil)
	config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true)

	ctx := NewTestContext(config)
	ctx.SetAllowMissingDependencies(true)

	result := emptyTestFixtureFactory.RunTest(t,
		PrepareForTestWithAllowMissingDependencies,
		FixtureRegisterWithContext(func(ctx RegistrationContext) {
			ctx.RegisterModuleType("test", mutatorTestModuleFactory)
			ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
				ctx.TopDown("add_missing_dependencies", addMissingDependenciesMutator)
			})
		}),
		FixtureWithRootAndroidBp(bp),
	)

	ctx.Register()
	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
	FailIfErrored(t, errs)
	_, errs = ctx.PrepareBuildActions(config)
	FailIfErrored(t, errs)

	foo := ctx.ModuleForTests("foo", "").Module().(*mutatorTestModule)
	foo := result.ModuleForTests("foo", "").Module().(*mutatorTestModule)

	if g, w := foo.missingDeps, []string{"added_missing_dep", "regular_missing_dep"}; !reflect.DeepEqual(g, w) {
		t.Errorf("want foo missing deps %q, got %q", w, g)
	}
	AssertDeepEquals(t, "foo missing deps", []string{"added_missing_dep", "regular_missing_dep"}, foo.missingDeps)
}

func TestModuleString(t *testing.T) {
@@ -98,12 +88,11 @@ func TestModuleString(t *testing.T) {
		}
	`

	config := TestConfig(buildDir, nil, bp, nil)

	ctx := NewTestContext(config)

	var moduleStrings []string

	emptyTestFixtureFactory.RunTest(t,
		FixtureRegisterWithContext(func(ctx RegistrationContext) {

			ctx.PreArchMutators(func(ctx RegisterMutatorsContext) {
				ctx.BottomUp("pre_arch", func(ctx BottomUpMutatorContext) {
					moduleStrings = append(moduleStrings, ctx.Module().String())
@@ -137,13 +126,9 @@ func TestModuleString(t *testing.T) {
			})

			ctx.RegisterModuleType("test", mutatorTestModuleFactory)

	ctx.Register()

	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
	FailIfErrored(t, errs)
	_, errs = ctx.PrepareBuildActions(config)
	FailIfErrored(t, errs)
		}),
		FixtureWithRootAndroidBp(bp),
	)

	want := []string{
		// Initial name.
@@ -184,9 +169,7 @@ func TestModuleString(t *testing.T) {
		"foo_renamed2{pre_arch:b,pre_deps:d,post_deps:f}",
	}

	if !reflect.DeepEqual(moduleStrings, want) {
		t.Errorf("want module String() values:\n%q\ngot:\n%q", want, moduleStrings)
	}
	AssertDeepEquals(t, "module String() values", want, moduleStrings)
}

func TestFinalDepsPhase(t *testing.T) {
@@ -202,12 +185,10 @@ func TestFinalDepsPhase(t *testing.T) {
		}
	`

	config := TestConfig(buildDir, nil, bp, nil)

	ctx := NewTestContext(config)

	finalGot := map[string]int{}

	emptyTestFixtureFactory.RunTest(t,
		FixtureRegisterWithContext(func(ctx RegistrationContext) {
			dep1Tag := struct {
				blueprint.BaseDependencyTag
			}{}
@@ -241,13 +222,9 @@ func TestFinalDepsPhase(t *testing.T) {
			})

			ctx.RegisterModuleType("test", mutatorTestModuleFactory)

	ctx.Register()

	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
	FailIfErrored(t, errs)
	_, errs = ctx.PrepareBuildActions(config)
	FailIfErrored(t, errs)
		}),
		FixtureWithRootAndroidBp(bp),
	)

	finalWant := map[string]int{
		"common_dep_1{variant:a}":                   1,
@@ -262,21 +239,18 @@ func TestFinalDepsPhase(t *testing.T) {
		"foo{variant:b} -> common_dep_2{variant:a}": 1,
	}

	if !reflect.DeepEqual(finalWant, finalGot) {
		t.Errorf("want:\n%q\ngot:\n%q", finalWant, finalGot)
	}
	AssertDeepEquals(t, "final", finalWant, finalGot)
}

func TestNoCreateVariationsInFinalDeps(t *testing.T) {
	config := TestConfig(buildDir, nil, `test {name: "foo"}`, nil)
	ctx := NewTestContext(config)

	checkErr := func() {
		if err := recover(); err == nil || !strings.Contains(fmt.Sprintf("%s", err), "not allowed in FinalDepsMutators") {
			panic("Expected FinalDepsMutators consistency check to fail")
		}
	}

	emptyTestFixtureFactory.RunTest(t,
		FixtureRegisterWithContext(func(ctx RegistrationContext) {
			ctx.FinalDepsMutators(func(ctx RegisterMutatorsContext) {
				ctx.BottomUp("vars", func(ctx BottomUpMutatorContext) {
					defer checkErr()
@@ -289,10 +263,7 @@ func TestNoCreateVariationsInFinalDeps(t *testing.T) {
			})

			ctx.RegisterModuleType("test", mutatorTestModuleFactory)
	ctx.Register()

	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
	FailIfErrored(t, errs)
	_, errs = ctx.PrepareBuildActions(config)
	FailIfErrored(t, errs)
		}),
		FixtureWithRootAndroidBp(`test {name: "foo"}`),
	)
}
+24 −29
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ var neverallowTests = []struct {
	rules []Rule

	// Additional contents to add to the virtual filesystem used by the tests.
	fs map[string][]byte
	fs MockFS

	// The expected error patterns. If empty then no errors are expected, otherwise each error
	// reported must be matched by at least one of these patterns. A pattern matches if the error
@@ -285,41 +285,36 @@ var neverallowTests = []struct {
	},
}

var prepareForNeverAllowTest = GroupFixturePreparers(
	FixtureRegisterWithContext(func(ctx RegistrationContext) {
		ctx.RegisterModuleType("cc_library", newMockCcLibraryModule)
		ctx.RegisterModuleType("java_library", newMockJavaLibraryModule)
		ctx.RegisterModuleType("java_library_host", newMockJavaLibraryModule)
		ctx.RegisterModuleType("java_device_for_host", newMockJavaLibraryModule)
		ctx.RegisterModuleType("makefile_goal", newMockMakefileGoalModule)
		ctx.PostDepsMutators(RegisterNeverallowMutator)
	}),
)

func TestNeverallow(t *testing.T) {
	for _, test := range neverallowTests {
		// Create a test per config to allow for test specific config, e.g. test rules.
		config := TestConfig(buildDir, nil, "", test.fs)

		t.Run(test.name, func(t *testing.T) {
			emptyTestFixtureFactory.
				ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)).
				RunTest(t,
					prepareForNeverAllowTest,
					FixtureModifyConfig(func(config Config) {
						// If the test has its own rules then use them instead of the default ones.
						if test.rules != nil {
							SetTestNeverallowRules(config, test.rules)
						}
			_, errs := testNeverallow(config)
			CheckErrorsAgainstExpectations(t, errs, test.expectedErrors)
					}),
					test.fs.AddToFixture(),
				)
		})
	}
}

func testNeverallow(config Config) (*TestContext, []error) {
	ctx := NewTestContext(config)
	ctx.RegisterModuleType("cc_library", newMockCcLibraryModule)
	ctx.RegisterModuleType("java_library", newMockJavaLibraryModule)
	ctx.RegisterModuleType("java_library_host", newMockJavaLibraryModule)
	ctx.RegisterModuleType("java_device_for_host", newMockJavaLibraryModule)
	ctx.RegisterModuleType("makefile_goal", newMockMakefileGoalModule)
	ctx.PostDepsMutators(RegisterNeverallowMutator)
	ctx.Register()

	_, errs := ctx.ParseBlueprintsFiles("Android.bp")
	if len(errs) > 0 {
		return ctx, errs
	}

	_, errs = ctx.PrepareBuildActions(config)
	return ctx, errs
}

type mockCcLibraryProperties struct {
	Include_dirs     []string
	Vendor_available *bool
+9 −12
Original line number Diff line number Diff line
@@ -53,23 +53,20 @@ func (testNinjaDepsSingleton) GenerateBuildActions(ctx SingletonContext) {
}

func TestNinjaDeps(t *testing.T) {
	fs := map[string][]byte{
	fs := MockFS{
		"test_ninja_deps/exists": nil,
	}
	config := TestConfig(buildDir, nil, "", fs)

	ctx := NewTestContext(config)
	result := emptyTestFixtureFactory.RunTest(t,
		FixtureRegisterWithContext(func(ctx RegistrationContext) {
			ctx.RegisterSingletonType("test_ninja_deps_singleton", testNinjaDepsSingletonFactory)
			ctx.RegisterSingletonType("ninja_deps_singleton", ninjaDepsSingletonFactory)
	ctx.Register()

	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
	FailIfErrored(t, errs)
	ninjaDeps, errs := ctx.PrepareBuildActions(config)
	FailIfErrored(t, errs)
		}),
		fs.AddToFixture(),
	)

	// Verify that the ninja file has a dependency on the test_ninja_deps directory.
	if g, w := ninjaDeps, "test_ninja_deps"; !InList(w, g) {
	if g, w := result.NinjaDeps, "test_ninja_deps"; !InList(w, g) {
		t.Errorf("expected %q in %q", w, g)
	}
}
Loading