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