Add a test for invokeinterface and default methods.

In S we used to have a bug overriding the imt index of an abstract
method. This got accidentally fixed in T, so add a regression test.

Test: 843-default-interface
Bug: 249522283
Change-Id: Ife65400a8ede0351bdcac67e6c6be44affdbe152
diff --git a/test/843-default-interface/expected-stderr.txt b/test/843-default-interface/expected-stderr.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/843-default-interface/expected-stderr.txt
diff --git a/test/843-default-interface/expected-stdout.txt b/test/843-default-interface/expected-stdout.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/843-default-interface/expected-stdout.txt
diff --git a/test/843-default-interface/info.txt b/test/843-default-interface/info.txt
new file mode 100644
index 0000000..3586e7f
--- /dev/null
+++ b/test/843-default-interface/info.txt
@@ -0,0 +1,2 @@
+Regression test for ArtMethod::CopyFrom, which used to wrongly override the
+imt_index_ of abstract methods with 0.
diff --git a/test/843-default-interface/src/Impl.java b/test/843-default-interface/src/Impl.java
new file mode 100644
index 0000000..8c9d76c
--- /dev/null
+++ b/test/843-default-interface/src/Impl.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class Impl implements SubItf {
+  public String foo() {
+    return "Impl";
+  }
+}
diff --git a/test/843-default-interface/src/Itf.java b/test/843-default-interface/src/Itf.java
new file mode 100644
index 0000000..0625429
--- /dev/null
+++ b/test/843-default-interface/src/Itf.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public interface Itf {
+  public default String bar() {
+    return "Itf";
+  }
+}
diff --git a/test/843-default-interface/src/Main.java b/test/843-default-interface/src/Main.java
new file mode 100644
index 0000000..8b2b2da
--- /dev/null
+++ b/test/843-default-interface/src/Main.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class Main {
+  static SubItf itf = new Impl();
+  public static void main(String[] args) throws Exception {
+    // Loop enough to trigger the native OOME.
+    for (int i = 0; i < 50000; ++i) {
+      // Because the imt index was overwritten to 0, this call ended up
+      // in the conflict trampoline which wrongly updated the 0th entry
+      // of the imt table. This lead to this call always calling the
+      // conflict trampoline.
+      itf.foo();
+    }
+  }
+}
diff --git a/test/843-default-interface/src/OtherItf.java b/test/843-default-interface/src/OtherItf.java
new file mode 100644
index 0000000..368631c
--- /dev/null
+++ b/test/843-default-interface/src/OtherItf.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public interface OtherItf {
+  // javac will complain when compiling SubItf if both superinterfaces Itf and OtherItf
+  // define a default method bar(), so we do not define bar() here.
+  // What will be loaded at runtime will actually be src2/OtherItf.
+  // public default String bar() {
+  //   return "OtherItf";
+  // }
+}
diff --git a/test/843-default-interface/src/SubItf.java b/test/843-default-interface/src/SubItf.java
new file mode 100644
index 0000000..6983b18
--- /dev/null
+++ b/test/843-default-interface/src/SubItf.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// The method bar will be a default conflict for this class. That used to make
+// the class linker re-allocate its ArtMethod array, and calling CopyFrom.
+// The bug was that CopyFrom was overwriting the imt index of interface methods,
+// and for this example `foo`.
+public interface SubItf extends Itf, OtherItf {
+  public String foo();
+}
diff --git a/test/843-default-interface/src2/OtherItf.java b/test/843-default-interface/src2/OtherItf.java
new file mode 100644
index 0000000..08028f4
--- /dev/null
+++ b/test/843-default-interface/src2/OtherItf.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public interface OtherItf {
+  public default String bar() {
+    return "OtherItf";
+  }
+}