Skip to content

Commit

Permalink
[fix,test] Make sure debug is initialized for timeout tests
Browse files Browse the repository at this point in the history
Added GraalCompilerTest.initializeForTimeout()
Call it from tests with a timeout (JUnit runs those on a different
thread).
  • Loading branch information
gilles-duboscq committed Jan 10, 2017
1 parent b0175e5 commit 3c054a0
Show file tree
Hide file tree
Showing 22 changed files with 77 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
*/
package org.graalvm.compiler.core.test;

import org.junit.Test;

import org.graalvm.compiler.common.RetryableBailoutException;
import org.graalvm.compiler.core.common.util.CompilationAlarm;
import org.graalvm.compiler.debug.GraalError;
Expand All @@ -32,6 +30,7 @@
import org.graalvm.compiler.options.OptionValue;
import org.graalvm.compiler.options.OptionValue.OverrideScope;
import org.graalvm.compiler.phases.Phase;
import org.junit.Test;

public class CooperativePhaseTest extends GraalCompilerTest {

Expand Down Expand Up @@ -101,6 +100,7 @@ private static void sleep(long millis) {
@Test(timeout = 60_000)
@SuppressWarnings("try")
public void test01() {
initializeForTimeout();
StructuredGraph g = parseEager("snippet", AllowAssumptions.NO);
try (OverrideScope o = OptionValue.override(CompilationAlarm.Options.CompilationExpirationPeriod, 1/* sec */);
CompilationAlarm c1 = CompilationAlarm.trackCompilationPeriod()) {
Expand All @@ -111,6 +111,7 @@ public void test01() {
@Test(expected = RetryableBailoutException.class, timeout = 60_000)
@SuppressWarnings("try")
public void test02() {
initializeForTimeout();
StructuredGraph g = parseEager("snippet", AllowAssumptions.NO);
try (OverrideScope o = OptionValue.override(CompilationAlarm.Options.CompilationExpirationPeriod, 1/* sec */);
CompilationAlarm c1 = CompilationAlarm.trackCompilationPeriod()) {
Expand All @@ -121,6 +122,7 @@ public void test02() {
@Test(timeout = 60_000)
@SuppressWarnings("try")
public void test03() {
initializeForTimeout();
StructuredGraph g = parseEager("snippet", AllowAssumptions.NO);
// 0 disables alarm utility
try (OverrideScope o = OptionValue.override(CompilationAlarm.Options.CompilationExpirationPeriod, 0);
Expand All @@ -132,6 +134,7 @@ public void test03() {
@Test(timeout = 60_000)
@SuppressWarnings("try")
public void test04() {
initializeForTimeout();
StructuredGraph g = parseEager("snippet", AllowAssumptions.NO);
new CooperativePhaseWithoutAlarm().apply(g);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@
import java.util.Set;
import java.util.function.Supplier;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.internal.AssumptionViolatedException;

import org.graalvm.compiler.api.directives.GraalDirectives;
import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
import org.graalvm.compiler.api.test.Graal;
Expand All @@ -62,8 +56,10 @@
import org.graalvm.compiler.debug.Debug;
import org.graalvm.compiler.debug.Debug.Scope;
import org.graalvm.compiler.debug.DebugDumpScope;
import org.graalvm.compiler.debug.DebugEnvironment;
import org.graalvm.compiler.debug.GraalError;
import org.graalvm.compiler.debug.TTY;
import org.graalvm.compiler.debug.internal.DebugScope;
import org.graalvm.compiler.graph.Node;
import org.graalvm.compiler.graph.NodeClass;
import org.graalvm.compiler.graph.NodeMap;
Expand Down Expand Up @@ -113,6 +109,11 @@
import org.graalvm.compiler.phases.util.Providers;
import org.graalvm.compiler.runtime.RuntimeProvider;
import org.graalvm.compiler.test.GraalTest;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.internal.AssumptionViolatedException;

import jdk.vm.ci.code.Architecture;
import jdk.vm.ci.code.BailoutException;
Expand Down Expand Up @@ -1202,4 +1203,15 @@ protected static boolean iterationCount(double i, boolean cond) {
protected boolean isArchitecture(String name) {
return name.equals(backend.getTarget().arch.getName());
}

/**
* This method should be called in "timeout" tests which JUnit runs in a different thread.
*/
public static void initializeForTimeout() {
if (Debug.isEnabled() && DebugScope.getConfig() == null) {
// timeout tests run in a separate thread which needs the DebugEnvironment to be
// initialized
DebugEnvironment.initialize(TTY.out);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

import org.graalvm.compiler.core.test.GraalCompilerTest;
import org.graalvm.compiler.debug.Debug;
import org.graalvm.compiler.debug.Debug.Scope;
Expand All @@ -48,6 +46,7 @@
import org.graalvm.compiler.phases.tiers.HighTierContext;
import org.graalvm.compiler.virtual.phases.ea.EarlyReadEliminationPhase;
import org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase;
import org.junit.Test;

import jdk.vm.ci.meta.ResolvedJavaMethod;
import sun.misc.Unsafe;
Expand Down Expand Up @@ -116,6 +115,7 @@ public void inlineDirectRecursiveLoopCallNoReads() {
}

private void testAndTime(String snippet) {
initializeForTimeout();
for (int i = IterationsStart; i < IterationsEnd; i++) {
StructuredGraph graph = getGraph(snippet, i);
long elapsed = runAndTimeEarlyReadEliminationPhase(graph);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
*/
package org.graalvm.compiler.jtt.hotspot;

import org.junit.Test;

import org.graalvm.compiler.jtt.JTTTest;
import org.junit.Test;

public class Test6959129 extends JTTTest {

Expand Down Expand Up @@ -76,6 +75,7 @@ public static long maxMoves(int min, int max) {

@Test(timeout = 20000)
public void run0() throws Throwable {
initializeForTimeout();
runTest("test");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
*/
package org.graalvm.compiler.jtt.threads;

import org.junit.Test;

import org.graalvm.compiler.jtt.JTTTest;
import org.junit.Test;

public final class Monitor_contended01 extends JTTTest {

Expand Down Expand Up @@ -77,6 +76,7 @@ public static boolean test() throws InterruptedException {

@Test(timeout = 20000)
public void run0() throws Throwable {
initializeForTimeout();
runTest("test");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
*/
package org.graalvm.compiler.jtt.threads;

import org.junit.Test;

import org.graalvm.compiler.jtt.JTTTest;
import org.junit.Test;

public class Monitor_notowner01 extends JTTTest {

Expand Down Expand Up @@ -66,6 +65,7 @@ public void run() {

@Test(timeout = 20000)
public void run0() throws Throwable {
initializeForTimeout();
runTest("test");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
*/
package org.graalvm.compiler.jtt.threads;

import org.junit.Test;

import org.graalvm.compiler.jtt.JTTTest;
import org.junit.Test;

public final class Monitorenter01 extends JTTTest {

Expand All @@ -43,6 +42,7 @@ public static boolean test() {

@Test(timeout = 20000)
public void run0() throws Throwable {
initializeForTimeout();
runTest("test");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
*/
package org.graalvm.compiler.jtt.threads;

import org.junit.Test;

import org.graalvm.compiler.jtt.JTTTest;
import org.junit.Test;

public final class Monitorenter02 extends JTTTest {

Expand All @@ -47,6 +46,7 @@ private static boolean test2() {

@Test(timeout = 20000)
public void run0() throws Throwable {
initializeForTimeout();
runTest("test");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
*/
package org.graalvm.compiler.jtt.threads;

import org.junit.Test;

import org.graalvm.compiler.jtt.JTTTest;
import org.junit.Test;

public class Object_wait01 extends JTTTest {

Expand Down Expand Up @@ -62,21 +61,25 @@ public static boolean test(int i) throws InterruptedException {

@Test(timeout = 20000)
public void run0() throws Throwable {
initializeForTimeout();
runTest("test", 0);
}

@Test(timeout = 20000)
public void run1() throws Throwable {
initializeForTimeout();
runTest("test", 1);
}

@Test(timeout = 20000)
public void run2() throws Throwable {
initializeForTimeout();
runTest("test", 3);
}

@Test(timeout = 20000)
public void run3() throws Throwable {
initializeForTimeout();
runTest("test", 15);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
*/
package org.graalvm.compiler.jtt.threads;

import org.junit.Test;

import org.graalvm.compiler.jtt.JTTTest;
import org.junit.Test;

public class Object_wait02 extends JTTTest {

Expand Down Expand Up @@ -63,16 +62,19 @@ public static boolean test(int i) throws InterruptedException {

@Test(timeout = 20000)
public void run0() throws Throwable {
initializeForTimeout();
runTest("test", 0);
}

@Test(timeout = 20000)
public void run1() throws Throwable {
initializeForTimeout();
runTest("test", 1);
}

@Test(timeout = 20000)
public void run2() throws Throwable {
initializeForTimeout();
runTest("test", 2);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
*/
package org.graalvm.compiler.jtt.threads;

import org.junit.Test;

import org.graalvm.compiler.jtt.JTTTest;
import org.junit.Test;

public class Object_wait03 extends JTTTest {

Expand Down Expand Up @@ -69,16 +68,19 @@ private static void dowait() throws InterruptedException {

@Test(timeout = 20000)
public void run0() throws Throwable {
initializeForTimeout();
runTest("test", 0);
}

@Test(timeout = 20000)
public void run1() throws Throwable {
initializeForTimeout();
runTest("test", 1);
}

@Test(timeout = 20000)
public void run2() throws Throwable {
initializeForTimeout();
runTest("test", 2);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
*/
package org.graalvm.compiler.jtt.threads;

import org.junit.Test;

import org.graalvm.compiler.jtt.JTTTest;
import org.junit.Test;

public class Object_wait04 extends JTTTest {

Expand Down Expand Up @@ -73,31 +72,37 @@ private static void dowait(int i) throws InterruptedException {

@Test(timeout = 20000)
public void run0() throws Throwable {
initializeForTimeout();
runTest("test", 0);
}

@Test(timeout = 20000)
public void run1() throws Throwable {
initializeForTimeout();
runTest("test", 1);
}

@Test(timeout = 20000)
public void run2() throws Throwable {
initializeForTimeout();
runTest("test", 2);
}

@Test(timeout = 20000)
public void run3() throws Throwable {
initializeForTimeout();
runTest("test", 3);
}

@Test(timeout = 20000)
public void run4() throws Throwable {
initializeForTimeout();
runTest("test", 4);
}

@Test(timeout = 20000)
public void run5() throws Throwable {
initializeForTimeout();
runTest("test", 5);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
*/
package org.graalvm.compiler.jtt.threads;

import org.junit.Test;

import org.graalvm.compiler.jtt.JTTTest;
import org.junit.Test;

/**
* Inspired by {@code com.sun.media.sound.DirectAudioDevice$DirectDL.drain()}.
Expand Down Expand Up @@ -55,6 +54,7 @@ public boolean test() {

@Test(timeout = 20000)
public void run0() throws Throwable {
initializeForTimeout();
runTest("test");
}

Expand Down
Loading

0 comments on commit 3c054a0

Please sign in to comment.