Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/runtime/containers/docker/TestCPUSets.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 JVM's awareness of cpu sets (cpus and mems)27* @library /testlibrary /testlibrary/whitebox28* @build AttemptOOM CPUSetsReader sun.hotspot.WhiteBox PrintContainerInfo29* @run driver ClassFileInstaller -jar whitebox.jar sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission30* @run driver TestCPUSets31*/3233import java.util.List;34import com.oracle.java.testlibrary.Common;35import com.oracle.java.testlibrary.DockerRunOptions;36import com.oracle.java.testlibrary.DockerTestUtils;37import com.oracle.java.testlibrary.Asserts;38import com.oracle.java.testlibrary.Platform;39import com.oracle.java.testlibrary.Utils;40import com.oracle.java.testlibrary.OutputAnalyzer;414243public class TestCPUSets {44private static final String imageName = Common.imageName("cpusets");4546public static void main(String[] args) throws Exception {47if (!DockerTestUtils.canTestDocker()) {48return;49}5051Common.prepareWhiteBox();52DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");5354try {55// Sanity test the cpu sets reader and parser56CPUSetsReader.test();57testTheSet("Cpus_allowed_list");58testTheSet("Mems_allowed_list");59} finally {60DockerTestUtils.removeDockerImage(imageName);61}62}636465private static void testTheSet(String setType) throws Exception {66String cpuSetStr = CPUSetsReader.readFromProcStatus(setType);6768if (cpuSetStr == null) {69System.out.printf("The %s test is skipped %n", setType);70} else {71List<Integer> cpuSet = CPUSetsReader.parseCpuSet(cpuSetStr);7273// Test subset of one, full subset, and half of the subset74testCpuSet(CPUSetsReader.listToString(cpuSet, 1));75if (cpuSet.size() > 1) {76testCpuSet(CPUSetsReader.listToString(cpuSet));77}78if (cpuSet.size() > 2) {79testCpuSet(CPUSetsReader.listToString(cpuSet, cpuSet.size()/2 ));80}81}82}838485private static DockerRunOptions commonOpts() {86DockerRunOptions opts = new DockerRunOptions(imageName, "/jdk/bin/java",87"PrintContainerInfo");88opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/");89opts.addJavaOpts("-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintContainerInfo", "-cp", "/test-classes/");90Common.addWhiteBoxOpts(opts);91return opts;92}939495private static void checkResult(List<String> lines, String lineMarker, String value) {96boolean lineMarkerFound = false;9798for (String line : lines) {99if (line.contains(lineMarker)) {100lineMarkerFound = true;101String[] parts = line.split(":");102System.out.println("DEBUG: line = " + line);103System.out.println("DEBUG: parts.length = " + parts.length);104105Asserts.assertEquals(parts.length, 2);106String set = parts[1].replaceAll("\\s","");107String actual = CPUSetsReader.listToString(CPUSetsReader.parseCpuSet(set));108Asserts.assertEquals(actual, value);109break;110}111}112Asserts.assertTrue(lineMarkerFound);113}114115116private static void testCpuSet(String value) throws Exception {117Common.logNewTestCase("cpusets.cpus, value = " + value);118119DockerRunOptions opts = commonOpts();120opts.addDockerOpts("--cpuset-cpus=" + value);121122List<String> lines = Common.run(opts).asLines();123checkResult(lines, "cpuset.cpus is:", value);124}125126private static void testMemSet(String value) throws Exception {127Common.logNewTestCase("cpusets.mems, value = " + value);128129DockerRunOptions opts = commonOpts();130opts.addDockerOpts("--cpuset-mems=" + value);131132List<String> lines = Common.run(opts).asLines();133checkResult(lines, "cpuset.mems is:", value);134}135136}137138139