Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/tools/launcher/ChangeDataModel.java
38833 views
/*1* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 4894330 4810347 6277269 802938826* @compile -XDignore.symbol.file ChangeDataModel.java27* @run main ChangeDataModel28* @summary Verify -d32 and -d64 options are accepted(rejected) on all platforms29* @author Joseph D. Darcy, ksrini30*/31import java.io.File;32import java.util.ArrayList;33import java.util.List;3435public class ChangeDataModel extends TestHelper {36private static final File TestJar = new File("test" + JAR_FILE_EXT);37private static final String OptionName = "Args";38private static final File TestOptionJar = new File(OptionName + JAR_FILE_EXT);39private static final String OPT_PREFIX = "ARCH_OPT:";4041static void createTestJar() throws Exception {42String[] code = {43" public static void main(String argv[]) {",44" System.out.println(\"" + OPT_PREFIX + "-d\" + System.getProperty(\"sun.arch.data.model\", \"none\"));",45" }",};46createJar(TestJar, code);47}48public static void main(String... args) throws Exception {49createTestJar();50createOptionsJar();5152// verify if data model flag for default data model is accepted, also53// verify if the complimentary data model is rejected.54if (is32Bit) {55checkAcceptance(javaCmd, "-d32");56checkRejection(javaCmd, "-d64");57checkOption(javaCmd, "-d64");58} else if (is64Bit) {59checkAcceptance(javaCmd, "-d64");60checkRejection(javaCmd, "-d32");61checkOption(javaCmd, "-d32");62} else {63throw new Error("unsupported data model");64}65}6667static void checkAcceptance(String cmd, String dmodel) {68TestResult tr = doExec(cmd, dmodel, "-jar", TestJar.getAbsolutePath());69if (!tr.contains(OPT_PREFIX + dmodel)) {70System.out.println(tr);71String message = "Data model flag " + dmodel +72" not accepted or had improper effect.";73throw new RuntimeException(message);74}75}7677static void checkRejection(String cmd, String dmodel) {78TestResult tr = doExec(cmd, dmodel, "-jar", TestJar.getAbsolutePath());79if (tr.contains(OPT_PREFIX + dmodel)) {80System.out.println(tr);81String message = "Data model flag " + dmodel + " was accepted.";82throw new RuntimeException(message);83}84}8586static void checkOption(String cmd, String dmodel) throws Exception {87TestResult tr = doExec(cmd, "-jar", TestOptionJar.getAbsolutePath(), dmodel);88verifyOption(tr, dmodel);8990tr = doExec(cmd, "-cp", ".", OptionName, dmodel);91verifyOption(tr, dmodel);92}9394static void verifyOption(TestResult tr, String dmodel) {95if (!tr.contains(OPT_PREFIX + dmodel)) {96System.out.println(tr);97String message = "app argument: " + dmodel + " not found.";98throw new RuntimeException(message);99}100if (!tr.isOK()) {101System.out.println(tr);102String message = "app argument: " + dmodel + " interpreted ?";103throw new RuntimeException(message);104}105}106107static void createOptionsJar() throws Exception {108List<String> code = new ArrayList<>();109code.add("public class Args {");110code.add(" public static void main(String argv[]) {");111code.add(" for (String x : argv)");112code.add(" System.out.println(\"" + OPT_PREFIX + "\" + x);");113code.add(" }");114code.add("}");115File optionsJava = new File(OptionName + JAVA_FILE_EXT);116createFile(optionsJava, code);117File optionsClass = new File(OptionName + CLASS_FILE_EXT);118119compile(optionsJava.getName());120createJar("cvfe",121TestOptionJar.getName(),122OptionName,123optionsClass.getName());124}125}126127128