Skip to content

Commit

Permalink
[GR-35042] Improve JFR testing infrastructure.
Browse files Browse the repository at this point in the history
PullRequest: graal/10927
  • Loading branch information
jovanstevanovic committed Feb 2, 2022
2 parents b6af368 + 2de0cb2 commit 04668a0
Show file tree
Hide file tree
Showing 27 changed files with 801 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@
* lock while they are paused at a safepoint.
*/
public final class JfrChunkWriter implements JfrUnlockedChunkWriter {
private static final byte[] FILE_MAGIC = {'F', 'L', 'R', '\0'};
private static final short JFR_VERSION_MAJOR = 2;
private static final short JFR_VERSION_MINOR = 0;
public static final byte[] FILE_MAGIC = {'F', 'L', 'R', '\0'};
public static final short JFR_VERSION_MAJOR = 2;
public static final short JFR_VERSION_MINOR = 0;
private static final int CHUNK_SIZE_OFFSET = 8;

private static final long METADATA_TYPE_ID = 0;
private static final long CONSTANT_POOL_TYPE_ID = 1;
public static final long METADATA_TYPE_ID = 0;
public static final long CONSTANT_POOL_TYPE_ID = 1;

private final JfrGlobalMemory globalMemory;
private final ReentrantLock lock;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2021, Red Hat Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -22,19 +23,59 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package com.oracle.svm.test.jfr;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assume.assumeTrue;

import org.graalvm.nativeimage.ImageInfo;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;

import com.oracle.svm.core.jfr.JfrEnabled;
import com.oracle.svm.test.jfr.utils.JFR;
import com.oracle.svm.test.jfr.utils.JFRFileParser;
import com.oracle.svm.test.jfr.utils.LocalJFR;

import jdk.jfr.Recording;
import jdk.jfr.consumer.RecordingFile;

/** Base class for JFR unit tests. */
public class JFRTest {
public abstract class JFRTest {

protected JFR jfr;
protected Recording recording;

@BeforeClass
public static void checkForJFR() {
assumeTrue("skipping JFR tests", !ImageInfo.inImageCode() || JfrEnabled.get());
}

@Before
public void startRecording() {
try {
jfr = new LocalJFR();
recording = jfr.startRecording(getClass().getName());
} catch (Exception e) {
Assert.fail("Fail to start recording! Cause: " + e.getMessage());
}
}

@After
public void endRecording() {
try {
jfr.endRecording(recording);
try (RecordingFile recordingFile = new RecordingFile(recording.getDestination())) {
assertNotNull(recordingFile);
JFRFileParser.parse(recording);
} finally {
jfr.cleanupRecording(recording);
}
} catch (Exception e) {
Assert.fail("Fail to stop recording! Cause: " + e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,15 @@

package com.oracle.svm.test.jfr;

import static org.junit.Assert.assertNotNull;

import com.oracle.svm.test.jfr.events.ClassEvent;
import org.junit.Test;

import jdk.jfr.Recording;
import jdk.jfr.consumer.RecordingFile;

public class TestClassEvent extends JFRTest {

@Test
public void test() throws Exception {
JFR jfr = new LocalJFR();
Recording recording = jfr.startRecording("TestClassEvent");

ClassEvent event = new ClassEvent();
event.clazz = TestClassEvent.class;
event.commit();

jfr.endRecording(recording);
try (RecordingFile recordingFile = new RecordingFile(recording.getDestination())) {
assertNotNull(recordingFile);
} finally {
jfr.cleanupRecording(recording);
}
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,15 @@

package com.oracle.svm.test.jfr;

import com.oracle.svm.test.jfr.events.StringEvent;
import org.junit.Test;

import jdk.jfr.Recording;

public class TestJFRCompiles extends JFRTest {
public class TestStringEvent extends JFRTest {

@Test
public void test() throws Exception {
JFR jfr = new LocalJFR();
Recording recording = jfr.startRecording("TestSingleEvent");

StringEvent event = new StringEvent();
event.message = "Event has been generated!";
event.commit();

jfr.endRecording(recording);
jfr.cleanupRecording(recording);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,18 @@

package com.oracle.svm.test.jfr;

import static org.junit.Assert.assertNotNull;

import com.oracle.svm.test.jfr.events.ThreadEvent;
import org.junit.Test;

import jdk.jfr.Recording;
import jdk.jfr.consumer.RecordingFile;

/**
* Test if event ({@link TestThreadEvent}) with {@link Thread} payload is working.
*/
public class TestThreadEvent extends JFRTest {

@Test
public void test() throws Exception {
JFR jfr = new LocalJFR();
Recording recording = jfr.startRecording("TestThreadEvent");

ThreadEvent event = new ThreadEvent();
event.thread = Thread.currentThread();
event.commit();

jfr.endRecording(recording);
try (RecordingFile recordingFile = new RecordingFile(recording.getDestination())) {
assertNotNull(recordingFile);
} finally {
jfr.cleanupRecording(recording);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* questions.
*/

package com.oracle.svm.test.jfr;
package com.oracle.svm.test.jfr.events;

import jdk.jfr.Description;
import jdk.jfr.Event;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* questions.
*/

package com.oracle.svm.test.jfr;
package com.oracle.svm.test.jfr.events;

import jdk.jfr.Description;
import jdk.jfr.Event;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* questions.
*/

package com.oracle.svm.test.jfr;
package com.oracle.svm.test.jfr.events;

import jdk.jfr.Description;
import jdk.jfr.Event;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* questions.
*/

package com.oracle.svm.test.jfr;
package com.oracle.svm.test.jfr.utils;

import java.io.IOException;

Expand All @@ -34,6 +34,7 @@
* Utility class to handle recording.
*/
public interface JFR {

Recording startRecording(String recordingName) throws Exception;

Recording startRecording(String recordingName, String configName) throws Exception;
Expand Down
Loading

0 comments on commit 04668a0

Please sign in to comment.