Add debug test using constant local

- This test checks that constant sharing optimization does not
impact debug behavior.
- One test is ignored because D8 replace goto targeting a return
instruction by the return instruction but it breaks the debug
behavior.

Bug: 65402086
Change-Id: I5c97c7c6f9820042e22f1e3f6e07cad562a3681b
diff --git a/src/test/debugTestResources/Locals.java b/src/test/debugTestResources/Locals.java
index 5afcabb..1221234 100644
--- a/src/test/debugTestResources/Locals.java
+++ b/src/test/debugTestResources/Locals.java
@@ -318,6 +318,26 @@
     nop();
   }
 
+  public static int localConstant(boolean b) {
+    if (b) {
+      int result1 = 1;
+      return result1;
+    } else {
+      int result2 = 2;
+      return result2;
+    }
+  }
+
+  public static int localConstantBis(boolean b) {
+    int result = 0;
+    if (b) {
+      result = 1;
+    } else {
+      result = 2;
+    }
+    return result;
+  }
+
   public static void main(String[] args) {
     noLocals();
     unusedLocals();
@@ -338,5 +358,7 @@
     switchRewriteToSwitches(1);
     regression65039701(true);
     regression65066975(false);
+    System.out.println(localConstant(true));
+    System.out.println(localConstantBis(true));
   }
 }
diff --git a/src/test/java/com/android/tools/r8/debug/LocalsTest.java b/src/test/java/com/android/tools/r8/debug/LocalsTest.java
index 12fd23d..35aeab2 100644
--- a/src/test/java/com/android/tools/r8/debug/LocalsTest.java
+++ b/src/test/java/com/android/tools/r8/debug/LocalsTest.java
@@ -9,6 +9,7 @@
 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants.Tag;
 import org.apache.harmony.jpda.tests.framework.jdwp.Value;
 import org.junit.Assert;
+import org.junit.Ignore;
 import org.junit.Test;
 
 /**
@@ -19,6 +20,50 @@
   public static final String SOURCE_FILE = "Locals.java";
 
   @Test
+  // TODO(b/65402086) Remove @ignore when debug behavior will be fixed.
+  @Ignore
+  public void testLocalConstantBis() throws Throwable {
+    final String className = "Locals";
+    final String methodName = "localConstantBis";
+    runDebugTest(className,
+        breakpoint(className, methodName),
+        run(),
+        checkLine(SOURCE_FILE, 332),
+        checkNoLocal("result"),
+        stepOver(),
+        checkLine(SOURCE_FILE, 333),
+        checkLocal("result", Value.createInt(0)),
+        stepOver(),
+        checkLine(SOURCE_FILE, 334),
+        checkLocal("result", Value.createInt(0)),
+        stepOver(),
+        checkLine(SOURCE_FILE, 338),
+        checkLocal("result", Value.createInt(1)),
+        run());
+  }
+
+  @Test
+  public void testLocalConstant() throws Throwable {
+    final String className = "Locals";
+    final String methodName = "localConstant";
+    runDebugTest(className,
+        breakpoint(className, methodName),
+        run(),
+        checkLine(SOURCE_FILE, 322),
+        checkNoLocal("result1"),
+        checkNoLocal("result2"),
+        stepOver(),
+        checkLine(SOURCE_FILE, 323),
+        checkNoLocal("result1"),
+        checkNoLocal("result2"),
+        stepOver(),
+        checkLine(SOURCE_FILE, 324),
+        checkLocal("result1"),
+        checkNoLocal("result2"),
+        run());
+  }
+
+  @Test
   public void testNoLocal() throws Throwable {
     final String className = "Locals";
     final String methodName = "noLocals";