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

device module unit tests #128

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
84 changes: 84 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,51 @@
<artifactId>aparapi-jni</artifactId>
<version>1.4.2-SNAPSHOT</version>
</dependency>

<!--Test Dependencies-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.7.4</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.7.4</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
<exclusion>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.powermock</groupId>
<artifactId>powermock-reflect</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
</dependencies>

Expand All @@ -101,6 +143,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -145,6 +191,44 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<!--
Prepares the property pointing to the JaCoCo runtime agent which
is passed as VM argument when Maven the Surefire plugin is executed.
-->
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
<!--
Sets the name of the property containing the settings
for JaCoCo runtime agent.
-->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<!--
Ensures that the code coverage report for unit tests is created after
unit tests have been run.
-->
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.mycila.maven-license-plugin</groupId>
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/aparapi/Range.java
Original file line number Diff line number Diff line change
Expand Up @@ -654,4 +654,19 @@ public int[] getMaxWorkItemSize() {
public void setMaxWorkItemSize(int[] maxWorkItemSize) {
this.maxWorkItemSize = maxWorkItemSize;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Range range = (Range) o;
return maxWorkGroupSize == range.maxWorkGroupSize &&
Objects.equals(device, range.device) &&
Arrays.equals(maxWorkItemSize, range.maxWorkItemSize);
}

@Override
public int hashCode() {
return Objects.hash(device, maxWorkGroupSize, maxWorkItemSize);
}
}
19 changes: 19 additions & 0 deletions src/main/java/com/aparapi/internal/opencl/OpenCLArgDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package com.aparapi.internal.opencl;

import java.util.Objects;

public class OpenCLArgDescriptor{

public final static int ARG_BYTE_BIT = 1 << 0x000;
Expand Down Expand Up @@ -114,4 +116,21 @@ public OpenCLArgDescriptor(String _name, long _bits) {

return (argBuilder.toString());
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
OpenCLArgDescriptor that = (OpenCLArgDescriptor) o;
return bits == that.bits &&
Objects.equals(memVal, that.memVal) &&
Objects.equals(name, that.name) &&
Objects.equals(kernel, that.kernel);
}

@Override
public int hashCode() {

return Objects.hash(memVal, name, bits, kernel);
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/aparapi/internal/util/UnsafeWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public class UnsafeWrapper{
arrayBaseOffsetMethod = uc.getDeclaredMethod("arrayBaseOffset", Class.class);
arrayIndexScaleMethod = uc.getDeclaredMethod("arrayIndexScale", Class.class);
getObjectMethod = uc.getDeclaredMethod("getObject", Object.class, long.class);
getIntMethod = uc.getDeclaredMethod("getInt", Object.class, long.class);
getIntMethod = uc.getDeclaredMethod("getInt", Object.class, long.class);
getFloatMethod = uc.getDeclaredMethod("getFloat", Object.class, long.class);
getByteMethod = uc.getDeclaredMethod("getByte", Object.class, long.class);
getBooleanMethod = uc.getDeclaredMethod("getBoolean", Object.class, long.class);
Expand Down
74 changes: 74 additions & 0 deletions src/test/java/com/aparapi/device/DeviceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* Copyright (c) 2016 - 2018 Syncleus, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.aparapi.device;

import com.aparapi.Range;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class DeviceTest {

private static final int LOCAL_WIDTH = 11;
private static final int GLOBAL_WIDTH = 11;
private static final int GLOBAL_HEIGHT = 12;
private static final int LOCAL_HEIGHT = 14;
private static final int GLOBAL_DEPTH = 15;
private static final int LOCAL_DEPTH = 17;
private static final String TEST = "test";

@Test
public void shouldCreateRangeWithCurrentDevice() {
Device sut = Utils.createDevice(Utils.createPlatform(TEST), Device.TYPE.ACC);
assertEquals(Range.create(sut, GLOBAL_WIDTH, LOCAL_WIDTH), sut.createRange(GLOBAL_WIDTH, LOCAL_WIDTH));
}

@Test
public void shouldCreateRange2DGlobalParamsWithCurrentDevice() {
Device sut = Utils.createDevice(Utils.createPlatform(TEST), Device.TYPE.ACC);
assertEquals(Range.create2D(sut, GLOBAL_WIDTH, GLOBAL_HEIGHT), sut.createRange2D(GLOBAL_WIDTH, GLOBAL_HEIGHT));
}

@Test
public void shouldCreateRange2DGlobalAndLocalWithCurrentDevice() {
Device sut = Utils.createDevice(Utils.createPlatform(TEST), Device.TYPE.ACC);
assertEquals(Range.create2D(sut, GLOBAL_WIDTH, GLOBAL_HEIGHT, LOCAL_WIDTH, LOCAL_HEIGHT),
sut.createRange2D(GLOBAL_WIDTH, GLOBAL_HEIGHT, LOCAL_WIDTH, LOCAL_HEIGHT));
}

@Test
public void shouldCreateRange3DGlobalWithCurrentDevice() {
Device sut = Utils.createDevice(Utils.createPlatform(TEST), Device.TYPE.ACC);
assertEquals(Range.create3D(sut, GLOBAL_WIDTH, GLOBAL_HEIGHT, GLOBAL_DEPTH),
sut.createRange3D(GLOBAL_WIDTH, GLOBAL_HEIGHT, GLOBAL_DEPTH));
}

@Test
public void shouldCreateRange3DGlobalAndLocalWithCurrentDevice() {
Device sut = Utils.createDevice(Utils.createPlatform(TEST), Device.TYPE.ACC);
assertEquals(Range.create3D(sut, GLOBAL_WIDTH, GLOBAL_HEIGHT, GLOBAL_DEPTH, LOCAL_WIDTH, LOCAL_HEIGHT, LOCAL_DEPTH),
sut.createRange3D(GLOBAL_WIDTH, GLOBAL_HEIGHT, GLOBAL_DEPTH, LOCAL_WIDTH, LOCAL_HEIGHT, LOCAL_DEPTH));
}

@Test
public void shouldCompareDevicesAccordingToTheirRank() {
Device least = Utils.createDevice(Utils.createPlatform(TEST), Device.TYPE.ACC);
Device largest = Utils.createDevice(Utils.createPlatform(TEST), Device.TYPE.SEQ);
assertEquals(-1, least.compareTo(largest));
assertEquals(1, largest.compareTo(least));
assertEquals(0, least.compareTo(least));
}
}
50 changes: 50 additions & 0 deletions src/test/java/com/aparapi/device/JavaDeviceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright (c) 2016 - 2018 Syncleus, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.aparapi.device;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class JavaDeviceTest {

@Test
public void shouldReturnCorrectPropertiesForThreadPoolDevice() {
assertEquals("Java Thread Pool", JavaDevice.THREAD_POOL.getShortDescription());
assertEquals(-3, JavaDevice.THREAD_POOL.getDeviceId());
assertEquals(Device.TYPE.JTP, JavaDevice.THREAD_POOL.getType());
assertEquals("Java Thread Pool", JavaDevice.THREAD_POOL.toString());

}

@Test
public void shouldReturnCorrectPropertiesForAlternativeAlgorithm() {
assertEquals("Java Alternative Algorithm", JavaDevice.ALTERNATIVE_ALGORITHM.getShortDescription());
assertEquals(-2, JavaDevice.ALTERNATIVE_ALGORITHM.getDeviceId());
assertEquals(Device.TYPE.ALT, JavaDevice.ALTERNATIVE_ALGORITHM.getType());
assertEquals("Java Alternative Algorithm", JavaDevice.ALTERNATIVE_ALGORITHM.toString());

}

@Test
public void shouldReturnCorrectPropertiesForSequential() {
assertEquals("Java Sequential", JavaDevice.SEQUENTIAL.getShortDescription());
assertEquals(-1, JavaDevice.SEQUENTIAL.getDeviceId());
assertEquals(Device.TYPE.SEQ, JavaDevice.SEQUENTIAL.getType());
assertEquals("Java Sequential", JavaDevice.SEQUENTIAL.toString());

}
}
Loading