Path: blob/master/test/hotspot/jtreg/containers/cgroup/PlainRead.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*/2223/*24* @test PlainRead25* @key cgroups26* @requires os.family == "linux"27* @requires vm.flagless28* @library /testlibrary /test/lib29* @build sun.hotspot.WhiteBox30* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox31* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI PlainRead32*/3334import jdk.test.lib.process.ProcessTools;35import jdk.test.lib.process.OutputAnalyzer;36import jdk.test.lib.Platform;37import sun.hotspot.WhiteBox;3839public class PlainRead {4041static public void match(OutputAnalyzer oa, String what, String value) {42oa.shouldMatch("^.*" + what + " *" + value + ".*$");43}4445static public void noMatch(OutputAnalyzer oa, String what, String value) {46oa.shouldNotMatch("^.*" + what + " *" + value + ".*$");47}4849static final String good_value = "(\\d+|-1|-2|Unlimited)";50static final String bad_value = "(failed)";5152static final String[] variables = {"Memory Limit is:", "CPU Shares is:", "CPU Quota is:", "CPU Period is:", "active_processor_count:"};5354static public void isContainer(OutputAnalyzer oa) {55for (String v: variables) {56match(oa, v, good_value);57}58for (String v: variables) {59noMatch(oa, v, bad_value);60}61}6263static public void isNotContainer(OutputAnalyzer oa) {64oa.shouldMatch("^.*Can't open /proc/self/mountinfo.*$");65}6667public static void main(String[] args) throws Exception {68WhiteBox wb = WhiteBox.getWhiteBox();69ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xlog:os+container=trace", "-version");70OutputAnalyzer output = new OutputAnalyzer(pb.start());7172if (wb.isContainerized()) {73System.out.println("Inside a cgroup, testing...");74isContainer(output);75}76}77}787980