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