Skip to content

Commit c5751e6

Browse files
lutkerdPaul Hohensee
authored andcommitted
8229182: [TESTBUG] runtime/containers/docker/TestMemoryAwareness.java test fails on SLES12
Reviewed-by: phh Backport-of: a41b9a71acdf69b78104677a1ca899ff36293a60
1 parent 47090d6 commit c5751e6

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

hotspot/test/runtime/containers/docker/TestMemoryAwareness.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2019, 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
@@ -133,15 +133,26 @@ private static void testMemorySoftLimit(String valueToSet, String expectedTraceV
133133
private static void testOOM(String dockerMemLimit, int sizeToAllocInMb) throws Exception {
134134
Common.logNewTestCase("OOM");
135135

136+
// add "--memory-swappiness 0" so as to disable anonymous page swapping.
136137
DockerRunOptions opts = Common.newOpts(imageName, "AttemptOOM")
137-
.addDockerOpts("--memory", dockerMemLimit, "--memory-swap", dockerMemLimit);
138+
.addDockerOpts("--memory", dockerMemLimit, "--memory-swappiness", "0", "--memory-swap", dockerMemLimit);
138139
opts.classParams.add("" + sizeToAllocInMb);
139140

140-
DockerTestUtils.dockerRunJava(opts)
141-
.shouldHaveExitValue(1)
142-
.shouldContain("Entering AttemptOOM main")
143-
.shouldNotContain("AttemptOOM allocation successful")
144-
.shouldContain("java.lang.OutOfMemoryError");
141+
// make sure we avoid inherited Xmx settings from the jtreg vmoptions
142+
// set Xmx ourselves instead
143+
System.out.println("sizeToAllocInMb is:" + sizeToAllocInMb + " sizeToAllocInMb/2 is:" + sizeToAllocInMb/2);
144+
String javaHeapSize = sizeToAllocInMb/2 + "m";
145+
opts.addJavaOptsAppended("-Xmx" + javaHeapSize);
146+
147+
OutputAnalyzer out = DockerTestUtils.dockerRunJava(opts);
148+
149+
if (out.getExitValue() == 0) {
150+
throw new RuntimeException("We exited successfully, but we wanted to provoke an OOM inside the container");
151+
}
152+
153+
out.shouldContain("Entering AttemptOOM main")
154+
.shouldNotContain("AttemptOOM allocation successful")
155+
.shouldContain("java.lang.OutOfMemoryError");
145156
}
146157

147158
private static void testOperatingSystemMXBeanAwareness(String memoryAllocation, String expectedMemory,

hotspot/test/testlibrary/com/oracle/java/testlibrary/DockerRunOptions.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2019, 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
@@ -31,11 +31,13 @@
3131
// in test environment.
3232
public class DockerRunOptions {
3333
public String imageNameAndTag;
34-
public ArrayList<String> dockerOpts = new ArrayList<String>();
34+
public ArrayList<String> dockerOpts = new ArrayList<>();
3535
public String command; // normally a full path to java
36-
public ArrayList<String> javaOpts = new ArrayList<String>();
36+
public ArrayList<String> javaOpts = new ArrayList<>();
37+
// more java options, but to be set AFTER the test Java options
38+
public ArrayList<String> javaOptsAppended = new ArrayList<>();
3739
public String classToRun; // class or "-version"
38-
public ArrayList<String> classParams = new ArrayList<String>();
40+
public ArrayList<String> classParams = new ArrayList<>();
3941

4042
public boolean tty = true;
4143
public boolean removeContainerAfterUse = true;
@@ -70,4 +72,8 @@ public DockerRunOptions addJavaOpts(String... opts) {
7072
return this;
7173
}
7274

75+
public DockerRunOptions addJavaOptsAppended(String... opts) {
76+
Collections.addAll(javaOptsAppended, opts);
77+
return this;
78+
}
7379
}

hotspot/test/testlibrary/com/oracle/java/testlibrary/DockerTestUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ public static OutputAnalyzer dockerRunJava(DockerRunOptions opts) throws Excepti
198198
if (opts.appendTestJavaOptions) {
199199
Collections.addAll(cmd, Utils.getTestJavaOpts());
200200
}
201+
cmd.addAll(opts.javaOptsAppended);
201202

202203
cmd.add(opts.classToRun);
203204
cmd.addAll(opts.classParams);

0 commit comments

Comments
 (0)