Distinguish between integration test and other tests
This change tries to distinguish between the preparations needed for an
integration test and the preparations needed for more unit-testy tests.
Integration tests exercise most, if not all of Soong (at least the
parts that are available when running tests in a specific package) and
as a result can take a long time. Other tests, while being as realistic
as possible, should only use a subset of the preparations in order to
reduce run time.
Registering module types has very little overhead so it is simplest to
try and register those all together. However, care needs to be taken
for singletons and mutators as they can do a lot of work. Especially
with tests that include lots of default module definitions such as are
created by java.GatherRequiredDepsForTest().
Once it is possible to use test fixtures in tests it will be much
easier to customize tests individually and so avoid just adding new
test specific content to the common deps.
Bug: 181070625
Test: m nothing
Change-Id: Ia0a676297224d90df947054746e7f99563ffb323
diff --git a/android/testing.go b/android/testing.go
index 2992678..0210f23 100644
--- a/android/testing.go
+++ b/android/testing.go
@@ -73,8 +73,19 @@
ctx.PostDepsMutators(RegisterOverridePostDepsMutators)
})
-// Prepares an integration test with build components from the android package.
-var PrepareForIntegrationTestWithAndroid = GroupFixturePreparers(
+// Test fixture preparer that will register most java build components.
+//
+// Singletons and mutators should only be added here if they are needed for a majority of java
+// module types, otherwise they should be added under a separate preparer to allow them to be
+// selected only when needed to reduce test execution time.
+//
+// Module types do not have much of an overhead unless they are used so this should include as many
+// module types as possible. The exceptions are those module types that require mutators and/or
+// singletons in order to function in which case they should be kept together in a separate
+// preparer.
+//
+// The mutators in this group were chosen because they are needed by the vast majority of tests.
+var PrepareForTestWithAndroidBuildComponents = GroupFixturePreparers(
// Sorted alphabetically as the actual order does not matter as tests automatically enforce the
// correct order.
PrepareForTestWithArchMutator,
@@ -87,6 +98,13 @@
PrepareForTestWithVisibility,
)
+// Prepares an integration test with all build components from the android package.
+//
+// This should only be used by tests that want to run with as much of the build enabled as possible.
+var PrepareForIntegrationTestWithAndroid = GroupFixturePreparers(
+ PrepareForTestWithAndroidBuildComponents,
+)
+
func NewTestArchContext(config Config) *TestContext {
ctx := NewTestContext(config)
ctx.preDeps = append(ctx.preDeps, registerArchMutator)