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