diff options
author | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2014-03-12 16:02:45 +0100 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2014-04-09 16:35:30 +0200 |
commit | d010cef9d0f62b727a35140d470472ab8f8355f5 (patch) | |
tree | 00df7ddb33ca0be4028a43a1adc2fe1b908e2c24 /test/test/ContextEscapeDetection.java | |
parent | 6bc463df6a6ea8312390915a65024b11cfdd2b77 (diff) | |
download | dotty-d010cef9d0f62b727a35140d470472ab8f8355f5.tar.gz dotty-d010cef9d0f62b727a35140d470472ab8f8355f5.tar.bz2 dotty-d010cef9d0f62b727a35140d470472ab8f8355f5.zip |
Context escape detection.
During creation of each of DottyTests context is stolen from test and a
WeakReference for it is created.
After running all tests references are examined to detect if any of them
has leaked.
Diffstat (limited to 'test/test/ContextEscapeDetection.java')
-rw-r--r-- | test/test/ContextEscapeDetection.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/test/test/ContextEscapeDetection.java b/test/test/ContextEscapeDetection.java new file mode 100644 index 000000000..233630eb2 --- /dev/null +++ b/test/test/ContextEscapeDetection.java @@ -0,0 +1,40 @@ +package test; + +import dotty.tools.dotc.core.Contexts; +import org.junit.*; + +import java.lang.ref.WeakReference; +import java.util.LinkedList; +import java.util.List; + + +public abstract class ContextEscapeDetection { + public static class TestContext{ + public TestContext(WeakReference<Contexts.Context> context, String testName) { + this.context = context; + this.testName = testName; + } + + public final WeakReference<Contexts.Context> context; + public final String testName; + + } + public static final List<TestContext> contexts = new LinkedList<>(); + + public abstract Contexts.Context getCtx(); + + public abstract void clearCtx(); + + @Before + public synchronized void stealContext() { + contexts.add(new TestContext(new WeakReference<>(this.getCtx()), this.getClass().getName())); + } + + @After + public synchronized void clearContext() { + this.clearCtx(); + } + + +} + |