1 /*
   2  * Copyright (c) 2013, 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 import com.oracle.java.testlibrary.*;
  25 
  26 /*
  27  * @test
  28  * @bug     8006997
  29  * @summary ContendedPaddingWidth should be range-checked
  30  *
  31  * @library /testlibrary
  32  * @build com.oracle.java.testlibrary.*
  33  * @run main Options
  34  */
  35 public class Options {
  36 
  37     public static void main(String[] args) throws Exception {
  38         ProcessBuilder pb;
  39         OutputAnalyzer output;
  40 
  41         pb = ProcessTools.createJavaProcessBuilder("-XX:ContendedPaddingWidth=-128", "-version");
  42         output = new OutputAnalyzer(pb.start());
  43         output.shouldContain("ContendedPaddingWidth");
  44         output.shouldContain("must be in between");
  45         output.shouldHaveExitValue(1);
  46 
  47         pb = ProcessTools.createJavaProcessBuilder("-XX:ContendedPaddingWidth=-8", "-version");
  48         output = new OutputAnalyzer(pb.start());
  49         output.shouldContain("ContendedPaddingWidth");
  50         output.shouldContain("must be in between");
  51         output.shouldHaveExitValue(1);
  52 
  53         pb = ProcessTools.createJavaProcessBuilder("-XX:ContendedPaddingWidth=-1", "-version");
  54         output = new OutputAnalyzer(pb.start());
  55         output.shouldContain("ContendedPaddingWidth");
  56         output.shouldContain("must be in between");
  57         output.shouldContain("must be a multiple of 8");
  58         output.shouldHaveExitValue(1);
  59 
  60         pb = ProcessTools.createJavaProcessBuilder("-XX:ContendedPaddingWidth=0", "-version");
  61         output = new OutputAnalyzer(pb.start());
  62         output.shouldHaveExitValue(0);
  63 
  64         pb = ProcessTools.createJavaProcessBuilder("-XX:ContendedPaddingWidth=1", "-version");
  65         output = new OutputAnalyzer(pb.start());
  66         output.shouldContain("ContendedPaddingWidth");
  67         output.shouldContain("must be a multiple of 8");
  68         output.shouldHaveExitValue(1);
  69 
  70         pb = ProcessTools.createJavaProcessBuilder("-XX:ContendedPaddingWidth=8", "-version");
  71         output = new OutputAnalyzer(pb.start());
  72         output.shouldHaveExitValue(0);
  73 
  74         pb = ProcessTools.createJavaProcessBuilder("-XX:ContendedPaddingWidth=8184", "-version"); // 8192-8 = 8184
  75         output = new OutputAnalyzer(pb.start());
  76         output.shouldHaveExitValue(0);
  77 
  78         pb = ProcessTools.createJavaProcessBuilder("-XX:ContendedPaddingWidth=8191", "-version");
  79         output = new OutputAnalyzer(pb.start());
  80         output.shouldContain("ContendedPaddingWidth");
  81         output.shouldContain("must be a multiple of 8");
  82         output.shouldHaveExitValue(1);
  83 
  84         pb = ProcessTools.createJavaProcessBuilder("-XX:ContendedPaddingWidth=8192", "-version");
  85         output = new OutputAnalyzer(pb.start());
  86         output.shouldHaveExitValue(0);
  87 
  88         pb = ProcessTools.createJavaProcessBuilder("-XX:ContendedPaddingWidth=8193", "-version");
  89         output = new OutputAnalyzer(pb.start());
  90         output.shouldContain("ContendedPaddingWidth");
  91         output.shouldContain("must be in between");
  92         output.shouldContain("must be a multiple of 8");
  93         output.shouldHaveExitValue(1);
  94 
  95         pb = ProcessTools.createJavaProcessBuilder("-XX:ContendedPaddingWidth=8200", "-version"); // 8192+8 = 8200
  96         output = new OutputAnalyzer(pb.start());
  97         output.shouldContain("ContendedPaddingWidth");
  98         output.shouldContain("must be in between");
  99         output.shouldHaveExitValue(1);
 100 
 101    }
 102 
 103 }
 104