Path: blob/master/test/hotspot/jtreg/compiler/compilercontrol/share/MultiCommand.java
64495 views
/*1* Copyright (c) 2015, 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 compiler.compilercontrol.share;2425import compiler.compilercontrol.share.method.MethodDescriptor;26import compiler.compilercontrol.share.scenario.Command;27import compiler.compilercontrol.share.scenario.CommandGenerator;28import compiler.compilercontrol.share.scenario.CompileCommand;29import compiler.compilercontrol.share.scenario.Scenario;30import jdk.test.lib.Utils;3132import java.lang.reflect.Executable;33import java.util.ArrayList;34import java.util.List;3536import static compiler.compilercontrol.share.IntrinsicCommand.VALID_INTRINSIC_SAMPLES;37import static compiler.compilercontrol.share.IntrinsicCommand.INVALID_INTRINSIC_SAMPLES;3839public class MultiCommand extends AbstractTestBase {40private final List<CompileCommand> testCases;4142public MultiCommand(List<CompileCommand> testCases) {43this.testCases = testCases;44}4546/**47* Generates a test containing multiple random commands48*49* @param validOnly shows that all commands should be valid50* @return test instance to run51*/52public static AbstractTestBase generateRandomTest(boolean validOnly) {53CommandGenerator cmdGen = new CommandGenerator();54List<Command> commands = cmdGen.generateCommands();55List<CompileCommand> testCases = new ArrayList<>();5657for (Command cmd : commands) {58String argument = null;5960if (validOnly && cmd == Command.NONEXISTENT) {61// replace with a valid command62cmd = Command.EXCLUDE;63}64if (cmd == Command.INTRINSIC) {65if (validOnly) {66argument = Utils.getRandomElement(VALID_INTRINSIC_SAMPLES);67} else {68argument = Utils.getRandomElement(INVALID_INTRINSIC_SAMPLES);69}70}7172Executable exec = Utils.getRandomElement(METHODS).first;73MethodDescriptor md;7475// Command.quiet discards the method descriptor - can never fail on the method descriptor76if (validOnly || cmd == Command.QUIET) {77md = AbstractTestBase.getValidMethodDescriptor(exec);78} else {79md = AbstractTestBase.METHOD_GEN.generateRandomDescriptor(exec);80}81CompileCommand cc;82if (cmd == Command.INTRINSIC) {83cc = cmdGen.generateCompileCommand(cmd, md, null, argument);84} else {85cc = cmdGen.generateCompileCommand(cmd, md, null);86}87testCases.add(cc);88}89return new MultiCommand(testCases);90}9192@Override93public void test() {94Scenario.Builder builder = Scenario.getBuilder();95builder.addFlag("-Xmixed");96builder.addFlag("-XX:+UnlockDiagnosticVMOptions");97builder.addFlag("-XX:CompilerDirectivesLimit=101");98for (CompileCommand cc : testCases) {99builder.add(cc);100}101Scenario scenario = builder.build();102scenario.execute();103}104}105106107