1 /*
   2  * Copyright (c) 2012, 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 /**
  25  * @test
  26  * @bug 4894330 4810347 6277269
  27  * @compile -XDignore.symbol.file ChangeDataModel.java
  28  * @run main ChangeDataModel
  29  * @summary Verify -d32 and -d64 options are accepted(rejected) on all platforms
  30  * @author Joseph D. Darcy, ksrini
  31  */
  32 import java.io.File;
  33 
  34 public class ChangeDataModel extends TestHelper {
  35     private static final File TestJar      = new File("test" + JAR_FILE_EXT);
  36     private static final String OPT_PREFIX = "ARCH_OPT:";
  37 
  38     public static void main(String... args) throws Exception {
  39         String[] code = {
  40             "   public static void main(String argv[]) {",
  41             "      System.out.println(\"" + OPT_PREFIX + "-d\" + System.getProperty(\"sun.arch.data.model\", \"none\"));",
  42             "   }",
  43         };
  44         createJar(TestJar, code);
  45 
  46         // verify if data model flag for default data model is accepted
  47         if (is32Bit) {
  48             checkAcceptance(javaCmd, "-d32");
  49         } else if (is64Bit) {
  50             checkAcceptance(javaCmd, "-d64");
  51         } else {
  52             throw new Error("unsupported data model");
  53         }
  54 
  55         // Negative tests: ensure that non-dual mode systems reject the
  56         // complementary (other) data model
  57         if (is32Bit) {
  58             checkRejection(javaCmd, "-d64");
  59         } else if (is64Bit) {
  60             checkRejection(javaCmd, "-d32");
  61         } else {
  62             throw new Error("unsupported data model");
  63         }
  64     }
  65 
  66     static void checkAcceptance(String cmd, String dmodel) {
  67         TestResult tr = doExec(cmd, dmodel, "-jar", TestJar.getAbsolutePath());
  68         if (!tr.contains(OPT_PREFIX + dmodel)) {
  69             System.out.println(tr);
  70             String message = "Data model flag " + dmodel +
  71                     " not accepted or had improper effect.";
  72             throw new RuntimeException(message);
  73         }
  74     }
  75 
  76     static void checkRejection(String cmd, String dmodel) {
  77         TestResult tr = doExec(cmd, dmodel, "-jar", TestJar.getAbsolutePath());
  78         if (tr.contains(OPT_PREFIX + dmodel)) {
  79             System.out.println(tr);
  80             String message = "Data model flag " + dmodel + " was accepted.";
  81             throw new RuntimeException(message);
  82         }
  83     }
  84 }