Skip to content

Commit 04668a0

Browse files
[GR-35042] Improve JFR testing infrastructure.
PullRequest: graal/10927
2 parents b6af368 + 2de0cb2 commit 04668a0

27 files changed

+801
-169
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrChunkWriter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@
5454
* lock while they are paused at a safepoint.
5555
*/
5656
public final class JfrChunkWriter implements JfrUnlockedChunkWriter {
57-
private static final byte[] FILE_MAGIC = {'F', 'L', 'R', '\0'};
58-
private static final short JFR_VERSION_MAJOR = 2;
59-
private static final short JFR_VERSION_MINOR = 0;
57+
public static final byte[] FILE_MAGIC = {'F', 'L', 'R', '\0'};
58+
public static final short JFR_VERSION_MAJOR = 2;
59+
public static final short JFR_VERSION_MINOR = 0;
6060
private static final int CHUNK_SIZE_OFFSET = 8;
6161

62-
private static final long METADATA_TYPE_ID = 0;
63-
private static final long CONSTANT_POOL_TYPE_ID = 1;
62+
public static final long METADATA_TYPE_ID = 0;
63+
public static final long CONSTANT_POOL_TYPE_ID = 1;
6464

6565
private final JfrGlobalMemory globalMemory;
6666
private final ReentrantLock lock;

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/JFRTest.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2021, 2021, Red Hat Inc. All rights reserved.
34
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45
*
56
* This code is free software; you can redistribute it and/or modify it
@@ -22,19 +23,59 @@
2223
* or visit www.oracle.com if you need additional information or have any
2324
* questions.
2425
*/
26+
2527
package com.oracle.svm.test.jfr;
2628

29+
import static org.junit.Assert.assertNotNull;
2730
import static org.junit.Assume.assumeTrue;
2831

2932
import org.graalvm.nativeimage.ImageInfo;
33+
import org.junit.After;
34+
import org.junit.Assert;
35+
import org.junit.Before;
3036
import org.junit.BeforeClass;
3137

3238
import com.oracle.svm.core.jfr.JfrEnabled;
39+
import com.oracle.svm.test.jfr.utils.JFR;
40+
import com.oracle.svm.test.jfr.utils.JFRFileParser;
41+
import com.oracle.svm.test.jfr.utils.LocalJFR;
42+
43+
import jdk.jfr.Recording;
44+
import jdk.jfr.consumer.RecordingFile;
3345

3446
/** Base class for JFR unit tests. */
35-
public class JFRTest {
47+
public abstract class JFRTest {
48+
49+
protected JFR jfr;
50+
protected Recording recording;
51+
3652
@BeforeClass
3753
public static void checkForJFR() {
3854
assumeTrue("skipping JFR tests", !ImageInfo.inImageCode() || JfrEnabled.get());
3955
}
56+
57+
@Before
58+
public void startRecording() {
59+
try {
60+
jfr = new LocalJFR();
61+
recording = jfr.startRecording(getClass().getName());
62+
} catch (Exception e) {
63+
Assert.fail("Fail to start recording! Cause: " + e.getMessage());
64+
}
65+
}
66+
67+
@After
68+
public void endRecording() {
69+
try {
70+
jfr.endRecording(recording);
71+
try (RecordingFile recordingFile = new RecordingFile(recording.getDestination())) {
72+
assertNotNull(recordingFile);
73+
JFRFileParser.parse(recording);
74+
} finally {
75+
jfr.cleanupRecording(recording);
76+
}
77+
} catch (Exception e) {
78+
Assert.fail("Fail to stop recording! Cause: " + e.getMessage());
79+
}
80+
}
4081
}

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestClassEvent.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,15 @@
2626

2727
package com.oracle.svm.test.jfr;
2828

29-
import static org.junit.Assert.assertNotNull;
30-
29+
import com.oracle.svm.test.jfr.events.ClassEvent;
3130
import org.junit.Test;
3231

33-
import jdk.jfr.Recording;
34-
import jdk.jfr.consumer.RecordingFile;
35-
3632
public class TestClassEvent extends JFRTest {
33+
3734
@Test
3835
public void test() throws Exception {
39-
JFR jfr = new LocalJFR();
40-
Recording recording = jfr.startRecording("TestClassEvent");
41-
4236
ClassEvent event = new ClassEvent();
4337
event.clazz = TestClassEvent.class;
4438
event.commit();
45-
46-
jfr.endRecording(recording);
47-
try (RecordingFile recordingFile = new RecordingFile(recording.getDestination())) {
48-
assertNotNull(recordingFile);
49-
} finally {
50-
jfr.cleanupRecording(recording);
51-
}
5239
}
53-
5440
}

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestSingleEvent.java

Lines changed: 0 additions & 90 deletions
This file was deleted.

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestJFRCompiles.java renamed to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestStringEvent.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,15 @@
2626

2727
package com.oracle.svm.test.jfr;
2828

29+
import com.oracle.svm.test.jfr.events.StringEvent;
2930
import org.junit.Test;
3031

31-
import jdk.jfr.Recording;
32-
33-
public class TestJFRCompiles extends JFRTest {
32+
public class TestStringEvent extends JFRTest {
3433

3534
@Test
3635
public void test() throws Exception {
37-
JFR jfr = new LocalJFR();
38-
Recording recording = jfr.startRecording("TestSingleEvent");
39-
4036
StringEvent event = new StringEvent();
4137
event.message = "Event has been generated!";
4238
event.commit();
43-
44-
jfr.endRecording(recording);
45-
jfr.cleanupRecording(recording);
4639
}
4740
}

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestThreadEvent.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,18 @@
2626

2727
package com.oracle.svm.test.jfr;
2828

29-
import static org.junit.Assert.assertNotNull;
30-
29+
import com.oracle.svm.test.jfr.events.ThreadEvent;
3130
import org.junit.Test;
3231

33-
import jdk.jfr.Recording;
34-
import jdk.jfr.consumer.RecordingFile;
35-
3632
/**
3733
* Test if event ({@link TestThreadEvent}) with {@link Thread} payload is working.
3834
*/
3935
public class TestThreadEvent extends JFRTest {
4036

4137
@Test
4238
public void test() throws Exception {
43-
JFR jfr = new LocalJFR();
44-
Recording recording = jfr.startRecording("TestThreadEvent");
45-
4639
ThreadEvent event = new ThreadEvent();
4740
event.thread = Thread.currentThread();
4841
event.commit();
49-
50-
jfr.endRecording(recording);
51-
try (RecordingFile recordingFile = new RecordingFile(recording.getDestination())) {
52-
assertNotNull(recordingFile);
53-
} finally {
54-
jfr.cleanupRecording(recording);
55-
}
5642
}
5743
}

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/ClassEvent.java renamed to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/events/ClassEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* questions.
2525
*/
2626

27-
package com.oracle.svm.test.jfr;
27+
package com.oracle.svm.test.jfr.events;
2828

2929
import jdk.jfr.Description;
3030
import jdk.jfr.Event;

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/StringEvent.java renamed to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/events/StringEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* questions.
2525
*/
2626

27-
package com.oracle.svm.test.jfr;
27+
package com.oracle.svm.test.jfr.events;
2828

2929
import jdk.jfr.Description;
3030
import jdk.jfr.Event;

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/ThreadEvent.java renamed to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/events/ThreadEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* questions.
2525
*/
2626

27-
package com.oracle.svm.test.jfr;
27+
package com.oracle.svm.test.jfr.events;
2828

2929
import jdk.jfr.Description;
3030
import jdk.jfr.Event;

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/JFR.java renamed to substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/utils/JFR.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* questions.
2525
*/
2626

27-
package com.oracle.svm.test.jfr;
27+
package com.oracle.svm.test.jfr.utils;
2828

2929
import java.io.IOException;
3030

@@ -34,6 +34,7 @@
3434
* Utility class to handle recording.
3535
*/
3636
public interface JFR {
37+
3738
Recording startRecording(String recordingName) throws Exception;
3839

3940
Recording startRecording(String recordingName, String configName) throws Exception;

0 commit comments

Comments
 (0)