1 /*
   2  * Copyright (c) 2020, Red Hat, Inc. 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 
  25 /*
  26  * @test TestModeUnlock
  27  * @summary Test that Shenandoah modes are unlocked properly
  28  * @key gc
  29  * @library /testlibrary
  30  * @run driver TestModeUnlock
  31  */
  32 
  33 import com.oracle.java.testlibrary.*;
  34 
  35 public class TestModeUnlock {
  36 
  37     enum Mode {
  38         PRODUCT,
  39         DIAGNOSTIC,
  40         EXPERIMENTAL,
  41     }
  42 
  43     public static void main(String[] args) throws Exception {
  44         testWith("-XX:ShenandoahGCMode=satb",    Mode.PRODUCT);
  45         testWith("-XX:ShenandoahGCMode=iu",      Mode.EXPERIMENTAL);
  46         testWith("-XX:ShenandoahGCMode=passive", Mode.DIAGNOSTIC);
  47     }
  48 
  49     private static void testWith(String h, Mode mode) throws Exception {
  50         if (false) { // When ShenandoahGC is experimental flag, this makes no sense to test
  51             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  52                     "-Xmx128m",
  53                     "-XX:-UnlockDiagnosticVMOptions",
  54                     "-XX:-UnlockExperimentalVMOptions",
  55                     "-XX:+UseShenandoahGC",
  56                     h,
  57                     "-version"
  58             );
  59             OutputAnalyzer output = new OutputAnalyzer(pb.start());
  60             switch (mode) {
  61                 case PRODUCT:
  62                     output.shouldHaveExitValue(0);
  63                     break;
  64                 case DIAGNOSTIC:
  65                 case EXPERIMENTAL:
  66                     output.shouldHaveExitValue(1);
  67                     break;
  68             }
  69         }
  70 
  71         if (false) { // When ShenandoahGC is experimental flag, this makes no sense to test
  72             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  73                     "-Xmx128m",
  74                     "-XX:+UnlockDiagnosticVMOptions",
  75                     "-XX:-UnlockExperimentalVMOptions",
  76                     "-XX:+UseShenandoahGC",
  77                     h,
  78                     "-version"
  79             );
  80             OutputAnalyzer output = new OutputAnalyzer(pb.start());
  81             switch (mode) {
  82                 case PRODUCT:
  83                 case DIAGNOSTIC:
  84                     output.shouldHaveExitValue(0);
  85                     break;
  86                 case EXPERIMENTAL:
  87                     output.shouldHaveExitValue(1);
  88                     break;
  89             }
  90         }
  91 
  92         {
  93             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  94                     "-Xmx128m",
  95                     "-XX:-UnlockDiagnosticVMOptions",
  96                     "-XX:+UnlockExperimentalVMOptions",
  97                     "-XX:+UseShenandoahGC",
  98                     h,
  99                     "-version"
 100             );
 101             OutputAnalyzer output = new OutputAnalyzer(pb.start());
 102             switch (mode) {
 103                 case PRODUCT:
 104                 case EXPERIMENTAL:
 105                     output.shouldHaveExitValue(0);
 106                     break;
 107                 case DIAGNOSTIC:
 108                     output.shouldHaveExitValue(1);
 109                     break;
 110             }
 111         }
 112     }
 113 
 114 }