Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/StressTestTemplate.java
41161 views
/*1* Copyright (c) 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*/2223package nsk.share.jdi;2425import com.sun.jdi.event.Event;26import nsk.share.Consts;27import nsk.share.TestBug;2829import java.io.PrintStream;30import java.util.ArrayList;3132/*33* Class is intended for stress testing, expected command line parameters:34* - debuggee class name (e.g.: -debuggeeClassName nsk.share.jdi.MonitorEventsDebuggee)35* - one or more tested event types (e.g.: -eventTypes MONITOR_CONTENTED_ENTER:MONITOR_CONTENTED_ENTERED)36* - number of events which should be generated during test execution (e.g.: -eventsNumber 500)37* - number of threads which simultaneously generate events (e.g.: -threadsNumber 10)38*39* Class parses command line and calls method JDIEventsDebugger.stressTestTemplate.40*/41public class StressTestTemplate extends JDIEventsDebugger {42protected String debuggeeClassName;43protected EventType[] testedEventTypes;44protected int eventsNumber = 1;45protected int threadsNumber = 1;4647public static void main(String[] argv) {48System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE);49}5051public static int run(String[] argv, PrintStream out) {52return new StressTestTemplate().runIt(argv, out);53}5455protected String[] doInit(String[] args, PrintStream out) {56args = super.doInit(args, out);5758ArrayList<String> standardArgs = new ArrayList<String>();5960for (int i = 0; i < args.length; i++) {61if (args[i].equals("-eventsNumber") && (i < args.length - 1)) {62eventsNumber = Integer.parseInt(args[i + 1]);6364// for this stress test events number is equivalent of iterations65// (don't support 0 value of IterationsFactor)66if (stressOptions.getIterationsFactor() != 0) {67eventsNumber *= stressOptions.getIterationsFactor();68}69i++;70} else if (args[i].equals("-threadsNumber") && (i < args.length - 1)) {71threadsNumber = Integer.parseInt(args[i + 1]);7273// if 'threadsNumber' is specified test should take in account stress options74threadsNumber *= stressOptions.getThreadsFactor();7576i++;77} else if (args[i].equals("-debuggeeClassName") && (i < args.length - 1)) {78debuggeeClassName = args[i + 1];79i++;80} else if (args[i].equals("-eventTypes") && (i < args.length - 1)) {81String[] eventTypesNames = args[i + 1].split(":");82testedEventTypes = new EventType[eventTypesNames.length];83try {84for (int j = 0; j < eventTypesNames.length; j++) {85testedEventTypes[j] = EventType.valueOf(eventTypesNames[j]);86}87} catch (IllegalArgumentException e) {88throw new TestBug("Invalid event type", e);89}9091i++;92} else {93standardArgs.add(args[i]);94}95}9697if (testedEventTypes == null || testedEventTypes.length == 0) {98throw new TestBug("Test requires 'eventTypes' parameter");99}100101if (debuggeeClassName == null) {102throw new TestBug("Test requires 'debuggeeClassName' parameter");103}104105return standardArgs.toArray(new String[]{});106}107108// can't control events from system libraries, so save events only from nsk packages109protected boolean shouldSaveEvent(Event event) {110return EventTestTemplates.isEventFromNSK(event, debuggee);111}112113protected String debuggeeClassName() {114return debuggeeClassName;115}116117public void doTest() {118prepareDebuggee(testedEventTypes);119120EventTestTemplates.runTestWithRerunPossibilty(this,121() -> stressTestTemplate(testedEventTypes, eventsNumber, threadsNumber));122123eventHandler.stopEventHandler();124removeDefaultBreakpoint();125}126}127128129