DebugOutputTest.java revision 9111:a41fe5ffa839
150276Speter/* 2262629Sdelphij * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 350276Speter * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 450276Speter * 550276Speter * This code is free software; you can redistribute it and/or modify it 650276Speter * under the terms of the GNU General Public License version 2 only, as 750276Speter * published by the Free Software Foundation. 850276Speter * 950276Speter * This code is distributed in the hope that it will be useful, but WITHOUT 1050276Speter * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1150276Speter * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1250276Speter * version 2 for more details (a copy is included in the LICENSE file that 1350276Speter * accompanied this code). 1450276Speter * 1550276Speter * You should have received a copy of the GNU General Public License version 1650276Speter * 2 along with this work; if not, write to the Free Software Foundation, 1750276Speter * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1850276Speter * 1950276Speter * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2050276Speter * or visit www.oracle.com if you need additional information or have any 2150276Speter * questions. 2250276Speter */ 2350276Speter 2450276Speter/* 2550276Speter * @test 2650276Speter * @bug 8136421 2750276Speter * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9") & os.arch != "aarch64" 2850276Speter * @library / /testlibrary /../../test/lib 2950276Speter * @compile ../common/CompilerToVMHelper.java 3050276Speter * @run main ClassFileInstaller 3150276Speter * jdk.vm.ci.hotspot.CompilerToVMHelper 3250276Speter * @run driver compiler.jvmci.compilerToVM.DebugOutputTest 3350276Speter */ 3450276Speter 3550276Speterpackage compiler.jvmci.compilerToVM; 3650276Speter 3750276Speterimport jdk.vm.ci.hotspot.CompilerToVMHelper; 3850276Speterimport jdk.test.lib.ProcessTools; 3950276Speterimport java.util.Arrays; 4050276Speterimport jdk.test.lib.OutputAnalyzer; 4150276Speterimport jdk.test.lib.Utils; 4250276Speter 43262629Sdelphijpublic class DebugOutputTest { 4450276Speter public static void main(String[] args) { 4576726Speter new DebugOutputTest().test(); 46178866Srafan } 4750276Speter 48178866Srafan private void test() { 49166124Srafan for (TestCaseData testCase : TestCaseData.values()) { 50166124Srafan System.out.println(testCase); 51166124Srafan OutputAnalyzer oa; 52166124Srafan try { 53166124Srafan ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 5450276Speter /* use test options = */ true, 55262629Sdelphij "-XX:+UnlockExperimentalVMOptions", 5650276Speter "-XX:+EnableJVMCI", 57178866Srafan "-Xbootclasspath/a:.", 58184989Srafan DebugOutputTest.Worker.class.getName(), 59178866Srafan testCase.name()); 60166124Srafan oa = ProcessTools.executeProcess(pb); 61178866Srafan } catch (Exception e) { 62178866Srafan e.printStackTrace(); 63178866Srafan throw new Error("Problems running child process", e); 64178866Srafan } 65166124Srafan if (testCase.expectedException != null) { 66178866Srafan oa.shouldHaveExitValue(1); 67178866Srafan oa.shouldContain(testCase.expectedException.getName()); 68178866Srafan } else { 69178866Srafan oa.shouldHaveExitValue(0); 7050276Speter oa.shouldContain(new String(testCase.getExpected())); 71178866Srafan } 72178866Srafan } 73178866Srafan } 74178866Srafan 7576726Speter /** 76178866Srafan * A list of test cases that are executed in forked VM 77178866Srafan */ 78178866Srafan private enum TestCaseData { 79178866Srafan PART_ARRAY(100, 50), 80166124Srafan FULL_ARRAY(0, 255), 81178866Srafan EMPTY(0, 0), 82166124Srafan NEGATIVE_LENGTH(0, Integer.MIN_VALUE, 83166124Srafan ArrayIndexOutOfBoundsException.class), 84166124Srafan NEGATIVE_OFFSET(-1, 255, 85166124Srafan ArrayIndexOutOfBoundsException.class), 86166124Srafan LEFT_BOUND(Integer.MIN_VALUE, 100, 87166124Srafan ArrayIndexOutOfBoundsException.class), 88166124Srafan RIGHT_BOUND(Integer.MAX_VALUE, 100, 89178866Srafan ArrayIndexOutOfBoundsException.class), 90178866Srafan BIG_LENGTH(0, Integer.MAX_VALUE, 91178866Srafan ArrayIndexOutOfBoundsException.class), 92178866Srafan NULL_POINTER(0, 0, 93178866Srafan NullPointerException.class), 94166124Srafan ; 95184989Srafan 96166124Srafan private static final int SIZE = 255; 97178866Srafan private static final byte[] DATA = generate(); 9850276Speter public final int offset; 9950276Speter public final int length; 10050276Speter public final Class<? extends Throwable> expectedException; 10150276Speter 10250276Speter private TestCaseData(int offset, int length, 10350276Speter Class<? extends Throwable> expectedException) { 10450276Speter this.offset = offset; 10550276Speter this.length = length; 10650276Speter this.expectedException = expectedException; 10750276Speter } 10850276Speter 10950276Speter private TestCaseData(int offset, int length) { 11076726Speter this(offset, length, null); 11176726Speter } 11250276Speter 113262629Sdelphij private static byte[] generate() { 11476726Speter byte[] byteArray = new byte[SIZE]; 11550276Speter for (int i = 0; i < SIZE; i++) { 11650276Speter byteArray[i] = (byte) (i + 1); 11750276Speter } 11850276Speter return byteArray; 11950276Speter } 12050276Speter 12150276Speter public byte[] getExpected() { 12250276Speter if (expectedException != null) { 12350276Speter return new byte[0]; 12450276Speter } 12550276Speter return Arrays.copyOfRange(TestCaseData.DATA, offset, 12650276Speter offset + length); 12776726Speter } 12876726Speter 12950276Speter @Override 130262629Sdelphij public String toString() { 13176726Speter return "CASE: " + this.name(); 13250276Speter } 13350276Speter 13476726Speter public byte[] getData() { 135166124Srafan if (equals(NULL_POINTER)) { 136166124Srafan return null; 137166124Srafan } else { 138166124Srafan return DATA; 139166124Srafan } 14050276Speter } 141178866Srafan } 14276726Speter 14376726Speter public static class Worker { 144174993Srafan public static void main(String[] args) { 145174993Srafan for (String arg : args) { 14650276Speter TestCaseData tcase = TestCaseData.valueOf(arg); 14776726Speter CompilerToVMHelper.writeDebugOutput(tcase.getData(), 148262629Sdelphij tcase.offset, tcase.length); 149262629Sdelphij CompilerToVMHelper.flushDebugOutput(); 150262629Sdelphij } 151262629Sdelphij } 152262629Sdelphij } 15350276Speter} 154178866Srafan