Improve cc tests by adding sanitizer mutators

This fixes an issue that arises when deduping cc build component
registration code.

The sanitize_runtime_deps and sanitize_runtime post deps mutators were
not previously added when running cc tests. That meant the tests were
not actually testing the same behavior as at runtime.

Adding the mutators breaks the TestFuzzTarget test as the mutator adds
libclang_rt.ubsan_standalone-aarch64-android as a dependency of libc++
and the former is not available.

This fixes the test by adding the missing dependency as a cc prebuilt
shared library.

Test: m checkbuild
Bug: 146540677
Change-Id: Ie13c7e6fcefef7d9cb1cc5364be3dc563ce40de5
diff --git a/apex/apex_test.go b/apex/apex_test.go
index de5fdf7..41a59a7 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -288,7 +288,6 @@
 
 	ctx.RegisterModuleType("cc_library_shared", cc.LibrarySharedFactory)
 	ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
-	cc.RegisterPrebuiltBuildComponents(ctx)
 	cc.RegisterRequiredBuildComponentsForTest(ctx)
 	ctx.RegisterModuleType("cc_binary", cc.BinaryFactory)
 	ctx.RegisterModuleType("cc_defaults", func() android.Module {
@@ -305,7 +304,6 @@
 	java.RegisterAppBuildComponents(ctx)
 
 	ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
-	android.RegisterPrebuiltMutators(ctx)
 	ctx.PreDepsMutators(RegisterPreDepsMutators)
 	ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators)
 	ctx.PostDepsMutators(RegisterPostDepsMutators)
diff --git a/cc/prebuilt_test.go b/cc/prebuilt_test.go
index 2441696..3d809fc 100644
--- a/cc/prebuilt_test.go
+++ b/cc/prebuilt_test.go
@@ -72,10 +72,6 @@
 
 	ctx := CreateTestContext()
 
-	RegisterPrebuiltBuildComponents(ctx)
-
-	android.RegisterPrebuiltMutators(ctx)
-
 	ctx.Register(config)
 
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
diff --git a/cc/testing.go b/cc/testing.go
index 905d037..245325b 100644
--- a/cc/testing.go
+++ b/cc/testing.go
@@ -19,11 +19,13 @@
 )
 
 func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
+	RegisterPrebuiltBuildComponents(ctx)
 	ctx.RegisterModuleType("toolchain_library", ToolchainLibraryFactory)
 	ctx.RegisterModuleType("cc_library", LibraryFactory)
 	ctx.RegisterModuleType("llndk_library", LlndkLibraryFactory)
 	ctx.RegisterModuleType("cc_object", ObjectFactory)
 
+	android.RegisterPrebuiltMutators(ctx)
 	ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
 		ctx.BottomUp("vndk", VndkMutator).Parallel()
 		ctx.BottomUp("link", LinkageMutator).Parallel()
@@ -33,6 +35,10 @@
 		ctx.BottomUp("begin", BeginMutator).Parallel()
 		ctx.BottomUp("sysprop_cc", SyspropMutator).Parallel()
 	})
+	ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
+		ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
+		ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
+	})
 }
 
 func GatherRequiredDepsForTest(os android.OsType) string {
@@ -114,6 +120,14 @@
 			src: "",
 		}
 
+		// Needed for sanitizer
+		cc_prebuilt_library_shared {
+			name: "libclang_rt.ubsan_standalone-aarch64-android",
+			vendor_available: true,
+			recovery_available: true,
+			srcs: [""],
+		}
+
 		toolchain_library {
 			name: "libgcc",
 			vendor_available: true,
diff --git a/java/java_test.go b/java/java_test.go
index f93d69c..096cdb9 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -74,7 +74,6 @@
 	RegisterDocsBuildComponents(ctx)
 	RegisterStubsBuildComponents(ctx)
 	RegisterSdkLibraryBuildComponents(ctx)
-	android.RegisterPrebuiltMutators(ctx)
 	ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
 
 	RegisterPrebuiltApisBuildComponents(ctx)
diff --git a/sdk/testing.go b/sdk/testing.go
index e3b8519..eec7f01 100644
--- a/sdk/testing.go
+++ b/sdk/testing.go
@@ -68,7 +68,6 @@
 	ctx.PreArchMutators(android.RegisterVisibilityRuleGatherer)
 	ctx.PostDepsMutators(android.RegisterVisibilityRuleEnforcer)
 
-	android.RegisterPrebuiltMutators(ctx)
 	ctx.RegisterModuleType("package", android.PackageFactory)
 
 	// from java package
@@ -80,7 +79,6 @@
 	cc.RegisterRequiredBuildComponentsForTest(ctx)
 	ctx.RegisterModuleType("cc_library_shared", cc.LibrarySharedFactory)
 	ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory)
-	cc.RegisterPrebuiltBuildComponents(ctx)
 
 	// from apex package
 	ctx.RegisterModuleType("apex", apex.BundleFactory)
diff --git a/sysprop/sysprop_test.go b/sysprop/sysprop_test.go
index bdb9915..0c0f222 100644
--- a/sysprop/sysprop_test.go
+++ b/sysprop/sysprop_test.go
@@ -60,7 +60,6 @@
 	java.RegisterAppBuildComponents(ctx)
 	java.RegisterSystemModulesBuildComponents(ctx)
 
-	android.RegisterPrebuiltMutators(ctx)
 	ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
 	ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
 		ctx.BottomUp("sysprop_deps", syspropDepsMutator).Parallel()