Fix out-of-bound accesses in Renderscript GetSetTest

On the Java side of the test, the test set up code, i.e.,
GetSetTest::testSetup(), creates allocations of width divided by the
given vector size, whereas the script side of the test getset.rs assumed
undivided widths. So when testing short vector types, the allocation's
X dimension would be 1/(vector width) of what expected by script, and
that error was caught by the debug context.

This CL fixes the problem by revising the script so it has the same
assumption on X dimension size as the Java side test set-up code. Also
fixes incomplete verification routines which only looked at first 252
elements out of total 252*31*4 elements.

Bug: 37914681
Test: Ran affected CTS tests in normal and debug contexts
Change-Id: I1dedb44092cc06630c7c5700641a075278156f3f
(cherry picked from commit 88b3c33bc83180fe12ecf95c7bbe75e51ab2d213)
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/GetSetTest.java b/tests/tests/renderscript/src/android/renderscript/cts/GetSetTest.java
index 4a26f8c..8c8caba 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/GetSetTest.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/GetSetTest.java
@@ -143,7 +143,7 @@
 
     private void verify(byte[] a1, byte[] a2, Allocation alloc, String s, int vsize) {
         alloc.copyTo(a2);
-        for (int i=0; i < gWidth; i++) {
+        for (int i=0; i < gCount; i++) {
             if (a1[i] != a2[i]) {
                 if ((vsize == 3) && ((i % 4) == 3)) {
                     continue;
@@ -157,7 +157,7 @@
 
     private void verify(short[] a1, short[] a2, Allocation alloc, String s, int vsize) {
         alloc.copyTo(a2);
-        for (int i=0; i < gWidth; i++) {
+        for (int i=0; i < gCount; i++) {
             if (a1[i] != a2[i]) {
                 if ((vsize == 3) && ((i % 4) == 3)) {
                     continue;
@@ -171,7 +171,7 @@
 
     private void verify(int[] a1, int[] a2, Allocation alloc, String s, int vsize) {
         alloc.copyTo(a2);
-        for (int i=0; i < gWidth; i++) {
+        for (int i=0; i < gCount; i++) {
             if (a1[i] != a2[i]) {
                 if ((vsize == 3) && ((i % 4) == 3)) {
                     continue;
@@ -185,7 +185,7 @@
 
     private void verify(long[] a1, long[] a2, Allocation alloc, String s, int vsize) {
         alloc.copyTo(a2);
-        for (int i=0; i < gWidth; i++) {
+        for (int i=0; i < gCount; i++) {
             if (a1[i] != a2[i]) {
                 if ((vsize == 3) && ((i % 4) == 3)) {
                     continue;
@@ -199,7 +199,7 @@
 
     private void verify(float[] a1, float[] a2, Allocation alloc, String s, int vsize) {
         alloc.copyTo(a2);
-        for (int i=0; i < gWidth; i++) {
+        for (int i=0; i < gCount; i++) {
             if (a1[i] != a2[i]) {
                 if ((vsize == 3) && ((i % 4) == 3)) {
                     continue;
@@ -213,7 +213,7 @@
 
     private void verify(double[] a1, double[] a2, Allocation alloc, String s, int vsize) {
         alloc.copyTo(a2);
-        for (int i=0; i < gWidth; i++) {
+        for (int i=0; i < gCount; i++) {
             if (a1[i] != a2[i]) {
                 if ((vsize == 3) && ((i % 4) == 3)) {
                     continue;
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/getset.rs b/tests/tests/renderscript/src/android/renderscript/cts/getset.rs
index 4a8fa7f..f2040e5 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/getset.rs
+++ b/tests/tests/renderscript/src/android/renderscript/cts/getset.rs
@@ -69,20 +69,23 @@
         rsSetElementAt_##ty(gAlloc2DOut, i, x, y);                    \
     }                                                               \
     void __attribute__((kernel)) copy2D_##ty##2(int idx) {          \
-        uint x = idx % gWidth;                                      \
-        uint y = idx / gWidth;                                      \
+        uint realWidth = gWidth / 2;                                \
+        uint x = idx % realWidth;                                      \
+        uint y = idx / realWidth;                                      \
         ty##2 i = rsGetElementAt_##ty##2(gAlloc2DIn, x, y);           \
         rsSetElementAt_##ty##2(gAlloc2DOut, i, x, y);                 \
     }                                                               \
     void __attribute__((kernel)) copy2D_##ty##3(int idx) {          \
-        uint x = idx % gWidth;                                      \
-        uint y = idx / gWidth;                                      \
+        uint realWidth = gWidth / 4;                                \
+        uint x = idx % realWidth;                                      \
+        uint y = idx / realWidth;                                      \
         ty##3 i = rsGetElementAt_##ty##3(gAlloc2DIn, x, y);           \
         rsSetElementAt_##ty##3(gAlloc2DOut, i, x, y);                 \
     }                                                               \
     void __attribute__((kernel)) copy2D_##ty##4(int idx) {          \
-        uint x = idx % gWidth;                                      \
-        uint y = idx / gWidth;                                      \
+        uint realWidth = gWidth / 4;                                \
+        uint x = idx % realWidth;                                      \
+        uint y = idx / realWidth;                                      \
         ty##4 i = rsGetElementAt_##ty##4(gAlloc2DIn, x, y);           \
         rsSetElementAt_##ty##4(gAlloc2DOut, i, x, y);                 \
     }
@@ -109,23 +112,26 @@
         rsSetElementAt_##ty(gAlloc3DOut, i, x, y, z);                 \
     }                                                               \
     void __attribute__((kernel)) copy3D_##ty##2(int idx) {          \
-        uint x = idx % gWidth;                                      \
-        uint y = (idx / gWidth) % gHeight;                          \
-        uint z = idx / (gWidth * gHeight);                          \
+        uint realWidth = gWidth / 2;                                \
+        uint x = idx % realWidth;                                   \
+        uint y = (idx / realWidth) % gHeight;                       \
+        uint z = idx / (realWidth * gHeight);                       \
         ty##2 i = rsGetElementAt_##ty##2(gAlloc3DIn, x, y, z);        \
         rsSetElementAt_##ty##2(gAlloc3DOut, i, x, y, z);              \
     }                                                               \
     void __attribute__((kernel)) copy3D_##ty##3(int idx) {          \
-        uint x = idx % gWidth;                                      \
-        uint y = (idx / gWidth) % gHeight;                          \
-        uint z = idx / (gWidth * gHeight);                          \
+        uint realWidth = gWidth / 4;                                \
+        uint x = idx % realWidth;                                   \
+        uint y = (idx / realWidth) % gHeight;                       \
+        uint z = idx / (realWidth * gHeight);                       \
         ty##3 i = rsGetElementAt_##ty##3(gAlloc3DIn, x, y, z);        \
         rsSetElementAt_##ty##3(gAlloc3DOut, i, x, y, z);              \
     }                                                               \
     void __attribute__((kernel)) copy3D_##ty##4(int idx) {          \
-        uint x = idx % gWidth;                                      \
-        uint y = (idx / gWidth) % gHeight;                          \
-        uint z = idx / (gWidth * gHeight);                          \
+        uint realWidth = gWidth / 4;                                \
+        uint x = idx % realWidth;                                   \
+        uint y = (idx / realWidth) % gHeight;                       \
+        uint z = idx / (realWidth * gHeight);                       \
         ty##4 i = rsGetElementAt_##ty##4(gAlloc3DIn, x, y, z);        \
         rsSetElementAt_##ty##4(gAlloc3DOut, i, x, y, z);              \
     }