jdk/test/com/sun/jdi/PopSynchronousTest.java
author iignatyev
Wed, 15 Mar 2017 22:48:59 -0700
changeset 44423 306c020eb154
parent 30376 2ccf2cf7ea48
permissions -rw-r--r--
8176176: fix @modules in jdk_svc tests Reviewed-by: shurailine, sspitsyn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 24973
diff changeset
     2
 * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/**
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    25
 * @test
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    26
 * @bug 4467564
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    27
 * @summary Test the popping of frames in synchronous context
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    28
 *          (that is, when stopped at an event)
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    29
 * @author Robert Field
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    31
 * @run build TestScaffold VMConnection TargetListener TargetAdapter
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    32
 * @run compile -g PopSynchronousTest.java
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    33
 * @run driver PopSynchronousTest
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import com.sun.jdi.request.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    /********** target program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
class PopSynchronousTarg {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    static String s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    static PopSynchronousTarg sole;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    synchronized void a(int y, boolean w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        if (y == 6 && w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
            s += "@";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
            s += " aArgFail ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    String b(String h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        if (h.equals("yo")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            s += "[";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            s += " bArgFail ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        a(6, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        s += "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    long c() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        s += "<";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        synchronized (s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            b("yo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        s += ">";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        return 17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    static void p() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        s += "(";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        if (sole.c() != 17) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            s += " cReturnFail ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        s += ")";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    static void report() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public static void main(String[] args){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        s = new String();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        sole = new PopSynchronousTarg();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        for (int i = 0; i < 100; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            p();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            // System.out.println(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            report();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /********** test program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
public class PopSynchronousTest extends TestScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    ReferenceType targetClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    ThreadReference mainThread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    int stateIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    String expected = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    static final String[] calls =  {"a", "b", "c", "p", "main"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    static final int popMax = calls.length - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    static final String[] states =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    {"main-i", "p-e", "p-i", "c-e", "c-i", "b-e", "b-i", "a-e", "a-l", "b-l", "c-l", "p-l", "main-r", "report-e"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    static final String[] output =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    {"",       "",    "(",   "",    "<",   "",    "[",   "",    "@",   "]",   ">",   ")",   "",       ""};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    PopSynchronousTest (String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public static void main(String[] args)      throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        new PopSynchronousTest(args).startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /********** test assist **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    StackFrame frameFor(String methodName) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        Iterator it = mainThread.frames().iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        while (it.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            StackFrame frame = (StackFrame)it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            if (frame.location().method().name().equals(methodName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                return frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        failure("FAIL: " + methodName + " not on stack");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    String actual() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        Field field = targetClass.fieldByName("s");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        StringReference sr = (StringReference)(targetClass.getValue(field));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        return sr.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    void checkExpected() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        if (!actual().equals(expected)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            failure("FAIL: expected value: " + expected +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                    " got: " + actual());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    int methodIndex(String methodName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        for (int i = 0; i < popMax; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            if (methodName.equals(calls[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    boolean isTop(String methodName) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        return mainThread.frame(0).location().method().name().equals(methodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    void checkTop(String methodName, boolean atStart) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        Location loc = mainThread.frame(0).location();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        Method meth = loc.method();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        String name = meth.name();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        if (!isTop(methodName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            failure("FAIL: expected " + methodName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                    " at top of stack, instead: " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        } else if ((meth.location().codeIndex() == loc.codeIndex()) != atStart) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            failure("FAIL: not at expect position: " + loc.codeIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    void checkState() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        String name = states[stateIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        int dash = name.indexOf('-');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        String methodName = name.substring(0,dash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        String posName = name.substring(dash+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        checkTop(methodName, posName.equals("e"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        checkExpected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    void incrementState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        stateIndex = (stateIndex + 1) % (states.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    void resetState(String stateName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        for (int i=0; i < states.length; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            if (states[i].equals(stateName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                stateIndex = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        failure("TEST FAILURE: cannot find state: " + stateName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    void resetExpected() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        println("Current value: " + actual());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        Field field = targetClass.fieldByName("s");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        expected = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        ((ClassType)targetClass).setValue(field, vm().mirrorOf(expected));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    void stateTo(String stateName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            incrementState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            expected += output[stateIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        } while(!states[stateIndex].equals(stateName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    void resumeTo(String methodName) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        List meths = targetClass.methodsByName(methodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        Method meth = (Method)(meths.get(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        resumeTo(meth.location());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        stateTo(methodName + "-e");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        checkState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    void pop(String methodName) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        mainThread.popFrames(frameFor(methodName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        resetState(methodName + "-e");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        --stateIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        checkState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    void reenter(String methodName) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        pop(methodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        stepIntoInstruction(mainThread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        incrementState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        checkState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /********** test core **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
         * Get to the top of main()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
         * to determine targetClass and mainThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        BreakpointEvent bpe = startToMain("PopSynchronousTarg");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        targetClass = bpe.location().declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        mainThread = bpe.thread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
         * Testing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        /* individual tests */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        for (int i = 0; i < popMax; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            String from = calls[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            for (int j = i; j < popMax; ++j) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                String to = calls[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                String prev = calls[j+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                println("TEST pop from '" + from + "' to '" + to + "'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                resumeTo(from);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                reenter(to);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                resumeTo("report");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                resetExpected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        /* sequential tests */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        println("TEST pop a b c p");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        resumeTo("a");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        pop("a");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        pop("b");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        pop("c");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        pop("p");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        resumeTo("report");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        resetExpected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        println("TEST pop a c p");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        resumeTo("a");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        pop("a");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        pop("c");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        pop("p");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        resumeTo("report");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        resetExpected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        println("TEST stress a");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        resumeTo("a");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        for (int i = 0; i < 100; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            reenter("a");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        resumeTo("report");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        resetExpected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        println("TEST stress c");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        resumeTo("c");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        for (int i = 0; i < 100; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            reenter("c");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        resumeTo("report");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        resetExpected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
         * we are done, get rid of target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        vm().dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
         * deal with results of test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
         * if anything has called failure("foo") testFailed will be true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            println("PopSynchronousTest: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            throw new Exception("PopSynchronousTest: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
}