Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/tools/launcher/Test7029048.java
38833 views
/*1* Copyright (c) 2011, 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 702904826* @summary Checks for LD_LIBRARY_PATH on *nixes27* @compile -XDignore.symbol.file ExecutionEnvironment.java Test7029048.java28* @run main Test702904829*/3031/*32* 7029048: test for LD_LIBRARY_PATH set to different paths which may or33* may not contain a libjvm.so, but we test to ensure that the launcher34* behaves correctly in all cases.35*/36import java.io.File;37import java.io.IOException;38import java.nio.file.Files;39import java.util.ArrayList;40import java.util.HashMap;41import java.util.List;42import java.util.Map;4344public class Test7029048 extends TestHelper {4546static int passes = 0;47static int errors = 0;4849private static final String LIBJVM = ExecutionEnvironment.LIBJVM;50private static final String LD_LIBRARY_PATH =51ExecutionEnvironment.LD_LIBRARY_PATH;52private static final String LD_LIBRARY_PATH_64 =53ExecutionEnvironment.LD_LIBRARY_PATH_64;5455private static final File libDir =56new File(System.getProperty("sun.boot.library.path"));57private static final File srcServerDir = new File(libDir, "server");58private static final File srcLibjvmSo = new File(srcServerDir, LIBJVM);5960private static final File dstLibDir = new File("lib");61private static final File dstLibArchDir =62new File(dstLibDir, getJreArch());6364private static final File dstServerDir = new File(dstLibArchDir, "server");65private static final File dstServerLibjvm = new File(dstServerDir, LIBJVM);6667private static final File dstClientDir = new File(dstLibArchDir, "client");68private static final File dstClientLibjvm = new File(dstClientDir, LIBJVM);6970private static final Map<String, String> env = new HashMap<>();717273static String getValue(String name, List<String> in) {74for (String x : in) {75String[] s = x.split("=");76if (name.equals(s[0].trim())) {77return s[1].trim();78}79}80return null;81}8283static void run(Map<String, String> env,84int nLLPComponents, String caseID) {85env.put(ExecutionEnvironment.JLDEBUG_KEY, "true");86List<String> cmdsList = new ArrayList<>();87cmdsList.add(javaCmd);88cmdsList.add("-server");89cmdsList.add("-jar");90cmdsList.add(ExecutionEnvironment.testJarFile.getAbsolutePath());91String[] cmds = new String[cmdsList.size()];92TestResult tr = doExec(env, cmdsList.toArray(cmds));93System.out.println(tr);94analyze(tr, nLLPComponents, caseID);95}9697static void analyze(TestResult tr, int nLLPComponents, String caseID) {98String envValue = getValue(LD_LIBRARY_PATH, tr.testOutput);99/*100* the envValue can never be null, since the test code should always101* print a "null" string.102*/103if (envValue == null) {104System.out.println(tr);105throw new RuntimeException("NPE, likely a program crash ??");106}107String values[] = envValue.split(File.pathSeparator);108if (values.length == nLLPComponents) {109System.out.println(caseID + " :OK");110passes++;111} else {112System.out.println("FAIL: test7029048, " + caseID);113System.out.println(" expected " + nLLPComponents114+ " but got " + values.length);115System.out.println(envValue);116System.out.println(tr);117errors++;118}119}120121/*122* A crucial piece, specifies what we should expect, given the conditions.123* That is for a given enum type, the value indicates how many absolute124* environment variables that can be expected. This value is used to base125* the actual expected values by adding the set environment variable usually126* it is 1, but it could be more if the test wishes to set more paths in127* the future.128*/129private static enum LLP_VAR {130LLP_SET_NON_EXISTENT_PATH(0), // env set, but the path does not exist131LLP_SET_EMPTY_PATH(0), // env set, with a path but no libjvm.so132LLP_SET_WITH_JVM(3); // env set, with a libjvm.so133private final int value;134LLP_VAR(int i) {135this.value = i;136}137}138139/*140* test for 7029048141*/142static void test7029048() throws IOException {143String desc = null;144for (LLP_VAR v : LLP_VAR.values()) {145switch (v) {146case LLP_SET_WITH_JVM:147// copy the files into the directory structures148copyFile(srcLibjvmSo, dstServerLibjvm);149// does not matter if it is client or a server150copyFile(srcLibjvmSo, dstClientLibjvm);151desc = "LD_LIBRARY_PATH should be set";152break;153case LLP_SET_EMPTY_PATH:154if (!dstClientDir.exists()) {155Files.createDirectories(dstClientDir.toPath());156} else {157Files.deleteIfExists(dstClientLibjvm.toPath());158}159160if (!dstServerDir.exists()) {161Files.createDirectories(dstServerDir.toPath());162} else {163Files.deleteIfExists(dstServerLibjvm.toPath());164}165166desc = "LD_LIBRARY_PATH should not be set";167break;168case LLP_SET_NON_EXISTENT_PATH:169if (dstLibDir.exists()) {170recursiveDelete(dstLibDir);171}172desc = "LD_LIBRARY_PATH should not be set";173break;174default:175throw new RuntimeException("unknown case");176}177178/*179* Case 1: set the server path180*/181env.clear();182env.put(LD_LIBRARY_PATH, dstServerDir.getAbsolutePath());183run(env, v.value + 1, "Case 1: " + desc);184185/*186* Case 2: repeat with client path187*/188env.clear();189env.put(LD_LIBRARY_PATH, dstClientDir.getAbsolutePath());190run(env, v.value + 1, "Case 2: " + desc);191192if (isSolaris) {193/*194* Case 3: set the appropriate LLP_XX flag,195* java64 -d64, LLP_64 is relevant, LLP_32 is ignored196*/197env.clear();198env.put(LD_LIBRARY_PATH_64, dstServerDir.getAbsolutePath());199run(env, v.value + 1, "Case 3: " + desc);200}201}202return;203}204205public static void main(String... args) throws Exception {206if (TestHelper.isWindows || TestHelper.isMacOSX) {207System.out.println("Note: applicable on neither Windows nor MacOSX");208return;209}210if (!TestHelper.haveServerVM) {211System.out.println("Note: test relies on server vm, not found, exiting");212return;213}214// create our test jar first215ExecutionEnvironment.createTestJar();216217// run the tests218test7029048();219if (errors > 0) {220throw new Exception("Test7029048: FAIL: with "221+ errors + " errors and passes " + passes);222} else if (isSolaris && passes < 9) {223throw new Exception("Test7029048: FAIL: " +224"all tests did not run, expected " + 9 + " got " + passes);225} else if (isLinux && passes < 6) {226throw new Exception("Test7029048: FAIL: " +227"all tests did not run, expected " + 6 + " got " + passes);228} else {229System.out.println("Test7029048: PASS " + passes);230}231}232}233234235