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
2727import jdk .test .lib .containers .docker .DockerRunOptions ;
2828import jdk .test .lib .containers .docker .DockerTestUtils ;
2929import jdk .test .lib .process .OutputAnalyzer ;
30+ import jtreg .SkippedException ;
3031
3132/*
3233 * @test
@@ -111,18 +112,22 @@ private static void testMemoryFailCount(String value) throws Exception {
111112
112113 // Check whether swapping really works for this test
113114 // 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+ // 'java -Xms{mem-limit} -Xmx{mem-limit} -XX:+AlwaysPreTouch -version'
116+ // would fail due to swap space size being 0. Note that when swap is
117+ // properly enabled on the system the container gets the same amount
118+ // of swap as is configured for memory. Thus, 2x{mem-limit} is the actual
119+ // memory and swap bound for this pre-test.
115120 DockerRunOptions preOpts =
116121 new DockerRunOptions (imageName , "/jdk/bin/java" , "-version" );
117122 preOpts .addDockerOpts ("--volume" , Utils .TEST_CLASSES + ":/test-classes/" )
118123 .addDockerOpts ("--memory=" + value )
124+ .addJavaOpts ("-XX:+AlwaysPreTouch" )
119125 .addJavaOpts ("-Xms" + value )
120126 .addJavaOpts ("-Xmx" + value );
121127 OutputAnalyzer oa = DockerTestUtils .dockerRunJava (preOpts );
122128 String output = oa .getOutput ();
123129 if (!output .contains ("version" )) {
124- System .out .println ("Swapping doesn't work for this test." );
125- return ;
130+ throw new SkippedException ("Swapping doesn't work for this test." );
126131 }
127132
128133 DockerRunOptions opts =
@@ -136,8 +141,7 @@ private static void testMemoryFailCount(String value) throws Exception {
136141 oa = DockerTestUtils .dockerRunJava (opts );
137142 output = oa .getOutput ();
138143 if (output .contains ("Ignoring test" )) {
139- System .out .println ("Ignored by the tester" );
140- return ;
144+ throw new SkippedException ("Ignored by the tester" );
141145 }
142146 oa .shouldHaveExitValue (0 ).shouldContain ("TEST PASSED!!!" );
143147 }
0 commit comments