From 0a6d8ab19736f2493438a9101dd19d9752679346 Mon Sep 17 00:00:00 2001 From: duke Date: Thu, 16 Oct 2025 07:07:54 +0000 Subject: [PATCH] Backport bfb034abf9d5e5eb24d524f35b3f745e94631c4a --- .../docker/TestDockerMemoryMetrics.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/test/jdk/jdk/internal/platform/docker/TestDockerMemoryMetrics.java b/test/jdk/jdk/internal/platform/docker/TestDockerMemoryMetrics.java index eda17c09a45..09cd60baabe 100644 --- a/test/jdk/jdk/internal/platform/docker/TestDockerMemoryMetrics.java +++ b/test/jdk/jdk/internal/platform/docker/TestDockerMemoryMetrics.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -108,6 +108,23 @@ private static void testMemoryLimit(String value, boolean addCgroupMount) throws private static void testMemoryFailCount(String value) throws Exception { Common.logNewTestCase("testMemoryFailCount" + value); + + // Check whether swapping really works for this test + // On some systems there is no swap space enabled. And running + // 'java -Xms{mem-limit} -Xmx{mem-limit} -version' would fail due to swap space size being 0. + DockerRunOptions preOpts = + new DockerRunOptions(imageName, "/jdk/bin/java", "-version"); + preOpts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/") + .addDockerOpts("--memory=" + value) + .addJavaOpts("-Xms" + value) + .addJavaOpts("-Xmx" + value); + OutputAnalyzer oa = DockerTestUtils.dockerRunJava(preOpts); + String output = oa.getOutput(); + if (!output.contains("version")) { + System.out.println("Swapping doesn't work for this test."); + return; + } + DockerRunOptions opts = new DockerRunOptions(imageName, "/jdk/bin/java", "MetricsMemoryTester"); opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/") @@ -116,7 +133,13 @@ private static void testMemoryFailCount(String value) throws Exception { .addJavaOpts("-cp", "/test-classes/") .addJavaOpts("--add-exports", "java.base/jdk.internal.platform=ALL-UNNAMED") .addClassOptions("failcount"); - DockerTestUtils.dockerRunJava(opts).shouldHaveExitValue(0).shouldContain("TEST PASSED!!!"); + oa = DockerTestUtils.dockerRunJava(opts); + output = oa.getOutput(); + if (output.contains("Ignoring test")) { + System.out.println("Ignored by the tester"); + return; + } + oa.shouldHaveExitValue(0).shouldContain("TEST PASSED!!!"); } private static void testMemoryAndSwapLimit(String memory, String memandswap) throws Exception {