--- old/test/lib/jdk/test/lib/process/ProcessTools.java 2020-01-30 20:31:18.000000000 -0800 +++ new/test/lib/jdk/test/lib/process/ProcessTools.java 2020-01-30 20:31:18.000000000 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 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 @@ -23,11 +23,13 @@ package jdk.test.lib.process; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintStream; import java.nio.charset.Charset; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -45,6 +47,7 @@ import java.security.PrivilegedExceptionAction; import jdk.test.lib.JDKToolFinder; +import jdk.test.lib.Platform; import jdk.test.lib.Utils; public final class ProcessTools { @@ -490,6 +493,44 @@ return analyzer; } + /** + * Helper method to create a process builder for launching native executable + * test that uses/loads JVM. + * + * @param executableName The name of an executable to be launched. + * @param args Arguments for the executable. + * @return New ProcessBuilder instance representing the command. + */ + public static ProcessBuilder createNativeTestProcessBuilder(String executableName, + String... args) throws Exception { + String executable = Paths.get(System.getProperty("test.nativepath"), executableName) + .toAbsolutePath() + .toString(); + + ProcessBuilder pb = new ProcessBuilder(executable); + pb.command().addAll(Arrays.asList(args)); + addJvmLib(pb); + return pb; + } + + /** + * Adds JVM library path to the native library path. + * + * @param pb ProcessBuilder to be updated with JVM library path. + */ + public static void addJvmLib(ProcessBuilder pb) throws Exception { + String jvmLibDir = Platform.jvmLibDir().toString(); + String libPathVar = Platform.sharedLibraryPathVariableName(); + String currentLibPath = pb.environment().get(libPathVar); + + String newLibPath = jvmLibDir; + if ( (currentLibPath != null) && !currentLibPath.isEmpty() ) { + newLibPath = currentLibPath + File.pathSeparator + jvmLibDir; + } + + pb.environment().put(libPathVar, newLibPath); + } + private static Process privilegedStart(ProcessBuilder pb) throws IOException { try { return AccessController.doPrivileged(