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