1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package jdk.jfr.startupargs; 27 28 import jdk.test.lib.Asserts; 29 import jdk.test.lib.process.OutputAnalyzer; 30 import jdk.test.lib.process.ProcessTools; 31 32 /** 33 * @test 34 * @key jfr 35 * 36 * 37 * @library /lib / 38 * 39 * @run main jdk.jfr.startupargs.TestMultipleStartupRecordings 40 */ 41 public class TestMultipleStartupRecordings { 42 43 private static final String START_FLIGHT_RECORDING = "-XX:StartFlightRecording"; 44 private static final String FLIGHT_RECORDER_OPTIONS = "-XX:FlightRecorderOptions"; 45 46 static class MainClass { 47 public static void main(String[] args) { 48 } 49 } 50 51 private static void test(ProcessBuilder pb, String... expectedOutputs) throws Exception { 52 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 53 for (String s : expectedOutputs) { 54 output.shouldContain(s); 55 } 56 } 57 58 private static void launchUnary(String options) throws Exception { 59 String recording1 = START_FLIGHT_RECORDING + (options != null ? options : ""); 60 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, recording1, MainClass.class.getName()); 61 test(pb, "Started recording 1"); 62 } 63 64 private static void launchBinary(String options1, String options2) throws Exception { 65 String recording1 = START_FLIGHT_RECORDING + (options1 != null ? options1 : ""); 66 String recording2 = START_FLIGHT_RECORDING + (options2 != null ? options2 : ""); 67 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, recording1, recording2, MainClass.class.getName()); 68 test(pb, "Started recording 1", "Started recording 2"); 69 } 70 71 private static void launchTernary(String options1, String options2, String options3) throws Exception { 72 String recording1 = START_FLIGHT_RECORDING + (options1 != null ? options1 : ""); 73 String recording2 = START_FLIGHT_RECORDING + (options2 != null ? options2 : ""); 74 String recording3 = START_FLIGHT_RECORDING + (options3 != null ? options3 : ""); 75 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, recording1, recording2, recording3, MainClass.class.getName()); 76 test(pb, "Started recording 1", "Started recording 2", "Started recording 3"); 77 } 78 79 private static void testDefault() throws Exception { 80 System.out.println("testDefault"); 81 launchUnary(null); 82 launchBinary(null, null); 83 launchTernary(null, null, null); 84 } 85 86 private static void testColonDelimited() throws Exception { 87 launchBinary(":name=myrecording1,filename=myrecording1.jfr", ":filename=myrecording2.jfr,name=myrecording2"); 88 } 89 90 private static void testMixed() throws Exception { 91 launchTernary(":maxage=2d,maxsize=5GB", "=dumponexit=true,maxage=10m,", ":name=myrecording,maxage=10m,filename=myrecording.jfr,disk=false"); 92 } 93 94 private static void testWithFlightRecorderOptions() throws Exception { 95 System.out.println("testWithFlightRecorderOptions"); 96 String flightRecorderOptions = FLIGHT_RECORDER_OPTIONS + "=maxchunksize=8m"; 97 String recording1 = START_FLIGHT_RECORDING + "=filename=recording1.jfr"; 98 String recording2 = START_FLIGHT_RECORDING + "=name=myrecording,filename=recording2.jfr"; 99 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, flightRecorderOptions, recording1, recording2, MainClass.class.getName()); 100 test(pb, "Started recording 1", "Started recording 2"); 101 } 102 103 public static void main(String[] args) throws Exception { 104 testDefault(); 105 testColonDelimited(); 106 testMixed(); 107 testWithFlightRecorderOptions(); 108 } 109 }