3986N/A/*
4651N/A * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
3986N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3986N/A *
3986N/A * This code is free software; you can redistribute it and/or modify it
3986N/A * under the terms of the GNU General Public License version 2 only, as
3986N/A * published by the Free Software Foundation.
3986N/A *
3986N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3986N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3986N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3986N/A * version 2 for more details (a copy is included in the LICENSE file that
3986N/A * accompanied this code).
3986N/A *
3986N/A * You should have received a copy of the GNU General Public License version
3986N/A * 2 along with this work; if not, write to the Free Software Foundation,
3986N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3986N/A *
3986N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3986N/A * or visit www.oracle.com if you need additional information or have any
3986N/A * questions.
3986N/A */
3986N/A
3986N/A/*
3986N/A * @test
3986N/A * @bug 7029048
3986N/A * @summary Checks for LD_LIBRARY_PATH on *nixes
3986N/A * @compile -XDignore.symbol.file ExecutionEnvironment.java TestHelper.java Test7029048.java
3986N/A * @run main Test7029048
3986N/A */
3986N/A
3986N/A/*
3986N/A * 7029048: test for LD_LIBRARY_PATH set to different paths pointing which may
3986N/A * contain a libjvm.so and may not, but we test to ensure that the launcher
3986N/A * behaves correctly in all cases.
3986N/A */
3986N/Aimport java.io.File;
3986N/Aimport java.io.IOException;
3986N/Aimport java.nio.file.Files;
3986N/Aimport java.util.ArrayList;
3986N/Aimport java.util.HashMap;
3986N/Aimport java.util.List;
3986N/Aimport java.util.Map;
3986N/A
3986N/Apublic class Test7029048 {
3986N/A
3986N/A static int passes = 0;
3986N/A static int errors = 0;
3986N/A
3986N/A private static final String LIBJVM = ExecutionEnvironment.LIBJVM;
3986N/A private static final String LD_LIBRARY_PATH =
3986N/A ExecutionEnvironment.LD_LIBRARY_PATH;
3986N/A private static final String LD_LIBRARY_PATH_32 =
3986N/A ExecutionEnvironment.LD_LIBRARY_PATH_32;
3986N/A private static final String LD_LIBRARY_PATH_64 =
3986N/A ExecutionEnvironment.LD_LIBRARY_PATH_64;
3986N/A
3986N/A private static final File libDir =
3986N/A new File(System.getProperty("sun.boot.library.path"));
3986N/A private static final File srcServerDir = new File(libDir, "server");
3986N/A private static final File srcLibjvmSo = new File(srcServerDir, LIBJVM);
3986N/A
3986N/A private static final File dstLibDir = new File("lib");
3986N/A private static final File dstLibArchDir =
3986N/A new File(dstLibDir, TestHelper.getJreArch());
3986N/A
3986N/A private static final File dstServerDir = new File(dstLibArchDir, "server");
3986N/A private static final File dstServerLibjvm = new File(dstServerDir, LIBJVM);
3986N/A
3986N/A private static final File dstClientDir = new File(dstLibArchDir, "client");
3986N/A private static final File dstClientLibjvm = new File(dstClientDir, LIBJVM);
3986N/A
3986N/A // used primarily to test the solaris variants in dual mode
3986N/A private static final File dstOtherArchDir;
3986N/A private static final File dstOtherServerDir;
3986N/A private static final File dstOtherServerLibjvm;
3986N/A
3986N/A private static final Map<String, String> env = new HashMap<>();
3986N/A
3986N/A static {
3986N/A if (TestHelper.isDualMode) {
3986N/A dstOtherArchDir = new File(dstLibDir, TestHelper.getComplementaryJreArch());
3986N/A dstOtherServerDir = new File(dstOtherArchDir, "server");
3986N/A dstOtherServerLibjvm = new File(dstOtherServerDir, LIBJVM);
3986N/A } else {
3986N/A dstOtherArchDir = null;
3986N/A dstOtherServerDir = null;
3986N/A dstOtherServerLibjvm = null;
3986N/A }
3986N/A }
3986N/A
3986N/A static String getValue(String name, List<String> in) {
3986N/A for (String x : in) {
3986N/A String[] s = x.split("=");
3986N/A if (name.equals(s[0].trim())) {
3986N/A return s[1].trim();
3986N/A }
3986N/A }
3986N/A return null;
3986N/A }
3986N/A
3986N/A static void run(boolean want32, String dflag, Map<String, String> env,
3986N/A int nLLPComponents, String caseID) {
3986N/A final boolean want64 = want32 == false;
3986N/A env.put(ExecutionEnvironment.JLDEBUG_KEY, "true");
3986N/A List<String> cmdsList = new ArrayList<>();
3986N/A
3986N/A // only for a dual-mode system
3986N/A if (want64 && TestHelper.isDualMode) {
3986N/A cmdsList.add(TestHelper.java64Cmd);
3986N/A } else {
3986N/A cmdsList.add(TestHelper.javaCmd); // a 32-bit java command for all
3986N/A }
3986N/A
3986N/A /*
3986N/A * empty or null strings can confuse the ProcessBuilder. A null flag
3986N/A * indicates that the appropriate data model is enforced on the chosen
3986N/A * launcher variant.
3986N/A */
3986N/A
3986N/A if (dflag != null) {
3986N/A cmdsList.add(dflag);
3986N/A } else {
3986N/A cmdsList.add(want32 ? "-d32" : "-d64");
3986N/A }
3986N/A cmdsList.add("-server");
3986N/A cmdsList.add("-jar");
3986N/A cmdsList.add(ExecutionEnvironment.testJarFile.getAbsolutePath());
3986N/A String[] cmds = new String[cmdsList.size()];
3986N/A TestHelper.TestResult tr = TestHelper.doExec(env, cmdsList.toArray(cmds));
3986N/A analyze(tr, nLLPComponents, caseID);
3986N/A }
3986N/A
3986N/A // no cross launch, ie. no change to the data model.
3986N/A static void run(Map<String, String> env, int nLLPComponents, String caseID)
3986N/A throws IOException {
3986N/A boolean want32 = TestHelper.is32Bit;
3986N/A run(want32, null, env, nLLPComponents, caseID);
3986N/A }
3986N/A
3986N/A static void analyze(TestHelper.TestResult tr, int nLLPComponents, String caseID) {
3986N/A String envValue = getValue(LD_LIBRARY_PATH, tr.testOutput);
3986N/A /*
3986N/A * the envValue can never be null, since the test code should always
3986N/A * print a "null" string.
3986N/A */
3986N/A if (envValue == null) {
3986N/A System.out.println(tr);
3986N/A throw new RuntimeException("NPE, likely a program crash ??");
3986N/A }
3986N/A String values[] = envValue.split(File.pathSeparator);
3986N/A if (values.length == nLLPComponents) {
3986N/A System.out.println(caseID + " :OK");
3986N/A passes++;
3986N/A } else {
3986N/A System.out.println("FAIL: test7029048, " + caseID);
3986N/A System.out.println(" expected " + nLLPComponents
3986N/A + " but got " + values.length);
3986N/A System.out.println(envValue);
3986N/A System.out.println(tr);
3986N/A errors++;
3986N/A }
3986N/A }
3986N/A
3986N/A /*
3986N/A * A crucial piece, specifies what we should expect, given the conditions.
3986N/A * That is for a given enum type, the value indicates how many absolute
3986N/A * environment variables that can be expected. This value is used to base
3986N/A * the actual expected values by adding the set environment variable usually
3986N/A * it is 1, but it could be more if the test wishes to set more paths in
3986N/A * the future.
3986N/A */
3986N/A private static enum LLP_VAR {
3986N/A LLP_SET_NON_EXISTENT_PATH(0), // env set, but the path does not exist
3986N/A LLP_SET_EMPTY_PATH(0), // env set, with a path but no libjvm.so
3986N/A LLP_SET_WITH_JVM(3); // env set, with a libjvm.so
3986N/A private final int value;
3986N/A LLP_VAR(int i) {
3986N/A this.value = i;
3986N/A }
3986N/A }
3986N/A
3986N/A /*
3986N/A * test for 7029048
3986N/A */
3986N/A static void test7029048() throws IOException {
3986N/A String desc = null;
3986N/A for (LLP_VAR v : LLP_VAR.values()) {
3986N/A switch (v) {
3986N/A case LLP_SET_WITH_JVM:
3986N/A // copy the files into the directory structures
3986N/A TestHelper.copyFile(srcLibjvmSo, dstServerLibjvm);
3986N/A // does not matter if it is client or a server
3986N/A TestHelper.copyFile(srcLibjvmSo, dstClientLibjvm);
3986N/A // does not matter if the arch do not match either
3986N/A if (TestHelper.isDualMode) {
3986N/A TestHelper.copyFile(srcLibjvmSo, dstOtherServerLibjvm);
3986N/A }
3986N/A desc = "LD_LIBRARY_PATH should be set";
3986N/A break;
3986N/A case LLP_SET_EMPTY_PATH:
3986N/A if (!dstClientDir.exists()) {
3986N/A Files.createDirectories(dstClientDir.toPath());
3986N/A } else {
3986N/A Files.deleteIfExists(dstClientLibjvm.toPath());
3986N/A }
3986N/A
3986N/A if (!dstServerDir.exists()) {
3986N/A Files.createDirectories(dstServerDir.toPath());
3986N/A } else {
3986N/A Files.deleteIfExists(dstServerLibjvm.toPath());
3986N/A }
3986N/A
3986N/A if (TestHelper.isDualMode) {
3986N/A if (!dstOtherServerDir.exists()) {
3986N/A Files.createDirectories(dstOtherServerDir.toPath());
3986N/A } else {
3986N/A Files.deleteIfExists(dstOtherServerLibjvm.toPath());
3986N/A }
3986N/A }
3986N/A
3986N/A desc = "LD_LIBRARY_PATH should not be set";
3986N/A break;
3986N/A case LLP_SET_NON_EXISTENT_PATH:
3986N/A if (dstLibDir.exists()) {
3986N/A TestHelper.recursiveDelete(dstLibDir);
3986N/A }
3986N/A desc = "LD_LIBRARY_PATH should not be set";
3986N/A break;
3986N/A default:
3986N/A throw new RuntimeException("unknown case");
3986N/A }
3986N/A
3986N/A /*
3986N/A * Case 1: set the server path
3986N/A */
3986N/A env.clear();
3986N/A env.put(LD_LIBRARY_PATH, dstServerDir.getAbsolutePath());
3986N/A run(env, v.value + 1, "Case 1: " + desc);
3986N/A
3986N/A /*
3986N/A * Case 2: repeat with client path
3986N/A */
3986N/A env.clear();
3986N/A env.put(LD_LIBRARY_PATH, dstClientDir.getAbsolutePath());
3986N/A run(env, v.value + 1, "Case 2: " + desc);
3986N/A
3986N/A if (!TestHelper.isDualMode) {
3986N/A continue; // nothing more to do for Linux
3986N/A }
3986N/A
3986N/A // Tests applicable only to solaris.
3986N/A
3986N/A // initialize test variables for dual mode operations
3986N/A final File dst32ServerDir = TestHelper.is32Bit
3986N/A ? dstServerDir
3986N/A : dstOtherServerDir;
3986N/A
3986N/A final File dst64ServerDir = TestHelper.is64Bit
3986N/A ? dstServerDir
3986N/A : dstOtherServerDir;
3986N/A
3986N/A /*
3986N/A * Case 3: set the appropriate LLP_XX flag,
3986N/A * java32 -d32, LLP_32 is relevant, LLP_64 is ignored
3986N/A * java64 -d64, LLP_64 is relevant, LLP_32 is ignored
3986N/A */
3986N/A env.clear();
3986N/A env.put(LD_LIBRARY_PATH_32, dst32ServerDir.getAbsolutePath());
3986N/A env.put(LD_LIBRARY_PATH_64, dst64ServerDir.getAbsolutePath());
3986N/A run(TestHelper.is32Bit, null, env, v.value + 1, "Case 3: " + desc);
3986N/A
3986N/A /*
3986N/A * Case 4: we are in dual mode environment, running 64-bit then
3986N/A * we have the following scenarios:
3986N/A * java32 -d64, LLP_64 is relevant, LLP_32 is ignored
3986N/A * java64 -d32, LLP_32 is relevant, LLP_64 is ignored
3986N/A */
3986N/A if (TestHelper.dualModePresent()) {
3986N/A run(true, "-d64", env, v.value + 1, "Case 4A: " + desc);
3986N/A run(false,"-d32", env, v.value + 1, "Case 4B: " + desc);
3986N/A }
3986N/A }
3986N/A return;
3986N/A }
3986N/A
3986N/A public static void main(String... args) throws Exception {
4651N/A if (TestHelper.isWindows || TestHelper.isMacOSX) {
4680N/A System.out.println("Note: applicable on neither Windows nor MacOSX");
3986N/A return;
3986N/A }
3986N/A // create our test jar first
3986N/A ExecutionEnvironment.createTestJar();
3986N/A
3986N/A // run the tests
3986N/A test7029048();
3986N/A if (errors > 0) {
3986N/A throw new Exception("Test7029048: FAIL: with "
3986N/A + errors + " errors and passes " + passes);
3986N/A } else if (TestHelper.dualModePresent() && passes < 15) {
3986N/A throw new Exception("Test7029048: FAIL: " +
3986N/A "all tests did not run, expected " + 15 + " got " + passes);
3986N/A } else if (TestHelper.isSolaris && passes < 9) {
3986N/A throw new Exception("Test7029048: FAIL: " +
3986N/A "all tests did not run, expected " + 9 + " got " + passes);
3986N/A } else if (TestHelper.isLinux && passes < 6) {
3986N/A throw new Exception("Test7029048: FAIL: " +
3986N/A "all tests did not run, expected " + 6 + " got " + passes);
3986N/A } else {
3986N/A System.out.println("Test7029048: PASS " + passes);
3986N/A }
3986N/A }
3986N/A}