14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package jdk.test.lib.containers.docker; 25 26 /* 27 * Methods and definitions common to docker tests container in this directory 28 */ 29 30 import java.io.File; 31 import java.nio.file.Files; 32 import java.nio.file.Paths; 33 import java.nio.file.StandardCopyOption; 34 import jdk.test.lib.containers.docker.DockerRunOptions; 35 import jdk.test.lib.containers.docker.DockerTestUtils; 36 import jdk.test.lib.Utils; 37 import jdk.test.lib.process.OutputAnalyzer; 38 39 40 public class Common { 41 public static final String imageNameAndTag = "jdk-internal:test"; 42 43 public static String imageName(String suffix) { 44 return imageNameAndTag + "-" + suffix; 45 } 46 47 48 public static void prepareWhiteBox() throws Exception { 49 Files.copy(Paths.get(new File("whitebox.jar").getAbsolutePath()), 50 Paths.get(Utils.TEST_CLASSES, "whitebox.jar"), StandardCopyOption.REPLACE_EXISTING); 51 } 52 53 70 71 public static DockerRunOptions addWhiteBoxOpts(DockerRunOptions opts) { 72 opts.addJavaOpts("-Xbootclasspath/a:/test-classes/whitebox.jar", 73 "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI"); 74 return opts; 75 } 76 77 78 // most common type of run and checks 79 public static OutputAnalyzer run(DockerRunOptions opts) throws Exception { 80 return DockerTestUtils.dockerRunJava(opts) 81 .shouldHaveExitValue(0).shouldContain("Initializing Container Support"); 82 } 83 84 85 // log beginning of a test case 86 public static void logNewTestCase(String msg) { 87 System.out.println("========== NEW TEST CASE: " + msg); 88 } 89 90 } | 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package jdk.test.lib.containers.docker; 25 26 /* 27 * Methods and definitions common to docker tests container in this directory 28 */ 29 30 import java.io.File; 31 import java.nio.file.Files; 32 import java.nio.file.Paths; 33 import java.nio.file.StandardCopyOption; 34 import java.util.List; 35 import java.util.stream.Collectors; 36 import jdk.test.lib.containers.docker.DockerRunOptions; 37 import jdk.test.lib.containers.docker.DockerTestUtils; 38 import jdk.test.lib.Utils; 39 import jdk.test.lib.process.OutputAnalyzer; 40 41 42 public class Common { 43 public static final String imageNameAndTag = "jdk-internal:test"; 44 45 public static String imageName(String suffix) { 46 return imageNameAndTag + "-" + suffix; 47 } 48 49 50 public static void prepareWhiteBox() throws Exception { 51 Files.copy(Paths.get(new File("whitebox.jar").getAbsolutePath()), 52 Paths.get(Utils.TEST_CLASSES, "whitebox.jar"), StandardCopyOption.REPLACE_EXISTING); 53 } 54 55 72 73 public static DockerRunOptions addWhiteBoxOpts(DockerRunOptions opts) { 74 opts.addJavaOpts("-Xbootclasspath/a:/test-classes/whitebox.jar", 75 "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI"); 76 return opts; 77 } 78 79 80 // most common type of run and checks 81 public static OutputAnalyzer run(DockerRunOptions opts) throws Exception { 82 return DockerTestUtils.dockerRunJava(opts) 83 .shouldHaveExitValue(0).shouldContain("Initializing Container Support"); 84 } 85 86 87 // log beginning of a test case 88 public static void logNewTestCase(String msg) { 89 System.out.println("========== NEW TEST CASE: " + msg); 90 } 91 92 // find process ID from JCMD output 93 public static long findPidFromJcmdOutput(OutputAnalyzer out, String name) throws Exception { 94 List<String> l = out.asLines() 95 .stream() 96 .filter(s -> s.contains(name)) 97 .collect(Collectors.toList()); 98 if (l.isEmpty()) { 99 throw new RuntimeException("Could not find matching process"); 100 } 101 String psInfo = l.get(0); 102 System.out.println("findPidFromJcmdOutput(): psInfo: " + psInfo); 103 String pid = psInfo.substring(0, psInfo.indexOf(' ')); 104 System.out.println("findPidFromJcmdOutput(): pid: " + pid); 105 return Long.parseLong(pid); 106 } 107 } |