Check renderscript kernels running on void* allocs
Change-Id: I274a91e25be2774bb315575898933ee80a715b3b
diff --git a/tests/src/android/renderscript/cts/void_ptr.rs b/tests/src/android/renderscript/cts/void_ptr.rs
new file mode 100644
index 0000000..895f0c7
--- /dev/null
+++ b/tests/src/android/renderscript/cts/void_ptr.rs
@@ -0,0 +1,49 @@
+#pragma version(1)
+#pragma rs java_package_name(android.renderscript.cts)
+
+rs_allocation aFailed;
+rs_allocation aOutput;
+
+void set_output_void_int(void *out, uint32_t x, uint32_t y) {
+ int *out_int = (int *)out;
+ *out_int = x + y;
+}
+
+void __attribute__((kernel))check_output_int(const int in, uint32_t x, uint32_t y)
+{
+ if (in != x + y) {
+ rsSetElementAt_int(aFailed, 1, 0);
+ }
+}
+
+void set_output_void_char(void *out, uint32_t x, uint32_t y) {
+ uchar *out_int = (uchar *)out;
+ *out_int = x + y;
+}
+
+void __attribute__((kernel))check_output_char(const uchar in, uint32_t x, uint32_t y)
+{
+ if (in != x + y) {
+ rsSetElementAt_int(aFailed, 1, 0);
+ }
+}
+
+int __attribute__((kernel)) set_output_int(uint32_t x, uint32_t y) {
+ return x + y;
+}
+
+void copy_void_int(const void *in, uint32_t x, uint32_t y)
+{
+ int *in_int = (int*) in;
+ rsSetElementAt_int(aOutput, *in_int, x, y);
+}
+
+uchar __attribute__((kernel)) set_output_char(uint32_t x, uint32_t y) {
+ return x + y;
+}
+
+void copy_void_char(const void *in, uint32_t x, uint32_t y)
+{
+ uchar *in_uchar = (uchar*) in;
+ rsSetElementAt_uchar(aOutput, *in_uchar, x, y);
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/VoidPtr.java b/tests/tests/renderscript/src/android/renderscript/cts/VoidPtr.java
new file mode 100644
index 0000000..9c18d2d
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/VoidPtr.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * 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 android.renderscript.cts;
+
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.Type;
+
+public class VoidPtr extends RSBaseCompute {
+ Allocation AOutput;
+ Allocation AInput;
+ Allocation AFailed;
+ int [] Failed;
+
+
+ protected void setupVoidPtr(RenderScript mRS, ScriptC_void_ptr gs) {
+ Type.Builder typeBuilder = new Type.Builder(mRS, Element.I32(mRS));
+ Type t = typeBuilder.setX(1).create();
+
+ AFailed = Allocation.createTyped(mRS, t);
+ Failed = new int [1];
+ Failed[0] = 0;
+ AFailed.copyFrom(Failed);
+ gs.set_aFailed(AFailed);
+ }
+
+ /**
+ * Test whether we properly iterate over the elements of an output
+ * allocation, even if the pointer passed to the kernel of the script
+ * is only of type 'void*'
+ *
+ * This test runs for an allocation of type int
+ */
+ public void testVoidOutInt() {
+ ScriptC_void_ptr gs = new ScriptC_void_ptr(mRS);
+ setupVoidPtr(mRS, gs);
+
+ Type.Builder typeBuilder = new Type.Builder(mRS, Element.I32(mRS));
+ Type t = typeBuilder.setX(10).setY(15).create();
+
+ AOutput = Allocation.createTyped(mRS, t);
+
+ gs.forEach_set_output_void_int(AOutput);
+ gs.forEach_check_output_int(AOutput);
+
+ AFailed.copyTo(Failed);
+ if (Failed[0] != 0) {
+ FoundError = true;
+ }
+
+ gs.destroy();
+ checkForErrors();
+ }
+
+ /**
+ * Test whether we properly iterate over the elements of an output
+ * allocation, even if the pointer passed to the kernel of the script
+ * is only of type 'void*'
+ *
+ * This test runs for an allocation of type uchar.
+ */
+ public void testVoidOutChar() {
+ ScriptC_void_ptr gs = new ScriptC_void_ptr(mRS);
+ setupVoidPtr(mRS, gs);
+
+ Type.Builder typeBuilder = new Type.Builder(mRS, Element.U8(mRS));
+ Type t = typeBuilder.setX(10).setY(15).create();
+
+ AOutput = Allocation.createTyped(mRS, t);
+
+ gs.forEach_set_output_void_char(AOutput);
+ gs.forEach_check_output_char(AOutput);
+
+ AFailed.copyTo(Failed);
+ if (Failed[0] != 0) {
+ FoundError = true;
+ }
+
+ gs.destroy();
+ checkForErrors();
+ }
+
+
+ /**
+ * Test whether we properly iterate over the elements of an input
+ * allocation, even if the pointer passed to the kernel of the script
+ * is only of type 'void*'
+ *
+ * This test runs for an allocation of type uchar.
+ */
+ public void testVoidInInt() {
+ ScriptC_void_ptr gs = new ScriptC_void_ptr(mRS);
+ setupVoidPtr(mRS, gs);
+
+ Type.Builder typeBuilder = new Type.Builder(mRS, Element.I32(mRS));
+ Type t = typeBuilder.setX(10).setY(15).create();
+
+ AOutput = Allocation.createTyped(mRS, t);
+ AInput = Allocation.createTyped(mRS, t);
+
+ gs.forEach_set_output_int(AInput);
+ gs.set_aOutput(AOutput);
+ gs.forEach_copy_void_int(AInput);
+ gs.forEach_check_output_int(AOutput);
+
+ AFailed.copyTo(Failed);
+ if (Failed[0] != 0) {
+ FoundError = true;
+ }
+
+ gs.destroy();
+ checkForErrors();
+ }
+
+ /**
+ * Test whether we properly iterate over the elements of an input
+ * allocation, even if the pointer passed to the kernel of the script
+ * is only of type 'void*'
+ *
+ * This test runs for an allocation of type uchar
+ */
+ public void testVoidInChar() {
+ ScriptC_void_ptr gs = new ScriptC_void_ptr(mRS);
+ setupVoidPtr(mRS, gs);
+
+ Type.Builder typeBuilder = new Type.Builder(mRS, Element.U8(mRS));
+ Type t = typeBuilder.setX(10).setY(15).create();
+
+ AOutput = Allocation.createTyped(mRS, t);
+ AInput = Allocation.createTyped(mRS, t);
+
+ gs.forEach_set_output_char(AInput);
+ gs.set_aOutput(AOutput);
+ gs.forEach_copy_void_char(AInput);
+ gs.forEach_check_output_char(AOutput);
+
+ AFailed.copyTo(Failed);
+ if (Failed[0] != 0) {
+ FoundError = true;
+ }
+
+ gs.destroy();
+ checkForErrors();
+ }
+
+}