|
| 1 | +/* |
| 2 | + * Copyright (c) 2024, Red Hat, Inc. |
| 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 | + |
| 25 | +/* |
| 26 | + * @test |
| 27 | + * @summary Test container info for cgroup v2 |
| 28 | + * @requires docker.support |
| 29 | + * @library /test/lib |
| 30 | + * @modules java.base/jdk.internal.misc |
| 31 | + * java.management |
| 32 | + * jdk.jartool/sun.tools.jar |
| 33 | + * @build CheckContainerized jdk.test.whitebox.WhiteBox PrintContainerInfo |
| 34 | + * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar whitebox.jar jdk.test.whitebox.WhiteBox |
| 35 | + * @run driver TestContainerInfo |
| 36 | + */ |
| 37 | +import jtreg.SkippedException; |
| 38 | +import jdk.test.lib.containers.docker.Common; |
| 39 | +import jdk.test.lib.containers.docker.DockerTestUtils; |
| 40 | +import jdk.test.lib.containers.docker.DockerRunOptions; |
| 41 | +import jdk.test.lib.process.OutputAnalyzer; |
| 42 | +import jdk.test.lib.process.ProcessTools; |
| 43 | + |
| 44 | + |
| 45 | +public class TestContainerInfo { |
| 46 | + private static final String imageName = Common.imageName("container-info"); |
| 47 | + |
| 48 | + public static void main(String[] args) throws Exception { |
| 49 | + if (!DockerTestUtils.canTestDocker()) { |
| 50 | + return; |
| 51 | + } |
| 52 | + |
| 53 | + Common.prepareWhiteBox(); |
| 54 | + DockerTestUtils.buildJdkContainerImage(imageName); |
| 55 | + |
| 56 | + try { |
| 57 | + testPrintContainerInfoWithoutSwap(); |
| 58 | + } finally { |
| 59 | + DockerTestUtils.removeDockerImage(imageName); |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + private static void testPrintContainerInfoWithoutSwap() throws Exception { |
| 64 | + Common.logNewTestCase("Test print_container_info() - without swap"); |
| 65 | + |
| 66 | + DockerRunOptions opts = Common.newOpts(imageName, "PrintContainerInfo") |
| 67 | + .addDockerOpts("--memory=500m") |
| 68 | + .addDockerOpts("--memory-swap=500m"); // no swap |
| 69 | + Common.addWhiteBoxOpts(opts); |
| 70 | + |
| 71 | + OutputAnalyzer out = Common.run(opts); |
| 72 | + checkContainerInfo(out); |
| 73 | + } |
| 74 | + |
| 75 | + private static void checkContainerInfo(OutputAnalyzer out) throws Exception { |
| 76 | + String str = out.getOutput(); |
| 77 | + if (str.contains("cgroupv2")) { |
| 78 | + out.shouldContain("memory_swap_max_limit_in_bytes: 0"); |
| 79 | + out.shouldContain("memory_swap_current_in_bytes: 0"); |
| 80 | + } else { |
| 81 | + throw new SkippedException("This test is cgroups v2 specific, skipped on cgroups v1"); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | +} |
0 commit comments