test/jdk/com/sun/jdi/ExceptionEvents.java
author dtitov
Tue, 30 Apr 2019 16:11:42 -0700
changeset 54660 4dc2f6122252
parent 47216 71c04702a3d5
permissions -rw-r--r--
8222821: com/sun/jdi/ExceptionEvents.java failed Reviewed-by: dlong, sspitsyn, jcbeyler, cjplummer
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
54660
4dc2f6122252 8222821: com/sun/jdi/ExceptionEvents.java failed
dtitov
parents: 47216
diff changeset
     2
 * Copyright (c) 2001, 2019, 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: 32018
diff changeset
    25
 * @test
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
diff changeset
    26
 * @bug 4407397
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
diff changeset
    27
 * @key intermittent
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
diff changeset
    28
 * @summary Test the requesting of exception events
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
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: 32018
diff changeset
    31
 * @run build TestScaffold VMConnection
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
diff changeset
    32
 * @run compile -g ExceptionEvents.java
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
diff changeset
    34
 * @run driver ExceptionEvents N A StackOverflowCaughtTarg java.lang.Exception
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
diff changeset
    35
 * @run driver ExceptionEvents C A StackOverflowCaughtTarg null
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
diff changeset
    36
 * @run driver ExceptionEvents C A StackOverflowCaughtTarg java.lang.Error
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
diff changeset
    37
 * @run driver ExceptionEvents C A StackOverflowCaughtTarg java.lang.StackOverflowError
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
diff changeset
    38
 * @run driver ExceptionEvents N A StackOverflowCaughtTarg java.lang.NullPointerException
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
diff changeset
    40
 * @run driver ExceptionEvents N T StackOverflowCaughtTarg java.lang.Exception
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
diff changeset
    41
 * @run driver ExceptionEvents C T StackOverflowCaughtTarg null
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
diff changeset
    42
 * @run driver ExceptionEvents C T StackOverflowCaughtTarg java.lang.Error
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
diff changeset
    43
 * @run driver ExceptionEvents C T StackOverflowCaughtTarg java.lang.StackOverflowError
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
diff changeset
    44
 * @run driver ExceptionEvents N T StackOverflowCaughtTarg java.lang.NullPointerException
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
diff changeset
    46
 * @run driver ExceptionEvents N N StackOverflowCaughtTarg java.lang.Exception
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
diff changeset
    47
 * @run driver ExceptionEvents C N StackOverflowCaughtTarg null
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
diff changeset
    48
 * @run driver ExceptionEvents C N StackOverflowCaughtTarg java.lang.Error
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
diff changeset
    49
 * @run driver ExceptionEvents C N StackOverflowCaughtTarg java.lang.StackOverflowError
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
diff changeset
    50
 * @run driver ExceptionEvents N N StackOverflowCaughtTarg java.lang.NullPointerException
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
diff changeset
    52
 * @run driver ExceptionEvents N A StackOverflowUncaughtTarg java.lang.Exception
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
diff changeset
    53
 * @run driver ExceptionEvents U A StackOverflowUncaughtTarg null
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
diff changeset
    54
 * @run driver ExceptionEvents U A StackOverflowUncaughtTarg java.lang.Error
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
diff changeset
    55
 * @run driver ExceptionEvents U A StackOverflowUncaughtTarg java.lang.StackOverflowError
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
diff changeset
    56
 * @run driver ExceptionEvents N A StackOverflowUncaughtTarg java.lang.NullPointerException
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
diff changeset
    58
 * @run driver ExceptionEvents N T StackOverflowUncaughtTarg java.lang.NullPointerException
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 32018
diff changeset
    59
 * @run driver ExceptionEvents N N StackOverflowUncaughtTarg java.lang.NullPointerException
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
import com.sun.jdi.request.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
class StackOverflowCaughtTarg {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            throw new StackOverflowError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        } catch (Throwable exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
class StackOverflowUncaughtTarg {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        thrower();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    static void thrower()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        throw new StackOverflowError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
class StackOverflowIndirectTarg {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            thrower();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        } catch (Throwable exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            System.out.println("Got exception: " + exc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    static void thrower()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        throw new StackOverflowError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
public class ExceptionEvents extends TestScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    static int failureCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    static StringBuffer tooManySummary = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    static StringBuffer notSentSummary = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    static StringBuffer unexpectedSummary = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    static int globalSuspendPolicy = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    static String[] flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    final String target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    final String exceptionName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    final boolean caught;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    final boolean uncaught;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    final int suspendPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    int eventCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    ExceptionRequest request;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    ExceptionEvents(String target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                    String exceptionName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                    boolean caught, boolean uncaught,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                    int suspendPolicy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        super(flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        this.target = target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        this.exceptionName = exceptionName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        this.caught = caught;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        this.uncaught = uncaught;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        this.suspendPolicy = suspendPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    static void everything() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        goNeither("StackOverflowCaughtTarg", "java.lang.Exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        goCaught("StackOverflowCaughtTarg", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        goCaught("StackOverflowCaughtTarg", "java.lang.Error");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        goCaught("StackOverflowCaughtTarg", "java.lang.StackOverflowError");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        goNeither("StackOverflowCaughtTarg", "java.lang.NullPointerException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        goNeither("StackOverflowUncaughtTarg", "java.lang.Exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        goUncaught("StackOverflowUncaughtTarg", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        goUncaught("StackOverflowUncaughtTarg", "java.lang.Error");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        goUncaught("StackOverflowUncaughtTarg", "java.lang.StackOverflowError");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        goNeither("StackOverflowUncaughtTarg", "java.lang.NullPointerException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    static void usage() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        System.err.println("Use either with no arguments or");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        System.err.println("  c|u|n a|t|n <TargetClass> <Exception>|null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        System.err.println("or for verbose folk");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        System.err.println("  caught|uncaught|neither all|thread|none <TargetClass> <Exception>|null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        throw new IllegalArgumentException("see usage");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        StringBuffer testName = new StringBuffer("ExceptionEvents(");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        List flagList = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        List argList = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        for (int i = 0; i < args.length; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            String arg = args[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            if (arg.startsWith("-")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                flagList.add(arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                argList.add(arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        flags = (String[])flagList.toArray(new String[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        args = (String[])argList.toArray(new String[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        if (args.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            everything();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            testName.append("Full Test");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        } else if (args.length == 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            switch (args[1].toLowerCase().charAt(0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            case 'a':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                globalSuspendPolicy = EventRequest.SUSPEND_ALL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            case 't':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                globalSuspendPolicy = EventRequest.SUSPEND_EVENT_THREAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            case 'n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                globalSuspendPolicy = EventRequest.SUSPEND_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            String excString = args[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            if (excString.equals("null")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                excString = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            switch (args[0].toLowerCase().charAt(0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            case 'c':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                goCaught(args[2], excString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            case 'u':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                goUncaught(args[2], excString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            case 'n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                goNeither(args[2], excString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            testName.append(args[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            testName.append(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            testName.append(args[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            testName.append(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            testName.append(args[2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        testName.append(")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        summarize(testName.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    static void summarize(String testName) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        // final analyse
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (tooManySummary.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            System.out.println("\nSummary of tests with too many events:\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                               tooManySummary.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (notSentSummary.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            System.out.println("\nSummary of tests with expected events not sent:\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                               notSentSummary.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        if (unexpectedSummary.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            System.out.println("\nSummary of tests with events when none expected:\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                               unexpectedSummary.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        if (failureCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            throw new Exception(testName + " FAILED " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                                failureCount + " tests!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            System.out.println("\n" + testName + " test PASSED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * Target throws caught exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Events if caught enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    static void goCaught(String target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                         String exceptionName) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        goSuspendPolicy(target, true, exceptionName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                        true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        goSuspendPolicy(target, true, exceptionName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                        true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        goSuspendPolicy(target, false, exceptionName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                        false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        goSuspendPolicy(target, false, exceptionName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                        false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * Target throws uncaught exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * Events if uncaught enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    static void goUncaught(String target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                           String exceptionName) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        goSuspendPolicy(target, true, exceptionName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                        true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        goSuspendPolicy(target, true, exceptionName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                        false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        goSuspendPolicy(target, false, exceptionName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                        true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        goSuspendPolicy(target, false, exceptionName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                        false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * Target doesn't throw named exception.  No events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    static void goNeither(String target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                           String exceptionName) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        goSuspendPolicy(target, false, exceptionName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                        true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        goSuspendPolicy(target, false, exceptionName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                        false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        goSuspendPolicy(target, false, exceptionName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                        true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        goSuspendPolicy(target, false, exceptionName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                        false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * Suspend policy should make no difference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * Iterate over all of them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    static void goSuspendPolicy(String target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                   boolean expectedEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                   String exceptionName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                   boolean caught, boolean uncaught) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        if (globalSuspendPolicy != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            go(target, expectedEvent, exceptionName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
               caught, uncaught, globalSuspendPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            go(target, expectedEvent, exceptionName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
               caught, uncaught, EventRequest.SUSPEND_ALL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            go(target, expectedEvent, exceptionName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
               caught, uncaught, EventRequest.SUSPEND_EVENT_THREAD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            go(target, expectedEvent, exceptionName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
               caught, uncaught, EventRequest.SUSPEND_NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    static void go(String target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                   boolean expectedEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                   String exceptionName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                   boolean caught, boolean uncaught,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                   int suspendPolicy) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        String description = target + " with " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                           exceptionName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                           "/caught=" + caught +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                           "/uncaught=" + uncaught +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                           " suspend=";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        switch (suspendPolicy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        case EventRequest.SUSPEND_ALL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            description += "All";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        case EventRequest.SUSPEND_EVENT_THREAD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            description += "Thread";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        case EventRequest.SUSPEND_NONE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            description += "None";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            throw new Exception("Test failure: bad suspend policy - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                                suspendPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        description += "\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        System.out.print("\nTesting " + description);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        ExceptionEvents aRun = new ExceptionEvents(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                             target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                             exceptionName, caught, uncaught,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                             suspendPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        aRun.startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        aRun.analyse(expectedEvent, description);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    void analyse(boolean expectedEvent, String description) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        if (expectedEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            if (eventCount == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                println("pass: got expected event");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            } else if (eventCount > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                failure("FAILURE: expected only one event got: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                                   eventCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                tooManySummary.append(description);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                ++failureCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                failure("FAILURE: expected event not sent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                notSentSummary.append(description);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                ++failureCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            if (eventCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                failure("FAILURE: unexpected event sent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                unexpectedSummary.append(description);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                ++failureCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                println("pass: as expected no event sent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    /********** event handlers **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    public void exceptionThrown(ExceptionEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        if (event.request() == request) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                System.out.print("ExceptionEvent: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                System.out.print("" + event.exception().referenceType().name());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                Location loc = event.location();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                System.out.print(" @ " + loc.method().name());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                System.out.print(":" + loc.lineNumber());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            } catch (VMDisconnectedException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                System.out.print("Oops - " + exc.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            eventCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            System.out.print("alien exception: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                println(event.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            } catch (VMDisconnectedException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                println("Oops - " + exc.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * Turn off default Exception Handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    protected void createDefaultExceptionRequest() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    /********** test core **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
         * Get to the top of main()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        startToMain(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        ReferenceType exceptionClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        if (exceptionName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            exceptionClass = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            exceptionClass = findReferenceType(exceptionName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            if (exceptionName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                throw new Exception("test failure - cannot find: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                                    exceptionName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        request = eventRequestManager().createExceptionRequest(exceptionClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                                                               caught, uncaught);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        request.addClassExclusionFilter("java.*");
20184
a2c4b7079eb6 8024985: com/sun/jdi/StepTest.java failed since jdk8b107
sla
parents: 5506
diff changeset
   419
        request.addClassExclusionFilter("javax.*");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        request.addClassExclusionFilter("sun.*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        request.addClassExclusionFilter("com.sun.*");
20184
a2c4b7079eb6 8024985: com/sun/jdi/StepTest.java failed since jdk8b107
sla
parents: 5506
diff changeset
   422
        request.addClassExclusionFilter("com.oracle.*");
a2c4b7079eb6 8024985: com/sun/jdi/StepTest.java failed since jdk8b107
sla
parents: 5506
diff changeset
   423
        request.addClassExclusionFilter("oracle.*");
a2c4b7079eb6 8024985: com/sun/jdi/StepTest.java failed since jdk8b107
sla
parents: 5506
diff changeset
   424
        request.addClassExclusionFilter("jdk.internal.*");
54660
4dc2f6122252 8222821: com/sun/jdi/ExceptionEvents.java failed
dtitov
parents: 47216
diff changeset
   425
        request.addClassExclusionFilter("jdk.vm.ci.hotspot.*");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        request.setSuspendPolicy(suspendPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        request.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        listenUntilVMDisconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
}