1 /*
   2  * Copyright (c) 2018, 2019 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.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 package com.sun.hotspot.tools.compiler;
  25 
  26 import java.util.Arrays;
  27 import java.util.Collection;
  28 import org.junit.BeforeClass;
  29 import org.junit.Test;
  30 import org.junit.runner.RunWith;
  31 import org.junit.runners.Parameterized;
  32 import org.junit.runners.Parameterized.Parameters;
  33 
  34 @RunWith(value = Parameterized.class)
  35 public class TestLogCompilation {
  36 
  37     String logFile;
  38 
  39     static final String setupArgsTiered[] = {
  40         "java",
  41         "-XX:+UnlockDiagnosticVMOptions",
  42         "-XX:+LogCompilation",
  43         "-XX:LogFile=target/tiered_short.log",
  44         "-version"
  45     };
  46 
  47     static final String setupArgsNoTiered[] = {
  48         "java",
  49         "-XX:-TieredCompilation",
  50         "-XX:+UnlockDiagnosticVMOptions",
  51         "-XX:+LogCompilation",
  52         "-XX:LogFile=target/no_tiered_short.log",
  53         "-version"
  54     };
  55 
  56     static final String allSetupArgs[][] = {
  57         setupArgsTiered,
  58         setupArgsNoTiered
  59     };
  60 
  61     @Parameters
  62     public static Collection data() {
  63         Object[][] data = new Object[][]{
  64             // Take care these match whats created in the setup method
  65             {"./target/tiered_short.log"},
  66             {"./target/no_tiered_short.log"}
  67         };
  68         return Arrays.asList(data);
  69     }
  70 
  71     @BeforeClass
  72     public static void setup() {
  73         try {
  74             for (String[] setupArgs : allSetupArgs) {
  75                 Process p = Runtime.getRuntime().exec(setupArgs);
  76                 p.waitFor();
  77                 assert p.exitValue() == 0 : "setup failed on " + setupArgs;
  78             }
  79         } catch (Exception e) {
  80             System.out.println(e + ": exec failed:" + setupArgsNoTiered[0]);
  81         }
  82     }
  83 
  84     public TestLogCompilation(String logFile) {
  85         this.logFile = logFile;
  86     }
  87 
  88     @Test
  89     public void testDashi() throws Exception {
  90         String[] args = {"-i",
  91             logFile
  92         };
  93 
  94         LogCompilation.main(args);
  95     }
  96 
  97     @Test
  98     public void testDashiDasht() throws Exception {
  99         String[] args = {"-i",
 100             "-t",
 101             logFile
 102         };
 103 
 104         LogCompilation.main(args);
 105     }
 106 
 107     @Test
 108     public void testDefault() throws Exception {
 109         String[] args = {
 110             logFile
 111         };
 112 
 113         LogCompilation.main(args);
 114     }
 115 
 116     @Test
 117     public void testDashS() throws Exception {
 118         String[] args = {"-S",
 119             logFile
 120         };
 121 
 122         LogCompilation.main(args);
 123     }
 124 
 125     @Test
 126     public void testDashU() throws Exception {
 127         String[] args = {"-U",
 128             logFile
 129         };
 130 
 131         LogCompilation.main(args);
 132     }
 133 
 134     @Test
 135     public void testDashe() throws Exception {
 136         String[] args = {"-e",
 137             logFile
 138         };
 139 
 140         LogCompilation.main(args);
 141     }
 142 
 143     @Test
 144     public void testDashn() throws Exception {
 145         String[] args = {"-n",
 146             logFile
 147         };
 148 
 149         LogCompilation.main(args);
 150     }
 151 }