[RenderScript] Test Float16 variants of Allocation copy functions
http://b/27251511
For Allocation-copy scenarios that are currently tested for short and
ushort, add tests for Float16 variants as well.
Change-Id: I1513c16fbb69219b8fb452b1b5acccb25a161f7c
(cherry picked from commit 58b96a2bb7d68db61aa9e61a9b934d1b8a42e73d)
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/AllocationCopyPaddedTest.java b/tests/tests/renderscript/src/android/renderscript/cts/AllocationCopyPaddedTest.java
index c74dbc0..6e74cb3 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/AllocationCopyPaddedTest.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/AllocationCopyPaddedTest.java
@@ -106,7 +106,7 @@
result);
}
- public void test_AllocationPadded_Short3_1D() {
+ void test_AllocationPadded_Short3_1D_Helper(Element element) {
Random random = new Random(0x172d8ab9);
int width = random.nextInt(512);
int arr_len = width * 3;
@@ -118,7 +118,7 @@
inArray[i] = (short)random.nextInt();
}
- Type.Builder typeBuilder = new Type.Builder(mRS, Element.I16_3(mRS));
+ Type.Builder typeBuilder = new Type.Builder(mRS, element);
typeBuilder.setX(width);
Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create());
alloc.setAutoPadding(true);
@@ -132,11 +132,16 @@
break;
}
}
- assertTrue("test_AllocationCopyTo_1D_Padded_Short Failed, output array does not match input",
+ assertTrue("test_AllocationPadded_Short3_1D_Helper Failed, output array does not match input",
result);
}
- public void test_AllocationPadded_Short3_2D() {
+ public void test_AllocationPadded_Short3_1D() {
+ test_AllocationPadded_Short3_1D_Helper(Element.I16_3(mRS));
+ test_AllocationPadded_Short3_1D_Helper(Element.F16_3(mRS));
+ }
+
+ void test_AllocationPadded_Short3_2D_Helper(Element element) {
Random random = new Random(0x172d8ab9);
int width = random.nextInt(128);
int height = random.nextInt(128);
@@ -149,7 +154,7 @@
inArray[i] = (short)random.nextInt();
}
- Type.Builder typeBuilder = new Type.Builder(mRS, Element.I16_3(mRS));
+ Type.Builder typeBuilder = new Type.Builder(mRS, element);
typeBuilder.setX(width).setY(height);
Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create());
alloc.setAutoPadding(true);
@@ -163,11 +168,16 @@
break;
}
}
- assertTrue("test_AllocationCopyTo_2D_Padded_Short Failed, output array does not match input",
+ assertTrue("test_AllocationPadded_Short3_2D_Helper Failed, output array does not match input",
result);
}
- public void test_AllocationPadded_Short3_3D() {
+ public void test_AllocationPadded_Short3_2D() {
+ test_AllocationPadded_Short3_2D_Helper(Element.I16_3(mRS));
+ test_AllocationPadded_Short3_2D_Helper(Element.F16_3(mRS));
+ }
+
+ void test_AllocationPadded_Short3_3D_Helper(Element element) {
Random random = new Random(0x172d8ab9);
int w = random.nextInt(32);
int h = random.nextInt(32);
@@ -181,7 +191,7 @@
inArray[i] = (short)random.nextInt();
}
- Type.Builder typeBuilder = new Type.Builder(mRS, Element.I16_3(mRS));
+ Type.Builder typeBuilder = new Type.Builder(mRS, element);
typeBuilder.setX(w).setY(h).setZ(d);
Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create());
alloc.setAutoPadding(true);
@@ -195,10 +205,15 @@
break;
}
}
- assertTrue("test_AllocationCopyTo_3D_Padded_Short Failed, output array does not match input",
+ assertTrue("test_AllocationPadded_Short3_3D_Helper Failed, output array does not match input",
result);
}
+ public void test_AllocationPadded_Short3_3D() {
+ test_AllocationPadded_Short3_3D_Helper(Element.I16_3(mRS));
+ test_AllocationPadded_Short3_3D_Helper(Element.F16_3(mRS));
+ }
+
public void test_AllocationPadded_Int3_1D() {
Random random = new Random(0x172d8ab9);
int width = random.nextInt(512);
@@ -603,7 +618,7 @@
result);
}
- public void test_AllocationPadded_copy1DRangeTo_Short3() {
+ void test_AllocationPadded_copy1DRangeTo_Short3_Helper(Element element) {
Random random = new Random(0x172d8ab9);
int width = random.nextInt(512);
int arr_len = width * 3;
@@ -615,7 +630,7 @@
inArray[i] = (short)random.nextInt();
}
- Type.Builder typeBuilder = new Type.Builder(mRS, Element.I16_3(mRS));
+ Type.Builder typeBuilder = new Type.Builder(mRS, element);
typeBuilder.setX(width);
Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create());
alloc.setAutoPadding(true);
@@ -637,10 +652,15 @@
break;
}
}
- assertTrue("test_copy1DRangeTo_Padded_Short Failed, output array does not match input",
+ assertTrue("test_AllocationPadded_copy1DRangeTo_Short3_Helper Failed, output array does not match input",
result);
}
+ public void test_AllocationPadded_copy1DRangeTo_Short3() {
+ test_AllocationPadded_copy1DRangeTo_Short3_Helper(Element.I16_3(mRS));
+ test_AllocationPadded_copy1DRangeTo_Short3_Helper(Element.F16_3(mRS));
+ }
+
public void test_AllocationPadded_copy1DRangeTo_Int3() {
Random random = new Random(0x172d8ab9);
int width = random.nextInt(512);
@@ -787,7 +807,7 @@
result);
}
- public void test_AllocationPadded_copy2DRangeTo_Short3() {
+ void test_AllocationPadded_copy2DRangeTo_Short3_Helper(Element element) {
Random random = new Random(0x172d8ab9);
int width = random.nextInt(128);
int height = random.nextInt(128);
@@ -804,7 +824,7 @@
inArray[i] = (short)random.nextInt();
}
- Type.Builder typeBuilder = new Type.Builder(mRS, Element.I16_3(mRS));
+ Type.Builder typeBuilder = new Type.Builder(mRS, element);
typeBuilder.setX(width).setY(height);
Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create());
alloc.setAutoPadding(true);
@@ -818,10 +838,15 @@
break;
}
}
- assertTrue("test_copy2DRangeTo_Padded_Short Failed, output array does not match input",
+ assertTrue("test_AllocationPadded_copy2DRangeTo_Short3_Helper Failed, output array does not match input",
result);
}
+ public void test_AllocationPadded_copy2DRangeTo_Short3() {
+ test_AllocationPadded_copy2DRangeTo_Short3_Helper(Element.I16_3(mRS));
+ test_AllocationPadded_copy2DRangeTo_Short3_Helper(Element.F16_3(mRS));
+ }
+
public void test_AllocationPadded_copy2DRangeTo_Int3() {
Random random = new Random(0x172d8ab9);
int width = random.nextInt(128);
@@ -963,7 +988,7 @@
result);
}
- public void test_AllocationPadded_copy1DRangeToUnchecked_Short3() {
+ void test_AllocationPadded_copy1DRangeToUnchecked_Short3_Helper(Element element) {
Random random = new Random(0x172d8ab9);
int width = random.nextInt(512);
int arr_len = width * 3;
@@ -975,7 +1000,7 @@
inArray[i] = (short)random.nextInt();
}
- Type.Builder typeBuilder = new Type.Builder(mRS, Element.I16_3(mRS));
+ Type.Builder typeBuilder = new Type.Builder(mRS, element);
typeBuilder.setX(width);
Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create());
alloc.setAutoPadding(true);
@@ -997,10 +1022,15 @@
break;
}
}
- assertTrue("test_copy1DRangeToUnchecked_Padded_Short Failed, output array does not match input",
+ assertTrue("test_AllocationPadded_copy1DRangeToUnchecked_Short3_Helper Failed, output array does not match input",
result);
}
+ public void test_AllocationPadded_copy1DRangeToUnchecked_Short3() {
+ test_AllocationPadded_copy1DRangeToUnchecked_Short3_Helper(Element.I16_3(mRS));
+ test_AllocationPadded_copy1DRangeToUnchecked_Short3_Helper(Element.F16_3(mRS));
+ }
+
public void test_AllocationPadded_copy1DRangeToUnchecked_Int3() {
Random random = new Random(0x172d8ab9);
int width = random.nextInt(512);
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/AllocationCopyToTest.java b/tests/tests/renderscript/src/android/renderscript/cts/AllocationCopyToTest.java
index f6bef0a..0c1f773 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/AllocationCopyToTest.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/AllocationCopyToTest.java
@@ -58,7 +58,7 @@
result);
}
- public void test_Allocationcopy1DRangeTo_Short() {
+ void test_Allocationcopy1DRangeTo_Short_Helper(Element element, boolean testTyped) {
Random random = new Random(0x172d8ab9);
int width = random.nextInt(512);
int arr_len = width;
@@ -70,13 +70,18 @@
inArray[i] = (short)random.nextInt();
}
- Type.Builder typeBuilder = new Type.Builder(mRS, Element.I16(mRS));
+ Type.Builder typeBuilder = new Type.Builder(mRS, element);
typeBuilder.setX(width);
alloc = Allocation.createTyped(mRS, typeBuilder.create());
int offset = random.nextInt(arr_len);
int count = arr_len - offset;
- alloc.copy1DRangeFrom(offset, count, inArray);
- alloc.copy1DRangeTo(offset, count, outArray);
+ if (testTyped) {
+ alloc.copy1DRangeFrom(offset, count, inArray);
+ alloc.copy1DRangeTo(offset, count, outArray);
+ } else {
+ alloc.copy1DRangeFrom(offset, count, (Object) inArray);
+ alloc.copy1DRangeTo(offset, count, (Object) outArray);
+ }
boolean result = true;
for (int i = 0; i < count; i++) {
@@ -91,10 +96,16 @@
break;
}
}
- assertTrue("test_Allocationcopy1DRangeTo_Short failed, output array does not match input",
+ assertTrue("test_Allocationcopy1DRangeTo_Short_Helper failed, output array does not match input",
result);
}
+ public void test_Allocationcopy1DRangeTo_Short() {
+ test_Allocationcopy1DRangeTo_Short_Helper(Element.I16(mRS), true);
+ test_Allocationcopy1DRangeTo_Short_Helper(Element.F16(mRS), true);
+ test_Allocationcopy1DRangeTo_Short_Helper(Element.F16(mRS), false);
+ }
+
public void test_Allocationcopy1DRangeTo_Int() {
Random random = new Random(0x172d8ab9);
int width = random.nextInt(512);
@@ -237,7 +248,7 @@
result);
}
- public void test_Allocationcopy2DRangeTo_Short() {
+ void test_Allocationcopy2DRangeTo_Short_Helper(Element element, boolean testTyped) {
Random random = new Random(0x172d8ab9);
int width = random.nextInt(128);
int height = random.nextInt(128);
@@ -257,8 +268,13 @@
Type.Builder typeBuilder = new Type.Builder(mRS, Element.I16(mRS));
typeBuilder.setX(width).setY(height);
alloc = Allocation.createTyped(mRS, typeBuilder.create());
- alloc.copy2DRangeFrom(xoff, yoff, xcount, ycount, inArray);
- alloc.copy2DRangeTo(xoff, yoff, xcount, ycount, outArray);
+ if (testTyped) {
+ alloc.copy2DRangeFrom(xoff, yoff, xcount, ycount, inArray);
+ alloc.copy2DRangeTo(xoff, yoff, xcount, ycount, outArray);
+ } else {
+ alloc.copy2DRangeFrom(xoff, yoff, xcount, ycount, (Object) inArray);
+ alloc.copy2DRangeTo(xoff, yoff, xcount, ycount, (Object) outArray);
+ }
boolean result = true;
for (int i = 0; i < arr_len; i++) {
@@ -267,10 +283,16 @@
break;
}
}
- assertTrue("test_Allocationcopy2DRangeTo_Short failed, output array does not match input",
+ assertTrue("test_Allocationcopy2DRangeTo_Short_Helper failed, output array does not match input",
result);
}
+ public void test_Allocationcopy2DRangeTo_Short() {
+ test_Allocationcopy2DRangeTo_Short_Helper(Element.I16(mRS), true);
+ test_Allocationcopy2DRangeTo_Short_Helper(Element.F16(mRS), true);
+ test_Allocationcopy2DRangeTo_Short_Helper(Element.F16(mRS), false);
+ }
+
public void test_Allocationcopy2DRangeTo_Int() {
Random random = new Random(0x172d8ab9);
int width = random.nextInt(128);
@@ -410,7 +432,7 @@
result);
}
- public void test_Allocationcopy3DRangeTo_Short() {
+ void test_Allocationcopy3DRangeTo_Short_Helper(Element element) {
Random random = new Random(0x172d8ab9);
int width = random.nextInt(64);
int height = random.nextInt(64);
@@ -432,7 +454,7 @@
inArray[i] = (short)random.nextInt();
}
- Type.Builder typeBuilder = new Type.Builder(mRS, Element.I16(mRS));
+ Type.Builder typeBuilder = new Type.Builder(mRS, element);
typeBuilder.setX(width).setY(height).setZ(depth);
alloc = Allocation.createTyped(mRS, typeBuilder.create());
alloc.copy3DRangeFrom(xoff, yoff, zoff, xcount, ycount, zcount, (Object)inArray);
@@ -446,10 +468,15 @@
break;
}
}
- assertTrue("test_Allocationcopy3DRangeTo_Short failed, output array does not match input",
+ assertTrue("test_Allocationcopy3DRangeTo_Short_Helper failed, output array does not match input",
result);
}
+ public void test_Allocationcopy3DRangeTo_Short() {
+ test_Allocationcopy3DRangeTo_Short_Helper(Element.I16(mRS));
+ test_Allocationcopy3DRangeTo_Short_Helper(Element.F16(mRS));
+ }
+
public void test_Allocationcopy3DRangeTo_Int() {
Random random = new Random(0x172d8ab9);
int width = random.nextInt(64);
@@ -647,7 +674,7 @@
result);
}
- public void test_Allocationcopy1DRangeToUnchecked_Short() {
+ void test_Allocationcopy1DRangeToUnchecked_Short_Helper(Element element) {
Random random = new Random(0x172d8ab9);
int width = random.nextInt(512);
int arr_len = width;
@@ -659,7 +686,7 @@
inArray[i] = (short)random.nextInt();
}
- Type.Builder typeBuilder = new Type.Builder(mRS, Element.I16(mRS));
+ Type.Builder typeBuilder = new Type.Builder(mRS, element);
typeBuilder.setX(width);
alloc = Allocation.createTyped(mRS, typeBuilder.create());
int offset = random.nextInt(arr_len);
@@ -680,10 +707,15 @@
break;
}
}
- assertTrue("test_Allocationcopy1DRangeToUnchecked_Short failed, output array does not match input",
+ assertTrue("test_Allocationcopy1DRangeToUnchecked_Short_Helper failed, output array does not match input",
result);
}
+ public void test_Allocationcopy1DRangeToUnchecked_Short() {
+ test_Allocationcopy1DRangeToUnchecked_Short_Helper(Element.I16(mRS));
+ test_Allocationcopy1DRangeToUnchecked_Short_Helper(Element.F16(mRS));
+ }
+
public void test_Allocationcopy1DRangeToUnchecked_Int() {
Random random = new Random(0x172d8ab9);
int width = random.nextInt(512);
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/AllocationTest.java b/tests/tests/renderscript/src/android/renderscript/cts/AllocationTest.java
index 9e42a6c..27315dd 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/AllocationTest.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/AllocationTest.java
@@ -115,6 +115,10 @@
createTypedHelper(Element.RGB_565(mRS));
createTypedHelper(Element.RGB_888(mRS));
createTypedHelper(Element.RGBA_8888(mRS));
+ createTypedHelper(Element.F16(mRS));
+ createTypedHelper(Element.F16_2(mRS));
+ createTypedHelper(Element.F16_3(mRS));
+ createTypedHelper(Element.F16_4(mRS));
createTypedHelper(Element.F32(mRS));
createTypedHelper(Element.F32_2(mRS));
createTypedHelper(Element.F32_3(mRS));
@@ -154,6 +158,10 @@
createSizedHelper(Element.RGB_565(mRS));
createSizedHelper(Element.RGB_888(mRS));
createSizedHelper(Element.RGBA_8888(mRS));
+ createSizedHelper(Element.F16(mRS));
+ createSizedHelper(Element.F16_2(mRS));
+ createSizedHelper(Element.F16_3(mRS));
+ createSizedHelper(Element.F16_4(mRS));
createSizedHelper(Element.F32(mRS));
createSizedHelper(Element.F32_2(mRS));
createSizedHelper(Element.F32_3(mRS));
@@ -333,8 +341,9 @@
}
}
- void helperShortCopy(int nElems, int offset, int count, int copyMode) {
- Allocation A = Allocation.createSized(mRS, Element.I16(mRS), nElems);
+ // Accept an Element parameter so this helper can test both I16 and F16 elements.
+ void helperShortCopy(Element element, int nElems, int offset, int count, int copyMode) {
+ Allocation A = Allocation.createSized(mRS, element, nElems);
short src[], dst[];
src = new short[nElems];
@@ -522,10 +531,11 @@
}
}
- void helperShortCopy2D(int nElemsX, int nElemsY,
+ // Accept an Element parameter so this helper can test both I16 and F16 elements.
+ void helperShortCopy2D(Element element, int nElemsX, int nElemsY,
int xOffset, int yOffset,
int width, int height) {
- Type.Builder b = new Type.Builder(mRS, Element.I16(mRS));
+ Type.Builder b = new Type.Builder(mRS, element);
Allocation A = Allocation.createTyped(mRS, b.setX(nElemsX).setY(nElemsY).create());
short src[], dst[];
@@ -635,7 +645,8 @@
for (int mode = 0; mode <= 1; mode ++) {
helperFloatCopy(s, 0, s, mode);
helperByteCopy(s, 0, s, mode);
- helperShortCopy(s, 0, s, mode);
+ helperShortCopy(Element.I16(mRS), s, 0, s, mode);
+ helperShortCopy(Element.F16(mRS), s, 0, s, mode);
helperIntCopy(s, 0, s, mode);
helperBaseObjCopy(s, 0, s, mode);
}
@@ -646,7 +657,8 @@
for (int count = 1; count <= s - off; count ++) {
helperFloatCopy(s, off, count, mode);
helperByteCopy(s, off, count, mode);
- helperShortCopy(s, off, count, mode);
+ helperShortCopy(Element.I16(mRS), s, off, count, mode);
+ helperShortCopy(Element.F16(mRS), s, off, count, mode);
helperIntCopy(s, off, count, mode);
helperBaseObjCopy(s, off, count, mode);
}
@@ -673,7 +685,8 @@
for (int h = 1; h <= sY - offY; h += 3) {
helperFloatCopy2D(sX, sY, offX, offY, w, h);
helperByteCopy2D(sX, sY, offX, offY, w, h);
- helperShortCopy2D(sX, sY, offX, offY, w, h);
+ helperShortCopy2D(Element.I16(mRS), sX, sY, offX, offY, w, h);
+ helperShortCopy2D(Element.F16(mRS), sX, sY, offX, offY, w, h);
helperIntCopy2D(sX, sY, offX, offY, w, h);
helperFloatAllocationCopy2D(sX, sY, offX, offY, w, h);
helperByteAllocationCopy2D(sX, sY, offX, offY, w, h);