Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/mlvm/meth/share/SimpleUnitTest.java
41162 views
/*1* Copyright (c) 2011, 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 vm.mlvm.meth.share;2425import java.lang.invoke.MethodHandles;26import java.lang.invoke.MethodType;2728import vm.mlvm.share.Env;29import vm.mlvm.share.MlvmTest;30import vm.share.options.Option;3132public class SimpleUnitTest extends MlvmTest {3334@Option(name = "failOnce", default_value = "false", description = "exit after the first failure")35private boolean failOnce = true;3637public SimpleUnitTest() {}3839public SimpleUnitTest test1(int a, float b) {40Env.traceNormal("test1(%d, %f) called", a, b);41return this;42}4344private static SimpleUnitTest sut = new SimpleUnitTest();4546public static SimpleUnitTest test2(int a, float b) {47Env.traceNormal("test2(%d, %f) called", a, b);48return sut;49}5051public static int test3(int a) {52Env.traceNormal("test3(%d) called", a);53return a;54}5556public void test4() {57Env.traceNormal("test4() called");58}5960public SimpleUnitTest test5() {61Env.traceNormal("test5() called");62return this;63}6465public static void main(String[] args) { MlvmTest.launch(args); }6667@Override68public boolean run() throws Throwable {69try {70Argument retArg;71retArg = new Argument(SimpleUnitTest.class, sut);72retArg.setPreserved(true);7374Argument intArg = new Argument(int.class, Integer.valueOf(1));7576for ( ;; ) {77try {78switch ( Env.getRNG().nextInt(5) ) {79case 0:80MHTransformationGen.createAndCallSequence(81retArg,82sut,83MethodHandles.lookup().findVirtual(84SimpleUnitTest.class,85"test1",86MethodType.methodType(SimpleUnitTest.class, int.class, float.class)87),88new Argument[] { new Argument(int.class, Integer.valueOf(1)), new Argument(float.class, Float.valueOf(1.0)) },89true);90break;9192case 1:93MHTransformationGen.createAndCallSequence(94retArg,95null,96MethodHandles.lookup().findStatic(97SimpleUnitTest.class,98"test2",99MethodType.methodType(SimpleUnitTest.class, int.class, float.class)100),101new Argument[] { new Argument(int.class, Integer.valueOf(1)), new Argument(float.class, Float.valueOf(1.0)) },102true);103break;104105case 2:106MHTransformationGen.createAndCallSequence(107intArg,108null,109MethodHandles.lookup().findStatic(110SimpleUnitTest.class,111"test3",112MethodType.methodType(int.class, int.class)113),114new Argument[] { intArg },115true);116break;117118case 3:119MHTransformationGen.createAndCallSequence(120new Argument(void.class, null),121sut,122MethodHandles.lookup().findVirtual(123SimpleUnitTest.class,124"test4",125MethodType.methodType(void.class)126),127new Argument[0],128false);129break;130131default:132MHTransformationGen.createAndCallSequence(133retArg,134sut,135MethodHandles.lookup().findVirtual(136SimpleUnitTest.class,137"test5",138MethodType.methodType(SimpleUnitTest.class)139),140new Argument[0],141true);142break;143144}145} catch ( Throwable e ) {146Env.getLog().complain("Caught exception", e);147if ( failOnce )148return false;149}150}151} catch ( Throwable t ) {152t.printStackTrace();153return false;154}155}156157}158159160