Skip to content

Commit

Permalink
[tests] Updated to use try-with-resouces
Browse files Browse the repository at this point in the history
  • Loading branch information
jjfumero committed Jun 24, 2024
1 parent 3bd96e1 commit e74c574
Show file tree
Hide file tree
Showing 66 changed files with 2,665 additions and 2,557 deletions.
2 changes: 1 addition & 1 deletion tornado-assembly/src/bin/tornado-test
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ __TEST_THE_WORLD__ = [
TestEntry("uk.ac.manchester.tornado.unittests.fails.RuntimeFail"),
TestEntry("uk.ac.manchester.tornado.unittests.math.TestTornadoMathCollection"),
TestEntry("uk.ac.manchester.tornado.unittests.arrays.TestNewArrays"),
TestEntry("uk.ac.manchester.tornado.unittests.dynsize.Resize"),
TestEntry("uk.ac.manchester.tornado.unittests.dynsize.ResizeTest"),
TestEntry("uk.ac.manchester.tornado.unittests.loops.TestLoopTransformations"),
TestEntry("uk.ac.manchester.tornado.unittests.numpromotion.TestNumericPromotion"),
TestEntry("uk.ac.manchester.tornado.unittests.numpromotion.Types"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@

package uk.ac.manchester.tornado.unittests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import org.junit.Test;

import uk.ac.manchester.tornado.api.ImmutableTaskGraph;
import uk.ac.manchester.tornado.api.TaskGraph;
import uk.ac.manchester.tornado.api.TornadoExecutionPlan;
import uk.ac.manchester.tornado.api.annotations.Parallel;
import uk.ac.manchester.tornado.api.types.arrays.IntArray;
import uk.ac.manchester.tornado.api.enums.DataTransferMode;
import uk.ac.manchester.tornado.api.enums.TornadoVMBackendType;
import uk.ac.manchester.tornado.api.exceptions.Debug;
import uk.ac.manchester.tornado.api.exceptions.TornadoExecutionPlanException;
import uk.ac.manchester.tornado.api.types.arrays.IntArray;
import uk.ac.manchester.tornado.unittests.common.TornadoTestBase;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

/**
* <p>
* How to run.
Expand Down Expand Up @@ -80,27 +81,21 @@ public void compute(int[] a, int[] b) {
}

@Test
public void testHello() {
public void testHello() throws TornadoExecutionPlanException {
assertNotBackend(TornadoVMBackendType.SPIRV);

TaskGraph taskGraph = new TaskGraph("s0") //
.task("t0", TestHello::printHello, 8);
assertNotNull(taskGraph);

ImmutableTaskGraph immutableTaskGraph = taskGraph.snapshot();
TornadoExecutionPlan executionPlan = new TornadoExecutionPlan(immutableTaskGraph);
executionPlan.execute();

try {
try (TornadoExecutionPlan executionPlan = new TornadoExecutionPlan(immutableTaskGraph)) {
executionPlan.execute();
assertTrue("Task was executed.", true);
} catch (Exception e) {
assertTrue("Task was not executed.", false);
}
}

@Test
public void testVectorAddition() {
public void testVectorAddition() throws TornadoExecutionPlanException {
int numElements = 16;
IntArray a = new IntArray(numElements);
IntArray b = new IntArray(numElements);
Expand All @@ -115,8 +110,9 @@ public void testVectorAddition() {
.transferToHost(DataTransferMode.EVERY_EXECUTION, c);

ImmutableTaskGraph immutableTaskGraph = taskGraph.snapshot();
TornadoExecutionPlan executionPlan = new TornadoExecutionPlan(immutableTaskGraph);
executionPlan.execute();
try (TornadoExecutionPlan executionPlan = new TornadoExecutionPlan(immutableTaskGraph)) {
executionPlan.execute();
}

for (int i = 0; i < c.getSize(); i++) {
assertEquals(a.get(i) + b.get(i), c.get(i), 0.001);
Expand All @@ -131,7 +127,7 @@ public void testVectorAddition() {
* </code>
*/
@Test
public void testSimpleCompute() {
public void testSimpleCompute() throws TornadoExecutionPlanException {
int numElements = 256;
IntArray a = new IntArray(numElements);
IntArray b = new IntArray(numElements);
Expand All @@ -146,16 +142,17 @@ public void testSimpleCompute() {
.transferToHost(DataTransferMode.EVERY_EXECUTION, b);

ImmutableTaskGraph immutableTaskGraph = taskGraph.snapshot();
TornadoExecutionPlan executionPlan = new TornadoExecutionPlan(immutableTaskGraph);
executionPlan.execute();
try (TornadoExecutionPlan executionPlan = new TornadoExecutionPlan(immutableTaskGraph)) {
executionPlan.execute();
}

for (int i = 0; i < b.getSize(); i++) {
assertEquals(a.get(i) * 2, b.get(i));
}
}

@Test
public void testSimpleCompute2() {
public void testSimpleCompute2() throws TornadoExecutionPlanException {
int numElements = 256;
IntArray a = new IntArray(numElements);
IntArray b = new IntArray(numElements);
Expand All @@ -170,16 +167,17 @@ public void testSimpleCompute2() {
.transferToHost(DataTransferMode.EVERY_EXECUTION, b);

ImmutableTaskGraph immutableTaskGraph = taskGraph.snapshot();
TornadoExecutionPlan executionPlan = new TornadoExecutionPlan(immutableTaskGraph);
executionPlan.execute();
try (TornadoExecutionPlan executionPlan = new TornadoExecutionPlan(immutableTaskGraph)) {
executionPlan.execute();
}

for (int i = 0; i < b.getSize(); i++) {
assertEquals(a.get(i) * 2, b.get(i));
}
}

@Test
public void testSimpleInOut() {
public void testSimpleInOut() throws TornadoExecutionPlanException {
int numElements = 256;
IntArray a = new IntArray(numElements);

Expand All @@ -190,8 +188,9 @@ public void testSimpleInOut() {
.transferToHost(DataTransferMode.EVERY_EXECUTION, a);

ImmutableTaskGraph immutableTaskGraph = taskGraph.snapshot();
TornadoExecutionPlan executionPlan = new TornadoExecutionPlan(immutableTaskGraph);
executionPlan.execute();
try (TornadoExecutionPlan executionPlan = new TornadoExecutionPlan(immutableTaskGraph)) {
executionPlan.execute();
}

for (int i = 0; i < a.getSize(); i++) {
assertEquals(20, a.get(i));
Expand Down
Loading

0 comments on commit e74c574

Please sign in to comment.