1 /* |
1 /* |
2 * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
25 |
26 package jdk.jfr.event.runtime; |
26 package jdk.jfr.event.runtime; |
27 |
27 |
28 |
|
29 |
|
30 import java.lang.management.ManagementFactory; |
28 import java.lang.management.ManagementFactory; |
31 import java.lang.management.RuntimeMXBean; |
29 import java.lang.management.RuntimeMXBean; |
|
30 import java.nio.file.Files; |
|
31 import java.nio.file.Paths; |
32 import java.util.List; |
32 import java.util.List; |
33 import java.util.stream.Collectors; |
33 import java.util.stream.Collectors; |
34 |
34 |
35 import jdk.jfr.Recording; |
35 import jdk.jfr.Recording; |
36 import jdk.jfr.consumer.RecordedEvent; |
36 import jdk.jfr.consumer.RecordedEvent; |
37 import jdk.test.lib.Asserts; |
37 import jdk.test.lib.Asserts; |
38 import jdk.test.lib.jfr.EventNames; |
38 import jdk.test.lib.jfr.EventNames; |
39 import jdk.test.lib.jfr.Events; |
39 import jdk.test.lib.jfr.Events; |
40 |
40 |
41 /** |
41 /** |
42 * The test will verify that JVM Information event values are delivered |
42 * @test |
43 * and compare them with the RuntimeMXBean's values. |
43 * @key jfr |
|
44 * @requires vm.hasJFR |
|
45 * @library /test/lib |
|
46 * @run driver jdk.jfr.event.runtime.TestVMInfoEvent generateFlagsFile |
|
47 * @run main/othervm -XX:Flags=TestVMInfoEvent.flags -Xmx500m jdk.jfr.event.runtime.TestVMInfoEvent arg1 arg2 |
44 */ |
48 */ |
45 public class TestVMInfoEvent { |
49 public class TestVMInfoEvent { |
46 private final static String EVENT_NAME = EventNames.JVMInformation; |
50 private final static String EVENT_NAME = EventNames.JVMInformation; |
47 |
51 |
48 public static void main(String[] args) throws Exception { |
52 public static void main(String[] args) throws Exception { |
|
53 if( (args.length > 0) && ("generateFlagsFile".equals(args[0])) ) { |
|
54 generateFlagsFile(); |
|
55 return; |
|
56 } |
49 RuntimeMXBean mbean = ManagementFactory.getRuntimeMXBean(); |
57 RuntimeMXBean mbean = ManagementFactory.getRuntimeMXBean(); |
50 Recording recording = new Recording(); |
58 Recording recording = new Recording(); |
51 recording.enable(EVENT_NAME); |
59 recording.enable(EVENT_NAME); |
52 recording.start(); |
60 recording.start(); |
53 recording.stop(); |
61 recording.stop(); |
74 Events.assertField(event, "javaArguments").equal(javaCommand); |
82 Events.assertField(event, "javaArguments").equal(javaCommand); |
75 Events.assertField(event, "jvmStartTime").equal(mbean.getStartTime()); |
83 Events.assertField(event, "jvmStartTime").equal(mbean.getStartTime()); |
76 } |
84 } |
77 } |
85 } |
78 |
86 |
|
87 public static void generateFlagsFile() throws Exception { |
|
88 Files.writeString(Paths.get("", "TestVMInfoEvent.flags"), "+UseSerialGC"); |
|
89 } |
79 } |
90 } |