Merge changes I6b408d44,I7e57c978
* changes: Add preparer for test to use AndroidMk Convert cc/cc_test.go tests that use CreateTestContext to fixtures
This commit is contained in:
commit
d7bbeffe0e
|
@ -44,6 +44,14 @@ func RegisterAndroidMkBuildComponents(ctx RegistrationContext) {
|
||||||
ctx.RegisterSingletonType("androidmk", AndroidMkSingleton)
|
ctx.RegisterSingletonType("androidmk", AndroidMkSingleton)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enable androidmk support.
|
||||||
|
// * Register the singleton
|
||||||
|
// * Configure that we are inside make
|
||||||
|
var PrepareForTestWithAndroidMk = GroupFixturePreparers(
|
||||||
|
FixtureRegisterWithContext(RegisterAndroidMkBuildComponents),
|
||||||
|
FixtureModifyConfig(SetKatiEnabledForTests),
|
||||||
|
)
|
||||||
|
|
||||||
// Deprecated: Use AndroidMkEntriesProvider instead, especially if you're not going to use the
|
// Deprecated: Use AndroidMkEntriesProvider instead, especially if you're not going to use the
|
||||||
// Custom function. It's easier to use and test.
|
// Custom function. It's easier to use and test.
|
||||||
type AndroidMkDataProvider interface {
|
type AndroidMkDataProvider interface {
|
||||||
|
|
144
cc/cc_test.go
144
cc/cc_test.go
|
@ -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,8 +3647,9 @@ func checkHasMemtagNote(t *testing.T, m android.TestingModule, expected MemtagNo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeMemtagTestConfig(t *testing.T) android.Config {
|
var prepareForTestWithMemtagHeap = android.GroupFixturePreparers(
|
||||||
templateBp := `
|
android.FixtureModifyMockFS(func(fs android.MockFS) {
|
||||||
|
templateBp := `
|
||||||
cc_test {
|
cc_test {
|
||||||
name: "%[1]s_test",
|
name: "%[1]s_test",
|
||||||
gtest: false,
|
gtest: false,
|
||||||
|
@ -3726,35 +3703,30 @@ func makeMemtagTestConfig(t *testing.T) android.Config {
|
||||||
sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
|
sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
subdirDefaultBp := fmt.Sprintf(templateBp, "default")
|
subdirDefaultBp := fmt.Sprintf(templateBp, "default")
|
||||||
subdirExcludeBp := fmt.Sprintf(templateBp, "exclude")
|
subdirExcludeBp := fmt.Sprintf(templateBp, "exclude")
|
||||||
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)
|
||||||
|
|
Loading…
Reference in New Issue