Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ExceptionRequest/addClassExclusionFilter/filter001.java
41162 views
/*1* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package nsk.jdi.ExceptionRequest.addClassExclusionFilter;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdi.*;2829import com.sun.jdi.*;30import com.sun.jdi.event.*;31import com.sun.jdi.request.*;3233import java.util.*;34import java.io.*;3536/**37* The test for the implementation of an object of the type38* ExceptionRequest.39*40* The test checks that results of the method41* <code>com.sun.jdi.ExceptionRequest.addClassExclusionFilter()</code>42* complies with its spec.43*44* The test checks up on the following assertion:45* Restricts the events generated by this request to those46* whose location is in a class whose name does not match a47* restricted regular expression.48* The cases to check include both a pattern that begins with '*' and49* one that end with '*'.50*51* The test works as follows.52* - The debugger53* - sets up two ExceptionRequests,54* - restricts the Requests using patterns that begins with '*' and55* ends with *, so that, events will be filtered only from thread1,56* - resumes the debuggee, and57* - waits for expected ExceptionEvents.58* - The debuggee creates and starts two threads, thread1 and thread2,59* that being run, throw NullPointerExceptions used60* to generate Events and to test the filters.61* - Upon getting the events, the debugger performs checks required.62*/6364public class filter001 extends TestDebuggerType1 {6566public static void main (String argv[]) {67System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE);68}6970public static int run (String argv[], PrintStream out) {71debuggeeName = "nsk.jdi.ExceptionRequest.addClassExclusionFilter.filter001a";72return new filter001().runThis(argv, out);73}7475private String testedClassName1 = "TestClass11";76private String testedClassName2 = "nsk.jdi.ExceptionRequest.addClassExclusionFilter.Thread2filter001a";7778protected void testRun() {7980String property1 = "ExceptionRequest1";81String property2 = "ExceptionRequest2";8283Event newEvent = null;8485for (int i = 0; ; i++) {8687if (!shouldRunAfterBreakpoint()) {88vm.resume();89break;90}9192display(":::::: case: # " + i);9394switch (i) {9596case 0:97final EventRequest eventRequest1 = setting23ExceptionRequest( null,98"*" + testedClassName1,99EventRequest.SUSPEND_NONE,100property1);101eventRequest1.enable();102eventHandler.addListener(103new EventHandler.EventListener() {104public boolean eventReceived(Event event) {105if (event instanceof ExceptionEvent && event.request().equals(eventRequest1)) {106String str = ((ExceptionEvent)event).location().declaringType().name();107if (str.endsWith(testedClassName1)) {108setFailedStatus("eventRequest1: Received unexpected ExceptionEvent for excluded class:" + str);109} else {110display("eventRequest1: Received expected ExceptionEvent for " + str);111}112return true;113}114return false;115}116}117);118119display("......waiting1 for ExceptionEvent in expected thread");120vm.resume();121break;122123case 1:124final EventRequest eventRequest2 = setting23ExceptionRequest( null,125testedClassName2 + "*",126EventRequest.SUSPEND_NONE,127property2);128eventRequest2.enable();129eventHandler.addListener(130new EventHandler.EventListener() {131public boolean eventReceived(Event event) {132if (event instanceof ExceptionEvent && event.request().equals(eventRequest2)) {133String str = ((ExceptionEvent)event).location().declaringType().name();134if (str.endsWith(testedClassName2)) {135setFailedStatus("eventRequest2: Received ExceptionEvent for excluded class:" + str);136} else {137display("eventRequest2: Received expected ExceptionEvent for " + str);138}139return true;140}141return false;142}143}144);145146display("......waiting for ExceptionEvent in expected thread");147vm.resume();148break;149150default:151throw new Failure("** default case 2 **");152}153}154return;155}156157private ExceptionRequest setting23ExceptionRequest ( ThreadReference thread,158String testedClass,159int suspendPolicy,160String property ) {161try {162display("......setting up ExceptionRequest:");163display(" thread: " + thread + "; class exclude filter: " + testedClass + "; property: " + property);164165ExceptionRequest166excr = eventRManager.createExceptionRequest(null, true, true);167excr.putProperty("number", property);168if (thread != null)169excr.addThreadFilter(thread);170excr.addClassExclusionFilter(testedClass);171excr.setSuspendPolicy(suspendPolicy);172173display(" ExceptionRequest has been set up");174return excr;175} catch ( Exception e ) {176throw new Failure("** FAILURE to set up ExceptionRequest **");177}178}179}180181182