File: MangleStepTest.java

package info (click to toggle)
openjdk-21 21.0.8%2B9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 823,976 kB
  • sloc: java: 5,613,338; xml: 1,643,607; cpp: 1,296,296; ansic: 420,291; asm: 404,850; objc: 20,994; sh: 15,271; javascript: 11,245; python: 6,895; makefile: 2,362; perl: 357; awk: 351; sed: 172; jsp: 24; csh: 3
file content (124 lines) | stat: -rw-r--r-- 3,777 bytes parent folder | download | duplicates (17)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
 * @test
 * @bug 4390869
 * @bug 4460328
 * @summary Test Stepping in the new SourceDebugExtension facility
 * @author Robert Field
 *
 * @library ..
 *
 * @run build TestScaffold VMConnection TargetListener TargetAdapter InstallSDE
 * @run compile MangleStepTest.java
 * @run compile -g  onion/pickle/Mangle.java
 * @run driver MangleStepTest unset
 * @run driver MangleStepTest Java
 * @run driver MangleStepTest XYZ
 * @run driver MangleStepTest Rats
 * @run driver MangleStepTest bogus
 */
import com.sun.jdi.*;
import com.sun.jdi.event.*;
import com.sun.jdi.request.*;

import java.util.*;
import java.io.File;

public class MangleStepTest extends TestScaffold {
    static final String op = "onion" + File.separator + "pickle" + File.separator;
    ReferenceType targetClass;
    final String stratum;
    static boolean aTestFailed = false;

    MangleStepTest (String stratum) {
        super(new String[0]);
        this.stratum = stratum;
    }

    public static void main(String[] args)      throws Exception {
        testSetUp();
        new MangleStepTest(args[0]).startTests();
        if (aTestFailed) {
            throw new Exception("MangleStepTest: failed");
        }

    }

    /********** test set-up **********/

    static void testSetUp() throws Exception {
        InstallSDE.install(new File(System.getProperty("test.classes", "."),
                                    op + "Mangle.class"),
                           new File(System.getProperty("test.src", "."),
                                    "Mangle.sde"));
    }

    /********** test assist **********/

    void lineMatch(Location loc, int javaLine, int defaultLine) {
        if (loc.lineNumber() != defaultLine) {
            failure("FAIL: at " + loc.lineNumber() +
                    ", expected " + defaultLine);
        } else {
            println("at: " + loc.lineNumber());
        }
        if (loc.lineNumber("Java") != javaLine) {
            failure("FAIL: at Java line " + loc.lineNumber("Java") +
                    ", expected " + javaLine);
        }
    }

    /********** test core **********/

    protected void runTests() throws Exception {
        /*
         * Get to the top of main()
         */
        int[] lines;
        int[] jLines;
        String targetName = "onion.pickle.Mangle";
        startUp(targetName);
        if (!stratum.equals("unset")) {
            vm().setDefaultStratum(stratum);
        }
        BreakpointEvent bpe = resumeTo(targetName, "main",
                                       "([Ljava/lang/String;)V");

        ThreadReference thread = bpe.thread();

        if (stratum.equals("Java")) {
            lines = new int[] {4, 5, 6, 7, 8, 9};
            jLines = new int[] {4, 5, 6, 7, 8, 9};
        } else if (stratum.equals("Rats")) {
            lines = new int[] {1000, 1111, 1112};
            jLines = new int[] {4, 5, 7};
        } else  {  /* XYZ (the class default) */
            lines = new int[] {200, 210, 217, 218};
            jLines = new int[] {4, 7, 8, 9};
        }

        println("Testing stratum: " + stratum);

        lineMatch(bpe.location(), jLines[0], lines[0]);

        for (int i = 1; i < lines.length; ++i) {
            StepEvent se = stepOverLine(thread);
            lineMatch(se.location(), jLines[i], lines[i]);
        }

        /*
         * resume the target to completion
         */
        listenUntilVMDisconnect();

        /*
         * deal with results of test
         * if anything has called failure("foo") testFailed will be true
         */
        if (!testFailed) {
            println("MangleStepTest (" + stratum + "): passed");
        } else {
            println("MangleStepTest (" + stratum + "): failed");
            aTestFailed = true;
        }
    }
}