Path: blob/master/test/hotspot/jtreg/compiler/lib/ir_framework/RunInfo.java
64507 views
/*1* Copyright (c) 2021, 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.lib.ir_framework;2425import compiler.lib.ir_framework.test.DeclaredTest;26import compiler.lib.ir_framework.shared.TestRunException;27import compiler.lib.ir_framework.test.TestVM;2829import java.lang.reflect.Method;30import java.util.HashMap;31import java.util.List;32import java.util.Map;3334/**35* Test info class which provides some useful utility methods and information about a <b>custom run test</b>.36*37* @see Run38*/39public class RunInfo extends AbstractInfo {40private final Method testMethod;41private final DeclaredTest test;42private final Map<String, DeclaredTest> tests;43private final boolean hasMultipleTests;4445public RunInfo(List<DeclaredTest> tests) {46super(tests.get(0).getTestMethod().getDeclaringClass());47this.test = tests.get(0);48this.testMethod = test.getTestMethod();49this.hasMultipleTests = tests.size() != 1;50if (hasMultipleTests) {51this.tests = new HashMap<>();52for (DeclaredTest test : tests) {53this.tests.put(test.getTestMethod().getName(), test);54}55} else {56this.tests = null;57}58}5960/**61* Get the associated test method object of this custom run test. This method can only be called if <i>one</i> test62* method is specified in the custom run test ({@link Run#test()}). Otherwise, use {@link #getTest(String)}.63*64* @return the associated test method object.65* @throws TestRunException if called for a custom run test that specifies multiple test methods in {@link Run#test()}.66*/67public Method getTest() {68checkSingleTest("getTest");69return testMethod;70}7172/**73* Get the associated method object of the test method with the name {@code testName}. This method can only be called74* if the custom run test specifies more than one test method in ({@link Run#test()}). Otherwise, use {@link #getTest()}.75*76* @param testName the test method for which the method object should be returned.77* @return the associated test method object with the name {@code testName}.78* @throws TestRunException if there is no test method with the name {@code testName} or if called with only79* <i>one</i> associated test method.80*/81public Method getTest(String testName) {82checkMultipleTests("getTest");83return getMethod(testName);84}8586/**87* Return a boolean indicating if the framework skipped a compilation of the associated test method after the warm-up88* due to VM flags not allowing a compilation on the requested level in {@link Test#compLevel()}. This method can only89* be called if <i>one</i> test method is specified in the custom run test ({@link Run#test()}). Otherwise, use90* {@link #isCompilationSkipped(String)}.91*92* @return {@code true} if the framework skipped compilation of the test;93* {@code false} otherwise.94* @throws TestRunException if called for a custom run test that specifies multiple test methods in {@link Run#test()}.95*/96public boolean isCompilationSkipped() {97checkSingleTest("isCompilationSkipped");98return test.getCompLevel() == CompLevel.SKIP;99}100101/**102* Return a boolean indicating if the framework skipped a compilation of the associated test method with the name103* {@code testName} after the warm-up due to VM flags not allowing a compilation on the requested level in104* {@link Test#compLevel()}. This method can only be called if the custom run test specifies more than one test method105* in ({@link Run#test()}). Otherwise, use {@link #isCompilationSkipped()}.106*107* @param testName the test method for which the method object should be returned.108* @return {@code true} if the framework skipped compilation of the test;109* {@code false} otherwise.110* @throws TestRunException if there is no test method with the name {@code testName} or if called with only111* <i>one</i> associated test method.112*/113public boolean isCompilationSkipped(String testName) {114checkMultipleTests("isCompilationSkipped");115return getDeclaredTest(testName).getCompLevel() == CompLevel.SKIP;116}117118/**119* Returns a boolean indicating if the associated test method is C1 compiled. This method can only be called if120* <i>one</i> test method is specified in the custom run test ({@link Run#test()}). Otherwise, use121* {@link #isTestC1Compiled(String)}.122*123* @return {@code true} if the associated test method is C1 compiled;124* {@code false} otherwise.125* @throws TestRunException if called for a custom run test that specifies multiple test methods in {@link Run#test()}.126*/127public boolean isTestC1Compiled() {128checkSingleTest("isTestC1Compiled");129return TestVM.isC1Compiled(testMethod);130}131132/**133* Returns a boolean indicating if the associated test method with the name {@code testName} is C1 compiled.134* This method can only be called if the custom run test specifies more than one test method in ({@link Run#test()}).135* Otherwise, use {@link #isTestC1Compiled()}.136*137* @param testName the name of the test method.138* @return {@code true} if the test method with the name {@code testName} is C1 compiled;139* {@code false} otherwise.140* @throws TestRunException if there is no test method with the name {@code testName} or if called with only141* <i>one</i> associated test method.142*/143public boolean isTestC1Compiled(String testName) {144checkMultipleTests("isTestC1Compiled");145return TestVM.isC1Compiled(getMethod(testName));146}147148/**149* Returns a boolean indicating if the associated test method is C2 compiled. This method can only be called if150* <i>one</i> test method is specified in the custom run test ({@link Run#test()}). Otherwise, use151* {@link #isTestC2Compiled(String)}.152*153* @return {@code true} if the associated test method is C2 compiled;154* {@code false} otherwise.155* @throws TestRunException if called for a custom run test that specifies multiple test methods in {@link Run#test()}.156*/157public boolean isTestC2Compiled() {158checkSingleTest("isTestC2Compiled");159return TestVM.isC2Compiled(testMethod);160}161162/**163* Returns a boolean indicating if the associated test method with the name {@code testName} is C2 compiled.164* This method can only be called if the custom run test specifies more than one test method in ({@link Run#test()}).165* Otherwise, use {@link #isTestC2Compiled()}.166*167* @param testName the name of the test method.168* @return {@code true} if the test method with the name {@code testName} is C2 compiled;169* {@code false} otherwise.170* @throws TestRunException if there is no test method with the name {@code testName} or if called with only171* <i>one</i> associated test method.172*/173public boolean isTestC2Compiled(String testName) {174checkMultipleTests("isTestC2Compiled");175return TestVM.isC2Compiled(getMethod(testName));176}177178/**179* Returns a boolean indicating if the associated test method is compiled at {@code compLevel}. This method can only180* be called if <i>one</i> test method is specified in the custom run test ({@link Run#test()}).181* Otherwise, use {@link #isTestCompiledAtLevel(String, CompLevel)}.182*183* @param compLevel the compilation level184* @return {@code true} if the associated test method is compiled at {@code compLevel};185* {@code false} otherwise.186* @throws TestRunException if called for a custom run test that specifies multiple test methods in {@link Run#test()}.187*/188public boolean isTestCompiledAtLevel(CompLevel compLevel) {189checkSingleTest("isTestCompiledAtLevel");190return TestVM.isCompiledAtLevel(testMethod, compLevel);191}192193/**194* Returns a boolean indicating if the associated test method with the name {@code testName} is compiled at195* {@code compLevel}. This method can only be called if the custom run test specifies more than one test method196* in ({@link Run#test()}). Otherwise, use {@link #isTestCompiledAtLevel(CompLevel)}.197*198* @param testName the name of the test method.199* @param compLevel the compilation level.200* @return {@code true} if the test method with the name {@code testName} is compiled at {@code compLevel};201* {@code false} otherwise.202* @throws TestRunException if there is no test method with the name {@code testName} oor if called with only203* <i>one</i> associated test method.204*/205public boolean isTestCompiledAtLevel(String testName, CompLevel compLevel) {206checkMultipleTests("isTestCompiledAtLevel");207return TestVM.isCompiledAtLevel(getMethod(testName), compLevel);208}209210private void checkSingleTest(String calledMethod) {211if (hasMultipleTests) {212throw new TestRunException("Use " + calledMethod + "(String) with testName String argument in @Run method " +213"for custom run test that specifies more than one @Test method.");214}215}216217private void checkMultipleTests(String calledMethod) {218if (!hasMultipleTests) {219throw new TestRunException("Use " + calledMethod + "() without testName String argument in @Run method " +220"for custom run test that specifies exactly one @Test method.");221}222}223224private DeclaredTest getDeclaredTest(String testName) {225DeclaredTest test = tests.get(testName);226if (test == null) {227throw new TestRunException("Could not find @Test \"" + testName + "\" in " + testClass + " being associated with" +228" corresponding @Run method.");229}230return test;231}232233private Method getMethod(String testName) {234return getDeclaredTest(testName).getTestMethod();235}236}237238239