Merge "Don't return null for an interface type."
diff --git a/androidmk/cmd/androidmk/android.go b/androidmk/cmd/androidmk/android.go
index a5dfcd9..4af5d97 100644
--- a/androidmk/cmd/androidmk/android.go
+++ b/androidmk/cmd/androidmk/android.go
@@ -72,6 +72,7 @@
 	"LOCAL_JAR_EXCLUDE_FILES":       skip, // Soong never excludes files from jars
 
 	"LOCAL_ANNOTATION_PROCESSOR_CLASSES": skip, // Soong gets the processor classes from the plugin
+	"LOCAL_CTS_TEST_PACKAGE":             skip, // Obsolete
 }
 
 // adds a group of properties all having the same type
diff --git a/androidmk/cmd/androidmk/androidmk_test.go b/androidmk/cmd/androidmk/androidmk_test.go
index 618dd42..9af2bea 100644
--- a/androidmk/cmd/androidmk/androidmk_test.go
+++ b/androidmk/cmd/androidmk/androidmk_test.go
@@ -758,6 +758,7 @@
 include $(CLEAR_VARS)
 LOCAL_PACKAGE_NAME := FooTest
 LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 include $(BUILD_CTS_SUPPORT_PACKAGE)
 `,
 		expected: `
@@ -765,6 +766,7 @@
     name: "FooTest",
     defaults: ["cts_support_defaults"],
     test_suites: ["cts"],
+
 }
 `,
 	},
@@ -774,6 +776,7 @@
 include $(CLEAR_VARS)
 LOCAL_PACKAGE_NAME := FooTest
 LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_CTS_TEST_PACKAGE := foo.bar
 include $(BUILD_CTS_PACKAGE)
 `,
 		expected: `
@@ -781,6 +784,7 @@
     name: "FooTest",
     defaults: ["cts_defaults"],
     test_suites: ["cts"],
+
 }
 `,
 	},
diff --git a/bpfix/bpfix/bpfix.go b/bpfix/bpfix/bpfix.go
index 11f1877..ba6435e 100644
--- a/bpfix/bpfix/bpfix.go
+++ b/bpfix/bpfix/bpfix.go
@@ -98,6 +98,10 @@
 		name: "removeTags",
 		fix:  runPatchListMod(removeTags),
 	},
+	{
+		name: "rewriteAndroidTest",
+		fix:  rewriteAndroidTest,
+	},
 }
 
 func NewFixRequest() FixRequest {
@@ -561,6 +565,30 @@
 	return nil
 }
 
+func rewriteAndroidTest(f *Fixer) error {
+	for _, def := range f.tree.Defs {
+		mod, ok := def.(*parser.Module)
+		if !(ok && mod.Type == "android_test") {
+			continue
+		}
+		// The rewriter converts LOCAL_MODULE_PATH attribute into a struct attribute
+		// 'local_module_path'. For the android_test module, it should be  $(TARGET_OUT_DATA_APPS),
+		// that is, `local_module_path: { var: "TARGET_OUT_DATA_APPS"}`
+		const local_module_path = "local_module_path"
+		if prop_local_module_path, ok := mod.GetProperty(local_module_path); ok {
+			removeProperty(mod, local_module_path)
+			prefixVariableName := getStringProperty(prop_local_module_path, "var")
+			path := getStringProperty(prop_local_module_path, "fixed")
+			if prefixVariableName == "TARGET_OUT_DATA_APPS" && path == "" {
+				continue
+			}
+			return indicateAttributeError(mod, "filename",
+				"Only LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS) is allowed for the android_test")
+		}
+	}
+	return nil
+}
+
 func runPatchListMod(modFunc func(mod *parser.Module, buf []byte, patchlist *parser.PatchList) error) func(*Fixer) error {
 	return func(f *Fixer) error {
 		// Make sure all the offsets are accurate
diff --git a/bpfix/bpfix/bpfix_test.go b/bpfix/bpfix/bpfix_test.go
index 1394223..459cd36 100644
--- a/bpfix/bpfix/bpfix_test.go
+++ b/bpfix/bpfix/bpfix_test.go
@@ -751,3 +751,36 @@
 		})
 	}
 }
+
+func TestRewriteAndroidTest(t *testing.T) {
+	tests := []struct {
+		name string
+		in   string
+		out  string
+	}{
+		{
+			name: "android_test valid module path",
+			in: `
+				android_test {
+					name: "foo",
+					local_module_path: {
+						var: "TARGET_OUT_DATA_APPS",
+					},
+				}
+			`,
+			out: `
+				android_test {
+					name: "foo",
+
+				}
+			`,
+		},
+	}
+	for _, test := range tests {
+		t.Run(test.name, func(t *testing.T) {
+			runPass(t, test.in, test.out, func(fixer *Fixer) error {
+				return rewriteAndroidTest(fixer)
+			})
+		})
+	}
+}