27
27
* @summary Memory/CPU awareness test for JDK-under-test inside a systemd slice.
28
28
* @requires systemd.support
29
29
* @library /test/lib
30
- * @build HelloSystemd
31
- * @run driver SystemdMemoryAwarenessTest
30
+ * @build HelloSystemd jdk.test.whitebox.WhiteBox
31
+ * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar whitebox.jar jdk.test.whitebox.WhiteBox
32
+ * @run main/othervm -Xbootclasspath/a:whitebox.jar -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI SystemdMemoryAwarenessTest
32
33
*/
33
34
import java .nio .file .Files ;
34
35
import java .nio .file .NoSuchFileException ;
36
+ import jdk .test .whitebox .WhiteBox ;
35
37
import jdk .test .lib .containers .systemd .SystemdRunOptions ;
36
38
import jdk .test .lib .containers .systemd .SystemdTestUtils ;
37
39
import jdk .test .lib .containers .systemd .SystemdTestUtils .ResultFiles ;
38
40
39
41
40
42
public class SystemdMemoryAwarenessTest {
41
43
44
+ private static final WhiteBox wb = WhiteBox .getWhiteBox ();
45
+
42
46
public static void main (String [] args ) throws Exception {
43
47
testHelloSystemd ();
44
48
}
45
49
46
50
private static void testHelloSystemd () throws Exception {
47
51
SystemdRunOptions opts = SystemdTestUtils .newOpts ("HelloSystemd" );
48
- // 1 GB memory and 2 cores CPU
49
- opts .memoryLimit ("1000M" ).cpuLimit ("200%" );
52
+ // 1 GB memory
53
+ opts .memoryLimit ("1000M" );
54
+ int physicalCpus = wb .hostCPUs ();
55
+ if (physicalCpus < 3 ) {
56
+ System .err .println ("WARNING: host system only has " + physicalCpus + " expected >= 3" );
57
+ }
58
+ // 1 or 2 cores limit depending on physical CPUs
59
+ int coreLimit = Math .min (physicalCpus , 2 );
60
+ System .out .println ("DEBUG: Running test with a CPU limit of " + coreLimit );
61
+ opts .cpuLimit (String .format ("%d%%" , coreLimit * 100 ));
50
62
opts .sliceName (SystemdMemoryAwarenessTest .class .getSimpleName ());
51
63
52
64
ResultFiles files = SystemdTestUtils .buildSystemdSlices (opts );
@@ -55,7 +67,7 @@ private static void testHelloSystemd() throws Exception {
55
67
SystemdTestUtils .systemdRunJava (opts )
56
68
.shouldHaveExitValue (0 )
57
69
.shouldContain ("Hello Systemd" )
58
- .shouldContain ("OSContainer::active_processor_count: 2" )
70
+ .shouldContain ("OSContainer::active_processor_count: " + coreLimit )
59
71
.shouldContain ("Memory Limit is: 1048576000" ); // 1 GB
60
72
} finally {
61
73
try {
0 commit comments