mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 12:09:14 +00:00
8252532: use Utils.TEST_NATIVE_PATH instead of System.getProperty("test.nativepath")
Reviewed-by: dholmes, sspitsyn
This commit is contained in:
parent
de49337060
commit
4fe6a3da68
@ -45,7 +45,7 @@ public class GTestWrapper {
|
||||
public static void main(String[] args) throws Throwable {
|
||||
// gtestLauncher is located in <test_image>/hotspot/gtest/<vm_variant>/
|
||||
// nativePath points either to <test_image>/hotspot/jtreg/native or to <test_image>/hotspot/gtest
|
||||
Path nativePath = Paths.get(System.getProperty("test.nativepath"));
|
||||
Path nativePath = Paths.get(Utils.TEST_NATIVE_PATH);
|
||||
String jvmVariantDir = getJVMVariantSubDir();
|
||||
// let's assume it's <test_image>/hotspot/gtest
|
||||
Path path = nativePath.resolve(jvmVariantDir);
|
||||
|
||||
@ -22,10 +22,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.Duration;
|
||||
|
||||
import jdk.test.lib.Utils;
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
|
||||
@ -42,11 +39,9 @@ import sun.hotspot.WhiteBox;
|
||||
*/
|
||||
|
||||
public class HandshakeTransitionTest {
|
||||
|
||||
public static native void someTime(int ms);
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
String lib = System.getProperty("test.nativepath");
|
||||
WhiteBox wb = WhiteBox.getWhiteBox();
|
||||
Boolean useJVMCICompiler = wb.getBooleanVMFlag("UseJVMCICompiler");
|
||||
String useJVMCICompilerStr;
|
||||
@ -58,7 +53,7 @@ public class HandshakeTransitionTest {
|
||||
}
|
||||
ProcessBuilder pb =
|
||||
ProcessTools.createTestJvm(
|
||||
"-Djava.library.path=" + lib,
|
||||
"-Djava.library.path=" + Utils.TEST_NATIVE_PATH,
|
||||
"-XX:+SafepointALot",
|
||||
"-XX:+HandshakeALot",
|
||||
"-XX:GuaranteedSafepointInterval=20",
|
||||
@ -70,7 +65,6 @@ public class HandshakeTransitionTest {
|
||||
useJVMCICompilerStr,
|
||||
"HandshakeTransitionTest$Test");
|
||||
|
||||
|
||||
OutputAnalyzer output = ProcessTools.executeProcess(pb);
|
||||
output.reportDiagnosticSummary();
|
||||
output.shouldHaveExitValue(0);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -22,7 +22,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
/*
|
||||
* @test
|
||||
* @bug 8067744
|
||||
* @comment Test uses custom launcher that starts VM in primordial thread. This is
|
||||
@ -35,7 +35,6 @@
|
||||
|
||||
import jdk.test.lib.Platform;
|
||||
import jdk.test.lib.Utils;
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
|
||||
import java.io.File;
|
||||
@ -47,14 +46,14 @@ import java.util.Optional;
|
||||
|
||||
public class FPRegs {
|
||||
public static void main(String[] args) throws IOException {
|
||||
Path launcher = Paths.get(System.getProperty("test.nativepath"), "FPRegs" + (Platform.isWindows() ? ".exe" : ""));
|
||||
Path launcher = Paths.get(Utils.TEST_NATIVE_PATH, "FPRegs" + (Platform.isWindows() ? ".exe" : ""));
|
||||
System.out.println("Launcher = " + launcher + (Files.exists(launcher) ? " (exists)" : " (not exists)"));
|
||||
Path jvmLib = findJVM();
|
||||
ProcessBuilder pb = new ProcessBuilder(launcher.toString(), jvmLib.toString());
|
||||
// bin as working directory to let Windows load dll
|
||||
pb.directory(jvmLib.getParent().getParent().toFile());
|
||||
OutputAnalyzer outputf = new OutputAnalyzer(pb.start());
|
||||
outputf.shouldHaveExitValue(0);
|
||||
OutputAnalyzer oa = new OutputAnalyzer(pb.start());
|
||||
oa.shouldHaveExitValue(0);
|
||||
}
|
||||
|
||||
static Path findJVM() throws IOException {
|
||||
|
||||
@ -20,6 +20,8 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import jdk.test.lib.Utils;
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
|
||||
@ -57,7 +59,7 @@ public class TestAtExit {
|
||||
// We mustn't load Tester in this VM so we exec by name.
|
||||
String main = "TestAtExit$Tester";
|
||||
|
||||
String jlp = "-Djava.library.path=" + System.getProperty("test.nativepath");
|
||||
String jlp = "-Djava.library.path=" + Utils.TEST_NATIVE_PATH;
|
||||
// First run will terminate via DestroyJavaVM
|
||||
OutputAnalyzer output = ProcessTools.executeTestJvm(jlp, main);
|
||||
output.shouldNotContain("Unexpected");
|
||||
|
||||
@ -45,7 +45,7 @@ public class SigTestDriver {
|
||||
}
|
||||
|
||||
// At least one argument should be specified
|
||||
if ( (args == null) || (args.length < 1) ) {
|
||||
if ((args == null) || (args.length < 1)) {
|
||||
throw new IllegalArgumentException("At lease one argument should be specified, the signal name");
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ public class SigTestDriver {
|
||||
}
|
||||
}
|
||||
|
||||
Path test = Paths.get(System.getProperty("test.nativepath"))
|
||||
Path test = Paths.get(Utils.TEST_NATIVE_PATH)
|
||||
.resolve("sigtest")
|
||||
.toAbsolutePath();
|
||||
String envVar = Platform.sharedLibraryPathVariableName();
|
||||
@ -87,16 +87,17 @@ public class SigTestDriver {
|
||||
cmd.addAll(vmargs());
|
||||
|
||||
// add test specific arguments w/o signame
|
||||
cmd.addAll(Arrays.asList(args)
|
||||
.subList(1, args.length));
|
||||
var argList = Arrays.asList(args)
|
||||
.subList(1, args.length);
|
||||
cmd.addAll(argList);
|
||||
|
||||
boolean passed = true;
|
||||
|
||||
for (String mode : new String[]{"sigset", "sigaction"}) {
|
||||
for (String mode : new String[] {"sigset", "sigaction"}) {
|
||||
for (String scenario : new String[] {"nojvm", "prepre", "prepost", "postpre", "postpost"}) {
|
||||
cmd.set(modeIdx, mode);
|
||||
cmd.set(scenarioIdx, scenario);
|
||||
System.out.printf("START TESTING: SIGNAL = %s, MODE = %s, SCENARIO=%s%n",signame, mode, scenario);
|
||||
System.out.printf("START TESTING: SIGNAL = %s, MODE = %s, SCENARIO=%s%n", signame, mode, scenario);
|
||||
System.out.printf("Do execute: %s%n", cmd.toString());
|
||||
|
||||
ProcessBuilder pb = new ProcessBuilder(cmd);
|
||||
@ -117,7 +118,7 @@ public class SigTestDriver {
|
||||
oa.reportDiagnosticSummary();
|
||||
int exitCode = oa.getExitValue();
|
||||
if (exitCode == 0) {
|
||||
System.out.println("PASSED with exit code 0");
|
||||
System.out.println("PASSED with exit code 0");
|
||||
} else {
|
||||
System.out.println("FAILED with exit code " + exitCode);
|
||||
passed = false;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -20,9 +20,15 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
import java.nio.file.Paths;
|
||||
import jdk.test.lib.dcmd.*;
|
||||
|
||||
import jdk.test.lib.Platform;
|
||||
import jdk.test.lib.Utils;
|
||||
import jdk.test.lib.dcmd.CommandExecutor;
|
||||
import jdk.test.lib.dcmd.JMXExecutor;
|
||||
import jdk.test.lib.dcmd.PidJcmdExecutor;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public abstract class AttachFailedTestBase {
|
||||
@ -42,18 +48,18 @@ public abstract class AttachFailedTestBase {
|
||||
libname = "lib" + name + ".so";
|
||||
}
|
||||
|
||||
return Paths.get(System.getProperty("test.nativepath"), libname)
|
||||
return Paths.get(Utils.TEST_NATIVE_PATH, libname)
|
||||
.toAbsolutePath()
|
||||
.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jmx() throws Throwable {
|
||||
public void jmx() {
|
||||
run(new JMXExecutor());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cli() throws Throwable {
|
||||
public void cli() {
|
||||
run(new PidJcmdExecutor());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -24,6 +24,7 @@
|
||||
package nsk.jvmti;
|
||||
|
||||
import jdk.test.lib.Platform;
|
||||
import jdk.test.lib.Utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
@ -32,7 +33,7 @@ import java.nio.file.Paths;
|
||||
|
||||
public class NativeLibraryCopier {
|
||||
public static void main(String[] args) {
|
||||
Path src = Paths.get( System.getProperty("test.nativepath", "."))
|
||||
Path src = Paths.get(Utils.TEST_NATIVE_PATH)
|
||||
.resolve(libname(args[0]))
|
||||
.toAbsolutePath();
|
||||
|
||||
|
||||
@ -23,6 +23,10 @@
|
||||
|
||||
package jdk.test.lib.process;
|
||||
|
||||
import jdk.test.lib.JDKToolFinder;
|
||||
import jdk.test.lib.Platform;
|
||||
import jdk.test.lib.Utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -32,6 +36,9 @@ import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@ -42,25 +49,20 @@ import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
|
||||
import jdk.test.lib.JDKToolFinder;
|
||||
import jdk.test.lib.Platform;
|
||||
import jdk.test.lib.Utils;
|
||||
|
||||
public final class ProcessTools {
|
||||
private static final class LineForwarder extends StreamPumper.LinePump {
|
||||
private final PrintStream ps;
|
||||
private final String prefix;
|
||||
|
||||
LineForwarder(String prefix, PrintStream os) {
|
||||
this.ps = os;
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processLine(String line) {
|
||||
ps.println("[" + prefix + "] " + line);
|
||||
@ -73,23 +75,25 @@ public final class ProcessTools {
|
||||
/**
|
||||
* <p>Starts a process from its builder.</p>
|
||||
* <span>The default redirects of STDOUT and STDERR are started</span>
|
||||
* @param name The process name
|
||||
*
|
||||
* @param name The process name
|
||||
* @param processBuilder The process builder
|
||||
* @return Returns the initialized process
|
||||
* @throws IOException
|
||||
*/
|
||||
public static Process startProcess(String name,
|
||||
ProcessBuilder processBuilder)
|
||||
throws IOException {
|
||||
return startProcess(name, processBuilder, (Consumer<String>)null);
|
||||
throws IOException {
|
||||
return startProcess(name, processBuilder, (Consumer<String>) null);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Starts a process from its builder.</p>
|
||||
* <span>The default redirects of STDOUT and STDERR are started</span>
|
||||
* <p>It is possible to monitor the in-streams via the provided {@code consumer}
|
||||
* @param name The process name
|
||||
* @param consumer {@linkplain Consumer} instance to process the in-streams
|
||||
*
|
||||
* @param name The process name
|
||||
* @param consumer {@linkplain Consumer} instance to process the in-streams
|
||||
* @param processBuilder The process builder
|
||||
* @return Returns the initialized process
|
||||
* @throws IOException
|
||||
@ -98,7 +102,7 @@ public final class ProcessTools {
|
||||
public static Process startProcess(String name,
|
||||
ProcessBuilder processBuilder,
|
||||
Consumer<String> consumer)
|
||||
throws IOException {
|
||||
throws IOException {
|
||||
try {
|
||||
return startProcess(name, processBuilder, consumer, null, -1, TimeUnit.NANOSECONDS);
|
||||
} catch (InterruptedException | TimeoutException e) {
|
||||
@ -114,14 +118,15 @@ public final class ProcessTools {
|
||||
* It is possible to wait for the process to get to a warmed-up state
|
||||
* via {@linkplain Predicate} condition on the STDOUT
|
||||
* </p>
|
||||
* @param name The process name
|
||||
*
|
||||
* @param name The process name
|
||||
* @param processBuilder The process builder
|
||||
* @param linePredicate The {@linkplain Predicate} to use on the STDOUT
|
||||
* Used to determine the moment the target app is
|
||||
* properly warmed-up.
|
||||
* It can be null - in that case the warmup is skipped.
|
||||
* @param timeout The timeout for the warmup waiting; -1 = no wait; 0 = wait forever
|
||||
* @param unit The timeout {@linkplain TimeUnit}
|
||||
* @param linePredicate The {@linkplain Predicate} to use on the STDOUT
|
||||
* Used to determine the moment the target app is
|
||||
* properly warmed-up.
|
||||
* It can be null - in that case the warmup is skipped.
|
||||
* @param timeout The timeout for the warmup waiting; -1 = no wait; 0 = wait forever
|
||||
* @param unit The timeout {@linkplain TimeUnit}
|
||||
* @return Returns the initialized {@linkplain Process}
|
||||
* @throws IOException
|
||||
* @throws InterruptedException
|
||||
@ -132,7 +137,7 @@ public final class ProcessTools {
|
||||
final Predicate<String> linePredicate,
|
||||
long timeout,
|
||||
TimeUnit unit)
|
||||
throws IOException, InterruptedException, TimeoutException {
|
||||
throws IOException, InterruptedException, TimeoutException {
|
||||
return startProcess(name, processBuilder, null, linePredicate, timeout, unit);
|
||||
}
|
||||
|
||||
@ -144,15 +149,16 @@ public final class ProcessTools {
|
||||
* via {@linkplain Predicate} condition on the STDOUT and monitor the
|
||||
* in-streams via the provided {@linkplain Consumer}
|
||||
* </p>
|
||||
* @param name The process name
|
||||
*
|
||||
* @param name The process name
|
||||
* @param processBuilder The process builder
|
||||
* @param lineConsumer The {@linkplain Consumer} the lines will be forwarded to
|
||||
* @param linePredicate The {@linkplain Predicate} to use on the STDOUT
|
||||
* Used to determine the moment the target app is
|
||||
* properly warmed-up.
|
||||
* It can be null - in that case the warmup is skipped.
|
||||
* @param timeout The timeout for the warmup waiting; -1 = no wait; 0 = wait forever
|
||||
* @param unit The timeout {@linkplain TimeUnit}
|
||||
* @param lineConsumer The {@linkplain Consumer} the lines will be forwarded to
|
||||
* @param linePredicate The {@linkplain Predicate} to use on the STDOUT
|
||||
* Used to determine the moment the target app is
|
||||
* properly warmed-up.
|
||||
* It can be null - in that case the warmup is skipped.
|
||||
* @param timeout The timeout for the warmup waiting; -1 = no wait; 0 = wait forever
|
||||
* @param unit The timeout {@linkplain TimeUnit}
|
||||
* @return Returns the initialized {@linkplain Process}
|
||||
* @throws IOException
|
||||
* @throws InterruptedException
|
||||
@ -164,8 +170,8 @@ public final class ProcessTools {
|
||||
final Predicate<String> linePredicate,
|
||||
long timeout,
|
||||
TimeUnit unit)
|
||||
throws IOException, InterruptedException, TimeoutException {
|
||||
System.out.println("["+name+"]:" + processBuilder.command().stream().collect(Collectors.joining(" ")));
|
||||
throws IOException, InterruptedException, TimeoutException {
|
||||
System.out.println("[" + name + "]:" + String.join(" ", processBuilder.command()));
|
||||
Process p = privilegedStart(processBuilder);
|
||||
StreamPumper stdout = new StreamPumper(p.getInputStream());
|
||||
StreamPumper stderr = new StreamPumper(p.getErrorStream());
|
||||
@ -214,7 +220,7 @@ public final class ProcessTools {
|
||||
}
|
||||
} catch (TimeoutException | InterruptedException e) {
|
||||
System.err.println("Failed to start a process (thread dump follows)");
|
||||
for(Map.Entry<Thread, StackTraceElement[]> s : Thread.getAllStackTraces().entrySet()) {
|
||||
for (Map.Entry<Thread, StackTraceElement[]> s : Thread.getAllStackTraces().entrySet()) {
|
||||
printStack(s.getKey(), s.getValue());
|
||||
}
|
||||
|
||||
@ -238,12 +244,13 @@ public final class ProcessTools {
|
||||
* via {@linkplain Predicate} condition on the STDOUT. The warm-up will
|
||||
* wait indefinitely.
|
||||
* </p>
|
||||
* @param name The process name
|
||||
*
|
||||
* @param name The process name
|
||||
* @param processBuilder The process builder
|
||||
* @param linePredicate The {@linkplain Predicate} to use on the STDOUT
|
||||
* Used to determine the moment the target app is
|
||||
* properly warmed-up.
|
||||
* It can be null - in that case the warmup is skipped.
|
||||
* @param linePredicate The {@linkplain Predicate} to use on the STDOUT
|
||||
* Used to determine the moment the target app is
|
||||
* properly warmed-up.
|
||||
* It can be null - in that case the warmup is skipped.
|
||||
* @return Returns the initialized {@linkplain Process}
|
||||
* @throws IOException
|
||||
* @throws InterruptedException
|
||||
@ -253,7 +260,7 @@ public final class ProcessTools {
|
||||
public static Process startProcess(String name,
|
||||
ProcessBuilder processBuilder,
|
||||
final Predicate<String> linePredicate)
|
||||
throws IOException, InterruptedException, TimeoutException {
|
||||
throws IOException, InterruptedException, TimeoutException {
|
||||
return startProcess(name, processBuilder, linePredicate, 0, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@ -303,8 +310,7 @@ public final class ProcessTools {
|
||||
}
|
||||
|
||||
private static void printStack(Thread t, StackTraceElement[] stack) {
|
||||
System.out.println("\t" + t +
|
||||
" stack: (length = " + stack.length + ")");
|
||||
System.out.println("\t" + t + " stack: (length = " + stack.length + ")");
|
||||
if (t != null) {
|
||||
for (StackTraceElement stack1 : stack) {
|
||||
System.out.println("\t" + stack1);
|
||||
@ -316,7 +322,7 @@ public final class ProcessTools {
|
||||
/**
|
||||
* Create ProcessBuilder using the java launcher from the jdk to be tested.
|
||||
* The default jvm options from jtreg, test.vm.opts and test.java.opts, are added.
|
||||
*
|
||||
* <p>
|
||||
* The command line will be like:
|
||||
* {test.jdk}/bin/java {test.vm.opts} {test.java.opts} cmds
|
||||
* Create ProcessBuilder using the java launcher from the jdk to be tested.
|
||||
@ -331,7 +337,7 @@ public final class ProcessTools {
|
||||
/**
|
||||
* Create ProcessBuilder using the java launcher from the jdk to be tested.
|
||||
* The default jvm options from jtreg, test.vm.opts and test.java.opts, are added.
|
||||
*
|
||||
* <p>
|
||||
* The command line will be like:
|
||||
* {test.jdk}/bin/java {test.vm.opts} {test.java.opts} cmds
|
||||
* Create ProcessBuilder using the java launcher from the jdk to be tested.
|
||||
@ -347,10 +353,10 @@ public final class ProcessTools {
|
||||
* Executes a test jvm process, waits for it to finish and returns the process output.
|
||||
* The default jvm options from jtreg, test.vm.opts and test.java.opts, are added.
|
||||
* The java from the test.jdk is used to execute the command.
|
||||
*
|
||||
* <p>
|
||||
* The command line will be like:
|
||||
* {test.jdk}/bin/java {test.vm.opts} {test.java.opts} cmds
|
||||
*
|
||||
* <p>
|
||||
* The jvm process will have exited before this method returns.
|
||||
*
|
||||
* @param cmds User specified arguments.
|
||||
@ -364,10 +370,10 @@ public final class ProcessTools {
|
||||
* Executes a test jvm process, waits for it to finish and returns the process output.
|
||||
* The default jvm options from jtreg, test.vm.opts and test.java.opts, are added.
|
||||
* The java from the test.jdk is used to execute the command.
|
||||
*
|
||||
* <p>
|
||||
* The command line will be like:
|
||||
* {test.jdk}/bin/java {test.vm.opts} {test.java.opts} cmds
|
||||
*
|
||||
* <p>
|
||||
* The jvm process will have exited before this method returns.
|
||||
*
|
||||
* @param cmds User specified arguments.
|
||||
@ -379,9 +385,9 @@ public final class ProcessTools {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #executeTestJvm(String...)
|
||||
* @param cmds User specified arguments.
|
||||
* @return The output from the process.
|
||||
* @see #executeTestJvm(String...)
|
||||
*/
|
||||
public static OutputAnalyzer executeTestJava(String... cmds) throws Exception {
|
||||
return executeTestJvm(cmds);
|
||||
@ -390,6 +396,7 @@ public final class ProcessTools {
|
||||
/**
|
||||
* Executes a process, waits for it to finish and returns the process output.
|
||||
* The process will have exited before this method returns.
|
||||
*
|
||||
* @param pb The ProcessBuilder to execute.
|
||||
* @return The {@linkplain OutputAnalyzer} instance wrapping the process.
|
||||
*/
|
||||
@ -401,7 +408,8 @@ public final class ProcessTools {
|
||||
* Executes a process, pipe some text into its STDIN, waits for it
|
||||
* to finish and returns the process output. The process will have exited
|
||||
* before this method returns.
|
||||
* @param pb The ProcessBuilder to execute.
|
||||
*
|
||||
* @param pb The ProcessBuilder to execute.
|
||||
* @param input The text to pipe into STDIN. Can be null.
|
||||
* @return The {@linkplain OutputAnalyzer} instance wrapping the process.
|
||||
*/
|
||||
@ -413,23 +421,24 @@ public final class ProcessTools {
|
||||
* Executes a process, pipe some text into its STDIN, waits for it
|
||||
* to finish and returns the process output. The process will have exited
|
||||
* before this method returns.
|
||||
* @param pb The ProcessBuilder to execute.
|
||||
*
|
||||
* @param pb The ProcessBuilder to execute.
|
||||
* @param input The text to pipe into STDIN. Can be null.
|
||||
* @param cs The charset used to convert from bytes to chars or null for
|
||||
* the default charset.
|
||||
* @param cs The charset used to convert from bytes to chars or null for
|
||||
* the default charset.
|
||||
* @return The {@linkplain OutputAnalyzer} instance wrapping the process.
|
||||
*/
|
||||
public static OutputAnalyzer executeProcess(ProcessBuilder pb, String input,
|
||||
Charset cs) throws Exception {
|
||||
Charset cs) throws Exception {
|
||||
OutputAnalyzer output = null;
|
||||
Process p = null;
|
||||
boolean failed = false;
|
||||
try {
|
||||
p = privilegedStart(pb);
|
||||
if (input != null) {
|
||||
try (PrintStream ps = new PrintStream(p.getOutputStream())) {
|
||||
ps.print(input);
|
||||
}
|
||||
try (PrintStream ps = new PrintStream(p.getOutputStream())) {
|
||||
ps.print(input);
|
||||
}
|
||||
}
|
||||
|
||||
output = new OutputAnalyzer(p, cs);
|
||||
@ -465,7 +474,7 @@ public final class ProcessTools {
|
||||
|
||||
/**
|
||||
* Executes a process, waits for it to finish and returns the process output.
|
||||
*
|
||||
* <p>
|
||||
* The process will have exited before this method returns.
|
||||
*
|
||||
* @param cmds The command line to execute.
|
||||
@ -477,22 +486,20 @@ public final class ProcessTools {
|
||||
|
||||
/**
|
||||
* Used to log command line, stdout, stderr and exit code from an executed process.
|
||||
* @param pb The executed process.
|
||||
*
|
||||
* @param pb The executed process.
|
||||
* @param output The output from the process.
|
||||
*/
|
||||
public static String getProcessLog(ProcessBuilder pb, OutputAnalyzer output) {
|
||||
String stderr = output == null ? "null" : output.getStderr();
|
||||
String stdout = output == null ? "null" : output.getStdout();
|
||||
String exitValue = output == null ? "null": Integer.toString(output.getExitValue());
|
||||
StringBuilder logMsg = new StringBuilder();
|
||||
final String nl = System.getProperty("line.separator");
|
||||
logMsg.append("--- ProcessLog ---" + nl);
|
||||
logMsg.append("cmd: " + getCommandLine(pb) + nl);
|
||||
logMsg.append("exitvalue: " + exitValue + nl);
|
||||
logMsg.append("stderr: " + stderr + nl);
|
||||
logMsg.append("stdout: " + stdout + nl);
|
||||
|
||||
return logMsg.toString();
|
||||
String exitValue = output == null ? "null" : Integer.toString(output.getExitValue());
|
||||
return String.format("--- ProcessLog ---%n" +
|
||||
"cmd: %s%n" +
|
||||
"exitvalue: %s%n" +
|
||||
"stderr: %s%n" +
|
||||
"stdout: %s%n",
|
||||
getCommandLine(pb), exitValue, stderr, stdout);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -512,7 +519,7 @@ public final class ProcessTools {
|
||||
/**
|
||||
* Executes a process, waits for it to finish, prints the process output
|
||||
* to stdout, and returns the process output.
|
||||
*
|
||||
* <p>
|
||||
* The process will have exited before this method returns.
|
||||
*
|
||||
* @param cmds The command line to execute.
|
||||
@ -520,7 +527,7 @@ public final class ProcessTools {
|
||||
*/
|
||||
public static OutputAnalyzer executeCommand(String... cmds)
|
||||
throws Throwable {
|
||||
String cmdLine = Arrays.stream(cmds).collect(Collectors.joining(" "));
|
||||
String cmdLine = String.join(" ", cmds);
|
||||
System.out.println("Command line: [" + cmdLine + "]");
|
||||
OutputAnalyzer analyzer = ProcessTools.executeProcess(cmds);
|
||||
System.out.println(analyzer.getOutput());
|
||||
@ -530,7 +537,7 @@ public final class ProcessTools {
|
||||
/**
|
||||
* Executes a process, waits for it to finish, prints the process output
|
||||
* to stdout and returns the process output.
|
||||
*
|
||||
* <p>
|
||||
* The process will have exited before this method returns.
|
||||
*
|
||||
* @param pb The ProcessBuilder to execute.
|
||||
@ -553,20 +560,19 @@ public final class ProcessTools {
|
||||
* test that uses/loads JVM.
|
||||
*
|
||||
* @param executableName The name of an executable to be launched.
|
||||
* @param args Arguments for the executable.
|
||||
* @param args Arguments for the executable.
|
||||
* @return New ProcessBuilder instance representing the command.
|
||||
*/
|
||||
public static ProcessBuilder createNativeTestProcessBuilder(String executableName,
|
||||
String... args) throws Exception {
|
||||
executableName = Platform.isWindows() ? executableName + ".exe" : executableName;
|
||||
String executable = Paths.get(System.getProperty("test.nativepath"), executableName)
|
||||
.toAbsolutePath()
|
||||
.toString();
|
||||
String executable = Paths.get(Utils.TEST_NATIVE_PATH, executableName)
|
||||
.toAbsolutePath()
|
||||
.toString();
|
||||
|
||||
ProcessBuilder pb = new ProcessBuilder(executable);
|
||||
pb.command().addAll(Arrays.asList(args));
|
||||
addJvmLib(pb);
|
||||
return pb;
|
||||
return addJvmLib(pb);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -585,7 +591,7 @@ public final class ProcessTools {
|
||||
String libDir = Platform.libDir().toString();
|
||||
newLibPath = newLibPath + File.pathSeparator + libDir;
|
||||
}
|
||||
if ( (currentLibPath != null) && !currentLibPath.isEmpty() ) {
|
||||
if ((currentLibPath != null) && !currentLibPath.isEmpty()) {
|
||||
newLibPath = newLibPath + File.pathSeparator + currentLibPath;
|
||||
}
|
||||
|
||||
@ -597,10 +603,9 @@ public final class ProcessTools {
|
||||
private static Process privilegedStart(ProcessBuilder pb) throws IOException {
|
||||
try {
|
||||
return AccessController.doPrivileged(
|
||||
(PrivilegedExceptionAction<Process>) () -> pb.start());
|
||||
(PrivilegedExceptionAction<Process>) pb::start);
|
||||
} catch (PrivilegedActionException e) {
|
||||
IOException t = (IOException) e.getException();
|
||||
throw t;
|
||||
throw (IOException) e.getException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user