1 /** 2 * @test 3 * @bug 4390869 4 * @bug 4460328 5 * @summary Test Stepping in the new SourceDebugExtension facility 6 * 7 * @author Robert Field 8 * 9 * @library .. 10 * @modules jdk.jdi 11 * @run build TestScaffold VMConnection TargetListener TargetAdapter InstallSDE 12 * @run compile MangleStepTest.java 13 * @run compile -g onion/pickle/Mangle.java 14 * @run driver MangleStepTest unset 15 * @run driver MangleStepTest Java 16 * @run driver MangleStepTest XYZ 17 * @run driver MangleStepTest Rats 18 * @run driver MangleStepTest bogus 19 */ 20 import com.sun.jdi.*; 21 import com.sun.jdi.event.*; 22 import com.sun.jdi.request.*; 23 24 import java.util.*; 25 import java.io.File; 26 27 public class MangleStepTest extends TestScaffold { 28 static final String op = "onion" + File.separator + "pickle" + File.separator; 29 ReferenceType targetClass; 30 final String stratum; 31 static boolean aTestFailed = false; 32 33 MangleStepTest (String stratum) { 34 super(new String[0]); 35 this.stratum = stratum; 36 } 37 38 public static void main(String[] args) throws Exception { 39 testSetUp(); 40 new MangleStepTest(args[0]).startTests(); 41 if (aTestFailed) { 42 throw new Exception("MangleStepTest: failed"); 43 } 44 45 } 46 47 /********** test set-up **********/ 48 49 static void testSetUp() throws Exception { 50 InstallSDE.install(new File(System.getProperty("test.classes", "."), 51 op + "Mangle.class"), 52 new File(System.getProperty("test.src", "."), 53 "Mangle.sde")); 54 } 55 56 /********** test assist **********/ 57 58 void lineMatch(Location loc, int javaLine, int defaultLine) { 59 if (loc.lineNumber() != defaultLine) { 60 failure("FAIL: at " + loc.lineNumber() + 61 ", expected " + defaultLine); 62 } else { 63 println("at: " + loc.lineNumber()); 64 } 65 if (loc.lineNumber("Java") != javaLine) { 66 failure("FAIL: at Java line " + loc.lineNumber("Java") + 67 ", expected " + javaLine); 68 } 69 } 70 71 /********** test core **********/ 72 73 protected void runTests() throws Exception { 74 /* 75 * Get to the top of main() 76 */ 77 int[] lines; 78 int[] jLines; 79 String targetName = "onion.pickle.Mangle"; 80 startUp(targetName); 81 if (!stratum.equals("unset")) { 82 vm().setDefaultStratum(stratum); 83 } 84 BreakpointEvent bpe = resumeTo(targetName, "main", 85 "([Ljava/lang/String;)V"); 86 87 ThreadReference thread = bpe.thread(); 88 89 if (stratum.equals("Java")) { 90 lines = new int[] {4, 5, 6, 7, 8, 9}; 91 jLines = new int[] {4, 5, 6, 7, 8, 9}; 92 } else if (stratum.equals("Rats")) { 93 lines = new int[] {1000, 1111, 1112}; 94 jLines = new int[] {4, 5, 7}; 95 } else { /* XYZ (the class default) */ 96 lines = new int[] {200, 210, 217, 218}; 97 jLines = new int[] {4, 7, 8, 9}; 98 } 99 100 println("Testing stratum: " + stratum); 101 102 lineMatch(bpe.location(), jLines[0], lines[0]); 103 104 for (int i = 1; i < lines.length; ++i) { 105 StepEvent se = stepOverLine(thread); 106 lineMatch(se.location(), jLines[i], lines[i]); 107 } 108 109 /* 110 * resume the target to completion 111 */ 112 listenUntilVMDisconnect(); 113 114 /* 115 * deal with results of test 116 * if anything has called failure("foo") testFailed will be true 117 */ 118 if (!testFailed) { 119 println("MangleStepTest (" + stratum + "): passed"); 120 } else { 121 println("MangleStepTest (" + stratum + "): failed"); 122 aTestFailed = true; 123 } 124 } 125 }