Skip to content

Commit 0a6d8ab

Browse files
author
duke
committed
Backport bfb034a
1 parent b638bb3 commit 0a6d8ab

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

test/jdk/jdk/internal/platform/docker/TestDockerMemoryMetrics.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* 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
108108

109109
private static void testMemoryFailCount(String value) throws Exception {
110110
Common.logNewTestCase("testMemoryFailCount" + value);
111+
112+
// Check whether swapping really works for this test
113+
// On some systems there is no swap space enabled. And running
114+
// 'java -Xms{mem-limit} -Xmx{mem-limit} -version' would fail due to swap space size being 0.
115+
DockerRunOptions preOpts =
116+
new DockerRunOptions(imageName, "/jdk/bin/java", "-version");
117+
preOpts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/")
118+
.addDockerOpts("--memory=" + value)
119+
.addJavaOpts("-Xms" + value)
120+
.addJavaOpts("-Xmx" + value);
121+
OutputAnalyzer oa = DockerTestUtils.dockerRunJava(preOpts);
122+
String output = oa.getOutput();
123+
if (!output.contains("version")) {
124+
System.out.println("Swapping doesn't work for this test.");
125+
return;
126+
}
127+
111128
DockerRunOptions opts =
112129
new DockerRunOptions(imageName, "/jdk/bin/java", "MetricsMemoryTester");
113130
opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/")
@@ -116,7 +133,13 @@ private static void testMemoryFailCount(String value) throws Exception {
116133
.addJavaOpts("-cp", "/test-classes/")
117134
.addJavaOpts("--add-exports", "java.base/jdk.internal.platform=ALL-UNNAMED")
118135
.addClassOptions("failcount");
119-
DockerTestUtils.dockerRunJava(opts).shouldHaveExitValue(0).shouldContain("TEST PASSED!!!");
136+
oa = DockerTestUtils.dockerRunJava(opts);
137+
output = oa.getOutput();
138+
if (output.contains("Ignoring test")) {
139+
System.out.println("Ignored by the tester");
140+
return;
141+
}
142+
oa.shouldHaveExitValue(0).shouldContain("TEST PASSED!!!");
120143
}
121144

122145
private static void testMemoryAndSwapLimit(String memory, String memandswap) throws Exception {

0 commit comments

Comments
 (0)