Skip to content

Commit 48818bc

Browse files
author
duke
committed
Backport 7e068cc8d572e61cf2f4203f66fe0175a541209d
1 parent 9d467de commit 48818bc

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2025, 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
@@ -70,7 +70,7 @@ private static void testMemoryFailCount() {
7070

7171
// We need swap to execute this test or will SEGV
7272
if (memAndSwapLimit <= memLimit) {
73-
System.out.println("No swap memory limits, test case skipped");
73+
System.out.println("No swap memory limits. Ignoring test!");
7474
} else {
7575
long count = Metrics.systemMetrics().getMemoryFailCount();
7676

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2025, 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
@@ -27,6 +27,7 @@
2727
import jdk.test.lib.containers.docker.DockerRunOptions;
2828
import jdk.test.lib.containers.docker.DockerTestUtils;
2929
import jdk.test.lib.process.OutputAnalyzer;
30+
import jtreg.SkippedException;
3031

3132
/*
3233
* @test
@@ -112,18 +113,22 @@ private static void testMemoryFailCount(String value) throws Exception {
112113

113114
// Check whether swapping really works for this test
114115
// On some systems there is no swap space enabled. And running
115-
// 'java -Xms{mem-limit} -Xmx{mem-limit} -version' would fail due to swap space size being 0.
116+
// 'java -Xms{mem-limit} -Xmx{mem-limit} -XX:+AlwaysPreTouch -version'
117+
// would fail due to swap space size being 0. Note that when swap is
118+
// properly enabled on the system the container gets the same amount
119+
// of swap as is configured for memory. Thus, 2x{mem-limit} is the actual
120+
// memory and swap bound for this pre-test.
116121
DockerRunOptions preOpts =
117122
new DockerRunOptions(imageName, "/jdk/bin/java", "-version");
118123
preOpts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/")
119124
.addDockerOpts("--memory=" + value)
125+
.addJavaOpts("-XX:+AlwaysPreTouch")
120126
.addJavaOpts("-Xms" + value)
121127
.addJavaOpts("-Xmx" + value);
122128
OutputAnalyzer oa = DockerTestUtils.dockerRunJava(preOpts);
123129
String output = oa.getOutput();
124130
if (!output.contains("version")) {
125-
System.out.println("Swapping doesn't work for this test.");
126-
return;
131+
throw new SkippedException("Swapping doesn't work for this test.");
127132
}
128133

129134
DockerRunOptions opts =
@@ -137,8 +142,7 @@ private static void testMemoryFailCount(String value) throws Exception {
137142
oa = DockerTestUtils.dockerRunJava(opts);
138143
output = oa.getOutput();
139144
if (output.contains("Ignoring test")) {
140-
System.out.println("Ignored by the tester");
141-
return;
145+
throw new SkippedException("Ignored by the tester");
142146
}
143147
oa.shouldHaveExitValue(0).shouldContain("TEST PASSED!!!");
144148
}

0 commit comments

Comments
 (0)