Merge "Add RenderScript backward compatibility testing"
diff --git a/tests/java_api/RSTestBackward/Android.mk b/tests/java_api/RSTestBackward/Android.mk
new file mode 100644
index 0000000..37a123e
--- /dev/null
+++ b/tests/java_api/RSTestBackward/Android.mk
@@ -0,0 +1,35 @@
+#
+# Copyright (C) 2017 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.
+#
+
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := tests
+LOCAL_PACKAGE_NAME := RSTestBackward
+
+LOCAL_SRC_FILES := \
+ $(call all-java-files-under, src)\
+ $(call all-java-files-under, ../RSUnitTests/src)\
+ $(call all-renderscript-files-under, ../RSUnitTests/src)\
+
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+LOCAL_COMPATIBILITY_SUITE := device-tests
+
+LOCAL_RENDERSCRIPT_TARGET_API := 0
+LOCAL_RENDERSCRIPT_COMPATIBILITY := 19
+LOCAL_MIN_SDK_VERSION := 19
+
+include $(BUILD_PACKAGE)
diff --git a/tests/java_api/RSTestBackward/AndroidManifest.xml b/tests/java_api/RSTestBackward/AndroidManifest.xml
new file mode 100644
index 0000000..9fe37bd
--- /dev/null
+++ b/tests/java_api/RSTestBackward/AndroidManifest.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2017 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.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.rs.testbackward">
+ <uses-sdk
+ android:minSdkVersion="19"
+ android:targetSdkVersion="26" />
+
+ <application
+ android:label="RSTestBackward">
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+ <instrumentation
+ android:name="android.support.test.runner.AndroidJUnitRunner"
+ android:targetPackage="com.android.rs.testbackward"
+ android:label="RenderScript Backward Compatibility Tests" />
+</manifest>
diff --git a/tests/java_api/RSTestBackward/src/com/android/rs/testbackward/RSBackwardCompatibilityTests.java b/tests/java_api/RSTestBackward/src/com/android/rs/testbackward/RSBackwardCompatibilityTests.java
new file mode 100644
index 0000000..cdb4520
--- /dev/null
+++ b/tests/java_api/RSTestBackward/src/com/android/rs/testbackward/RSBackwardCompatibilityTests.java
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.testbackward;
+
+import com.android.rs.unittest.*;
+
+import android.content.Context;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.MediumTest;
+import android.util.Log;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * RSTestBackward, functional test for platform RenderScript APIs.
+ * To run the test, please use command
+ *
+ * adb shell am instrument -w com.android.rs.testbackward/android.support.test.runner.AndroidJUnitRunner
+ *
+ */
+@RunWith(Parameterized.class)
+public class RSBackwardCompatibilityTests {
+ private static final String TAG = "RSBackwardCompatibilityTests";
+
+ /**
+ * Returns the list of subclasses of UnitTest to run.
+ *
+ * Filters out any tests with API version greater than current API version.
+ */
+ @Parameters(name = "{0}")
+ public static Iterable<?> getParams() throws Exception {
+ Context ctx = InstrumentationRegistry.getTargetContext();
+
+ int thisApiVersion = android.os.Build.VERSION.SDK_INT;
+
+ ArrayList<UnitTest> validUnitTests = new ArrayList<>();
+
+ if (thisApiVersion >= 19) {
+ validUnitTests.add(new UT_alloc(ctx));
+ validUnitTests.add(new UT_array_alloc(ctx));
+ validUnitTests.add(new UT_array_init(ctx));
+ validUnitTests.add(new UT_atomic(ctx));
+ validUnitTests.add(new UT_bug_char(ctx));
+ validUnitTests.add(new UT_check_dims(ctx));
+ validUnitTests.add(new UT_clamp(ctx));
+ validUnitTests.add(new UT_clamp_relaxed(ctx));
+ validUnitTests.add(new UT_constant(ctx));
+ validUnitTests.add(new UT_convert(ctx));
+ validUnitTests.add(new UT_convert_relaxed(ctx));
+ validUnitTests.add(new UT_copy_test(ctx));
+ validUnitTests.add(new UT_element(ctx));
+ validUnitTests.add(new UT_foreach_bounds(ctx));
+ validUnitTests.add(new UT_foreach(ctx));
+ validUnitTests.add(new UT_fp_mad(ctx));
+ validUnitTests.add(new UT_int4(ctx));
+ validUnitTests.add(new UT_kernel(ctx));
+ validUnitTests.add(new UT_kernel_struct(ctx));
+ validUnitTests.add(new UT_math_agree(ctx));
+ validUnitTests.add(new UT_math_conformance(ctx));
+ validUnitTests.add(new UT_math(ctx));
+ // validUnitTests.add(new UT_mesh(ctx)); // removed in 21
+ validUnitTests.add(new UT_min(ctx));
+ validUnitTests.add(new UT_noroot(ctx));
+ validUnitTests.add(new UT_primitives(ctx));
+ // validUnitTests.add(new UT_program_raster(ctx)); // removed in 21
+ // validUnitTests.add(new UT_program_store(ctx)); // removed in 21
+ validUnitTests.add(new UT_refcount(ctx));
+ validUnitTests.add(new UT_rsdebug(ctx));
+ validUnitTests.add(new UT_rstime(ctx));
+ validUnitTests.add(new UT_rstypes(ctx));
+ validUnitTests.add(new UT_sampler(ctx));
+ validUnitTests.add(new UT_static_globals(ctx));
+ validUnitTests.add(new UT_struct(ctx));
+ validUnitTests.add(new UT_unsigned(ctx));
+ validUnitTests.add(new UT_vector(ctx));
+ }
+
+ if (thisApiVersion >= 23) {
+ validUnitTests.add(new UT_ctxt_default(ctx));
+ validUnitTests.add(new UT_foreach_multi(ctx));
+ validUnitTests.add(new UT_kernel2d(ctx));
+ validUnitTests.add(new UT_kernel2d_oldstyle(ctx));
+ validUnitTests.add(new UT_kernel3d(ctx));
+ validUnitTests.add(new UT_script_group2_gatherscatter(ctx));
+ validUnitTests.add(new UT_script_group2_nochain(ctx));
+ validUnitTests.add(new UT_script_group2_pointwise(ctx));
+ }
+
+ if (thisApiVersion >= 24) {
+ validUnitTests.add(new UT_fp16_globals(ctx));
+ validUnitTests.add(new UT_fp16(ctx));
+ validUnitTests.add(new UT_math_24(ctx));
+ validUnitTests.add(new UT_math_fp16(ctx));
+ validUnitTests.add(new UT_reduce_backward(ctx));
+ validUnitTests.add(new UT_reduce(ctx));
+ validUnitTests.add(new UT_rsdebug_24(ctx));
+ validUnitTests.add(new UT_script_group2_float(ctx));
+ validUnitTests.add(new UT_single_source_alloc(ctx));
+ validUnitTests.add(new UT_single_source_ref_count(ctx));
+ validUnitTests.add(new UT_single_source_script(ctx));
+ validUnitTests.add(new UT_small_struct(ctx));
+ }
+
+ if (thisApiVersion >= 25) {
+ validUnitTests.add(new UT_bitfield(ctx));
+ validUnitTests.add(new UT_small_struct_2(ctx));
+ validUnitTests.add(new UT_struct_field(ctx));
+ validUnitTests.add(new UT_struct_field_simple(ctx));
+ }
+
+ return validUnitTests;
+ }
+
+ @Parameter(0)
+ public UnitTest mTest;
+
+ @Test
+ @MediumTest
+ public void testRSUnitTest() throws Exception {
+ mTest.runTest();
+ switch (mTest.getResult()) {
+ case UT_NOT_STARTED:
+ case UT_RUNNING:
+ Log.w(TAG, "unexpected unit test result: " + mTest.getResult().toString());
+ break;
+ }
+ Assert.assertTrue(mTest.getSuccess());
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_alloc.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_alloc.java
new file mode 100644
index 0000000..6bbf3b6
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_alloc.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.Type;
+
+public class UT_alloc extends UnitTest {
+ private Type T;
+ private Type mTFaces;
+ private Type mTLOD;
+ private Type mTFacesLOD;
+ private Allocation mAFaces;
+ private Allocation mALOD;
+ private Allocation mAFacesLOD;
+
+ public UT_alloc(Context ctx) {
+ super("Alloc", ctx);
+ }
+
+ private void initializeGlobals(RenderScript RS, ScriptC_alloc s) {
+ Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS));
+ int X = 5;
+ int Y = 7;
+ int Z = 0;
+ s.set_dimX(X);
+ s.set_dimY(Y);
+ s.set_dimZ(Z);
+ typeBuilder.setX(X); // Only build a 1-D version of this
+ T = typeBuilder.create();
+ Allocation A = Allocation.createTyped(RS, T);
+ s.bind_a(A);
+ s.set_aRaw(A);
+
+ typeBuilder = new Type.Builder(RS, Element.I32(RS));
+ typeBuilder.setX(X).setY(Y).setFaces(true);
+ mTFaces = typeBuilder.create();
+ mAFaces = Allocation.createTyped(RS, mTFaces);
+ s.set_aFaces(mAFaces);
+ typeBuilder.setFaces(false).setMipmaps(true);
+ mTLOD = typeBuilder.create();
+ mALOD = Allocation.createTyped(RS, mTLOD);
+ s.set_aLOD(mALOD);
+ typeBuilder.setFaces(true).setMipmaps(true);
+ mTFacesLOD = typeBuilder.create();
+ mAFacesLOD = Allocation.createTyped(RS, mTFacesLOD);
+ s.set_aFacesLOD(mAFacesLOD);
+
+ return;
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_alloc s = new ScriptC_alloc(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ initializeGlobals(pRS, s);
+ s.forEach_root(s.get_aRaw());
+ s.invoke_alloc_test();
+ pRS.finish();
+ T.destroy();
+ s.get_a().destroy();
+ mAFaces.destroy();
+ mALOD.destroy();
+ mAFacesLOD.destroy();
+ mTFaces.destroy();
+ mTLOD.destroy();
+ mTFacesLOD.destroy();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_array_alloc.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_array_alloc.java
new file mode 100644
index 0000000..df57e85
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_array_alloc.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.Type;
+
+public class UT_array_alloc extends UnitTest {
+
+ public UT_array_alloc(Context ctx) {
+ super("Array Allocation", ctx);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_array_alloc s = new ScriptC_array_alloc(pRS);
+ pRS.setMessageHandler(mRsMessage);
+
+ int dimX = s.get_dimX();
+ Allocation[] Arr = new Allocation[dimX];
+ Type.Builder typeBuilder = new Type.Builder(pRS, Element.I32(pRS));
+ Type T = typeBuilder.setX(1).create();
+ for (int i = 0; i < dimX; i++) {
+ Allocation A = Allocation.createTyped(pRS, T);
+ Arr[i] = A;
+ }
+ s.set_a(Arr);
+
+ s.invoke_array_alloc_test();
+ pRS.finish();
+ for (int i = 0; i < dimX; i++) {
+ Arr[i].destroy();
+ }
+ T.destroy();
+ s.destroy();
+ pRS.destroy();
+ passTest();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_array_init.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_array_init.java
new file mode 100644
index 0000000..b76685d
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_array_init.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript;
+
+public class UT_array_init extends UnitTest {
+
+ public UT_array_init(Context ctx) {
+ super("Array Init", ctx);
+ }
+
+ private void checkInit(ScriptC_array_init s) {
+ float[] fa = s.get_fa();
+ _RS_ASSERT("fa[0] == 1.0", fa[0] == 1.0);
+ _RS_ASSERT("fa[1] == 9.9999f", fa[1] == 9.9999f);
+ _RS_ASSERT("fa[2] == 0", fa[2] == 0);
+ _RS_ASSERT("fa[3] == 0", fa[3] == 0);
+ _RS_ASSERT("fa.length == 4", fa.length == 4);
+
+ double[] da = s.get_da();
+ _RS_ASSERT("da[0] == 7.0", da[0] == 7.0);
+ _RS_ASSERT("da[1] == 8.88888", da[1] == 8.88888);
+ _RS_ASSERT("da.length == 2", da.length == 2);
+
+ byte[] ca = s.get_ca();
+ _RS_ASSERT("ca[0] == 'a'", ca[0] == 'a');
+ _RS_ASSERT("ca[1] == 7", ca[1] == 7);
+ _RS_ASSERT("ca[2] == 'b'", ca[2] == 'b');
+ _RS_ASSERT("ca[3] == 'c'", ca[3] == 'c');
+ _RS_ASSERT("ca.length == 4", ca.length == 4);
+
+ short[] sa = s.get_sa();
+ _RS_ASSERT("sa[0] == 1", sa[0] == 1);
+ _RS_ASSERT("sa[1] == 1", sa[1] == 1);
+ _RS_ASSERT("sa[2] == 2", sa[2] == 2);
+ _RS_ASSERT("sa[3] == 3", sa[3] == 3);
+ _RS_ASSERT("sa.length == 4", sa.length == 4);
+
+ int[] ia = s.get_ia();
+ _RS_ASSERT("ia[0] == 5", ia[0] == 5);
+ _RS_ASSERT("ia[1] == 8", ia[1] == 8);
+ _RS_ASSERT("ia[2] == 0", ia[2] == 0);
+ _RS_ASSERT("ia[3] == 0", ia[3] == 0);
+ _RS_ASSERT("ia.length == 4", ia.length == 4);
+
+ long[] la = s.get_la();
+ _RS_ASSERT("la[0] == 13", la[0] == 13);
+ _RS_ASSERT("la[1] == 21", la[1] == 21);
+ _RS_ASSERT("la.length == 4", la.length == 2);
+
+ long[] lla = s.get_lla();
+ _RS_ASSERT("lla[0] == 34", lla[0] == 34);
+ _RS_ASSERT("lla[1] == 0", lla[1] == 0);
+ _RS_ASSERT("lla[2] == 0", lla[2] == 0);
+ _RS_ASSERT("lla[3] == 0", lla[3] == 0);
+ _RS_ASSERT("lla.length == 4", lla.length == 4);
+
+ boolean[] ba = s.get_ba();
+ _RS_ASSERT("ba[0] == true", ba[0] == true);
+ _RS_ASSERT("ba[1] == false", ba[1] == false);
+ _RS_ASSERT("ba[2] == false", ba[2] == false);
+ _RS_ASSERT("ba.length == 3", ba.length == 3);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_array_init s = new ScriptC_array_init(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ checkInit(s);
+ s.invoke_array_init_test();
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+ passTest();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_atomic.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_atomic.java
new file mode 100644
index 0000000..7a92685
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_atomic.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript;
+
+public class UT_atomic extends UnitTest {
+
+ public UT_atomic(Context ctx) {
+ super("Atomics", ctx);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_atomic s = new ScriptC_atomic(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ s.invoke_atomic_test();
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_bitfield.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_bitfield.java
new file mode 100644
index 0000000..e02119a
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_bitfield.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript;
+
+public class UT_bitfield extends UnitTest {
+
+ public UT_bitfield(Context ctx) {
+ super("Bitfield", ctx);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_bitfield s = new ScriptC_bitfield(pRS);
+ pRS.setMessageHandler(mRsMessage);
+
+ final long L = 0x76543210fedcba98L;
+ final int I = 0x12345678;
+
+ s.invoke_choose(1);
+ s.invoke_setUnion(L, I);
+ s.invoke_testUnion(L, I);
+
+ pRS.finish();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_bug_char.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_bug_char.java
new file mode 100644
index 0000000..a2477e7
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_bug_char.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Byte2;
+import android.renderscript.RenderScript;
+import android.util.Log;
+
+import java.util.Arrays;
+
+public class UT_bug_char extends UnitTest {
+
+ public UT_bug_char(Context ctx) {
+ super("Bug Char", ctx);
+ }
+
+ // packing functions
+ private Byte2 pack_b2(byte[] val) {
+ assert val.length == 2;
+ Log.i("bug_char", "pack_b2 " + val[0] + " " + val[1]);
+ return new Byte2(val[0], val[1]);
+ }
+
+ private byte min(byte v1, byte v2) {
+ return v1 < v2 ? v1 : v2;
+ }
+
+ private byte[] min(byte[] v1, byte[] v2) {
+ assert v1.length == v2.length;
+ byte[] rv = new byte[v1.length];
+ for (int i = 0; i < v1.length; ++i)
+ rv[i] = min(v1[i], v2[i]);
+ return rv;
+ }
+
+ private void initializeValues(ScriptC_bug_char s) {
+ byte rand_sc1_0 = (byte) 7;
+ byte[] rand_sc2_0 = new byte[2];
+ rand_sc2_0[0] = 11;
+ rand_sc2_0[1] = 21;
+ Log.i("bug_char", "Generated sc2_0 to " + Arrays.toString(rand_sc2_0));
+ byte rand_sc1_1 = (byte) 10;
+ byte[] rand_sc2_1 = new byte[2];
+ rand_sc2_1[0] = 13;
+ rand_sc2_1[1] = 15;
+ Log.i("bug_char", "Generated sc2_1 to " + Arrays.toString(rand_sc2_1));
+
+ s.set_rand_sc1_0(rand_sc1_0);
+ s.set_rand_sc2_0(pack_b2(rand_sc2_0));
+ s.set_rand_sc1_1(rand_sc1_1);
+ s.set_rand_sc2_1(pack_b2(rand_sc2_1));
+ // Set results for min
+ s.set_min_rand_sc1_sc1(min(rand_sc1_0, rand_sc1_1));
+ byte[] min_rand_sc2_raw = min(rand_sc2_0, rand_sc2_1);
+ Log.i("bug_char", "Generating min_rand_sc2_sc2 to " +
+ Arrays.toString(min_rand_sc2_raw));
+ Byte2 min_rand_sc2 = pack_b2(min_rand_sc2_raw);
+ Log.i("bug_char", "Setting min_rand_sc2_sc2 to [" + min_rand_sc2.x +
+ ", " + min_rand_sc2.y + "]");
+ s.set_min_rand_sc2_sc2(min_rand_sc2);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_bug_char s = new ScriptC_bug_char(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ initializeValues(s);
+ s.invoke_bug_char_test();
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_check_dims.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_check_dims.java
new file mode 100644
index 0000000..770d5df
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_check_dims.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.Type;
+
+public class UT_check_dims extends UnitTest {
+ byte mFailedArr[];
+ int mData[];
+ Allocation mAFailed;
+ Allocation mA;
+ static final int Pattern = 0xA5A5A5A5;
+
+ public UT_check_dims(Context ctx) {
+ super("Check Dims", ctx);
+ }
+
+ private void initializeGlobals(RenderScript RS, ScriptC_check_dims s) {
+ Type.Builder typeBuilder = new Type.Builder(RS, Element.U8(RS));
+ typeBuilder.setX(1);
+ mAFailed = Allocation.createTyped(RS, typeBuilder.create());
+ s.set_aFailed(mAFailed);
+
+ mFailedArr = new byte[1];
+ mFailedArr[0] = 0;
+ mAFailed.copyFrom(mFailedArr);
+
+ typeBuilder = new Type.Builder(RS, Element.I32(RS));
+ int X = 5;
+ int Y = 7;
+ typeBuilder.setX(X).setY(Y);
+ mA = Allocation.createTyped(RS, typeBuilder.create());
+ s.set_pattern(Pattern);
+
+ mData = new int[X * Y];
+ for (int i = 0; i < X * Y; i++) {
+ mData[i] = Pattern;
+ }
+ mA.copyFrom(mData);
+
+ return;
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_check_dims s = new ScriptC_check_dims(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ initializeGlobals(pRS, s);
+ s.forEach_root(mA);
+ s.invoke_check_dims_test();
+ pRS.finish();
+ mAFailed.destroy();
+ mA.destroy();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_clamp.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_clamp.java
new file mode 100644
index 0000000..37c8772
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_clamp.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript;
+
+public class UT_clamp extends UnitTest {
+
+ public UT_clamp(Context ctx) {
+ super("Clamp (Full)", ctx);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_clamp s = new ScriptC_clamp(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ s.invoke_clamp_test();
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_clamp_relaxed.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_clamp_relaxed.java
new file mode 100644
index 0000000..3074623
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_clamp_relaxed.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript;
+
+public class UT_clamp_relaxed extends UnitTest {
+
+ public UT_clamp_relaxed(Context ctx) {
+ super("Clamp (Relaxed)", ctx);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_clamp_relaxed s =
+ new ScriptC_clamp_relaxed(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ s.invoke_clamp_test();
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_constant.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_constant.java
new file mode 100644
index 0000000..b2196ec
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_constant.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+
+public class UT_constant extends UnitTest {
+
+ public UT_constant(Context ctx) {
+ super("Const", ctx);
+ }
+
+ private void Assert(boolean b) {
+ if (!b) {
+ failTest();
+ }
+ }
+
+ public void run() {
+ Assert(ScriptC_constant.const_floatTest == 1.99f);
+ Assert(ScriptC_constant.const_doubleTest == 2.05);
+ Assert(ScriptC_constant.const_charTest == -8);
+ Assert(ScriptC_constant.const_shortTest == -16);
+ Assert(ScriptC_constant.const_intTest == -32);
+ Assert(ScriptC_constant.const_longTest == 17179869184l);
+ Assert(ScriptC_constant.const_longlongTest == 68719476736l);
+
+ Assert(ScriptC_constant.const_ucharTest == 8);
+ Assert(ScriptC_constant.const_ushortTest == 16);
+ Assert(ScriptC_constant.const_uintTest == 32);
+ Assert(ScriptC_constant.const_ulongTest == 4611686018427387904L);
+ Assert(ScriptC_constant.const_int64_tTest == -17179869184l);
+ Assert(ScriptC_constant.const_uint64_tTest == 117179869184l);
+
+ Assert(ScriptC_constant.const_boolTest == true);
+
+ passTest();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_convert.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_convert.java
new file mode 100644
index 0000000..ed460a3
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_convert.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript;
+
+public class UT_convert extends UnitTest {
+
+ public UT_convert(Context ctx) {
+ super("Convert", ctx);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_convert s = new ScriptC_convert(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ s.invoke_convert_test();
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_convert_relaxed.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_convert_relaxed.java
new file mode 100644
index 0000000..058dc5e
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_convert_relaxed.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript;
+
+public class UT_convert_relaxed extends UnitTest {
+
+ public UT_convert_relaxed(Context ctx) {
+ super("Convert (Relaxed)", ctx);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_convert_relaxed s =
+ new ScriptC_convert_relaxed(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ s.invoke_convert_test();
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_copy_test.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_copy_test.java
new file mode 100644
index 0000000..7feddca
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_copy_test.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.util.Log;
+
+public class UT_copy_test extends UnitTest {
+ boolean pass = true;
+
+ public UT_copy_test(Context ctx) {
+ super("Copy", ctx);
+ }
+
+ void testFloat2(RenderScript rs, ScriptC_copy_test s) {
+ Allocation a1 = Allocation.createSized(rs, Element.F32_2(rs), 1024);
+ Allocation a2 = Allocation.createSized(rs, Element.F32_2(rs), 1024);
+
+ float[] f1 = new float[1024 * 2];
+ float[] f2 = new float[1024 * 2];
+ for (int ct = 0; ct < f1.length; ct++) {
+ f1[ct] = (float) ct;
+ }
+ a1.copyFrom(f1);
+
+ s.forEach_copyFloat2(a1, a2);
+
+ a2.copyTo(f2);
+ for (int ct = 0; ct < f1.length; ct++) {
+ if (f1[ct] != f2[ct]) {
+ failTest();
+ Log.v("RS Test", "Compare failed at " + ct + ", " + f1[ct] + ", " + f2[ct]);
+ }
+ }
+ a1.destroy();
+ a2.destroy();
+ }
+
+ void testFloat3(RenderScript rs, ScriptC_copy_test s) {
+ Allocation a1 = Allocation.createSized(rs, Element.F32_3(rs), 1024);
+ Allocation a2 = Allocation.createSized(rs, Element.F32_3(rs), 1024);
+
+ float[] f1 = new float[1024 * 4];
+ float[] f2 = new float[1024 * 4];
+ for (int ct = 0; ct < f1.length; ct++) {
+ f1[ct] = (float) ct;
+ }
+ a1.copyFrom(f1);
+
+ s.forEach_copyFloat3(a1, a2);
+
+ a2.copyTo(f2);
+ for (int ct = 0; ct < f1.length; ct++) {
+ if ((f1[ct] != f2[ct]) && ((ct & 3) != 3)) {
+ failTest();
+ Log.v("RS Test", "Compare failed at " + ct + ", " + f1[ct] + ", " + f2[ct]);
+ }
+ }
+ a1.destroy();
+ a2.destroy();
+ }
+
+ void testFloat4(RenderScript rs, ScriptC_copy_test s) {
+ Allocation a1 = Allocation.createSized(rs, Element.F32_4(rs), 1024);
+ Allocation a2 = Allocation.createSized(rs, Element.F32_4(rs), 1024);
+
+ float[] f1 = new float[1024 * 4];
+ float[] f2 = new float[1024 * 4];
+ for (int ct = 0; ct < f1.length; ct++) {
+ f1[ct] = (float) ct;
+ }
+ a1.copyFrom(f1);
+
+ s.forEach_copyFloat4(a1, a2);
+
+ a2.copyTo(f2);
+ for (int ct = 0; ct < f1.length; ct++) {
+ if (f1[ct] != f2[ct]) {
+ failTest();
+ Log.v("RS Test", "Compare failed at " + ct + ", " + f1[ct] + ", " + f2[ct]);
+ }
+ }
+ a1.destroy();
+ a2.destroy();
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_copy_test s = new ScriptC_copy_test(pRS);
+ pRS.setMessageHandler(mRsMessage);
+
+ testFloat2(pRS, s);
+ testFloat3(pRS, s);
+ testFloat4(pRS, s);
+ s.invoke_sendResult(true);
+
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+ }
+}
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_ctxt_default.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_ctxt_default.java
new file mode 100644
index 0000000..40ad6ce
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_ctxt_default.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.Type;
+
+public class UT_ctxt_default extends UnitTest {
+ private Type T;
+ private Allocation A;
+ private Allocation B;
+
+ public UT_ctxt_default(Context ctx) {
+ super("Kernel context default", ctx);
+ }
+
+ private void initializeGlobals(RenderScript RS, ScriptC_ctxt_default s) {
+ Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS));
+ int X = 2;
+ s.set_gDimX(X);
+ typeBuilder.setX(X);
+
+ T = typeBuilder.create();
+ A = Allocation.createTyped(RS, T);
+ s.set_A(A);
+ B = Allocation.createTyped(RS, T);
+ s.set_B(B);
+ return;
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_ctxt_default s = new ScriptC_ctxt_default(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ initializeGlobals(pRS, s);
+ s.forEach_init_vars(A);
+ s.forEach_root(A, B);
+ s.invoke_verify_root();
+ s.invoke_kernel_test();
+ pRS.finish();
+ T.destroy();
+ A.destroy();
+ B.destroy();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_element.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_element.java
new file mode 100644
index 0000000..af821b7
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_element.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Element;
+import android.renderscript.Element.DataKind;
+import android.renderscript.Element.DataType;
+import android.renderscript.RenderScript;
+
+public class UT_element extends UnitTest {
+ Element simpleElem;
+ Element complexElem;
+
+ final String subElemNames[] = {
+ "subElem0",
+ "subElem1",
+ "subElem2",
+ "arrayElem0",
+ "arrayElem1",
+ "subElem3",
+ "subElem4",
+ "subElem5",
+ "subElem6",
+ "subElem_7",
+ };
+
+ final int subElemArraySizes[] = {
+ 1,
+ 1,
+ 1,
+ 2,
+ 5,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ };
+
+ final int subElemOffsets[] = {
+ 0,
+ 4,
+ 8,
+ 12,
+ 20,
+ 40,
+ 44,
+ 48,
+ 64,
+ 80,
+ };
+
+ public UT_element(Context ctx) {
+ super("Element", ctx);
+ }
+
+ private void initializeGlobals(RenderScript RS, ScriptC_element s) {
+ simpleElem = Element.F32_3(RS);
+ complexElem = ScriptField_ComplexStruct.createElement(RS);
+ s.set_simpleElem(simpleElem);
+ s.set_complexElem(complexElem);
+
+ ScriptField_ComplexStruct data = new ScriptField_ComplexStruct(RS, 1);
+ s.bind_complexStruct(data);
+ }
+
+ private void testScriptSide(RenderScript pRS) {
+ ScriptC_element s = new ScriptC_element(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ initializeGlobals(pRS, s);
+ s.invoke_element_test();
+ pRS.finish();
+ s.get_complexStruct().getAllocation().destroy();
+ s.get_complexStruct().getElement().destroy();
+ s.destroy();
+ }
+
+ private void testJavaSide(RenderScript RS) {
+
+ int subElemCount = simpleElem.getSubElementCount();
+ _RS_ASSERT("subElemCount == 0", subElemCount == 0);
+ _RS_ASSERT("simpleElem.getDataKind() == USER",
+ simpleElem.getDataKind() == DataKind.USER);
+ _RS_ASSERT("simpleElem.getDataType() == FLOAT_32",
+ simpleElem.getDataType() == DataType.FLOAT_32);
+
+ subElemCount = complexElem.getSubElementCount();
+ _RS_ASSERT("subElemCount == 10", subElemCount == 10);
+ _RS_ASSERT("complexElem.getDataKind() == USER",
+ complexElem.getDataKind() == DataKind.USER);
+ _RS_ASSERT("complexElemsimpleElem.getDataType() == NONE",
+ complexElem.getDataType() == DataType.NONE);
+
+ for (int i = 0; i < subElemCount; i++) {
+ _RS_ASSERT("complexElem.getSubElement(i) != null",
+ complexElem.getSubElement(i) != null);
+ _RS_ASSERT("complexElem.getSubElementName(i).equals(subElemNames[i])",
+ complexElem.getSubElementName(i).equals(subElemNames[i]));
+ _RS_ASSERT("complexElem.getSubElementArraySize(i) == subElemArraySizes[i]",
+ complexElem.getSubElementArraySize(i) == subElemArraySizes[i]);
+ _RS_ASSERT("complexElem.getSubElementOffsetBytes(i) == subElemOffsets[i]",
+ complexElem.getSubElementOffsetBytes(i) == subElemOffsets[i]);
+ }
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ testScriptSide(pRS);
+ testJavaSide(pRS);
+ passTest();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_foreach.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_foreach.java
new file mode 100644
index 0000000..dfa56c6
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_foreach.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.Type;
+
+public class UT_foreach extends UnitTest {
+ private Allocation A;
+
+ public UT_foreach(Context ctx) {
+ super("ForEach", ctx);
+ }
+
+ private void initializeGlobals(RenderScript RS, ScriptC_foreach s) {
+ Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS));
+ int X = 5;
+ int Y = 7;
+ s.set_dimX(X);
+ s.set_dimY(Y);
+ typeBuilder.setX(X).setY(Y);
+ A = Allocation.createTyped(RS, typeBuilder.create());
+ s.set_aRaw(A);
+
+ return;
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_foreach s = new ScriptC_foreach(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ initializeGlobals(pRS, s);
+ s.forEach_root(A);
+ s.invoke_verify_root();
+ s.forEach_foo(A, A);
+ s.invoke_verify_foo();
+ s.invoke_foreach_test();
+ pRS.finish();
+ A.getType().destroy();
+ A.destroy();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_foreach_bounds.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_foreach_bounds.java
new file mode 100644
index 0000000..5ea1ae6
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_foreach_bounds.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.Script;
+import android.renderscript.Type;
+
+public class UT_foreach_bounds extends UnitTest {
+ private Allocation A;
+
+ public UT_foreach_bounds(Context ctx) {
+ super("ForEach (bounds)", ctx);
+ }
+
+ private void initializeGlobals(RenderScript RS, ScriptC_foreach_bounds s) {
+ Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS));
+ int X = 5;
+ int Y = 7;
+ final int xStart = 2;
+ final int xEnd = 5;
+ final int yStart = 3;
+ final int yEnd = 6;
+ s.set_dimX(X);
+ s.set_dimY(Y);
+ typeBuilder.setX(X).setY(Y);
+ A = Allocation.createTyped(RS, typeBuilder.create());
+ s.set_aRaw(A);
+ s.set_s(s);
+ s.set_ain(A);
+ s.set_aout(A);
+ s.set_xStart(xStart);
+ s.set_xEnd(xEnd);
+ s.set_yStart(yStart);
+ s.set_yEnd(yEnd);
+ s.forEach_zero(A);
+
+ Script.LaunchOptions sc = new Script.LaunchOptions();
+ sc.setX(xStart, xEnd).setY(yStart, yEnd);
+ s.forEach_root(A, sc);
+
+ return;
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_foreach_bounds s = new ScriptC_foreach_bounds(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ initializeGlobals(pRS, s);
+ s.invoke_verify_root();
+ s.invoke_foreach_bounds_test();
+ pRS.finish();
+ A.getType().destroy();
+ A.destroy();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_foreach_multi.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_foreach_multi.java
new file mode 100644
index 0000000..959f8ba
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_foreach_multi.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.Type;
+
+public class UT_foreach_multi extends UnitTest {
+ private Allocation Ain0;
+ private Allocation Ain1;
+ private Allocation Ain2;
+ private Allocation Ain3;
+
+ private Allocation Out0;
+ private Allocation Out1;
+ private Allocation Out2;
+ private Allocation Out3;
+
+ public UT_foreach_multi(Context ctx) {
+ super("Foreach Multi-input", ctx);
+ }
+
+ private void initializeGlobals(RenderScript RS, ScriptC_foreach_multi s) {
+ Type.Builder type32Builder = new Type.Builder(RS, Element.U32(RS));
+ Type.Builder type16Builder = new Type.Builder(RS, Element.U16(RS));
+
+ int Xdim = 5;
+ s.set_dimX(Xdim);
+ type32Builder.setX(Xdim);
+ type16Builder.setX(Xdim);
+
+ // 32-bit input allocations
+
+ Ain0 = Allocation.createTyped(RS, type32Builder.create());
+ s.set_ain0(Ain0);
+ s.forEach_init_uint32_alloc(Ain0);
+
+ Ain1 = Allocation.createTyped(RS, type32Builder.create());
+ s.set_ain1(Ain1);
+ s.forEach_init_uint32_alloc(Ain1);
+
+ Ain2 = Allocation.createTyped(RS, type32Builder.create());
+ s.set_ain2(Ain2);
+ s.forEach_init_uint32_alloc(Ain2);
+
+ // 16-bit input allocation
+
+ Ain3 = Allocation.createTyped(RS, type16Builder.create());
+ s.set_ain3(Ain3);
+ s.forEach_init_uint16_alloc(Ain3);
+
+ // 32-bit output allocations
+
+ Out0 = Allocation.createTyped(RS, type32Builder.create());
+ s.set_aout0(Out0);
+
+ Out1 = Allocation.createTyped(RS, type32Builder.create());
+ s.set_aout1(Out1);
+
+ Out2 = Allocation.createTyped(RS, type32Builder.create());
+ s.set_aout2(Out2);
+
+ // RetStruct output allocations
+
+ ScriptField_RetStruct StructType = new ScriptField_RetStruct(RS, Xdim);
+ Out3 = StructType.getAllocation();
+ s.set_aout3(Out3);
+
+ return;
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_foreach_multi s = new ScriptC_foreach_multi(pRS);
+
+ pRS.setMessageHandler(mRsMessage);
+
+ initializeGlobals(pRS, s);
+
+ s.forEach_sum2(Ain0, Ain1, Out0);
+ s.forEach_sum3(Ain0, Ain1, Ain2, Out1);
+ s.forEach_sum_mixed(Ain0, Ain3, Out2);
+ s.forEach_sum2_struct(Ain0, Ain1, Out3);
+
+ s.invoke_test_outputs();
+ s.invoke_check_test_results();
+
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_fp16.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_fp16.java
new file mode 100644
index 0000000..01e99c5
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_fp16.java
@@ -0,0 +1,160 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.Type;
+
+public class UT_fp16 extends UnitTest {
+ private int dimX = 7;
+ private int dimY = 5;
+ private int dimZ = 3;
+ private Type type;
+ private Allocation alloc;
+
+ public UT_fp16(Context ctx) {
+ super("Fp16", ctx);
+ }
+
+ private void initializeGlobals(RenderScript RS, ScriptC_fp16 s, Element e, int nDims) {
+ Type.Builder typeBuilder = new Type.Builder(RS, e);
+ switch (nDims) {
+ case 1:
+ typeBuilder.setX(dimX);
+ break;
+ case 2:
+ typeBuilder.setX(dimX).setY(dimY);
+ break;
+ case 3:
+ typeBuilder.setX(dimX).setY(dimY).setZ(dimZ);
+ break;
+ }
+ type = typeBuilder.create();
+ alloc = Allocation.createTyped(RS, type);
+
+ s.set_gDimX(dimX);
+ s.set_gDimY(nDims > 1 ? dimY : 0);
+ s.set_gDimZ(nDims > 2 ? dimZ : 0);
+ s.set_gAlloc(alloc);
+ }
+
+ private void TestHalf(RenderScript RS, ScriptC_fp16 s, int nDims) {
+ initializeGlobals(RS, s, Element.F16(RS), nDims);
+
+ // set in kernel and test rsGetElementAt in invoke
+ s.forEach_set_kernel_half(alloc);
+ s.invoke_verify_half();
+
+ RS.finish();
+ alloc.destroy();
+ type.destroy();
+
+ initializeGlobals(RS, s, Element.F16(RS), nDims);
+ // rsSetElementAt in invoke and verify in kernel
+ s.invoke_set_half();
+ s.forEach_verify_kernel_half(alloc);
+
+ RS.finish();
+ alloc.destroy();
+ type.destroy();
+ }
+
+ private void TestHalf2(RenderScript RS, ScriptC_fp16 s, int nDims) {
+ initializeGlobals(RS, s, Element.F16_2(RS), nDims);
+
+ // set in kernel and test rsGetElementAt in invoke
+ s.forEach_set_kernel_half2(alloc);
+ s.invoke_verify_half2();
+
+ RS.finish();
+ alloc.destroy();
+ type.destroy();
+
+ initializeGlobals(RS, s, Element.F16_2(RS), nDims);
+ // rsSetElementAt in invoke and verify in kernel
+ s.invoke_set_half2();
+ s.forEach_verify_kernel_half2(alloc);
+
+ RS.finish();
+ alloc.destroy();
+ type.destroy();
+ }
+
+ private void TestHalf3(RenderScript RS, ScriptC_fp16 s, int nDims) {
+ initializeGlobals(RS, s, Element.F16_3(RS), nDims);
+
+ // set in kernel and test rsGetElementAt in invoke
+ s.forEach_set_kernel_half3(alloc);
+ s.invoke_verify_half3();
+
+ RS.finish();
+ alloc.destroy();
+ type.destroy();
+
+ initializeGlobals(RS, s, Element.F16_3(RS), nDims);
+ // rsSetElementAt in invoke and verify in kernel
+ s.invoke_set_half3();
+ s.forEach_verify_kernel_half3(alloc);
+
+ RS.finish();
+ alloc.destroy();
+ type.destroy();
+ }
+
+ private void TestHalf4(RenderScript RS, ScriptC_fp16 s, int nDims) {
+ initializeGlobals(RS, s, Element.F16_4(RS), nDims);
+
+ // set in kernel and test rsGetElementAt in invoke
+ s.forEach_set_kernel_half4(alloc);
+ s.invoke_verify_half4();
+
+ RS.finish();
+ alloc.destroy();
+ type.destroy();
+
+ initializeGlobals(RS, s, Element.F16_4(RS), nDims);
+ // rsSetElementAt in invoke and verify in kernel
+ s.invoke_set_half4();
+ s.forEach_verify_kernel_half4(alloc);
+
+ RS.finish();
+ alloc.destroy();
+ type.destroy();
+ }
+
+ public void run() {
+ Allocation A;
+ RenderScript pRS = RenderScript.create(mCtx);
+ pRS.setMessageHandler(mRsMessage);
+ ScriptC_fp16 s = new ScriptC_fp16(pRS);
+
+ for (int nDims = 1; nDims <= 3; nDims++) {
+ TestHalf(pRS, s, nDims);
+ TestHalf2(pRS, s, nDims);
+ TestHalf3(pRS, s, nDims);
+ TestHalf4(pRS, s, nDims);
+ }
+
+ s.invoke_fp16_test();
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_fp16_globals.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_fp16_globals.java
new file mode 100644
index 0000000..0aad93c
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_fp16_globals.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript;
+import android.renderscript.Short2;
+import android.renderscript.Short3;
+import android.renderscript.Short4;
+
+public class UT_fp16_globals extends UnitTest {
+ private static final short mHalfConst0 = (short) 0x4900; // 10.f
+ private static final short mHalfConst1 = (short) 0x4980; // 11.f
+ private static final short mHalfConst2 = (short) 0xca00; // -12.f
+ private static final short mHalfConst3 = (short) 0xca80; // -13.f
+
+ public UT_fp16_globals(Context ctx) {
+ super("Fp16 Globals", ctx);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ pRS.setMessageHandler(mRsMessage);
+ ScriptC_fp16_globals s = new ScriptC_fp16_globals(pRS);
+
+ Short2 half2Value = new Short2(mHalfConst0, mHalfConst1);
+ Short3 half3Value = new Short3(mHalfConst0, mHalfConst1, mHalfConst2);
+ Short4 half4Value = new Short4(mHalfConst0, mHalfConst1, mHalfConst2, mHalfConst3);
+
+ s.set_gHalf(mHalfConst0);
+ s.set_gHalf2(half2Value);
+ s.set_gHalf3(half3Value);
+ s.set_gHalf4(half4Value);
+
+ s.invoke_test(mHalfConst0, half2Value, half3Value, half4Value);
+ s.invoke_validateHalf(mHalfConst0);
+ s.invoke_validateHalf2(half2Value);
+ s.invoke_validateHalf3(half3Value);
+ s.invoke_validateHalf4(half4Value);
+
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_fp_mad.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_fp_mad.java
new file mode 100644
index 0000000..e8c5b52
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_fp_mad.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript;
+
+public class UT_fp_mad extends UnitTest {
+
+ public UT_fp_mad(Context ctx) {
+ super("Fp_Mad", ctx);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_fp_mad s = new ScriptC_fp_mad(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ s.invoke_fp_mad_test(0, 0);
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_int4.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_int4.java
new file mode 100644
index 0000000..cc76aae
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_int4.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript;
+
+public class UT_int4 extends UnitTest {
+
+ public UT_int4(Context ctx) {
+ super("int4", ctx);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_int4 s = new ScriptC_int4(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ s.invoke_int4_test();
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_kernel.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_kernel.java
new file mode 100644
index 0000000..f3a4e5e
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_kernel.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.Type;
+
+public class UT_kernel extends UnitTest {
+ private Type TA;
+ private Type TB;
+ private Allocation A;
+ private Allocation B;
+
+ public UT_kernel(Context ctx) {
+ super("Kernels (pass-by-value)", ctx);
+ }
+
+ private void initializeGlobals(RenderScript RS, ScriptC_kernel s) {
+ Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS));
+ int X = 5;
+ s.set_dimX(X);
+ typeBuilder.setX(X);
+ TA = typeBuilder.create();
+ A = Allocation.createTyped(RS, TA);
+ s.bind_ain(A);
+ TB = typeBuilder.create();
+ B = Allocation.createTyped(RS, TB);
+ s.bind_aout(B);
+
+ return;
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_kernel s = new ScriptC_kernel(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ initializeGlobals(pRS, s);
+ s.forEach_init_vars(A);
+ s.forEach_root(A, B);
+ s.invoke_verify_root();
+ s.invoke_kernel_test();
+ pRS.finish();
+ A.destroy();
+ B.destroy();
+ TA.destroy();
+ TB.destroy();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_kernel2d.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_kernel2d.java
new file mode 100644
index 0000000..9211517
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_kernel2d.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.Type;
+
+public class UT_kernel2d extends UnitTest {
+ private Type T;
+ private Allocation A;
+ private Allocation B;
+
+ public UT_kernel2d(Context ctx) {
+ super("Kernel 2d (pass-by-value)", ctx);
+ }
+
+ private void initializeGlobals(RenderScript RS, ScriptC_kernel2d s) {
+ Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS));
+ int X = 2;
+ s.set_gDimX(X);
+ typeBuilder.setX(X);
+ int Y = 5;
+ s.set_gDimY(Y);
+ typeBuilder.setY(Y);
+
+ T = typeBuilder.create();
+ A = Allocation.createTyped(RS, T);
+ s.set_A(A);
+ B = Allocation.createTyped(RS, T);
+ s.set_B(B);
+ return;
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_kernel2d s = new ScriptC_kernel2d(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ initializeGlobals(pRS, s);
+ s.forEach_init_vars(A);
+ s.forEach_root(A, B);
+ s.invoke_verify_root();
+ s.invoke_kernel_test();
+ pRS.finish();
+ T.destroy();
+ A.destroy();
+ B.destroy();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_kernel2d_oldstyle.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_kernel2d_oldstyle.java
new file mode 100644
index 0000000..faf7e9d
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_kernel2d_oldstyle.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.Type;
+
+public class UT_kernel2d_oldstyle extends UnitTest {
+ private Type T;
+ private Allocation A;
+ private Allocation B;
+
+ public UT_kernel2d_oldstyle(Context ctx) {
+ super("Kernel 2d (old style)", ctx);
+ }
+
+ private void initializeGlobals(RenderScript RS, ScriptC_kernel2d_oldstyle s) {
+ Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS));
+ int X = 2;
+ s.set_gDimX(X);
+ typeBuilder.setX(X);
+ int Y = 5;
+ s.set_gDimY(Y);
+ typeBuilder.setY(Y);
+
+ T = typeBuilder.create();
+ A = Allocation.createTyped(RS, T);
+ s.set_A(A);
+ B = Allocation.createTyped(RS, T);
+ s.set_B(B);
+ return;
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_kernel2d_oldstyle s = new ScriptC_kernel2d_oldstyle(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ initializeGlobals(pRS, s);
+ s.forEach_init_vars(A);
+ s.forEach_xform(A, B);
+ s.invoke_verify_xform();
+ s.invoke_kernel_test();
+ pRS.finish();
+ T.destroy();
+ A.destroy();
+ B.destroy();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_kernel3d.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_kernel3d.java
new file mode 100644
index 0000000..0373129
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_kernel3d.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.Type;
+
+public class UT_kernel3d extends UnitTest {
+ private Type T;
+ private Allocation A;
+ private Allocation B;
+
+ public UT_kernel3d(Context ctx) {
+ super("Kernel 3d (pass-by-value)", ctx);
+ }
+
+ private void initializeGlobals(RenderScript RS, ScriptC_kernel3d s) {
+ Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS));
+ int X = 2;
+ s.set_gDimX(X);
+ typeBuilder.setX(X);
+ int Y = 5;
+ s.set_gDimY(Y);
+ typeBuilder.setY(Y);
+ int Z = 11;
+ s.set_gDimZ(Z);
+ typeBuilder.setZ(Z);
+
+ T = typeBuilder.create();
+ A = Allocation.createTyped(RS, T);
+ s.set_A(A);
+ B = Allocation.createTyped(RS, T);
+ s.set_B(B);
+ return;
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_kernel3d s = new ScriptC_kernel3d(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ initializeGlobals(pRS, s);
+ s.forEach_init_vars(A);
+ s.forEach_root(A, B);
+ s.invoke_verify_root();
+ s.invoke_kernel_test();
+ pRS.finish();
+ T.destroy();
+ A.destroy();
+ B.destroy();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_kernel_struct.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_kernel_struct.java
new file mode 100644
index 0000000..8df7258
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_kernel_struct.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.RenderScript;
+
+public class UT_kernel_struct extends UnitTest {
+ private Allocation A;
+ private Allocation B;
+
+ public UT_kernel_struct(Context ctx) {
+ super("Kernels (struct pass-by-value)", ctx);
+ }
+
+ private void initializeGlobals(RenderScript RS, ScriptC_kernel_struct s) {
+ int X = 5;
+ s.set_dimX(X);
+ ScriptField_simpleStruct t;
+ t = new ScriptField_simpleStruct(RS, X);
+ s.bind_ain(t);
+ A = t.getAllocation();
+ t = new ScriptField_simpleStruct(RS, X);
+ s.bind_aout(t);
+ B = t.getAllocation();
+
+ return;
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_kernel_struct s = new ScriptC_kernel_struct(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ initializeGlobals(pRS, s);
+ s.forEach_init_vars(A);
+ s.forEach_root(A, B);
+ s.invoke_verify_root();
+ s.invoke_kernel_struct_test();
+ pRS.finish();
+ A.destroy();
+ B.destroy();
+ s.get_ain().getElement().destroy();
+ s.get_aout().getElement().destroy();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_math.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_math.java
new file mode 100644
index 0000000..c81ee7f
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_math.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript;
+
+public class UT_math extends UnitTest {
+
+ public UT_math(Context ctx) {
+ super("Math", ctx);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_math s = new ScriptC_math(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ s.invoke_math_test(0, 0);
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_math_24.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_math_24.java
new file mode 100644
index 0000000..6e6ec39
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_math_24.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript;
+
+public class UT_math_24 extends UnitTest {
+
+ public UT_math_24(Context ctx) {
+ super("Math", ctx);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_math_24 s = new ScriptC_math_24(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ s.invoke_math_24_test(0, 0);
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_math_agree.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_math_agree.java
new file mode 100644
index 0000000..5645c8d
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_math_agree.java
@@ -0,0 +1,581 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Byte2;
+import android.renderscript.Byte3;
+import android.renderscript.Byte4;
+import android.renderscript.Float2;
+import android.renderscript.Float3;
+import android.renderscript.Float4;
+import android.renderscript.Int2;
+import android.renderscript.Int3;
+import android.renderscript.Int4;
+import android.renderscript.Long2;
+import android.renderscript.Long3;
+import android.renderscript.Long4;
+import android.renderscript.RenderScript;
+import android.renderscript.Short2;
+import android.renderscript.Short3;
+import android.renderscript.Short4;
+
+import java.util.Random;
+
+public class UT_math_agree extends UnitTest {
+ private Random rand;
+
+ public UT_math_agree(Context ctx) {
+ super("Math Agreement", ctx);
+ rand = new Random();
+ }
+
+ // packing functions
+ private Float2 pack_f2(float[] val) {
+ assert val.length == 2;
+ return new Float2(val[0], val[1]);
+ }
+
+ private Float3 pack_f3(float[] val) {
+ assert val.length == 3;
+ return new Float3(val[0], val[1], val[2]);
+ }
+
+ private Float4 pack_f4(float[] val) {
+ assert val.length == 4;
+ return new Float4(val[0], val[1], val[2], val[3]);
+ }
+
+ private Byte2 pack_b2(byte[] val) {
+ assert val.length == 2;
+ return new Byte2(val[0], val[1]);
+ }
+
+ private Byte3 pack_b3(byte[] val) {
+ assert val.length == 3;
+ return new Byte3(val[0], val[1], val[2]);
+ }
+
+ private Byte4 pack_b4(byte[] val) {
+ assert val.length == 4;
+ return new Byte4(val[0], val[1], val[2], val[3]);
+ }
+
+ private Short2 pack_s2(short[] val) {
+ assert val.length == 2;
+ return new Short2(val[0], val[1]);
+ }
+
+ private Short3 pack_s3(short[] val) {
+ assert val.length == 3;
+ return new Short3(val[0], val[1], val[2]);
+ }
+
+ private Short4 pack_s4(short[] val) {
+ assert val.length == 4;
+ return new Short4(val[0], val[1], val[2], val[3]);
+ }
+
+ private Int2 pack_i2(int[] val) {
+ assert val.length == 2;
+ return new Int2(val[0], val[1]);
+ }
+
+ private Int3 pack_i3(int[] val) {
+ assert val.length == 3;
+ return new Int3(val[0], val[1], val[2]);
+ }
+
+ private Int4 pack_i4(int[] val) {
+ assert val.length == 4;
+ return new Int4(val[0], val[1], val[2], val[3]);
+ }
+
+ private Long2 pack_l2(long[] val) {
+ assert val.length == 2;
+ return new Long2(val[0], val[1]);
+ }
+
+ private Long3 pack_l3(long[] val) {
+ assert val.length == 3;
+ return new Long3(val[0], val[1], val[2]);
+ }
+
+ private Long4 pack_l4(long[] val) {
+ assert val.length == 4;
+ return new Long4(val[0], val[1], val[2], val[3]);
+ }
+
+ // random vector generation functions
+ private float[] randvec_float(int dim) {
+ float[] fv = new float[dim];
+ for (int i = 0; i < dim; ++i)
+ fv[i] = rand.nextFloat();
+ return fv;
+ }
+
+ private byte[] randvec_char(int dim) {
+ byte[] cv = new byte[dim];
+ rand.nextBytes(cv);
+ return cv;
+ }
+
+ private short[] randvec_uchar(int dim) {
+ short[] ucv = new short[dim];
+ for (int i = 0; i < dim; ++i)
+ ucv[i] = (short) rand.nextInt(0x1 << 8);
+ return ucv;
+ }
+
+ private short[] randvec_short(int dim) {
+ short[] sv = new short[dim];
+ for (int i = 0; i < dim; ++i)
+ sv[i] = (short) rand.nextInt(0x1 << 16);
+ return sv;
+ }
+
+ private int[] randvec_ushort(int dim) {
+ int[] usv = new int[dim];
+ for (int i = 0; i < dim; ++i)
+ usv[i] = rand.nextInt(0x1 << 16);
+ return usv;
+ }
+
+ private int[] randvec_int(int dim) {
+ int[] iv = new int[dim];
+ for (int i = 0; i < dim; ++i)
+ iv[i] = rand.nextInt();
+ return iv;
+ }
+
+ private long[] randvec_uint(int dim) {
+ long[] uiv = new long[dim];
+ for (int i = 0; i < dim; ++i)
+ uiv[i] = (long) rand.nextInt() - (long) Integer.MIN_VALUE;
+ return uiv;
+ }
+
+ private long[] randvec_long(int dim) {
+ long[] lv = new long[dim];
+ for (int i = 0; i < dim; ++i)
+ lv[i] = rand.nextLong();
+ return lv;
+ }
+ // TODO: unsigned long generator
+
+ // min reference functions
+ private float min(float v1, float v2) {
+ return v1 < v2 ? v1 : v2;
+ }
+
+ private float[] min(float[] v1, float[] v2) {
+ assert v1.length == v2.length;
+ float[] rv = new float[v1.length];
+ for (int i = 0; i < v1.length; ++i)
+ rv[i] = min(v1[i], v2[i]);
+ return rv;
+ }
+
+ private byte min(byte v1, byte v2) {
+ return v1 < v2 ? v1 : v2;
+ }
+
+ private byte[] min(byte[] v1, byte[] v2) {
+ assert v1.length == v2.length;
+ byte[] rv = new byte[v1.length];
+ for (int i = 0; i < v1.length; ++i)
+ rv[i] = min(v1[i], v2[i]);
+ return rv;
+ }
+
+ private short min(short v1, short v2) {
+ return v1 < v2 ? v1 : v2;
+ }
+
+ private short[] min(short[] v1, short[] v2) {
+ assert v1.length == v2.length;
+ short[] rv = new short[v1.length];
+ for (int i = 0; i < v1.length; ++i)
+ rv[i] = min(v1[i], v2[i]);
+ return rv;
+ }
+
+ private int min(int v1, int v2) {
+ return v1 < v2 ? v1 : v2;
+ }
+
+ private int[] min(int[] v1, int[] v2) {
+ assert v1.length == v2.length;
+ int[] rv = new int[v1.length];
+ for (int i = 0; i < v1.length; ++i)
+ rv[i] = min(v1[i], v2[i]);
+ return rv;
+ }
+
+ private long min(long v1, long v2) {
+ return v1 < v2 ? v1 : v2;
+ }
+
+ private long[] min(long[] v1, long[] v2) {
+ assert v1.length == v2.length;
+ long[] rv = new long[v1.length];
+ for (int i = 0; i < v1.length; ++i)
+ rv[i] = min(v1[i], v2[i]);
+ return rv;
+ }
+ // TODO: unsigned long version of min
+
+ // max reference functions
+ private float max(float v1, float v2) {
+ return v1 > v2 ? v1 : v2;
+ }
+
+ private float[] max(float[] v1, float[] v2) {
+ assert v1.length == v2.length;
+ float[] rv = new float[v1.length];
+ for (int i = 0; i < v1.length; ++i)
+ rv[i] = max(v1[i], v2[i]);
+ return rv;
+ }
+
+ private byte max(byte v1, byte v2) {
+ return v1 > v2 ? v1 : v2;
+ }
+
+ private byte[] max(byte[] v1, byte[] v2) {
+ assert v1.length == v2.length;
+ byte[] rv = new byte[v1.length];
+ for (int i = 0; i < v1.length; ++i)
+ rv[i] = max(v1[i], v2[i]);
+ return rv;
+ }
+
+ private short max(short v1, short v2) {
+ return v1 > v2 ? v1 : v2;
+ }
+
+ private short[] max(short[] v1, short[] v2) {
+ assert v1.length == v2.length;
+ short[] rv = new short[v1.length];
+ for (int i = 0; i < v1.length; ++i)
+ rv[i] = max(v1[i], v2[i]);
+ return rv;
+ }
+
+ private int max(int v1, int v2) {
+ return v1 > v2 ? v1 : v2;
+ }
+
+ private int[] max(int[] v1, int[] v2) {
+ assert v1.length == v2.length;
+ int[] rv = new int[v1.length];
+ for (int i = 0; i < v1.length; ++i)
+ rv[i] = max(v1[i], v2[i]);
+ return rv;
+ }
+
+ private long max(long v1, long v2) {
+ return v1 > v2 ? v1 : v2;
+ }
+
+ private long[] max(long[] v1, long[] v2) {
+ assert v1.length == v2.length;
+ long[] rv = new long[v1.length];
+ for (int i = 0; i < v1.length; ++i)
+ rv[i] = max(v1[i], v2[i]);
+ return rv;
+ }
+ // TODO: unsigned long version of max
+
+ // fmin reference functions
+ private float fmin(float v1, float v2) {
+ return min(v1, v2);
+ }
+
+ private float[] fmin(float[] v1, float[] v2) {
+ return min(v1, v2);
+ }
+
+ private float[] fmin(float[] v1, float v2) {
+ float[] rv = new float[v1.length];
+ for (int i = 0; i < v1.length; ++i)
+ rv[i] = min(v1[i], v2);
+ return rv;
+ }
+
+ // fmax reference functions
+ private float fmax(float v1, float v2) {
+ return max(v1, v2);
+ }
+
+ private float[] fmax(float[] v1, float[] v2) {
+ return max(v1, v2);
+ }
+
+ private float[] fmax(float[] v1, float v2) {
+ float[] rv = new float[v1.length];
+ for (int i = 0; i < v1.length; ++i)
+ rv[i] = max(v1[i], v2);
+ return rv;
+ }
+
+ private void initializeValues(ScriptC_math_agree s) {
+ float x = rand.nextFloat();
+ float y = rand.nextFloat();
+
+ s.set_x(x);
+ s.set_y(y);
+ s.set_result_add(x + y);
+ s.set_result_sub(x - y);
+ s.set_result_mul(x * y);
+ s.set_result_div(x / y);
+
+ // Generate random vectors of all types
+ float rand_f1_0 = rand.nextFloat();
+ float[] rand_f2_0 = randvec_float(2);
+ float[] rand_f3_0 = randvec_float(3);
+ float[] rand_f4_0 = randvec_float(4);
+ float rand_f1_1 = rand.nextFloat();
+ float[] rand_f2_1 = randvec_float(2);
+ float[] rand_f3_1 = randvec_float(3);
+ float[] rand_f4_1 = randvec_float(4);
+ short rand_uc1_0 = (short) rand.nextInt(0x1 << 8);
+ short[] rand_uc2_0 = randvec_uchar(2);
+ short[] rand_uc3_0 = randvec_uchar(3);
+ short[] rand_uc4_0 = randvec_uchar(4);
+ short rand_uc1_1 = (short) rand.nextInt(0x1 << 8);
+ short[] rand_uc2_1 = randvec_uchar(2);
+ short[] rand_uc3_1 = randvec_uchar(3);
+ short[] rand_uc4_1 = randvec_uchar(4);
+ short rand_ss1_0 = (short) rand.nextInt(0x1 << 16);
+ short[] rand_ss2_0 = randvec_short(2);
+ short[] rand_ss3_0 = randvec_short(3);
+ short[] rand_ss4_0 = randvec_short(4);
+ short rand_ss1_1 = (short) rand.nextInt(0x1 << 16);
+ short[] rand_ss2_1 = randvec_short(2);
+ short[] rand_ss3_1 = randvec_short(3);
+ short[] rand_ss4_1 = randvec_short(4);
+ int rand_us1_0 = rand.nextInt(0x1 << 16);
+ int[] rand_us2_0 = randvec_ushort(2);
+ int[] rand_us3_0 = randvec_ushort(3);
+ int[] rand_us4_0 = randvec_ushort(4);
+ int rand_us1_1 = rand.nextInt(0x1 << 16);
+ int[] rand_us2_1 = randvec_ushort(2);
+ int[] rand_us3_1 = randvec_ushort(3);
+ int[] rand_us4_1 = randvec_ushort(4);
+ int rand_si1_0 = rand.nextInt();
+ int[] rand_si2_0 = randvec_int(2);
+ int[] rand_si3_0 = randvec_int(3);
+ int[] rand_si4_0 = randvec_int(4);
+ int rand_si1_1 = rand.nextInt();
+ int[] rand_si2_1 = randvec_int(2);
+ int[] rand_si3_1 = randvec_int(3);
+ int[] rand_si4_1 = randvec_int(4);
+ long rand_ui1_0 = (long) rand.nextInt() - (long) Integer.MIN_VALUE;
+ long[] rand_ui2_0 = randvec_uint(2);
+ long[] rand_ui3_0 = randvec_uint(3);
+ long[] rand_ui4_0 = randvec_uint(4);
+ long rand_ui1_1 = (long) rand.nextInt() - (long) Integer.MIN_VALUE;
+ long[] rand_ui2_1 = randvec_uint(2);
+ long[] rand_ui3_1 = randvec_uint(3);
+ long[] rand_ui4_1 = randvec_uint(4);
+ long rand_sl1_0 = rand.nextLong();
+ long[] rand_sl2_0 = randvec_long(2);
+ long[] rand_sl3_0 = randvec_long(3);
+ long[] rand_sl4_0 = randvec_long(4);
+ long rand_sl1_1 = rand.nextLong();
+ long[] rand_sl2_1 = randvec_long(2);
+ long[] rand_sl3_1 = randvec_long(3);
+ long[] rand_sl4_1 = randvec_long(4);
+ byte rand_sc1_0 = (byte) rand.nextInt(0x1 << 8);
+ byte[] rand_sc2_0 = randvec_char(2);
+ byte[] rand_sc3_0 = randvec_char(3);
+ byte[] rand_sc4_0 = randvec_char(4);
+ byte rand_sc1_1 = (byte) rand.nextInt(0x1 << 8);
+ byte[] rand_sc2_1 = randvec_char(2);
+ byte[] rand_sc3_1 = randvec_char(3);
+ byte[] rand_sc4_1 = randvec_char(4);
+ // TODO: generate unsigned long vectors
+
+ // Set random vectors in renderscript code
+ s.set_rand_f1_0(rand_f1_0);
+ s.set_rand_f2_0(pack_f2(rand_f2_0));
+ s.set_rand_f3_0(pack_f3(rand_f3_0));
+ s.set_rand_f4_0(pack_f4(rand_f4_0));
+ s.set_rand_f1_1(rand_f1_1);
+ s.set_rand_f2_1(pack_f2(rand_f2_1));
+ s.set_rand_f3_1(pack_f3(rand_f3_1));
+ s.set_rand_f4_1(pack_f4(rand_f4_1));
+ s.set_rand_uc1_1(rand_uc1_1);
+ s.set_rand_uc2_1(pack_s2(rand_uc2_1));
+ s.set_rand_uc3_1(pack_s3(rand_uc3_1));
+ s.set_rand_uc4_1(pack_s4(rand_uc4_1));
+ s.set_rand_ss1_0(rand_ss1_0);
+ s.set_rand_ss2_0(pack_s2(rand_ss2_0));
+ s.set_rand_ss3_0(pack_s3(rand_ss3_0));
+ s.set_rand_ss4_0(pack_s4(rand_ss4_0));
+ s.set_rand_ss1_1(rand_ss1_1);
+ s.set_rand_ss2_1(pack_s2(rand_ss2_1));
+ s.set_rand_ss3_1(pack_s3(rand_ss3_1));
+ s.set_rand_ss4_1(pack_s4(rand_ss4_1));
+ s.set_rand_us1_0(rand_us1_0);
+ s.set_rand_us2_0(pack_i2(rand_us2_0));
+ s.set_rand_us3_0(pack_i3(rand_us3_0));
+ s.set_rand_us4_0(pack_i4(rand_us4_0));
+ s.set_rand_us1_1(rand_us1_1);
+ s.set_rand_us2_1(pack_i2(rand_us2_1));
+ s.set_rand_us3_1(pack_i3(rand_us3_1));
+ s.set_rand_us4_1(pack_i4(rand_us4_1));
+ s.set_rand_si1_0(rand_si1_0);
+ s.set_rand_si2_0(pack_i2(rand_si2_0));
+ s.set_rand_si3_0(pack_i3(rand_si3_0));
+ s.set_rand_si4_0(pack_i4(rand_si4_0));
+ s.set_rand_si1_1(rand_si1_1);
+ s.set_rand_si2_1(pack_i2(rand_si2_1));
+ s.set_rand_si3_1(pack_i3(rand_si3_1));
+ s.set_rand_si4_1(pack_i4(rand_si4_1));
+ s.set_rand_ui1_0(rand_ui1_0);
+ s.set_rand_ui2_0(pack_l2(rand_ui2_0));
+ s.set_rand_ui3_0(pack_l3(rand_ui3_0));
+ s.set_rand_ui4_0(pack_l4(rand_ui4_0));
+ s.set_rand_ui1_1(rand_ui1_1);
+ s.set_rand_ui2_1(pack_l2(rand_ui2_1));
+ s.set_rand_ui3_1(pack_l3(rand_ui3_1));
+ s.set_rand_ui4_1(pack_l4(rand_ui4_1));
+ s.set_rand_sl1_0(rand_sl1_0);
+ s.set_rand_sl2_0(pack_l2(rand_sl2_0));
+ s.set_rand_sl3_0(pack_l3(rand_sl3_0));
+ s.set_rand_sl4_0(pack_l4(rand_sl4_0));
+ s.set_rand_sl1_1(rand_sl1_1);
+ s.set_rand_sl2_1(pack_l2(rand_sl2_1));
+ s.set_rand_sl3_1(pack_l3(rand_sl3_1));
+ s.set_rand_sl4_1(pack_l4(rand_sl4_1));
+ s.set_rand_uc1_0(rand_uc1_0);
+ s.set_rand_uc2_0(pack_s2(rand_uc2_0));
+ s.set_rand_uc3_0(pack_s3(rand_uc3_0));
+ s.set_rand_uc4_0(pack_s4(rand_uc4_0));
+ s.set_rand_sc1_0(rand_sc1_0);
+ s.set_rand_sc2_0(pack_b2(rand_sc2_0));
+ s.set_rand_sc3_0(pack_b3(rand_sc3_0));
+ s.set_rand_sc4_0(pack_b4(rand_sc4_0));
+ s.set_rand_sc1_1(rand_sc1_1);
+ s.set_rand_sc2_1(pack_b2(rand_sc2_1));
+ s.set_rand_sc3_1(pack_b3(rand_sc3_1));
+ s.set_rand_sc4_1(pack_b4(rand_sc4_1));
+ // TODO: set unsigned long vectors
+
+ // Set results for min
+ s.set_min_rand_f1_f1(min(rand_f1_0, rand_f1_1));
+ s.set_min_rand_f2_f2(pack_f2(min(rand_f2_0, rand_f2_1)));
+ s.set_min_rand_f3_f3(pack_f3(min(rand_f3_0, rand_f3_1)));
+ s.set_min_rand_f4_f4(pack_f4(min(rand_f4_0, rand_f4_1)));
+ s.set_min_rand_uc1_uc1(min(rand_uc1_0, rand_uc1_1));
+ s.set_min_rand_uc2_uc2(pack_s2(min(rand_uc2_0, rand_uc2_1)));
+ s.set_min_rand_uc3_uc3(pack_s3(min(rand_uc3_0, rand_uc3_1)));
+ s.set_min_rand_uc4_uc4(pack_s4(min(rand_uc4_0, rand_uc4_1)));
+ s.set_min_rand_ss1_ss1(min(rand_ss1_0, rand_ss1_1));
+ s.set_min_rand_ss2_ss2(pack_s2(min(rand_ss2_0, rand_ss2_1)));
+ s.set_min_rand_ss3_ss3(pack_s3(min(rand_ss3_0, rand_ss3_1)));
+ s.set_min_rand_ss4_ss4(pack_s4(min(rand_ss4_0, rand_ss4_1)));
+ s.set_min_rand_us1_us1(min(rand_us1_0, rand_us1_1));
+ s.set_min_rand_us2_us2(pack_i2(min(rand_us2_0, rand_us2_1)));
+ s.set_min_rand_us3_us3(pack_i3(min(rand_us3_0, rand_us3_1)));
+ s.set_min_rand_us4_us4(pack_i4(min(rand_us4_0, rand_us4_1)));
+ s.set_min_rand_si1_si1(min(rand_si1_0, rand_si1_1));
+ s.set_min_rand_si2_si2(pack_i2(min(rand_si2_0, rand_si2_1)));
+ s.set_min_rand_si3_si3(pack_i3(min(rand_si3_0, rand_si3_1)));
+ s.set_min_rand_si4_si4(pack_i4(min(rand_si4_0, rand_si4_1)));
+ s.set_min_rand_ui1_ui1(min(rand_ui1_0, rand_ui1_1));
+ s.set_min_rand_ui2_ui2(pack_l2(min(rand_ui2_0, rand_ui2_1)));
+ s.set_min_rand_ui3_ui3(pack_l3(min(rand_ui3_0, rand_ui3_1)));
+ s.set_min_rand_ui4_ui4(pack_l4(min(rand_ui4_0, rand_ui4_1)));
+ s.set_min_rand_sl1_sl1(min(rand_sl1_0, rand_sl1_1));
+ s.set_min_rand_sl2_sl2(pack_l2(min(rand_sl2_0, rand_sl2_1)));
+ s.set_min_rand_sl3_sl3(pack_l3(min(rand_sl3_0, rand_sl3_1)));
+ s.set_min_rand_sl4_sl4(pack_l4(min(rand_sl4_0, rand_sl4_1)));
+ s.set_min_rand_sc1_sc1(min(rand_sc1_0, rand_sc1_1));
+ s.set_min_rand_sc2_sc2(pack_b2(min(rand_sc2_0, rand_sc2_1)));
+ s.set_min_rand_sc3_sc3(pack_b3(min(rand_sc3_0, rand_sc3_1)));
+ s.set_min_rand_sc4_sc4(pack_b4(min(rand_sc4_0, rand_sc4_1)));
+ // TODO: set results for unsigned long min
+
+ // Set results for max
+ s.set_max_rand_f1_f1(max(rand_f1_0, rand_f1_1));
+ s.set_max_rand_f2_f2(pack_f2(max(rand_f2_0, rand_f2_1)));
+ s.set_max_rand_f3_f3(pack_f3(max(rand_f3_0, rand_f3_1)));
+ s.set_max_rand_f4_f4(pack_f4(max(rand_f4_0, rand_f4_1)));
+ s.set_max_rand_uc1_uc1(max(rand_uc1_0, rand_uc1_1));
+ s.set_max_rand_uc2_uc2(pack_s2(max(rand_uc2_0, rand_uc2_1)));
+ s.set_max_rand_uc3_uc3(pack_s3(max(rand_uc3_0, rand_uc3_1)));
+ s.set_max_rand_uc4_uc4(pack_s4(max(rand_uc4_0, rand_uc4_1)));
+ s.set_max_rand_ss1_ss1(max(rand_ss1_0, rand_ss1_1));
+ s.set_max_rand_ss2_ss2(pack_s2(max(rand_ss2_0, rand_ss2_1)));
+ s.set_max_rand_ss3_ss3(pack_s3(max(rand_ss3_0, rand_ss3_1)));
+ s.set_max_rand_ss4_ss4(pack_s4(max(rand_ss4_0, rand_ss4_1)));
+ s.set_max_rand_us1_us1(max(rand_us1_0, rand_us1_1));
+ s.set_max_rand_us2_us2(pack_i2(max(rand_us2_0, rand_us2_1)));
+ s.set_max_rand_us3_us3(pack_i3(max(rand_us3_0, rand_us3_1)));
+ s.set_max_rand_us4_us4(pack_i4(max(rand_us4_0, rand_us4_1)));
+ s.set_max_rand_si1_si1(max(rand_si1_0, rand_si1_1));
+ s.set_max_rand_si2_si2(pack_i2(max(rand_si2_0, rand_si2_1)));
+ s.set_max_rand_si3_si3(pack_i3(max(rand_si3_0, rand_si3_1)));
+ s.set_max_rand_si4_si4(pack_i4(max(rand_si4_0, rand_si4_1)));
+ s.set_max_rand_ui1_ui1(max(rand_ui1_0, rand_ui1_1));
+ s.set_max_rand_ui2_ui2(pack_l2(max(rand_ui2_0, rand_ui2_1)));
+ s.set_max_rand_ui3_ui3(pack_l3(max(rand_ui3_0, rand_ui3_1)));
+ s.set_max_rand_ui4_ui4(pack_l4(max(rand_ui4_0, rand_ui4_1)));
+ s.set_max_rand_sl1_sl1(max(rand_sl1_0, rand_sl1_1));
+ s.set_max_rand_sl2_sl2(pack_l2(max(rand_sl2_0, rand_sl2_1)));
+ s.set_max_rand_sl3_sl3(pack_l3(max(rand_sl3_0, rand_sl3_1)));
+ s.set_max_rand_sl4_sl4(pack_l4(max(rand_sl4_0, rand_sl4_1)));
+ s.set_max_rand_sc1_sc1(max(rand_sc1_0, rand_sc1_1));
+ s.set_max_rand_sc2_sc2(pack_b2(max(rand_sc2_0, rand_sc2_1)));
+ s.set_max_rand_sc3_sc3(pack_b3(max(rand_sc3_0, rand_sc3_1)));
+ s.set_max_rand_sc4_sc4(pack_b4(max(rand_sc4_0, rand_sc4_1)));
+
+ // TODO: set results for unsigned long max
+
+ // Set results for fmin
+ s.set_fmin_rand_f1_f1(fmin(rand_f1_0, rand_f1_1));
+ s.set_fmin_rand_f2_f2(pack_f2(fmin(rand_f2_0, rand_f2_1)));
+ s.set_fmin_rand_f3_f3(pack_f3(fmin(rand_f3_0, rand_f3_1)));
+ s.set_fmin_rand_f4_f4(pack_f4(fmin(rand_f4_0, rand_f4_1)));
+ s.set_fmin_rand_f2_f1(pack_f2(fmin(rand_f2_0, rand_f1_1)));
+ s.set_fmin_rand_f3_f1(pack_f3(fmin(rand_f3_0, rand_f1_1)));
+ s.set_fmin_rand_f4_f1(pack_f4(fmin(rand_f4_0, rand_f1_1)));
+
+ // Set results for fmax
+ s.set_fmax_rand_f1_f1(fmax(rand_f1_0, rand_f1_1));
+ s.set_fmax_rand_f2_f2(pack_f2(fmax(rand_f2_0, rand_f2_1)));
+ s.set_fmax_rand_f3_f3(pack_f3(fmax(rand_f3_0, rand_f3_1)));
+ s.set_fmax_rand_f4_f4(pack_f4(fmax(rand_f4_0, rand_f4_1)));
+ s.set_fmax_rand_f2_f1(pack_f2(fmax(rand_f2_0, rand_f1_1)));
+ s.set_fmax_rand_f3_f1(pack_f3(fmax(rand_f3_0, rand_f1_1)));
+ s.set_fmax_rand_f4_f1(pack_f4(fmax(rand_f4_0, rand_f1_1)));
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_math_agree s = new ScriptC_math_agree(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ initializeValues(s);
+ s.invoke_math_agree_test();
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_math_conformance.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_math_conformance.java
new file mode 100644
index 0000000..b130b3e
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_math_conformance.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript;
+
+public class UT_math_conformance extends UnitTest {
+
+ public UT_math_conformance(Context ctx) {
+ super("Math Conformance", ctx);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_math_conformance s =
+ new ScriptC_math_conformance(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ s.invoke_math_conformance_test();
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+ passTest();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_math_fp16.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_math_fp16.java
new file mode 100644
index 0000000..a17abd5
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_math_fp16.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.RenderScript;
+
+// IMPORTANT: This whole test fails on 32-bit x86.
+public class UT_math_fp16 extends UnitTest {
+ private Allocation testAllocation1, testAllocation2;
+
+ public UT_math_fp16(Context ctx) {
+ super("Math_fp16", ctx);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_math_fp16 s = new ScriptC_math_fp16(pRS);
+ pRS.setMessageHandler(mRsMessage);
+
+ s.invoke_testFp16Math();
+
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_min.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_min.java
new file mode 100644
index 0000000..9c56fd1
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_min.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript;
+
+public class UT_min extends UnitTest {
+
+ public UT_min(Context ctx) {
+ super("Min (relaxed)", ctx);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_min s = new ScriptC_min(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ s.invoke_min_test();
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_noroot.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_noroot.java
new file mode 100644
index 0000000..661ee6d
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_noroot.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.Type;
+
+public class UT_noroot extends UnitTest {
+ private Allocation A;
+
+ public UT_noroot(Context ctx) {
+ super("ForEach (no root)", ctx);
+ }
+
+ private void initializeGlobals(RenderScript RS, ScriptC_noroot s) {
+ Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS));
+ int X = 5;
+ int Y = 7;
+ s.set_dimX(X);
+ s.set_dimY(Y);
+ typeBuilder.setX(X).setY(Y);
+ A = Allocation.createTyped(RS, typeBuilder.create());
+ s.set_aRaw(A);
+
+ return;
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_noroot s = new ScriptC_noroot(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ initializeGlobals(pRS, s);
+ s.forEach_foo(A, A);
+ s.invoke_verify_foo();
+ s.invoke_noroot_test();
+ pRS.finish();
+ A.getType().destroy();
+ A.destroy();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_primitives.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_primitives.java
new file mode 100644
index 0000000..7bda9c3
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_primitives.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript;
+
+public class UT_primitives extends UnitTest {
+
+ public UT_primitives(Context ctx) {
+ super("Primitives", ctx);
+ }
+
+ private boolean initializeGlobals(ScriptC_primitives s) {
+ float pF = s.get_floatTest();
+ if (pF != 1.99f) {
+ return false;
+ }
+ s.set_floatTest(2.99f);
+
+ double pD = s.get_doubleTest();
+ if (pD != 2.05) {
+ return false;
+ }
+ s.set_doubleTest(3.05);
+
+ byte pC = s.get_charTest();
+ if (pC != -8) {
+ return false;
+ }
+ s.set_charTest((byte) -16);
+
+ short pS = s.get_shortTest();
+ if (pS != -16) {
+ return false;
+ }
+ s.set_shortTest((short) -32);
+
+ int pI = s.get_intTest();
+ if (pI != -32) {
+ return false;
+ }
+ s.set_intTest(-64);
+
+ long pL = s.get_longTest();
+ if (pL != 17179869184l) {
+ return false;
+ }
+ s.set_longTest(17179869185l);
+
+ long puL = s.get_ulongTest();
+ if (puL != 4611686018427387904L) {
+ return false;
+ }
+ s.set_ulongTest(4611686018427387903L);
+
+
+ long pLL = s.get_longlongTest();
+ if (pLL != 68719476736L) {
+ return false;
+ }
+ s.set_longlongTest(68719476735L);
+
+ long pu64 = s.get_uint64_tTest();
+ if (pu64 != 117179869184l) {
+ return false;
+ }
+ s.set_uint64_tTest(117179869185l);
+
+ return true;
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_primitives s = new ScriptC_primitives(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ if (!initializeGlobals(s)) {
+ failTest();
+ } else {
+ s.invoke_primitives_test(0, 0);
+ pRS.finish();
+ }
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_reduce.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_reduce.java
new file mode 100644
index 0000000..1cd7acc
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_reduce.java
@@ -0,0 +1,1502 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+/* UT_reduce_backward.java is a much simpler version of this test
+ * case that exercises pragmas after the functions (backward
+ * reference), whereas this test case exercises the pragmas before
+ * the functions (forward reference).
+ */
+
+package com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.Float2;
+import android.renderscript.Int2;
+import android.renderscript.Int3;
+import android.renderscript.RenderScript;
+import android.renderscript.ScriptIntrinsicHistogram;
+import android.renderscript.Type;
+import android.util.Log;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Random;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+
+public class UT_reduce extends UnitTest {
+ private static final String TAG = "reduce";
+
+ public UT_reduce(Context ctx) {
+ super("reduce", ctx);
+ }
+
+ private static class timing {
+ timing(long myJavaStart, long myJavaEnd, long myRsStart,
+ long myCopyStart, long myKernelStart, long myRsEnd,
+ Allocation... myInputs) {
+ javaStart = myJavaStart;
+ javaEnd = myJavaEnd;
+ rsStart = myRsStart;
+ copyStart = myCopyStart;
+ kernelStart = myKernelStart;
+ rsEnd = myRsEnd;
+
+ inputBytes = 0;
+ for (Allocation input : myInputs)
+ inputBytes += input.getBytesSize();
+
+ inputCells = (myInputs.length > 0) ? myInputs[0].getType().getCount() : 0;
+ }
+
+ timing(long myInputCells) {
+ inputCells = myInputCells;
+ }
+
+ private long javaStart = -1;
+ private long javaEnd = -1;
+ private long rsStart = -1;
+ private long copyStart = -1;
+ private long kernelStart = -1;
+ private long rsEnd = -1;
+ private long inputBytes = -1;
+ private long inputCells = -1;
+
+ public long javaTime() {
+ return javaEnd - javaStart;
+ }
+
+ public long rsTime() {
+ return rsEnd - rsStart;
+ }
+
+ public long kernelTime() {
+ return rsEnd - kernelStart;
+ }
+
+ public long overheadTime() {
+ return kernelStart - rsStart;
+ }
+
+ public long allocationTime() {
+ return copyStart - rsStart;
+ }
+
+ public long copyTime() {
+ return kernelStart - copyStart;
+ }
+
+ public static String string(long myJavaStart, long myJavaEnd, long myRsStart,
+ long myCopyStart, long myKernelStart, long myRsEnd,
+ Allocation... myInputs) {
+ return (new timing(myJavaStart, myJavaEnd, myRsStart,
+ myCopyStart, myKernelStart, myRsEnd, myInputs)).string();
+ }
+
+ public static String string(long myInputCells) {
+ return (new timing(myInputCells)).string();
+ }
+
+ public String string() {
+ String result;
+ if (javaStart >= 0) {
+ result = "(java " + javaTime() + "ms, rs " + rsTime() + "ms = overhead " +
+ overheadTime() + "ms (alloc " + allocationTime() + "ms + copy " +
+ copyTime() + "ms) + kernel+get() " + kernelTime() + "ms)";
+ if (inputCells > 0)
+ result += " ";
+ } else {
+ result = "";
+ }
+ if (inputCells > 0) {
+ result += "(" + fmt.format(inputCells) + " cells";
+ if (inputBytes > 0)
+ result += ", " + fmt.format(inputBytes) + " bytes";
+ result += ")";
+ }
+ return result;
+ }
+
+ private static java.text.DecimalFormat fmt;
+
+ static {
+ fmt = new java.text.DecimalFormat("###,###");
+ }
+ }
+
+ private byte[] createInputArrayByte(int len, int seed) {
+ byte[] array = new byte[len];
+ (new Random(seed)).nextBytes(array);
+ return array;
+ }
+
+ private float[] createInputArrayFloat(int len, Random rand) {
+ float[] array = new float[len];
+ for (int i = 0; i < len; ++i) {
+ final float val = rand.nextFloat();
+ array[i] = rand.nextBoolean() ? val : -val;
+ }
+ return array;
+ }
+
+ private float[] createInputArrayFloat(int len, int seed) {
+ return createInputArrayFloat(len, new Random(seed));
+ }
+
+ private float[] createInputArrayFloatWithInfs(int len, int infs, int seed) {
+ Random rand = new Random(seed);
+ float[] array = createInputArrayFloat(len, rand);
+ for (int i = 0; i < infs; ++i)
+ array[rand.nextInt(len)] = (rand.nextBoolean() ? Float.POSITIVE_INFINITY : Float.NEGATIVE_INFINITY);
+ return array;
+ }
+
+ private int[] createInputArrayInt(int len, int seed) {
+ Random rand = new Random(seed);
+ int[] array = new int[len];
+ for (int i = 0; i < len; ++i)
+ array[i] = rand.nextInt();
+ return array;
+ }
+
+ private int[] createInputArrayInt(int len, int seed, int eltRange) {
+ Random rand = new Random(seed);
+ int[] array = new int[len];
+ for (int i = 0; i < len; ++i)
+ array[i] = rand.nextInt(eltRange);
+ return array;
+ }
+
+ private long[] intArrayToLong(final int[] input) {
+ final long[] output = new long[input.length];
+
+ for (int i = 0; i < input.length; ++i)
+ output[i] = input[i];
+
+ return output;
+ }
+
+ private <T extends Number> boolean result(String testName, final timing t,
+ T javaResult, T rsResult) {
+ final boolean success = javaResult.equals(rsResult);
+ String status = (success ? "PASSED" : "FAILED");
+ if (success && (t != null))
+ status += " " + t.string();
+ Log.i(TAG, testName + ": java " + javaResult + ", rs " + rsResult + ": " + status);
+ return success;
+ }
+
+ private boolean result(String testName, final timing t,
+ final float[] javaResult, final float[] rsResult) {
+ if (javaResult.length != rsResult.length) {
+ Log.i(TAG, testName + ": java length " + javaResult.length +
+ ", rs length " + rsResult.length + ": FAILED");
+ return false;
+ }
+ for (int i = 0; i < javaResult.length; ++i) {
+ if (javaResult[i] != rsResult[i]) {
+ Log.i(TAG, testName + "[" + i + "]: java " + javaResult[i] +
+ ", rs " + rsResult[i] + ": FAILED");
+ return false;
+ }
+ }
+ String status = "PASSED";
+ if (t != null)
+ status += " " + t.string();
+ Log.i(TAG, testName + ": " + status);
+ return true;
+ }
+
+ private boolean result(String testName, final timing t,
+ final long[] javaResult, final long[] rsResult) {
+ if (javaResult.length != rsResult.length) {
+ Log.i(TAG, testName + ": java length " + javaResult.length +
+ ", rs length " + rsResult.length + ": FAILED");
+ return false;
+ }
+ for (int i = 0; i < javaResult.length; ++i) {
+ if (javaResult[i] != rsResult[i]) {
+ Log.i(TAG, testName + "[" + i + "]: java " + javaResult[i] +
+ ", rs " + rsResult[i] + ": FAILED");
+ return false;
+ }
+ }
+ String status = "PASSED";
+ if (t != null)
+ status += " " + t.string();
+ Log.i(TAG, testName + ": " + status);
+ return true;
+ }
+
+ private boolean result(String testName, final timing t,
+ final int[] javaResult, final int[] rsResult) {
+ return result(testName, t, intArrayToLong(javaResult), intArrayToLong(rsResult));
+ }
+
+ private boolean result(String testName, final timing t, Int2 javaResult, Int2 rsResult) {
+ final boolean success = (javaResult.x == rsResult.x) && (javaResult.y == rsResult.y);
+ String status = (success ? "PASSED" : "FAILED");
+ if (success && (t != null))
+ status += " " + t.string();
+ Log.i(TAG,
+ testName +
+ ": java (" + javaResult.x + ", " + javaResult.y + ")" +
+ ", rs (" + rsResult.x + ", " + rsResult.y + ")" +
+ ": " + status);
+ return success;
+ }
+
+ private boolean result(String testName, final timing t, Float2 javaResult, Float2 rsResult) {
+ final boolean success = (javaResult.x == rsResult.x) && (javaResult.y == rsResult.y);
+ String status = (success ? "PASSED" : "FAILED");
+ if (success && (t != null))
+ status += " " + t.string();
+ Log.i(TAG,
+ testName +
+ ": java (" + javaResult.x + ", " + javaResult.y + ")" +
+ ", rs (" + rsResult.x + ", " + rsResult.y + ")" +
+ ": " + status);
+ return success;
+ }
+
+ ///////////////////////////////////////////////////////////////////
+
+ private int addint(int[] input) {
+ int result = 0;
+ for (int idx = 0; idx < input.length; ++idx)
+ result += input[idx];
+ return result;
+ }
+
+ private boolean addint1D_array(RenderScript RS, ScriptC_reduce s, int seed, int[] size) {
+ final int[] input = createInputArrayInt(size[0], seed, Integer.MAX_VALUE / size[0]);
+
+ final int javaResult = addint(input);
+ final int rsResult = s.reduce_addint(input).get();
+
+ return result("addint1D_array", new timing(size[0]), javaResult, rsResult);
+ }
+
+ private boolean addint1D(RenderScript RS, ScriptC_reduce s, int seed, int[] size) {
+ final int[] inputArray = createInputArrayInt(size[0], seed, Integer.MAX_VALUE / size[0]);
+
+ final long javaTimeStart = java.lang.System.currentTimeMillis();
+ final int javaResult = addint(inputArray);
+ final long javaTimeEnd = java.lang.System.currentTimeMillis();
+
+ final long rsTimeStart = java.lang.System.currentTimeMillis();
+
+ Allocation inputAllocation = Allocation.createSized(RS, Element.I32(RS), inputArray.length);
+
+ final long copyTimeStart = java.lang.System.currentTimeMillis();
+
+ inputAllocation.copyFrom(inputArray);
+
+ final long kernelTimeStart = java.lang.System.currentTimeMillis();
+ final int rsResult = s.reduce_addint(inputAllocation).get();
+ final long rsTimeEnd = java.lang.System.currentTimeMillis();
+
+ final boolean success =
+ result("addint1D",
+ new timing(javaTimeStart, javaTimeEnd, rsTimeStart,
+ copyTimeStart, kernelTimeStart, rsTimeEnd, inputAllocation),
+ javaResult, rsResult);
+ inputAllocation.destroy();
+ return success;
+ }
+
+ private boolean addint2D(RenderScript RS, ScriptC_reduce s, int seed, int[] size) {
+ final int dimX = size[0];
+ final int dimY = size[1];
+
+ final int[] inputArray = createInputArrayInt(dimX * dimY, seed, Integer.MAX_VALUE / (dimX * dimY));
+
+ final long javaTimeStart = java.lang.System.currentTimeMillis();
+ final int javaResult = addint(inputArray);
+ final long javaTimeEnd = java.lang.System.currentTimeMillis();
+
+ final long rsTimeStart = java.lang.System.currentTimeMillis();
+
+ Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS));
+ typeBuilder.setX(dimX).setY(dimY);
+ Allocation inputAllocation = Allocation.createTyped(RS, typeBuilder.create());
+
+ final long copyTimeStart = java.lang.System.currentTimeMillis();
+
+ inputAllocation.copy2DRangeFrom(0, 0, dimX, dimY, inputArray);
+
+ final long kernelTimeStart = java.lang.System.currentTimeMillis();
+ final int rsResult = s.reduce_addint(inputAllocation).get();
+ final long rsTimeEnd = java.lang.System.currentTimeMillis();
+
+ final boolean success =
+ result("addint2D",
+ new timing(javaTimeStart, javaTimeEnd, rsTimeStart,
+ copyTimeStart, kernelTimeStart, rsTimeEnd, inputAllocation),
+ javaResult, rsResult);
+ inputAllocation.destroy();
+ return success;
+ }
+
+ private boolean addint3D(RenderScript RS, ScriptC_reduce s, int seed, int[] size) {
+ final int dimX = size[0];
+ final int dimY = size[1];
+ final int dimZ = size[2];
+
+ final int[] inputArray = createInputArrayInt(dimX * dimY * dimZ, seed, Integer.MAX_VALUE / (dimX * dimY * dimZ));
+
+ final long javaTimeStart = java.lang.System.currentTimeMillis();
+ final int javaResult = addint(inputArray);
+ final long javaTimeEnd = java.lang.System.currentTimeMillis();
+
+ final long rsTimeStart = java.lang.System.currentTimeMillis();
+
+ Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS));
+ typeBuilder.setX(dimX).setY(dimY).setZ(dimZ);
+ Allocation inputAllocation = Allocation.createTyped(RS, typeBuilder.create());
+
+ final long copyTimeStart = java.lang.System.currentTimeMillis();
+
+ inputAllocation.copy3DRangeFrom(0, 0, 0, dimX, dimY, dimZ, inputArray);
+
+ final long kernelTimeStart = java.lang.System.currentTimeMillis();
+ final int rsResult = s.reduce_addint(inputAllocation).get();
+ final long rsTimeEnd = java.lang.System.currentTimeMillis();
+
+ final boolean success =
+ result("addint3D",
+ new timing(javaTimeStart, javaTimeEnd, rsTimeStart,
+ copyTimeStart, kernelTimeStart, rsTimeEnd, inputAllocation),
+ javaResult, rsResult);
+ inputAllocation.destroy();
+ return success;
+ }
+
+ //-----------------------------------------------------------------
+
+ private boolean patternInterleavedReduce(RenderScript RS, ScriptC_reduce s) {
+ // Run two reduce operations without forcing completion between them.
+ // We want to ensure that the driver can handle this, and that
+ // temporary Allocations created to run the reduce operations survive
+ // until get().
+
+ boolean pass = true;
+
+ final int inputSize = (1 << 18);
+
+ final int[] input1 = createInputArrayInt(123, Integer.MAX_VALUE / inputSize);
+ final int[] input2 = createInputArrayInt(456, Integer.MAX_VALUE / inputSize);
+
+ final int javaResult1 = addint(input1);
+ final int javaResult2 = addint(input2);
+
+ final ScriptC_reduce.result_int rsResultFuture1 = s.reduce_addint(input1);
+ final ScriptC_reduce.result_int rsResultFuture2 = s.reduce_addint(input2);
+
+ pass &= result("patternInterleavedReduce (1)", new timing(inputSize),
+ javaResult1, rsResultFuture1.get());
+ pass &= result("patternInterleavedReduce (2)", new timing(inputSize),
+ javaResult2, rsResultFuture2.get());
+
+ return pass;
+ }
+
+ //-----------------------------------------------------------------
+
+ private int[] sillySumIntoDecArray(final int[] input) {
+ final int resultScalar = addint(input);
+ final int[] result = new int[4];
+ for (int i = 0; i < 4; ++i)
+ result[i] = resultScalar / (i + 1);
+ return result;
+ }
+
+ private int[] sillySumIntoIncArray(final int[] input) {
+ final int resultScalar = addint(input);
+ final int[] result = new int[4];
+ for (int i = 0; i < 4; ++i)
+ result[i] = resultScalar / (4 - i);
+ return result;
+ }
+
+ private boolean patternDuplicateAnonymousResult(RenderScript RS, ScriptC_reduce s) {
+ // Ensure that we can have two kernels with the same anonymous result type.
+
+ boolean pass = true;
+
+ final int inputSize = 1000;
+ final int[] input = createInputArrayInt(149, Integer.MAX_VALUE / inputSize);
+
+ final int[] javaResultDec = sillySumIntoDecArray(input);
+ final int[] rsResultDec = s.reduce_sillySumIntoDecArray(input).get();
+ pass &= result("patternDuplicateAnonymousResult (Dec)", new timing(inputSize),
+ javaResultDec, rsResultDec);
+
+ final int[] javaResultInc = sillySumIntoIncArray(input);
+ final int[] rsResultInc = s.reduce_sillySumIntoIncArray(input).get();
+ pass &= result("patternDuplicateAnonymousResult (Inc)", new timing(inputSize),
+ javaResultInc, rsResultInc);
+
+ return pass;
+ }
+
+ ///////////////////////////////////////////////////////////////////
+
+ private float findMinAbs(float[] input) {
+ float accum = input[0];
+ for (int idx = 1; idx < input.length; ++idx) {
+ final float val = input[idx];
+ if (Math.abs(val) < Math.abs(accum))
+ accum = val;
+ }
+ return accum;
+ }
+
+ static interface ReduceFindMinAbs {
+ float run(Allocation input);
+ }
+
+ private boolean findMinAbs(RenderScript RS, float[] inputArray, String testName, ReduceFindMinAbs reduction) {
+ final long javaTimeStart = java.lang.System.currentTimeMillis();
+ final float javaResult = findMinAbs(inputArray);
+ final long javaTimeEnd = java.lang.System.currentTimeMillis();
+
+ final long rsTimeStart = java.lang.System.currentTimeMillis();
+
+ Allocation inputAllocation = Allocation.createSized(RS, Element.F32(RS), inputArray.length);
+
+ final long copyTimeStart = java.lang.System.currentTimeMillis();
+
+ inputAllocation.copyFrom(inputArray);
+
+ final long kernelTimeStart = java.lang.System.currentTimeMillis();
+ final float rsResult = reduction.run(inputAllocation);
+ final long rsTimeEnd = java.lang.System.currentTimeMillis();
+
+ // Note that the Java and RenderScript algorithms are not
+ // guaranteed to find the same results -- but the results
+ // should have the same absolute value.
+
+ final boolean success =
+ result(testName,
+ new timing(javaTimeStart, javaTimeEnd, rsTimeStart,
+ copyTimeStart, kernelTimeStart, rsTimeEnd, inputAllocation),
+ Math.abs(javaResult), Math.abs(rsResult));
+ inputAllocation.destroy();
+ return success;
+ }
+
+ private boolean findMinAbsBool(RenderScript RS, ScriptC_reduce s, int seed, int[] size) {
+ return findMinAbs(RS, createInputArrayFloat(size[0], seed), "findMinAbsBool",
+ (Allocation input) -> s.reduce_findMinAbsBool(input).get());
+ }
+
+ private boolean findMinAbsBoolInf(RenderScript RS, ScriptC_reduce s, int seed, int[] size) {
+ return findMinAbs(RS, createInputArrayFloatWithInfs(size[0], 1 + size[0] / 1000, seed), "findMinAbsBoolInf",
+ (Allocation input) -> s.reduce_findMinAbsBool(input).get());
+ }
+
+ private boolean findMinAbsNaN(RenderScript RS, ScriptC_reduce s, int seed, int[] size) {
+ return findMinAbs(RS, createInputArrayFloat(size[0], seed), "findMinAbsNaN",
+ (Allocation input) -> s.reduce_findMinAbsNaN(input).get());
+ }
+
+ private boolean findMinAbsNaNInf(RenderScript RS, ScriptC_reduce s, int seed, int[] size) {
+ return findMinAbs(RS, createInputArrayFloatWithInfs(size[0], 1 + size[0] / 1000, seed), "findMinAbsNaNInf",
+ (Allocation input) -> s.reduce_findMinAbsNaN(input).get());
+ }
+
+ ///////////////////////////////////////////////////////////////////
+
+ private Int2 findMinAndMax(float[] input) {
+ float minVal = Float.POSITIVE_INFINITY;
+ int minIdx = -1;
+ float maxVal = Float.NEGATIVE_INFINITY;
+ int maxIdx = -1;
+
+ for (int idx = 0; idx < input.length; ++idx) {
+ if ((minIdx < 0) || (input[idx] < minVal)) {
+ minVal = input[idx];
+ minIdx = idx;
+ }
+ if ((maxIdx < 0) || (input[idx] > maxVal)) {
+ maxVal = input[idx];
+ maxIdx = idx;
+ }
+ }
+
+ return new Int2(minIdx, maxIdx);
+ }
+
+ private boolean findMinAndMax_array(RenderScript RS, ScriptC_reduce s, int seed, int[] size) {
+ final float[] input = createInputArrayFloat(size[0], seed);
+
+ final Int2 javaResult = findMinAndMax(input);
+ final Int2 rsResult = s.reduce_findMinAndMax(input).get();
+
+ // Note that the Java and RenderScript algorithms are not
+ // guaranteed to find the same cells -- but they should
+ // find cells of the same value.
+ final Float2 javaVal = new Float2(input[javaResult.x], input[javaResult.y]);
+ final Float2 rsVal = new Float2(input[rsResult.x], input[rsResult.y]);
+
+ return result("findMinAndMax_array", new timing(size[0]), javaVal, rsVal);
+ }
+
+ private boolean findMinAndMax(RenderScript RS, ScriptC_reduce s, int seed, int[] size) {
+ final float[] inputArray = createInputArrayFloat(size[0], seed);
+
+ final long javaTimeStart = java.lang.System.currentTimeMillis();
+ final Int2 javaResult = findMinAndMax(inputArray);
+ final long javaTimeEnd = java.lang.System.currentTimeMillis();
+
+ final long rsTimeStart = java.lang.System.currentTimeMillis();
+
+ Allocation inputAllocation = Allocation.createSized(RS, Element.F32(RS), inputArray.length);
+
+ final long copyTimeStart = java.lang.System.currentTimeMillis();
+
+ inputAllocation.copyFrom(inputArray);
+
+ final long kernelTimeStart = java.lang.System.currentTimeMillis();
+ final Int2 rsResult = s.reduce_findMinAndMax(inputAllocation).get();
+ final long rsTimeEnd = java.lang.System.currentTimeMillis();
+
+ // Note that the Java and RenderScript algorithms are not
+ // guaranteed to find the same cells -- but they should
+ // find cells of the same value.
+ final Float2 javaVal = new Float2(inputArray[javaResult.x], inputArray[javaResult.y]);
+ final Float2 rsVal = new Float2(inputArray[rsResult.x], inputArray[rsResult.y]);
+
+ final boolean success =
+ result("findMinAndMax",
+ new timing(javaTimeStart, javaTimeEnd, rsTimeStart,
+ copyTimeStart, kernelTimeStart, rsTimeEnd, inputAllocation),
+ javaVal, rsVal);
+ inputAllocation.destroy();
+ return success;
+ }
+
+ //-----------------------------------------------------------------
+
+ private boolean patternFindMinAndMaxInf(RenderScript RS, ScriptC_reduce s) {
+ // Run this kernel on an input consisting solely of a single infinity.
+
+ final float[] input = new float[1];
+ input[0] = Float.POSITIVE_INFINITY;
+
+ final Int2 javaResult = findMinAndMax(input);
+ final Int2 rsResult = s.reduce_findMinAndMax(input).get();
+
+ // Note that the Java and RenderScript algorithms are not
+ // guaranteed to find the same cells -- but they should
+ // find cells of the same value.
+ final Float2 javaVal = new Float2(input[javaResult.x], input[javaResult.y]);
+ final Float2 rsVal = new Float2(input[rsResult.x], input[rsResult.y]);
+
+ return result("patternFindMinAndMaxInf", new timing(1), javaVal, rsVal);
+ }
+
+ ///////////////////////////////////////////////////////////////////
+
+ // Both the input and the result are linearized representations of matSize*matSize matrices.
+ private float[] findMinMat(final float[] inputArray, final int matSize) {
+ final int matSizeSquared = matSize * matSize;
+
+ float[] result = new float[matSizeSquared];
+ for (int i = 0; i < matSizeSquared; ++i)
+ result[i] = Float.POSITIVE_INFINITY;
+
+ for (int i = 0; i < inputArray.length; ++i)
+ result[i % matSizeSquared] = Math.min(result[i % matSizeSquared], inputArray[i]);
+
+ return result;
+ }
+
+ static interface ReduceFindMinMat {
+ float[] run(Allocation input);
+ }
+
+ private boolean findMinMat(RenderScript RS, int seed, int[] inputSize,
+ int matSize, Element matElement, ReduceFindMinMat reduction) {
+ final int length = inputSize[0];
+ final int matSizeSquared = matSize * matSize;
+
+ final float[] inputArray = createInputArrayFloat(matSizeSquared * length, seed);
+
+ final long javaTimeStart = java.lang.System.currentTimeMillis();
+ final float[] javaResult = findMinMat(inputArray, matSize);
+ final long javaTimeEnd = java.lang.System.currentTimeMillis();
+
+ final long rsTimeStart = java.lang.System.currentTimeMillis();
+
+ Allocation inputAllocation = Allocation.createSized(RS, matElement, length);
+
+ final long copyTimeStart = java.lang.System.currentTimeMillis();
+
+ inputAllocation.copyFromUnchecked(inputArray);
+
+ final long kernelTimeStart = java.lang.System.currentTimeMillis();
+ final float[] rsResult = reduction.run(inputAllocation);
+ final long rsTimeEnd = java.lang.System.currentTimeMillis();
+
+ final boolean success =
+ result("findMinMat" + matSize,
+ new timing(javaTimeStart, javaTimeEnd, rsTimeStart,
+ copyTimeStart, kernelTimeStart, rsTimeEnd, inputAllocation),
+ javaResult, rsResult);
+ inputAllocation.destroy();
+ return success;
+ }
+
+ private boolean findMinMat2(RenderScript RS, ScriptC_reduce s, int seed, int[] size) {
+ return findMinMat(RS, seed, size, 2, Element.MATRIX_2X2(RS),
+ (Allocation input) -> s.reduce_findMinMat2(input).get());
+ }
+
+ private boolean findMinMat4(RenderScript RS, ScriptC_reduce s, int seed, int[] size) {
+ return findMinMat(RS, seed, size, 4, Element.MATRIX_4X4(RS),
+ (Allocation input) -> s.reduce_findMinMat4(input).get());
+ }
+
+ ///////////////////////////////////////////////////////////////////
+
+ private int fz(final int[] input) {
+ for (int i = 0; i < input.length; ++i)
+ if (input[i] == 0)
+ return i;
+ return -1;
+ }
+
+ private boolean fz_array(RenderScript RS, ScriptC_reduce s, int seed, int size[]) {
+ final int inputLen = size[0];
+ int[] input = createInputArrayInt(inputLen, seed + 0);
+ // just in case we got unlucky
+ input[(new Random(seed + 1)).nextInt(inputLen)] = 0;
+
+ final int rsResult = s.reduce_fz(input).get();
+
+ final boolean success = (input[rsResult] == 0);
+ Log.i(TAG,
+ "fz_array: input[" + rsResult + "] == " + input[rsResult] + ": " +
+ (success ? "PASSED " + timing.string(size[0]) : "FAILED"));
+ return success;
+ }
+
+ private boolean fz(RenderScript RS, ScriptC_reduce s, int seed, int size[]) {
+ final int inputLen = size[0];
+ int[] inputArray = createInputArrayInt(inputLen, seed + 0);
+ // just in case we got unlucky
+ inputArray[(new Random(seed + 1)).nextInt(inputLen)] = 0;
+
+ final long javaTimeStart = java.lang.System.currentTimeMillis();
+ final int javaResult = fz(inputArray);
+ final long javaTimeEnd = java.lang.System.currentTimeMillis();
+
+ final long rsTimeStart = java.lang.System.currentTimeMillis();
+
+ Allocation inputAllocation = Allocation.createSized(RS, Element.I32(RS), inputArray.length);
+
+ final long copyTimeStart = java.lang.System.currentTimeMillis();
+
+ inputAllocation.copyFrom(inputArray);
+
+ final long kernelTimeStart = java.lang.System.currentTimeMillis();
+ final int rsResult = s.reduce_fz(inputAllocation).get();
+ final long rsTimeEnd = java.lang.System.currentTimeMillis();
+
+ final boolean success = (inputArray[rsResult] == 0);
+ String status = (success ? "PASSED" : "FAILED");
+ if (success)
+ status += " " + timing.string(javaTimeStart, javaTimeEnd, rsTimeStart,
+ copyTimeStart, kernelTimeStart, rsTimeEnd, inputAllocation);
+ Log.i(TAG,
+ "fz: java input[" + javaResult + "] == " + inputArray[javaResult] +
+ ", rs input[" + rsResult + "] == " + inputArray[javaResult] + ": " + status);
+ inputAllocation.destroy();
+ return success;
+ }
+
+ ///////////////////////////////////////////////////////////////////
+
+ private boolean fz2(RenderScript RS, ScriptC_reduce s, int seed, int size[]) {
+ final int dimX = size[0], dimY = size[1];
+ final int inputLen = dimX * dimY;
+
+ int[] inputArray = createInputArrayInt(inputLen, seed + 0);
+ // just in case we got unlucky
+ inputArray[(new Random(seed + 1)).nextInt(inputLen)] = 0;
+
+ final long javaTimeStart = java.lang.System.currentTimeMillis();
+ final int javaResultLinear = fz(inputArray);
+ final long javaTimeEnd = java.lang.System.currentTimeMillis();
+
+ final Int2 javaResult = new Int2(javaResultLinear % dimX, javaResultLinear / dimX);
+ final int javaCellVal = inputArray[javaResult.x + dimX * javaResult.y];
+
+ final long rsTimeStart = java.lang.System.currentTimeMillis();
+
+ Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS));
+ typeBuilder.setX(dimX).setY(dimY);
+ Allocation inputAllocation = Allocation.createTyped(RS, typeBuilder.create());
+
+ final long copyTimeStart = java.lang.System.currentTimeMillis();
+
+ inputAllocation.copy2DRangeFrom(0, 0, dimX, dimY, inputArray);
+
+ final long kernelTimeStart = java.lang.System.currentTimeMillis();
+ final Int2 rsResult = s.reduce_fz2(inputAllocation).get();
+ final long rsTimeEnd = java.lang.System.currentTimeMillis();
+
+ final int rsCellVal = inputArray[rsResult.x + dimX * rsResult.y];
+ final boolean success = (rsCellVal == 0);
+ String status = (success ? "PASSED" : "FAILED");
+ if (success)
+ status += " " + timing.string(javaTimeStart, javaTimeEnd, rsTimeStart,
+ copyTimeStart, kernelTimeStart, rsTimeEnd, inputAllocation);
+ Log.i(TAG,
+ "fz2: java input[" + javaResult.x + ", " + javaResult.y + "] == " + javaCellVal +
+ ", rs input[" + rsResult.x + ", " + rsResult.y + "] == " + rsCellVal + ": " + status);
+ inputAllocation.destroy();
+ return success;
+ }
+
+ ///////////////////////////////////////////////////////////////////
+
+ private boolean fz3(RenderScript RS, ScriptC_reduce s, int seed, int[] size) {
+ final int dimX = size[0], dimY = size[1], dimZ = size[2];
+ final int inputLen = dimX * dimY * dimZ;
+
+ int[] inputArray = createInputArrayInt(inputLen, seed + 0);
+ // just in case we got unlucky
+ inputArray[(new Random(seed + 1)).nextInt(inputLen)] = 0;
+
+ final long javaTimeStart = java.lang.System.currentTimeMillis();
+ final int javaResultLinear = fz(inputArray);
+ final long javaTimeEnd = java.lang.System.currentTimeMillis();
+
+ final Int3 javaResult = new Int3(
+ javaResultLinear % dimX,
+ (javaResultLinear / dimX) % dimY,
+ javaResultLinear / (dimX * dimY));
+ final int javaCellVal = inputArray[javaResult.x + dimX * javaResult.y + dimX * dimY * javaResult.z];
+
+ final long rsTimeStart = java.lang.System.currentTimeMillis();
+
+ Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS));
+ typeBuilder.setX(dimX).setY(dimY).setZ(dimZ);
+ Allocation inputAllocation = Allocation.createTyped(RS, typeBuilder.create());
+
+ final long copyTimeStart = java.lang.System.currentTimeMillis();
+
+ inputAllocation.copy3DRangeFrom(0, 0, 0, dimX, dimY, dimZ, inputArray);
+
+ final long kernelTimeStart = java.lang.System.currentTimeMillis();
+ final Int3 rsResult = s.reduce_fz3(inputAllocation).get();
+ final long rsTimeEnd = java.lang.System.currentTimeMillis();
+
+ final int rsCellVal = inputArray[rsResult.x + dimX * rsResult.y + dimX * dimY * rsResult.z];
+ final boolean success = (rsCellVal == 0);
+ String status = (success ? "PASSED" : "FAILED");
+ if (success)
+ status += " " + timing.string(javaTimeStart, javaTimeEnd, rsTimeStart,
+ copyTimeStart, kernelTimeStart, rsTimeEnd, inputAllocation);
+ Log.i(TAG,
+ "fz3: java input[" + javaResult.x + ", " + javaResult.y + ", " + javaResult.z + "] == " + javaCellVal +
+ ", rs input[" + rsResult.x + ", " + rsResult.y + ", " + rsResult.z + "] == " + rsCellVal + ": " + status);
+ inputAllocation.destroy();
+ return success;
+ }
+
+ ///////////////////////////////////////////////////////////////////
+
+ private static final int histogramBucketCount = 256;
+
+ private long[] histogram(RenderScript RS, final byte[] inputArray) {
+ Allocation inputAllocation = Allocation.createSized(RS, Element.U8(RS), inputArray.length);
+ inputAllocation.copyFrom(inputArray);
+
+ Allocation outputAllocation = Allocation.createSized(RS, Element.U32(RS), histogramBucketCount);
+
+ ScriptIntrinsicHistogram scriptHsg = ScriptIntrinsicHistogram.create(RS, Element.U8(RS));
+ scriptHsg.setOutput(outputAllocation);
+ scriptHsg.forEach(inputAllocation);
+
+ int[] outputArrayMistyped = new int[histogramBucketCount];
+ outputAllocation.copyTo(outputArrayMistyped);
+
+ long[] outputArray = new long[histogramBucketCount];
+ for (int i = 0; i < histogramBucketCount; ++i)
+ outputArray[i] = outputArrayMistyped[i] & (long) 0xffffffff;
+
+ inputAllocation.destroy();
+ outputAllocation.destroy();
+
+ scriptHsg.destroy();
+ return outputArray;
+ }
+
+ private boolean histogram_array(RenderScript RS, ScriptC_reduce s, int seed, int size[]) {
+ final byte[] inputArray = createInputArrayByte(size[0], seed);
+
+ final long[] javaResult = histogram(RS, inputArray);
+ assertEquals("javaResult length", histogramBucketCount, javaResult.length);
+ final long[] rsResult = s.reduce_histogram(inputArray).get();
+ assertEquals("rsResult length", histogramBucketCount, rsResult.length);
+
+ return result("histogram_array", new timing(size[0]), javaResult, rsResult);
+ }
+
+ private boolean histogram(RenderScript RS, ScriptC_reduce s, int seed, int size[]) {
+ final byte[] inputArray = createInputArrayByte(size[0], seed);
+
+ final long javaTimeStart = java.lang.System.currentTimeMillis();
+ final long[] javaResult = histogram(RS, inputArray);
+ final long javaTimeEnd = java.lang.System.currentTimeMillis();
+ assertEquals("javaResult length", histogramBucketCount, javaResult.length);
+
+ final long rsTimeStart = java.lang.System.currentTimeMillis();
+
+ Allocation inputAllocation = Allocation.createSized(RS, Element.U8(RS), inputArray.length);
+
+ final long copyTimeStart = java.lang.System.currentTimeMillis();
+
+ inputAllocation.copyFrom(inputArray);
+
+ final long kernelTimeStart = java.lang.System.currentTimeMillis();
+ final long[] rsResult = s.reduce_histogram(inputAllocation).get();
+ final long rsTimeEnd = java.lang.System.currentTimeMillis();
+ assertEquals("rsResult length", histogramBucketCount, rsResult.length);
+
+ // NOTE: The "java time" is actually for the RenderScript histogram intrinsic
+ final boolean success =
+ result("histogram",
+ new timing(javaTimeStart, javaTimeEnd, rsTimeStart,
+ copyTimeStart, kernelTimeStart, rsTimeEnd, inputAllocation),
+ javaResult, rsResult);
+ inputAllocation.destroy();
+ return success;
+ }
+
+ //-----------------------------------------------------------------
+
+ private boolean patternRedundantGet(RenderScript RS, ScriptC_reduce s) {
+ // Ensure that get() can be called multiple times on the same
+ // result, and returns the same object each time.
+
+ boolean pass = true;
+
+ final int inputLength = 1 << 18;
+ final byte[] inputArray = createInputArrayByte(inputLength, 789);
+
+ final long[] javaResult = histogram(RS, inputArray);
+ assertEquals("javaResult length", histogramBucketCount, javaResult.length);
+
+ final ScriptC_reduce.resultArray256_uint rsResultFuture = s.reduce_histogram(inputArray);
+ final long[] rsResult1 = rsResultFuture.get();
+ assertEquals("rsResult1 length", histogramBucketCount, rsResult1.length);
+ pass &= result("patternRedundantGet (1)", new timing(inputLength), javaResult, rsResult1);
+
+ final long[] rsResult2 = rsResultFuture.get();
+ pass &= result("patternRedundantGet (2)", new timing(inputLength), javaResult, rsResult2);
+
+ final boolean success = (rsResult1 == rsResult2);
+ Log.i(TAG, "patternRedundantGet (object equality): " + (success ? "PASSED" : "FAILED"));
+ pass &= success;
+
+ return pass;
+ }
+
+ //-----------------------------------------------------------------
+
+ private Int2 mode(RenderScript RS, final byte[] inputArray) {
+ long[] hsg = histogram(RS, inputArray);
+
+ int modeIdx = 0;
+ for (int i = 1; i < hsg.length; ++i)
+ if (hsg[i] > hsg[modeIdx]) modeIdx = i;
+ return new Int2(modeIdx, (int) hsg[modeIdx]);
+ }
+
+ private boolean mode_array(RenderScript RS, ScriptC_reduce s, int seed, int size[]) {
+ final byte[] inputArray = createInputArrayByte(size[0], seed);
+
+ final Int2 javaResult = mode(RS, inputArray);
+ final Int2 rsResult = s.reduce_mode(inputArray).get();
+
+ return result("mode", new timing(size[0]), javaResult, rsResult);
+ }
+
+ ///////////////////////////////////////////////////////////////////
+
+ private long sumgcd(final int in1[], final int in2[]) {
+ assertEquals("sumgcd input lengths", in1.length, in2.length);
+
+ long sum = 0;
+ for (int i = 0; i < in1.length; ++i) {
+ int a = in1[i], b = in2[i];
+
+ while (b != 0) {
+ final int aNew = b;
+ final int bNew = a % b;
+
+ a = aNew;
+ b = bNew;
+ }
+
+ sum += a;
+ }
+ return sum;
+ }
+
+ private boolean sumgcd(RenderScript RS, ScriptC_reduce s, int seed, int size[]) {
+ final int len = size[0];
+
+ final int[] inputArrayA = createInputArrayInt(len, seed + 0);
+ final int[] inputArrayB = createInputArrayInt(len, seed + 1);
+
+ final long javaTimeStart = java.lang.System.currentTimeMillis();
+ final long javaResult = sumgcd(inputArrayA, inputArrayB);
+ final long javaTimeEnd = java.lang.System.currentTimeMillis();
+
+ final long rsTimeStart = java.lang.System.currentTimeMillis();
+
+ Allocation inputAllocationA = Allocation.createSized(RS, Element.I32(RS), len);
+ Allocation inputAllocationB = Allocation.createSized(RS, Element.I32(RS), len);
+
+ final long copyTimeStart = java.lang.System.currentTimeMillis();
+
+ inputAllocationA.copyFrom(inputArrayA);
+ inputAllocationB.copyFrom(inputArrayB);
+
+ final long kernelTimeStart = java.lang.System.currentTimeMillis();
+ final long rsResult = s.reduce_sumgcd(inputAllocationA, inputAllocationB).get();
+ final long rsTimeEnd = java.lang.System.currentTimeMillis();
+
+ final boolean success =
+ result("sumgcd",
+ new timing(javaTimeStart, javaTimeEnd, rsTimeStart, copyTimeStart, kernelTimeStart, rsTimeEnd,
+ inputAllocationA, inputAllocationB),
+ javaResult, rsResult);
+ inputAllocationA.destroy();
+ inputAllocationB.destroy();
+ return success;
+ }
+
+ ///////////////////////////////////////////////////////////////////
+
+ // Return an array of sparse integer values from 0 to maxVal inclusive.
+ // The array consists of all values k*sparseness (k a nonnegative integer)
+ // that are less than maxVal, and maxVal itself. For example, if maxVal
+ // is 20 and sparseness is 6, then the result is { 0, 6, 12, 18, 20 };
+ // and if maxVal is 20 and sparseness is 10, then the result is { 0, 10, 20 }.
+ //
+ // The elements of the array are sorted in increasing order.
+ //
+ // maxVal -- must be nonnegative
+ // sparseness -- must be positive
+ private static int[] computeSizePoints(int maxVal, int sparseness) {
+ assertTrue((maxVal >= 0) && (sparseness > 0));
+
+ final boolean maxValIsExtra = ((maxVal % sparseness) != 0);
+ int[] result = new int[1 + maxVal / sparseness + (maxValIsExtra ? 1 : 0)];
+
+ for (int i = 0; i * sparseness <= maxVal; ++i)
+ result[i] = i * sparseness;
+ if (maxValIsExtra)
+ result[result.length - 1] = maxVal;
+
+ return result;
+ }
+
+ private static final int maxSeedsPerTest = 10;
+
+ static interface Test {
+ // A test execution is characterized by two properties: A seed
+ // and a size.
+ //
+ // The seed is used for generating pseudorandom input data.
+ // Ideally, we use different seeds for different tests and for
+ // different executions of the same test at different sizes.
+ // A test with multiple blocks of input data (i.e., for a
+ // reduction with multiple inputs) may want multiple seeds; it
+ // may use the seeds seed..seed+maxSeedsPerTest-1.
+ //
+ // The size indicates the amount of input data. It is the number
+ // of cells in a particular dimension of the iteration space.
+ boolean run(RenderScript RS, ScriptC_reduce s, int seed, int[] size);
+ }
+
+ static class TestDescription {
+ public TestDescription(String myTestName, Test myTest, int mySeed, int[] myDefSize,
+ int myLog2MaxSize, int mySparseness) {
+ testName = myTestName;
+ test = myTest;
+ seed = mySeed;
+ defSize = myDefSize;
+ log2MaxSize = myLog2MaxSize;
+ sparseness = mySparseness;
+ }
+
+ public TestDescription(String myTestName, Test myTest, int mySeed, int[] myDefSize, int myLog2MaxSize) {
+ testName = myTestName;
+ test = myTest;
+ seed = mySeed;
+ defSize = myDefSize;
+ log2MaxSize = myLog2MaxSize;
+ sparseness = 1;
+ }
+
+ public TestDescription(String myTestName, Test myTest, int mySeed, int[] myDefSize) {
+ testName = myTestName;
+ test = myTest;
+ seed = mySeed;
+ defSize = myDefSize;
+ log2MaxSize = -1;
+ sparseness = 1;
+ }
+
+ public final String testName;
+
+ public final Test test;
+
+ // When executing the test, scale this up by maxSeedsPerTest.
+ public final int seed;
+
+ // If we're only going to run the test once, what size should
+ // we use? The length of the array is the number of
+ // dimensions of the input data.
+ public final int[] defSize;
+
+ // If we're going to run the test over a range of sizes, what
+ // is the maximum size to use? (This constrains the number of
+ // cells of the input data, not the number of cells ALONG A
+ // PARTICULAR DIMENSION of the input data.)
+ public final int log2MaxSize;
+
+ // If we're going to run the test "exhaustively" over a range
+ // of sizes, what is the size of a step through the range?
+ //
+ // For 1D, must be 1.
+ public final int sparseness;
+ }
+
+ private boolean run(TestDescription td, RenderScript RS, ScriptC_reduce s, int seed, int[] size) {
+ String arrayContent = "";
+ for (int i = 0; i < size.length; ++i) {
+ if (i != 0)
+ arrayContent += ", ";
+ arrayContent += size[i];
+ }
+ Log.i(TAG, "Running " + td.testName + "(seed = " + seed + ", size[] = {" + arrayContent + "})");
+ return td.test.run(RS, s, seed, size);
+ }
+
+ private final TestDescription[] correctnessTests = {
+ // alloc and array variants of the same test will use the same
+ // seed, in case results need to be compared.
+
+ new TestDescription("addint1D", this::addint1D, 0, new int[]{100000}, 20),
+ new TestDescription("addint1D_array", this::addint1D_array, 0, new int[]{100000}, 20),
+ new TestDescription("addint2D", this::addint2D, 1, new int[]{450, 225}, 20, 5),
+ new TestDescription("addint3D", this::addint3D, 2, new int[]{37, 48, 49}, 20, 7),
+
+ // Bool and NaN variants of the same test will use the same
+ // seed, in case results need to be compared.
+ new TestDescription("findMinAbsBool", this::findMinAbsBool, 3, new int[]{100000}, 20),
+ new TestDescription("findMinAbsNaN", this::findMinAbsNaN, 3, new int[]{100000}, 20),
+ new TestDescription("findMinAbsBoolInf", this::findMinAbsBoolInf, 4, new int[]{100000}, 20),
+ new TestDescription("findMinAbsNaNInf", this::findMinAbsNaNInf, 4, new int[]{100000}, 20),
+
+ new TestDescription("findMinAndMax", this::findMinAndMax, 5, new int[]{100000}, 20),
+ new TestDescription("findMinAndMax_array", this::findMinAndMax_array, 5, new int[]{100000}, 20),
+ new TestDescription("findMinMat2", this::findMinMat2, 6, new int[]{25000}, 17),
+ new TestDescription("findMinMat4", this::findMinMat4, 7, new int[]{10000}, 15),
+ new TestDescription("fz", this::fz, 8, new int[]{100000}, 20),
+ new TestDescription("fz_array", this::fz_array, 8, new int[]{100000}, 20),
+ new TestDescription("fz2", this::fz2, 9, new int[]{225, 450}, 20, 5),
+ new TestDescription("fz3", this::fz3, 10, new int[]{59, 48, 37}, 20, 7),
+ new TestDescription("histogram", this::histogram, 11, new int[]{100000}, 20),
+ new TestDescription("histogram_array", this::histogram_array, 11, new int[]{100000}, 20),
+ // might want to add: new TestDescription("mode", this::mode, 12, new int[]{100000}, 20),
+ new TestDescription("mode_array", this::mode_array, 12, new int[]{100000}, 20),
+ new TestDescription("sumgcd", this::sumgcd, 13, new int[]{1 << 16}, 20)
+ };
+
+ private boolean runCorrectnessQuick(RenderScript RS, ScriptC_reduce s) {
+ boolean pass = true;
+
+ for (TestDescription td : correctnessTests) {
+ pass &= run(td, RS, s, maxSeedsPerTest * td.seed, td.defSize);
+ }
+
+ return pass;
+ }
+
+ // NOTE: Each test execution gets maxSeedsPerTest, and there are
+ // up to 3 + 5*log2MaxSize test executions in the full (as opposed
+ // to quick) correctness run of a particular test description, and
+ // we need an additional seed for pseudorandom size generation.
+ // Assuming log2MaxSize does not exceed 32, then it should be
+ // sufficient to reserve 1 + (3+5*32)*maxSeedsPerTest seeds per
+ // TestDescription.
+ //
+ // See runCorrectness1D().
+ private static final int seedsPerTestDescriptionCorrectness1D = 1 + (3 + 5 * 32) * maxSeedsPerTest;
+
+ // NOTE: Each test execution gets maxSeedsPerTest, and there are
+ // about 11*((log2MaxSize+1)**2) test executions in the full (as
+ // opposed to quick) correctness run of a particular test
+ // description, and we need a seed for pseudorandom size
+ // generation. Assuming log2MaxSize does not exceed 32, then it
+ // should be sufficient to reserve 1 + 11*1089*maxSeedsPerTest
+ // seeds per TestDescription.
+ //
+ // See runCorrectness2D().
+ private static final int seedsPerTestDescriptionCorrectness2D = 1 + (11 * 1089) * maxSeedsPerTest;
+
+ // NOTE: Each test execution gets maxSeedsPerTest, and there are
+ // about 27*((log2MaxSize+1)**3) + 6*((log2MaxSize+1)**2) test
+ // executions in the full (as opposed to quick) correctness run of
+ // a particular test description, and we need a seed for (c).
+ // Assuming log2MaxSize does not exceed 32, then it should
+ // be sufficient to reserve 1 + (27*(33**3) + 6*(33**2))*maxSeedsPerTest
+ // seeds per TestDescription, which can be simplified upwards to
+ // 1 + (28*(33**3))*maxSeedsPerTest seeds per TestDescription.
+ private static final int seedsPerTestDescriptionCorrectness3D = 1 + (28 * 35937) * maxSeedsPerTest;
+
+ // Each test execution gets a certain number of seeds, and a full
+ // (as opposed to quick) correctness run of a particular
+ // TestDescription consists of some number of executions (each of
+ // which needs up to maxSeedsPerTest) and may require some
+ // additional seeds.
+ private static final int seedsPerTestDescriptionCorrectness =
+ Math.max(seedsPerTestDescriptionCorrectness1D,
+ Math.max(seedsPerTestDescriptionCorrectness2D,
+ seedsPerTestDescriptionCorrectness3D));
+
+ private boolean runCorrectness(RenderScript RS, ScriptC_reduce s) {
+ boolean pass = true;
+
+ for (TestDescription td : correctnessTests) {
+ switch (td.defSize.length) {
+ case 1:
+ pass &= runCorrectness1D(td, RS, s);
+ break;
+ case 2:
+ pass &= runCorrectness2D(td, RS, s);
+ break;
+ case 3:
+ pass &= runCorrectness3D(td, RS, s);
+ break;
+ default:
+ assertTrue("unexpected defSize.length " + td.defSize.length, false);
+ pass &= false;
+ break;
+ }
+ }
+
+ return pass;
+ }
+
+ private boolean runCorrectness1D(TestDescription td, RenderScript RS, ScriptC_reduce s) {
+ assertEquals(1, td.sparseness);
+ final int log2MaxSize = td.log2MaxSize;
+ assertTrue(log2MaxSize >= 0);
+
+ boolean pass = true;
+
+ // We will execute the test with the following sizes:
+ // (a) Each power of 2 from zero (2**0) up to log2MaxSize (2**log2MaxSize)
+ // (b) Each size from (a) +/-1
+ // (c) 2 random sizes between each pair of adjacent points in (a)
+ int[] testSizes = new int[
+ /* a */ (1 + log2MaxSize) +
+ /* b */ 2 * (1 + log2MaxSize) +
+ /* c */ 2 * log2MaxSize];
+ // See seedsPerTestDescriptionCorrectness1D
+
+ final int seedForPickingTestSizes = td.seed * seedsPerTestDescriptionCorrectness;
+
+ int nextTestIdx = 0;
+
+ // Fill in (a) and (b)
+ for (int i = 0; i <= log2MaxSize; ++i) {
+ final int pwrOf2 = 1 << i;
+ testSizes[nextTestIdx++] = pwrOf2; /* a */
+ testSizes[nextTestIdx++] = pwrOf2 - 1; /* b */
+ testSizes[nextTestIdx++] = pwrOf2 + 1; /* b */
+ }
+
+ // Fill in (c)
+ Random r = new Random(seedForPickingTestSizes);
+ for (int i = 0; i < log2MaxSize; ++i) {
+ final int lo = (1 << i) + 1;
+ final int hi = 1 << (i + 1);
+
+ if (lo < hi) {
+ for (int j = 0; j < 2; ++j) {
+ testSizes[nextTestIdx++] = r.nextInt(hi - lo) + lo;
+ }
+ }
+ }
+
+ Arrays.sort(testSizes);
+
+ int[] lastTestSizeArg = new int[]{-1};
+ for (int i = 0; i < testSizes.length; ++i) {
+ if ((testSizes[i] > 0) && (testSizes[i] != lastTestSizeArg[0])) {
+ lastTestSizeArg[0] = testSizes[i];
+ final int seedForTestExecution = seedForPickingTestSizes + 1 + i * maxSeedsPerTest;
+ pass &= run(td, RS, s, seedForTestExecution, lastTestSizeArg);
+ }
+ }
+
+ return pass;
+ }
+
+ private boolean runCorrectness2D(TestDescription td, RenderScript RS, ScriptC_reduce s) {
+ final int log2MaxSize = td.log2MaxSize, maxSize = 1 << log2MaxSize, sparseness = td.sparseness;
+ assertTrue((log2MaxSize >= 0) && (sparseness >= 1));
+
+ boolean pass = true;
+
+ final int[] sizePoints = computeSizePoints(log2MaxSize, sparseness);
+
+ // We will execute the test with the following sizes:
+ // (a) Each dimension at a power of 2 from sizePoints[]
+ /// such that the sum of the exponents does not exceed
+ // log2MaxSize
+ // (b) Each size from (a) with one or both dimensions +/-1,
+ // except where this would exceed 2**log2MaxSize
+ // (c) Approximately 2*(sizePoints.length**2) random sizes
+ ArrayList<int[]> testSizesList = new ArrayList<int[]>();
+ // See seedsPerTestDescriptionCorrectness2D
+
+ final int seedForPickingTestSizes = td.seed * seedsPerTestDescriptionCorrectness;
+
+ // Fill in (a) and (b)
+ for (int i : sizePoints) {
+ final int iPwrOf2 = 1 << i;
+ for (int iDelta = -1; iDelta <= 1; ++iDelta) {
+ final int iSize = iPwrOf2 + iDelta;
+ for (int j : sizePoints) {
+ final int jPwrOf2 = 1 << j;
+ for (int jDelta = -1; jDelta <= 1; ++jDelta) {
+ final int jSize = jPwrOf2 + jDelta;
+ if ((long) iSize * (long) jSize <= maxSize)
+ testSizesList.add(new int[]{iSize, jSize});
+ }
+ }
+ }
+ }
+
+ // Fill in (c)
+ Random r = new Random(seedForPickingTestSizes);
+ for (int i : sizePoints) {
+ for (int j : sizePoints) {
+ final int size0 = 1 + r.nextInt(1 << i);
+ final int size1 = 1 + r.nextInt(maxSize / size0);
+
+ testSizesList.add(new int[]{size0, size1});
+ testSizesList.add(new int[]{size1, size0});
+ }
+ }
+
+ int[][] testSizes = testSizesList.toArray(new int[0][]);
+ Arrays.sort(testSizes,
+ (a, b) -> {
+ final int comp0 = ((Integer) a[0]).compareTo(b[0]);
+ return (comp0 != 0 ? comp0 : ((Integer) a[1]).compareTo(b[1]));
+ });
+
+ int[] lastTestSizeArg = null;
+ for (int i = 0; i < testSizes.length; ++i) {
+ if ((testSizes[i][0] <= 0) || (testSizes[i][1] <= 0))
+ continue;
+ if ((lastTestSizeArg != null) &&
+ (testSizes[i][0] == lastTestSizeArg[0]) &&
+ (testSizes[i][1] == lastTestSizeArg[1]))
+ continue;
+ lastTestSizeArg = testSizes[i];
+ final int seedForTestExecution = seedForPickingTestSizes + 1 + i * maxSeedsPerTest;
+ pass &= run(td, RS, s, seedForTestExecution, lastTestSizeArg);
+ }
+
+ return pass;
+ }
+
+ private boolean runCorrectness3D(TestDescription td, RenderScript RS, ScriptC_reduce s) {
+ final int log2MaxSize = td.log2MaxSize, maxSize = 1 << log2MaxSize, sparseness = td.sparseness;
+ assertTrue((log2MaxSize >= 0) && (sparseness >= 1));
+
+ boolean pass = true;
+
+ final int[] sizePoints = computeSizePoints(log2MaxSize, sparseness);
+
+ // We will execute the test with the following sizes:
+ // (a) Each dimension at a power of 2 from sizePoints[]
+ /// such that the sum of the exponents does not exceed
+ // log2MaxSize
+ // (b) Each size from (a) with one or both dimensions +/-1,
+ // except where this would exceed 2**log2MaxSize
+ // (c) Approximately 6*(sizePoints.length**2) random sizes
+ ArrayList<int[]> testSizesList = new ArrayList<int[]>();
+ // See seedsPerTestDescriptionCorrectness3D
+
+ final int seedForPickingTestSizes = td.seed * seedsPerTestDescriptionCorrectness;
+
+ // Fill in (a) and (b)
+ for (int i : sizePoints) {
+ final int iPwrOf2 = 1 << i;
+ for (int iDelta = -1; iDelta <= 1; ++iDelta) {
+ final int iSize = iPwrOf2 + iDelta;
+ for (int j : sizePoints) {
+ final int jPwrOf2 = 1 << j;
+ for (int jDelta = -1; jDelta <= 1; ++jDelta) {
+ final int jSize = jPwrOf2 + jDelta;
+ for (int k : sizePoints) {
+ final int kPwrOf2 = 1 << k;
+ for (int kDelta = -1; kDelta <= 1; ++kDelta) {
+ final int kSize = kPwrOf2 + kDelta;
+ if ((long) iSize * (long) jSize * (long) kSize <= maxSize)
+ testSizesList.add(new int[]{iSize, jSize, kSize});
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // Fill in (c)
+ Random r = new Random(seedForPickingTestSizes);
+ for (int i : sizePoints) {
+ for (int j : sizePoints) {
+ final int size0 = 1 + r.nextInt(1 << i);
+ final int size1 = 1 + r.nextInt(Math.min(1 << j, maxSize / size0));
+ final int size2 = 1 + r.nextInt(maxSize / (size0 * size1));
+
+ testSizesList.add(new int[]{size0, size1, size2});
+ testSizesList.add(new int[]{size0, size2, size1});
+ testSizesList.add(new int[]{size1, size0, size2});
+ testSizesList.add(new int[]{size1, size2, size0});
+ testSizesList.add(new int[]{size2, size0, size1});
+ testSizesList.add(new int[]{size2, size1, size0});
+ }
+ }
+
+ int[][] testSizes = testSizesList.toArray(new int[0][]);
+ Arrays.sort(testSizes,
+ (a, b) -> {
+ int comp = ((Integer) a[0]).compareTo(b[0]);
+ if (comp == 0)
+ comp = ((Integer) a[1]).compareTo(b[1]);
+ if (comp == 0)
+ comp = ((Integer) a[2]).compareTo(b[2]);
+ return comp;
+ });
+
+ int[] lastTestSizeArg = null;
+ for (int i = 0; i < testSizes.length; ++i) {
+ if ((testSizes[i][0] <= 0) || (testSizes[i][1] <= 0) || (testSizes[i][2] <= 0))
+ continue;
+ if ((lastTestSizeArg != null) &&
+ (testSizes[i][0] == lastTestSizeArg[0]) &&
+ (testSizes[i][1] == lastTestSizeArg[1]) &&
+ (testSizes[i][2] == lastTestSizeArg[2]))
+ continue;
+
+ // Apply Z-dimension limiting.
+ //
+ // The Z dimension is always handled specially by GPU
+ // drivers, and a high value for this dimension can have
+ // serious performance implications. For example, Cuda
+ // and OpenCL encourage Z to be the smallest dimension.
+ if (testSizes[i][2] > 1024)
+ continue;
+
+ lastTestSizeArg = testSizes[i];
+ final int seedForTestExecution = seedForPickingTestSizes + 1 + i * maxSeedsPerTest;
+ pass &= run(td, RS, s, seedForTestExecution, lastTestSizeArg);
+ }
+
+ return pass;
+ }
+
+ private final TestDescription[] performanceTests = {
+ new TestDescription("addint1D", this::addint1D, 0, new int[]{100000 << 10}),
+ new TestDescription("addint2D", this::addint2D, 1, new int[]{450 << 5, 225 << 5}),
+ new TestDescription("addint3D", this::addint3D, 2, new int[]{37 << 3, 48 << 3, 49 << 3}),
+ new TestDescription("findMinAndMax", this::findMinAndMax, 3, new int[]{100000 << 9}),
+ new TestDescription("fz", this::fz, 4, new int[]{100000 << 10}),
+ new TestDescription("fz2", this::fz2, 5, new int[]{225 << 5, 450 << 5}),
+ new TestDescription("fz3", this::fz3, 6, new int[]{59 << 3, 48 << 3, 37 << 3}),
+ new TestDescription("histogram", this::histogram, 7, new int[]{100000 << 10}),
+ // might want to add: new TestDescription("mode", this::mode, 8, new int[]{100000}),
+ new TestDescription("sumgcd", this::sumgcd, 9, new int[]{1 << 21})
+ };
+
+ private boolean runPerformanceQuick(RenderScript RS, ScriptC_reduce s) {
+ boolean pass = true;
+
+ for (TestDescription td : performanceTests) {
+ pass &= run(td, RS, s, maxSeedsPerTest * td.seed, td.defSize);
+ }
+
+ return pass;
+ }
+
+ private boolean runCorrectnessPatterns(RenderScript RS, ScriptC_reduce s) {
+ // Test some very specific usage patterns.
+ boolean pass = true;
+
+ pass &= patternDuplicateAnonymousResult(RS, s);
+ pass &= patternFindMinAndMaxInf(RS, s);
+ pass &= patternInterleavedReduce(RS, s);
+ pass &= patternRedundantGet(RS, s);
+
+ return pass;
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_reduce s = new ScriptC_reduce(pRS);
+ s.set_negInf(Float.NEGATIVE_INFINITY);
+ s.set_posInf(Float.POSITIVE_INFINITY);
+
+ boolean pass = true;
+
+ pass &= runCorrectnessPatterns(pRS, s);
+ pass &= runCorrectnessQuick(pRS, s);
+ pass &= runCorrectness(pRS, s);
+ // pass &= runPerformanceQuick(pRS, s);
+
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+
+ Log.i(TAG, pass ? "PASSED" : "FAILED");
+ if (pass)
+ passTest();
+ else
+ failTest();
+ }
+}
+
+// TODO: Add machinery for easily running fuller (i.e., non-sparse) testing.
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_reduce_backward.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_reduce_backward.java
new file mode 100644
index 0000000..de08759
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_reduce_backward.java
@@ -0,0 +1,330 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+/* This is a much simpler version of UT_reduce.java that
+ * exercises pragmas after the functions (backward reference),
+ * whereas the other test case exercises the pragmas before the
+ * functions (forward reference).
+ */
+
+package com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.Float2;
+import android.renderscript.Int2;
+import android.renderscript.Int3;
+import android.renderscript.RenderScript;
+import android.renderscript.ScriptIntrinsicHistogram;
+import android.renderscript.Type;
+import android.util.Log;
+
+import java.util.Random;
+
+public class UT_reduce_backward extends UnitTest {
+ private static final String TAG = "reduce_backward";
+
+ public UT_reduce_backward(Context ctx) {
+ super("reduce_backward", ctx);
+ }
+
+ private byte[] createInputArrayByte(int len, int seed) {
+ byte[] array = new byte[len];
+ (new Random(seed)).nextBytes(array);
+ return array;
+ }
+
+ private float[] createInputArrayFloat(int len, int seed) {
+ Random rand = new Random(seed);
+ float[] array = new float[len];
+ for (int i = 0; i < len; ++i)
+ array[i] = rand.nextFloat();
+ return array;
+ }
+
+ private int[] createInputArrayInt(int len, int seed) {
+ Random rand = new Random(seed);
+ int[] array = new int[len];
+ for (int i = 0; i < len; ++i)
+ array[i] = rand.nextInt();
+ return array;
+ }
+
+ private int[] createInputArrayInt(int len, int seed, int eltRange) {
+ Random rand = new Random(seed);
+ int[] array = new int[len];
+ for (int i = 0; i < len; ++i)
+ array[i] = rand.nextInt(eltRange);
+ return array;
+ }
+
+ private <T extends Number> boolean result(String testName, T javaRslt, T rsRslt) {
+ final boolean success = javaRslt.equals(rsRslt);
+ Log.i(TAG,
+ testName + ": java " + javaRslt + ", rs " + rsRslt + ": " +
+ (success ? "PASSED" : "FAILED"));
+ return success;
+ }
+
+ private boolean result(String testName, Float2 javaRslt, Float2 rsRslt) {
+ final boolean success = (javaRslt.x == rsRslt.x) && (javaRslt.y == rsRslt.y);
+ Log.i(TAG,
+ testName +
+ ": java (" + javaRslt.x + ", " + javaRslt.y + ")" +
+ ", rs (" + rsRslt.x + ", " + rsRslt.y + ")" +
+ ": " + (success ? "PASSED" : "FAILED"));
+ return success;
+ }
+
+ private boolean result(String testName, Int2 javaRslt, Int2 rsRslt) {
+ final boolean success = (javaRslt.x == rsRslt.x) && (javaRslt.y == rsRslt.y);
+ Log.i(TAG,
+ testName +
+ ": java (" + javaRslt.x + ", " + javaRslt.y + ")" +
+ ", rs (" + rsRslt.x + ", " + rsRslt.y + ")" +
+ ": " + (success ? "PASSED" : "FAILED"));
+ return success;
+ }
+
+ ///////////////////////////////////////////////////////////////////
+
+ private int addint(int[] input) {
+ int rslt = 0;
+ for (int idx = 0; idx < input.length; ++idx)
+ rslt += input[idx];
+ return rslt;
+ }
+
+ private boolean addint1D(RenderScript RS, ScriptC_reduce_backward s) {
+ final int[] input = createInputArrayInt(100000, 0, 1 << 13);
+
+ final int javaRslt = addint(input);
+ final int rsRslt = s.reduce_addint(input).get();
+
+ return result("addint1D", javaRslt, rsRslt);
+ }
+
+ private boolean addint2D(RenderScript RS, ScriptC_reduce_backward s) {
+ final int dimX = 450, dimY = 225;
+
+ final int[] inputArray = createInputArrayInt(dimX * dimY, 1, 1 << 13);
+ Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS));
+ typeBuilder.setX(dimX).setY(dimY);
+ Allocation inputAllocation = Allocation.createTyped(RS, typeBuilder.create());
+ inputAllocation.copy2DRangeFrom(0, 0, dimX, dimY, inputArray);
+
+ final int javaRslt = addint(inputArray);
+ final int rsRslt = s.reduce_addint(inputAllocation).get();
+
+ return result("addint2D", javaRslt, rsRslt);
+ }
+
+ ///////////////////////////////////////////////////////////////////
+
+ private Int2 findMinAndMax(float[] input) {
+ float minVal = Float.POSITIVE_INFINITY;
+ int minIdx = -1;
+ float maxVal = Float.NEGATIVE_INFINITY;
+ int maxIdx = -1;
+
+ for (int idx = 0; idx < input.length; ++idx) {
+ if (input[idx] < minVal) {
+ minVal = input[idx];
+ minIdx = idx;
+ }
+ if (input[idx] > maxVal) {
+ maxVal = input[idx];
+ maxIdx = idx;
+ }
+ }
+
+ return new Int2(minIdx, maxIdx);
+ }
+
+ private boolean findMinAndMax(RenderScript RS, ScriptC_reduce_backward s) {
+ final float[] input = createInputArrayFloat(100000, 4);
+
+ final Int2 javaRslt = findMinAndMax(input);
+ final Int2 rsRslt = s.reduce_findMinAndMax(input).get();
+
+ // Note that the Java and RenderScript algorithms are not
+ // guaranteed to find the same cells -- but they should
+ // find cells of the same value.
+ final Float2 javaVal = new Float2(input[javaRslt.x], input[javaRslt.y]);
+ final Float2 rsVal = new Float2(input[rsRslt.x], input[rsRslt.y]);
+
+ return result("findMinAndMax", javaVal, rsVal);
+ }
+
+ ///////////////////////////////////////////////////////////////////
+
+ private boolean fz(RenderScript RS, ScriptC_reduce_backward s) {
+ final int inputLen = 100000;
+ int[] input = createInputArrayInt(inputLen, 5);
+ // just in case we got unlucky
+ input[(new Random(6)).nextInt(inputLen)] = 0;
+
+ final int rsRslt = s.reduce_fz(input).get();
+
+ final boolean success = (input[rsRslt] == 0);
+ Log.i(TAG,
+ "fz: input[" + rsRslt + "] == " + input[rsRslt] + ": " +
+ (success ? "PASSED" : "FAILED"));
+ return success;
+ }
+
+ ///////////////////////////////////////////////////////////////////
+
+ private boolean fz2(RenderScript RS, ScriptC_reduce_backward s) {
+ final int dimX = 225, dimY = 450;
+ final int inputLen = dimX * dimY;
+
+ int[] inputArray = createInputArrayInt(inputLen, 7);
+ // just in case we got unlucky
+ inputArray[(new Random(8)).nextInt(inputLen)] = 0;
+
+ Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS));
+ typeBuilder.setX(dimX).setY(dimY);
+ Allocation inputAllocation = Allocation.createTyped(RS, typeBuilder.create());
+ inputAllocation.copy2DRangeFrom(0, 0, dimX, dimY, inputArray);
+
+ final Int2 rsRslt = s.reduce_fz2(inputAllocation).get();
+
+ final int cellVal = inputArray[rsRslt.x + dimX * rsRslt.y];
+ final boolean success = (cellVal == 0);
+ Log.i(TAG,
+ "fz2: input[" + rsRslt.x + ", " + rsRslt.y + "] == " + cellVal + ": " +
+ (success ? "PASSED" : "FAILED"));
+ return success;
+ }
+
+ ///////////////////////////////////////////////////////////////////
+
+ private boolean fz3(RenderScript RS, ScriptC_reduce_backward s) {
+ final int dimX = 59, dimY = 48, dimZ = 37;
+ final int inputLen = dimX * dimY * dimZ;
+
+ int[] inputArray = createInputArrayInt(inputLen, 9);
+ // just in case we got unlucky
+ inputArray[(new Random(10)).nextInt(inputLen)] = 0;
+
+ Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS));
+ typeBuilder.setX(dimX).setY(dimY).setZ(dimZ);
+ Allocation inputAllocation = Allocation.createTyped(RS, typeBuilder.create());
+ inputAllocation.copy3DRangeFrom(0, 0, 0, dimX, dimY, dimZ, inputArray);
+
+ final Int3 rsRslt = s.reduce_fz3(inputAllocation).get();
+
+ final int cellVal = inputArray[rsRslt.x + dimX * rsRslt.y + dimX * dimY * rsRslt.z];
+ final boolean success = (cellVal == 0);
+ Log.i(TAG,
+ "fz3: input[" + rsRslt.x + ", " + rsRslt.y + ", " + rsRslt.z + "] == " + cellVal + ": " +
+ (success ? "PASSED" : "FAILED"));
+ return success;
+ }
+
+ ///////////////////////////////////////////////////////////////////
+
+ private static final int histogramBucketCount = 256;
+
+ private long[] histogram(RenderScript RS, final byte[] inputArray) {
+ Allocation inputAllocation = Allocation.createSized(RS, Element.U8(RS), inputArray.length);
+ inputAllocation.copyFrom(inputArray);
+
+ Allocation outputAllocation = Allocation.createSized(RS, Element.U32(RS), histogramBucketCount);
+
+ ScriptIntrinsicHistogram scriptHsg = ScriptIntrinsicHistogram.create(RS, Element.U8(RS));
+ scriptHsg.setOutput(outputAllocation);
+ scriptHsg.forEach(inputAllocation);
+
+ int[] outputArrayMistyped = new int[histogramBucketCount];
+ outputAllocation.copyTo(outputArrayMistyped);
+
+ long[] outputArray = new long[histogramBucketCount];
+ for (int i = 0; i < histogramBucketCount; ++i)
+ outputArray[i] = outputArrayMistyped[i] & (long) 0xffffffff;
+ return outputArray;
+ }
+
+ private boolean histogram(RenderScript RS, ScriptC_reduce_backward s) {
+ final byte[] inputArray = createInputArrayByte(100000, 11);
+
+ final long[] javaRslt = histogram(RS, inputArray);
+ _RS_ASSERT("javaRslt unexpected length: " + javaRslt.length, javaRslt.length == histogramBucketCount);
+ final long[] rsRslt = s.reduce_histogram(inputArray).get();
+ _RS_ASSERT("rsRslt unexpected length: " + rsRslt.length, rsRslt.length == histogramBucketCount);
+
+ for (int i = 0; i < histogramBucketCount; ++i) {
+ if (javaRslt[i] != rsRslt[i]) {
+ Log.i(TAG,
+ "histogram[" + i + "]: java " + javaRslt[i] + ", rs " + rsRslt[i] + ": FAILED");
+ return false;
+ }
+ }
+
+ Log.i(TAG, "histogram: PASSED");
+ return true;
+ }
+
+ //-----------------------------------------------------------------
+
+ private Int2 mode(RenderScript RS, final byte[] inputArray) {
+ long[] hsg = histogram(RS, inputArray);
+
+ int modeIdx = 0;
+ for (int i = 1; i < hsg.length; ++i)
+ if (hsg[i] > hsg[modeIdx]) modeIdx = i;
+ return new Int2(modeIdx, (int) hsg[modeIdx]);
+ }
+
+ private boolean mode(RenderScript RS, ScriptC_reduce_backward s) {
+ final byte[] inputArray = createInputArrayByte(100000, 12);
+
+ final Int2 javaRslt = mode(RS, inputArray);
+ final Int2 rsRslt = s.reduce_mode(inputArray).get();
+
+ return result("mode", javaRslt, rsRslt);
+ }
+
+ ///////////////////////////////////////////////////////////////////
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_reduce_backward s = new ScriptC_reduce_backward(pRS);
+ s.set_negInf(Float.NEGATIVE_INFINITY);
+ s.set_posInf(Float.POSITIVE_INFINITY);
+
+ boolean pass = true;
+ pass &= addint1D(pRS, s);
+ pass &= addint2D(pRS, s);
+ pass &= findMinAndMax(pRS, s);
+ pass &= fz(pRS, s);
+ pass &= fz2(pRS, s);
+ pass &= fz3(pRS, s);
+ pass &= histogram(pRS, s);
+ pass &= mode(pRS, s);
+
+ pRS.finish();
+ pRS.destroy();
+
+ Log.i(TAG, pass ? "PASSED" : "FAILED");
+ if (pass)
+ passTest();
+ else
+ failTest();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_refcount.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_refcount.java
new file mode 100644
index 0000000..d3de987
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_refcount.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.Type;
+
+public class UT_refcount extends UnitTest {
+ private Type mT;
+ private Allocation mA;
+
+ public UT_refcount(Context ctx) {
+ super("Refcount", ctx);
+ }
+
+ private void initializeGlobals(RenderScript RS, ScriptC_refcount s) {
+ Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS));
+ int X = 500;
+ int Y = 700;
+ typeBuilder.setX(X).setY(Y);
+ mT = typeBuilder.create();
+ mA = Allocation.createTyped(RS, mT);
+ s.set_globalA(mA);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ pRS.setMessageHandler(mRsMessage);
+ ScriptC_refcount s = new ScriptC_refcount(pRS);
+ initializeGlobals(pRS, s);
+ s.invoke_refcount_test();
+ pRS.finish();
+ mA.destroy();
+ mT.destroy();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_rsdebug.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_rsdebug.java
new file mode 100644
index 0000000..685c1e6
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_rsdebug.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript;
+
+public class UT_rsdebug extends UnitTest {
+
+ public UT_rsdebug(Context ctx) {
+ super("rsDebug", ctx);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_rsdebug s = new ScriptC_rsdebug(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ s.invoke_test_rsdebug(0, 0);
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_rsdebug_24.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_rsdebug_24.java
new file mode 100644
index 0000000..23313d6
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_rsdebug_24.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript;
+
+public class UT_rsdebug_24 extends UnitTest {
+
+ public UT_rsdebug_24(Context ctx) {
+ super("rsDebug_24", ctx);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_rsdebug_24 s = new ScriptC_rsdebug_24(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ s.invoke_test_rsdebug_24(0, 0);
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_rstime.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_rstime.java
new file mode 100644
index 0000000..6730715
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_rstime.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript;
+
+public class UT_rstime extends UnitTest {
+
+ public UT_rstime(Context ctx) {
+ super("rsTime", ctx);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_rstime s = new ScriptC_rstime(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ s.setTimeZone("America/Los_Angeles");
+ s.invoke_test_rstime(0, 0);
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_rstypes.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_rstypes.java
new file mode 100644
index 0000000..9dfd20d
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_rstypes.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript;
+
+public class UT_rstypes extends UnitTest {
+
+ public UT_rstypes(Context ctx) {
+ super("rsTypes", ctx);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_rstypes s = new ScriptC_rstypes(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ s.invoke_test_rstypes(0, 0);
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_sampler.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_sampler.java
new file mode 100644
index 0000000..b6643cd
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_sampler.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript;
+import android.renderscript.Sampler;
+
+public class UT_sampler extends UnitTest {
+ Sampler minification;
+ Sampler magnification;
+ Sampler wrapS;
+ Sampler wrapT;
+ Sampler anisotropy;
+
+ public UT_sampler(Context ctx) {
+ super("Sampler", ctx);
+ }
+
+ private Sampler.Builder getDefaultBuilder(RenderScript RS) {
+ Sampler.Builder b = new Sampler.Builder(RS);
+ b.setMinification(Sampler.Value.NEAREST);
+ b.setMagnification(Sampler.Value.NEAREST);
+ b.setWrapS(Sampler.Value.CLAMP);
+ b.setWrapT(Sampler.Value.CLAMP);
+ b.setAnisotropy(1.0f);
+ return b;
+ }
+
+ private void initializeGlobals(RenderScript RS, ScriptC_sampler s) {
+ Sampler.Builder b = getDefaultBuilder(RS);
+ b.setMinification(Sampler.Value.LINEAR_MIP_LINEAR);
+ minification = b.create();
+
+ b = getDefaultBuilder(RS);
+ b.setMagnification(Sampler.Value.LINEAR);
+ magnification = b.create();
+
+ b = getDefaultBuilder(RS);
+ b.setWrapS(Sampler.Value.WRAP);
+ wrapS = b.create();
+
+ b = getDefaultBuilder(RS);
+ b.setWrapT(Sampler.Value.WRAP);
+ wrapT = b.create();
+
+ b = getDefaultBuilder(RS);
+ b.setAnisotropy(8.0f);
+ anisotropy = b.create();
+
+ s.set_minification(minification);
+ s.set_magnification(magnification);
+ s.set_wrapS(wrapS);
+ s.set_wrapT(wrapT);
+ s.set_anisotropy(anisotropy);
+ }
+
+ private void testScriptSide(RenderScript pRS) {
+ ScriptC_sampler s = new ScriptC_sampler(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ initializeGlobals(pRS, s);
+ s.invoke_sampler_test();
+ pRS.finish();
+ s.destroy();
+ }
+
+ private void testJavaSide(RenderScript RS) {
+ _RS_ASSERT("minification.getMagnification() == Sampler.Value.NEAREST",
+ minification.getMagnification() == Sampler.Value.NEAREST);
+ _RS_ASSERT("minification.getMinification() == Sampler.Value.LINEAR_MIP_LINEAR",
+ minification.getMinification() == Sampler.Value.LINEAR_MIP_LINEAR);
+ _RS_ASSERT("minification.getWrapS() == Sampler.Value.CLAMP",
+ minification.getWrapS() == Sampler.Value.CLAMP);
+ _RS_ASSERT("minification.getWrapT() == Sampler.Value.CLAMP",
+ minification.getWrapT() == Sampler.Value.CLAMP);
+ _RS_ASSERT("minification.getAnisotropy() == 1.0f",
+ minification.getAnisotropy() == 1.0f);
+
+ _RS_ASSERT("magnification.getMagnification() == Sampler.Value.LINEAR",
+ magnification.getMagnification() == Sampler.Value.LINEAR);
+ _RS_ASSERT("magnification.getMinification() == Sampler.Value.NEAREST",
+ magnification.getMinification() == Sampler.Value.NEAREST);
+ _RS_ASSERT("magnification.getWrapS() == Sampler.Value.CLAMP",
+ magnification.getWrapS() == Sampler.Value.CLAMP);
+ _RS_ASSERT("magnification.getWrapT() == Sampler.Value.CLAMP",
+ magnification.getWrapT() == Sampler.Value.CLAMP);
+ _RS_ASSERT("magnification.getAnisotropy() == 1.0f",
+ magnification.getAnisotropy() == 1.0f);
+
+ _RS_ASSERT("wrapS.getMagnification() == Sampler.Value.NEAREST",
+ wrapS.getMagnification() == Sampler.Value.NEAREST);
+ _RS_ASSERT("wrapS.getMinification() == Sampler.Value.NEAREST",
+ wrapS.getMinification() == Sampler.Value.NEAREST);
+ _RS_ASSERT("wrapS.getWrapS() == Sampler.Value.WRAP",
+ wrapS.getWrapS() == Sampler.Value.WRAP);
+ _RS_ASSERT("wrapS.getWrapT() == Sampler.Value.CLAMP",
+ wrapS.getWrapT() == Sampler.Value.CLAMP);
+ _RS_ASSERT("wrapS.getAnisotropy() == 1.0f",
+ wrapS.getAnisotropy() == 1.0f);
+
+ _RS_ASSERT("wrapT.getMagnification() == Sampler.Value.NEAREST",
+ wrapT.getMagnification() == Sampler.Value.NEAREST);
+ _RS_ASSERT("wrapT.getMinification() == Sampler.Value.NEAREST",
+ wrapT.getMinification() == Sampler.Value.NEAREST);
+ _RS_ASSERT("wrapT.getWrapS() == Sampler.Value.CLAMP",
+ wrapT.getWrapS() == Sampler.Value.CLAMP);
+ _RS_ASSERT("wrapT.getWrapT() == Sampler.Value.WRAP",
+ wrapT.getWrapT() == Sampler.Value.WRAP);
+ _RS_ASSERT("wrapT.getAnisotropy() == 1.0f",
+ wrapT.getAnisotropy() == 1.0f);
+
+ _RS_ASSERT("anisotropy.getMagnification() == Sampler.Value.NEAREST",
+ anisotropy.getMagnification() == Sampler.Value.NEAREST);
+ _RS_ASSERT("anisotropy.getMinification() == Sampler.Value.NEAREST",
+ anisotropy.getMinification() == Sampler.Value.NEAREST);
+ _RS_ASSERT("anisotropy.getWrapS() == Sampler.Value.CLAMP",
+ anisotropy.getWrapS() == Sampler.Value.CLAMP);
+ _RS_ASSERT("anisotropy.getWrapT() == Sampler.Value.CLAMP",
+ anisotropy.getWrapT() == Sampler.Value.CLAMP);
+ _RS_ASSERT("anisotropy.getAnisotropy() == 1.0f",
+ anisotropy.getAnisotropy() == 8.0f);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ testScriptSide(pRS);
+ testJavaSide(pRS);
+ passTest();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_script_group2_float.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_script_group2_float.java
new file mode 100644
index 0000000..21989af
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_script_group2_float.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.ScriptGroup;
+import android.renderscript.Type;
+import android.util.Log;
+
+public class UT_script_group2_float extends UnitTest {
+ private static final int ARRAY_SIZE = 8;
+
+ private static final String TAG = "ScritGroup2 (Floating Point Test)";
+
+ public UT_script_group2_float(Context ctx) {
+ super(TAG, ctx);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ pRS.setMessageHandler(mRsMessage);
+
+ ScriptC_float_test s_float = new ScriptC_float_test(pRS);
+
+ float[] array = new float[ARRAY_SIZE];
+
+ for (int i = 0; i < ARRAY_SIZE; i++) {
+ array[i] = 0.0f;
+ }
+
+ Allocation input = Allocation.createSized(pRS, Element.F32(pRS), ARRAY_SIZE);
+ input.copyFrom(array);
+
+ ScriptGroup.Builder2 builder = new ScriptGroup.Builder2(pRS);
+
+ ScriptGroup.Input unbound = builder.addInput();
+
+ final float floatVal = 3.14f;
+ final double doubleVal = 1.23456789;
+ final long longVal = 0x100000000L;
+ final Type T = Type.createX(pRS, Element.F64(pRS), ARRAY_SIZE);
+ ScriptGroup.Closure c0 =
+ builder.addKernel(s_float.getKernelID_foo(),
+ T,
+ unbound,
+ new ScriptGroup.Binding(s_float.getFieldID_floatVal(),
+ floatVal),
+ new ScriptGroup.Binding(s_float.getFieldID_val(),
+ doubleVal));
+
+ ScriptGroup.Closure c1 =
+ builder.addKernel(s_float.getKernelID_goo(),
+ T,
+ c0.getReturn(),
+ new ScriptGroup.Binding(s_float.getFieldID_valLong(),
+ longVal));
+
+ ScriptGroup group = builder.create("TestFloatAnd64bit", c1.getReturn());
+
+ double[] a = new double[ARRAY_SIZE];
+ ((Allocation) group.execute(input)[0]).copyTo(a);
+
+ pRS.finish();
+ T.destroy();
+ group.destroy();
+ input.destroy();
+ s_float.destroy();
+ pRS.destroy();
+
+ boolean failed = false;
+ for (int i = 0; i < ARRAY_SIZE; i++) {
+ if (a[i] != doubleVal + longVal + floatVal) {
+ Log.e(TAG, "a[" + i + "]=" + a[i] + ", should be " + (doubleVal + longVal));
+ failed = true;
+ }
+ }
+ if (failed) {
+ failTest();
+ return;
+ }
+ passTest();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_script_group2_gatherscatter.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_script_group2_gatherscatter.java
new file mode 100644
index 0000000..6ff47bb
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_script_group2_gatherscatter.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.ScriptGroup;
+import android.renderscript.Type;
+import android.util.Log;
+
+public class UT_script_group2_gatherscatter extends UnitTest {
+ private static final int ARRAY_SIZE = 256;
+
+ private static final String TAG = "ScriptGroup2 (GatherScatter)";
+
+ int[] mArray;
+
+ public UT_script_group2_gatherscatter(Context ctx) {
+ super(TAG, ctx);
+ }
+
+ public void initializeGlobals(RenderScript RS, ScriptC_addup s) {
+ mArray = new int[ARRAY_SIZE * 4];
+
+ for (int i = 0; i < ARRAY_SIZE; i++) {
+ mArray[i * 4] = i * 7;
+ mArray[i * 4 + 1] = i * 7 + 1;
+ mArray[i * 4 + 2] = i * 7 + 2;
+ mArray[i * 4 + 3] = i * 7 + 3;
+ }
+ }
+
+ // This test tests ScriptGroup2 API for handling gather scatter operations
+ // on global allocations that are passed across kernels in a script group.
+ // The test sums up all elements in the input int4 array of size ARRAY_SIZE.
+ // To do so, it adds up the second half of the array to its first half using
+ // kernel function add() in addsup.rs, and then repeatedly applies the same
+ // kernel function to the shrinking result arrays until the result is a
+ // single int4 value.
+ // These steps are created as a script group by repeatedly adding the
+ // same kernel function, with the input of one kernel being the output of
+ // the previous added kernel function.
+ // Since the kernel function relies on rsGetElementAt to access the counterpart
+ // of the current element in the second half of the array, the compiler cannot
+ // fuse it with the other kernel that it dependes on.
+ // This test verifies an ScriptGroup2 implementation correctly handles such
+ // a case.
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_addup s = new ScriptC_addup(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ initializeGlobals(pRS, s);
+
+ Allocation input = Allocation.createSized(pRS, Element.I32_4(pRS), ARRAY_SIZE);
+ input.copyFrom(mArray);
+
+ ScriptGroup.Builder2 builder = new ScriptGroup.Builder2(pRS);
+
+ ScriptGroup.Input unbound = builder.addInput();
+
+ ScriptGroup.Closure c = null;
+ ScriptGroup.Future f = null;
+ int stride;
+ for (stride = ARRAY_SIZE / 2; stride >= 1; stride >>= 1) {
+ ScriptGroup.Binding binding;
+ if (f == null) {
+ binding = new ScriptGroup.Binding(s.getFieldID_a_in(), unbound);
+ } else {
+ binding = new ScriptGroup.Binding(s.getFieldID_a_in(), f);
+ }
+ c = builder.addKernel(s.getKernelID_add(),
+ Type.createX(pRS, Element.I32_4(pRS), stride),
+ new ScriptGroup.Binding(s.getFieldID_reduction_stride(), stride),
+ binding);
+ f = c.getReturn();
+ }
+
+ ScriptGroup group = builder.create("Summation", c.getReturn());
+
+ if (c == null) {
+ return;
+ }
+
+ int[] a = new int[4];
+ ((Allocation) group.execute(input)[0]).copyTo(a);
+
+ pRS.finish();
+
+ group.destroy();
+ input.destroy();
+ s.destroy();
+ pRS.destroy();
+
+ boolean failed = false;
+ for (int i = 0; i < 4; i++) {
+ if (failed == false &&
+ a[i] != ARRAY_SIZE * (ARRAY_SIZE - 1) * 7 / 2 + i * ARRAY_SIZE) {
+ Log.e(TAG, "a[" + i + "]=" + a[i] + ", should be " +
+ (ARRAY_SIZE * (ARRAY_SIZE - 1) * 7 / 2 + i * ARRAY_SIZE));
+ failed = true;
+ }
+ }
+ if (failed) {
+ failTest();
+ return;
+ }
+ passTest();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_script_group2_nochain.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_script_group2_nochain.java
new file mode 100644
index 0000000..153e974
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_script_group2_nochain.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.ScriptGroup;
+import android.renderscript.Type;
+import android.util.Log;
+
+public class UT_script_group2_nochain extends UnitTest {
+ private static final int ARRAY_SIZE = 256;
+
+ private static final String TAG = "ScritGroup2 (nochain)";
+
+ public UT_script_group2_nochain(Context ctx) {
+ super(TAG, ctx);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_increment s_inc = new ScriptC_increment(pRS);
+ ScriptC_increment2 s_inc2 = new ScriptC_increment2(pRS);
+ ScriptC_double s_double = new ScriptC_double(pRS);
+ pRS.setMessageHandler(mRsMessage);
+
+ int[] array = new int[ARRAY_SIZE * 4];
+
+ for (int i = 0; i < ARRAY_SIZE * 4; i++) {
+ array[i] = i;
+ }
+
+ Allocation input = Allocation.createSized(pRS, Element.I32_4(pRS), ARRAY_SIZE);
+ input.copyFrom(array);
+
+ ScriptGroup.Builder2 builder = new ScriptGroup.Builder2(pRS);
+
+ ScriptGroup.Input unbound = builder.addInput();
+
+ Type T = Type.createX(pRS, Element.I32_4(pRS), ARRAY_SIZE);
+
+ ScriptGroup.Closure c0 =
+ builder.addKernel(s_inc.getKernelID_increment(),
+ T,
+ unbound);
+
+ ScriptGroup.Closure c1 =
+ builder.addKernel(s_inc2.getKernelID_increment2(),
+ T,
+ unbound,
+ new ScriptGroup.Binding(s_inc2.getFieldID_a(), unbound));
+
+ ScriptGroup.Closure c2 =
+ builder.addKernel(s_double.getKernelID_doubleKernel(),
+ T,
+ unbound);
+
+ ScriptGroup group = builder.create("AddDouble2", c2.getReturn());
+
+ int[] a = new int[ARRAY_SIZE * 4];
+ ((Allocation) group.execute(input)[0]).copyTo(a);
+
+ pRS.finish();
+ group.destroy();
+ T.destroy();
+ input.destroy();
+ s_inc.destroy();
+ s_inc2.destroy();
+ s_double.destroy();
+ pRS.destroy();
+
+ boolean failed = false;
+ for (int i = 0; i < ARRAY_SIZE * 4; i++) {
+ if (a[i] != (i + 1) * 2) {
+ Log.e(TAG, "a[" + i + "]=" + a[i] + ", should be " + ((i + 1) * 2));
+ failed = true;
+ }
+ }
+ if (failed) {
+ failTest();
+ return;
+ }
+ passTest();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_script_group2_pointwise.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_script_group2_pointwise.java
new file mode 100644
index 0000000..d22f29e
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_script_group2_pointwise.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.ScriptGroup;
+import android.renderscript.Type;
+import android.util.Log;
+
+public class UT_script_group2_pointwise extends UnitTest {
+ private static final int ARRAY_SIZE = 256;
+
+ private static final String TAG = "ScritGroup2 (Pointwise)";
+
+ public UT_script_group2_pointwise(Context ctx) {
+ super(TAG, ctx);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_increment s_inc = new ScriptC_increment(pRS);
+ ScriptC_double s_double = new ScriptC_double(pRS);
+ pRS.setMessageHandler(mRsMessage);
+
+ int[] array = new int[ARRAY_SIZE * 4];
+
+ for (int i = 0; i < ARRAY_SIZE * 4; i++) {
+ array[i] = i;
+ }
+
+ Allocation input = Allocation.createSized(pRS, Element.I32_4(pRS), ARRAY_SIZE);
+ input.copyFrom(array);
+
+ ScriptGroup.Builder2 builder = new ScriptGroup.Builder2(pRS);
+
+ ScriptGroup.Input unbound = builder.addInput();
+
+ Type T = Type.createX(pRS, Element.I32_4(pRS), ARRAY_SIZE);
+
+ ScriptGroup.Closure c0 =
+ builder.addKernel(s_inc.getKernelID_increment(),
+ T,
+ unbound);
+
+ ScriptGroup.Closure c1 =
+ builder.addKernel(s_double.getKernelID_doubleKernel(),
+ T,
+ c0.getReturn());
+
+ ScriptGroup group = builder.create("AddDouble", c1.getReturn());
+
+ int[] a = new int[ARRAY_SIZE * 4];
+ ((Allocation) group.execute(input)[0]).copyTo(a);
+
+ pRS.finish();
+ group.destroy();
+ T.destroy();
+ input.destroy();
+ s_double.destroy();
+ s_inc.destroy();
+ pRS.destroy();
+
+ boolean failed = false;
+ for (int i = 0; i < ARRAY_SIZE * 4; i++) {
+ if (a[i] != (i + 1) * 2) {
+ Log.e(TAG, "a[" + i + "]=" + a[i] + ", should be " + ((i + 1) * 2));
+ failed = true;
+ }
+ }
+ if (failed) {
+ failTest();
+ return;
+ }
+ passTest();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_single_source_alloc.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_single_source_alloc.java
new file mode 100644
index 0000000..efc7535
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_single_source_alloc.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript;
+
+public class UT_single_source_alloc extends UnitTest {
+ private int dimX = 3;
+ private int dimY = 4;
+ private int dimZ = 5;
+ private int start = 23;
+
+ // rs_data_type for float, double, char, short, int, long, uchar, ushort, uint, ulong in that
+ // order
+ private int rsDataTypes[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
+
+ public UT_single_source_alloc(Context ctx) {
+ super("SingleSourceAllocation", ctx);
+ }
+
+ private void initializeGlobals(RenderScript RS, ScriptC_single_source_alloc s, int nDims) {
+ s.set_gDimX(dimX);
+ s.set_gDimY(nDims > 1 ? dimY : 0);
+ s.set_gDimZ(nDims > 2 ? dimZ : 0);
+ s.set_gStart(start);
+
+ return;
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_single_source_alloc s = new ScriptC_single_source_alloc(pRS);
+ pRS.setMessageHandler(mRsMessage);
+
+ // Test 1-D, 2-D and 3-D Allocations of basic RenderScript types by creating Allocations and
+ // invoking a kernel on them.
+ for (int dataType : rsDataTypes) {
+ for (int vecSize = 1; vecSize <= 4; vecSize++) {
+ for (int nDims = 1; nDims <= 3; nDims++) {
+ initializeGlobals(pRS, s, nDims);
+ s.invoke_CreateAndTestAlloc(dataType, vecSize);
+ }
+ }
+ }
+
+ // Exhaustively test valid and invalid calls to rs_* creation functions. (These tests don't
+ // walk the created allocations, though.)
+ s.invoke_TestAllCases();
+
+ s.invoke_single_source_alloc_test();
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_single_source_ref_count.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_single_source_ref_count.java
new file mode 100644
index 0000000..cf67aa8
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_single_source_ref_count.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript;
+
+public class UT_single_source_ref_count extends UnitTest {
+
+ public UT_single_source_ref_count(Context ctx) {
+ super("SingleSourceRefCount", ctx);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_single_source_ref_count s = new ScriptC_single_source_ref_count(pRS);
+ pRS.setMessageHandler(mRsMessage);
+
+ s.invoke_entrypoint();
+
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_single_source_script.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_single_source_script.java
new file mode 100644
index 0000000..a5fc3d3
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_single_source_script.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.Type;
+
+public class UT_single_source_script extends UnitTest {
+ private Allocation testAllocation1, testAllocation2;
+
+ public UT_single_source_script(Context ctx) {
+ super("SingleSourceScript", ctx);
+ }
+
+ private void initializeGlobals(RenderScript RS, ScriptC_single_source_script s) {
+ Type.Builder i32TypeBuilder = new Type.Builder(RS, Element.I32(RS));
+ int X = 1024;
+ int Y = 768;
+ s.set_dimX(X);
+ s.set_dimY(Y);
+ i32TypeBuilder.setX(X).setY(Y);
+ testAllocation1 = Allocation.createTyped(RS, i32TypeBuilder.create());
+ testAllocation2 = Allocation.createTyped(RS, i32TypeBuilder.create());
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_single_source_script s = new ScriptC_single_source_script(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ initializeGlobals(pRS, s);
+
+ s.invoke_entrypoint(testAllocation1, testAllocation2);
+ s.forEach_oldFoo(testAllocation2, testAllocation2);
+ s.forEach_oldGoo(testAllocation2, testAllocation2);
+ s.invoke_validate(testAllocation2);
+
+ pRS.finish();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_small_struct.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_small_struct.java
new file mode 100644
index 0000000..62500dd
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_small_struct.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.RenderScript;
+import android.renderscript.Type;
+
+// Same as UT_small_struct_2.java except for names of classes and of test.
+
+public class UT_small_struct extends UnitTest {
+ private Allocation A;
+ private Allocation B;
+ private static final int dimX = 3;
+ private static final int dimY = 2;
+
+ public UT_small_struct(Context ctx) {
+ super("Small Structs", ctx);
+ }
+
+ private void initializeGlobals(RenderScript RS, ScriptC_small_struct s) {
+ s.set_gDimX(dimX);
+ s.set_gDimY(dimY);
+
+ Type.Builder builderA = new Type.Builder(RS, ScriptField_small_struct.createElement(RS));
+ builderA.setX(dimX);
+ builderA.setY(dimY);
+
+ A = Allocation.createTyped(RS, builderA.create());
+ s.set_A(A);
+
+ Type.Builder builderB = new Type.Builder(RS, ScriptField_struct_of_struct.createElement(RS));
+ builderB.setX(dimX);
+ builderB.setY(dimY);
+
+ B = Allocation.createTyped(RS, builderB.create());
+ s.set_B(B);
+ return;
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_small_struct s = new ScriptC_small_struct(pRS);
+ pRS.setMessageHandler(mRsMessage);
+
+ initializeGlobals(pRS, s);
+ s.forEach_setStruct(A);
+ s.forEach_setArrayOfStruct(B);
+ s.invoke_test();
+
+ pRS.finish();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_small_struct_2.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_small_struct_2.java
new file mode 100644
index 0000000..ca19aec
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_small_struct_2.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.RenderScript;
+import android.renderscript.Type;
+
+// Same as UT_small_struct.java except for names of classes and of test.
+
+public class UT_small_struct_2 extends UnitTest {
+ private Allocation A;
+ private Allocation B;
+ private static final int dimX = 3;
+ private static final int dimY = 2;
+
+ public UT_small_struct_2(Context ctx) {
+ super("Small Structs 2", ctx);
+ }
+
+ private void initializeGlobals(RenderScript RS, ScriptC_small_struct_2 s) {
+ s.set_gDimX(dimX);
+ s.set_gDimY(dimY);
+
+ Type.Builder builderA = new Type.Builder(RS, ScriptField_small_struct_2.createElement(RS));
+ builderA.setX(dimX);
+ builderA.setY(dimY);
+
+ A = Allocation.createTyped(RS, builderA.create());
+ s.set_A(A);
+
+ Type.Builder builderB = new Type.Builder(RS, ScriptField_struct_of_struct_2.createElement(RS));
+ builderB.setX(dimX);
+ builderB.setY(dimY);
+
+ B = Allocation.createTyped(RS, builderB.create());
+ s.set_B(B);
+ return;
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_small_struct_2 s = new ScriptC_small_struct_2(pRS);
+ pRS.setMessageHandler(mRsMessage);
+
+ initializeGlobals(pRS, s);
+ s.forEach_setStruct(A);
+ s.forEach_setArrayOfStruct(B);
+ s.invoke_test();
+
+ pRS.finish();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_static_globals.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_static_globals.java
new file mode 100644
index 0000000..d9653f2
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_static_globals.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.Type;
+
+public class UT_static_globals extends UnitTest {
+
+ public UT_static_globals(Context ctx) {
+ super("Static Globals", ctx);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_static_globals s = new ScriptC_static_globals(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ Type.Builder typeBuilder = new Type.Builder(pRS, Element.I32(pRS));
+ Type t = typeBuilder.setX(1).create();
+ Allocation A = Allocation.createTyped(pRS, t);
+ s.forEach_root(A);
+ s.invoke_static_globals_test();
+ pRS.finish();
+ A.destroy();
+ t.destroy();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_struct.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_struct.java
new file mode 100644
index 0000000..0cb87e1
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_struct.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript;
+
+public class UT_struct extends UnitTest {
+
+ public UT_struct(Context ctx) {
+ super("Struct", ctx);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_struct s = new ScriptC_struct(pRS);
+ pRS.setMessageHandler(mRsMessage);
+
+ ScriptField_Point2 p = new ScriptField_Point2(pRS, 1);
+ ScriptField_Point2.Item i = new ScriptField_Point2.Item();
+ int val = 100;
+ i.x = val;
+ i.y = val;
+ p.set(i, 0, true);
+ s.bind_point2(p);
+ s.invoke_struct_test(val);
+ pRS.finish();
+
+ val = 200;
+ p.set_x(0, val, true);
+ p.set_y(0, val, true);
+ s.invoke_struct_test(val);
+ pRS.finish();
+ p.getAllocation().destroy();
+ p.getElement().destroy();
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_struct_field.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_struct_field.java
new file mode 100644
index 0000000..72c82d2
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_struct_field.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript;
+import java.util.Random;
+
+public class UT_struct_field extends UnitTest {
+
+ Random r;
+
+ public UT_struct_field(Context ctx) {
+ super("Structure-typed Fields", ctx);
+ r = new Random(0);
+ }
+
+ private ScriptField_InnerOne.Item makeInnerOne() {
+ ScriptField_InnerOne.Item innerOne = new ScriptField_InnerOne.Item();
+ innerOne.x = r.nextInt();
+ innerOne.y = r.nextInt();
+ innerOne.f = r.nextFloat();
+ return innerOne;
+ }
+
+ private ScriptField_InnerTwo.Item makeInnerTwo() {
+ ScriptField_InnerTwo.Item innerTwo = new ScriptField_InnerTwo.Item();
+ innerTwo.z = (byte)r.nextInt();
+ innerTwo.innerOne = makeInnerOne();
+ return innerTwo;
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_struct_field s = new ScriptC_struct_field(pRS);
+ pRS.setMessageHandler(mRsMessage);
+
+ ScriptField_Outer.Item outer = new ScriptField_Outer.Item();
+ outer.innerOneA = makeInnerOne();
+ outer.l = r.nextLong();
+ outer.innerOneB = makeInnerOne();
+ for (int i = 0; i < 3; ++i)
+ outer.innerTwo3[i] = makeInnerTwo();
+ for (int i = 0; i < 2; ++i)
+ outer.innerTwo2[i] = makeInnerTwo();
+ for (int i = 0; i < 4; ++i)
+ outer.innerOne4[i] = makeInnerOne();
+ outer.innerOneC = makeInnerOne();
+ s.set_outer(outer);
+
+ s.invoke_checkOuter(
+ outer.innerOneA.x, outer.innerOneA.y, outer.innerOneA.f,
+ outer.l,
+ outer.innerOneB.x, outer.innerOneB.y, outer.innerOneB.f,
+ outer.innerTwo3[0].z,
+ outer.innerTwo3[0].innerOne.x, outer.innerTwo3[0].innerOne.y, outer.innerTwo3[0].innerOne.f,
+ outer.innerTwo3[1].z,
+ outer.innerTwo3[1].innerOne.x, outer.innerTwo3[1].innerOne.y, outer.innerTwo3[1].innerOne.f,
+ outer.innerTwo3[2].z,
+ outer.innerTwo3[2].innerOne.x, outer.innerTwo3[2].innerOne.y, outer.innerTwo3[2].innerOne.f,
+ outer.innerTwo2[0].z,
+ outer.innerTwo2[0].innerOne.x, outer.innerTwo2[0].innerOne.y, outer.innerTwo2[0].innerOne.f,
+ outer.innerTwo2[1].z,
+ outer.innerTwo2[1].innerOne.x, outer.innerTwo2[1].innerOne.y, outer.innerTwo2[1].innerOne.f,
+ outer.innerOne4[0].x, outer.innerOne4[0].y, outer.innerOne4[0].f,
+ outer.innerOne4[1].x, outer.innerOne4[1].y, outer.innerOne4[1].f,
+ outer.innerOne4[2].x, outer.innerOne4[2].y, outer.innerOne4[2].f,
+ outer.innerOne4[3].x, outer.innerOne4[3].y, outer.innerOne4[3].f,
+ outer.innerOneC.x, outer.innerOneC.y, outer.innerOneC.f);
+
+ pRS.finish();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_struct_field_simple.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_struct_field_simple.java
new file mode 100644
index 0000000..04aab65
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_struct_field_simple.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript;
+
+public class UT_struct_field_simple extends UnitTest {
+
+ public UT_struct_field_simple(Context ctx) {
+ super("Structure Fields", ctx);
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_struct_field_simple s = new ScriptC_struct_field_simple(pRS);
+ pRS.setMessageHandler(mRsMessage);
+
+ ScriptField_Simple.Item simple = new ScriptField_Simple.Item();
+ final int I = 0x12345678;
+ final long L = 0x76543210fedcba98L;
+ simple.I = I;
+ simple.L = L;
+ s.set_simple(simple);
+
+ s.invoke_checkSimple(I, L);
+
+ pRS.finish();
+ pRS.destroy();
+ }
+}
+
+// struct Simple {
+// int I;
+// long L;
+// };
+//
+// Consistently padded, we expect:
+// I = 0x12345678
+// L.lo = 0xfedcba98
+// L.hi = 0x76543210
+//
+// And indeed on N9 --abi armeabi-v7a (i.e., ARM-32) we see:
+//
+// 09-23 21:55:51.026 5990 6005 D RenderScript: argI 305419896 0x12345678
+// 09-23 21:55:51.026 5990 6005 D RenderScript: simple.I 305419896 0x12345678
+// 09-23 21:55:51.026 5990 6005 D RenderScript: argL.lo 4275878552 0xfedcba98
+// 09-23 21:55:51.026 5990 6005 D RenderScript: simple.L.lo 4275878552 0xfedcba98
+// 09-23 21:55:51.026 5990 6005 D RenderScript: argL.hi 1985229328 0x76543210
+// 09-23 21:55:51.026 5990 6005 D RenderScript: simple.L.hi 1985229328 0x76543210
+// 09-23 21:55:51.026 5990 6005 D RenderScript: struct_field_simple PASSED 0 0x0
+//
+// Inconsistently padded (Java pads, x86-32 script does not), we expect:
+// I = 0x12345678 // fine
+// L.lo = 0 // oops, script read the padding
+// L.hi = 0xfedcba98 // oops, script read L.lo
+//
+// And indeed on fugu (i.e., x86-32) before the fix for http://b/29154200 and http://b/28070272
+// we see:
+//
+// 09-23 21:39:19.775 4090 4107 D RenderScript: argI 305419896 0x12345678
+// 09-23 21:39:19.775 4090 4107 D RenderScript: simple.I 305419896 0x12345678
+// 09-23 21:39:19.775 4090 4107 D RenderScript: argL.lo 4275878552 0xfedcba98
+// 09-23 21:39:19.775 4090 4107 D RenderScript: simple.L.lo 0 0x0
+// 09-23 21:39:19.775 4090 4107 D RenderScript: argL.hi 1985229328 0x76543210
+// 09-23 21:39:19.775 4090 4107 D RenderScript: simple.L.hi 4275878552 0xfedcba98
+// 09-23 21:39:19.775 4090 4107 D RenderScript: simple.L == argL FAILED 0 0x0
+// 09-23 21:39:19.775 4090 4107 D RenderScript: struct_field_simple FAILED 0 0x0
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_unsigned.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_unsigned.java
new file mode 100644
index 0000000..3a4f8a2
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_unsigned.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript;
+
+public class UT_unsigned extends UnitTest {
+
+ public UT_unsigned(Context ctx) {
+ super("Unsigned", ctx);
+ }
+
+ private boolean initializeGlobals(ScriptC_unsigned s) {
+ short pUC = s.get_uc();
+ if (pUC != 5) {
+ return false;
+ }
+ s.set_uc((short) 129);
+
+ long pUI = s.get_ui();
+ if (pUI != 37) {
+ return false;
+ }
+ s.set_ui(0x7fffffff);
+
+ return true;
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_unsigned s = new ScriptC_unsigned(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ if (!initializeGlobals(s)) {
+ failTest();
+ } else {
+ s.invoke_unsigned_test();
+ pRS.finish();
+ }
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_vector.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_vector.java
new file mode 100644
index 0000000..e337212
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UT_vector.java
@@ -0,0 +1,333 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.Byte2;
+import android.renderscript.Byte3;
+import android.renderscript.Byte4;
+import android.renderscript.Double2;
+import android.renderscript.Double3;
+import android.renderscript.Double4;
+import android.renderscript.Float2;
+import android.renderscript.Float3;
+import android.renderscript.Float4;
+import android.renderscript.Int2;
+import android.renderscript.Int3;
+import android.renderscript.Int4;
+import android.renderscript.Long2;
+import android.renderscript.Long3;
+import android.renderscript.Long4;
+import android.renderscript.RenderScript;
+import android.renderscript.Short2;
+import android.renderscript.Short3;
+import android.renderscript.Short4;
+
+public class UT_vector extends UnitTest {
+
+ public UT_vector(Context ctx) {
+ super("Vector", ctx);
+ }
+
+ private boolean initializeGlobals(ScriptC_vector s) {
+ Float2 F2 = s.get_f2();
+ if (F2.x != 1.0f || F2.y != 2.0f) {
+ return false;
+ }
+ F2.x = 2.99f;
+ F2.y = 3.99f;
+ s.set_f2(F2);
+
+ Float3 F3 = s.get_f3();
+ if (F3.x != 1.0f || F3.y != 2.0f || F3.z != 3.0f) {
+ return false;
+ }
+ F3.x = 2.99f;
+ F3.y = 3.99f;
+ F3.z = 4.99f;
+ s.set_f3(F3);
+
+ Float4 F4 = s.get_f4();
+ if (F4.x != 1.0f || F4.y != 2.0f || F4.z != 3.0f || F4.w != 4.0f) {
+ return false;
+ }
+ F4.x = 2.99f;
+ F4.y = 3.99f;
+ F4.z = 4.99f;
+ F4.w = 5.99f;
+ s.set_f4(F4);
+
+ Double2 D2 = s.get_d2();
+ if (D2.x != 1.0 || D2.y != 2.0) {
+ return false;
+ }
+ D2.x = 2.99;
+ D2.y = 3.99;
+ s.set_d2(D2);
+
+ Double3 D3 = s.get_d3();
+ if (D3.x != 1.0 || D3.y != 2.0 || D3.z != 3.0) {
+ return false;
+ }
+ D3.x = 2.99;
+ D3.y = 3.99;
+ D3.z = 4.99;
+ s.set_d3(D3);
+
+ Double4 D4 = s.get_d4();
+ if (D4.x != 1.0 || D4.y != 2.0 || D4.z != 3.0 || D4.w != 4.0) {
+ return false;
+ }
+ D4.x = 2.99;
+ D4.y = 3.99;
+ D4.z = 4.99;
+ D4.w = 5.99;
+ s.set_d4(D4);
+
+ Byte2 B2 = s.get_i8_2();
+ if (B2.x != 1 || B2.y != 2) {
+ return false;
+ }
+ B2.x = 2;
+ B2.y = 3;
+ s.set_i8_2(B2);
+
+ Byte3 B3 = s.get_i8_3();
+ if (B3.x != 1 || B3.y != 2 || B3.z != 3) {
+ return false;
+ }
+ B3.x = 2;
+ B3.y = 3;
+ B3.z = 4;
+ s.set_i8_3(B3);
+
+ Byte4 B4 = s.get_i8_4();
+ if (B4.x != 1 || B4.y != 2 || B4.z != 3 || B4.w != 4) {
+ return false;
+ }
+ B4.x = 2;
+ B4.y = 3;
+ B4.z = 4;
+ B4.w = 5;
+ s.set_i8_4(B4);
+
+ Short2 S2 = s.get_u8_2();
+ if (S2.x != 1 || S2.y != 2) {
+ return false;
+ }
+ S2.x = 2;
+ S2.y = 3;
+ s.set_u8_2(S2);
+
+ Short3 S3 = s.get_u8_3();
+ if (S3.x != 1 || S3.y != 2 || S3.z != 3) {
+ return false;
+ }
+ S3.x = 2;
+ S3.y = 3;
+ S3.z = 4;
+ s.set_u8_3(S3);
+
+ Short4 S4 = s.get_u8_4();
+ if (S4.x != 1 || S4.y != 2 || S4.z != 3 || S4.w != 4) {
+ return false;
+ }
+ S4.x = 2;
+ S4.y = 3;
+ S4.z = 4;
+ S4.w = 5;
+ s.set_u8_4(S4);
+
+ S2 = s.get_i16_2();
+ if (S2.x != 1 || S2.y != 2) {
+ return false;
+ }
+ S2.x = 2;
+ S2.y = 3;
+ s.set_i16_2(S2);
+
+ S3 = s.get_i16_3();
+ if (S3.x != 1 || S3.y != 2 || S3.z != 3) {
+ return false;
+ }
+ S3.x = 2;
+ S3.y = 3;
+ S3.z = 4;
+ s.set_i16_3(S3);
+
+ S4 = s.get_i16_4();
+ if (S4.x != 1 || S4.y != 2 || S4.z != 3 || S4.w != 4) {
+ return false;
+ }
+ S4.x = 2;
+ S4.y = 3;
+ S4.z = 4;
+ S4.w = 5;
+ s.set_i16_4(S4);
+
+ Int2 I2 = s.get_u16_2();
+ if (I2.x != 1 || I2.y != 2) {
+ return false;
+ }
+ I2.x = 2;
+ I2.y = 3;
+ s.set_u16_2(I2);
+
+ Int3 I3 = s.get_u16_3();
+ if (I3.x != 1 || I3.y != 2 || I3.z != 3) {
+ return false;
+ }
+ I3.x = 2;
+ I3.y = 3;
+ I3.z = 4;
+ s.set_u16_3(I3);
+
+ Int4 I4 = s.get_u16_4();
+ if (I4.x != 1 || I4.y != 2 || I4.z != 3 || I4.w != 4) {
+ return false;
+ }
+ I4.x = 2;
+ I4.y = 3;
+ I4.z = 4;
+ I4.w = 5;
+ s.set_u16_4(I4);
+
+ I2 = s.get_i32_2();
+ if (I2.x != 1 || I2.y != 2) {
+ return false;
+ }
+ I2.x = 2;
+ I2.y = 3;
+ s.set_i32_2(I2);
+
+ I3 = s.get_i32_3();
+ if (I3.x != 1 || I3.y != 2 || I3.z != 3) {
+ return false;
+ }
+ I3.x = 2;
+ I3.y = 3;
+ I3.z = 4;
+ s.set_i32_3(I3);
+
+ I4 = s.get_i32_4();
+ if (I4.x != 1 || I4.y != 2 || I4.z != 3 || I4.w != 4) {
+ return false;
+ }
+ I4.x = 2;
+ I4.y = 3;
+ I4.z = 4;
+ I4.w = 5;
+ s.set_i32_4(I4);
+
+ Long2 L2 = s.get_u32_2();
+ if (L2.x != 1 || L2.y != 2) {
+ return false;
+ }
+ L2.x = 2;
+ L2.y = 3;
+ s.set_u32_2(L2);
+
+ Long3 L3 = s.get_u32_3();
+ if (L3.x != 1 || L3.y != 2 || L3.z != 3) {
+ return false;
+ }
+ L3.x = 2;
+ L3.y = 3;
+ L3.z = 4;
+ s.set_u32_3(L3);
+
+ Long4 L4 = s.get_u32_4();
+ if (L4.x != 1 || L4.y != 2 || L4.z != 3 || L4.w != 4) {
+ return false;
+ }
+ L4.x = 2;
+ L4.y = 3;
+ L4.z = 4;
+ L4.w = 5;
+ s.set_u32_4(L4);
+
+ L2 = s.get_i64_2();
+ if (L2.x != 1 || L2.y != 2) {
+ return false;
+ }
+ L2.x = 2;
+ L2.y = 3;
+ s.set_i64_2(L2);
+
+ L3 = s.get_i64_3();
+ if (L3.x != 1 || L3.y != 2 || L3.z != 3) {
+ return false;
+ }
+ L3.x = 2;
+ L3.y = 3;
+ L3.z = 4;
+ s.set_i64_3(L3);
+
+ L4 = s.get_i64_4();
+ if (L4.x != 1 || L4.y != 2 || L4.z != 3 || L4.w != 4) {
+ return false;
+ }
+ L4.x = 2;
+ L4.y = 3;
+ L4.z = 4;
+ L4.w = 5;
+ s.set_i64_4(L4);
+
+ L2 = s.get_u64_2();
+ if (L2.x != 1 || L2.y != 2) {
+ return false;
+ }
+ L2.x = 2;
+ L2.y = 3;
+ s.set_u64_2(L2);
+
+ L3 = s.get_u64_3();
+ if (L3.x != 1 || L3.y != 2 || L3.z != 3) {
+ return false;
+ }
+ L3.x = 2;
+ L3.y = 3;
+ L3.z = 4;
+ s.set_u64_3(L3);
+
+ L4 = s.get_u64_4();
+ if (L4.x != 1 || L4.y != 2 || L4.z != 3 || L4.w != 4) {
+ return false;
+ }
+ L4.x = 2;
+ L4.y = 3;
+ L4.z = 4;
+ L4.w = 5;
+ s.set_u64_4(L4);
+
+ return true;
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_vector s = new ScriptC_vector(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ if (!initializeGlobals(s)) {
+ failTest();
+ } else {
+ s.invoke_vector_test();
+ pRS.finish();
+ }
+ s.destroy();
+ pRS.destroy();
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UnitTest.java b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UnitTest.java
new file mode 100644
index 0000000..397d43b
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/UnitTest.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2017 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 com.android.rs.unittest;
+
+import android.content.Context;
+import android.renderscript.RenderScript.RSMessageHandler;
+import android.util.Log;
+
+public abstract class UnitTest {
+ public enum UnitTestResult {
+ UT_NOT_STARTED,
+ UT_RUNNING,
+ UT_SUCCESS,
+ UT_FAIL,
+ }
+
+ private final static String TAG = "RSUnitTest";
+
+ public String name;
+ private UnitTestResult result;
+ protected Context mCtx;
+
+ /* These constants must match those in shared.rsh */
+ public static final int RS_MSG_TEST_PASSED = 100;
+ public static final int RS_MSG_TEST_FAILED = 101;
+
+ public UnitTest(String n, Context ctx) {
+ name = n;
+ mCtx = ctx;
+ result = UnitTestResult.UT_NOT_STARTED;
+ }
+
+ protected void _RS_ASSERT(String message, boolean b) {
+ if (!b) {
+ Log.e(TAG, message + " FAILED");
+ failTest();
+ }
+ }
+
+ protected RSMessageHandler mRsMessage =
+ new RSMessageHandler() {
+ public void run() {
+ if (result == UnitTestResult.UT_RUNNING) {
+ switch (mID) {
+ case RS_MSG_TEST_PASSED:
+ result = UnitTestResult.UT_SUCCESS;
+ break;
+ case RS_MSG_TEST_FAILED:
+ result = UnitTestResult.UT_FAIL;
+ break;
+ default:
+ Log.v(TAG, "Unit test got unexpected message");
+ break;
+ }
+ }
+ }
+ };
+
+ protected void failTest() {
+ result = UnitTestResult.UT_FAIL;
+ }
+
+ protected void passTest() {
+ if (result != UnitTestResult.UT_FAIL) {
+ result = UnitTestResult.UT_SUCCESS;
+ }
+ }
+
+ public String toString() {
+ String out = name;
+ if (result == UnitTestResult.UT_SUCCESS) {
+ out += " - PASSED";
+ } else if (result == UnitTestResult.UT_FAIL) {
+ out += " - FAILED";
+ }
+ return out;
+ }
+
+ public UnitTestResult getResult() {
+ return result;
+ }
+
+ public boolean getSuccess() {
+ return result == UnitTestResult.UT_SUCCESS;
+ }
+
+ public void runTest() {
+ result = UnitTestResult.UT_RUNNING;
+ run();
+ }
+
+ abstract protected void run();
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/addup.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/addup.rs
new file mode 100644
index 0000000..5d69ce5
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/addup.rs
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#pragma version(1)
+#pragma rs java_package_name(com.android.rs.unittest)
+
+rs_allocation a_in;
+int reduction_stride;
+
+int4 RS_KERNEL add(uint x)
+{
+ return rsGetElementAt_int4(a_in, x) + rsGetElementAt_int4(a_in, x + reduction_stride);
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/alloc.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/alloc.rs
new file mode 100644
index 0000000..bf271d5
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/alloc.rs
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+int *a;
+int dimX;
+int dimY;
+int dimZ;
+
+rs_allocation aRaw;
+rs_allocation aFaces;
+rs_allocation aLOD;
+rs_allocation aFacesLOD;
+
+void root(int *o, uint32_t x) {
+ *o = x;
+}
+
+static bool test_alloc_dims() {
+ bool failed = false;
+ int i;
+
+ _RS_ASSERT(rsAllocationGetDimX(aRaw) == dimX);
+ // Since we are binding with our A allocation, it has 0 Y/Z dimensions.
+ _RS_ASSERT(rsAllocationGetDimY(aRaw) == 0);
+ _RS_ASSERT(rsAllocationGetDimZ(aRaw) == 0);
+
+ // Test 1D addressing
+ for (i = 0; i < dimX; i++) {
+ rsDebug("Verifying ", i);
+ const void *p = rsGetElementAt(aRaw, i);
+ int val = *(const int *)p;
+ _RS_ASSERT(val == i);
+ }
+
+ _RS_ASSERT(rsAllocationGetDimX(aFaces) == dimX);
+ _RS_ASSERT(rsAllocationGetDimY(aFaces) == dimY);
+ _RS_ASSERT(rsAllocationGetDimZ(aFaces) == dimZ);
+ _RS_ASSERT(rsAllocationGetDimFaces(aFaces) != 0);
+ _RS_ASSERT(rsAllocationGetDimLOD(aFaces) == 0);
+
+ _RS_ASSERT(rsAllocationGetDimX(aLOD) == dimX);
+ _RS_ASSERT(rsAllocationGetDimY(aLOD) == dimY);
+ _RS_ASSERT(rsAllocationGetDimZ(aLOD) == dimZ);
+ _RS_ASSERT(rsAllocationGetDimFaces(aLOD) == 0);
+ _RS_ASSERT(rsAllocationGetDimLOD(aLOD) != 0);
+
+ _RS_ASSERT(rsAllocationGetDimX(aFacesLOD) == dimX);
+ _RS_ASSERT(rsAllocationGetDimY(aFacesLOD) == dimY);
+ _RS_ASSERT(rsAllocationGetDimZ(aFacesLOD) == dimZ);
+ _RS_ASSERT(rsAllocationGetDimFaces(aFacesLOD) != 0);
+ _RS_ASSERT(rsAllocationGetDimLOD(aFacesLOD) != 0);
+
+ if (failed) {
+ rsDebug("test_alloc_dims FAILED", 0);
+ }
+ else {
+ rsDebug("test_alloc_dims PASSED", 0);
+ }
+
+ return failed;
+}
+
+void alloc_test() {
+ bool failed = false;
+ failed |= test_alloc_dims();
+
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/array_alloc.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/array_alloc.rs
new file mode 100644
index 0000000..79ede39
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/array_alloc.rs
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+const int dimX = 20;
+rs_allocation a[dimX];
+
+void array_alloc_test() {
+ bool failed = false;
+
+ for (int i = 0; i < dimX; i++) {
+ rsDebug("i: ", i);
+ _RS_ASSERT(rsAllocationGetDimX(a[i]) == 1);
+ }
+
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/array_init.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/array_init.rs
new file mode 100644
index 0000000..03e2787
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/array_init.rs
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+// Testing constant array initialization
+float fa[4] = {1.0, 9.9999f};
+double da[2] = {7.0, 8.88888};
+char ca[4] = {'a', 7, 'b', 'c'};
+short sa[4] = {1, 1, 2, 3};
+int ia[4] = {5, 8};
+long la[2] = {13, 21};
+long long lla[4] = {34};
+bool ba[3] = {true, false};
+
+void array_init_test() {
+ bool failed = false;
+
+ _RS_ASSERT(fa[0] == 1.0);
+ _RS_ASSERT(fa[1] == 9.9999f);
+ _RS_ASSERT(fa[2] == 0);
+ _RS_ASSERT(fa[3] == 0);
+
+ _RS_ASSERT(da[0] == 7.0);
+ _RS_ASSERT(da[1] == 8.88888);
+
+ _RS_ASSERT(ca[0] == 'a');
+ _RS_ASSERT(ca[1] == 7);
+ _RS_ASSERT(ca[2] == 'b');
+ _RS_ASSERT(ca[3] == 'c');
+
+ _RS_ASSERT(sa[0] == 1);
+ _RS_ASSERT(sa[1] == 1);
+ _RS_ASSERT(sa[2] == 2);
+ _RS_ASSERT(sa[3] == 3);
+
+ _RS_ASSERT(ia[0] == 5);
+ _RS_ASSERT(ia[1] == 8);
+ _RS_ASSERT(ia[2] == 0);
+ _RS_ASSERT(ia[3] == 0);
+
+ _RS_ASSERT(la[0] == 13);
+ _RS_ASSERT(la[1] == 21);
+
+ _RS_ASSERT(lla[0] == 34);
+ _RS_ASSERT(lla[1] == 0);
+ _RS_ASSERT(lla[2] == 0);
+ _RS_ASSERT(lla[3] == 0);
+
+ _RS_ASSERT(ba[0] == true);
+ _RS_ASSERT(ba[1] == false);
+ _RS_ASSERT(ba[2] == false);
+
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/atomic.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/atomic.rs
new file mode 100644
index 0000000..b81669d
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/atomic.rs
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+// Testing atomic operations
+static bool testUMax(uint32_t dst, uint32_t src) {
+ bool failed = false;
+ uint32_t old = dst;
+ uint32_t expect = (dst > src ? dst : src);
+ uint32_t ret = rsAtomicMax(&dst, src);
+ _RS_ASSERT(old == ret);
+ _RS_ASSERT(dst == expect);
+ return failed;
+}
+
+static bool testUMin(uint32_t dst, uint32_t src) {
+ bool failed = false;
+ uint32_t old = dst;
+ uint32_t expect = (dst < src ? dst : src);
+ uint32_t ret = rsAtomicMin(&dst, src);
+ _RS_ASSERT(old == ret);
+ _RS_ASSERT(dst == expect);
+ return failed;
+}
+
+static bool testUCas(uint32_t dst, uint32_t cmp, uint32_t swp) {
+ bool failed = false;
+ uint32_t old = dst;
+ uint32_t expect = (dst == cmp ? swp : dst);
+ uint32_t ret = rsAtomicCas(&dst, cmp, swp);
+ _RS_ASSERT(old == ret);
+ _RS_ASSERT(dst == expect);
+ return failed;
+}
+
+static bool test_atomics() {
+ bool failed = false;
+
+ failed |= testUMax(5, 6);
+ failed |= testUMax(6, 5);
+ failed |= testUMax(5, 0xf0000006);
+ failed |= testUMax(0xf0000006, 5);
+
+ failed |= testUMin(5, 6);
+ failed |= testUMin(6, 5);
+ failed |= testUMin(5, 0xf0000006);
+ failed |= testUMin(0xf0000006, 5);
+
+ failed |= testUCas(4, 4, 5);
+ failed |= testUCas(4, 5, 5);
+ failed |= testUCas(5, 5, 4);
+ failed |= testUCas(5, 4, 4);
+ failed |= testUCas(0xf0000004, 0xf0000004, 0xf0000005);
+ failed |= testUCas(0xf0000004, 0xf0000005, 0xf0000005);
+ failed |= testUCas(0xf0000005, 0xf0000005, 0xf0000004);
+ failed |= testUCas(0xf0000005, 0xf0000004, 0xf0000004);
+
+ if (failed) {
+ rsDebug("test_atomics FAILED", 0);
+ }
+ else {
+ rsDebug("test_atomics PASSED", 0);
+ }
+
+ return failed;
+}
+
+void atomic_test() {
+ bool failed = false;
+ failed |= test_atomics();
+
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/bitfield.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/bitfield.rs
new file mode 100644
index 0000000..fe22138
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/bitfield.rs
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+// There is a C99 rule (under "Structure and union members") that
+// reads "One special guarantee is made in order to simplify the use
+// of unions: if a union contains several structures that share a
+// common initial sequence, and if the union object currently contains
+// one of these structures, it is permitted to inspect the common
+// initial part of any of them anywhere that a declaration of the
+// completed type of the union is visible. Two structures share a
+// common initial sequence if corresponding members have compatible
+// types (and, for bit-fields, the same widths) for a sequence of one
+// or more initial members."
+//
+// We want to ensure that the common initial sequences of exported
+// and non-exported types have the same layout.
+
+// An exported type (because we declare a global variable of this type)
+struct NoBitfield {
+ int I;
+ // expect 4 bytes of padding here
+ long L;
+ float F;
+ // expect 4 bytes of padding here
+};
+
+struct NoBitfield junk; // just to make this an exported type
+
+// A non-exported type that shares a common initial sequence with NoBitfield
+struct Bitfield {
+ int I;
+ // expect 4 bytes of padding here
+ long L;
+ uint U:3;
+};
+
+union CommonInitialSequence {
+ struct NoBitfield nbf;
+ struct Bitfield bf;
+};
+
+static union CommonInitialSequence U, V;
+
+static struct NoBitfield *nbf;
+static struct Bitfield * bf;
+
+// Note: Sets through the exported type (NoBitfield)
+void setUnion(long argL, int argI) {
+ nbf->L = argL;
+ nbf->I = argI;
+}
+
+// Note: Tests through the non-exported type (Bitfield)
+void testUnion(long argL, int argI) {
+ bool failed = false;
+
+ rsDebug("argI ", argI);
+ rsDebug("bf->I ", bf->I);
+ rsDebug("argL.lo ", (unsigned)argL & ~0U);
+ rsDebug("bf->L.lo", (unsigned)bf->L & ~0U);
+ rsDebug("argL.hi ", (unsigned)((ulong)argL >> 32));
+ rsDebug("bf->L.hi", (unsigned)((ulong)bf->L >> 32));
+
+ _RS_ASSERT(bf->I == argI);
+ _RS_ASSERT(bf->L == argL);
+
+ if (failed) {
+ rsDebug("bitfield FAILED", 0);
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsDebug("bitfield PASSED", 0);
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
+// Note: Prevent compiler from optimizing setUnion()/testUnion()
+// to convert indirect accesses through nbf/bf into direct
+// accesses through U or V.
+void choose(int i) {
+ if (i) {
+ nbf = &U.nbf;
+ bf = &U. bf;
+ } else {
+ nbf = &V.nbf;
+ bf = &V. bf;
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/bug_char.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/bug_char.rs
new file mode 100644
index 0000000..8e11d89
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/bug_char.rs
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+char rand_sc1_0, rand_sc1_1;
+char2 rand_sc2_0, rand_sc2_1;
+
+char min_rand_sc1_sc1;
+char2 min_rand_sc2_sc2;
+
+static bool test_bug_char() {
+ bool failed = false;
+
+ rsDebug("rand_sc2_0.x: ", rand_sc2_0.x);
+ rsDebug("rand_sc2_0.y: ", rand_sc2_0.y);
+ rsDebug("rand_sc2_1.x: ", rand_sc2_1.x);
+ rsDebug("rand_sc2_1.y: ", rand_sc2_1.y);
+ char temp_sc1;
+ char2 temp_sc2;
+
+ temp_sc1 = min( rand_sc1_0, rand_sc1_1 );
+ if (temp_sc1 != min_rand_sc1_sc1) {
+ rsDebug("temp_sc1", temp_sc1);
+ failed = true;
+ }
+ rsDebug("broken", 'y');
+
+ temp_sc2 = min( rand_sc2_0, rand_sc2_1 );
+ if (temp_sc2.x != min_rand_sc2_sc2.x
+ || temp_sc2.y != min_rand_sc2_sc2.y) {
+ failed = true;
+ }
+
+
+ return failed;
+}
+
+void bug_char_test() {
+ bool failed = false;
+ failed |= test_bug_char();
+
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/check_dims.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/check_dims.rs
new file mode 100644
index 0000000..57c14b2
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/check_dims.rs
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+int pattern;
+
+rs_allocation aFailed;
+
+// This test checks to see that we only work on the cells specified for the
+// input allocation (i.e. don't affect anything between dimX and stride for
+// each row). If we don't see the pattern that we wrote, we know that we
+// are definitely working outside our proper bounds.
+void root(const int *o, uint32_t x, uint32_t y) {
+ if (*o != pattern) {
+ rsSetElementAt_uchar(aFailed, 1, 0);
+ }
+}
+
+void check_dims_test() {
+ bool failed = rsGetElementAt_uchar(aFailed, 0);
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/clamp.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/clamp.rs
new file mode 100644
index 0000000..6de80c9
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/clamp.rs
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+static bool test_clamp_vector() {
+ bool failed = false;
+
+ float2 src2 = { 2.0f, 2.0f};
+ float2 min2 = { 0.5f, -3.0f};
+ float2 max2 = { 1.0f, 9.0f};
+
+ float2 res2 = clamp(src2, min2, max2);
+ _RS_ASSERT(res2.x == 1.0f);
+ _RS_ASSERT(res2.y == 2.0f);
+
+
+ float3 src3 = { 2.0f, 2.0f, 1.0f};
+ float3 min3 = { 0.5f, -3.0f, 3.0f};
+ float3 max3 = { 1.0f, 9.0f, 4.0f};
+
+ float3 res3 = clamp(src3, min3, max3);
+ _RS_ASSERT(res3.x == 1.0f);
+ _RS_ASSERT(res3.y == 2.0f);
+ _RS_ASSERT(res3.z == 3.0f);
+
+
+ float4 src4 = { 2.0f, 2.0f, 1.0f, 4.0f };
+ float4 min4 = { 0.5f, -3.0f, 3.0f, 4.0f };
+ float4 max4 = { 1.0f, 9.0f, 4.0f, 4.0f };
+
+ float4 res4 = clamp(src4, min4, max4);
+ _RS_ASSERT(res4.x == 1.0f);
+ _RS_ASSERT(res4.y == 2.0f);
+ _RS_ASSERT(res4.z == 3.0f);
+ _RS_ASSERT(res4.w == 4.0f);
+
+ if (failed) {
+ rsDebug("test_clamp_vector FAILED", 0);
+ }
+ else {
+ rsDebug("test_clamp_vector PASSED", 0);
+ }
+
+ return failed;
+}
+
+void clamp_test() {
+ bool failed = false;
+ failed |= test_clamp_vector();
+
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/clamp_relaxed.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/clamp_relaxed.rs
new file mode 100644
index 0000000..9cc597f
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/clamp_relaxed.rs
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "clamp.rs"
+#pragma rs_fp_relaxed
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/constant.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/constant.rs
new file mode 100644
index 0000000..aad61e9
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/constant.rs
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+const float floatTest = 1.99f;
+const double doubleTest = 2.05;
+const char charTest = -8;
+const short shortTest = -16;
+const int intTest = -32;
+const long longTest = 17179869184l; // 1 << 34
+const long long longlongTest = 68719476736l; // 1 << 36
+
+const uchar ucharTest = 8;
+const ushort ushortTest = 16;
+const uint uintTest = 32;
+const ulong ulongTest = 4611686018427387904L;
+const int64_t int64_tTest = -17179869184l; // - 1 << 34
+const uint64_t uint64_tTest = 117179869184l;
+
+const bool boolTest = true;
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/convert.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/convert.rs
new file mode 100644
index 0000000..a9eb16d
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/convert.rs
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+float4 f4 = { 2.0f, 4.0f, 6.0f, 8.0f };
+
+char4 i8_4 = { -1, -2, -3, 4 };
+
+static bool test_convert() {
+ bool failed = false;
+
+ f4 = convert_float4(i8_4);
+ _RS_ASSERT(f4.x == -1.0f);
+ _RS_ASSERT(f4.y == -2.0f);
+ _RS_ASSERT(f4.z == -3.0f);
+ _RS_ASSERT(f4.w == 4.0f);
+
+ if (failed) {
+ rsDebug("test_convert FAILED", 0);
+ }
+ else {
+ rsDebug("test_convert PASSED", 0);
+ }
+
+ return failed;
+}
+
+void convert_test() {
+ bool failed = false;
+ failed |= test_convert();
+
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/convert_relaxed.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/convert_relaxed.rs
new file mode 100644
index 0000000..93fd7cb
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/convert_relaxed.rs
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "convert.rs"
+#pragma rs_fp_relaxed
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/copy_test.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/copy_test.rs
new file mode 100644
index 0000000..34fd01b
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/copy_test.rs
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+void sendResult(bool pass) {
+ if (pass) {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+}
+
+
+float2 __attribute((kernel)) copyFloat2(float2 i) {
+ return i;
+}
+
+float3 __attribute((kernel)) copyFloat3(float3 i) {
+ return i;
+}
+
+float4 __attribute((kernel)) copyFloat4(float4 i) {
+ return i;
+}
+
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/ctxt_default.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/ctxt_default.rs
new file mode 100644
index 0000000..cae6fb7
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/ctxt_default.rs
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+rs_allocation A;
+rs_allocation B;
+uint32_t gDimX;
+static bool failed = false;
+
+void init_vars(int *out) {
+ *out = 7;
+}
+
+int RS_KERNEL root(int ain, rs_kernel_context context, uint32_t x) {
+ _RS_ASSERT_EQU(rsGetArray0(context), 0);
+ _RS_ASSERT_EQU(rsGetArray1(context), 0);
+ _RS_ASSERT_EQU(rsGetArray2(context), 0);
+ _RS_ASSERT_EQU(rsGetArray3(context), 0);
+ _RS_ASSERT_EQU(rsGetFace(context), RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X);
+ _RS_ASSERT_EQU(rsGetLod(context), 0);
+
+ _RS_ASSERT_EQU(rsGetDimY(context), 0);
+ _RS_ASSERT_EQU(rsGetDimZ(context), 0);
+ _RS_ASSERT_EQU(rsGetDimArray0(context), 0);
+ _RS_ASSERT_EQU(rsGetDimArray1(context), 0);
+ _RS_ASSERT_EQU(rsGetDimArray2(context), 0);
+ _RS_ASSERT_EQU(rsGetDimArray3(context), 0);
+ _RS_ASSERT_EQU(rsGetDimHasFaces(context), false);
+ _RS_ASSERT_EQU(rsGetDimLod(context), 0);
+
+ if (!_RS_ASSERT_EQU(ain, 7))
+ rsDebug("root at x", x);
+ uint32_t dimX = rsGetDimX(context);
+ _RS_ASSERT_EQU(dimX, gDimX);
+ return ain + x;
+}
+
+static bool test_root_output() {
+ bool failed = false;
+ int i;
+
+ for (i = 0; i < gDimX; i++) {
+ int bElt = rsGetElementAt_int(B, i);
+ int aElt = rsGetElementAt_int(A, i);
+ if (!_RS_ASSERT_EQU(bElt, (aElt + i)))
+ rsDebug("test_root_output at i", i);
+ }
+
+ if (failed) {
+ rsDebug("ctxt_default test_root_output FAILED", 0);
+ }
+ else {
+ rsDebug("ctxt_default test_root_output PASSED", 0);
+ }
+
+ return failed;
+}
+
+void verify_root() {
+ failed |= test_root_output();
+}
+
+void kernel_test() {
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/double.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/double.rs
new file mode 100644
index 0000000..869dc45
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/double.rs
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#pragma version(1)
+#pragma rs java_package_name(com.android.rs.unittest)
+
+int4 RS_KERNEL doubleKernel(int4 in)
+{
+ return in * 2;
+}
\ No newline at end of file
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/element.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/element.rs
new file mode 100644
index 0000000..9dceea4
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/element.rs
@@ -0,0 +1,166 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+#include "rs_graphics.rsh"
+
+rs_element simpleElem;
+rs_element complexElem;
+typedef struct ComplexStruct {
+ float subElem0;
+ float subElem1;
+ int subElem2;
+ float arrayElem0[2];
+ int arrayElem1[5];
+ char subElem3;
+ float subElem4;
+ float2 subElem5;
+ float3 subElem6;
+ float4 subElem_7;
+} ComplexStruct_t;
+
+ComplexStruct_t *complexStruct;
+
+static const char *subElemNames[] = {
+ "subElem0",
+ "subElem1",
+ "subElem2",
+ "arrayElem0",
+ "arrayElem1",
+ "subElem3",
+ "subElem4",
+ "subElem5",
+ "subElem6",
+ "subElem_7",
+};
+
+static uint32_t subElemNamesSizes[] = {
+ 8,
+ 8,
+ 8,
+ 10,
+ 10,
+ 8,
+ 8,
+ 8,
+ 8,
+ 9,
+};
+
+static uint32_t subElemArraySizes[] = {
+ 1,
+ 1,
+ 1,
+ 2,
+ 5,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+};
+
+static bool equals(const char *name0, const char * name1, uint32_t len) {
+ for (uint32_t i = 0; i < len; i ++) {
+ if (name0[i] != name1[i]) {
+ return false;
+ }
+ }
+ return true;
+}
+
+static bool test_element_getters() {
+ bool failed = false;
+
+ uint32_t subElemOffsets[10];
+ uint32_t index = 0;
+ subElemOffsets[index++] = (uint32_t)&complexStruct->subElem0 - (uint32_t)complexStruct;
+ subElemOffsets[index++] = (uint32_t)&complexStruct->subElem1 - (uint32_t)complexStruct;
+ subElemOffsets[index++] = (uint32_t)&complexStruct->subElem2 - (uint32_t)complexStruct;
+ subElemOffsets[index++] = (uint32_t)&complexStruct->arrayElem0 - (uint32_t)complexStruct;
+ subElemOffsets[index++] = (uint32_t)&complexStruct->arrayElem1 - (uint32_t)complexStruct;
+ subElemOffsets[index++] = (uint32_t)&complexStruct->subElem3 - (uint32_t)complexStruct;
+ subElemOffsets[index++] = (uint32_t)&complexStruct->subElem4 - (uint32_t)complexStruct;
+ subElemOffsets[index++] = (uint32_t)&complexStruct->subElem5 - (uint32_t)complexStruct;
+ subElemOffsets[index++] = (uint32_t)&complexStruct->subElem6 - (uint32_t)complexStruct;
+ subElemOffsets[index++] = (uint32_t)&complexStruct->subElem_7 - (uint32_t)complexStruct;
+
+ uint32_t subElemCount = rsElementGetSubElementCount(simpleElem);
+ _RS_ASSERT(subElemCount == 0);
+ _RS_ASSERT(rsElementGetDataKind(simpleElem) == RS_KIND_USER);
+ _RS_ASSERT(rsElementGetDataType(simpleElem) == RS_TYPE_FLOAT_32);
+ _RS_ASSERT(rsElementGetVectorSize(simpleElem) == 3);
+
+ subElemCount = rsElementGetSubElementCount(complexElem);
+ _RS_ASSERT(subElemCount == 10);
+ _RS_ASSERT(rsElementGetDataKind(complexElem) == RS_KIND_USER);
+ _RS_ASSERT(rsElementGetDataType(complexElem) == RS_TYPE_NONE);
+ _RS_ASSERT(rsElementGetVectorSize(complexElem) == 1);
+ _RS_ASSERT(rsElementGetBytesSize(complexElem) == sizeof(*complexStruct));
+
+ char buffer[64];
+ for (uint32_t i = 0; i < subElemCount; i ++) {
+ rs_element subElem = rsElementGetSubElement(complexElem, i);
+ _RS_ASSERT(rsIsObject(subElem));
+
+ _RS_ASSERT(rsElementGetSubElementNameLength(complexElem, i) == subElemNamesSizes[i] + 1);
+
+ uint32_t written = rsElementGetSubElementName(complexElem, i, buffer, 64);
+ _RS_ASSERT(written == subElemNamesSizes[i]);
+ _RS_ASSERT(equals(buffer, subElemNames[i], written));
+
+ _RS_ASSERT(rsElementGetSubElementArraySize(complexElem, i) == subElemArraySizes[i]);
+ _RS_ASSERT(rsElementGetSubElementOffsetBytes(complexElem, i) == subElemOffsets[i]);
+ }
+
+ // Tests error checking
+ rs_element subElem = rsElementGetSubElement(complexElem, subElemCount);
+ _RS_ASSERT(!rsIsObject(subElem));
+
+ _RS_ASSERT(rsElementGetSubElementNameLength(complexElem, subElemCount) == 0);
+
+ _RS_ASSERT(rsElementGetSubElementName(complexElem, subElemCount, buffer, 64) == 0);
+ _RS_ASSERT(rsElementGetSubElementName(complexElem, 0, NULL, 64) == 0);
+ _RS_ASSERT(rsElementGetSubElementName(complexElem, 0, buffer, 0) == 0);
+ uint32_t written = rsElementGetSubElementName(complexElem, 0, buffer, 5);
+ _RS_ASSERT(written == 4);
+ _RS_ASSERT(buffer[4] == '\0');
+
+ _RS_ASSERT(rsElementGetSubElementArraySize(complexElem, subElemCount) == 0);
+ _RS_ASSERT(rsElementGetSubElementOffsetBytes(complexElem, subElemCount) == 0);
+
+ if (failed) {
+ rsDebug("test_element_getters FAILED", 0);
+ }
+ else {
+ rsDebug("test_element_getters PASSED", 0);
+ }
+
+ return failed;
+}
+
+void element_test() {
+ bool failed = false;
+ failed |= test_element_getters();
+
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/float_test.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/float_test.rs
new file mode 100644
index 0000000..46e8ef6
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/float_test.rs
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+float floatVal;
+double val;
+long valLong;
+
+double __attribute__((kernel)) foo(float a) {
+ return a + val + floatVal;
+}
+
+double __attribute__((kernel)) goo(double a) {
+ return a + valLong;
+}
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/foreach.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/foreach.rs
new file mode 100644
index 0000000..ed53cd7
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/foreach.rs
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+rs_allocation aRaw;
+int dimX;
+int dimY;
+static bool failed = false;
+
+void root(int *out, uint32_t x, uint32_t y) {
+ *out = x + y * dimX;
+}
+
+void foo(const int *in, int *out, uint32_t x, uint32_t y) {
+ _RS_ASSERT(*in == (x + y * dimX));
+ *out = 99 + x + y * dimX;
+ _RS_ASSERT(*out == (99 + x + y * dimX));
+}
+
+static bool test_root_output() {
+ bool failed = false;
+ int i, j;
+
+ for (j = 0; j < dimY; j++) {
+ for (i = 0; i < dimX; i++) {
+ int v = rsGetElementAt_int(aRaw, i, j);
+ _RS_ASSERT(v == (i + j * dimX));
+ }
+ }
+
+ if (failed) {
+ rsDebug("test_root_output FAILED", 0);
+ }
+ else {
+ rsDebug("test_root_output PASSED", 0);
+ }
+
+ return failed;
+}
+
+static bool test_foo_output() {
+ bool failed = false;
+ int i, j;
+
+ for (j = 0; j < dimY; j++) {
+ for (i = 0; i < dimX; i++) {
+ int v = rsGetElementAt_int(aRaw, i, j);
+ _RS_ASSERT(v == (99 + i + j * dimX));
+ }
+ }
+
+ if (failed) {
+ rsDebug("test_foo_output FAILED", 0);
+ }
+ else {
+ rsDebug("test_foo_output PASSED", 0);
+ }
+
+ return failed;
+}
+
+void verify_root() {
+ failed |= test_root_output();
+}
+
+void verify_foo() {
+ failed |= test_foo_output();
+}
+
+void foreach_test() {
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/foreach_bounds.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/foreach_bounds.rs
new file mode 100644
index 0000000..854df66
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/foreach_bounds.rs
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+int dimX;
+int dimY;
+int xStart = 0;
+int xEnd = 0;
+int yStart = 0;
+int yEnd = 0;
+
+static bool failed = false;
+
+rs_script s;
+rs_allocation aRaw;
+rs_allocation ain;
+rs_allocation aout;
+
+void root(int *out, uint32_t x, uint32_t y) {
+ *out = x + y * dimX;
+}
+
+int RS_KERNEL zero() {
+ return 0;
+}
+
+static bool test_root_output() {
+ bool failed = false;
+ int i, j;
+
+ for (j = 0; j < dimY; j++) {
+ for (i = 0; i < dimX; i++) {
+ int v = rsGetElementAt_int(aRaw, i, j);
+ if (i < xStart || i >= xEnd || j < yStart || j >= yEnd) {
+ _RS_ASSERT(v == 0);
+ } else {
+ _RS_ASSERT(v == (i + j * dimX));
+ }
+ }
+ }
+
+ if (failed) {
+ rsDebug("test_root_output FAILED", 0);
+ }
+ else {
+ rsDebug("test_root_output PASSED", 0);
+ }
+
+ return failed;
+}
+
+void verify_root() {
+ failed |= test_root_output();
+}
+
+void foreach_bounds_test() {
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/foreach_multi.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/foreach_multi.rs
new file mode 100644
index 0000000..86603e4
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/foreach_multi.rs
@@ -0,0 +1,194 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+struct RetStruct {
+ uint32_t i0;
+ uint32_t i1;
+ uint32_t i2;
+ uint32_t i3;
+ uint32_t i4;
+ uint32_t i5;
+ uint32_t i6;
+ uint32_t i7;
+};
+
+rs_allocation ain0, ain1, ain2;
+rs_allocation ain3;
+
+rs_allocation aout0, aout1, aout2, aout3;
+
+uint32_t dimX;
+
+static bool failed = false;
+
+uint32_t RS_KERNEL init_uint32_alloc(uint32_t x) {
+ return x;
+}
+
+uint16_t RS_KERNEL init_uint16_alloc(uint32_t x) {
+ return x;
+}
+
+uint32_t RS_KERNEL sum2(uint32_t in0, uint32_t in1, uint32_t x) {
+ _RS_ASSERT(in0 == x);
+ _RS_ASSERT(in1 == x);
+
+ return in0 + in1;
+}
+
+struct RetStruct RS_KERNEL
+sum2_struct(uint32_t in0, uint32_t in1, uint32_t x) {
+
+ _RS_ASSERT(in0 == x);
+ _RS_ASSERT(in1 == x);
+
+ struct RetStruct retval;
+
+ retval.i0 = in0 + in1;
+ retval.i1 = in0 + in1;
+ retval.i2 = in0 + in1;
+ retval.i3 = in0 + in1;
+ retval.i4 = in0 + in1;
+ retval.i5 = in0 + in1;
+ retval.i6 = in0 + in1;
+ retval.i7 = in0 + in1;
+
+ return retval;
+}
+
+uint32_t RS_KERNEL sum3(uint32_t in0, uint32_t in1, uint32_t in2, uint32_t x) {
+ _RS_ASSERT(in0 == x);
+ _RS_ASSERT(in1 == x);
+ _RS_ASSERT(in2 == x);
+
+ return in0 + in1 + in2;
+}
+
+
+uint32_t RS_KERNEL sum_mixed(uint32_t in0, uint16_t in1, uint32_t x) {
+ _RS_ASSERT(in0 == x);
+ _RS_ASSERT(in1 == x);
+
+ return in0 + in1;
+}
+
+static bool test_sum2_output() {
+ bool failed = false;
+ uint32_t i;
+
+ for (i = 0; i < dimX; i++) {
+ _RS_ASSERT(rsGetElementAt_uint(aout0, i) ==
+ (rsGetElementAt_uint(ain0, i) +
+ rsGetElementAt_uint(ain1, i)));
+ }
+
+ if (failed) {
+ rsDebug("test_sum2_output FAILED", 0);
+ }
+ else {
+ rsDebug("test_sum2_output PASSED", 0);
+ }
+
+ return failed;
+}
+
+static bool test_sum3_output() {
+ bool failed = false;
+ uint32_t i;
+
+ for (i = 0; i < dimX; i++) {
+ _RS_ASSERT(rsGetElementAt_uint(aout1, i) ==
+ (rsGetElementAt_uint(ain0, i) +
+ rsGetElementAt_uint(ain1, i) +
+ rsGetElementAt_uint(ain2, i)));
+ }
+
+ if (failed) {
+ rsDebug("test_sum3_output FAILED", 0);
+ }
+ else {
+ rsDebug("test_sum3_output PASSED", 0);
+ }
+
+ return failed;
+}
+
+static bool test_sum_mixed_output() {
+ bool failed = false;
+ uint32_t i;
+
+ for (i = 0; i < dimX; i++) {
+ _RS_ASSERT(rsGetElementAt_uint(aout2, i) ==
+ (rsGetElementAt_uint(ain0, i) +
+ rsGetElementAt_ushort(ain3, i)));
+ }
+
+ if (failed) {
+ rsDebug("test_sum_mixed_output FAILED", 0);
+ }
+ else {
+ rsDebug("test_sum_mixed_output PASSED", 0);
+ }
+
+ return failed;
+}
+
+static bool test_sum2_struct_output() {
+ bool failed = false;
+ uint32_t i;
+
+ for (i = 0; i < dimX; i++) {
+ struct RetStruct *result = (struct RetStruct*)rsGetElementAt(aout3, i);
+
+ uint32_t sum = rsGetElementAt_uint(ain0, i) +
+ rsGetElementAt_uint(ain1, i);
+
+ _RS_ASSERT(result->i0 == sum);
+ _RS_ASSERT(result->i1 == sum);
+ _RS_ASSERT(result->i2 == sum);
+ _RS_ASSERT(result->i3 == sum);
+ _RS_ASSERT(result->i4 == sum);
+ _RS_ASSERT(result->i5 == sum);
+ _RS_ASSERT(result->i6 == sum);
+ _RS_ASSERT(result->i7 == sum);
+ }
+
+ if (failed) {
+ rsDebug("test_sum2_struct_output FAILED", 0);
+ }
+ else {
+ rsDebug("test_sum2_struct_output PASSED", 0);
+ }
+
+ return failed;
+}
+
+void test_outputs() {
+ failed |= test_sum2_output();
+ failed |= test_sum3_output();
+ failed |= test_sum_mixed_output();
+ failed |= test_sum2_struct_output();
+}
+
+void check_test_results() {
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ } else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/fp16.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/fp16.rs
new file mode 100644
index 0000000..0e01b9a
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/fp16.rs
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+rs_allocation gAlloc;
+static bool failed = false;
+
+static half gStart = 12.0f;
+static half gIncr = 0.125;
+int gDimX;
+int gDimY;
+int gDimZ;
+
+static half ElementAt_half(int x, int y, int z) {
+ return gStart + x + y * gDimX + z * gDimX * gDimY;
+}
+
+static half2 ElementAt_half2(int x, int y, int z) {
+ half r = gStart + x + y * gDimX + z * gDimX * gDimY;
+ half2 ret = {r, r + gIncr};
+ return ret;
+}
+
+static half3 ElementAt_half3(int x, int y, int z) {
+ half r = gStart + x + y * gDimX + z * gDimX * gDimY;
+ half3 ret = {r, r + gIncr, r + gIncr * 2};
+ return ret;
+}
+
+static half4 ElementAt_half4(int x, int y, int z) {
+ half r = gStart + x + y * gDimX + z * gDimX * gDimY;
+ half4 ret = {r, r + gIncr, r + gIncr * 2, r + gIncr * 3};
+ return ret;
+}
+
+static void compare_half(half x, half y) {
+ _RS_ASSERT_EQU(x, y);
+ if (x != y) {
+ rsDebug("Different half values: ", x, y);
+ }
+}
+
+static void compare_half2(half2 x, half2 y) {
+ _RS_ASSERT_EQU(x.r, y.r);
+ _RS_ASSERT_EQU(x.g, y.g);
+ if (x.r != y.r || x.g != y.g) {
+ rsDebug("Different half vectors v1: ", x.r, x.g);
+ rsDebug(" v2: ", y.r, y.g);
+ }
+}
+
+static void compare_half3(half3 x, half3 y) {
+ _RS_ASSERT_EQU(x.r, y.r);
+ _RS_ASSERT_EQU(x.g, y.g);
+ _RS_ASSERT_EQU(x.b, y.b);
+ if (x.r != y.r || x.g != y.g || x.b != y.b) {
+ rsDebug("Different half vectors v1: ", x.r, x.g, x.b);
+ rsDebug(" v2: ", y.r, y.g, y.b);
+ }
+}
+
+static void compare_half4(half4 x, half4 y) {
+ _RS_ASSERT_EQU(x.r, y.r);
+ _RS_ASSERT_EQU(x.g, y.g);
+ _RS_ASSERT_EQU(x.b, y.b);
+ _RS_ASSERT_EQU(x.a, y.a);
+ if (x.r != y.r || x.g != y.g || x.b != y.b || x.a != y.a) {
+ rsDebug("Different half vectors v1: ", x.r, x.g, x.b, x.a);
+ rsDebug(" v2: ", y.r, y.g, x.b, x.a);
+ }
+}
+
+#define SET_KERNEL(T) \
+ T RS_KERNEL set_kernel_##T(int x, int y, int z) { \
+ return ElementAt_##T(x, y, z); \
+ }
+
+SET_KERNEL(half)
+SET_KERNEL(half2)
+SET_KERNEL(half3)
+SET_KERNEL(half4)
+
+#define INVOKE_SET(T) \
+ void set_##T() { \
+ int yEnd = (gDimY != 0) ? gDimY: 1; \
+ int zEnd = (gDimZ != 0) ? gDimZ: 1; \
+ for (int x=0; x < gDimX; x ++) \
+ for (int y=0; y < yEnd; y++) \
+ for (int z=0; z < zEnd; z++) \
+ rsSetElementAt_##T(gAlloc, ElementAt_##T(x, y, z), \
+ x, y, z); \
+ }
+
+INVOKE_SET(half)
+INVOKE_SET(half2)
+INVOKE_SET(half3)
+INVOKE_SET(half4)
+
+#define VERIFY_KERNEL(T) \
+ void RS_KERNEL verify_kernel_##T(T val, int x, int y, int z) { \
+ compare_##T(val, ElementAt_##T(x, y, z)); \
+ }
+
+VERIFY_KERNEL(half);
+VERIFY_KERNEL(half2);
+VERIFY_KERNEL(half3);
+VERIFY_KERNEL(half4);
+
+#define INVOKE_VERIFY(T) \
+ void verify_##T() { \
+ int yEnd = (gDimY != 0) ? gDimY: 1; \
+ int zEnd = (gDimZ != 0) ? gDimZ: 1; \
+ for (int x=0; x < gDimX; x ++) { \
+ for (int y=0; y < yEnd; y++) { \
+ for (int z=0; z < zEnd; z++) { \
+ T val = rsGetElementAt_##T(gAlloc, x, y, z); \
+ compare_##T(val, ElementAt_##T(x, y, z)); \
+ } \
+ } \
+ } \
+ }
+
+INVOKE_VERIFY(half)
+INVOKE_VERIFY(half2)
+INVOKE_VERIFY(half3)
+INVOKE_VERIFY(half4)
+
+void fp16_test() {
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/fp16_globals.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/fp16_globals.rs
new file mode 100644
index 0000000..fd8906f
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/fp16_globals.rs
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+half gHalf;
+half2 gHalf2;
+half3 gHalf3;
+half4 gHalf4;
+
+static bool failed = false;
+
+void validateHalf(half h) {
+ _RS_ASSERT_EQU((float) h, 10.f);
+}
+
+void validateHalf2(half2 h2) {
+ _RS_ASSERT_EQU((float) h2.x, 10.f);
+ _RS_ASSERT_EQU((float) h2.y, 11.f);
+}
+
+void validateHalf3(half3 h3) {
+ _RS_ASSERT_EQU((float) h3.x, 10.f);
+ _RS_ASSERT_EQU((float) h3.y, 11.f);
+ _RS_ASSERT_EQU((float) h3.z, -12.f);
+}
+
+void validateHalf4(half4 h4) {
+ _RS_ASSERT_EQU((float) h4.x, 10.f);
+ _RS_ASSERT_EQU((float) h4.y, 11.f);
+ _RS_ASSERT_EQU((float) h4.z, -12.f);
+ _RS_ASSERT_EQU((float) h4.w, -13.f);
+}
+
+void test(half h, half2 h2, half3 h3, half4 h4) {
+ validateHalf(gHalf);
+ validateHalf2(gHalf2);
+ validateHalf3(gHalf3);
+ validateHalf4(gHalf4);
+
+ validateHalf(h);
+ validateHalf2(h2);
+ validateHalf3(h3);
+ validateHalf4(h4);
+
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/fp_mad.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/fp_mad.rs
new file mode 100644
index 0000000..9ba1f92
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/fp_mad.rs
@@ -0,0 +1,182 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+const int TEST_COUNT = 1;
+
+static float data_f1[1025];
+static float4 data_f4[1025];
+
+static void test_mad4(uint32_t index) {
+ start();
+
+ // Do ~1 billion ops
+ for (int ct=0; ct < 1000 * (1000 / 80); ct++) {
+ for (int i=0; i < (1000); i++) {
+ data_f4[i] = (data_f4[i] * 0.02f +
+ data_f4[i+1] * 0.04f +
+ data_f4[i+2] * 0.05f +
+ data_f4[i+3] * 0.1f +
+ data_f4[i+4] * 0.2f +
+ data_f4[i+5] * 0.2f +
+ data_f4[i+6] * 0.1f +
+ data_f4[i+7] * 0.05f +
+ data_f4[i+8] * 0.04f +
+ data_f4[i+9] * 0.02f + 1.f);
+ }
+ }
+
+ float time = end(index);
+ rsDebug("fp_mad4 M ops", 1000.f / time);
+}
+
+static void test_mad(uint32_t index) {
+ start();
+
+ // Do ~1 billion ops
+ for (int ct=0; ct < 1000 * (1000 / 20); ct++) {
+ for (int i=0; i < (1000); i++) {
+ data_f1[i] = (data_f1[i] * 0.02f +
+ data_f1[i+1] * 0.04f +
+ data_f1[i+2] * 0.05f +
+ data_f1[i+3] * 0.1f +
+ data_f1[i+4] * 0.2f +
+ data_f1[i+5] * 0.2f +
+ data_f1[i+6] * 0.1f +
+ data_f1[i+7] * 0.05f +
+ data_f1[i+8] * 0.04f +
+ data_f1[i+9] * 0.02f + 1.f);
+ }
+ }
+
+ float time = end(index);
+ rsDebug("fp_mad M ops", 1000.f / time);
+}
+
+static void test_norm(uint32_t index) {
+ start();
+
+ // Do ~10 M ops
+ for (int ct=0; ct < 1000 * 10; ct++) {
+ for (int i=0; i < (1000); i++) {
+ data_f4[i] = normalize(data_f4[i]);
+ }
+ }
+
+ float time = end(index);
+ rsDebug("fp_norm M ops", 10.f / time);
+}
+
+static void test_sincos4(uint32_t index) {
+ start();
+
+ // Do ~10 M ops
+ for (int ct=0; ct < 1000 * 10 / 4; ct++) {
+ for (int i=0; i < (1000); i++) {
+ data_f4[i] = sin(data_f4[i]) * cos(data_f4[i]);
+ }
+ }
+
+ float time = end(index);
+ rsDebug("fp_sincos4 M ops", 10.f / time);
+}
+
+static void test_sincos(uint32_t index) {
+ start();
+
+ // Do ~10 M ops
+ for (int ct=0; ct < 1000 * 10; ct++) {
+ for (int i=0; i < (1000); i++) {
+ data_f1[i] = sin(data_f1[i]) * cos(data_f1[i]);
+ }
+ }
+
+ float time = end(index);
+ rsDebug("fp_sincos M ops", 10.f / time);
+}
+
+static void test_clamp(uint32_t index) {
+ start();
+
+ // Do ~100 M ops
+ for (int ct=0; ct < 1000 * 100; ct++) {
+ for (int i=0; i < (1000); i++) {
+ data_f1[i] = clamp(data_f1[i], -1.f, 1.f);
+ }
+ }
+
+ float time = end(index);
+ rsDebug("fp_clamp M ops", 100.f / time);
+
+ start();
+ // Do ~100 M ops
+ for (int ct=0; ct < 1000 * 100; ct++) {
+ for (int i=0; i < (1000); i++) {
+ if (data_f1[i] < -1.f) data_f1[i] = -1.f;
+ if (data_f1[i] > -1.f) data_f1[i] = 1.f;
+ }
+ }
+
+ time = end(index);
+ rsDebug("fp_clamp ref M ops", 100.f / time);
+}
+
+static void test_clamp4(uint32_t index) {
+ start();
+
+ // Do ~100 M ops
+ for (int ct=0; ct < 1000 * 100 /4; ct++) {
+ for (int i=0; i < (1000); i++) {
+ data_f4[i] = clamp(data_f4[i], -1.f, 1.f);
+ }
+ }
+
+ float time = end(index);
+ rsDebug("fp_clamp4 M ops", 100.f / time);
+}
+
+void fp_mad_test(uint32_t index, int test_num) {
+ int x;
+ for (x=0; x < 1025; x++) {
+ data_f1[x] = (x & 0xf) * 0.1f;
+ data_f4[x].x = (x & 0xf) * 0.1f;
+ data_f4[x].y = (x & 0xf0) * 0.1f;
+ data_f4[x].z = (x & 0x33) * 0.1f;
+ data_f4[x].w = (x & 0x77) * 0.1f;
+ }
+
+ test_mad4(index);
+ test_mad(index);
+
+ for (x=0; x < 1025; x++) {
+ data_f1[x] = (x & 0xf) * 0.1f + 1.f;
+ data_f4[x].x = (x & 0xf) * 0.1f + 1.f;
+ data_f4[x].y = (x & 0xf0) * 0.1f + 1.f;
+ data_f4[x].z = (x & 0x33) * 0.1f + 1.f;
+ data_f4[x].w = (x & 0x77) * 0.1f + 1.f;
+ }
+
+ test_norm(index);
+ test_sincos4(index);
+ test_sincos(index);
+ test_clamp4(index);
+ test_clamp(index);
+
+ // TODO Actually verify test result accuracy
+ rsDebug("fp_mad_test PASSED", 0);
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/increment.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/increment.rs
new file mode 100644
index 0000000..26d1252
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/increment.rs
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#pragma version(1)
+#pragma rs java_package_name(com.android.rs.unittest)
+
+int4 RS_KERNEL increment(int4 in)
+{
+ return in + 1;
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/increment2.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/increment2.rs
new file mode 100644
index 0000000..006b11a
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/increment2.rs
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#pragma version(1)
+#pragma rs java_package_name(com.android.rs.unittest)
+
+rs_allocation a;
+
+void RS_KERNEL increment2(int4 in, int x)
+{
+ rsSetElementAt_int4(a, in + 1, x);
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/int4.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/int4.rs
new file mode 100644
index 0000000..fac0619
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/int4.rs
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+#pragma rs_fp_relaxed
+
+uchar4 u4 = 4;
+int4 gi4 = {2, 2, 2, 2};
+
+void int4_test() {
+ bool failed = false;
+ int4 i4 = {u4.x, u4.y, u4.z, u4.w};
+ i4 *= gi4;
+
+ rsDebug("i4.x", i4.x);
+ rsDebug("i4.y", i4.y);
+ rsDebug("i4.z", i4.z);
+ rsDebug("i4.w", i4.w);
+
+ _RS_ASSERT(i4.x == 8);
+ _RS_ASSERT(i4.y == 8);
+ _RS_ASSERT(i4.z == 8);
+ _RS_ASSERT(i4.w == 8);
+
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/kernel.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/kernel.rs
new file mode 100644
index 0000000..dd6a2e6
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/kernel.rs
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+int *ain;
+int *aout;
+int dimX;
+static bool failed = false;
+
+void init_vars(int *out) {
+ *out = 7;
+}
+
+
+int RS_KERNEL root(int ain, uint32_t x) {
+ _RS_ASSERT(ain == 7);
+ return ain + x;
+}
+
+static bool test_root_output() {
+ bool failed = false;
+ int i;
+
+ for (i = 0; i < dimX; i++) {
+ _RS_ASSERT(aout[i] == (i + ain[i]));
+ }
+
+ if (failed) {
+ rsDebug("test_root_output FAILED", 0);
+ }
+ else {
+ rsDebug("test_root_output PASSED", 0);
+ }
+
+ return failed;
+}
+
+void verify_root() {
+ failed |= test_root_output();
+}
+
+void kernel_test() {
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/kernel2d.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/kernel2d.rs
new file mode 100644
index 0000000..69e95c8
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/kernel2d.rs
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+rs_allocation A;
+rs_allocation B;
+uint32_t gDimX, gDimY;
+static bool failed = false;
+
+void init_vars(int *out) {
+ *out = 7;
+}
+
+int RS_KERNEL root(int ain, rs_kernel_context context, uint32_t x, uint32_t y) {
+ if (!_RS_ASSERT_EQU(ain, 7))
+ rsDebug("root at x, y", x, y);
+ uint32_t dimX = rsGetDimX(context);
+ uint32_t dimY = rsGetDimY(context);
+ _RS_ASSERT_EQU(dimX, gDimX);
+ _RS_ASSERT_EQU(dimY, gDimY);
+ return ain + x + dimX * y;
+}
+
+static bool test_root_output() {
+ bool failed = false;
+ int i, j;
+
+ for (i = 0; i < gDimX; i++) {
+ for (j = 0; j < gDimY; j++) {
+ int bElt = rsGetElementAt_int(B, i, j);
+ int aElt = rsGetElementAt_int(A, i, j);
+ if (!_RS_ASSERT_EQU(bElt, (aElt + i + gDimX * j)))
+ rsDebug("test_root_output at i, j", i, j);
+ }
+ }
+
+ if (failed) {
+ rsDebug("kernel2d test_root_output FAILED", 0);
+ }
+ else {
+ rsDebug("kernel2d test_root_output PASSED", 0);
+ }
+
+ return failed;
+}
+
+void verify_root() {
+ failed |= test_root_output();
+}
+
+void kernel_test() {
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/kernel2d_oldstyle.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/kernel2d_oldstyle.rs
new file mode 100644
index 0000000..7d76c9a
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/kernel2d_oldstyle.rs
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+rs_allocation A;
+rs_allocation B;
+uint32_t gDimX, gDimY;
+static bool failed = false;
+
+void init_vars(int *out) {
+ *out = 7;
+}
+
+void xform(const int *in, int *out, rs_kernel_context context, uint32_t x, uint32_t y) {
+ if (!_RS_ASSERT_EQU(*in, 7))
+ rsDebug("xform at x, y", x, y);
+ uint32_t dimX = rsGetDimX(context);
+ uint32_t dimY = rsGetDimY(context);
+ _RS_ASSERT_EQU(dimX, gDimX);
+ _RS_ASSERT_EQU(dimY, gDimY);
+ *out = *in + x + dimX * y;
+}
+
+static bool test_xform_output() {
+ bool failed = false;
+ int i, j;
+
+ for (i = 0; i < gDimX; i++) {
+ for (j = 0; j < gDimY; j++) {
+ int bElt = rsGetElementAt_int(B, i, j);
+ int aElt = rsGetElementAt_int(A, i, j);
+ if (!_RS_ASSERT_EQU(bElt, (aElt + i + gDimX * j)))
+ rsDebug("test_xform_output at i, j", i, j);
+ }
+ }
+
+ if (failed) {
+ rsDebug("kernel2d (old style) test_xform_output FAILED", 0);
+ }
+ else {
+ rsDebug("kernel2d (old style) test_xform_output PASSED", 0);
+ }
+
+ return failed;
+}
+
+void verify_xform() {
+ failed |= test_xform_output();
+}
+
+void kernel_test() {
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/kernel3d.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/kernel3d.rs
new file mode 100644
index 0000000..1771a7c
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/kernel3d.rs
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+rs_allocation A;
+rs_allocation B;
+uint32_t gDimX, gDimY, gDimZ;
+static bool failed = false;
+
+void init_vars(int *out) {
+ *out = 7;
+}
+
+int RS_KERNEL root(int ain, rs_kernel_context context, uint32_t x, uint32_t y, uint32_t z) {
+ if (!_RS_ASSERT_EQU(ain, 7))
+ rsDebug("root at x, y, z", x, y, z);
+ uint32_t dimX = rsGetDimX(context);
+ uint32_t dimY = rsGetDimY(context);
+ uint32_t dimZ = rsGetDimZ(context);
+ _RS_ASSERT_EQU(dimX, gDimX);
+ _RS_ASSERT_EQU(dimY, gDimY);
+ _RS_ASSERT_EQU(dimZ, gDimZ);
+ return ain + x + dimX * y + dimX * dimY * z;
+}
+
+static bool test_root_output() {
+ bool failed = false;
+ int i, j, k;
+
+ for (i = 0; i < gDimX; i++) {
+ for (j = 0; j < gDimY; j++) {
+ for (k = 0; k < gDimZ; k++) {
+ int bElt = rsGetElementAt_int(B, i, j, k);
+ int aElt = rsGetElementAt_int(A, i, j, k);
+ if (!_RS_ASSERT_EQU(bElt, (aElt + i + gDimX * j + gDimX * gDimY * k)))
+ rsDebug("test_root_output at i, j, k", i, j, k);
+ }
+ }
+ }
+
+ if (failed) {
+ rsDebug("kernel3d test_root_output FAILED", 0);
+ }
+ else {
+ rsDebug("kernel3d test_root_output PASSED", 0);
+ }
+
+ return failed;
+}
+
+void verify_root() {
+ failed |= test_root_output();
+}
+
+void kernel_test() {
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/kernel_struct.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/kernel_struct.rs
new file mode 100644
index 0000000..f54fe6d
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/kernel_struct.rs
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+struct simpleStruct {
+ int i1;
+ char ignored1;
+ float f1;
+ int i2;
+ char ignored2;
+ float f2;
+};
+
+struct simpleStruct *ain;
+struct simpleStruct *aout;
+int dimX;
+static bool failed = false;
+
+void init_vars(struct simpleStruct *out, uint32_t x) {
+ out->i1 = 0;
+ out->f1 = 0.f;
+ out->i2 = 1;
+ out->f2 = 1.0f;
+}
+
+struct simpleStruct RS_KERNEL
+ root(struct simpleStruct in, uint32_t x) {
+ struct simpleStruct s;
+ s.i1 = in.i1 + x;
+ s.f1 = in.f1 + x;
+ s.i2 = in.i2 + x;
+ s.f2 = in.f2 + x;
+ return s;
+}
+
+static bool test_root_output() {
+ bool failed = false;
+ int i;
+
+ for (i = 0; i < dimX; i++) {
+ _RS_ASSERT(aout[i].i1 == (i + ain[i].i1));
+ _RS_ASSERT(aout[i].f1 == (i + ain[i].f1));
+ _RS_ASSERT(aout[i].i2 == (i + ain[i].i2));
+ _RS_ASSERT(aout[i].f2 == (i + ain[i].f2));
+ }
+
+ if (failed) {
+ rsDebug("test_root_output FAILED", 0);
+ }
+ else {
+ rsDebug("test_root_output PASSED", 0);
+ }
+
+ return failed;
+}
+
+void verify_root() {
+ failed |= test_root_output();
+}
+
+void kernel_struct_test() {
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/math.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/math.rs
new file mode 100644
index 0000000..2e53481
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/math.rs
@@ -0,0 +1,459 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+// Testing math library
+
+volatile float f1;
+volatile float2 f2;
+volatile float3 f3;
+volatile float4 f4;
+
+volatile int i1;
+volatile int2 i2;
+volatile int3 i3;
+volatile int4 i4;
+
+volatile uint ui1;
+volatile uint2 ui2;
+volatile uint3 ui3;
+volatile uint4 ui4;
+
+volatile short s1;
+volatile short2 s2;
+volatile short3 s3;
+volatile short4 s4;
+
+volatile ushort us1;
+volatile ushort2 us2;
+volatile ushort3 us3;
+volatile ushort4 us4;
+
+volatile char c1;
+volatile char2 c2;
+volatile char3 c3;
+volatile char4 c4;
+
+volatile uchar uc1;
+volatile uchar2 uc2;
+volatile uchar3 uc3;
+volatile uchar4 uc4;
+
+#define DECL_INT(prefix) \
+volatile char prefix##_c_1 = 1; \
+volatile char2 prefix##_c_2 = 1; \
+volatile char3 prefix##_c_3 = 1; \
+volatile char4 prefix##_c_4 = 1; \
+volatile uchar prefix##_uc_1 = 1; \
+volatile uchar2 prefix##_uc_2 = 1; \
+volatile uchar3 prefix##_uc_3 = 1; \
+volatile uchar4 prefix##_uc_4 = 1; \
+volatile short prefix##_s_1 = 1; \
+volatile short2 prefix##_s_2 = 1; \
+volatile short3 prefix##_s_3 = 1; \
+volatile short4 prefix##_s_4 = 1; \
+volatile ushort prefix##_us_1 = 1; \
+volatile ushort2 prefix##_us_2 = 1; \
+volatile ushort3 prefix##_us_3 = 1; \
+volatile ushort4 prefix##_us_4 = 1; \
+volatile int prefix##_i_1 = 1; \
+volatile int2 prefix##_i_2 = 1; \
+volatile int3 prefix##_i_3 = 1; \
+volatile int4 prefix##_i_4 = 1; \
+volatile uint prefix##_ui_1 = 1; \
+volatile uint2 prefix##_ui_2 = 1; \
+volatile uint3 prefix##_ui_3 = 1; \
+volatile uint4 prefix##_ui_4 = 1; \
+volatile long prefix##_l_1 = 1; \
+volatile ulong prefix##_ul_1 = 1;
+
+DECL_INT(res)
+DECL_INT(src1)
+DECL_INT(src2)
+
+#define TEST_INT_OP_TYPE(op, type) \
+rsDebug("Testing " #op " for " #type "1", i++); \
+res_##type##_1 = src1_##type##_1 op src2_##type##_1; \
+rsDebug("Testing " #op " for " #type "2", i++); \
+res_##type##_2 = src1_##type##_2 op src2_##type##_2; \
+rsDebug("Testing " #op " for " #type "3", i++); \
+res_##type##_3 = src1_##type##_3 op src2_##type##_3; \
+rsDebug("Testing " #op " for " #type "4", i++); \
+res_##type##_4 = src1_##type##_4 op src2_##type##_4;
+
+#define TEST_INT_OP(op) \
+TEST_INT_OP_TYPE(op, c) \
+TEST_INT_OP_TYPE(op, uc) \
+TEST_INT_OP_TYPE(op, s) \
+TEST_INT_OP_TYPE(op, us) \
+TEST_INT_OP_TYPE(op, i) \
+TEST_INT_OP_TYPE(op, ui) \
+rsDebug("Testing " #op " for l1", i++); \
+res_l_1 = src1_l_1 op src2_l_1; \
+rsDebug("Testing " #op " for ul1", i++); \
+res_ul_1 = src1_ul_1 op src2_ul_1;
+
+#define TEST_XN_FUNC_YN(typeout, fnc, typein) \
+ res_##typeout##_1 = fnc(src1_##typein##_1); \
+ res_##typeout##_2 = fnc(src1_##typein##_2); \
+ res_##typeout##_3 = fnc(src1_##typein##_3); \
+ res_##typeout##_4 = fnc(src1_##typein##_4);
+
+#define TEST_XN_FUNC_XN_XN(type, fnc) \
+ res_##type##_1 = fnc(src1_##type##_1, src2_##type##_1); \
+ res_##type##_2 = fnc(src1_##type##_2, src2_##type##_2); \
+ res_##type##_3 = fnc(src1_##type##_3, src2_##type##_3); \
+ res_##type##_4 = fnc(src1_##type##_4, src2_##type##_4);
+
+#define TEST_X_FUNC_X_X_X(type, fnc) \
+ res_##type##_1 = fnc(src1_##type##_1, src2_##type##_1, src2_##type##_1);
+
+#define TEST_IN_FUNC_IN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ TEST_XN_FUNC_YN(uc, fnc, uc) \
+ TEST_XN_FUNC_YN(c, fnc, c) \
+ TEST_XN_FUNC_YN(us, fnc, us) \
+ TEST_XN_FUNC_YN(s, fnc, s) \
+ TEST_XN_FUNC_YN(ui, fnc, ui) \
+ TEST_XN_FUNC_YN(i, fnc, i)
+
+#define TEST_UIN_FUNC_IN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ TEST_XN_FUNC_YN(uc, fnc, c) \
+ TEST_XN_FUNC_YN(us, fnc, s) \
+ TEST_XN_FUNC_YN(ui, fnc, i) \
+
+#define TEST_IN_FUNC_IN_IN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ TEST_XN_FUNC_XN_XN(uc, fnc) \
+ TEST_XN_FUNC_XN_XN(c, fnc) \
+ TEST_XN_FUNC_XN_XN(us, fnc) \
+ TEST_XN_FUNC_XN_XN(s, fnc) \
+ TEST_XN_FUNC_XN_XN(ui, fnc) \
+ TEST_XN_FUNC_XN_XN(i, fnc)
+
+#define TEST_I_FUNC_I_I_I(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ TEST_X_FUNC_X_X_X(uc, fnc) \
+ TEST_X_FUNC_X_X_X(c, fnc) \
+ TEST_X_FUNC_X_X_X(us, fnc) \
+ TEST_X_FUNC_X_X_X(s, fnc) \
+ TEST_X_FUNC_X_X_X(ui, fnc) \
+ TEST_X_FUNC_X_X_X(i, fnc)
+
+#define TEST_FN_FUNC_FN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ f1 = fnc(f1); \
+ f2 = fnc(f2); \
+ f3 = fnc(f3); \
+ f4 = fnc(f4);
+
+#define TEST_FN_FUNC_FN_PFN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ f1 = fnc(f1, (float*) &f1); \
+ f2 = fnc(f2, (float2*) &f2); \
+ f3 = fnc(f3, (float3*) &f3); \
+ f4 = fnc(f4, (float4*) &f4);
+
+#define TEST_FN_FUNC_FN_FN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ f1 = fnc(f1, f1); \
+ f2 = fnc(f2, f2); \
+ f3 = fnc(f3, f3); \
+ f4 = fnc(f4, f4);
+
+#define TEST_F34_FUNC_F34_F34(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ f3 = fnc(f3, f3); \
+ f4 = fnc(f4, f4);
+
+#define TEST_FN_FUNC_FN_F(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ f1 = fnc(f1, f1); \
+ f2 = fnc(f2, f1); \
+ f3 = fnc(f3, f1); \
+ f4 = fnc(f4, f1);
+
+#define TEST_FN_FUNC_F_FN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ f1 = fnc(f1, f1); \
+ f2 = fnc(f1, f2); \
+ f3 = fnc(f1, f3); \
+ f4 = fnc(f1, f4);
+
+#define TEST_F_FUNC_FN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ f1 = fnc(f1); \
+ f1 = fnc(f2); \
+ f1 = fnc(f3); \
+ f1 = fnc(f4);
+
+#define TEST_F_FUNC_FN_FN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ f1 = fnc(f1, f1); \
+ f1 = fnc(f2, f2); \
+ f1 = fnc(f3, f3); \
+ f1 = fnc(f4, f4);
+
+#define TEST_FN_FUNC_FN_IN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ f1 = fnc(f1, i1); \
+ f2 = fnc(f2, i2); \
+ f3 = fnc(f3, i3); \
+ f4 = fnc(f4, i4);
+
+#define TEST_FN_FUNC_FN_I(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ f1 = fnc(f1, i1); \
+ f2 = fnc(f2, i1); \
+ f3 = fnc(f3, i1); \
+ f4 = fnc(f4, i1);
+
+#define TEST_FN_FUNC_FN_FN_FN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ f1 = fnc(f1, f1, f1); \
+ f2 = fnc(f2, f2, f2); \
+ f3 = fnc(f3, f3, f3); \
+ f4 = fnc(f4, f4, f4);
+
+#define TEST_FN_FUNC_FN_FN_F(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ f1 = fnc(f1, f1, f1); \
+ f2 = fnc(f2, f1, f1); \
+ f3 = fnc(f3, f1, f1); \
+ f4 = fnc(f4, f1, f1);
+
+#define TEST_FN_FUNC_FN_PIN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ f1 = fnc(f1, (int*) &i1); \
+ f2 = fnc(f2, (int2*) &i2); \
+ f3 = fnc(f3, (int3*) &i3); \
+ f4 = fnc(f4, (int4*) &i4);
+
+#define TEST_FN_FUNC_FN_FN_PIN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ f1 = fnc(f1, f1, (int*) &i1); \
+ f2 = fnc(f2, f2, (int2*) &i2); \
+ f3 = fnc(f3, f3, (int3*) &i3); \
+ f4 = fnc(f4, f4, (int4*) &i4);
+
+#define TEST_IN_FUNC_FN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ i1 = fnc(f1); \
+ i2 = fnc(f2); \
+ i3 = fnc(f3); \
+ i4 = fnc(f4);
+
+static bool test_fp_math(uint32_t index) {
+ bool failed = false;
+ start();
+
+ TEST_FN_FUNC_FN(acos);
+ TEST_FN_FUNC_FN(acosh);
+ TEST_FN_FUNC_FN(acospi);
+ TEST_FN_FUNC_FN(asin);
+ TEST_FN_FUNC_FN(asinh);
+ TEST_FN_FUNC_FN(asinpi);
+ TEST_FN_FUNC_FN(atan);
+ TEST_FN_FUNC_FN_FN(atan2);
+ TEST_FN_FUNC_FN(atanh);
+ TEST_FN_FUNC_FN(atanpi);
+ TEST_FN_FUNC_FN_FN(atan2pi);
+ TEST_FN_FUNC_FN(cbrt);
+ TEST_FN_FUNC_FN(ceil);
+ TEST_FN_FUNC_FN_FN_FN(clamp);
+ TEST_FN_FUNC_FN_FN_F(clamp);
+ TEST_FN_FUNC_FN_FN(copysign);
+ TEST_FN_FUNC_FN(cos);
+ TEST_FN_FUNC_FN(cosh);
+ TEST_FN_FUNC_FN(cospi);
+ TEST_F34_FUNC_F34_F34(cross);
+ TEST_FN_FUNC_FN(degrees);
+ TEST_F_FUNC_FN_FN(distance);
+ TEST_F_FUNC_FN_FN(dot);
+ TEST_FN_FUNC_FN(erfc);
+ TEST_FN_FUNC_FN(erf);
+ TEST_FN_FUNC_FN(exp);
+ TEST_FN_FUNC_FN(exp2);
+ TEST_FN_FUNC_FN(exp10);
+ TEST_FN_FUNC_FN(expm1);
+ TEST_FN_FUNC_FN(fabs);
+ TEST_FN_FUNC_FN_FN(fdim);
+ TEST_FN_FUNC_FN(floor);
+ TEST_FN_FUNC_FN_FN_FN(fma);
+ TEST_FN_FUNC_FN_FN(fmax);
+ TEST_FN_FUNC_FN_F(fmax);
+ TEST_FN_FUNC_FN_FN(fmin);
+ TEST_FN_FUNC_FN_F(fmin);
+ TEST_FN_FUNC_FN_FN(fmod);
+ TEST_FN_FUNC_FN_PFN(fract);
+ TEST_FN_FUNC_FN_PIN(frexp);
+ TEST_FN_FUNC_FN_FN(hypot);
+ TEST_IN_FUNC_FN(ilogb);
+ TEST_FN_FUNC_FN_IN(ldexp);
+ TEST_FN_FUNC_FN_I(ldexp);
+ TEST_F_FUNC_FN(length);
+ TEST_FN_FUNC_FN(lgamma);
+ TEST_FN_FUNC_FN_PIN(lgamma);
+ TEST_FN_FUNC_FN(log);
+ TEST_FN_FUNC_FN(log2);
+ TEST_FN_FUNC_FN(log10);
+ TEST_FN_FUNC_FN(log1p);
+ TEST_FN_FUNC_FN(logb);
+ TEST_FN_FUNC_FN_FN_FN(mad);
+ TEST_FN_FUNC_FN_FN(max);
+ TEST_FN_FUNC_FN_F(max);
+ TEST_FN_FUNC_FN_FN(min);
+ TEST_FN_FUNC_FN_F(min);
+ TEST_FN_FUNC_FN_FN_FN(mix);
+ TEST_FN_FUNC_FN_FN_F(mix);
+ TEST_FN_FUNC_FN_PFN(modf);
+ // nan
+ TEST_FN_FUNC_FN_FN(nextafter);
+ TEST_FN_FUNC_FN(normalize);
+ TEST_FN_FUNC_FN_FN(pow);
+ TEST_FN_FUNC_FN_IN(pown);
+ TEST_FN_FUNC_FN_FN(powr);
+ TEST_FN_FUNC_FN(radians);
+ TEST_FN_FUNC_FN_FN(remainder);
+ TEST_FN_FUNC_FN_FN_PIN(remquo);
+ TEST_FN_FUNC_FN(rint);
+ TEST_FN_FUNC_FN_IN(rootn);
+ TEST_FN_FUNC_FN(round);
+ TEST_FN_FUNC_FN(rsqrt);
+ TEST_FN_FUNC_FN(sign);
+ TEST_FN_FUNC_FN(sin);
+ TEST_FN_FUNC_FN_PFN(sincos);
+ TEST_FN_FUNC_FN(sinh);
+ TEST_FN_FUNC_FN(sinpi);
+ TEST_FN_FUNC_FN(sqrt);
+ TEST_FN_FUNC_FN_FN(step);
+ TEST_FN_FUNC_FN_F(step);
+ TEST_FN_FUNC_F_FN(step);
+ TEST_FN_FUNC_FN(tan);
+ TEST_FN_FUNC_FN(tanh);
+ TEST_FN_FUNC_FN(tanpi);
+ TEST_FN_FUNC_FN(tgamma);
+ TEST_FN_FUNC_FN(trunc);
+
+ float time = end(index);
+
+ if (failed) {
+ rsDebug("test_fp_math FAILED", time);
+ }
+ else {
+ rsDebug("test_fp_math PASSED", time);
+ }
+
+ return failed;
+}
+
+static bool test_int_math(uint32_t index) {
+ bool failed = false;
+ start();
+
+ TEST_UIN_FUNC_IN(abs);
+ TEST_IN_FUNC_IN(clz);
+ TEST_IN_FUNC_IN_IN(min);
+ TEST_IN_FUNC_IN_IN(max);
+ TEST_I_FUNC_I_I_I(clamp);
+
+ float time = end(index);
+
+ if (failed) {
+ rsDebug("test_int_math FAILED", time);
+ }
+ else {
+ rsDebug("test_int_math PASSED", time);
+ }
+
+ return failed;
+}
+
+static bool test_basic_operators() {
+ bool failed = false;
+ int i = 0;
+
+ TEST_INT_OP(+);
+ TEST_INT_OP(-);
+ TEST_INT_OP(*);
+ TEST_INT_OP(/);
+ TEST_INT_OP(%);
+ TEST_INT_OP(<<);
+ TEST_INT_OP(>>);
+
+ if (failed) {
+ rsDebug("test_basic_operators FAILED", 0);
+ }
+ else {
+ rsDebug("test_basic_operators PASSED", 0);
+ }
+
+ return failed;
+}
+
+#define TEST_CVT(to, from, type) \
+rsDebug("Testing convert from " #from " to " #to, 0); \
+to##1 = from##1; \
+to##2 = convert_##type##2(from##2); \
+to##3 = convert_##type##3(from##3); \
+to##4 = convert_##type##4(from##4);
+
+#define TEST_CVT_MATRIX(to, type) \
+TEST_CVT(to, c, type); \
+TEST_CVT(to, uc, type); \
+TEST_CVT(to, s, type); \
+TEST_CVT(to, us, type); \
+TEST_CVT(to, i, type); \
+TEST_CVT(to, ui, type); \
+TEST_CVT(to, f, type); \
+
+static bool test_convert() {
+ bool failed = false;
+
+ TEST_CVT_MATRIX(c, char);
+ TEST_CVT_MATRIX(uc, uchar);
+ TEST_CVT_MATRIX(s, short);
+ TEST_CVT_MATRIX(us, ushort);
+ TEST_CVT_MATRIX(i, int);
+ TEST_CVT_MATRIX(ui, uint);
+ TEST_CVT_MATRIX(f, float);
+
+ if (failed) {
+ rsDebug("test_convert FAILED", 0);
+ }
+ else {
+ rsDebug("test_convert PASSED", 0);
+ }
+
+ return failed;
+}
+
+void math_test(uint32_t index, int test_num) {
+ bool failed = false;
+ failed |= test_convert();
+ failed |= test_fp_math(index);
+ failed |= test_int_math(index);
+ failed |= test_basic_operators();
+
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/math_24.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/math_24.rs
new file mode 100644
index 0000000..bc0ed54
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/math_24.rs
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+// Testing math_24 library
+
+volatile float f1;
+volatile float2 f2;
+volatile float3 f3;
+volatile float4 f4;
+
+#define TEST_FN_FUNC_FN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ f1 = fnc(f1); \
+ f2 = fnc(f2); \
+ f3 = fnc(f3); \
+ f4 = fnc(f4);
+
+static bool test_fp_math_24(uint32_t index) {
+ bool failed = false;
+ start();
+
+ TEST_FN_FUNC_FN(fract);
+
+ float time = end(index);
+
+ if (failed) {
+ rsDebug("test_fp_math_24 FAILED", time);
+ }
+ else {
+ rsDebug("test_fp_math_24 PASSED", time);
+ }
+
+ return failed;
+}
+
+void math_24_test(uint32_t index, int test_num) {
+ bool failed = false;
+ failed |= test_fp_math_24(index);
+
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/math_agree.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/math_agree.rs
new file mode 100644
index 0000000..6d8fd5c
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/math_agree.rs
@@ -0,0 +1,420 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+//#pragma rs_fp_relaxed
+
+volatile float x = 0.0f;
+volatile float y = 0.0f;
+volatile float result_add = 0.0f;
+volatile float result_sub = 0.0f;
+volatile float result_mul = 0.0f;
+volatile float result_div = 0.0f;
+
+#define DECLARE_INPUT_SET(type, abbrev) \
+volatile type rand_##abbrev##1_0, rand_##abbrev##1_1; \
+volatile type##2 rand_##abbrev##2_0, rand_##abbrev##2_1; \
+volatile type##3 rand_##abbrev##3_0, rand_##abbrev##3_1; \
+volatile type##4 rand_##abbrev##4_0, rand_##abbrev##4_1;
+
+#define DECLARE_ALL_INPUT_SETS() \
+DECLARE_INPUT_SET(float, f); \
+DECLARE_INPUT_SET(char, sc); \
+DECLARE_INPUT_SET(uchar, uc); \
+DECLARE_INPUT_SET(short, ss); \
+DECLARE_INPUT_SET(ushort, us); \
+DECLARE_INPUT_SET(int, si); \
+DECLARE_INPUT_SET(uint, ui); \
+DECLARE_INPUT_SET(long, sl); \
+DECLARE_INPUT_SET(ulong, ul);
+
+DECLARE_ALL_INPUT_SETS();
+
+#define DECLARE_REFERENCE_SET_VEC_VEC(type, abbrev, func) \
+volatile type func##_rand_##abbrev##1_##abbrev##1; \
+volatile type##2 func##_rand_##abbrev##2_##abbrev##2; \
+volatile type##3 func##_rand_##abbrev##3_##abbrev##3; \
+volatile type##4 func##_rand_##abbrev##4_##abbrev##4;
+#define DECLARE_REFERENCE_SET_VEC_SCL(type, abbrev, func) \
+volatile type##2 func##_rand_##abbrev##2_##abbrev##1; \
+volatile type##3 func##_rand_##abbrev##3_##abbrev##1; \
+volatile type##4 func##_rand_##abbrev##4_##abbrev##1;
+
+#define DECLARE_ALL_REFERENCE_SETS_VEC_VEC(func) \
+DECLARE_REFERENCE_SET_VEC_VEC(float, f, func); \
+DECLARE_REFERENCE_SET_VEC_VEC(char, sc, func); \
+DECLARE_REFERENCE_SET_VEC_VEC(uchar, uc, func); \
+DECLARE_REFERENCE_SET_VEC_VEC(short, ss, func); \
+DECLARE_REFERENCE_SET_VEC_VEC(ushort, us, func); \
+DECLARE_REFERENCE_SET_VEC_VEC(int, si, func); \
+DECLARE_REFERENCE_SET_VEC_VEC(uint, ui, func); \
+DECLARE_REFERENCE_SET_VEC_VEC(long, sl, func); \
+DECLARE_REFERENCE_SET_VEC_VEC(ulong, ul, func);
+
+DECLARE_ALL_REFERENCE_SETS_VEC_VEC(min);
+DECLARE_ALL_REFERENCE_SETS_VEC_VEC(max);
+DECLARE_REFERENCE_SET_VEC_VEC(float, f, fmin);
+DECLARE_REFERENCE_SET_VEC_SCL(float, f, fmin);
+DECLARE_REFERENCE_SET_VEC_VEC(float, f, fmax);
+DECLARE_REFERENCE_SET_VEC_SCL(float, f, fmax);
+
+static void fail_f1(float v1, float v2, float actual, float expected, char *op_name) {
+ int dist = float_dist(actual, expected);
+ rsDebug("float operation did not match!", op_name);
+ rsDebug("v1", v1);
+ rsDebug("v2", v2);
+ rsDebug("Dalvik result", expected);
+ rsDebug("Renderscript result", actual);
+ rsDebug("ULP difference", dist);
+}
+
+static void fail_f2(float2 v1, float2 v2, float2 actual, float2 expected, char *op_name) {
+ int2 dist;
+ dist.x = float_dist(actual.x, expected.x);
+ dist.y = float_dist(actual.y, expected.y);
+ rsDebug("float2 operation did not match!", op_name);
+ rsDebug("v1.x", v1.x);
+ rsDebug("v1.y", v1.y);
+ rsDebug("v2.x", v2.x);
+ rsDebug("v2.y", v2.y);
+ rsDebug("Dalvik result .x", expected.x);
+ rsDebug("Dalvik result .y", expected.y);
+ rsDebug("Renderscript result .x", actual.x);
+ rsDebug("Renderscript result .y", actual.y);
+ rsDebug("ULP difference .x", dist.x);
+ rsDebug("ULP difference .y", dist.y);
+}
+
+static void fail_f3(float3 v1, float3 v2, float3 actual, float3 expected, char *op_name) {
+ int3 dist;
+ dist.x = float_dist(actual.x, expected.x);
+ dist.y = float_dist(actual.y, expected.y);
+ dist.z = float_dist(actual.z, expected.z);
+ rsDebug("float3 operation did not match!", op_name);
+ rsDebug("v1.x", v1.x);
+ rsDebug("v1.y", v1.y);
+ rsDebug("v1.z", v1.z);
+ rsDebug("v2.x", v2.x);
+ rsDebug("v2.y", v2.y);
+ rsDebug("v2.z", v2.z);
+ rsDebug("Dalvik result .x", expected.x);
+ rsDebug("Dalvik result .y", expected.y);
+ rsDebug("Dalvik result .z", expected.z);
+ rsDebug("Renderscript result .x", actual.x);
+ rsDebug("Renderscript result .y", actual.y);
+ rsDebug("Renderscript result .z", actual.z);
+ rsDebug("ULP difference .x", dist.x);
+ rsDebug("ULP difference .y", dist.y);
+ rsDebug("ULP difference .z", dist.z);
+}
+
+static void fail_f4(float4 v1, float4 v2, float4 actual, float4 expected, char *op_name) {
+ int4 dist;
+ dist.x = float_dist(actual.x, expected.x);
+ dist.y = float_dist(actual.y, expected.y);
+ dist.z = float_dist(actual.z, expected.z);
+ dist.w = float_dist(actual.w, expected.w);
+ rsDebug("float4 operation did not match!", op_name);
+ rsDebug("v1.x", v1.x);
+ rsDebug("v1.y", v1.y);
+ rsDebug("v1.z", v1.z);
+ rsDebug("v1.w", v1.w);
+ rsDebug("v2.x", v2.x);
+ rsDebug("v2.y", v2.y);
+ rsDebug("v2.z", v2.z);
+ rsDebug("v2.w", v2.w);
+ rsDebug("Dalvik result .x", expected.x);
+ rsDebug("Dalvik result .y", expected.y);
+ rsDebug("Dalvik result .z", expected.z);
+ rsDebug("Dalvik result .w", expected.w);
+ rsDebug("Renderscript result .x", actual.x);
+ rsDebug("Renderscript result .y", actual.y);
+ rsDebug("Renderscript result .z", actual.z);
+ rsDebug("Renderscript result .w", actual.w);
+ rsDebug("ULP difference .x", dist.x);
+ rsDebug("ULP difference .y", dist.y);
+ rsDebug("ULP difference .z", dist.z);
+ rsDebug("ULP difference .w", dist.w);
+}
+
+static bool f1_almost_equal(float a, float b) {
+ return float_almost_equal(a, b);
+}
+
+static bool f2_almost_equal(float2 a, float2 b) {
+ return float_almost_equal(a.x, b.x) && float_almost_equal(a.y, b.y);
+}
+
+
+static bool f3_almost_equal(float3 a, float3 b) {
+ return float_almost_equal(a.x, b.x) && float_almost_equal(a.y, b.y)
+ && float_almost_equal(a.z, b.z);
+}
+
+static bool f4_almost_equal(float4 a, float4 b) {
+ return float_almost_equal(a.x, b.x) && float_almost_equal(a.y, b.y)
+ && float_almost_equal(a.z, b.z) && float_almost_equal(a.w, b.w);
+}
+
+#define TEST_BASIC_FLOAT_OP(op, opName) \
+temp_f1 = x op y; \
+if (! float_almost_equal(temp_f1, result_##opName)) { \
+ fail_f1(x, y , temp_f1, result_##opName, #opName); \
+ failed = true; \
+}
+
+#define TEST_FN_FN(func, size) \
+temp_f##size = func(rand_f##size##_0, rand_f##size##_1); \
+if (! f##size##_almost_equal(temp_f##size , func##_rand_f##size##_f##size)) { \
+ fail_f##size (x, y , temp_f##size, func##_rand_f##size##_f##size, #func); \
+ failed = true; \
+}
+#define TEST_FN_F(func, size) \
+temp_f##size = func(rand_f##size##_0, rand_f1_1); \
+if (! f##size##_almost_equal(temp_f##size , func##_rand_f##size##_f1)) { \
+ fail_f##size (x, y , temp_f##size, func##_rand_f##size##_f1 , #func); \
+ failed = true; \
+}
+
+#define TEST_FN_FN_ALL(func) \
+TEST_FN_FN(func, 1) \
+TEST_FN_FN(func, 2) \
+TEST_FN_FN(func, 3) \
+TEST_FN_FN(func, 4)
+#define TEST_FN_F_ALL(func) \
+TEST_FN_F(func, 2) \
+TEST_FN_F(func, 3) \
+TEST_FN_F(func, 4)
+
+#define TEST_VEC1_VEC1(func, type) \
+temp_##type##1 = func( rand_##type##1_0, rand_##type##1_1 ); \
+if (temp_##type##1 != func##_rand_##type##1_##type##1) { \
+ rsDebug(#func " " #type "1 operation did not match!", 0); \
+ rsDebug("v1", rand_##type##1_0); \
+ rsDebug("v2", rand_##type##1_1); \
+ rsDebug("Dalvik result", func##_rand_##type##1_##type##1); \
+ rsDebug("Renderscript result", temp_##type##1); \
+ failed = true; \
+}
+#define TEST_VEC2_VEC2(func, type) \
+temp_##type##2 = func( rand_##type##2_0, rand_##type##2_1 ); \
+if (temp_##type##2 .x != func##_rand_##type##2_##type##2 .x \
+ || temp_##type##2 .y != func##_rand_##type##2_##type##2 .y) { \
+ rsDebug(#func " " #type "2 operation did not match!", 0); \
+ rsDebug("v1.x", rand_##type##2_0 .x); \
+ rsDebug("v1.y", rand_##type##2_0 .y); \
+ rsDebug("v2.x", rand_##type##2_1 .x); \
+ rsDebug("v2.y", rand_##type##2_1 .y); \
+ rsDebug("Dalvik result .x", func##_rand_##type##2_##type##2 .x); \
+ rsDebug("Dalvik result .y", func##_rand_##type##2_##type##2 .y); \
+ rsDebug("Renderscript result .x", temp_##type##2 .x); \
+ rsDebug("Renderscript result .y", temp_##type##2 .y); \
+ failed = true; \
+}
+#define TEST_VEC3_VEC3(func, type) \
+temp_##type##3 = func( rand_##type##3_0, rand_##type##3_1 ); \
+if (temp_##type##3 .x != func##_rand_##type##3_##type##3 .x \
+ || temp_##type##3 .y != func##_rand_##type##3_##type##3 .y \
+ || temp_##type##3 .z != func##_rand_##type##3_##type##3 .z) { \
+ rsDebug(#func " " #type "3 operation did not match!", 0); \
+ rsDebug("v1.x", rand_##type##3_0 .x); \
+ rsDebug("v1.y", rand_##type##3_0 .y); \
+ rsDebug("v1.z", rand_##type##3_0 .z); \
+ rsDebug("v2.x", rand_##type##3_1 .x); \
+ rsDebug("v2.y", rand_##type##3_1 .y); \
+ rsDebug("v2.z", rand_##type##3_1 .z); \
+ rsDebug("Dalvik result .x", func##_rand_##type##3_##type##3 .x); \
+ rsDebug("Dalvik result .y", func##_rand_##type##3_##type##3 .y); \
+ rsDebug("Dalvik result .z", func##_rand_##type##3_##type##3 .z); \
+ rsDebug("Renderscript result .x", temp_##type##3 .x); \
+ rsDebug("Renderscript result .y", temp_##type##3 .y); \
+ rsDebug("Renderscript result .z", temp_##type##3 .z); \
+ failed = true; \
+}
+#define TEST_VEC4_VEC4(func, type) \
+temp_##type##4 = func( rand_##type##4_0, rand_##type##4_1 ); \
+if (temp_##type##4 .x != func##_rand_##type##4_##type##4 .x \
+ || temp_##type##4 .y != func##_rand_##type##4_##type##4 .y \
+ || temp_##type##4 .z != func##_rand_##type##4_##type##4 .z \
+ || temp_##type##4 .w != func##_rand_##type##4_##type##4 .w) { \
+ rsDebug(#func " " #type "4 operation did not match!", 0); \
+ rsDebug("v1.x", rand_##type##4_0 .x); \
+ rsDebug("v1.y", rand_##type##4_0 .y); \
+ rsDebug("v1.z", rand_##type##4_0 .z); \
+ rsDebug("v1.w", rand_##type##4_0 .w); \
+ rsDebug("v2.x", rand_##type##4_1 .x); \
+ rsDebug("v2.y", rand_##type##4_1 .y); \
+ rsDebug("v2.z", rand_##type##4_1 .z); \
+ rsDebug("v2.w", rand_##type##4_1 .w); \
+ rsDebug("Dalvik result .x", func##_rand_##type##4_##type##4 .x); \
+ rsDebug("Dalvik result .y", func##_rand_##type##4_##type##4 .y); \
+ rsDebug("Dalvik result .z", func##_rand_##type##4_##type##4 .z); \
+ rsDebug("Dalvik result .w", func##_rand_##type##4_##type##4 .w); \
+ rsDebug("Renderscript result .x", temp_##type##4 .x); \
+ rsDebug("Renderscript result .y", temp_##type##4 .y); \
+ rsDebug("Renderscript result .z", temp_##type##4 .z); \
+ rsDebug("Renderscript result .w", temp_##type##4 .w); \
+ failed = true; \
+}
+
+#define TEST_SC1_SC1(func) TEST_VEC1_VEC1(func, sc)
+#define TEST_SC2_SC2(func) TEST_VEC2_VEC2(func, sc)
+#define TEST_SC3_SC3(func) TEST_VEC3_VEC3(func, sc)
+#define TEST_SC4_SC4(func) TEST_VEC4_VEC4(func, sc)
+
+#define TEST_UC1_UC1(func) TEST_VEC1_VEC1(func, uc)
+#define TEST_UC2_UC2(func) TEST_VEC2_VEC2(func, uc)
+#define TEST_UC3_UC3(func) TEST_VEC3_VEC3(func, uc)
+#define TEST_UC4_UC4(func) TEST_VEC4_VEC4(func, uc)
+
+#define TEST_SS1_SS1(func) TEST_VEC1_VEC1(func, ss)
+#define TEST_SS2_SS2(func) TEST_VEC2_VEC2(func, ss)
+#define TEST_SS3_SS3(func) TEST_VEC3_VEC3(func, ss)
+#define TEST_SS4_SS4(func) TEST_VEC4_VEC4(func, ss)
+
+#define TEST_US1_US1(func) TEST_VEC1_VEC1(func, us)
+#define TEST_US2_US2(func) TEST_VEC2_VEC2(func, us)
+#define TEST_US3_US3(func) TEST_VEC3_VEC3(func, us)
+#define TEST_US4_US4(func) TEST_VEC4_VEC4(func, us)
+
+#define TEST_SI1_SI1(func) TEST_VEC1_VEC1(func, si)
+#define TEST_SI2_SI2(func) TEST_VEC2_VEC2(func, si)
+#define TEST_SI3_SI3(func) TEST_VEC3_VEC3(func, si)
+#define TEST_SI4_SI4(func) TEST_VEC4_VEC4(func, si)
+
+#define TEST_UI1_UI1(func) TEST_VEC1_VEC1(func, ui)
+#define TEST_UI2_UI2(func) TEST_VEC2_VEC2(func, ui)
+#define TEST_UI3_UI3(func) TEST_VEC3_VEC3(func, ui)
+#define TEST_UI4_UI4(func) TEST_VEC4_VEC4(func, ui)
+
+#define TEST_SL1_SL1(func) TEST_VEC1_VEC1(func, sl)
+#define TEST_SL2_SL2(func) TEST_VEC2_VEC2(func, sl)
+#define TEST_SL3_SL3(func) TEST_VEC3_VEC3(func, sl)
+#define TEST_SL4_SL4(func) TEST_VEC4_VEC4(func, sl)
+
+#define TEST_UL1_UL1(func) TEST_VEC1_VEC1(func, ul)
+#define TEST_UL2_UL2(func) TEST_VEC2_VEC2(func, ul)
+#define TEST_UL3_UL3(func) TEST_VEC3_VEC3(func, ul)
+#define TEST_UL4_UL4(func) TEST_VEC4_VEC4(func, ul)
+
+#define TEST_SC_SC_ALL(func) \
+TEST_SC1_SC1(func) \
+TEST_SC2_SC2(func) \
+TEST_SC3_SC3(func) \
+TEST_SC4_SC4(func)
+#define TEST_UC_UC_ALL(func) \
+TEST_UC1_UC1(func) \
+TEST_UC2_UC2(func) \
+TEST_UC3_UC3(func) \
+TEST_UC4_UC4(func)
+
+#define TEST_SS_SS_ALL(func) \
+TEST_SS1_SS1(func) \
+TEST_SS2_SS2(func) \
+TEST_SS3_SS3(func) \
+TEST_SS4_SS4(func)
+#define TEST_US_US_ALL(func) \
+TEST_US1_US1(func) \
+TEST_US2_US2(func) \
+TEST_US3_US3(func) \
+TEST_US4_US4(func)
+#define TEST_SI_SI_ALL(func) \
+TEST_SI1_SI1(func) \
+TEST_SI2_SI2(func) \
+TEST_SI3_SI3(func) \
+TEST_SI4_SI4(func)
+#define TEST_UI_UI_ALL(func) \
+TEST_UI1_UI1(func) \
+TEST_UI2_UI2(func) \
+TEST_UI3_UI3(func) \
+TEST_UI4_UI4(func)
+#define TEST_SL_SL_ALL(func) \
+TEST_SL1_SL1(func) \
+TEST_SL2_SL2(func) \
+TEST_SL3_SL3(func) \
+TEST_SL4_SL4(func)
+#define TEST_UL_UL_ALL(func) \
+TEST_UL1_UL1(func) \
+TEST_UL2_UL2(func) \
+TEST_UL3_UL3(func) \
+TEST_UL4_UL4(func)
+
+#define TEST_VEC_VEC_ALL(func) \
+TEST_FN_FN_ALL(func) \
+TEST_SC_SC_ALL(func) \
+TEST_UC_UC_ALL(func) \
+TEST_SS_SS_ALL(func) \
+TEST_US_US_ALL(func) \
+TEST_SI_SI_ALL(func) \
+TEST_UI_UI_ALL(func) \
+TEST_SL_SL_ALL(func) \
+TEST_UL_UL_ALL(func)
+
+#define DECLARE_TEMP_SET(type, abbrev) \
+volatile type temp_##abbrev##1; \
+volatile type##2 temp_##abbrev##2; \
+volatile type##3 temp_##abbrev##3; \
+volatile type##4 temp_##abbrev##4;
+
+#define DECLARE_ALL_TEMP_SETS() \
+DECLARE_TEMP_SET(float, f); \
+DECLARE_TEMP_SET(char, sc); \
+DECLARE_TEMP_SET(uchar, uc); \
+DECLARE_TEMP_SET(short, ss); \
+DECLARE_TEMP_SET(ushort, us); \
+DECLARE_TEMP_SET(int, si); \
+DECLARE_TEMP_SET(uint, ui); \
+DECLARE_TEMP_SET(long, sl); \
+DECLARE_TEMP_SET(ulong, ul);
+
+static bool test_math_agree() {
+ bool failed = false;
+
+ DECLARE_ALL_TEMP_SETS();
+
+ TEST_BASIC_FLOAT_OP(+, add);
+ TEST_BASIC_FLOAT_OP(-, sub);
+ TEST_BASIC_FLOAT_OP(*, mul);
+ TEST_BASIC_FLOAT_OP(/, div);
+
+ TEST_VEC_VEC_ALL(min);
+ TEST_VEC_VEC_ALL(max);
+ TEST_FN_FN_ALL(fmin);
+ TEST_FN_F_ALL(fmin);
+ TEST_FN_FN_ALL(fmax);
+ TEST_FN_F_ALL(fmax);
+
+ if (failed) {
+ rsDebug("test_math_agree FAILED", 0);
+ }
+ else {
+ rsDebug("test_math_agree PASSED", 0);
+ }
+
+ return failed;
+}
+
+void math_agree_test() {
+ bool failed = false;
+ failed |= test_math_agree();
+
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/math_conformance.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/math_conformance.rs
new file mode 100644
index 0000000..402bbfe
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/math_conformance.rs
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+// Testing math conformance
+
+static bool test_rootn() {
+ bool failed = false;
+
+ // rootn(x, 0) -> +inf
+ _RS_ASSERT(isposinf(rootn(1.0f, 0)));
+
+ // rootn(+/-0, n) -> +/-inf for odd n < 0
+ _RS_ASSERT(isposinf(rootn(0.f, -3)));
+ _RS_ASSERT(isneginf(rootn(-0.f, -3)));
+
+ // rootn(+/-0, n) -> +inf for even n < 0
+ _RS_ASSERT(isposinf(rootn(0.f, -8)));
+ _RS_ASSERT(isposinf(rootn(-0.f, -8)));
+
+ // rootn(+/-0, n) -> +/-0 for odd n > 0
+ _RS_ASSERT(isposzero(rootn(0.f, 3)));
+ _RS_ASSERT(isnegzero(rootn(-0.f, 3)));
+
+ // rootn(+/-0, n) -> +0 for even n > 0
+ _RS_ASSERT(isposzero(rootn(0.f, 8)));
+ _RS_ASSERT(isposzero(rootn(-0.f, 8)));
+
+ // rootn(x, n) -> NaN for x < 0 and even n
+ _RS_ASSERT(isnan(rootn(-10000.f, -4)));
+ _RS_ASSERT(isnan(rootn(-10000.f, 4)));
+
+ // rootn(x, n) -> value for x < 0 and odd n
+ _RS_ASSERT(!isnan(rootn(-10000.f, -3)));
+ _RS_ASSERT(!isnan(rootn(-10000.f, 3)));
+
+ if (failed) {
+ rsDebug("test_rootn FAILED", -1);
+ }
+ else {
+ rsDebug("test_rootn PASSED", 0);
+ }
+
+ return failed;
+}
+
+void math_conformance_test() {
+ bool failed = false;
+ failed |= test_rootn();
+
+ if (failed) {
+ rsDebug("math_conformance_test FAILED", -1);
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsDebug("math_conformance_test PASSED", 0);
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/math_fp16.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/math_fp16.rs
new file mode 100644
index 0000000..04cd8d0
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/math_fp16.rs
@@ -0,0 +1,488 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+static volatile half h1;
+static volatile half2 h2;
+static volatile half3 h3;
+static volatile half4 h4;
+
+static volatile int i1;
+static volatile int2 i2;
+static volatile int3 i3;
+static volatile int4 i4;
+
+#define TEST_HN_FUNC_HN(fn) \
+ h1 = fn(h1); \
+ h2 = fn(h2); \
+ h3 = fn(h3); \
+ h4 = fn(h4);
+
+#define TEST_IN_FUNC_HN(fn) \
+ i1 = fn(h1); \
+ i2 = fn(h2); \
+ i3 = fn(h3); \
+ i4 = fn(h4);
+
+#define TEST_HN_FUNC_HN_HN(fn) \
+ h1 = fn(h1, h1); \
+ h2 = fn(h2, h2); \
+ h3 = fn(h3, h3); \
+ h4 = fn(h4, h4);
+
+#define TEST_HN_FUNC_HN_IN(fn) \
+ h1 = fn(h1, i1); \
+ h2 = fn(h2, i2); \
+ h3 = fn(h3, i3); \
+ h4 = fn(h4, i4);
+
+#define TEST_HN_FUNC_HN_PIN(fn) \
+ h1 = fn(h1, (int *) &i1); \
+ h2 = fn(h2, (int2 *) &i2); \
+ h3 = fn(h3, (int3 *) &i3); \
+ h4 = fn(h4, (int4 *) &i4);
+
+#define TEST_HN_FUNC_HN_I(fn) \
+ h1 = fn(h1, i1); \
+ h2 = fn(h2, i1); \
+ h3 = fn(h3, i1); \
+ h4 = fn(h4, i1);
+
+#define TEST_HN_FUNC_HN_H(fn) \
+ h1 = fn(h1, h1); \
+ h2 = fn(h2, h1); \
+ h3 = fn(h3, h1); \
+ h4 = fn(h4, h1);
+
+#define TEST_HN_FUNC_H_HN(fn) \
+ h1 = fn(h1, h1); \
+ h2 = fn(h1, h2); \
+ h3 = fn(h1, h3); \
+ h4 = fn(h1, h4); \
+
+#define TEST_HN_FUNC_HN_PHN(fn) \
+ h1 = fn(h1, (half *) &h1); \
+ h2 = fn(h2, (half2 *) &h2); \
+ h3 = fn(h3, (half3 *) &h3); \
+ h4 = fn(h4, (half4 *) &h4); \
+
+#define TEST_HN_FUNC_HN_HN_HN(fn) \
+ h1 = fn(h1, h1, h1); \
+ h2 = fn(h2, h2, h2); \
+ h3 = fn(h3, h3, h3); \
+ h4 = fn(h4, h4, h4);
+
+#define TEST_HN_FUNC_HN_HN_H(fn) \
+ h1 = fn(h1, h1, h1); \
+ h2 = fn(h2, h2, h1); \
+ h3 = fn(h3, h3, h1); \
+ h4 = fn(h4, h4, h1);
+
+#define TEST_HN_FUNC_HN_HN_PIN(fn) \
+ h1 = fn(h1, h1, (int *) &i1); \
+ h2 = fn(h2, h2, (int2 *) &i2); \
+ h3 = fn(h3, h3, (int3 *) &i3); \
+ h4 = fn(h4, h4, (int4 *) &i4);
+
+#define TEST_H_FUNC_HN(fn) \
+ h1 = fn(h1); \
+ h1 = fn(h2); \
+ h1 = fn(h3); \
+ h1 = fn(h4);
+
+#define TEST_H_FUNC_HN_HN(fn) \
+ h1 = fn(h1, h1); \
+ h1 = fn(h2, h2); \
+ h1 = fn(h3, h3); \
+ h1 = fn(h4, h4);
+
+static bool testAPI() {
+ TEST_HN_FUNC_HN(acos);
+ TEST_HN_FUNC_HN(acosh);
+ TEST_HN_FUNC_HN(acospi);
+
+ TEST_HN_FUNC_HN(asin);
+ TEST_HN_FUNC_HN(asinh);
+ TEST_HN_FUNC_HN(asinpi);
+
+ TEST_HN_FUNC_HN(atan);
+ TEST_HN_FUNC_HN_HN(atan2);
+ TEST_HN_FUNC_HN_HN(atan2pi);
+ TEST_HN_FUNC_HN(atanh);
+ TEST_HN_FUNC_HN(atanpi);
+
+ TEST_HN_FUNC_HN(cbrt);
+ TEST_HN_FUNC_HN(ceil);
+ TEST_HN_FUNC_HN_HN(copysign);
+
+ TEST_HN_FUNC_HN(cos);
+ TEST_HN_FUNC_HN(cosh);
+ TEST_HN_FUNC_HN(cospi);
+
+ TEST_HN_FUNC_HN(degrees);
+ TEST_HN_FUNC_HN(erf);
+ TEST_HN_FUNC_HN(erfc);
+ TEST_HN_FUNC_HN(exp);
+ TEST_HN_FUNC_HN(exp10);
+ TEST_HN_FUNC_HN(exp2);
+ TEST_HN_FUNC_HN(expm1);
+
+ TEST_HN_FUNC_HN(fabs);
+ TEST_HN_FUNC_HN_HN(fdim);
+ TEST_HN_FUNC_HN(floor);
+ TEST_HN_FUNC_HN_HN_HN(fma);
+
+ TEST_HN_FUNC_HN_HN(fmax);
+ TEST_HN_FUNC_HN_H(fmax);
+ TEST_HN_FUNC_HN_HN(fmin);
+ TEST_HN_FUNC_HN_H(fmin);
+ TEST_HN_FUNC_HN_HN(fmod);
+
+ TEST_HN_FUNC_HN(fract);
+ TEST_HN_FUNC_HN_PHN(fract);
+ TEST_HN_FUNC_HN_PIN(frexp);
+
+ TEST_HN_FUNC_HN_HN(hypot);
+ TEST_IN_FUNC_HN(ilogb);
+ TEST_HN_FUNC_HN_IN(ldexp);
+ TEST_HN_FUNC_HN_I(ldexp);
+ TEST_HN_FUNC_HN(lgamma);
+ TEST_HN_FUNC_HN_PIN(lgamma);
+
+ TEST_HN_FUNC_HN(log);
+ TEST_HN_FUNC_HN(log10);
+ TEST_HN_FUNC_HN(log1p);
+ TEST_HN_FUNC_HN(log2);
+ TEST_HN_FUNC_HN(logb);
+
+ TEST_HN_FUNC_HN_HN_HN(mad);
+ TEST_HN_FUNC_HN_HN(max);
+ TEST_HN_FUNC_HN_H(max);
+ TEST_HN_FUNC_HN_HN(min);
+ TEST_HN_FUNC_HN_H(min);
+ TEST_HN_FUNC_HN_HN_HN(mix);
+ TEST_HN_FUNC_HN_HN_H(mix);
+ TEST_HN_FUNC_HN_PHN(modf);
+
+ h1 = nan_half();
+
+ TEST_HN_FUNC_HN(native_acos);
+ TEST_HN_FUNC_HN(native_acosh);
+ TEST_HN_FUNC_HN(native_acospi);
+
+ TEST_HN_FUNC_HN(native_asin);
+ TEST_HN_FUNC_HN(native_asinh);
+ TEST_HN_FUNC_HN(native_asinpi);
+
+ TEST_HN_FUNC_HN(native_atan);
+ TEST_HN_FUNC_HN_HN(native_atan2);
+ TEST_HN_FUNC_HN_HN(native_atan2pi);
+ TEST_HN_FUNC_HN(native_atanh);
+ TEST_HN_FUNC_HN(native_atanpi);
+
+ TEST_HN_FUNC_HN(native_cbrt);
+ TEST_HN_FUNC_HN(native_cos);
+ TEST_HN_FUNC_HN(native_cosh);
+ TEST_HN_FUNC_HN(native_cospi);
+
+ TEST_HN_FUNC_HN_HN(native_divide);
+ TEST_HN_FUNC_HN(native_exp);
+ TEST_HN_FUNC_HN(native_exp10);
+ TEST_HN_FUNC_HN(native_exp2);
+ TEST_HN_FUNC_HN(native_expm1);
+
+ TEST_HN_FUNC_HN_HN(native_hypot);
+ TEST_H_FUNC_HN(native_length);
+ TEST_HN_FUNC_HN(native_log);
+ TEST_HN_FUNC_HN(native_log10);
+ TEST_HN_FUNC_HN(native_log1p);
+ TEST_HN_FUNC_HN(native_log2);
+
+ TEST_HN_FUNC_HN_HN(native_powr);
+ TEST_HN_FUNC_HN(native_recip);
+ TEST_HN_FUNC_HN_IN(native_rootn);
+ TEST_HN_FUNC_HN(native_rsqrt);
+
+ TEST_HN_FUNC_HN(native_sin);
+ TEST_HN_FUNC_HN_PHN(native_sincos);
+ TEST_HN_FUNC_HN(native_sinh);
+ TEST_HN_FUNC_HN(native_sinpi);
+
+ TEST_HN_FUNC_HN(native_tan);
+ TEST_HN_FUNC_HN(native_tanh);
+ TEST_HN_FUNC_HN(native_tanpi);
+
+ TEST_HN_FUNC_HN_HN(nextafter);
+ TEST_HN_FUNC_HN_HN(pow);
+ TEST_HN_FUNC_HN_IN(pown);
+ TEST_HN_FUNC_HN_HN(powr);
+
+ TEST_HN_FUNC_HN(radians);
+ TEST_HN_FUNC_HN_HN(remainder);
+ TEST_HN_FUNC_HN_HN_PIN(remquo);
+ TEST_HN_FUNC_HN(rint);
+ TEST_HN_FUNC_HN_IN(rootn);
+ TEST_HN_FUNC_HN(round);
+ TEST_HN_FUNC_HN(rsqrt);
+
+ TEST_HN_FUNC_HN(sign);
+ TEST_HN_FUNC_HN(sin);
+ TEST_HN_FUNC_HN_PHN(sincos);
+ TEST_HN_FUNC_HN(sinh);
+ TEST_HN_FUNC_HN(sinpi);
+ TEST_HN_FUNC_HN(sqrt);
+
+ TEST_HN_FUNC_HN_HN(step);
+ TEST_HN_FUNC_HN_H(step);
+ TEST_HN_FUNC_H_HN(step);
+
+ TEST_HN_FUNC_HN(tan);
+ TEST_HN_FUNC_HN(tanh);
+ TEST_HN_FUNC_HN(tanpi);
+
+ TEST_HN_FUNC_HN(tgamma);
+ TEST_HN_FUNC_HN(trunc);
+
+ // Vector math functions
+ h3 = cross(h3, h3);
+ h4 = cross(h4, h4);
+
+ TEST_H_FUNC_HN_HN(distance);
+ TEST_H_FUNC_HN_HN(dot);
+ TEST_H_FUNC_HN(length);
+ TEST_H_FUNC_HN_HN(native_distance);
+ TEST_H_FUNC_HN(native_length);
+ TEST_HN_FUNC_HN(native_normalize);
+ TEST_HN_FUNC_HN(normalize);
+ return true;
+}
+
+typedef union {
+ half hval;
+ short sval;
+} fp16_shape_type;
+
+/* half h = unsigned short s; */
+#define SET_HALF_WORD(h, s) \
+do { \
+ fp16_shape_type fp16_u; \
+ fp16_u.sval = (s); \
+ (h) = fp16_u.hval; \
+} while (0)
+
+#define VALIDATE_FREXP_HALF(inp, ref, refExp) \
+do { \
+ int exp; \
+ half out = frexp(((half) inp), &exp); \
+ _RS_ASSERT_EQU(out, ((half) ref)); \
+ _RS_ASSERT_EQU(exp, (refExp)); \
+} while (0);
+
+static bool testFrexp() {
+ bool failed= false;
+
+ VALIDATE_FREXP_HALF(0, 0, 0);
+ VALIDATE_FREXP_HALF(-0, -0, 0);
+ VALIDATE_FREXP_HALF(1, 0.5, 1);
+ VALIDATE_FREXP_HALF(0.25, 0.5, -1);
+ VALIDATE_FREXP_HALF(1.5, 0.75, 1);
+ VALIDATE_FREXP_HALF(1.99, 0.995, 1);
+
+ return !failed;
+}
+
+// Place sentinel values around the *intPart paramter to modf to ensure that
+// the call writes to just the 2 bytes pointed-to by the paramter.
+#define VALIDATE_MODF_HALF(inp, ref, refIntPart) \
+do { \
+ half intPart[3]; \
+ intPart[0] = (half) 42.0f; \
+ intPart[2] = (half) 3.14f; \
+ half out = modf(((half) inp), &intPart[1]); \
+ _RS_ASSERT_EQU(out, ((half) ref)); \
+ _RS_ASSERT_EQU(intPart[1], ((half) refIntPart)); \
+ _RS_ASSERT_EQU(intPart[0], (half) 42.0f); \
+ _RS_ASSERT_EQU(intPart[2], (half) 3.14f); \
+} while (0);
+
+static bool testModf() {
+ bool failed = false;
+
+ VALIDATE_MODF_HALF(0.5, 0.5, 0.0);
+ VALIDATE_MODF_HALF(1.5, 0.5, 1.0);
+ VALIDATE_MODF_HALF(100.5625, 0.5625, 100.0);
+
+ VALIDATE_MODF_HALF(-0.5, -0.5, -0.0);
+ VALIDATE_MODF_HALF(-1.5, -0.5, -1.0);
+ VALIDATE_MODF_HALF(-100.5625, -0.5625, -100.0);
+
+ return !failed;
+}
+
+static bool testNextAfter() {
+ half zero, minSubNormal, maxSubNormal, minNormal, infinity;
+ half negativeZero, negativeInfinity;
+ half negativeMinSubNormal, negativeMaxSubNormal, negativeMinNormal;
+
+ // TODO Define these constants so the SET_HALF_WORD macro is unnecessary.
+ SET_HALF_WORD(zero, 0x0000);
+ SET_HALF_WORD(minSubNormal, 0x0001);
+ SET_HALF_WORD(maxSubNormal, 0x03ff);
+ SET_HALF_WORD(minNormal, 0x0400);
+ SET_HALF_WORD(infinity, 0x7c00);
+
+ SET_HALF_WORD(negativeZero, 0x7000);
+ SET_HALF_WORD(negativeMinSubNormal, 0x8001);
+ SET_HALF_WORD(negativeMaxSubNormal, 0x83ff);
+ SET_HALF_WORD(negativeMinNormal, 0x8400);
+ SET_HALF_WORD(negativeInfinity, 0xfc00);
+
+ // Number of normal fp16 values:
+ // All-zero exponent is for zero and subnormals. All-one exponent is for
+ // Infinity and NaN. Hence number of possible values for exponent = 30
+ //
+ // No. of possible values for mantissa = 2 ^ 10 = 1024
+ //
+ // Number of positive, non-zero and normal fp16 values = 30 * 1024 = 30720
+ // Number of negative, non-zero and normal fp16 values = 30 * 1024 = 30720
+ //
+ // The following tests call nextafter in a loop starting at infinity
+ // towards the smallest normal and vice versa (for +ve and -ve) and verify
+ // that the number of loop iterations is 30720.
+
+ const unsigned int numDistinctExpected = 30720;
+ const unsigned int maxSteps = 31000;
+
+ unsigned int numDistinct;
+ half h, toward;
+
+ for (h = minNormal, toward = infinity, numDistinct = 0;
+ numDistinct < maxSteps && h != toward; numDistinct ++) {
+ h = nextafter(h, toward);
+ }
+ if (numDistinct != numDistinctExpected)
+ return false;
+
+ for (h = infinity, toward = minNormal, numDistinct = 0;
+ numDistinct < maxSteps && h != toward; numDistinct ++) {
+ h = nextafter(h, toward);
+ }
+ if (numDistinct != numDistinctExpected)
+ return false;
+
+ for (h = negativeMinNormal, toward = negativeInfinity, numDistinct = 0;
+ numDistinct < maxSteps && h != toward; numDistinct ++) {
+ h = nextafter(h, toward);
+ }
+ if (numDistinct != numDistinctExpected)
+ return false;
+
+ for (h = negativeInfinity, toward = negativeMinNormal, numDistinct = 0;
+ numDistinct < maxSteps && h != toward; numDistinct ++) {
+ h = nextafter(h, toward);
+ }
+ if (numDistinct != numDistinctExpected)
+ return false;
+
+ // Test nextafter at the boundary of subnormal numbers. Since RenderScript
+ // doesn't require implementations to handle FP16 subnormals correctly,
+ // allow nextafter to return a valid normal number that satisfies the
+ // constraints of nextafter.
+
+ // nextafter(0, infinity) = minnormal or minsubnormal
+ h = nextafter(zero, infinity);
+ if (h != minSubNormal && h != minNormal)
+ return false;
+ h = nextafter(zero, negativeInfinity);
+ if (h != negativeMinSubNormal && h != negativeMinNormal)
+ return false;
+
+ // nextafter(minNormal, negativeInfinity) = maxSubNormal or zero
+ h = nextafter(minNormal, negativeInfinity);
+ if (h != maxSubNormal && h != zero)
+ return false;
+ h = nextafter(negativeMinNormal, infinity);
+ if (h != negativeMaxSubNormal && h != negativeZero)
+ return false;
+
+ return true;
+}
+
+static bool testIlogb() {
+ bool failed = false;
+
+ // Test ilogb for 0, +/- infininty and NaN
+ half infinity, negativeInfinity;
+ SET_HALF_WORD(infinity, 0x7c00);
+ SET_HALF_WORD(negativeInfinity, 0xfc00);
+
+ _RS_ASSERT_EQU(ilogb((half) 0), 0x80000000);
+ _RS_ASSERT_EQU(ilogb((half) -0), 0x80000000);
+ _RS_ASSERT_EQU(ilogb(infinity), 0x7fffffff);
+ _RS_ASSERT_EQU(ilogb(negativeInfinity), 0x7fffffff);
+ _RS_ASSERT_EQU(ilogb(nan_half()), 0x7fffffff);
+
+ // ilogb(2^n) = n. Test at the boundary on either side of 2^n.
+ // Don't test subnormal numbers as implementations are not expected to
+ // handle them.
+ _RS_ASSERT_EQU(ilogb((half) 0.24), -3);
+ _RS_ASSERT_EQU(ilogb((half) 0.26), -2);
+ _RS_ASSERT_EQU(ilogb((half) 0.49), -2);
+ _RS_ASSERT_EQU(ilogb((half) 0.51), -1);
+ _RS_ASSERT_EQU(ilogb((half) 0.99), -1);
+ _RS_ASSERT_EQU(ilogb((half) 1.01), 0);
+ _RS_ASSERT_EQU(ilogb((half) 1.99), 0);
+ _RS_ASSERT_EQU(ilogb((half) 2.01), 1);
+ _RS_ASSERT_EQU(ilogb((half) 1023), 9);
+ _RS_ASSERT_EQU(ilogb((half) 1025), 10);
+
+ // Result is same irrespective of sign.
+ _RS_ASSERT_EQU(ilogb((half) -0.24), -3);
+ _RS_ASSERT_EQU(ilogb((half) -0.26), -2);
+ _RS_ASSERT_EQU(ilogb((half) -0.49), -2);
+ _RS_ASSERT_EQU(ilogb((half) -0.51), -1);
+ _RS_ASSERT_EQU(ilogb((half) -0.99), -1);
+ _RS_ASSERT_EQU(ilogb((half) -1.01), 0);
+ _RS_ASSERT_EQU(ilogb((half) -1.99), 0);
+ _RS_ASSERT_EQU(ilogb((half) -2.01), 1);
+ _RS_ASSERT_EQU(ilogb((half) -1023), 9);
+ _RS_ASSERT_EQU(ilogb((half) -1025), 10);
+
+ return !failed;
+}
+
+void testFp16Math() {
+ bool success = true;
+
+ success &= testAPI();
+ success &= testFrexp();
+ success &= testModf();
+ success &= testNextAfter();
+ success &= testIlogb();
+
+ if (success) {
+ rsDebug("PASSED", 0);
+ } else {
+ rsDebug("FAILED", 0);
+ }
+
+ if (success) {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ } else {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/min.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/min.rs
new file mode 100644
index 0000000..5833a29
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/min.rs
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+#pragma rs_fp_relaxed
+
+volatile uchar2 res_uc_2 = 1;
+volatile uchar2 src1_uc_2 = 1;
+volatile uchar2 src2_uc_2 = 1;
+
+void min_test() {
+ bool failed = false;
+
+ res_uc_2 = min(src1_uc_2, src2_uc_2);
+
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/noroot.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/noroot.rs
new file mode 100644
index 0000000..d850c86
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/noroot.rs
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+rs_allocation aRaw;
+int dimX;
+int dimY;
+static bool failed = false;
+
+void foo(const int *in, int *out, uint32_t x, uint32_t y) {
+ *out = 99 + x + y * dimX;
+}
+
+static bool test_foo_output() {
+ bool failed = false;
+ int i, j;
+
+ for (j = 0; j < dimY; j++) {
+ for (i = 0; i < dimX; i++) {
+ int v = rsGetElementAt_int(aRaw, i, j);
+ _RS_ASSERT(v == (99 + i + j * dimX));
+ }
+ }
+
+ if (failed) {
+ rsDebug("test_foo_output FAILED", 0);
+ }
+ else {
+ rsDebug("test_foo_output PASSED", 0);
+ }
+
+ return failed;
+}
+
+void verify_foo() {
+ failed |= test_foo_output();
+}
+
+void noroot_test() {
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/primitives.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/primitives.rs
new file mode 100644
index 0000000..290a28d
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/primitives.rs
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+// Testing primitive types
+float floatTest = 1.99f;
+double doubleTest = 2.05;
+char charTest = -8;
+short shortTest = -16;
+int intTest = -32;
+long longTest = 17179869184l; // 1 << 34
+long long longlongTest = 68719476736l; // 1 << 36
+
+uchar ucharTest = 8;
+ushort ushortTest = 16;
+uint uintTest = 32;
+ulong ulongTest = 4611686018427387904L;
+int64_t int64_tTest = -17179869184l; // - 1 << 34
+uint64_t uint64_tTest = 117179869184l;
+
+static bool test_primitive_types(uint32_t index) {
+ bool failed = false;
+ start();
+
+ _RS_ASSERT(floatTest == 2.99f);
+ _RS_ASSERT(doubleTest == 3.05);
+ _RS_ASSERT(charTest == -16);
+ _RS_ASSERT(shortTest == -32);
+ _RS_ASSERT(intTest == -64);
+ _RS_ASSERT(longTest == 17179869185l);
+ _RS_ASSERT(longlongTest == 68719476735l);
+
+ _RS_ASSERT(ucharTest == 8);
+ _RS_ASSERT(ushortTest == 16);
+ _RS_ASSERT(uintTest == 32);
+ _RS_ASSERT(ulongTest == 4611686018427387903L);
+ _RS_ASSERT(int64_tTest == -17179869184l);
+ _RS_ASSERT(uint64_tTest == 117179869185l);
+
+ float time = end(index);
+
+ if (failed) {
+ rsDebug("test_primitives FAILED", time);
+ }
+ else {
+ rsDebug("test_primitives PASSED", time);
+ }
+
+ return failed;
+}
+
+void primitives_test(uint32_t index, int test_num) {
+ bool failed = false;
+ failed |= test_primitive_types(index);
+
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/reduce.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/reduce.rs
new file mode 100644
index 0000000..cff0b85
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/reduce.rs
@@ -0,0 +1,356 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+// Has the same kernels as reduce_backward.rs, plus some others.
+//
+// This test case places the pragmas before the functions (forward
+// reference), and the other test case places the pragmas after the
+// functions (backward reference).
+
+float negInf, posInf;
+
+static bool IsNaN(float v) {
+ // a NaN (and only a NaN) compares unequal to everything
+ return v != v;
+}
+
+/////////////////////////////////////////////////////////////////////////
+
+#pragma rs reduce(addint) \
+ accumulator(aiAccum)
+
+static void aiAccum(int *accum, int val) { *accum += val; }
+
+/////////////////////////////////////////////////////////////////////////
+
+// These kernels find an input value of minimum absolute value.
+//
+// If the input domain consists of all non-NaN values (including
+// infinities), we cannot pick an initializer from the input domain,
+// because there are two different members of the domain with maximum
+// absolute value -- positive and negative infinity. Instead, we need
+// to pick some other distinguished initializer, and explicitly check
+// for and handle an accumulator with this distinguished value.
+//
+// The two kernels represent the distinguished value differently.
+
+//.......................................................................
+
+// The kernel findMinAbsNaN uses an initializer from outside the input
+// domain that is nonetheless representable as a float -- NaN.
+
+#pragma rs reduce(findMinAbsNaN) \
+ initializer(fMinAbsNaNInit) accumulator(fMinAbsNaNAccumulator) combiner(fMinAbsNaNCombiner)
+
+static void fMinAbsNaNInit(float *accum) {
+ *accum = nan(0);
+}
+
+static void fMinAbsNaNAccumulator(float *accum, float val) {
+ if (IsNaN(*accum) || (fabs(val) < fabs(*accum)))
+ *accum = val;
+}
+
+static void fMinAbsNaNCombiner(float *accum, const float *other) {
+ if (!IsNaN(*other))
+ fMinAbsNaNAccumulator(accum, *other);
+}
+
+//.......................................................................
+
+// The kernel findMinAbsBool represents its accumulator as a struct
+// with two fields -- a bool field to indicate whether or not the
+// accumulator has the distinguished initial value, and a float field
+// for a non-initial value.
+
+typedef struct FindMinAbsBoolAccumType {
+ // set to true by initializer function;
+ // set to false by accumulator function
+ bool onlyInitialized;
+ // only valid when onlyInitialized is false
+ float val;
+} FindMinAbsBoolAccumType;
+
+#pragma rs reduce(findMinAbsBool) \
+ initializer(fMinAbsBoolInit) accumulator(fMinAbsBoolAccumulator) combiner(fMinAbsBoolCombiner) \
+ outconverter(fMinAbsBoolOut)
+
+static void fMinAbsBoolInit(FindMinAbsBoolAccumType *accum) {
+ accum->onlyInitialized = true;
+}
+
+static void fMinAbsBoolAccumulator(FindMinAbsBoolAccumType *accum, float val) {
+ if (accum->onlyInitialized || (fabs(val) < fabs(accum->val)))
+ accum->val = val;
+ accum->onlyInitialized = false;
+}
+
+static void fMinAbsBoolCombiner(FindMinAbsBoolAccumType *accum, const FindMinAbsBoolAccumType *other) {
+ if (!other->onlyInitialized)
+ fMinAbsBoolAccumulator(accum, other->val);
+}
+
+static void fMinAbsBoolOut(float *out, const FindMinAbsBoolAccumType *accum) {
+ *out = accum->val;
+}
+
+/////////////////////////////////////////////////////////////////////////
+
+#pragma rs reduce(findMinAndMax) \
+ initializer(fMMInit) accumulator(fMMAccumulator) \
+ combiner(fMMCombiner) outconverter(fMMOutConverter)
+
+typedef struct {
+ float val;
+ int idx;
+} IndexedVal;
+
+typedef struct {
+ IndexedVal min, max;
+} MinAndMax;
+
+static void fMMInit(MinAndMax *accum) {
+ accum->min.val = posInf;
+ accum->min.idx = -1;
+ accum->max.val = negInf;
+ accum->max.idx = -1;
+}
+
+static void fMMAccumulator(MinAndMax *accum, float in, int x) {
+ IndexedVal me;
+ me.val = in;
+ me.idx = x;
+
+ if (me.val <= accum->min.val)
+ accum->min = me;
+ if (me.val >= accum->max.val)
+ accum->max = me;
+}
+
+static void fMMCombiner(MinAndMax *accum,
+ const MinAndMax *val) {
+ if ((accum->min.idx < 0) || (val->min.val < accum->min.val))
+ accum->min = val->min;
+ if ((accum->max.idx < 0) || (val->max.val > accum->max.val))
+ accum->max = val->max;
+}
+
+static void fMMOutConverter(int2 *result,
+ const MinAndMax *val) {
+ result->x = val->min.idx;
+ result->y = val->max.idx;
+}
+
+/////////////////////////////////////////////////////////////////////////
+
+#pragma rs reduce(fz) \
+ initializer(fzInit) \
+ accumulator(fzAccum) combiner(fzCombine)
+
+static void fzInit(int *accumIdx) { *accumIdx = -1; }
+
+static void fzAccum(int *accumIdx,
+ int inVal, int x /* special arg */) {
+ if (inVal==0) *accumIdx = x;
+}
+
+static void fzCombine(int *accumIdx, const int *accumIdx2) {
+ if (*accumIdx2 >= 0) *accumIdx = *accumIdx2;
+}
+
+/////////////////////////////////////////////////////////////////////////
+
+#pragma rs reduce(fz2) \
+ initializer(fz2Init) \
+ accumulator(fz2Accum) combiner(fz2Combine)
+
+static void fz2Init(int2 *accum) { accum->x = accum->y = -1; }
+
+static void fz2Accum(int2 *accum,
+ int inVal,
+ int x /* special arg */,
+ int y /* special arg */) {
+ if (inVal==0) {
+ accum->x = x;
+ accum->y = y;
+ }
+}
+
+static void fz2Combine(int2 *accum, const int2 *accum2) {
+ if (accum2->x >= 0) *accum = *accum2;
+}
+
+/////////////////////////////////////////////////////////////////////////
+
+#pragma rs reduce(fz3) \
+ initializer(fz3Init) \
+ accumulator(fz3Accum) combiner(fz3Combine)
+
+static void fz3Init(int3 *accum) { accum->x = accum->y = accum->z = -1; }
+
+static void fz3Accum(int3 *accum,
+ int inVal,
+ int x /* special arg */,
+ int y /* special arg */,
+ int z /* special arg */) {
+ if (inVal==0) {
+ accum->x = x;
+ accum->y = y;
+ accum->z = z;
+ }
+}
+
+static void fz3Combine(int3 *accum, const int3 *accum2) {
+ if (accum2->x >= 0) *accum = *accum2;
+}
+
+/////////////////////////////////////////////////////////////////////////
+
+#pragma rs reduce(histogram) \
+ accumulator(hsgAccum) combiner(hsgCombine)
+
+#define BUCKETS 256
+typedef uint32_t Histogram[BUCKETS];
+
+static void hsgAccum(Histogram *h, uchar in) { ++(*h)[in]; }
+
+static void hsgCombine(Histogram *accum, const Histogram *addend) {
+ for (int i = 0; i < BUCKETS; ++i)
+ (*accum)[i] += (*addend)[i];
+}
+
+#pragma rs reduce(mode) \
+ accumulator(hsgAccum) combiner(hsgCombine) \
+ outconverter(modeOutConvert)
+
+static void modeOutConvert(int2 *result, const Histogram *h) {
+ uint32_t mode = 0;
+ for (int i = 1; i < BUCKETS; ++i)
+ if ((*h)[i] > (*h)[mode]) mode = i;
+ result->x = mode;
+ result->y = (*h)[mode];
+}
+
+/////////////////////////////////////////////////////////////////////////
+
+#pragma rs reduce(sumgcd) accumulator(sgAccum) combiner(sgCombine)
+
+static int gcd(int a, int b) {
+ while (b != 0) {
+ const int aNew = b;
+ const int bNew = a % b;
+
+ a = aNew;
+ b = bNew;
+ }
+ return a;
+}
+
+static void sgAccum(long *accum, int a, int b) {
+ *accum += gcd(a, b);
+}
+
+static void sgCombine(long *accum, const long *other) { *accum += *other; }
+
+/////////////////////////////////////////////////////////////////////////
+
+// These two kernels have anonymous result types that are equivalent.
+// slang doesn't common them (i.e., each gets its own RSExportType);
+// so Java reflection must guard against this to avoid creating two
+// copies of the text that defines the reflected class resultArray4_int.
+
+#pragma rs reduce(sillySumIntoDecArray) accumulator(aiAccum) outconverter(outSillySumIntoDecArray)
+static void outSillySumIntoDecArray(int (*out)[4], const int *accumDatum) {
+ for (int i = 0; i < 4; ++i)
+ (*out)[i] = (*accumDatum)/(i+1);
+}
+
+#pragma rs reduce(sillySumIntoIncArray) accumulator(aiAccum) outconverter(outSillySumIntoIncArray)
+static void outSillySumIntoIncArray(int (*out)[4], const int *accumDatum) {
+ for (int i = 0; i < 4; ++i)
+ (*out)[i] = (*accumDatum)/(4-i);
+}
+
+/////////////////////////////////////////////////////////////////////////
+
+// finds min values (not their locations) from matrix input
+
+// tests matrix input and matrix accumulator
+
+// also tests calling conventions for two different composite types
+// rs_matrix2x2: 32-bit coerces this to an int array
+// 64-bit coerces this to float array
+// rs_matrix4x4: 64-bit passes this by reference
+
+//.......................................................................
+
+#pragma rs reduce(findMinMat2) \
+ initializer(fMinMat2Init) accumulator(fMinMat2Accumulator) \
+ outconverter(fMinMat2OutConverter)
+
+static void fMinMat2Init(rs_matrix2x2 *accum) {
+ for (int i = 0; i < 2; ++i)
+ for (int j = 0; j < 2; ++j)
+ rsMatrixSet(accum, i, j, posInf);
+}
+
+static void fMinMat2Accumulator(rs_matrix2x2 *accum, rs_matrix2x2 val) {
+ for (int i = 0; i < 2; ++i) {
+ for (int j = 0; j < 2; ++j) {
+ const float accumElt = rsMatrixGet(accum, i, j);
+ const float valElt = rsMatrixGet(&val, i, j);
+ if (valElt < accumElt)
+ rsMatrixSet(accum, i, j, valElt);
+ }
+ }
+}
+
+// reduction does not support matrix result, so use array instead
+static void fMinMat2OutConverter(float (*result)[4], const rs_matrix2x2 *accum) {
+ for (int i = 0; i < 4; ++i)
+ (*result)[i] = accum->m[i];
+}
+
+//.......................................................................
+
+#pragma rs reduce(findMinMat4) \
+ initializer(fMinMat4Init) accumulator(fMinMat4Accumulator) \
+ outconverter(fMinMat4OutConverter)
+
+static void fMinMat4Init(rs_matrix4x4 *accum) {
+ for (int i = 0; i < 4; ++i)
+ for (int j = 0; j < 4; ++j)
+ rsMatrixSet(accum, i, j, posInf);
+}
+
+static void fMinMat4Accumulator(rs_matrix4x4 *accum, rs_matrix4x4 val) {
+ for (int i = 0; i < 4; ++i) {
+ for (int j = 0; j < 4; ++j) {
+ const float accumElt = rsMatrixGet(accum, i, j);
+ const float valElt = rsMatrixGet(&val, i, j);
+ if (valElt < accumElt)
+ rsMatrixSet(accum, i, j, valElt);
+ }
+ }
+}
+
+// reduction does not support matrix result, so use array instead
+static void fMinMat4OutConverter(float (*result)[16], const rs_matrix4x4 *accum) {
+ for (int i = 0; i < 16; ++i)
+ (*result)[i] = accum->m[i];
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/reduce_backward.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/reduce_backward.rs
new file mode 100644
index 0000000..ab4ff33
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/reduce_backward.rs
@@ -0,0 +1,169 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+// Has a subset of the kernels from reduce.rs.
+//
+// This test case places the pragmas after the functions (backward
+// reference), and the other test case places the pragmas before the
+// functions (forward reference).
+
+float negInf, posInf;
+
+/////////////////////////////////////////////////////////////////////////
+
+static void aiAccum(int *accum, int val) { *accum += val; }
+
+#pragma rs reduce(addint) \
+ accumulator(aiAccum)
+
+/////////////////////////////////////////////////////////////////////////
+
+typedef struct {
+ float val;
+ int idx;
+} IndexedVal;
+
+typedef struct {
+ IndexedVal min, max;
+} MinAndMax;
+
+static void fMMInit(MinAndMax *accum) {
+ accum->min.val = posInf;
+ accum->min.idx = -1;
+ accum->max.val = negInf;
+ accum->max.idx = -1;
+}
+
+static void fMMAccumulator(MinAndMax *accum, float in, int x) {
+ IndexedVal me;
+ me.val = in;
+ me.idx = x;
+
+ if (me.val <= accum->min.val)
+ accum->min = me;
+ if (me.val >= accum->max.val)
+ accum->max = me;
+}
+
+static void fMMCombiner(MinAndMax *accum,
+ const MinAndMax *val) {
+ if ((accum->min.idx < 0) || (val->min.val < accum->min.val))
+ accum->min = val->min;
+ if ((accum->max.idx < 0) || (val->max.val > accum->max.val))
+ accum->max = val->max;
+}
+
+static void fMMOutConverter(int2 *result,
+ const MinAndMax *val) {
+ result->x = val->min.idx;
+ result->y = val->max.idx;
+}
+
+#pragma rs reduce(findMinAndMax) \
+ initializer(fMMInit) accumulator(fMMAccumulator) \
+ combiner(fMMCombiner) outconverter(fMMOutConverter)
+
+/////////////////////////////////////////////////////////////////////////
+
+static void fzInit(int *accumIdx) { *accumIdx = -1; }
+
+static void fzAccum(int *accumIdx,
+ int inVal, int x /* special arg */) {
+ if (inVal==0) *accumIdx = x;
+}
+
+static void fzCombine(int *accumIdx, const int *accumIdx2) {
+ if (*accumIdx2 >= 0) *accumIdx = *accumIdx2;
+}
+
+#pragma rs reduce(fz) \
+ initializer(fzInit) \
+ accumulator(fzAccum) combiner(fzCombine)
+
+/////////////////////////////////////////////////////////////////////////
+
+static void fz2Init(int2 *accum) { accum->x = accum->y = -1; }
+
+static void fz2Accum(int2 *accum,
+ int inVal,
+ int x /* special arg */,
+ int y /* special arg */) {
+ if (inVal==0) {
+ accum->x = x;
+ accum->y = y;
+ }
+}
+
+static void fz2Combine(int2 *accum, const int2 *accum2) {
+ if (accum2->x >= 0) *accum = *accum2;
+}
+
+#pragma rs reduce(fz2) \
+ initializer(fz2Init) \
+ accumulator(fz2Accum) combiner(fz2Combine)
+
+/////////////////////////////////////////////////////////////////////////
+
+static void fz3Init(int3 *accum) { accum->x = accum->y = accum->z = -1; }
+
+static void fz3Accum(int3 *accum,
+ int inVal,
+ int x /* special arg */,
+ int y /* special arg */,
+ int z /* special arg */) {
+ if (inVal==0) {
+ accum->x = x;
+ accum->y = y;
+ accum->z = z;
+ }
+}
+
+static void fz3Combine(int3 *accum, const int3 *accum2) {
+ if (accum2->x >= 0) *accum = *accum2;
+}
+
+#pragma rs reduce(fz3) \
+ initializer(fz3Init) \
+ accumulator(fz3Accum) combiner(fz3Combine)
+
+/////////////////////////////////////////////////////////////////////////
+
+#define BUCKETS 256
+typedef uint32_t Histogram[BUCKETS];
+
+static void hsgAccum(Histogram *h, uchar in) { ++(*h)[in]; }
+
+static void hsgCombine(Histogram *accum, const Histogram *addend) {
+ for (int i = 0; i < BUCKETS; ++i)
+ (*accum)[i] += (*addend)[i];
+}
+
+#pragma rs reduce(histogram) \
+ accumulator(hsgAccum) combiner(hsgCombine)
+
+static void modeOutConvert(int2 *result, const Histogram *h) {
+ uint32_t mode = 0;
+ for (int i = 1; i < BUCKETS; ++i)
+ if ((*h)[i] > (*h)[mode]) mode = i;
+ result->x = mode;
+ result->y = (*h)[mode];
+}
+
+#pragma rs reduce(mode) \
+ accumulator(hsgAccum) combiner(hsgCombine) \
+ outconverter(modeOutConvert)
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/refcount.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/refcount.rs
new file mode 100644
index 0000000..805ba6c
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/refcount.rs
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+// Testing reference counting of RS object types
+
+rs_allocation globalA;
+static rs_allocation staticGlobalA;
+
+void refcount_test() {
+ staticGlobalA = globalA;
+ rsClearObject(&globalA);
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+}
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/rsdebug.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/rsdebug.rs
new file mode 100644
index 0000000..74245cb
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/rsdebug.rs
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+// Testing primitive types
+float floatTest = 1.99f;
+float2 float2Test = {2.99f, 12.99f};
+float3 float3Test = {3.99f, 13.99f, 23.99f};
+float4 float4Test = {4.99f, 14.99f, 24.99f, 34.99f};
+double doubleTest = 2.05;
+double2 double2Test = {2.05, 12.05};
+double3 double3Test = {3.05, 13.05, 23.05};
+double4 double4Test = {4.05, 14.05, 24.05, 34.05};
+char charTest = -8;
+short shortTest = -16;
+int intTest = -32;
+long longTest = 17179869184l; // 1 << 34
+long long longlongTest = 68719476736l; // 1 << 36
+
+uchar ucharTest = 8;
+ushort ushortTest = 16;
+uint uintTest = 32;
+ulong ulongTest = 4611686018427387904L;
+int64_t int64_tTest = -17179869184l; // - 1 << 34
+uint64_t uint64_tTest = 117179869184l;
+
+static bool basic_test(uint32_t index) {
+ bool failed = false;
+
+ // This test focuses primarily on compilation-time, not run-time.
+ // For this reason, none of the outputs are actually checked.
+
+ rsDebug("floatTest", floatTest);
+ rsDebug("float2Test", float2Test);
+ rsDebug("float3Test", float3Test);
+ rsDebug("float4Test", float4Test);
+ rsDebug("doubleTest", doubleTest);
+ rsDebug("double2Test", double2Test);
+ rsDebug("double3Test", double3Test);
+ rsDebug("double4Test", double4Test);
+ rsDebug("charTest", charTest);
+ rsDebug("shortTest", shortTest);
+ rsDebug("intTest", intTest);
+ rsDebug("longTest", longTest);
+ rsDebug("longlongTest", longlongTest);
+
+ rsDebug("ucharTest", ucharTest);
+ rsDebug("ushortTest", ushortTest);
+ rsDebug("uintTest", uintTest);
+ rsDebug("ulongTest", ulongTest);
+ rsDebug("int64_tTest", int64_tTest);
+ rsDebug("uint64_tTest", uint64_tTest);
+
+ return failed;
+}
+
+void test_rsdebug(uint32_t index, int test_num) {
+ bool failed = false;
+ failed |= basic_test(index);
+
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ rsDebug("rsdebug_test FAILED", -1);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ rsDebug("rsdebug_test PASSED", 0);
+ }
+}
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/rsdebug_24.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/rsdebug_24.rs
new file mode 100644
index 0000000..08a1a42
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/rsdebug_24.rs
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+static bool basic_test(uint32_t index) {
+ bool failed = false;
+
+ // This test focuses primarily on compilation-time, not run-time.
+ // For this reason, none of the outputs are actually checked.
+
+ // http://b/27526302 - globals of half type cannot be exported and fail compilation
+ half halfTest = (half) 1.5f;
+ half2 half2Test = {(half) 1.5f, (half) 2.5f};
+ half3 half3Test = {(half) 1.5f, (half) 2.5f, (half) 3.5f};
+ half4 half4Test = {(half) 0.f, (half) -0.f, (half) 1.f/0.f, (half) 0.f/0.f};
+
+ rsDebug("halfTest", halfTest);
+ rsDebug("half2Test", half2Test);
+ rsDebug("half3Test", half3Test);
+ rsDebug("half4Test", half4Test);
+
+ return failed;
+}
+
+void test_rsdebug_24(uint32_t index, int test_num) {
+ bool failed = false;
+ failed |= basic_test(index);
+
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ rsDebug("rsdebug_24_test FAILED", -1);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ rsDebug("rsdebug_24_test PASSED", 0);
+ }
+}
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/rslist.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/rslist.rs
new file mode 100644
index 0000000..e21a865
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/rslist.rs
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#pragma version(1)
+
+#pragma rs java_package_name(com.android.rs.unittest)
+
+typedef struct ListAllocs_s {
+ rs_allocation text;
+ int result;
+} ListAllocs;
+
+ListAllocs *gList;
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/rstime.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/rstime.rs
new file mode 100644
index 0000000..a47df28
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/rstime.rs
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+static bool basic_test(uint32_t index) {
+ bool failed = false;
+
+ rs_time_t curTime = rsTime(0);
+ rs_tm tm;
+ rsDebug("curTime", curTime);
+
+ rsLocaltime(&tm, &curTime);
+
+ rsDebug("tm.tm_sec", tm.tm_sec);
+ rsDebug("tm.tm_min", tm.tm_min);
+ rsDebug("tm.tm_hour", tm.tm_hour);
+ rsDebug("tm.tm_mday", tm.tm_mday);
+ rsDebug("tm.tm_mon", tm.tm_mon);
+ rsDebug("tm.tm_year", tm.tm_year);
+ rsDebug("tm.tm_wday", tm.tm_wday);
+ rsDebug("tm.tm_yday", tm.tm_yday);
+ rsDebug("tm.tm_isdst", tm.tm_isdst);
+
+ // Test a specific time (since we set America/Los_Angeles localtime)
+ curTime = 1294438893;
+ rsLocaltime(&tm, &curTime);
+
+ _RS_ASSERT(tm.tm_sec == 33);
+ _RS_ASSERT(tm.tm_min == 21);
+ _RS_ASSERT(tm.tm_hour == 14);
+ _RS_ASSERT(tm.tm_mday == 7);
+ _RS_ASSERT(tm.tm_mon == 0);
+ _RS_ASSERT(tm.tm_year == 111);
+ _RS_ASSERT(tm.tm_wday == 5);
+ _RS_ASSERT(tm.tm_yday == 6);
+ _RS_ASSERT(tm.tm_isdst == 0);
+
+ return failed;
+}
+
+void test_rstime(uint32_t index, int test_num) {
+ bool failed = false;
+ failed |= basic_test(index);
+
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ rsDebug("rstime_test FAILED", -1);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ rsDebug("rstime_test PASSED", 0);
+ }
+}
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/rstypes.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/rstypes.rs
new file mode 100644
index 0000000..d53538c
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/rstypes.rs
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+#include "rs_graphics.rsh"
+
+rs_element elementTest;
+rs_type typeTest;
+rs_allocation allocationTest;
+rs_sampler samplerTest;
+rs_script scriptTest;
+
+rs_matrix4x4 matrix4x4Test;
+rs_matrix3x3 matrix3x3Test;
+rs_matrix2x2 matrix2x2Test;
+
+struct my_struct {
+ int i;
+ rs_allocation banana;
+};
+
+static bool basic_test(uint32_t index) {
+ bool failed = false;
+
+ rs_matrix4x4 matrix4x4TestLocal;
+ rs_matrix3x3 matrix3x3TestLocal;
+ rs_matrix2x2 matrix2x2TestLocal;
+ (void) matrix4x4TestLocal;
+ (void) matrix3x3TestLocal;
+ (void) matrix2x2TestLocal;
+
+ // This test focuses primarily on compilation-time, not run-time.
+ rs_element elementTestLocal;
+ rs_type typeTestLocal;
+ rs_allocation allocationTestLocal;
+ rs_sampler samplerTestLocal;
+ rs_script scriptTestLocal;
+ (void) elementTestLocal;
+ (void) typeTestLocal;
+ (void) allocationTestLocal;
+ (void) samplerTestLocal;
+ (void) scriptTestLocal;
+
+ struct my_struct structTest;
+ (void) structTest;
+
+ /*for (int i = 0; i < 4; i++) {
+ fontTestLocalArray[i] = fontTestLocal;
+ }*/
+
+ /*fontTest = fontTestLocalArray[3];*/
+
+ return failed;
+}
+
+void test_rstypes(uint32_t index, int test_num) {
+ bool failed = false;
+ failed |= basic_test(index);
+
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ rsDebug("rstypes_test FAILED", -1);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ rsDebug("rstypes_test PASSED", 0);
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/sampler.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/sampler.rs
new file mode 100644
index 0000000..89aa210
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/sampler.rs
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+#include "rs_graphics.rsh"
+rs_sampler minification;
+rs_sampler magnification;
+rs_sampler wrapS;
+rs_sampler wrapT;
+rs_sampler anisotropy;
+
+static bool test_sampler_getters() {
+ bool failed = false;
+
+ _RS_ASSERT(rsSamplerGetMagnification(minification) == RS_SAMPLER_NEAREST);
+ _RS_ASSERT(rsSamplerGetMinification(minification) == RS_SAMPLER_LINEAR_MIP_LINEAR);
+ _RS_ASSERT(rsSamplerGetWrapS(minification) == RS_SAMPLER_CLAMP);
+ _RS_ASSERT(rsSamplerGetWrapT(minification) == RS_SAMPLER_CLAMP);
+ _RS_ASSERT(rsSamplerGetAnisotropy(minification) == 1.0f);
+
+ _RS_ASSERT(rsSamplerGetMagnification(magnification) == RS_SAMPLER_LINEAR);
+ _RS_ASSERT(rsSamplerGetMinification(magnification) == RS_SAMPLER_NEAREST);
+ _RS_ASSERT(rsSamplerGetWrapS(magnification) == RS_SAMPLER_CLAMP);
+ _RS_ASSERT(rsSamplerGetWrapT(magnification) == RS_SAMPLER_CLAMP);
+ _RS_ASSERT(rsSamplerGetAnisotropy(magnification) == 1.0f);
+
+ _RS_ASSERT(rsSamplerGetMagnification(wrapS) == RS_SAMPLER_NEAREST);
+ _RS_ASSERT(rsSamplerGetMinification(wrapS) == RS_SAMPLER_NEAREST);
+ _RS_ASSERT(rsSamplerGetWrapS(wrapS) == RS_SAMPLER_WRAP);
+ _RS_ASSERT(rsSamplerGetWrapT(wrapS) == RS_SAMPLER_CLAMP);
+ _RS_ASSERT(rsSamplerGetAnisotropy(wrapS) == 1.0f);
+
+ _RS_ASSERT(rsSamplerGetMagnification(wrapT) == RS_SAMPLER_NEAREST);
+ _RS_ASSERT(rsSamplerGetMinification(wrapT) == RS_SAMPLER_NEAREST);
+ _RS_ASSERT(rsSamplerGetWrapS(wrapT) == RS_SAMPLER_CLAMP);
+ _RS_ASSERT(rsSamplerGetWrapT(wrapT) == RS_SAMPLER_WRAP);
+ _RS_ASSERT(rsSamplerGetAnisotropy(wrapT) == 1.0f);
+
+ _RS_ASSERT(rsSamplerGetMagnification(anisotropy) == RS_SAMPLER_NEAREST);
+ _RS_ASSERT(rsSamplerGetMinification(anisotropy) == RS_SAMPLER_NEAREST);
+ _RS_ASSERT(rsSamplerGetWrapS(anisotropy) == RS_SAMPLER_CLAMP);
+ _RS_ASSERT(rsSamplerGetWrapT(anisotropy) == RS_SAMPLER_CLAMP);
+ _RS_ASSERT(rsSamplerGetAnisotropy(anisotropy) == 8.0f);
+
+ if (failed) {
+ rsDebug("test_sampler_getters FAILED", 0);
+ }
+ else {
+ rsDebug("test_sampler_getters PASSED", 0);
+ }
+
+ return failed;
+}
+
+void sampler_test() {
+ bool failed = false;
+ failed |= test_sampler_getters();
+
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/shared.rsh b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/shared.rsh
new file mode 100644
index 0000000..2de3a6e
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/shared.rsh
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#pragma version(1)
+
+#pragma rs java_package_name(com.android.rs.unittest)
+
+typedef struct TestResult_s {
+ rs_allocation name;
+ bool pass;
+ float score;
+ int64_t time;
+} TestResult;
+//TestResult *g_results;
+
+static int64_t g_time;
+
+static inline void start(void) {
+ g_time = rsUptimeMillis();
+}
+
+static inline float end(uint32_t idx) {
+ int64_t t = rsUptimeMillis() - g_time;
+ //g_results[idx].time = t;
+ //rsDebug("test time", (int)t);
+ return ((float)t) / 1000.f;
+}
+
+#define _RS_ASSERT(b) \
+do { \
+ if (!(b)) { \
+ failed = true; \
+ rsDebug(#b " FAILED", 0); \
+ } \
+\
+} while (0)
+
+#define _RS_ASSERT_EQU(e1, e2) \
+ (((e1) != (e2)) ? (failed = true, rsDebug(#e1 " != " #e2, (e1), (e2)), false) : true)
+
+static const int iposinf = 0x7f800000;
+static const int ineginf = 0xff800000;
+
+static inline const float posinf() {
+ float f = *((float*)&iposinf);
+ return f;
+}
+
+static inline const float neginf() {
+ float f = *((float*)&ineginf);
+ return f;
+}
+
+static inline bool isposinf(float f) {
+ int i = *((int*)(void*)&f);
+ return (i == iposinf);
+}
+
+static inline bool isneginf(float f) {
+ int i = *((int*)(void*)&f);
+ return (i == ineginf);
+}
+
+static inline bool isnan(float f) {
+ int i = *((int*)(void*)&f);
+ return (((i & 0x7f800000) == 0x7f800000) && (i & 0x007fffff));
+}
+
+static inline bool isposzero(float f) {
+ int i = *((int*)(void*)&f);
+ return (i == 0x00000000);
+}
+
+static inline bool isnegzero(float f) {
+ int i = *((int*)(void*)&f);
+ return (i == 0x80000000);
+}
+
+static inline bool iszero(float f) {
+ return isposzero(f) || isnegzero(f);
+}
+
+/* Absolute epsilon used for floats. Value is similar to float.h. */
+#ifndef FLT_EPSILON
+#define FLT_EPSILON 1.19e7f
+#endif
+/* Max ULPs while still being considered "equal". Only used when this number
+ of ULPs is of a greater size than FLT_EPSILON. */
+#define FLT_MAX_ULP 1
+
+/* Calculate the difference in ULPs between the two values. (Return zero on
+ perfect equality.) */
+static inline int float_dist(float f1, float f2) {
+ return *((int *)(&f1)) - *((int *)(&f2));
+}
+
+/* Check if two floats are essentially equal. Will fail with some values
+ due to design. (Validate using FLT_EPSILON or similar if necessary.) */
+static inline bool float_almost_equal(float f1, float f2) {
+ int *i1 = (int*)(&f1);
+ int *i2 = (int*)(&f2);
+
+ // Check for sign equality
+ if ( ((*i1 >> 31) == 0) != ((*i2 >> 31) == 0) ) {
+ // Handle signed zeroes
+ if (f1 == f2)
+ return true;
+ return false;
+ }
+
+ // Check with ULP distance
+ if (float_dist(f1, f2) > FLT_MAX_ULP)
+ return false;
+ return true;
+}
+
+/* These constants must match those in UnitTest.java */
+static const int RS_MSG_TEST_PASSED = 100;
+static const int RS_MSG_TEST_FAILED = 101;
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/single_source_alloc.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/single_source_alloc.rs
new file mode 100644
index 0000000..d854296
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/single_source_alloc.rs
@@ -0,0 +1,417 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+int gDimX;
+int gDimY;
+int gDimZ;
+int gStart;
+static bool failed = false;
+
+
+// For each type, define 4 kernels, one per vector variant, that walk an
+// allocation and validate each cell. The value in a cell must be gStart +
+// "index-of-the-cell-starting-from-zero". For vector types, the 'x' field
+// must have this value. The expected values for 'y', 'z' and 'w' follow the
+// 'x' value in increments of one.
+//
+// 'z' will be zero for 2D and 1D allocations. 'y' will be zero for 1D
+// allocations.
+
+// TODO When the requirement that kernels must return an output to be launched
+// using rsForEach is relaxed, make the kernel not return its input.
+#define VERIFY_KERNEL(CT) \
+ CT RS_KERNEL verify_##CT(CT in, int x, int y, int z) { \
+ int val = (gStart + x + y * gDimX + z * gDimY * gDimX); \
+ _RS_ASSERT_EQU(in, (CT) val); \
+ return in; \
+ } \
+ CT##2 RS_KERNEL verify_##CT##2(CT##2 in, int x, int y, int z) { \
+ int val = (gStart + x + y * gDimX + z * gDimY * gDimX); \
+ _RS_ASSERT_EQU(in.x, (CT) val); \
+ _RS_ASSERT_EQU(in.y, (CT) (val + 1)); \
+ return in; \
+ } \
+ CT##3 RS_KERNEL verify_##CT##3(CT##3 in, int x, int y, int z) { \
+ int val = (gStart + x + y * gDimX + z * gDimY * gDimX); \
+ _RS_ASSERT_EQU(in.x, (CT) val); \
+ _RS_ASSERT_EQU(in.y, (CT) (val + 1)); \
+ _RS_ASSERT_EQU(in.z, (CT) (val + 2)); \
+ return in; \
+ } \
+ CT##4 RS_KERNEL verify_##CT##4(CT##4 in, int x, int y, int z) { \
+ int val = (gStart + x + y * gDimX + z * gDimY * gDimX); \
+ _RS_ASSERT_EQU(in.x, (CT) val); \
+ _RS_ASSERT_EQU(in.y, (CT) (val + 1)); \
+ _RS_ASSERT_EQU(in.z, (CT) (val + 2)); \
+ _RS_ASSERT_EQU(in.w, (CT) (val + 3)); \
+ return in; \
+ } \
+
+VERIFY_KERNEL(half)
+VERIFY_KERNEL(float)
+VERIFY_KERNEL(double)
+VERIFY_KERNEL(char)
+VERIFY_KERNEL(short)
+VERIFY_KERNEL(int)
+VERIFY_KERNEL(long)
+VERIFY_KERNEL(uchar)
+VERIFY_KERNEL(ushort)
+VERIFY_KERNEL(uint)
+VERIFY_KERNEL(ulong)
+
+
+// Store to an allocation based on the vector size and dimensionality being
+// tested. SETLEMENTAT, STORE_TO_ALLOC capture the following variables from
+// the context where they get instantiated:
+// vecSize, gAlloc, val, x, y, z
+
+#define SETELEMENTAT(CT) \
+ if (gDimZ != 0) { \
+ rsSetElementAt_##CT(gAlloc, storeVal, x, y, z); \
+ } \
+ else if (gDimY != 0) { \
+ rsSetElementAt_##CT(gAlloc, storeVal, x, y); \
+ } \
+ else { \
+ rsSetElementAt_##CT(gAlloc, storeVal, x); \
+ }
+
+#define STORE_TO_ALLOC(RST, CT) \
+ case RST: \
+ switch (vecSize) { \
+ case 1: { \
+ CT storeVal = (CT) val; \
+ SETELEMENTAT(CT); \
+ } \
+ break; \
+ case 2: { \
+ CT##2 storeVal = {(CT) val, (CT) (val + 1)}; \
+ SETELEMENTAT(CT##2); \
+ } \
+ break; \
+ case 3: { \
+ CT##3 storeVal = {(CT) val, (CT) (val + 1), (CT) (val + 2)}; \
+ SETELEMENTAT(CT##3); \
+ } \
+ break; \
+ case 4: { \
+ CT##4 storeVal = {(CT) val, (CT) (val + 1), (CT) (val + 2), \
+ (CT) (val + 3)}; \
+ SETELEMENTAT(CT##4); \
+ } \
+ break; \
+ } \
+ break; \
+
+
+// Launch the verify_kernel based on the appropriate type and vector size.
+#define LAUNCH_VERIFY_KERNEL(RST, CT) \
+ case RST: \
+ if (vecSize == 1) rsForEach(verify_##CT, gAlloc, gAlloc); \
+ else if (vecSize == 2) rsForEach(verify_##CT##2, gAlloc, gAlloc); \
+ else if (vecSize == 3) rsForEach(verify_##CT##3, gAlloc, gAlloc); \
+ else if (vecSize == 4) rsForEach(verify_##CT##4, gAlloc, gAlloc); \
+ break;
+
+void CreateAndTestAlloc(int dataType, int vecSize) {
+ if (gDimZ != 0 && gDimY == 0) {
+ _RS_ASSERT(false); // Invalid test
+ return;
+ }
+ if (gDimX == 0) {
+ _RS_ASSERT(false); // Invalid test
+ return;
+ }
+
+ rs_data_type dt = (rs_data_type) dataType;
+
+ rs_element element;
+ rs_type type;
+ rs_allocation gAlloc;
+
+ // Create and validate the rs_element object
+ if (vecSize == 1)
+ element = rsCreateElement((rs_data_type) dt);
+ else
+ element = rsCreateVectorElement((rs_data_type) dt, vecSize);
+ _RS_ASSERT(rsIsObject(element));
+ if (!rsIsObject(element))
+ return;
+
+ // Create and validate the rs_type object
+ type = rsCreateType(element, gDimX, gDimY, gDimZ);
+ _RS_ASSERT(rsIsObject(type));
+ if (!rsIsObject(type))
+ return;
+
+ // Create and validate the rs_allocation object
+ gAlloc = rsCreateAllocation(type);
+ if (!rsIsObject(gAlloc))
+ return;
+
+ // Handle RenderScript's distinction between Y or Z dimension being absent
+ // and having a size of 1
+ int zEnd = (gDimZ != 0) ? gDimZ: 1;
+ int yEnd = (gDimY != 0) ? gDimY: 1;
+ for (int z = 0; z < zEnd; z ++) {
+ for (int y = 0; y < yEnd; y ++) {
+ for (int x = 0; x < gDimX; x ++) {
+ int val = gStart + (x + y * gDimX + z * gDimY * gDimX);
+
+ // Store to a cell based on the type, vector size and
+ // dimensionality
+ switch (dt) {
+ STORE_TO_ALLOC(RS_TYPE_FLOAT_16, half);
+ STORE_TO_ALLOC(RS_TYPE_FLOAT_32, float);
+ STORE_TO_ALLOC(RS_TYPE_FLOAT_64, double);
+ STORE_TO_ALLOC(RS_TYPE_SIGNED_8, char);
+ STORE_TO_ALLOC(RS_TYPE_SIGNED_16, short);
+ STORE_TO_ALLOC(RS_TYPE_SIGNED_32, int);
+ STORE_TO_ALLOC(RS_TYPE_SIGNED_64, long);
+ STORE_TO_ALLOC(RS_TYPE_UNSIGNED_8, uchar);
+ STORE_TO_ALLOC(RS_TYPE_UNSIGNED_16, ushort);
+ STORE_TO_ALLOC(RS_TYPE_UNSIGNED_32, uint);
+ STORE_TO_ALLOC(RS_TYPE_UNSIGNED_64, ulong);
+ default:
+ // Invalid test
+ _RS_ASSERT(false);
+ break;
+ }
+ }
+ }
+ }
+
+ // Launch the appropriate verify_ kernel
+ switch (dt) {
+ LAUNCH_VERIFY_KERNEL(RS_TYPE_FLOAT_16, half);
+ LAUNCH_VERIFY_KERNEL(RS_TYPE_FLOAT_32, float);
+ LAUNCH_VERIFY_KERNEL(RS_TYPE_FLOAT_64, double);
+ LAUNCH_VERIFY_KERNEL(RS_TYPE_SIGNED_8, char);
+ LAUNCH_VERIFY_KERNEL(RS_TYPE_SIGNED_16, short);
+ LAUNCH_VERIFY_KERNEL(RS_TYPE_SIGNED_32, int);
+ LAUNCH_VERIFY_KERNEL(RS_TYPE_SIGNED_64, long);
+ LAUNCH_VERIFY_KERNEL(RS_TYPE_UNSIGNED_8, uchar);
+ LAUNCH_VERIFY_KERNEL(RS_TYPE_UNSIGNED_16, ushort);
+ LAUNCH_VERIFY_KERNEL(RS_TYPE_UNSIGNED_32, uint);
+ LAUNCH_VERIFY_KERNEL(RS_TYPE_UNSIGNED_64, ulong);
+
+ default:
+ // Invalid test
+ _RS_ASSERT(false);
+ break;
+ }
+}
+
+#define TEST_DATA_TYPE(dt, allowSimple, allowVector, allowPixel) { \
+ if (allowSimple) \
+ _RS_ASSERT(rsIsObject(rsCreateElement(dt))); \
+ else \
+ _RS_ASSERT(!rsIsObject(rsCreateElement(dt))); \
+ if (allowVector) \
+ _RS_ASSERT(rsIsObject(rsCreateVectorElement(dt, 3))); \
+ else \
+ _RS_ASSERT(!rsIsObject(rsCreateVectorElement(dt, 3))); \
+ if (allowPixel) \
+ _RS_ASSERT(rsIsObject(rsCreatePixelElement(dt, RS_KIND_PIXEL_DEPTH))); \
+ else \
+ _RS_ASSERT(!rsIsObject(rsCreatePixelElement(dt, RS_KIND_PIXEL_DEPTH)));\
+}
+
+#define TEST_SUPPORTED_PIXEL(dt, dk) { \
+ _RS_ASSERT(rsIsObject(rsCreatePixelElement(dt, dk))); \
+}
+
+#define TEST_UNSUPPORTED_PIXEL(dt, dk) { \
+ _RS_ASSERT(!rsIsObject(rsCreatePixelElement(dt, dk))); \
+}
+
+#define TEST_HELPER(suffix) { \
+ _RS_ASSERT(rsIsObject(rsCreateAllocation_##suffix(3))); \
+ _RS_ASSERT(rsIsObject(rsCreateAllocation_##suffix(3, 4))); \
+ _RS_ASSERT(rsIsObject(rsCreateAllocation_##suffix(3, 4, 5))); \
+ }
+
+#define TEST_HELPERS(CT) { \
+ TEST_HELPER(CT); \
+ TEST_HELPER(CT##2); \
+ TEST_HELPER(CT##3); \
+ TEST_HELPER(CT##4); \
+}
+
+void TestAllCases() {
+ // vector_width must be at least 2
+ rs_element oneElt = rsCreateVectorElement(RS_TYPE_SIGNED_32, 1);
+ _RS_ASSERT(!rsIsObject(oneElt));
+
+ // vector_width must be at most 4
+ rs_element fiveElt = rsCreateVectorElement(RS_TYPE_SIGNED_32, 5);
+ _RS_ASSERT(!rsIsObject(fiveElt));
+
+ /////////////////////////////////////////////////////////////////
+ // Element validation
+ /////////////////////////////////////////////////////////////////
+ // These types are valid for scalar and vectors, but don't support pixel
+ TEST_DATA_TYPE(RS_TYPE_BOOLEAN, true, true, false);
+ TEST_DATA_TYPE(RS_TYPE_FLOAT_32, true, true, false);
+ TEST_DATA_TYPE(RS_TYPE_FLOAT_64, true, true, false);
+ TEST_DATA_TYPE(RS_TYPE_SIGNED_8, true, true, false);
+ TEST_DATA_TYPE(RS_TYPE_SIGNED_16, true, true, false);
+ TEST_DATA_TYPE(RS_TYPE_SIGNED_32, true, true, false);
+ TEST_DATA_TYPE(RS_TYPE_SIGNED_64, true, true, false);
+ TEST_DATA_TYPE(RS_TYPE_UNSIGNED_32, true, true, false);
+ TEST_DATA_TYPE(RS_TYPE_UNSIGNED_64, true, true, false);
+
+ // These types are valid only for scalars
+ TEST_DATA_TYPE(RS_TYPE_MATRIX_4X4, true, false, false);
+ TEST_DATA_TYPE(RS_TYPE_MATRIX_3X3, true, false, false);
+ TEST_DATA_TYPE(RS_TYPE_MATRIX_2X2, true, false, false);
+ TEST_DATA_TYPE(RS_TYPE_ELEMENT, true, false, false);
+ TEST_DATA_TYPE(RS_TYPE_TYPE, true, false, false);
+ TEST_DATA_TYPE(RS_TYPE_ALLOCATION, true, false, false);
+ TEST_DATA_TYPE(RS_TYPE_SCRIPT, true, false, false);
+
+ // U8, U16 are valid for scalar, vector and pixel
+ TEST_DATA_TYPE(RS_TYPE_UNSIGNED_8, true, true, true);
+ TEST_DATA_TYPE(RS_TYPE_UNSIGNED_16, true, true, true);
+
+ // These data types are only for pixels and a particular data_kind
+ TEST_SUPPORTED_PIXEL (RS_TYPE_UNSIGNED_5_6_5, RS_KIND_PIXEL_RGB);
+ TEST_UNSUPPORTED_PIXEL(RS_TYPE_UNSIGNED_5_6_5, RS_KIND_PIXEL_L);
+ TEST_SUPPORTED_PIXEL (RS_TYPE_UNSIGNED_5_5_5_1, RS_KIND_PIXEL_RGBA);
+ TEST_UNSUPPORTED_PIXEL(RS_TYPE_UNSIGNED_5_5_5_1, RS_KIND_PIXEL_L);
+ TEST_SUPPORTED_PIXEL (RS_TYPE_UNSIGNED_4_4_4_4, RS_KIND_PIXEL_RGBA);
+ TEST_UNSUPPORTED_PIXEL(RS_TYPE_UNSIGNED_4_4_4_4, RS_KIND_PIXEL_L);
+ TEST_SUPPORTED_PIXEL (RS_TYPE_UNSIGNED_16, RS_KIND_PIXEL_DEPTH);
+ TEST_UNSUPPORTED_PIXEL(RS_TYPE_UNSIGNED_4_4_4_4, RS_KIND_PIXEL_L);
+
+ // These data types are not supported from single-source
+ TEST_DATA_TYPE(RS_TYPE_NONE, false, false, false);
+ TEST_DATA_TYPE(RS_TYPE_SAMPLER, false, false, false);
+ TEST_DATA_TYPE(RS_TYPE_MESH, false, false, false);
+ TEST_DATA_TYPE(RS_TYPE_PROGRAM_FRAGMENT, false, false, false);
+ TEST_DATA_TYPE(RS_TYPE_PROGRAM_VERTEX, false, false, false);
+ TEST_DATA_TYPE(RS_TYPE_PROGRAM_RASTER, false, false, false);
+ TEST_DATA_TYPE(RS_TYPE_PROGRAM_STORE, false, false, false);
+ TEST_DATA_TYPE(RS_TYPE_FONT, false, false, false);
+ TEST_DATA_TYPE(RS_TYPE_INVALID, false, false, false);
+
+ /////////////////////////////////////////////////////////////////
+ // Test rs_type creation
+ /////////////////////////////////////////////////////////////////
+ rs_element I32_3 = rsCreateVectorElement(RS_TYPE_SIGNED_32, 3);
+
+ // Create 1D, 2D, 3D types
+ _RS_ASSERT(rsIsObject(rsCreateType(I32_3, 3)));
+ _RS_ASSERT(rsIsObject(rsCreateType(I32_3, 3, 4)));
+ _RS_ASSERT(rsIsObject(rsCreateType(I32_3, 3, 4, 5)));
+ _RS_ASSERT(rsIsObject(rsCreateType(I32_3, 0))); // x = 0 is allowed
+
+ // Invalid dimensionality
+ _RS_ASSERT(!rsIsObject(rsCreateType(I32_3, 0, 4))); // x is 0 but y isn't
+ _RS_ASSERT(!rsIsObject(rsCreateType(I32_3, 0, 4, 5))); // x is 0 but z isn't
+ _RS_ASSERT(!rsIsObject(rsCreateType(I32_3, 3, 0, 5))); // y is 0 but z isn't
+
+ // shape attributes
+ // Valid yuv_format
+ _RS_ASSERT(rsIsObject(rsCreateType(I32_3, 3, 4, 0, false, false,
+ RS_YUV_NONE)));
+ _RS_ASSERT(rsIsObject(rsCreateType(I32_3, 3, 4, 0, false, false,
+ RS_YUV_YV12)));
+ _RS_ASSERT(rsIsObject(rsCreateType(I32_3, 3, 4, 0, false, false,
+ RS_YUV_NV21)));
+ _RS_ASSERT(rsIsObject(rsCreateType(I32_3, 3, 4, 0, false, false,
+ RS_YUV_420_888)));
+
+ // Invalid yuv_format
+ _RS_ASSERT(!rsIsObject(rsCreateType(I32_3, 3, 4, 5, false, false, 1024)));
+ // yuv_format with 1D or 3D is invalid
+ _RS_ASSERT(!rsIsObject(rsCreateType(I32_3, 3, 0, 0, false, false,
+ RS_YUV_YV12)));
+ _RS_ASSERT(!rsIsObject(rsCreateType(I32_3, 3, 4, 5, false, false,
+ RS_YUV_YV12)));
+
+ // yuv_format with mipmaps or cubemap is invalid
+ _RS_ASSERT(!rsIsObject(rsCreateType(I32_3, 3, 4, 0, false, true,
+ RS_YUV_YV12)));
+ _RS_ASSERT(!rsIsObject(rsCreateType(I32_3, 3, 4, 0, true, false,
+ RS_YUV_YV12)));
+
+ // mipmaps with 1D or 3D is invalid
+ _RS_ASSERT(!rsIsObject(rsCreateType(I32_3, 3, 0, 0, true, false,
+ RS_YUV_NONE)));
+ _RS_ASSERT(!rsIsObject(rsCreateType(I32_3, 3, 4, 5, true, false,
+ RS_YUV_NONE)));
+
+ // cubemap with 1D or 3D is invalid
+ _RS_ASSERT(!rsIsObject(rsCreateType(I32_3, 3, 0, 0, false, true,
+ RS_YUV_NONE)));
+ _RS_ASSERT(!rsIsObject(rsCreateType(I32_3, 3, 4, 5, false, true,
+ RS_YUV_NONE)));
+
+ /////////////////////////////////////////////////////////////////
+ // Test rs_allocation creation
+ /////////////////////////////////////////////////////////////////
+ rs_type I32_3_2D = rsCreateType(I32_3, 3, 4);
+
+ // Valid uses
+ _RS_ASSERT(rsIsObject(rsCreateAllocation(I32_3_2D)));
+ _RS_ASSERT(rsIsObject(rsCreateAllocation(I32_3_2D,\
+ (uint32_t) RS_ALLOCATION_USAGE_SCRIPT)));
+ _RS_ASSERT(rsIsObject(rsCreateAllocation(I32_3_2D,\
+ (uint32_t) RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE)));
+ _RS_ASSERT(rsIsObject(rsCreateAllocation(I32_3_2D,
+ (uint32_t) RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE |
+ RS_ALLOCATION_USAGE_SCRIPT)));
+
+ // Invalid uses
+ _RS_ASSERT(!rsIsObject(rsCreateAllocation(I32_3_2D,
+ (uint32_t) RS_ALLOCATION_USAGE_GRAPHICS_VERTEX)));
+ _RS_ASSERT(!rsIsObject(rsCreateAllocation(I32_3_2D,
+ (uint32_t) RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS)));
+ _RS_ASSERT(!rsIsObject(rsCreateAllocation(I32_3_2D,
+ (uint32_t) RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET)));
+ _RS_ASSERT(!rsIsObject(rsCreateAllocation(I32_3_2D,
+ (uint32_t) RS_ALLOCATION_USAGE_IO_INPUT)));
+ _RS_ASSERT(!rsIsObject(rsCreateAllocation(I32_3_2D,
+ (uint32_t) RS_ALLOCATION_USAGE_IO_OUTPUT)));
+ _RS_ASSERT(!rsIsObject(rsCreateAllocation(I32_3_2D,
+ (uint32_t) RS_ALLOCATION_USAGE_SHARED)));
+
+ TEST_HELPER(half);
+ TEST_HELPERS(float);
+ TEST_HELPERS(double);
+ TEST_HELPERS(char);
+ TEST_HELPERS(short);
+ TEST_HELPERS(int);
+ TEST_HELPERS(long);
+ TEST_HELPERS(uchar);
+ TEST_HELPERS(ushort);
+ TEST_HELPERS(uint);
+ TEST_HELPERS(ulong);
+}
+
+void single_source_alloc_test() {
+ if (failed) {
+ rsDebug("Single Source Alloc Test Failed", 0);
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsDebug("Single Source Alloc Test Passed", 0);
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/single_source_ref_count.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/single_source_ref_count.rs
new file mode 100644
index 0000000..20d6e9a
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/single_source_ref_count.rs
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+static const int dimX = 1024;
+static const int dimY = 768;
+static const int dimZ = 0;
+
+// Tests an object returned via a local variable is valid to the caller.
+static rs_allocation test1() {
+ rs_allocation retValue = {};
+ rs_element element = rsCreateVectorElement(RS_TYPE_FLOAT_32, 4);
+ if (!rsIsObject(element)) {
+ rsDebug("element is null.", element.p);
+ return retValue;
+ }
+
+ rs_type type = rsCreateType(element, dimX, dimY, dimZ);
+ if (!rsIsObject(type)) {
+ rsDebug("type is null.", type.p);
+ return retValue;
+ }
+
+ retValue = rsCreateAllocation(type);
+ if (!rsIsObject(retValue)) {
+ rsDebug("rs_allocation retValue is null.", retValue.p);
+ }
+
+ return retValue;
+}
+
+// Tests an object returned via an expression is valid to the caller.
+static rs_allocation test2() {
+ rs_allocation empty = {};
+ rs_element element = rsCreateVectorElement(RS_TYPE_FLOAT_32, 4);
+ if (!rsIsObject(element)) {
+ rsDebug("element is null.", element.p);
+ return empty;
+ }
+
+ rs_type type = rsCreateType(element, dimX, dimY, dimZ);
+ if (!rsIsObject(type)) {
+ rsDebug("type is null.", type.p);
+ return empty;
+ }
+
+ return rsCreateAllocation(type);
+}
+
+static struct testS {
+ rs_allocation (*fp)();
+ const char* name;
+} tests[] = {
+ { test1, "test1" },
+ { test2, "test2" },
+ { NULL, NULL }
+};
+
+void entrypoint() {
+ int failed = 0;
+
+ for (int i = 0; tests[i].fp; i++) {
+ rsDebug(tests[i].name, 0);
+ rs_allocation allocation = tests[i].fp();
+ if (!rsIsObject(allocation)) {
+ failed++;
+ rsDebug("failed.", 0);
+ } else {
+ rsDebug("passed.", 0);
+ }
+ }
+
+ if (failed) {
+ rsDebug("Reference counting tests failed: ", failed);
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ } else {
+ rsDebug("All reference counting tests passed.", 0);
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/single_source_script.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/single_source_script.rs
new file mode 100644
index 0000000..773bb63
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/single_source_script.rs
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+int dimX;
+int dimY;
+
+rs_allocation gAllocOut;
+
+void oldFoo(const int* in, int* out, uint32_t x, uint32_t y) {
+ out[0] = in[0] * 3;
+}
+
+int __attribute__((kernel)) foo(int a) {
+ return a * 2;
+}
+
+void oldGoo(const int* a, int* out) {
+ *out = *a + 47;
+}
+
+int __attribute__((kernel)) goo(int a, int b) {
+ return a + b;
+}
+
+void __attribute__((kernel)) bar(int x, int y) {
+ int a = rsGetElementAt_int(gAllocOut, x, y);
+ a++;
+ rsSetElementAt_int(gAllocOut, a, x, y);
+}
+
+void validate(rs_allocation out) {
+ bool failed = false;
+
+ int i, j;
+
+ for (j = 0; j < dimY; j++) {
+ for (i = 0; i < dimX; i++) {
+ const int actual = rsGetElementAt_int(out, i, j);
+ int expected = (i + j * dimX) * 4;
+ if (j < dimY / 2) {
+ expected *= 2;
+ }
+ expected += (i + j * dimX) + 1;
+ expected *= 3;
+ expected += 47;
+ if (actual != expected) {
+ failed = true;
+ rsDebug("row ", j);
+ rsDebug("column ", i);
+ rsDebug("expects ", expected);
+ rsDebug("got ", actual);
+ }
+ }
+ }
+
+ if (failed) {
+ rsDebug("FAILED", 0);
+ } else {
+ rsDebug("PASSED", 0);
+ }
+
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ } else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
+void entrypoint(rs_allocation in, rs_allocation out) {
+ int i, j;
+ for (i = 0; i < dimX; i++) {
+ for (j = 0; j < dimY; j++) {
+ rsSetElementAt_int(in, j * dimX + i, i, j);
+ }
+ }
+
+ rsForEach(foo, in, out);
+ rsForEach(foo, out, out);
+
+ rs_script_call_t opts = {0};
+ opts.xStart = 0;
+ opts.xEnd = dimX;
+ opts.yStart = 0;
+ opts.yEnd = dimY / 2;
+ rsForEachWithOptions(foo, &opts, out, out);
+
+ rsForEach(goo, in, out, out);
+
+ gAllocOut = out;
+ rs_script_call_t opts2 = {0};
+ opts2.xStart = 0;
+ opts2.xEnd = dimX;
+ opts2.yStart = 0;
+ opts2.yEnd = dimY;
+ rsForEachWithOptions(bar, &opts2);
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/small_struct.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/small_struct.rs
new file mode 100644
index 0000000..7841573
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/small_struct.rs
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+// Same as small_struct_2.rs except for location of padding in struct small_struct[_2].
+
+#include "shared.rsh"
+
+int gDimX;
+int gDimY;
+
+rs_allocation A;
+rs_allocation B;
+
+static int gIntStart = 0x7;
+static long gLongStart = 0x12345678abcdef12;
+
+typedef struct small_struct {
+ int i;
+ // expect 4 bytes of padding here
+ long l;
+} small_struct;
+
+#define ARRAY_LEN 3
+
+typedef struct struct_of_struct {
+ small_struct arr[ARRAY_LEN];
+} struct_of_struct;
+
+void test() {
+ bool failed = false;
+ for (int x = 0; x < gDimX; x ++) {
+ for (int y = 0; y < gDimY; y ++) {
+ small_struct *v = (small_struct *) rsGetElementAt(A, x, y);
+ _RS_ASSERT_EQU(v->i, gIntStart + y * gDimX + x);
+ _RS_ASSERT_EQU(v->l, gLongStart + y * gDimX + x);
+ }
+ }
+
+ for (int x = 0; x < gDimX; x ++) {
+ for (int y = 0; y < gDimY; y ++) {
+ struct_of_struct *v = (struct_of_struct *) rsGetElementAt(B, x, y);
+ for (int idx = 0; idx < ARRAY_LEN; idx ++) {
+ _RS_ASSERT_EQU((*v).arr[idx].i, gIntStart + y * gDimX + x + idx);
+ _RS_ASSERT_EQU((*v).arr[idx].l, gLongStart + y * gDimX + x + idx);
+ }
+ }
+ }
+
+ if (failed) {
+ rsDebug("small_struct test FAILED", 0);
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsDebug("small_struct test PASSED", 0);
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
+small_struct RS_KERNEL setStruct(int x, int y) {
+ small_struct output;
+ output.i = gIntStart + y * gDimX + x;
+ output.l = gLongStart + y * gDimX + x;
+ return output;
+}
+
+struct_of_struct RS_KERNEL setArrayOfStruct(int x, int y) {
+ struct_of_struct output;
+ for (int idx = 0; idx < ARRAY_LEN; idx ++) {
+ output.arr[idx].i = gIntStart + y * gDimX + x + idx;
+ output.arr[idx].l = gLongStart + y * gDimX + x + idx;
+ }
+ return output;
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/small_struct_2.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/small_struct_2.rs
new file mode 100644
index 0000000..da6b7ff
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/small_struct_2.rs
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+// Same as small_struct.rs except for location of padding in struct small_struct[_2].
+
+#include "shared.rsh"
+
+int gDimX;
+int gDimY;
+
+rs_allocation A;
+rs_allocation B;
+
+static int gIntStart = 0x7;
+static long gLongStart = 0x12345678abcdef12;
+
+typedef struct small_struct_2 {
+ long l;
+ int i;
+ // expect 4 bytes of padding here
+} small_struct_2;
+
+#define ARRAY_LEN 3
+
+typedef struct struct_of_struct_2 {
+ small_struct_2 arr[ARRAY_LEN];
+} struct_of_struct_2;
+
+void test() {
+ bool failed = false;
+ for (int x = 0; x < gDimX; x ++) {
+ for (int y = 0; y < gDimY; y ++) {
+ small_struct_2 *v = (small_struct_2 *) rsGetElementAt(A, x, y);
+ _RS_ASSERT_EQU(v->i, gIntStart + y * gDimX + x);
+ _RS_ASSERT_EQU(v->l, gLongStart + y * gDimX + x);
+ }
+ }
+
+ for (int x = 0; x < gDimX; x ++) {
+ for (int y = 0; y < gDimY; y ++) {
+ struct_of_struct_2 *v = (struct_of_struct_2 *) rsGetElementAt(B, x, y);
+ for (int idx = 0; idx < ARRAY_LEN; idx ++) {
+ _RS_ASSERT_EQU((*v).arr[idx].i, gIntStart + y * gDimX + x + idx);
+ _RS_ASSERT_EQU((*v).arr[idx].l, gLongStart + y * gDimX + x + idx);
+ }
+ }
+ }
+
+ if (failed) {
+ rsDebug("small_struct_2 test FAILED", 0);
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsDebug("small_struct_2 test PASSED", 0);
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
+small_struct_2 RS_KERNEL setStruct(int x, int y) {
+ small_struct_2 output;
+ output.i = gIntStart + y * gDimX + x;
+ output.l = gLongStart + y * gDimX + x;
+ return output;
+}
+
+struct_of_struct_2 RS_KERNEL setArrayOfStruct(int x, int y) {
+ struct_of_struct_2 output;
+ for (int idx = 0; idx < ARRAY_LEN; idx ++) {
+ output.arr[idx].i = gIntStart + y * gDimX + x + idx;
+ output.arr[idx].l = gLongStart + y * gDimX + x + idx;
+ }
+ return output;
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/static_globals.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/static_globals.rs
new file mode 100644
index 0000000..303bf99
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/static_globals.rs
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+static bool b = false;
+
+void root(const int *o, uint32_t x, uint32_t y) {
+ b = true;
+}
+
+void static_globals_test() {
+ if (!b) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/struct.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/struct.rs
new file mode 100644
index 0000000..06f1f2e
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/struct.rs
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+typedef struct Point2 {
+ int x;
+ int y;
+} Point_2;
+Point_2 *point2;
+
+static bool test_Point_2(int expected) {
+ bool failed = false;
+
+ rsDebug("Point: ", point2[0].x, point2[0].y);
+ _RS_ASSERT(point2[0].x == expected);
+ _RS_ASSERT(point2[0].y == expected);
+
+ if (failed) {
+ rsDebug("test_Point_2 FAILED", 0);
+ }
+ else {
+ rsDebug("test_Point_2 PASSED", 0);
+ }
+
+ return failed;
+}
+
+void struct_test(int expected) {
+ bool failed = false;
+ failed |= test_Point_2(expected);
+
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/struct_field.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/struct_field.rs
new file mode 100644
index 0000000..755a717
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/struct_field.rs
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+// Ensure that we can reflect correct Java code for a struct with
+// multiple fields of type struct. Java sets the script global
+// variable "outer", and then calls a verification invokable
+// "checkOuter()", passing the expected field values as scalar
+// arguments.
+
+struct InnerOne {
+ int x;
+ int y;
+ float f;
+};
+
+typedef struct InnerOne s_innerOne;
+
+struct InnerTwo {
+ int8_t z;
+ struct InnerOne innerOne;
+};
+
+struct Outer {
+ struct InnerOne innerOneA;
+ long l; // to induce padding
+ struct InnerOne innerOneB;
+ struct InnerTwo innerTwo3[3];
+ struct InnerTwo innerTwo2[2];
+ struct InnerOne innerOne4[4];
+ s_innerOne innerOneC; // does a typedef confuse reflection?
+};
+
+struct Outer outer;
+
+// Fragment of incoming argument list: Fields for struct InnerOne.
+// Arguments are named argPrefix"_x", argPrefix"_y", argPrefix"_f".
+#define ARGS_INNERONE_(argPrefix) \
+ int argPrefix ## _x, int argPrefix ## _y, float argPrefix ## _f
+
+// Fragment of incoming argument list: Fields for struct InnerOne
+// within struct Outer.
+// Arguments are named outerFieldName"_x", outerFieldName"_y", outerFieldName"_f".
+#define ARGS_INNERONE_SCALAR(outerFieldName) \
+ ARGS_INNERONE_(outerFieldName)
+
+// Fragment of incoming argument list: Fields for element of array of
+// struct InnerOne within struct Outer.
+// Arguments are named outerFieldName"_"index"_x", outerFieldName"_"index"_y",
+// and outerFieldName"_"index"_f".
+#define ARGS_INNERONE_ARRAY(outerFieldName, index) \
+ ARGS_INNERONE_(outerFieldName ## _ ## index)
+
+// Fragment of incoming argument list: Fields for element of array of
+// struct InnerTwo (with nested InnerOne flattened out) within struct Outer.
+// Arguments are named outerFieldName"_"index"_z", outerFieldName"_"index"_innerOne_x", etc.
+#define ARGS_INNERTWO_ARRAY(outerFieldName, index) \
+ int8_t outerFieldName ## _ ## index ## _z, ARGS_INNERONE_(outerFieldName ## _ ## index ## _innerOne)
+
+// #define TRACE(...) rsDebug(__VA_ARGS__)
+#define TRACE(...) (void)0
+
+void checkOuter(ARGS_INNERONE_SCALAR(innerOneA),
+ long l,
+ ARGS_INNERONE_SCALAR(innerOneB),
+ ARGS_INNERTWO_ARRAY(innerTwo3, 0),
+ ARGS_INNERTWO_ARRAY(innerTwo3, 1),
+ ARGS_INNERTWO_ARRAY(innerTwo3, 2),
+ ARGS_INNERTWO_ARRAY(innerTwo2, 0),
+ ARGS_INNERTWO_ARRAY(innerTwo2, 1),
+ ARGS_INNERONE_ARRAY(innerOne4, 0),
+ ARGS_INNERONE_ARRAY(innerOne4, 1),
+ ARGS_INNERONE_ARRAY(innerOne4, 2),
+ ARGS_INNERONE_ARRAY(innerOne4, 3),
+ ARGS_INNERONE_SCALAR(innerOneC)) {
+ bool failed = false;
+
+ // Compare contents of a struct InnerOne instance against incoming argument values.
+ // Compares instanceName".x" to argPrefix"_x", etc.
+#define CHECK_INNERONE_(instanceName, argPrefix) \
+ do { \
+ TRACE(# instanceName, instanceName.x); \
+ _RS_ASSERT(instanceName.x == argPrefix ## _x); \
+ TRACE(# instanceName, instanceName.y); \
+ _RS_ASSERT(instanceName.y == argPrefix ## _y); \
+ TRACE(# instanceName, instanceName.f); \
+ _RS_ASSERT(instanceName.f == argPrefix ## _f); \
+ } while(false)
+
+ // Compare contents of a struct InnerOne instance within global
+ // variable "outer" against incoming argument values.
+ // Compares "outer."outerFieldName".x" to outerFieldName"_x", etc.
+#define CHECK_INNERONE_SCALAR(outerFieldName) \
+ CHECK_INNERONE_(outer.outerFieldName, outerFieldName)
+
+ // Compare contents of element of array of struct InnerOne
+ // instance within global variable "outer" against incoming argument values.
+ // Compares "outer"outerFieldName"["index"].x" to outerFieldName"_"index"_x", etc.
+#define CHECK_INNERONE_ARRAY(outerFieldName, index) \
+ CHECK_INNERONE_(outer.outerFieldName[index], outerFieldName ## _ ## index)
+
+ // Compare contents of element of array of struct InnerTwo
+ // instance within global variable "outer" against incoming argument values.
+ // Compares "outer."outerFieldName"["index"].z" to outerFieldName"_"index"_z",
+ // "outer."outerFieldName"["index"].innerOne.x" to outerFieldName""index"_innerOne_x",
+ // etc.
+#define CHECK_INNERTWO_ARRAY(outerFieldName, index) \
+ do { \
+ TRACE(# index, outer.outerFieldName[index].z); \
+ _RS_ASSERT(outer.outerFieldName[index].z == outerFieldName ## _ ## index ## _z); \
+ CHECK_INNERONE_(outer.outerFieldName[index].innerOne, outerFieldName ## _ ## index ## _innerOne); \
+ } while (false);
+
+ CHECK_INNERONE_SCALAR(innerOneA);
+ TRACE("l", outer.l);
+ _RS_ASSERT(outer.l == l);
+ CHECK_INNERONE_SCALAR(innerOneB);
+ CHECK_INNERTWO_ARRAY(innerTwo3, 0);
+ CHECK_INNERTWO_ARRAY(innerTwo3, 1);
+ CHECK_INNERTWO_ARRAY(innerTwo3, 2);
+ CHECK_INNERTWO_ARRAY(innerTwo2, 0);
+ CHECK_INNERTWO_ARRAY(innerTwo2, 1);
+ CHECK_INNERONE_ARRAY(innerOne4, 0);
+ CHECK_INNERONE_ARRAY(innerOne4, 1);
+ CHECK_INNERONE_ARRAY(innerOne4, 2);
+ CHECK_INNERONE_ARRAY(innerOne4, 3);
+ CHECK_INNERONE_SCALAR(innerOneC);
+
+ if (failed) {
+ rsDebug("struct_field FAILED", 0);
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsDebug("struct_field PASSED", 0);
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/struct_field_simple.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/struct_field_simple.rs
new file mode 100644
index 0000000..5ec4591
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/struct_field_simple.rs
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+struct Simple {
+ int I;
+ long L;
+};
+
+struct Simple simple;
+
+void checkSimple(int argI, long argL) {
+ bool failed = false;
+
+ rsDebug("argI ", argI);
+ rsDebug("simple.I ", simple.I);
+ rsDebug("argL.lo ", (unsigned)argL & ~0U);
+ rsDebug("simple.L.lo", (unsigned)simple.L & ~0U);
+ rsDebug("argL.hi ", (unsigned)((ulong)argL >> 32));
+ rsDebug("simple.L.hi", (unsigned)((ulong)simple.L >> 32));
+
+ _RS_ASSERT(simple.I == argI);
+ _RS_ASSERT(simple.L == argL);
+
+ if (failed) {
+ rsDebug("struct_field_simple FAILED", 0);
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsDebug("struct_field_simple PASSED", 0);
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/unsigned.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/unsigned.rs
new file mode 100644
index 0000000..53e58e0
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/unsigned.rs
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+// Testing unsigned types for Bug 6764163
+unsigned int ui = 37;
+unsigned char uc = 5;
+
+static bool test_unsigned() {
+ bool failed = false;
+
+ rsDebug("ui", ui);
+ rsDebug("uc", uc);
+ _RS_ASSERT(ui == 0x7fffffff);
+ _RS_ASSERT(uc == 129);
+
+ if (failed) {
+ rsDebug("test_unsigned FAILED", -1);
+ }
+ else {
+ rsDebug("test_unsigned PASSED", 0);
+ }
+
+ return failed;
+}
+
+void unsigned_test() {
+ bool failed = false;
+ failed |= test_unsigned();
+
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+
diff --git a/tests/java_api/RSUnitTests/src/com/android/rs/unittest/vector.rs b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/vector.rs
new file mode 100644
index 0000000..c81f270
--- /dev/null
+++ b/tests/java_api/RSUnitTests/src/com/android/rs/unittest/vector.rs
@@ -0,0 +1,214 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "shared.rsh"
+
+// Testing vector types
+float2 f2 = { 1.0f, 2.0f };
+float3 f3 = { 1.0f, 2.0f, 3.0f };
+float4 f4 = { 1.0f, 2.0f, 3.0f, 4.0f };
+
+double2 d2 = { 1.0, 2.0 };
+double3 d3 = { 1.0, 2.0, 3.0 };
+double4 d4 = { 1.0, 2.0, 3.0, 4.0 };
+
+char2 i8_2 = { 1, 2 };
+char3 i8_3 = { 1, 2, 3 };
+char4 i8_4 = { 1, 2, 3, 4 };
+
+uchar2 u8_2 = { 1, 2 };
+uchar3 u8_3 = { 1, 2, 3 };
+uchar4 u8_4 = { 1, 2, 3, 4 };
+
+short2 i16_2 = { 1, 2 };
+short3 i16_3 = { 1, 2, 3 };
+short4 i16_4 = { 1, 2, 3, 4 };
+
+ushort2 u16_2 = { 1, 2 };
+ushort3 u16_3 = { 1, 2, 3 };
+ushort4 u16_4 = { 1, 2, 3, 4 };
+
+int2 i32_2 = { 1, 2 };
+int3 i32_3 = { 1, 2, 3 };
+int4 i32_4 = { 1, 2, 3, 4 };
+
+uint2 u32_2 = { 1, 2 };
+uint3 u32_3 = { 1, 2, 3 };
+uint4 u32_4 = { 1, 2, 3, 4 };
+
+long2 i64_2 = { 1, 2 };
+long3 i64_3 = { 1, 2, 3 };
+long4 i64_4 = { 1, 2, 3, 4 };
+
+ulong2 u64_2 = { 1, 2 };
+ulong3 u64_3 = { 1, 2, 3 };
+ulong4 u64_4 = { 1, 2, 3, 4 };
+
+static bool test_vector_types() {
+ bool failed = false;
+
+ rsDebug("Testing F32", 0);
+ _RS_ASSERT(f2.x == 2.99f);
+ _RS_ASSERT(f2.y == 3.99f);
+
+ _RS_ASSERT(f3.x == 2.99f);
+ _RS_ASSERT(f3.y == 3.99f);
+ _RS_ASSERT(f3.z == 4.99f);
+
+ _RS_ASSERT(f4.x == 2.99f);
+ _RS_ASSERT(f4.y == 3.99f);
+ _RS_ASSERT(f4.z == 4.99f);
+ _RS_ASSERT(f4.w == 5.99f);
+
+ rsDebug("Testing F64", 0);
+ _RS_ASSERT(d2.x == 2.99);
+ _RS_ASSERT(d2.y == 3.99);
+
+ _RS_ASSERT(d3.x == 2.99);
+ _RS_ASSERT(d3.y == 3.99);
+ _RS_ASSERT(d3.z == 4.99);
+
+ _RS_ASSERT(d4.x == 2.99);
+ _RS_ASSERT(d4.y == 3.99);
+ _RS_ASSERT(d4.z == 4.99);
+ _RS_ASSERT(d4.w == 5.99);
+
+ rsDebug("Testing I8", 0);
+ _RS_ASSERT(i8_2.x == 2);
+ _RS_ASSERT(i8_2.y == 3);
+
+ _RS_ASSERT(i8_3.x == 2);
+ _RS_ASSERT(i8_3.y == 3);
+ _RS_ASSERT(i8_3.z == 4);
+
+ _RS_ASSERT(i8_4.x == 2);
+ _RS_ASSERT(i8_4.y == 3);
+ _RS_ASSERT(i8_4.z == 4);
+ _RS_ASSERT(i8_4.w == 5);
+
+ rsDebug("Testing U8", 0);
+ _RS_ASSERT(u8_2.x == 2);
+ _RS_ASSERT(u8_2.y == 3);
+
+ _RS_ASSERT(u8_3.x == 2);
+ _RS_ASSERT(u8_3.y == 3);
+ _RS_ASSERT(u8_3.z == 4);
+
+ _RS_ASSERT(u8_4.x == 2);
+ _RS_ASSERT(u8_4.y == 3);
+ _RS_ASSERT(u8_4.z == 4);
+ _RS_ASSERT(u8_4.w == 5);
+
+ rsDebug("Testing I16", 0);
+ _RS_ASSERT(i16_2.x == 2);
+ _RS_ASSERT(i16_2.y == 3);
+
+ _RS_ASSERT(i16_3.x == 2);
+ _RS_ASSERT(i16_3.y == 3);
+ _RS_ASSERT(i16_3.z == 4);
+
+ _RS_ASSERT(i16_4.x == 2);
+ _RS_ASSERT(i16_4.y == 3);
+ _RS_ASSERT(i16_4.z == 4);
+ _RS_ASSERT(i16_4.w == 5);
+
+ rsDebug("Testing U16", 0);
+ _RS_ASSERT(u16_2.x == 2);
+ _RS_ASSERT(u16_2.y == 3);
+
+ _RS_ASSERT(u16_3.x == 2);
+ _RS_ASSERT(u16_3.y == 3);
+ _RS_ASSERT(u16_3.z == 4);
+
+ _RS_ASSERT(u16_4.x == 2);
+ _RS_ASSERT(u16_4.y == 3);
+ _RS_ASSERT(u16_4.z == 4);
+ _RS_ASSERT(u16_4.w == 5);
+
+ rsDebug("Testing I32", 0);
+ _RS_ASSERT(i32_2.x == 2);
+ _RS_ASSERT(i32_2.y == 3);
+
+ _RS_ASSERT(i32_3.x == 2);
+ _RS_ASSERT(i32_3.y == 3);
+ _RS_ASSERT(i32_3.z == 4);
+
+ _RS_ASSERT(i32_4.x == 2);
+ _RS_ASSERT(i32_4.y == 3);
+ _RS_ASSERT(i32_4.z == 4);
+ _RS_ASSERT(i32_4.w == 5);
+
+ rsDebug("Testing U32", 0);
+ _RS_ASSERT(u32_2.x == 2);
+ _RS_ASSERT(u32_2.y == 3);
+
+ _RS_ASSERT(u32_3.x == 2);
+ _RS_ASSERT(u32_3.y == 3);
+ _RS_ASSERT(u32_3.z == 4);
+
+ _RS_ASSERT(u32_4.x == 2);
+ _RS_ASSERT(u32_4.y == 3);
+ _RS_ASSERT(u32_4.z == 4);
+ _RS_ASSERT(u32_4.w == 5);
+
+ rsDebug("Testing I64", 0);
+ _RS_ASSERT(i64_2.x == 2);
+ _RS_ASSERT(i64_2.y == 3);
+
+ _RS_ASSERT(i64_3.x == 2);
+ _RS_ASSERT(i64_3.y == 3);
+ _RS_ASSERT(i64_3.z == 4);
+
+ _RS_ASSERT(i64_4.x == 2);
+ _RS_ASSERT(i64_4.y == 3);
+ _RS_ASSERT(i64_4.z == 4);
+ _RS_ASSERT(i64_4.w == 5);
+
+ rsDebug("Testing U64", 0);
+ _RS_ASSERT(u64_2.x == 2);
+ _RS_ASSERT(u64_2.y == 3);
+
+ _RS_ASSERT(u64_3.x == 2);
+ _RS_ASSERT(u64_3.y == 3);
+ _RS_ASSERT(u64_3.z == 4);
+
+ _RS_ASSERT(u64_4.x == 2);
+ _RS_ASSERT(u64_4.y == 3);
+ _RS_ASSERT(u64_4.z == 4);
+ _RS_ASSERT(u64_4.w == 5);
+
+ if (failed) {
+ rsDebug("test_vector FAILED", 0);
+ }
+ else {
+ rsDebug("test_vector PASSED", 0);
+ }
+
+ return failed;
+}
+
+void vector_test() {
+ bool failed = false;
+ failed |= test_vector_types();
+
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
+