Skip to content

Commit 5d26229

Browse files
author
Sandhya Viswanathan
committed
8255174: Vector API unit tests for missed public api code coverage
Reviewed-by: psandoz
1 parent b9186be commit 5d26229

File tree

67 files changed

+19354
-100
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+19354
-100
lines changed

test/jdk/jdk/incubator/vector/AbstractVectorTest.java

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
import java.util.Set;
3232
import java.util.function.BiFunction;
3333
import java.util.function.IntFunction;
34+
import java.util.function.IntUnaryOperator;
35+
import java.util.stream.Stream;
36+
import java.util.stream.Collectors;
37+
38+
import org.testng.Assert;
3439

3540
public class AbstractVectorTest {
3641

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

157+
static final List<List<IntFunction<boolean[]>>>
158+
BOOLEAN_MASK_COMPARE_GENERATOR_PAIRS =
159+
Stream.of(BOOLEAN_MASK_GENERATORS.get(0)).
160+
flatMap(fa -> BOOLEAN_MASK_GENERATORS.stream().skip(1).map(
161+
fb -> List.of(fa, fb))).collect(Collectors.toList());
162+
152163
static final List<BiFunction<Integer,Integer,int[]>> INT_SHUFFLE_GENERATORS = List.of(
153164
withToStringBi("shuffle[random]", (Integer l, Integer m) -> {
154165
return RAND.ints(l, 0, m).toArray();
155166
})
156167
);
157168

169+
interface RangeIntOp {
170+
int apply(int i, int min, int max);
171+
}
172+
173+
static int[] fillRangeInts(int s, int min, int max, RangeIntOp f) {
174+
return fillRangeInts(new int[s], min, max, f);
175+
}
176+
177+
static int[] fillRangeInts(int[] a, int min, int max, RangeIntOp f) {
178+
for (int i = 0; i < a.length; i++) {
179+
a[i] = f.apply(i, min, max);
180+
}
181+
return a;
182+
}
183+
184+
static final List<List<BiFunction<Integer, Integer, int[]>>>
185+
INT_SHUFFLE_COMPARE_GENERATOR_PAIRS = List.of(
186+
List.of(
187+
withToStringBi("shuffle[i]", (Integer l, Integer m) -> {
188+
return fillRangeInts(l, 0, m, (i, _min, _max) -> (i % _max));
189+
}),
190+
withToStringBi("shuffle[random]", (Integer l, Integer m) -> {
191+
return RAND.ints(l, 0, m).toArray();
192+
})
193+
),
194+
List.of(
195+
withToStringBi("shuffle[i]", (Integer l, Integer m) -> {
196+
return fillRangeInts(l, 0, m, (i, _min, _max) -> (i % _max));
197+
}),
198+
withToStringBi("shuffle[random]", (Integer l, Integer m) -> {
199+
return RAND.ints(l, 0, m).toArray();
200+
})
201+
)
202+
);
203+
158204
static final List<BiFunction<Integer,Integer,int[]>> INT_INDEX_GENERATORS = List.of(
159205
withToStringBi("index[random]", (Integer l, Integer m) -> {
160206
return RAND.ints(l, 0, m).toArray();
@@ -187,4 +233,32 @@ static boolean isIndexOutOfBounds(int size, int offset, int length) {
187233
int upperBound = offset + size;
188234
return upperBound < size || upperBound > length;
189235
}
236+
237+
public static int[] expectedShuffle(int length, IntUnaryOperator fn) {
238+
int [] a = new int[length];
239+
for (int i = 0; i < length; i++) {
240+
int elem = fn.applyAsInt(i);
241+
int wrapElem = Math.floorMod(elem, length);
242+
if (elem != wrapElem) {
243+
elem = wrapElem - length;
244+
}
245+
a[i] = elem;
246+
}
247+
return a;
248+
}
249+
250+
interface FBooleanBinOp {
251+
boolean apply(boolean a, boolean b);
252+
}
253+
254+
static void assertArraysEquals(boolean[] a, boolean[] b, boolean[] r, FBooleanBinOp f) {
255+
int i = 0;
256+
try {
257+
for (; i < a.length; i++) {
258+
Assert.assertEquals(r[i], f.apply(a[i], b[i]));
259+
}
260+
} catch (AssertionError e) {
261+
Assert.assertEquals(r[i], f.apply(a[i], b[i]), "(" + a[i] + ", " + b[i] + ") at index #" + i);
262+
}
263+
}
190264
}

test/jdk/jdk/incubator/vector/Byte128VectorLoadStoreTests.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import jdk.incubator.vector.ByteVector;
3434
import jdk.incubator.vector.VectorMask;
3535
import jdk.incubator.vector.VectorSpecies;
36+
import jdk.incubator.vector.VectorShuffle;
3637
import jdk.internal.vm.annotation.DontInline;
3738
import org.testng.Assert;
3839
import org.testng.annotations.DataProvider;
@@ -42,7 +43,7 @@
4243
import java.nio.ByteOrder;
4344
import java.nio.ReadOnlyBufferException;
4445
import java.util.List;
45-
import java.util.function.IntFunction;
46+
import java.util.function.*;
4647

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

168+
@DataProvider
169+
public Object[][] maskProvider() {
170+
return BOOLEAN_MASK_GENERATORS.stream().
171+
map(f -> new Object[]{f}).
172+
toArray(Object[][]::new);
173+
}
174+
167175
@DataProvider
168176
public Object[][] byteProviderForIOOBE() {
169177
var f = BYTE_GENERATORS.get(0);
@@ -936,4 +944,30 @@ static void storeByteArrayMaskIOOBE(IntFunction<byte[]> fa, IntFunction<Integer>
936944
}
937945
}
938946
}
947+
948+
@Test(dataProvider = "maskProvider")
949+
static void loadStoreMask(IntFunction<boolean[]> fm) {
950+
boolean[] a = fm.apply(SPECIES.length());
951+
boolean[] r = new boolean[a.length];
952+
953+
for (int ic = 0; ic < INVOC_COUNT; ic++) {
954+
for (int i = 0; i < a.length; i += SPECIES.length()) {
955+
VectorMask<Byte> vmask = SPECIES.loadMask(a, i);
956+
vmask.intoArray(r, i);
957+
}
958+
}
959+
Assert.assertEquals(a, r);
960+
}
961+
962+
@Test
963+
static void loadStoreShuffle() {
964+
IntUnaryOperator fn = a -> a + 5;
965+
for (int ic = 0; ic < INVOC_COUNT; ic++) {
966+
var shuffle = VectorShuffle.fromOp(SPECIES, fn);
967+
int [] r = shuffle.toArray();
968+
969+
int [] a = expectedShuffle(SPECIES.length(), fn);
970+
Assert.assertEquals(a, r);
971+
}
972+
}
939973
}

0 commit comments

Comments
 (0)