Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/runtime/containers/docker/TestMisc.java
32285 views
/*1* Copyright (c) 2018, 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*/222324/*25* @test26* @summary Test miscellanous functionality related to JVM running in docker container27* @library /testlibrary /testlibrary/whitebox28* @build CheckContainerized sun.hotspot.WhiteBox PrintContainerInfo29* @run driver ClassFileInstaller -jar whitebox.jar sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission30* @run driver TestMisc31*/3233import com.oracle.java.testlibrary.Common;34import com.oracle.java.testlibrary.DockerTestUtils;35import com.oracle.java.testlibrary.DockerRunOptions;36import com.oracle.java.testlibrary.OutputAnalyzer;37import com.oracle.java.testlibrary.ProcessTools;383940public class TestMisc {41private static final String imageName = Common.imageName("misc");4243public static void main(String[] args) throws Exception {44if (!DockerTestUtils.canTestDocker()) {45return;46}4748Common.prepareWhiteBox();49DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");5051try {52testMinusContainerSupport();53testIsContainerized();54testPrintContainerInfo();55} finally {56DockerTestUtils.removeDockerImage(imageName);57}58}596061private static void testMinusContainerSupport() throws Exception {62Common.logNewTestCase("Test related flags: '-UseContainerSupport'");63DockerRunOptions opts = new DockerRunOptions(imageName, "/jdk/bin/java", "-version");64opts.addJavaOpts("-XX:+UnlockDiagnosticVMOptions", "-XX:-UseContainerSupport", "-XX:+PrintContainerInfo");6566Common.run(opts)67.shouldContain("Container Support not enabled");68}697071private static void testIsContainerized() throws Exception {72Common.logNewTestCase("Test is_containerized() inside a docker container");7374DockerRunOptions opts = Common.newOpts(imageName, "CheckContainerized");75Common.addWhiteBoxOpts(opts);7677Common.run(opts)78.shouldContain(CheckContainerized.INSIDE_A_CONTAINER);79}808182private static void testPrintContainerInfo() throws Exception {83Common.logNewTestCase("Test print_container_info()");8485DockerRunOptions opts = Common.newOpts(imageName, "PrintContainerInfo");86Common.addWhiteBoxOpts(opts);8788checkContainerInfo(Common.run(opts));89}909192private static void checkContainerInfo(OutputAnalyzer out) throws Exception {93String[] expectedToContain = new String[] {94"cpuset.cpus",95"cpuset.mems",96"CPU Shares",97"CPU Quota",98"CPU Period",99"OSContainer::active_processor_count",100"Memory Limit",101"Memory Soft Limit",102"Memory Usage",103"Maximum Memory Usage",104"memory_max_usage_in_bytes"105};106107for (String s : expectedToContain) {108out.shouldContain(s);109}110}111112}113114115