1 /* 2 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 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 jdk.test.lib.containers.docker.DockerRunOptions; 34 import jdk.test.lib.containers.docker.DockerTestUtils; 35 import jdk.test.lib.Utils; 36 import jdk.test.lib.process.OutputAnalyzer; 37 38 39 public class Common { 40 public static final String imageNameAndTag = "jdk-internal:test"; 41 42 public static String imageName(String suffix) { 43 return imageNameAndTag + "-" + suffix; 44 } 45 46 47 public static void prepareWhiteBox() throws Exception { 48 Files.copy(Paths.get(new File("whitebox.jar").getAbsolutePath()), 49 Paths.get(Utils.TEST_CLASSES, "whitebox.jar")); 50 } 51 52 53 // create simple commonly used options 54 public static DockerRunOptions newOpts(String imageNameAndTag) { 55 return new DockerRunOptions(imageNameAndTag, "/jdk/bin/java", "-version") 56 .addJavaOpts("-Xlog:os+container=trace"); 57 } 58 59 60 // create commonly used options with class to be launched inside container 61 public static DockerRunOptions newOpts(String imageNameAndTag, String testClass) { 62 DockerRunOptions opts = 63 new DockerRunOptions(imageNameAndTag, "/jdk/bin/java", testClass); 64 opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/"); 65 opts.addJavaOpts("-Xlog:os+container=trace", "-cp", "/test-classes/"); 66 return opts; 67 } 68 69 70 public static DockerRunOptions addWhiteBoxOpts(DockerRunOptions opts) { 71 opts.addJavaOpts("-Xbootclasspath/a:/test-classes/whitebox.jar", 72 "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI"); 73 return opts; 74 } 75 76 77 // most common type of run and checks 78 public static OutputAnalyzer run(DockerRunOptions opts) throws Exception { 79 return DockerTestUtils.dockerRunJava(opts) 80 .shouldHaveExitValue(0).shouldContain("Initializing Container Support"); 81 } 82 83 84 // log beginning of a test case 85 public static void logNewTestCase(String msg) { 86 System.out.println("========== NEW TEST CASE: " + msg); 87 } 88 89 }