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