Path: blob/master/test/hotspot/jtreg/compiler/compilercontrol/share/MultiCommand.java
41155 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;74if (validOnly) {75md = AbstractTestBase.getValidMethodDescriptor(exec);76} else {77md = AbstractTestBase.METHOD_GEN.generateRandomDescriptor(exec);78}79CompileCommand cc;80if (cmd == Command.INTRINSIC) {81cc = cmdGen.generateCompileCommand(cmd, md, null, argument);82} else {83cc = cmdGen.generateCompileCommand(cmd, md, null);84}85testCases.add(cc);86}87return new MultiCommand(testCases);88}8990@Override91public void test() {92Scenario.Builder builder = Scenario.getBuilder();93builder.addFlag("-Xmixed");94builder.addFlag("-XX:+UnlockDiagnosticVMOptions");95builder.addFlag("-XX:CompilerDirectivesLimit=101");96for (CompileCommand cc : testCases) {97builder.add(cc);98}99Scenario scenario = builder.build();100scenario.execute();101}102}103104105