Path: blob/master/test/jdk/tools/launcher/JliLaunchTest.java
41144 views
/*1* Copyright (c) 2016, 2020, 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*22*/2324/**25* @test26* @bug 8213362 823822527* @comment Test JLI_Launch for tools distributed outside JDK28* @library /test/lib29* @run main/native JliLaunchTest30*/3132import java.util.Map;33import jdk.test.lib.Utils;34import jdk.test.lib.Platform;35import jdk.test.lib.process.OutputAnalyzer;3637import java.io.File;38import java.io.IOException;39import java.nio.file.Files;40import java.nio.file.Path;41import java.nio.file.Paths;4243public class JliLaunchTest {44public static void main(String[] args) throws IOException {45Path launcher = Paths.get(System.getProperty("test.nativepath"),46"JliLaunchTest" + (Platform.isWindows() ? ".exe" : ""));47System.out.println("Launcher = " + launcher + (Files.exists(launcher) ? " (exists)" : " (not exists)"));48ProcessBuilder pb = new ProcessBuilder(launcher.toString(), "--version");49Map<String, String> env = pb.environment();50// On windows, the DLL should be in JDK/bin, else in JDK/lib.51String libdir = Paths.get(Utils.TEST_JDK).resolve(Platform.isWindows() ? "bin" : "lib")52.toAbsolutePath().toString();53String pathEnvVar = Platform.sharedLibraryPathVariableName();54env.compute(pathEnvVar, (k, v) -> (v == null) ? libdir : libdir + File.pathSeparator + v);5556OutputAnalyzer outputf = new OutputAnalyzer(pb.start());57outputf.shouldHaveExitValue(0);5859if (Platform.isOSX()) {60Path javaHome = Paths.get(Utils.TEST_JDK);61if (javaHome.getFileName().toString().equals("Home")) {62// To exercise this test path you need to make sure the JDK under test is63// the MacOS bundle and not the simple jdk image. This can currently be64// achieved by running something like this (from the build output dir):65// $ make test-only TEST=test/jdk/tools/launcher/JliLaunchTest.java \66// JDK_IMAGE_DIR=$PWD/images/jdk-bundle/jdk-15.jdk/Contents/Home67System.out.println("MacOS bundle distribution detected, also testing Contents/MacOS/libjli.dylib");68String macosDir = javaHome.getParent().resolve("MacOS").toString();69ProcessBuilder pb2 = new ProcessBuilder(launcher.toString(), "--version");70env = pb2.environment();71env.compute(pathEnvVar, (k, v) -> (v == null) ? macosDir : macosDir + File.pathSeparator + v);7273OutputAnalyzer output2 = new OutputAnalyzer(pb2.start());74output2.shouldHaveExitValue(0);75} else {76System.out.println("Not a MacOS bundle distribution, not testing Contents/MacOS/libjli.dylib");77}78}79}80}818283