Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/EventTestTemplates.java
41161 views
/*1* Copyright (c) 2006, 2020, 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*/22package nsk.share.jdi;2324import com.sun.jdi.ObjectCollectedException;25import com.sun.jdi.event.Event;26import com.sun.jdi.event.MonitorContendedEnterEvent;27import com.sun.jdi.event.MonitorContendedEnteredEvent;28import com.sun.jdi.event.MonitorWaitEvent;29import com.sun.jdi.event.MonitorWaitedEvent;3031/*32* Class contains debugger classes based on JDIEventsDebugger intended for JDI events testing33*/34public class EventTestTemplates {3536// how many times rerun test in case when tested events aren't generated37static final int MAX_TEST_RUN_NUMBER = 10;3839/*40* Method contains common code used by EventFilterTests and StressTestTemplate41*/42static void runTestWithRerunPossibilty(JDIEventsDebugger debugger, Runnable testRunner) {43for (int i = 0; i < MAX_TEST_RUN_NUMBER; i++) {44testRunner.run();4546/*47* If events weren't generated at all but test accepts missing events48* try to rerun test (rerun test only if it didn't fail yet)49*/50if (debugger.eventsNotGenerated() && debugger.getSuccess()) {51if (i < MAX_TEST_RUN_NUMBER - 1) {52debugger.log.display("\nWARNING: tested events weren't generated at all, trying to rerun test (rerun attempt " + (i + 1) + ")\n");53} else {54debugger.setSuccess(false);55debugger.log.complain("Tested events weren't generated after " + MAX_TEST_RUN_NUMBER + " runs, test FAILED");56}57} else {58break;59}60}61}6263static public boolean isEventFromNSK(Event event, Debugee debuggee) {64try {65if (event instanceof MonitorContendedEnterEvent) {66return ((MonitorContendedEnterEvent) event).location() != null && ((MonitorContendedEnterEvent) event).monitor().type().name().startsWith("nsk.");67}68if (event instanceof MonitorContendedEnteredEvent) {69return ((MonitorContendedEnteredEvent) event).location() != null && ((MonitorContendedEnteredEvent) event).monitor().type().name().startsWith("nsk.");70}71if (event instanceof MonitorWaitEvent) {72return ((MonitorWaitEvent) event).monitor().type().name().startsWith("nsk.");73}74if (event instanceof MonitorWaitedEvent) {75return ((MonitorWaitedEvent) event).monitor().type().name().startsWith("nsk.");76}77} catch (ObjectCollectedException ex) {78// The monitor object the event refers to might be already collected. Ignore this exception.79debuggee.getLog().display("Exception caught:" + ex);80return false;81}82// don't filter other events83return true;84}8586}878889