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

8255174: Vector API unit tests for missed public api code coverage #785

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
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
74 changes: 74 additions & 0 deletions test/jdk/jdk/incubator/vector/AbstractVectorTest.java
Original file line number Diff line number Diff line change
@@ -31,6 +31,11 @@
import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.IntFunction;
import java.util.function.IntUnaryOperator;
import java.util.stream.Stream;
import java.util.stream.Collectors;

import org.testng.Assert;

public class AbstractVectorTest {

@@ -149,12 +154,53 @@ static int[] fillInts(int[] a, IntOp f) {
withToString("mask[false]", boolean[]::new)
);

static final List<List<IntFunction<boolean[]>>>
BOOLEAN_MASK_COMPARE_GENERATOR_PAIRS =
Stream.of(BOOLEAN_MASK_GENERATORS.get(0)).
flatMap(fa -> BOOLEAN_MASK_GENERATORS.stream().skip(1).map(
fb -> List.of(fa, fb))).collect(Collectors.toList());

static final List<BiFunction<Integer,Integer,int[]>> INT_SHUFFLE_GENERATORS = List.of(
withToStringBi("shuffle[random]", (Integer l, Integer m) -> {
return RAND.ints(l, 0, m).toArray();
})
);

interface RangeIntOp {
int apply(int i, int min, int max);
}

static int[] fillRangeInts(int s, int min, int max, RangeIntOp f) {
return fillRangeInts(new int[s], min, max, f);
}

static int[] fillRangeInts(int[] a, int min, int max, RangeIntOp f) {
for (int i = 0; i < a.length; i++) {
a[i] = f.apply(i, min, max);
}
return a;
}

static final List<List<BiFunction<Integer, Integer, int[]>>>
INT_SHUFFLE_COMPARE_GENERATOR_PAIRS = List.of(
List.of(
withToStringBi("shuffle[i]", (Integer l, Integer m) -> {
return fillRangeInts(l, 0, m, (i, _min, _max) -> (i % _max));
}),
withToStringBi("shuffle[random]", (Integer l, Integer m) -> {
return RAND.ints(l, 0, m).toArray();
})
),
List.of(
withToStringBi("shuffle[i]", (Integer l, Integer m) -> {
return fillRangeInts(l, 0, m, (i, _min, _max) -> (i % _max));
}),
withToStringBi("shuffle[random]", (Integer l, Integer m) -> {
return RAND.ints(l, 0, m).toArray();
})
)
);

static final List<BiFunction<Integer,Integer,int[]>> INT_INDEX_GENERATORS = List.of(
withToStringBi("index[random]", (Integer l, Integer m) -> {
return RAND.ints(l, 0, m).toArray();
@@ -187,4 +233,32 @@ static boolean isIndexOutOfBounds(int size, int offset, int length) {
int upperBound = offset + size;
return upperBound < size || upperBound > length;
}

public static int[] expectedShuffle(int length, IntUnaryOperator fn) {
int [] a = new int[length];
for (int i = 0; i < length; i++) {
int elem = fn.applyAsInt(i);
int wrapElem = Math.floorMod(elem, length);
if (elem != wrapElem) {
elem = wrapElem - length;
}
a[i] = elem;
}
return a;
}

interface FBooleanBinOp {
boolean apply(boolean a, boolean b);
}

static void assertArraysEquals(boolean[] a, boolean[] b, boolean[] r, FBooleanBinOp f) {
int i = 0;
try {
for (; i < a.length; i++) {
Assert.assertEquals(r[i], f.apply(a[i], b[i]));
}
} catch (AssertionError e) {
Assert.assertEquals(r[i], f.apply(a[i], b[i]), "(" + a[i] + ", " + b[i] + ") at index #" + i);
}
}
}
36 changes: 35 additions & 1 deletion test/jdk/jdk/incubator/vector/Byte128VectorLoadStoreTests.java
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@
import jdk.incubator.vector.ByteVector;
import jdk.incubator.vector.VectorMask;
import jdk.incubator.vector.VectorSpecies;
import jdk.incubator.vector.VectorShuffle;
import jdk.internal.vm.annotation.DontInline;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
@@ -42,7 +43,7 @@
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.util.List;
import java.util.function.IntFunction;
import java.util.function.*;

@Test
public class Byte128VectorLoadStoreTests extends AbstractVectorTest {
@@ -164,6 +165,13 @@ public Object[][] byteProvider() {
toArray(Object[][]::new);
}

@DataProvider
public Object[][] maskProvider() {
return BOOLEAN_MASK_GENERATORS.stream().
map(f -> new Object[]{f}).
toArray(Object[][]::new);
}

@DataProvider
public Object[][] byteProviderForIOOBE() {
var f = BYTE_GENERATORS.get(0);
@@ -936,4 +944,30 @@ static void storeByteArrayMaskIOOBE(IntFunction<byte[]> fa, IntFunction<Integer>
}
}
}

@Test(dataProvider = "maskProvider")
static void loadStoreMask(IntFunction<boolean[]> fm) {
boolean[] a = fm.apply(SPECIES.length());
boolean[] r = new boolean[a.length];

for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
VectorMask<Byte> vmask = SPECIES.loadMask(a, i);
vmask.intoArray(r, i);
}
}
Assert.assertEquals(a, r);
}

@Test
static void loadStoreShuffle() {
IntUnaryOperator fn = a -> a + 5;
for (int ic = 0; ic < INVOC_COUNT; ic++) {
var shuffle = VectorShuffle.fromOp(SPECIES, fn);
int [] r = shuffle.toArray();

int [] a = expectedShuffle(SPECIES.length(), fn);
Assert.assertEquals(a, r);
}
}
}
Loading