# HG changeset patch # User mbaesken # Date 1566911326 -7200 # Tue Aug 27 15:08:46 2019 +0200 # Node ID c4426e4b8368f31b0b51bf3c0d9dee1bb2018490 # Parent dd0f6703203fba0484ae952d1c808473c593c1ac 8229182: runtime/containers/docker/TestMemoryAwareness.java test fails on SLES12 diff --git a/test/hotspot/jtreg/containers/docker/TestMemoryAwareness.java b/test/hotspot/jtreg/containers/docker/TestMemoryAwareness.java --- a/test/hotspot/jtreg/containers/docker/TestMemoryAwareness.java +++ b/test/hotspot/jtreg/containers/docker/TestMemoryAwareness.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2019, 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 @@ -37,7 +37,7 @@ import jdk.test.lib.containers.docker.Common; import jdk.test.lib.containers.docker.DockerRunOptions; import jdk.test.lib.containers.docker.DockerTestUtils; - +import jdk.test.lib.process.OutputAnalyzer; public class TestMemoryAwareness { private static final String imageName = Common.imageName("memory"); @@ -98,15 +98,26 @@ private static void testOOM(String dockerMemLimit, int sizeToAllocInMb) throws Exception { Common.logNewTestCase("OOM"); + // add "--memory-swappiness 0" so as to disable anonymous page swapping. DockerRunOptions opts = Common.newOpts(imageName, "AttemptOOM") - .addDockerOpts("--memory", dockerMemLimit, "--memory-swap", dockerMemLimit); + .addDockerOpts("--memory", dockerMemLimit, "--memory-swappiness", "0", "--memory-swap", dockerMemLimit); opts.classParams.add("" + sizeToAllocInMb); + // make sure we avoid inherited Xmx settings from the jtreg vmoptions + //opts.appendTestJavaOptions = false; + // set Xmx ourselves instead + System.out.println("sizeToAllocInMb is:" + sizeToAllocInMb + " sizeToAllocInMb/2 is:" + sizeToAllocInMb/2); + String javaHeapSize = sizeToAllocInMb/2 + "m"; + opts.addJavaOpts("-Xmx" + javaHeapSize); - DockerTestUtils.dockerRunJava(opts) - .shouldHaveExitValue(1) - .shouldContain("Entering AttemptOOM main") - .shouldNotContain("AttemptOOM allocation successful") - .shouldContain("java.lang.OutOfMemoryError"); + OutputAnalyzer out = DockerTestUtils.dockerRunJava(opts); + + if (out.getExitValue() == 0) { + throw new RuntimeException("We exited successfully, but we wanted to provoke an OOM inside the container"); + } + + out.shouldContain("Entering AttemptOOM main") + .shouldNotContain("AttemptOOM allocation successful") + .shouldContain("java.lang.OutOfMemoryError"); } } diff --git a/test/lib/jdk/test/lib/containers/docker/DockerTestUtils.java b/test/lib/jdk/test/lib/containers/docker/DockerTestUtils.java --- a/test/lib/jdk/test/lib/containers/docker/DockerTestUtils.java +++ b/test/lib/jdk/test/lib/containers/docker/DockerTestUtils.java @@ -208,10 +208,12 @@ cmd.add(opts.imageNameAndTag); cmd.add(opts.command); - cmd.addAll(opts.javaOpts); + // move after test java options + //cmd.addAll(opts.javaOpts); if (opts.appendTestJavaOptions) { Collections.addAll(cmd, Utils.getTestJavaOpts()); } + cmd.addAll(opts.javaOpts); cmd.add(opts.classToRun); cmd.addAll(opts.classParams);