Support test fixtures in cc package
Restructures the cc package test setup code to create FixturePreparer instances for setting up a test fixture and converts some tests to use it. The goal with this change is not to switch all the cc tests over to directly using the new model but instead to ensure that the majority of the cc tests run with the new model, to allow existing tests to easily switch to the new model when needed and to allow dependent packages to be switched to the new model. Bug: 181070625 Test: m nothing Change-Id: I00415f10fb44c1b9e78e1317e7f50bb61984d3a4
This commit is contained in:
@@ -52,29 +52,50 @@ func TestMain(m *testing.M) {
|
||||
os.Exit(run())
|
||||
}
|
||||
|
||||
var ccFixtureFactory = android.NewFixtureFactory(
|
||||
&buildDir,
|
||||
PrepareForTestWithCcIncludeVndk,
|
||||
|
||||
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
||||
variables.DeviceVndkVersion = StringPtr("current")
|
||||
variables.ProductVndkVersion = StringPtr("current")
|
||||
variables.Platform_vndk_version = StringPtr("VER")
|
||||
}),
|
||||
)
|
||||
|
||||
// testCcWithConfig runs tests using the ccFixtureFactory
|
||||
//
|
||||
// See testCc for an explanation as to how to stop using this deprecated method.
|
||||
//
|
||||
// deprecated
|
||||
func testCcWithConfig(t *testing.T, config android.Config) *android.TestContext {
|
||||
t.Helper()
|
||||
ctx := CreateTestContext(config)
|
||||
ctx.Register()
|
||||
|
||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
||||
android.FailIfErrored(t, errs)
|
||||
_, errs = ctx.PrepareBuildActions(config)
|
||||
android.FailIfErrored(t, errs)
|
||||
|
||||
return ctx
|
||||
result := ccFixtureFactory.RunTestWithConfig(t, config)
|
||||
return result.TestContext
|
||||
}
|
||||
|
||||
// testCc runs tests using the ccFixtureFactory
|
||||
//
|
||||
// Do not add any new usages of this, instead use the ccFixtureFactory directly as it makes it much
|
||||
// easier to customize the test behavior.
|
||||
//
|
||||
// If it is necessary to customize the behavior of an existing test that uses this then please first
|
||||
// convert the test to using ccFixtureFactory first and then in a following change add the
|
||||
// appropriate fixture preparers. Keeping the conversion change separate makes it easy to verify
|
||||
// that it did not change the test behavior unexpectedly.
|
||||
//
|
||||
// deprecated
|
||||
func testCc(t *testing.T, bp string) *android.TestContext {
|
||||
t.Helper()
|
||||
config := TestConfig(buildDir, android.Android, nil, bp, nil)
|
||||
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
|
||||
config.TestProductVariables.ProductVndkVersion = StringPtr("current")
|
||||
config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
|
||||
|
||||
return testCcWithConfig(t, config)
|
||||
result := ccFixtureFactory.RunTestWithBp(t, bp)
|
||||
return result.TestContext
|
||||
}
|
||||
|
||||
// testCcNoVndk runs tests using the ccFixtureFactory
|
||||
//
|
||||
// See testCc for an explanation as to how to stop using this deprecated method.
|
||||
//
|
||||
// deprecated
|
||||
func testCcNoVndk(t *testing.T, bp string) *android.TestContext {
|
||||
t.Helper()
|
||||
config := TestConfig(buildDir, android.Android, nil, bp, nil)
|
||||
@@ -83,6 +104,11 @@ func testCcNoVndk(t *testing.T, bp string) *android.TestContext {
|
||||
return testCcWithConfig(t, config)
|
||||
}
|
||||
|
||||
// testCcNoProductVndk runs tests using the ccFixtureFactory
|
||||
//
|
||||
// See testCc for an explanation as to how to stop using this deprecated method.
|
||||
//
|
||||
// deprecated
|
||||
func testCcNoProductVndk(t *testing.T, bp string) *android.TestContext {
|
||||
t.Helper()
|
||||
config := TestConfig(buildDir, android.Android, nil, bp, nil)
|
||||
@@ -92,27 +118,24 @@ func testCcNoProductVndk(t *testing.T, bp string) *android.TestContext {
|
||||
return testCcWithConfig(t, config)
|
||||
}
|
||||
|
||||
// testCcErrorWithConfig runs tests using the ccFixtureFactory
|
||||
//
|
||||
// See testCc for an explanation as to how to stop using this deprecated method.
|
||||
//
|
||||
// deprecated
|
||||
func testCcErrorWithConfig(t *testing.T, pattern string, config android.Config) {
|
||||
t.Helper()
|
||||
|
||||
ctx := CreateTestContext(config)
|
||||
ctx.Register()
|
||||
|
||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
||||
if len(errs) > 0 {
|
||||
android.FailIfNoMatchingErrors(t, pattern, errs)
|
||||
return
|
||||
}
|
||||
|
||||
_, errs = ctx.PrepareBuildActions(config)
|
||||
if len(errs) > 0 {
|
||||
android.FailIfNoMatchingErrors(t, pattern, errs)
|
||||
return
|
||||
}
|
||||
|
||||
t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
|
||||
ccFixtureFactory.Extend().
|
||||
ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)).
|
||||
RunTestWithConfig(t, config)
|
||||
}
|
||||
|
||||
// testCcError runs tests using the ccFixtureFactory
|
||||
//
|
||||
// See testCc for an explanation as to how to stop using this deprecated method.
|
||||
//
|
||||
// deprecated
|
||||
func testCcError(t *testing.T, pattern string, bp string) {
|
||||
t.Helper()
|
||||
config := TestConfig(buildDir, android.Android, nil, bp, nil)
|
||||
@@ -122,6 +145,11 @@ func testCcError(t *testing.T, pattern string, bp string) {
|
||||
return
|
||||
}
|
||||
|
||||
// testCcErrorProductVndk runs tests using the ccFixtureFactory
|
||||
//
|
||||
// See testCc for an explanation as to how to stop using this deprecated method.
|
||||
//
|
||||
// deprecated
|
||||
func testCcErrorProductVndk(t *testing.T, pattern string, bp string) {
|
||||
t.Helper()
|
||||
config := TestConfig(buildDir, android.Android, nil, bp, nil)
|
||||
|
Reference in New Issue
Block a user