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 
@@ -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