Convert cc/cc_test.go tests that use CreateTestContext to fixtures

Bug: 181070625
Test: m nothing
Change-Id: I7e57c978fa07ee8c0f35d567753751bd7b128b1e
This commit is contained in:
Paul Duffin 2021-03-07 15:58:39 +00:00
parent 25259e93e1
commit 7d8a8ad0d1
1 changed files with 53 additions and 91 deletions

View File

@ -55,7 +55,6 @@ func TestMain(m *testing.M) {
var ccFixtureFactory = android.NewFixtureFactory( var ccFixtureFactory = android.NewFixtureFactory(
&buildDir, &buildDir,
PrepareForTestWithCcIncludeVndk, PrepareForTestWithCcIncludeVndk,
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
variables.DeviceVndkVersion = StringPtr("current") variables.DeviceVndkVersion = StringPtr("current")
variables.ProductVndkVersion = StringPtr("current") variables.ProductVndkVersion = StringPtr("current")
@ -3421,24 +3420,16 @@ func TestProductVariableDefaults(t *testing.T) {
} }
` `
config := TestConfig(buildDir, android.Android, nil, bp, nil) result := ccFixtureFactory.Extend(
config.TestProductVariables.Debuggable = BoolPtr(true) android.PrepareForTestWithVariables,
ctx := CreateTestContext(config) android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { variables.Debuggable = BoolPtr(true)
ctx.BottomUp("variable", android.VariableMutator).Parallel() }),
}) ).RunTestWithBp(t, bp)
ctx.Register()
_, errs := ctx.ParseFileList(".", []string{"Android.bp"}) libfoo := result.Module("libfoo", "android_arm64_armv8-a_static").(*Module)
android.FailIfErrored(t, errs) result.AssertStringListContains("cppflags", libfoo.flags.Local.CppFlags, "-DBAR")
_, errs = ctx.PrepareBuildActions(config)
android.FailIfErrored(t, errs)
libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*Module)
if !android.InList("-DBAR", libfoo.flags.Local.CppFlags) {
t.Errorf("expected -DBAR in cppflags, got %q", libfoo.flags.Local.CppFlags)
}
} }
func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) { func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) {
@ -3456,32 +3447,17 @@ func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) {
} }
` `
config := TestConfig(buildDir, android.Android, nil, bp, nil) result := ccFixtureFactory.Extend(
config.TestProductVariables.Allow_missing_dependencies = BoolPtr(true) android.PrepareForTestWithAllowMissingDependencies,
).RunTestWithBp(t, bp)
ctx := CreateTestContext(config) libbar := result.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a")
ctx.SetAllowMissingDependencies(true) result.AssertDeepEquals("libbar rule", android.ErrorRule, libbar.Rule)
ctx.Register()
_, errs := ctx.ParseFileList(".", []string{"Android.bp"}) result.AssertStringDoesContain("libbar error", libbar.Args["error"], "missing dependencies: libmissing")
android.FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
android.FailIfErrored(t, errs)
libbar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a")
if g, w := libbar.Rule, android.ErrorRule; g != w {
t.Fatalf("Expected libbar rule to be %q, got %q", w, g)
}
if g, w := libbar.Args["error"], "missing dependencies: libmissing"; !strings.Contains(g, w) {
t.Errorf("Expected libbar error to contain %q, was %q", w, g)
}
libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a")
if g, w := libfoo.Inputs.Strings(), libbar.Output.String(); !android.InList(w, g) {
t.Errorf("Expected libfoo.a to depend on %q, got %q", w, g)
}
libfoo := result.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a")
result.AssertStringListContains("libfoo.a dependencies", libfoo.Inputs.Strings(), libbar.Output.String())
} }
func TestInstallSharedLibs(t *testing.T) { func TestInstallSharedLibs(t *testing.T) {
@ -3671,7 +3647,8 @@ func checkHasMemtagNote(t *testing.T, m android.TestingModule, expected MemtagNo
} }
} }
func makeMemtagTestConfig(t *testing.T) android.Config { var prepareForTestWithMemtagHeap = android.GroupFixturePreparers(
android.FixtureModifyMockFS(func(fs android.MockFS) {
templateBp := ` templateBp := `
cc_test { cc_test {
name: "%[1]s_test", name: "%[1]s_test",
@ -3731,30 +3708,25 @@ func makeMemtagTestConfig(t *testing.T) android.Config {
subdirSyncBp := fmt.Sprintf(templateBp, "sync") subdirSyncBp := fmt.Sprintf(templateBp, "sync")
subdirAsyncBp := fmt.Sprintf(templateBp, "async") subdirAsyncBp := fmt.Sprintf(templateBp, "async")
mockFS := map[string][]byte{ fs.Merge(android.MockFS{
"subdir_default/Android.bp": []byte(subdirDefaultBp), "subdir_default/Android.bp": []byte(subdirDefaultBp),
"subdir_exclude/Android.bp": []byte(subdirExcludeBp), "subdir_exclude/Android.bp": []byte(subdirExcludeBp),
"subdir_sync/Android.bp": []byte(subdirSyncBp), "subdir_sync/Android.bp": []byte(subdirSyncBp),
"subdir_async/Android.bp": []byte(subdirAsyncBp), "subdir_async/Android.bp": []byte(subdirAsyncBp),
} })
}),
return TestConfig(buildDir, android.Android, nil, "", mockFS) android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
} variables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
variables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
variables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
}),
)
func TestSanitizeMemtagHeap(t *testing.T) { func TestSanitizeMemtagHeap(t *testing.T) {
variant := "android_arm64_armv8-a" variant := "android_arm64_armv8-a"
config := makeMemtagTestConfig(t) result := ccFixtureFactory.Extend(prepareForTestWithMemtagHeap).RunTest(t)
config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"} ctx := result.TestContext
config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
ctx := CreateTestContext(config)
ctx.Register()
_, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
android.FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
android.FailIfErrored(t, errs)
checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync) checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None) checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
@ -3808,18 +3780,13 @@ func TestSanitizeMemtagHeap(t *testing.T) {
func TestSanitizeMemtagHeapWithSanitizeDevice(t *testing.T) { func TestSanitizeMemtagHeapWithSanitizeDevice(t *testing.T) {
variant := "android_arm64_armv8-a" variant := "android_arm64_armv8-a"
config := makeMemtagTestConfig(t) result := ccFixtureFactory.Extend(
config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"} prepareForTestWithMemtagHeap,
config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"} android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"} variables.SanitizeDevice = []string{"memtag_heap"}
config.TestProductVariables.SanitizeDevice = []string{"memtag_heap"} }),
ctx := CreateTestContext(config) ).RunTest(t)
ctx.Register() ctx := result.TestContext
_, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
android.FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
android.FailIfErrored(t, errs)
checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync) checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None) checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
@ -3873,19 +3840,14 @@ func TestSanitizeMemtagHeapWithSanitizeDevice(t *testing.T) {
func TestSanitizeMemtagHeapWithSanitizeDeviceDiag(t *testing.T) { func TestSanitizeMemtagHeapWithSanitizeDeviceDiag(t *testing.T) {
variant := "android_arm64_armv8-a" variant := "android_arm64_armv8-a"
config := makeMemtagTestConfig(t) result := ccFixtureFactory.Extend(
config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"} prepareForTestWithMemtagHeap,
config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"} android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"} variables.SanitizeDevice = []string{"memtag_heap"}
config.TestProductVariables.SanitizeDevice = []string{"memtag_heap"} variables.SanitizeDeviceDiag = []string{"memtag_heap"}
config.TestProductVariables.SanitizeDeviceDiag = []string{"memtag_heap"} }),
ctx := CreateTestContext(config) ).RunTest(t)
ctx.Register() ctx := result.TestContext
_, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
android.FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
android.FailIfErrored(t, errs)
checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync) checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None) checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)