Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from JUnit 4 to JUnit 5 #353

Open
wants to merge 20 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
4845f0c
Merge pull request #347 from jjfumero/fix/examples
jjfumero Mar 7, 2024
c27eea8
Refactor TornadoHelper in unit tests for optimization.
mikepapadim Mar 17, 2024
18b4468
Remove junit-vintage-engine dependency from pom.xml
mikepapadim Mar 17, 2024
343e8d9
Refactor TestBatches for Junit5
mikepapadim Mar 18, 2024
f601427
fix merge
mikepapadim Mar 19, 2024
5da10da
Fix merge conflicts
mikepapadim Mar 21, 2024
a674053
Fix merge conflicts
mikepapadim Mar 21, 2024
84e6826
Merge remote-tracking branch 'oss/develop' into mikepapadim/junit5
mikepapadim Apr 16, 2024
2aadad4
Update unit tests to use JUnit 5
mikepapadim Apr 16, 2024
80e9825
Merge branch 'develop' of github.com:beehive-lab/TornadoVM into mikep…
mikepapadim Apr 16, 2024
a176e55
Merge branch 'develop' into mikepapadim/junit5
mikepapadim Apr 23, 2024
c0d9a2c
Partial fix for segfaults in OpenCL
mikepapadim Apr 23, 2024
8520559
Refactor memory allocation and test methods
mikepapadim Apr 23, 2024
1b50d07
Merge branch 'develop' into mikepapadim/junit5
mikepapadim Apr 29, 2024
3d25f40
Migrate unit tests to JUnit5
mikepapadim Apr 29, 2024
582228e
Fix PTX code cache using an invalid module
gigiblender May 20, 2024
1533ff4
Merge branch 'develop' of github.com:beehive-lab/TornadoVM into mikep…
mikepapadim May 21, 2024
d4ee6c3
Merge branch 'develop' of github.com:beehive-lab/TornadoVM into mikep…
mikepapadim Sep 3, 2024
c7960a1
Update JUnit versions in POM files
mikepapadim Sep 3, 2024
0214abc
Switch from JUnit 4 to JUnit 5 and refactor asserts
mikepapadim Sep 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<jmh.version>1.29</jmh.version>
<tornadojmhjar.name>jmhbenchmarks</tornadojmhjar.name>
<checkstyle.config.location>tornado-assembly/src/etc/checkstyle.xml</checkstyle.config.location>
<junit.jupiter.version>5.11.0</junit.jupiter.version>
<junit.platform.version>1.11.0</junit.platform.version>
</properties>

<profiles>
Expand Down Expand Up @@ -2039,9 +2041,19 @@
<version>10.12.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>${junit.platform.version}</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public OCLMemorySegmentWrapper(long bufferSize, OCLDeviceContext deviceContext,
this.bufferSize = bufferSize;
this.bufferId = INIT_VALUE;
this.bufferOffset = 0;
onDevice = false;
onDevice = false;
}

@Override
Expand Down Expand Up @@ -160,13 +160,14 @@ public List<Integer> enqueueWrite(long executionPlanId, Object reference, long b
MemorySegment segment;
segment = getSegmentWithHeader(reference);

final long numBytes = getSizeSubRegionSize() > 0 ? getSizeSubRegionSize() : bufferSize;
int internalEvent;
if (batchSize <= 0) {
internalEvent = deviceContext.enqueueWriteBuffer(executionPlanId, toBuffer(), bufferOffset, bufferSize, segment.address(), hostOffset, (useDeps) ? events : null);
internalEvent = deviceContext.enqueueWriteBuffer(executionPlanId, toBuffer(), bufferOffset, numBytes, segment.address(), hostOffset, (useDeps) ? events : null);
} else {
internalEvent = deviceContext.enqueueWriteBuffer(executionPlanId, toBuffer(), 0, TornadoNativeArray.ARRAY_HEADER, segment.address(), 0, (useDeps) ? events : null);
returnEvents.add(internalEvent);
internalEvent = deviceContext.enqueueWriteBuffer(executionPlanId, toBuffer(), bufferOffset + TornadoNativeArray.ARRAY_HEADER, bufferSize, segment.address(),
internalEvent = deviceContext.enqueueWriteBuffer(executionPlanId, toBuffer(), bufferOffset + TornadoNativeArray.ARRAY_HEADER, numBytes, segment.address(),
hostOffset + TornadoNativeArray.ARRAY_HEADER, (useDeps) ? events : null);
}
returnEvents.add(internalEvent);
Expand All @@ -184,7 +185,7 @@ public void allocate(Object reference, long batchSize) throws TornadoOutOfMemory
bufferId = deviceContext.getBufferProvider().getOrAllocateBufferWithSize(bufferSize);
} else {
bufferSize = batchSize;
bufferId = deviceContext.getBufferProvider().getOrAllocateBufferWithSize(bufferSize + TornadoNativeArray.ARRAY_HEADER);
bufferId = deviceContext.getBufferProvider().getOrAllocateBufferWithSize(batchSize + TornadoNativeArray.ARRAY_HEADER);
}

if (bufferSize <= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public PTXCodeCache(PTXDeviceContext deviceContext) {

public PTXInstalledCode installSource(String name, byte[] targetCode, String resolvedMethodName, boolean debugKernel) {

if (!cache.containsKey(name)) {
PTXInstalledCode installedCode = cache.get(name);
if (installedCode == null || !installedCode.isValid()) {
if (debugKernel) {
RuntimeUtilities.dumpKernel(targetCode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,12 @@ public void write(long executionPlanId, Object reference) {
public int enqueueRead(long executionPlanId, Object reference, long hostOffset, int[] events, boolean useDeps) {
MemorySegment segment = getSegmentWithHeader(reference);

final long numBytes = getSizeSubRegionSize() > 0 ? getSizeSubRegionSize() : bufferSize;
final int returnEvent;
if (batchSize <= 0) {
returnEvent = deviceContext.enqueueReadBuffer(executionPlanId, toBuffer(), bufferSize, segment.address(), hostOffset, (useDeps) ? events : null);
} else {
returnEvent = deviceContext.enqueueReadBuffer(executionPlanId, toBuffer() + TornadoNativeArray.ARRAY_HEADER, bufferSize - TornadoNativeArray.ARRAY_HEADER, segment.address(), hostOffset,
returnEvent = deviceContext.enqueueReadBuffer(executionPlanId, toBuffer() + TornadoNativeArray.ARRAY_HEADER, numBytes, segment.address(), hostOffset,
(useDeps) ? events : null);
}
return useDeps ? returnEvent : -1;
Expand All @@ -157,13 +158,14 @@ public List<Integer> enqueueWrite(long executionPlanId, Object reference, long b

MemorySegment segment = getSegmentWithHeader(reference);

final long numBytes = getSizeSubRegionSize() > 0 ? getSizeSubRegionSize() : bufferSize;
int internalEvent;
if (batchSize <= 0) {
internalEvent = deviceContext.enqueueWriteBuffer(executionPlanId, toBuffer(), bufferSize, segment.address(), hostOffset, (useDeps) ? events : null);
internalEvent = deviceContext.enqueueWriteBuffer(executionPlanId, toBuffer(), numBytes, segment.address(), hostOffset, (useDeps) ? events : null);
} else {
internalEvent = deviceContext.enqueueWriteBuffer(executionPlanId, toBuffer(), TornadoNativeArray.ARRAY_HEADER, segment.address(), 0, (useDeps) ? events : null);
returnEvents.add(internalEvent);
internalEvent = deviceContext.enqueueWriteBuffer(executionPlanId, toBuffer() + TornadoNativeArray.ARRAY_HEADER, bufferSize, segment.address(), hostOffset + TornadoNativeArray.ARRAY_HEADER,
internalEvent = deviceContext.enqueueWriteBuffer(executionPlanId, toBuffer() + TornadoNativeArray.ARRAY_HEADER, numBytes, segment.address(), hostOffset + TornadoNativeArray.ARRAY_HEADER,
(useDeps) ? events : null);
}
returnEvents.add(internalEvent);
Expand Down
38 changes: 32 additions & 6 deletions tornado-unittests/pom.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<properties>
<junit.jupiter.version>5.11.0</junit.jupiter.version>
<junit.platform.version>1.11.0</junit.platform.version>
</properties>
<parent>
<groupId>tornado</groupId>
<artifactId>tornado</artifactId>
Expand All @@ -23,13 +27,35 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>${junit.platform.version}</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.jupiter.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
7 changes: 6 additions & 1 deletion tornado-unittests/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
open module tornado.unittests {
requires transitive junit;
requires transitive tornado.api;
requires lucene.core;
requires java.desktop;
requires transitive org.junit.jupiter.api;
requires org.junit.platform.commons;
requires org.junit.jupiter.engine;
requires org.junit.platform.launcher;
requires jdk.incubator.vector;
requires com.microsoft.onnxruntime;
requires junit;


exports uk.ac.manchester.tornado.unittests;
exports uk.ac.manchester.tornado.unittests.api;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

package uk.ac.manchester.tornado.unittests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import uk.ac.manchester.tornado.api.ImmutableTaskGraph;
import uk.ac.manchester.tornado.api.TaskGraph;
Expand Down Expand Up @@ -106,6 +107,9 @@ public void testHello() throws TornadoExecutionPlanException {
ImmutableTaskGraph immutableTaskGraph = taskGraph.snapshot();
try (TornadoExecutionPlan executionPlan = new TornadoExecutionPlan(immutableTaskGraph)) {
executionPlan.execute();
assertTrue(true, "Task was executed.");
} catch (Exception e) {
assertTrue(false, "Task was not executed.");
}
}

Expand All @@ -119,9 +123,7 @@ public void testPrintIntArray() throws TornadoExecutionPlanException {
a.set(0, 1);
a.set(1, 2);

TaskGraph taskGraph = new TaskGraph("s0")
.transferToDevice(DataTransferMode.FIRST_EXECUTION, a)
.task("t0", TestHello::printIntArray, a);
TaskGraph taskGraph = new TaskGraph("s0").transferToDevice(DataTransferMode.FIRST_EXECUTION, a).task("t0", TestHello::printIntArray, a);
assertNotNull(taskGraph);

ImmutableTaskGraph immutableTaskGraph = taskGraph.snapshot();
Expand All @@ -141,9 +143,7 @@ public void testPrintIntArray2() throws TornadoExecutionPlanException {
a.set(i, i + 1);
}

TaskGraph taskGraph = new TaskGraph("s0")
.transferToDevice(DataTransferMode.FIRST_EXECUTION, a)
.task("t0", TestHello::printIntArray2, a);
TaskGraph taskGraph = new TaskGraph("s0").transferToDevice(DataTransferMode.FIRST_EXECUTION, a).task("t0", TestHello::printIntArray2, a);
assertNotNull(taskGraph);

ImmutableTaskGraph immutableTaskGraph = taskGraph.snapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

package uk.ac.manchester.tornado.unittests.api;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;
import java.util.stream.IntStream;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import uk.ac.manchester.tornado.api.DataRange;
import uk.ac.manchester.tornado.api.ImmutableTaskGraph;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.nio.LongBuffer;
import java.nio.ShortBuffer;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import uk.ac.manchester.tornado.api.types.arrays.ByteArray;
import uk.ac.manchester.tornado.api.types.arrays.CharArray;
Expand Down
Loading