diff --git a/src/test/java/com/aparapi/runtime/AtomicsSupportAdvTest.java b/src/test/java/com/aparapi/runtime/AtomicsSupportAdvTest.java index e9daf33a7546a3bf499890fee0b8366588a776ea..94a8a62cab03ce6708cf92c025b8e939a158e2a5 100644 --- a/src/test/java/com/aparapi/runtime/AtomicsSupportAdvTest.java +++ b/src/test/java/com/aparapi/runtime/AtomicsSupportAdvTest.java @@ -24,7 +24,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.AfterClass; +import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -76,8 +76,8 @@ public class AtomicsSupportAdvTest { openCLDevice = (OpenCLDevice) device; } - @AfterClass - public static void classTeardown() { + @After + public void classTeardown() { Util.resetKernelManager(); } diff --git a/src/test/java/com/aparapi/runtime/AtomicsSupportTest.java b/src/test/java/com/aparapi/runtime/AtomicsSupportTest.java index ef9bd22f0928547120453a37f3fec06a23e5f2e3..b7aca3cc7210163644e4020652f61f7e4b1074e3 100644 --- a/src/test/java/com/aparapi/runtime/AtomicsSupportTest.java +++ b/src/test/java/com/aparapi/runtime/AtomicsSupportTest.java @@ -23,7 +23,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.AfterClass; +import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -61,8 +61,8 @@ public class AtomicsSupportTest { } } - @AfterClass - public static void classTeardown() { + @After + public void classTeardown() { Util.resetKernelManager(); } diff --git a/src/test/java/com/aparapi/runtime/LocalArrayArgsTest.java b/src/test/java/com/aparapi/runtime/LocalArrayArgsTest.java index 3f5e805269884fa4dd9bc6adbf928678d3bc92e0..2ea3ba7b4318ea6d816a3e1cf44b1898b665293e 100644 --- a/src/test/java/com/aparapi/runtime/LocalArrayArgsTest.java +++ b/src/test/java/com/aparapi/runtime/LocalArrayArgsTest.java @@ -24,6 +24,7 @@ import com.aparapi.internal.kernel.KernelManager; import static org.junit.Assert.*; import static org.junit.Assume.*; +import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -39,6 +40,12 @@ public class LocalArrayArgsTest { openCLDevice = (OpenCLDevice) device; } + @After + public void classTeardown() { + Util.resetKernelManager(); + } + + @Test public void test() { final LocalArrayArgsKernel kernel = new LocalArrayArgsKernel(); diff --git a/src/test/java/com/aparapi/runtime/MultiDimensionalLocalArrayTest.java b/src/test/java/com/aparapi/runtime/MultiDimensionalLocalArrayTest.java index 7eb5461c9c47ebc7122ca10f90b085fed61468ad..1173cdce307858018314d7fec6bd6094862e40de 100644 --- a/src/test/java/com/aparapi/runtime/MultiDimensionalLocalArrayTest.java +++ b/src/test/java/com/aparapi/runtime/MultiDimensionalLocalArrayTest.java @@ -22,7 +22,7 @@ import java.util.Arrays; import java.util.LinkedHashSet; import java.util.List; -import org.junit.AfterClass; +import org.junit.After; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -61,8 +61,8 @@ public class MultiDimensionalLocalArrayTest } } - @AfterClass - public static void classTeardown() { + @After + public void classTeardown() { Util.resetKernelManager(); } diff --git a/src/test/java/com/aparapi/runtime/NegativeIntegerTest.java b/src/test/java/com/aparapi/runtime/NegativeIntegerTest.java index 183bc772d2ab1c0f3f08d3281261f8aaca28727c..8cd9a5405601e608c24796bf2b0884dbed8d3250 100644 --- a/src/test/java/com/aparapi/runtime/NegativeIntegerTest.java +++ b/src/test/java/com/aparapi/runtime/NegativeIntegerTest.java @@ -21,7 +21,7 @@ import static org.junit.Assume.assumeTrue; import java.util.Arrays; import java.util.List; -import org.junit.AfterClass; +import org.junit.After; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -59,8 +59,8 @@ public class NegativeIntegerTest openCLDevice = (OpenCLDevice) device; } - @AfterClass - public static void classTeardown() { + @After + public void classTeardown() { Util.resetKernelManager(); } diff --git a/src/test/java/com/aparapi/runtime/ProfileReportBackwardsCompatTest.java b/src/test/java/com/aparapi/runtime/ProfileReportBackwardsCompatTest.java index 8ec24e314fe9294454e82a86e8a775aca4fee616..180fdc45d41192e17e092345259a958a47554248 100644 --- a/src/test/java/com/aparapi/runtime/ProfileReportBackwardsCompatTest.java +++ b/src/test/java/com/aparapi/runtime/ProfileReportBackwardsCompatTest.java @@ -78,7 +78,7 @@ public class ProfileReportBackwardsCompatTest { return Arrays.asList(Device.TYPE.JTP); } } - + @After public void classTeardown() { Util.resetKernelManager(); @@ -149,6 +149,7 @@ public class ProfileReportBackwardsCompatTest { assertEquals("Test estimated accumulated time doesn't match within 500ms window", runTime, accumulatedExecutionTime, 500); assertTrue(validateBasic1Kernel(inputArray, outputArray)); } finally { + kernel.registerProfileReportObserver(null); kernel.dispose(); } @@ -250,6 +251,8 @@ public class ProfileReportBackwardsCompatTest { assertEquals("Test estimated accumulated time doesn't match within 300ms window", results[1].runTime, results[1].accumulatedExecutionTime, 300); assertTrue(validateBasic2Kernel(inputArray, results[1].outputArray)); } finally { + kernel1.registerProfileReportObserver(null); + kernel2.registerProfileReportObserver(null); kernel1.dispose(); kernel2.dispose(); } diff --git a/src/test/java/com/aparapi/runtime/ProfileReportNewAPITest.java b/src/test/java/com/aparapi/runtime/ProfileReportNewAPITest.java index 7c25051a5ddafab9509b02142e21ce0099445410..21daa4d3d8f808bdeb6d841cc8726e748cddd591 100644 --- a/src/test/java/com/aparapi/runtime/ProfileReportNewAPITest.java +++ b/src/test/java/com/aparapi/runtime/ProfileReportNewAPITest.java @@ -208,6 +208,7 @@ public class ProfileReportNewAPITest { } assertTrue(validateBasic1Kernel(inputArray, outputArray)); } finally { + kernel.registerProfileReportObserver(null); kernel.dispose(); } @@ -276,6 +277,9 @@ public class ProfileReportNewAPITest { future.get(); } } finally { + for (Basic1Kernel k : kernels) { + k.registerProfileReportObserver(null); + } executorService.shutdown(); try { terminatedOk = executorService.awaitTermination(1, TimeUnit.MINUTES); diff --git a/src/test/java/com/aparapi/runtime/ProfileReportUnitTest.java b/src/test/java/com/aparapi/runtime/ProfileReportUnitTest.java index 8e9a297ff38c485b6d1bed4b3aa3f10b898826f6..f65411c82bb7edec156be0329092969eb73954fd 100644 --- a/src/test/java/com/aparapi/runtime/ProfileReportUnitTest.java +++ b/src/test/java/com/aparapi/runtime/ProfileReportUnitTest.java @@ -87,34 +87,38 @@ public class ProfileReportUnitTest { ExecutorService executorService = Executors.newFixedThreadPool(javaThreads); try { - events.forEach(evt -> { - final int idx = index.getAndIncrement(); - executorService.submit(() -> { - threadIds[idx] = Thread.currentThread().getId(); - kernelDeviceProfile.onEvent(ProfilingEvent.START); - kernelDeviceProfile.onEvent(ProfilingEvent.EXECUTED); + try { + events.forEach(evt -> { + final int idx = index.getAndIncrement(); + executorService.submit(() -> { + threadIds[idx] = Thread.currentThread().getId(); + kernelDeviceProfile.onEvent(ProfilingEvent.START); + kernelDeviceProfile.onEvent(ProfilingEvent.EXECUTED); + }); }); - }); - } finally { - executorService.shutdown(); - if (!executorService.awaitTermination(1, TimeUnit.MINUTES)) { - executorService.shutdownNow(); - throw new IllegalStateException("ExecutorService terminated abnormaly"); + } finally { + executorService.shutdown(); + if (!executorService.awaitTermination(1, TimeUnit.MINUTES)) { + executorService.shutdownNow(); + throw new IllegalStateException("ExecutorService terminated abnormaly"); + } } + + threadIds[index.get()] = Thread.currentThread().getId(); + for (int i = 0; i < javaThreads; i++) { + assertTrue("Report wasn't received for thread with index " + i, onEventAccepted.contains(threadIds[i])); + } + assertFalse("Report was received for main thread", onEventAccepted.contains(threadIds[javaThreads])); + assertEquals("Reports from all threads should have been received", javaThreads, receivedReports.get()); + + //Only after this event should the main thread have received a report + kernelDeviceProfile.onEvent(ProfilingEvent.EXECUTED); + + assertTrue("Report wasn't received for main thread", onEventAccepted.contains(threadIds[javaThreads])); + assertEquals("Reports from all threads should have been received", javaThreads + 1, receivedReports.get()); + } finally { + kernelProfile.setReportObserver(null); } - - threadIds[index.get()] = Thread.currentThread().getId(); - for (int i = 0; i < javaThreads; i++) { - assertTrue("Report wasn't received for thread with index " + i, onEventAccepted.contains(threadIds[i])); - } - assertFalse("Report was received for main thread", onEventAccepted.contains(threadIds[javaThreads])); - assertEquals("Reports from all threads should have been received", javaThreads, receivedReports.get()); - - //Only after this event should the main thread have received a report - kernelDeviceProfile.onEvent(ProfilingEvent.EXECUTED); - - assertTrue("Report wasn't received for main thread", onEventAccepted.contains(threadIds[javaThreads])); - assertEquals("Reports from all threads should have been received", javaThreads + 1, receivedReports.get()); } @Test