Path: blob/master/test/hotspot/jtreg/containers/docker/TestMisc.java
40942 views
/*1* Copyright (c) 2017, 2021, 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* @requires docker.support28* @library /test/lib29* @modules java.base/jdk.internal.misc30* java.management31* jdk.jartool/sun.tools.jar32* @build CheckContainerized sun.hotspot.WhiteBox PrintContainerInfo33* @run driver jdk.test.lib.helpers.ClassFileInstaller -jar whitebox.jar sun.hotspot.WhiteBox34* @run driver TestMisc35*/36import jdk.test.lib.containers.docker.Common;37import jdk.test.lib.containers.docker.DockerTestUtils;38import jdk.test.lib.containers.docker.DockerRunOptions;39import jdk.test.lib.process.OutputAnalyzer;40import jdk.test.lib.process.ProcessTools;414243public class TestMisc {44private static final String imageName = Common.imageName("misc");4546public static void main(String[] args) throws Exception {47if (!DockerTestUtils.canTestDocker()) {48return;49}5051Common.prepareWhiteBox();52DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");5354try {55testMinusContainerSupport();56testIsContainerized();57testPrintContainerInfo();58} finally {59DockerTestUtils.removeDockerImage(imageName);60}61}626364private static void testMinusContainerSupport() throws Exception {65Common.logNewTestCase("Test related flags: '-UseContainerSupport'");66DockerRunOptions opts = new DockerRunOptions(imageName, "/jdk/bin/java", "-version");67opts.addJavaOpts("-XX:-UseContainerSupport", "-Xlog:os+container=trace");6869Common.run(opts)70.shouldContain("Container Support not enabled");71}727374private static void testIsContainerized() throws Exception {75Common.logNewTestCase("Test is_containerized() inside a docker container");7677DockerRunOptions opts = Common.newOpts(imageName, "CheckContainerized");78Common.addWhiteBoxOpts(opts);7980Common.run(opts)81.shouldContain(CheckContainerized.INSIDE_A_CONTAINER);82}838485private static void testPrintContainerInfo() throws Exception {86Common.logNewTestCase("Test print_container_info()");8788DockerRunOptions opts = Common.newOpts(imageName, "PrintContainerInfo");89Common.addWhiteBoxOpts(opts);9091checkContainerInfo(Common.run(opts));92}939495private static void checkContainerInfo(OutputAnalyzer out) throws Exception {96String[] expectedToContain = new String[] {97"cpuset.cpus",98"cpuset.mems",99"CPU Shares",100"CPU Quota",101"CPU Period",102"OSContainer::active_processor_count",103"Memory Limit",104"Memory Soft Limit",105"Memory Usage",106"Maximum Memory Usage",107"memory_max_usage_in_bytes"108};109110for (String s : expectedToContain) {111out.shouldContain(s);112}113}114115}116117118