diff options
author | Stephen Hines <srhines@google.com> | 2015-07-24 16:45:36 -0700 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2015-07-27 13:04:30 -0700 |
commit | 648a1c137663ef7207684d0d7009dd5518942111 (patch) | |
tree | deb2260741dc70a883a4811282e5725e0f68f9a8 | |
parent | 697efc125b3a9844602551ff1de11f275761e584 (diff) | |
download | android_frameworks_rs-648a1c137663ef7207684d0d7009dd5518942111.tar.gz android_frameworks_rs-648a1c137663ef7207684d0d7009dd5518942111.tar.bz2 android_frameworks_rs-648a1c137663ef7207684d0d7009dd5518942111.zip |
Prepare for arm64 prebuilts of RS support library.
Bug: 22693954
This change fixes update_rs_prebuilts.sh to build for arm64 as well. It
also makes some changes to RSTest_CompatLib for working on arm64 (i.e.
removed APIs, etc.). The old version of RSTest_CompatLib is retained as
RSTest_CompatLibLegacy, but it is disabled from building due to errors
with mma and FORCE_BUILD_RS_COMPAT. We also now need to ensure we
properly build all the required libraries (both .so and .a files).
Change-Id: If89b8a542eb0d61db0ba186d4e3221bcc6e5664b
85 files changed, 9497 insertions, 62 deletions
diff --git a/java/tests/RSTest_CompatLib/Android.mk b/java/tests/RSTest_CompatLib/Android.mk index bcfdec0a..8ef89105 100644 --- a/java/tests/RSTest_CompatLib/Android.mk +++ b/java/tests/RSTest_CompatLib/Android.mk @@ -26,8 +26,8 @@ LOCAL_PACKAGE_NAME := RSTest_Compat LOCAL_STATIC_JAVA_LIBRARIES := android-support-v8-renderscript LOCAL_SDK_VERSION := 8 -LOCAL_RENDERSCRIPT_TARGET_API := 18 -LOCAL_RENDERSCRIPT_COMPATIBILITY := 18 +LOCAL_RENDERSCRIPT_TARGET_API := 23 +LOCAL_RENDERSCRIPT_COMPATIBILITY := 23 LOCAL_RENDERSCRIPT_CC := $(LLVM_RS_CC) LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE := \ @@ -36,6 +36,5 @@ LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE := \ LOCAL_RENDERSCRIPT_FLAGS := -rs-package-name=android.support.v8.renderscript LOCAL_JNI_SHARED_LIBRARIES := librsjni -LOCAL_32_BIT_ONLY := true include $(BUILD_PACKAGE) diff --git a/java/tests/RSTest_CompatLib/src/com/android/rs/test/UT_element.java b/java/tests/RSTest_CompatLib/src/com/android/rs/test/UT_element.java index abfa44c3..87447886 100644 --- a/java/tests/RSTest_CompatLib/src/com/android/rs/test/UT_element.java +++ b/java/tests/RSTest_CompatLib/src/com/android/rs/test/UT_element.java @@ -96,8 +96,6 @@ public class UT_element extends UnitTest { subElemCount = complexElem.getSubElementCount(); _RS_ASSERT("subElemCount == 10", subElemCount == 10); - _RS_ASSERT("complexElem.getSizeBytes() == ScriptField_ComplexStruct.Item.sizeof", - complexElem.getBytesSize() == ScriptField_ComplexStruct.Item.sizeof); for (int i = 0; i < subElemCount; i ++) { _RS_ASSERT("complexElem.getSubElement(i) != null", diff --git a/java/tests/RSTest_CompatLib/src/com/android/rs/test/apitest.rs b/java/tests/RSTest_CompatLib/src/com/android/rs/test/apitest.rs index 865620f2..e046672f 100644 --- a/java/tests/RSTest_CompatLib/src/com/android/rs/test/apitest.rs +++ b/java/tests/RSTest_CompatLib/src/com/android/rs/test/apitest.rs @@ -1119,9 +1119,6 @@ void check_api_presence() { rsSendToClientBlocking(0); rsSendToClientBlocking(0, NULL, 0); - rs_script_call_t sc; - rsForEach(scriptNonNull, allocNonNull, allocNonNull, NULL, 0, &sc); - rsForEach(scriptNonNull, allocNonNull, allocNonNull, NULL, 0); rsForEach(scriptNonNull, allocNonNull, allocNonNull); // rs_debug.rsh @@ -1190,13 +1187,13 @@ void check_api_presence() { i = rsRand(i); i = rsRand(i, i); f = rsRand(f); - f = rsFrac(f); - ui = rsClamp(ui, ui, ui); - i = rsClamp(i, i, i); - us = rsClamp(us, us, us); - s = rsClamp(s, s, s); - uc = rsClamp(uc, uc, uc); - c = rsClamp(c, c, c); + f = fract(f); + ui = clamp(ui, ui, ui); + i = clamp(i, i, i); + us = clamp(us, us, us); + s = clamp(s, s, s); + uc = clamp(uc, uc, uc); + c = clamp(c, c, c); // skip always-inlined rsExtractFrustumPlanes // skip always-inlined rsIsSphereInFrustum @@ -1343,7 +1340,7 @@ static bool test_obj_api() { static bool test_rs_alloc_api() { bool failed = false; - rs_allocation a = rsGetAllocation(allocPtr); + rs_allocation a = allocDst; _RS_ASSERT(rsIsObject(a)); _RS_ASSERT(rsAllocationGetDimX(a) == x); _RS_ASSERT(rsAllocationGetDimY(a) == y); diff --git a/java/tests/RSTest_CompatLib/src/com/android/rs/test/foreach_bounds.rs b/java/tests/RSTest_CompatLib/src/com/android/rs/test/foreach_bounds.rs index 875f2156..006d1e5c 100644 --- a/java/tests/RSTest_CompatLib/src/com/android/rs/test/foreach_bounds.rs +++ b/java/tests/RSTest_CompatLib/src/com/android/rs/test/foreach_bounds.rs @@ -20,48 +20,9 @@ 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); - rsDebug("i: ", i); - rsDebug("j: ", j); - rsDebug("a[j][i]: ", v); - 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 foreach_bounds_test() { static bool failed = false; - rs_script_call_t rssc = {0}; - rssc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; - rssc.xStart = xStart; - rssc.xEnd = xEnd; - rssc.yStart = yStart; - rssc.yEnd = yEnd; - - rsForEach(s, ain, aout, NULL, 0, &rssc); - - failed |= test_root_output(); - if (failed) { rsSendToClientBlocking(RS_MSG_TEST_FAILED); } diff --git a/java/tests/RSTest_CompatLib/src/com/android/rs/test/math.rs b/java/tests/RSTest_CompatLib/src/com/android/rs/test/math.rs index aae29a4c..4a4ad52f 100644 --- a/java/tests/RSTest_CompatLib/src/com/android/rs/test/math.rs +++ b/java/tests/RSTest_CompatLib/src/com/android/rs/test/math.rs @@ -346,7 +346,7 @@ static bool test_int_math(uint32_t index) { TEST_IN_FUNC_IN(clz); TEST_IN_FUNC_IN_IN(min); TEST_IN_FUNC_IN_IN(max); - TEST_I_FUNC_I_I_I(rsClamp); + TEST_I_FUNC_I_I_I(clamp); float time = end(index); diff --git a/java/tests/RSTest_CompatLibLegacy/Android.mk b/java/tests/RSTest_CompatLibLegacy/Android.mk new file mode 100644 index 00000000..2e707984 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/Android.mk @@ -0,0 +1,48 @@ +# +# Copyright (C) 2013 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Bug: 22693954 +# Temporarily disable this build because it doesn't work for 64-bit builds +# with mma on even a separate directory. +ifeq (0,1) + +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := tests + +LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src) + +LOCAL_PACKAGE_NAME := RSTest_CompatLegacy + +LOCAL_STATIC_JAVA_LIBRARIES := android-support-v8-renderscript + +LOCAL_SDK_VERSION := 8 +LOCAL_RENDERSCRIPT_TARGET_API := 18 +LOCAL_RENDERSCRIPT_COMPATIBILITY := 18 + +LOCAL_RENDERSCRIPT_CC := $(LLVM_RS_CC) +LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE := \ + $(TOPDIR)external/clang/lib/Headers \ + $(TOPDIR)frameworks/rs/scriptc + +LOCAL_RENDERSCRIPT_FLAGS := -rs-package-name=android.support.v8.renderscript +LOCAL_JNI_SHARED_LIBRARIES := librsjni +LOCAL_32_BIT_ONLY := true + +include $(BUILD_PACKAGE) + +endif # ifeq (0,1) diff --git a/java/tests/RSTest_CompatLibLegacy/AndroidManifest.xml b/java/tests/RSTest_CompatLibLegacy/AndroidManifest.xml new file mode 100644 index 00000000..85715d57 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/AndroidManifest.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.rs.test_compatlegacy"> + <uses-sdk android:minSdkVersion="8" /> + <uses-sdk android:targetSdkVersion="8" /> + <application + android:label="_RS_Test_CompatLegacy" + android:icon="@drawable/test_pattern"> + <activity android:name="RSTestCompatLegacy" + android:screenOrientation="portrait"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + </application> +</manifest> diff --git a/java/tests/RSTest_CompatLibLegacy/res/drawable-nodpi/test_pattern.png b/java/tests/RSTest_CompatLibLegacy/res/drawable-nodpi/test_pattern.png Binary files differnew file mode 100644 index 00000000..e7d14555 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/res/drawable-nodpi/test_pattern.png diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/RSTest.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/RSTest.java new file mode 100644 index 00000000..10aed171 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/RSTest.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.support.v8.renderscript.RenderScript; + +import android.app.ListActivity; +import android.content.res.Configuration; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.os.Message; +import android.provider.Settings.System; +import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.Window; +import android.widget.Button; +import android.widget.ListView; +import android.widget.ArrayAdapter; + +import java.lang.Runtime; + +public class RSTest extends ListActivity { + + private static final String LOG_TAG = "RSTest_CompatLegacy"; + private static final boolean DEBUG = false; + private static final boolean LOG_ENABLED = true; + + private RenderScript mRS; + private RSTestCore RSTC; + + String mTestNames[]; + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + mRS = RenderScript.create(this); + + RSTC = new RSTestCore(this); + RSTC.init(mRS, getResources()); + } + + static void log(String message) { + if (LOG_ENABLED) { + Log.v(LOG_TAG, message); + } + } + + +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/RSTestCore.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/RSTestCore.java new file mode 100644 index 00000000..d059e451 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/RSTestCore.java @@ -0,0 +1,202 @@ +/* + * Copyright (C) 2008-2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; +import android.util.Log; +import java.util.ArrayList; +import java.util.ListIterator; +import java.util.Timer; +import java.util.TimerTask; +import android.app.ListActivity; +import android.widget.ArrayAdapter; + +public class RSTestCore { + ListActivity mCtx; + + public RSTestCore(ListActivity ctx) { + mCtx = ctx; + } + + private Resources mRes; + private RenderScript mRS; + + private ArrayList<UnitTest> unitTests; + private ListIterator<UnitTest> test_iter; + private UnitTest activeTest; + private boolean stopTesting; + + private ScriptField_ListAllocs_s mListAllocs; + + private ArrayAdapter<UnitTest> testAdapter; + + /* Periodic timer for ensuring future tests get scheduled */ + private Timer mTimer; + public static final int RS_TIMER_PERIOD = 100; + + public void init(RenderScript rs, Resources res) { + mRS = rs; + mRes = res; + stopTesting = false; + + unitTests = new ArrayList<UnitTest>(); + + unitTests.add(new UT_apitest(this, mRes, mCtx)); + unitTests.add(new UT_primitives(this, mRes, mCtx)); + unitTests.add(new UT_instance(this, mRes, mCtx)); + unitTests.add(new UT_constant(this, mRes, mCtx)); + unitTests.add(new UT_vector(this, mRes, mCtx)); + unitTests.add(new UT_unsigned(this, mRes, mCtx)); + unitTests.add(new UT_array_init(this, mRes, mCtx)); + unitTests.add(new UT_array_alloc(this, mRes, mCtx)); + unitTests.add(new UT_alloc_copy(this, mRes, mCtx)); + unitTests.add(new UT_alloc_copyPadded(this, mRes, mCtx)); + unitTests.add(new UT_kernel(this, mRes, mCtx)); + unitTests.add(new UT_kernel_struct(this, mRes, mCtx)); + unitTests.add(new UT_bug_char(this, mRes, mCtx)); + unitTests.add(new UT_clamp(this, mRes, mCtx)); + unitTests.add(new UT_clamp_relaxed(this, mRes, mCtx)); + unitTests.add(new UT_convert(this, mRes, mCtx)); + unitTests.add(new UT_convert_relaxed(this, mRes, mCtx)); + unitTests.add(new UT_copy_test(this, mRes, mCtx)); + unitTests.add(new UT_rsdebug(this, mRes, mCtx)); + unitTests.add(new UT_rstime(this, mRes, mCtx)); + unitTests.add(new UT_rstypes(this, mRes, mCtx)); + unitTests.add(new UT_alloc(this, mRes, mCtx)); + unitTests.add(new UT_refcount(this, mRes, mCtx)); + unitTests.add(new UT_foreach(this, mRes, mCtx)); + unitTests.add(new UT_foreach_bounds(this, mRes, mCtx)); + unitTests.add(new UT_noroot(this, mRes, mCtx)); + unitTests.add(new UT_atomic(this, mRes, mCtx)); + unitTests.add(new UT_struct(this, mRes, mCtx)); + unitTests.add(new UT_math(this, mRes, mCtx)); + unitTests.add(new UT_math_conformance(this, mRes, mCtx)); + unitTests.add(new UT_math_agree(this, mRes, mCtx)); + unitTests.add(new UT_min(this, mRes, mCtx)); + unitTests.add(new UT_int4(this, mRes, mCtx)); + unitTests.add(new UT_element(this, mRes, mCtx)); + unitTests.add(new UT_sampler(this, mRes, mCtx)); + unitTests.add(new UT_fp_mad(this, mRes, mCtx)); + + /* + unitTests.add(new UnitTest(null, "<Pass>", 1)); + unitTests.add(new UnitTest()); + unitTests.add(new UnitTest(null, "<Fail>", -1)); + + for (int i = 0; i < 20; i++) { + unitTests.add(new UnitTest(null, "<Pass>", 1)); + } + */ + + UnitTest [] uta = new UnitTest[unitTests.size()]; + uta = unitTests.toArray(uta); + + mListAllocs = new ScriptField_ListAllocs_s(mRS, uta.length); + for (int i = 0; i < uta.length; i++) { + ScriptField_ListAllocs_s.Item listElem = new ScriptField_ListAllocs_s.Item(); + listElem.text = Allocation.createFromString(mRS, uta[i].name, Allocation.USAGE_SCRIPT); + listElem.result = uta[i].getResult(); + mListAllocs.set(listElem, i, false); + uta[i].setItem(listElem); + } + + mListAllocs.copyAll(); + + testAdapter = new ArrayAdapter<UnitTest>(mCtx, android.R.layout.simple_list_item_1, unitTests); + mCtx.setListAdapter(testAdapter); + + test_iter = unitTests.listIterator(); + refreshTestResults(); /* Kick off the first test */ + + TimerTask pTask = new TimerTask() { + public void run() { + refreshTestResults(); + } + }; + + mTimer = new Timer(); + mTimer.schedule(pTask, RS_TIMER_PERIOD, RS_TIMER_PERIOD); + } + + public void checkAndRunNextTest() { + mCtx.runOnUiThread(new Runnable() { + public void run() { + if (testAdapter != null) + testAdapter.notifyDataSetChanged(); + } + }); + + if (activeTest != null) { + if (!activeTest.isAlive()) { + /* Properly clean up on our last test */ + try { + activeTest.join(); + } + catch (InterruptedException e) { + } + activeTest = null; + } + } + + if (!stopTesting && activeTest == null) { + if (test_iter.hasNext()) { + activeTest = test_iter.next(); + activeTest.start(); + /* This routine will only get called once when a new test + * should start running. The message handler in UnitTest.java + * ensures this. */ + } + else { + if (mTimer != null) { + mTimer.cancel(); + mTimer.purge(); + mTimer = null; + } + } + } + } + + public void refreshTestResults() { + checkAndRunNextTest(); + } + + public void cleanup() { + stopTesting = true; + UnitTest t = activeTest; + + /* Stop periodic refresh of testing */ + if (mTimer != null) { + mTimer.cancel(); + mTimer.purge(); + mTimer = null; + } + + /* Wait to exit until we finish the current test */ + if (t != null) { + try { + t.join(); + } + catch (InterruptedException e) { + } + t = null; + } + + } + +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_alloc.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_alloc.java new file mode 100644 index 00000000..44f3c305 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_alloc.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_alloc extends UnitTest { + private Resources mRes; + + protected UT_alloc(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Alloc", ctx); + mRes = res; + } + + 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).setY(Y); + Allocation A = Allocation.createTyped(RS, typeBuilder.create()); + s.bind_a(A); + s.set_aRaw(A); + + typeBuilder = new Type.Builder(RS, Element.I32(RS)); + typeBuilder.setX(X).setY(Y).setFaces(true); + Allocation AFaces = Allocation.createTyped(RS, typeBuilder.create()); + s.set_aFaces(AFaces); + typeBuilder.setFaces(false).setMipmaps(true); + Allocation ALOD = Allocation.createTyped(RS, typeBuilder.create()); + s.set_aLOD(ALOD); + typeBuilder.setFaces(true).setMipmaps(true); + Allocation AFacesLOD = Allocation.createTyped(RS, typeBuilder.create()); + s.set_aFacesLOD(AFacesLOD); + + 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(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_alloc_copy.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_alloc_copy.java new file mode 100644 index 00000000..30c4e649 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_alloc_copy.java @@ -0,0 +1,658 @@ +/* + * Copyright (C) 2015 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.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; +import java.util.Random; + +public class UT_alloc_copy extends UnitTest { + private Resources mRes; + + protected UT_alloc_copy(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Allocation CopyTo", ctx); + mRes = res; + } + + public void run() { + RenderScript mRS = RenderScript.create(mCtx); + + allocation_copy1DRangeTo_Byte(mRS); + allocation_copy1DRangeTo_Short(mRS); + allocation_copy1DRangeTo_Int(mRS); + allocation_copy1DRangeTo_Float(mRS); + allocation_copy1DRangeTo_Long(mRS); + + allocation_copy2DRangeTo_Byte(mRS); + allocation_copy2DRangeTo_Short(mRS); + allocation_copy2DRangeTo_Int(mRS); + allocation_copy2DRangeTo_Float(mRS); + allocation_copy2DRangeTo_Long(mRS); + + allocation_copy1DRangeToUnchecked_Byte(mRS); + allocation_copy1DRangeToUnchecked_Short(mRS); + allocation_copy1DRangeToUnchecked_Int(mRS); + allocation_copy1DRangeToUnchecked_Float(mRS); + allocation_copy1DRangeToUnchecked_Long(mRS); + + mRS.destroy(); + passTest(); + } + + public void allocation_copy1DRangeTo_Byte(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(512); + int arr_len = width; + + byte[] inArray = new byte[arr_len]; + byte[] outArray = new byte[arr_len]; + random.nextBytes(inArray); + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I8(mRS)); + typeBuilder.setX(width); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + int offset = random.nextInt(arr_len); + int count = arr_len - offset; + alloc.copy1DRangeFrom(offset, count, inArray); + alloc.copy1DRangeTo(offset, count, outArray); + + boolean result = true; + for (int i = 0; i < count; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + for (int i = count; i < arr_len; i++) { + if (outArray[i] != 0) { + result = false; + android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Allocation CopyTo Test", "copy1DRangeTo_Byte TEST PASSED"); + } else { + failTest(); + } + } + + public void allocation_copy1DRangeTo_Short(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(512); + int arr_len = width; + + short[] inArray = new short[arr_len]; + short[] outArray = new short[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = (short)random.nextInt(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I16(mRS)); + typeBuilder.setX(width); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + int offset = random.nextInt(arr_len); + int count = arr_len - offset; + alloc.copy1DRangeFrom(offset, count, inArray); + alloc.copy1DRangeTo(offset, count, outArray); + + boolean result = true; + for (int i = 0; i < count; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + for (int i = count; i < arr_len; i++) { + if (outArray[i] != 0) { + result = false; + android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Allocation CopyTo Test", "copy1DRangeTo_Short TEST PASSED"); + } else { + failTest(); + } + } + + public void allocation_copy1DRangeTo_Int(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(512); + int arr_len = width; + + int[] inArray = new int[arr_len]; + int[] outArray = new int[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextInt(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I32(mRS)); + typeBuilder.setX(width); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + int offset = random.nextInt(arr_len); + int count = arr_len - offset; + alloc.copy1DRangeFrom(offset, count, inArray); + alloc.copy1DRangeTo(offset, count, outArray); + + boolean result = true; + for (int i = 0; i < count; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + for (int i = count; i < arr_len; i++) { + if (outArray[i] != 0) { + result = false; + android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Allocation CopyTo Test", "copy1DRangeTo_Int TEST PASSED"); + } else { + failTest(); + } + } + + public void allocation_copy1DRangeTo_Float(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(512); + int arr_len = width; + + float[] inArray = new float[arr_len]; + float[] outArray = new float[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextFloat(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.F32(mRS)); + typeBuilder.setX(width); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + int offset = random.nextInt(arr_len); + int count = arr_len - offset; + alloc.copy1DRangeFrom(offset, count, inArray); + alloc.copy1DRangeTo(offset, count, outArray); + + boolean result = true; + for (int i = 0; i < count; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + for (int i = count; i < arr_len; i++) { + if (outArray[i] != 0f) { + result = false; + android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Allocation CopyTo Test", "copy1DRangeTo_Float TEST PASSED"); + } else { + failTest(); + } + } + + public void allocation_copy1DRangeTo_Long(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(512); + int arr_len = width; + + long[] inArray = new long[arr_len]; + long[] outArray = new long[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextLong(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I64(mRS)); + typeBuilder.setX(width); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + int offset = random.nextInt(arr_len); + int count = arr_len - offset; + alloc.copy1DRangeFrom(offset, count, inArray); + alloc.copy1DRangeTo(offset, count, outArray); + + boolean result = true; + for (int i = 0; i < count; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + for (int i = count; i < arr_len; i++) { + if (outArray[i] != 0) { + result = false; + android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Allocation CopyTo Test", "copy1DRangeTo_Long TEST PASSED"); + } else { + failTest(); + } + } + + public void allocation_copy2DRangeTo_Byte(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(128); + int height = random.nextInt(128); + int xoff = random.nextInt(width); + int yoff = random.nextInt(height); + int xcount = width - xoff; + int ycount = height - yoff; + int arr_len = xcount * ycount; + + byte[] inArray = new byte[arr_len]; + byte[] outArray = new byte[arr_len]; + random.nextBytes(inArray); + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I8(mRS)); + typeBuilder.setX(width).setY(height); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.copy2DRangeFrom(xoff, yoff, xcount, ycount, inArray); + alloc.copy2DRangeTo(xoff, yoff, xcount, ycount, outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Allocation CopyTo Test", "copy2DRangeTo_Byte TEST PASSED"); + } else { + failTest(); + } + } + + public void allocation_copy2DRangeTo_Short(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(128); + int height = random.nextInt(128); + int xoff = random.nextInt(width); + int yoff = random.nextInt(height); + int xcount = width - xoff; + int ycount = height - yoff; + int arr_len = xcount * ycount; + + short[] inArray = new short[arr_len]; + short[] outArray = new short[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = (short)random.nextInt(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I16(mRS)); + typeBuilder.setX(width).setY(height); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.copy2DRangeFrom(xoff, yoff, xcount, ycount, inArray); + alloc.copy2DRangeTo(xoff, yoff, xcount, ycount, outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Allocation CopyTo Test", "copy2DRangeTo_Short TEST PASSED"); + } else { + failTest(); + } + } + + public void allocation_copy2DRangeTo_Int(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(128); + int height = random.nextInt(128); + int xoff = random.nextInt(width); + int yoff = random.nextInt(height); + int xcount = width - xoff; + int ycount = height - yoff; + int arr_len = xcount * ycount; + + int[] inArray = new int[arr_len]; + int[] outArray = new int[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextInt(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I32(mRS)); + typeBuilder.setX(width).setY(height); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.copy2DRangeFrom(xoff, yoff, xcount, ycount, inArray); + alloc.copy2DRangeTo(xoff, yoff, xcount, ycount, outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Allocation CopyTo Test", "copy2DRangeTo_Int TEST PASSED"); + } else { + failTest(); + } + } + + public void allocation_copy2DRangeTo_Float(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(128); + int height = random.nextInt(128); + int xoff = random.nextInt(width); + int yoff = random.nextInt(height); + int xcount = width - xoff; + int ycount = height - yoff; + int arr_len = xcount * ycount; + + float[] inArray = new float[arr_len]; + float[] outArray = new float[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextFloat(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.F32(mRS)); + typeBuilder.setX(width).setY(height); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.copy2DRangeFrom(xoff, yoff, xcount, ycount, inArray); + alloc.copy2DRangeTo(xoff, yoff, xcount, ycount, outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Allocation CopyTo Test", "copy2DRangeTo_Float TEST PASSED"); + } else { + failTest(); + } + } + + public void allocation_copy2DRangeTo_Long(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(128); + int height = random.nextInt(128); + int xoff = random.nextInt(width); + int yoff = random.nextInt(height); + int xcount = width - xoff; + int ycount = height - yoff; + int arr_len = xcount * ycount; + + long[] inArray = new long[arr_len]; + long[] outArray = new long[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextLong(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I64(mRS)); + typeBuilder.setX(width).setY(height); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.copy2DRangeFrom(xoff, yoff, xcount, ycount, inArray); + alloc.copy2DRangeTo(xoff, yoff, xcount, ycount, outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Allocation CopyTo Test", "copy2DRangeTo_Long TEST PASSED"); + } else { + failTest(); + } + } + + + public void allocation_copy1DRangeToUnchecked_Byte(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(512); + int arr_len = width; + + byte[] inArray = new byte[arr_len]; + byte[] outArray = new byte[arr_len]; + random.nextBytes(inArray); + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I8(mRS)); + typeBuilder.setX(width); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + int offset = random.nextInt(arr_len); + int count = arr_len - offset; + alloc.copy1DRangeFrom(offset, count, inArray); + alloc.copy1DRangeToUnchecked(offset, count, outArray); + + boolean result = true; + for (int i = 0; i < count; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + for (int i = count; i < arr_len; i++) { + if (outArray[i] != 0) { + result = false; + android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Allocation CopyTo Test", "copy1DRangeToUnchecked_Byte TEST PASSED"); + } else { + failTest(); + } + } + + public void allocation_copy1DRangeToUnchecked_Short(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(512); + int arr_len = width; + + short[] inArray = new short[arr_len]; + short[] outArray = new short[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = (short)random.nextInt(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I16(mRS)); + typeBuilder.setX(width); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + int offset = random.nextInt(arr_len); + int count = arr_len - offset; + alloc.copy1DRangeFrom(offset, count, inArray); + alloc.copy1DRangeToUnchecked(offset, count, outArray); + + boolean result = true; + for (int i = 0; i < count; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + for (int i = count; i < arr_len; i++) { + if (outArray[i] != 0) { + result = false; + android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Allocation CopyTo Test", "copy1DRangeToUnchecked_Short TEST PASSED"); + } else { + failTest(); + } + } + + public void allocation_copy1DRangeToUnchecked_Int(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(512); + int arr_len = width; + + int[] inArray = new int[arr_len]; + int[] outArray = new int[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextInt(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I32(mRS)); + typeBuilder.setX(width); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + int offset = random.nextInt(arr_len); + int count = arr_len - offset; + alloc.copy1DRangeFrom(offset, count, inArray); + alloc.copy1DRangeToUnchecked(offset, count, outArray); + + boolean result = true; + for (int i = 0; i < count; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + for (int i = count; i < arr_len; i++) { + if (outArray[i] != 0) { + result = false; + android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Allocation CopyTo Test", "copy1DRangeToUnchecked_Int TEST PASSED"); + } else { + failTest(); + } + } + + public void allocation_copy1DRangeToUnchecked_Float(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(512); + int arr_len = width; + + float[] inArray = new float[arr_len]; + float[] outArray = new float[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextFloat(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.F32(mRS)); + typeBuilder.setX(width); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + int offset = random.nextInt(arr_len); + int count = arr_len - offset; + alloc.copy1DRangeFrom(offset, count, inArray); + alloc.copy1DRangeToUnchecked(offset, count, outArray); + + boolean result = true; + for (int i = 0; i < count; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + for (int i = count; i < arr_len; i++) { + if (outArray[i] != 0f) { + result = false; + android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Allocation CopyTo Test", "copy1DRangeToUnchecked_Float TEST PASSED"); + } else { + failTest(); + } + } + + public void allocation_copy1DRangeToUnchecked_Long(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(512); + int arr_len = width; + + long[] inArray = new long[arr_len]; + long[] outArray = new long[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextLong(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I64(mRS)); + typeBuilder.setX(width); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + int offset = random.nextInt(arr_len); + int count = arr_len - offset; + alloc.copy1DRangeFrom(offset, count, inArray); + alloc.copy1DRangeToUnchecked(offset, count, outArray); + + boolean result = true; + for (int i = 0; i < count; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + for (int i = count; i < arr_len; i++) { + if (outArray[i] != 0) { + result = false; + android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Allocation CopyTo Test", "copy1DRangeToUnchecked_Long TEST PASSED"); + } else { + failTest(); + } + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_alloc_copyPadded.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_alloc_copyPadded.java new file mode 100644 index 00000000..968ac304 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_alloc_copyPadded.java @@ -0,0 +1,1316 @@ +/* + * Copyright (C) 2015 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.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; +import java.util.Random; + +public class UT_alloc_copyPadded extends UnitTest { + private Resources mRes; + + protected UT_alloc_copyPadded(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Allocation CopyTo Padded", ctx); + mRes = res; + } + + public void run() { + RenderScript mRS = RenderScript.create(mCtx); + + testAllocation_Byte3_1D(mRS); + testAllocation_Byte3_2D(mRS); + testAllocation_Byte3_3D(mRS); + + testAllocation_Short3_1D(mRS); + testAllocation_Short3_2D(mRS); + testAllocation_Short3_3D(mRS); + + testAllocation_Int3_1D(mRS); + testAllocation_Int3_2D(mRS); + testAllocation_Int3_3D(mRS); + + testAllocation_Float3_1D(mRS); + testAllocation_Float3_2D(mRS); + testAllocation_Float3_3D(mRS); + + testAllocation_Double3_1D(mRS); + testAllocation_Double3_2D(mRS); + testAllocation_Double3_3D(mRS); + + testAllocation_Long3_1D(mRS); + testAllocation_Long3_2D(mRS); + testAllocation_Long3_3D(mRS); + + + testAllocation_copy1DRangeTo_Byte3(mRS); + testAllocation_copy1DRangeTo_Short3(mRS); + testAllocation_copy1DRangeTo_Int3(mRS); + testAllocation_copy1DRangeTo_Float3(mRS); + testAllocation_copy1DRangeTo_Long3(mRS); + + testAllocation_copy2DRangeTo_Byte3(mRS); + testAllocation_copy2DRangeTo_Short3(mRS); + testAllocation_copy2DRangeTo_Int3(mRS); + testAllocation_copy2DRangeTo_Float3(mRS); + testAllocation_copy2DRangeTo_Long3(mRS); + + testAllocation_copy1DRangeToUnchecked_Byte3(mRS); + testAllocation_copy1DRangeToUnchecked_Short3(mRS); + testAllocation_copy1DRangeToUnchecked_Int3(mRS); + testAllocation_copy1DRangeToUnchecked_Float3(mRS); + testAllocation_copy1DRangeToUnchecked_Long3(mRS); + + mRS.destroy(); + passTest(); + } + + public void testAllocation_Byte3_1D(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(512); + int arr_len = width * 3; + + byte[] inArray = new byte[arr_len]; + byte[] outArray = new byte[arr_len]; + random.nextBytes(inArray); + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I8_3(mRS)); + typeBuilder.setX(width); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + alloc.copyFrom(inArray); + alloc.copyTo(outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "" + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "Byte1D TEST PASSED"); + } else { + failTest(); + } + } + + public void testAllocation_Byte3_2D(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(128); + int height = random.nextInt(128); + int arr_len = width * height * 3; + + byte[] inArray = new byte[arr_len]; + byte[] outArray = new byte[arr_len]; + random.nextBytes(inArray); + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I8_3(mRS)); + typeBuilder.setX(width).setY(height); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + alloc.copyFrom(inArray); + alloc.copyTo(outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "" + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "Byte2D TEST PASSED"); + } else { + failTest(); + } + } + + public void testAllocation_Byte3_3D(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int w = random.nextInt(32); + int h = random.nextInt(32); + int d = random.nextInt(32); + int arr_len = w * d * h * 3; + + byte[] inArray = new byte[arr_len]; + byte[] outArray = new byte[arr_len]; + random.nextBytes(inArray); + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I8_3(mRS)); + typeBuilder.setX(w).setY(h).setZ(d); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + alloc.copyFrom(inArray); + alloc.copyTo(outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "" + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "Byte3D TEST PASSED"); + } else { + failTest(); + } + } + + public void testAllocation_Short3_1D(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(512); + int arr_len = width * 3; + + short[] inArray = new short[arr_len]; + short[] outArray = new short[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = (short)random.nextInt(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I16_3(mRS)); + typeBuilder.setX(width); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + alloc.copyFrom(inArray); + alloc.copyTo(outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "" + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "Short1D TEST PASSED"); + } else { + failTest(); + } + } + + public void testAllocation_Short3_2D(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(128); + int height = random.nextInt(128); + int arr_len = width * height * 3; + + short[] inArray = new short[arr_len]; + short[] outArray = new short[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = (short)random.nextInt(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I16_3(mRS)); + typeBuilder.setX(width).setY(height); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + alloc.copyFrom(inArray); + alloc.copyTo(outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "" + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "Short2D TEST PASSED"); + } else { + failTest(); + } + } + + public void testAllocation_Short3_3D(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int w = random.nextInt(32); + int h = random.nextInt(32); + int d = random.nextInt(32); + int arr_len = w * d * h * 3; + + short[] inArray = new short[arr_len]; + short[] outArray = new short[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = (short)random.nextInt(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I16_3(mRS)); + typeBuilder.setX(w).setY(h).setZ(d); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + alloc.copyFrom(inArray); + alloc.copyTo(outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "" + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "Short3D TEST PASSED"); + } else { + failTest(); + } + } + + public void testAllocation_Int3_1D(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(512); + int arr_len = width * 3; + + int[] inArray = new int[arr_len]; + int[] outArray = new int[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextInt(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I32_3(mRS)); + typeBuilder.setX(width); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + alloc.copyFrom(inArray); + alloc.copyTo(outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "" + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "Int1D TEST PASSED"); + } else { + failTest(); + } + } + + public void testAllocation_Int3_2D(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(128); + int height = random.nextInt(128); + int arr_len = width * height * 3; + + int[] inArray = new int[arr_len]; + int[] outArray = new int[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextInt(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I32_3(mRS)); + typeBuilder.setX(width).setY(height); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + alloc.copyFrom(inArray); + alloc.copyTo(outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "" + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "Int2D TEST PASSED"); + } else { + failTest(); + } + } + + public void testAllocation_Int3_3D(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int w = random.nextInt(32); + int h = random.nextInt(32); + int d = random.nextInt(32); + int arr_len = w * d * h * 3; + + int[] inArray = new int[arr_len]; + int[] outArray = new int[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextInt(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I32_3(mRS)); + typeBuilder.setX(w).setY(h).setZ(d); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + alloc.copyFrom(inArray); + alloc.copyTo(outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "" + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "Int3D TEST PASSED"); + } else { + failTest(); + } + } + + public void testAllocation_Float3_1D(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(512); + int arr_len = width * 3; + + float[] inArray = new float[arr_len]; + float[] outArray = new float[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextFloat(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.F32_3(mRS)); + typeBuilder.setX(width); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + alloc.copyFrom(inArray); + alloc.copyTo(outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "" + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "Float1D TEST PASSED"); + } else { + failTest(); + } + } + public void testAllocation_Float3_2D(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(128); + int height = random.nextInt(128); + int arr_len = width * height * 3; + + float[] inArray = new float[arr_len]; + float[] outArray = new float[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextFloat(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.F32_3(mRS)); + typeBuilder.setX(width).setY(height); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + alloc.copyFrom(inArray); + alloc.copyTo(outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "" + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "Float2D TEST PASSED"); + } else { + failTest(); + } + } + public void testAllocation_Float3_3D(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int w = random.nextInt(32); + int h = random.nextInt(32); + int d = random.nextInt(32); + int arr_len = w * d * h * 3; + + float[] inArray = new float[arr_len]; + float[] outArray = new float[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextFloat(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.F32_3(mRS)); + typeBuilder.setX(w).setY(h).setZ(d); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + alloc.copyFrom(inArray); + alloc.copyTo(outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "" + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "Float3D TEST PASSED"); + } else { + failTest(); + } + } + + public void testAllocation_Double3_1D(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(512); + int arr_len = width * 3; + + double[] inArray = new double[arr_len]; + double[] outArray = new double[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = (double)random.nextFloat(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.F64_3(mRS)); + typeBuilder.setX(width); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + alloc.copyFrom(inArray); + alloc.copyTo(outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "" + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "Double1D TEST PASSED"); + } else { + failTest(); + } + } + public void testAllocation_Double3_2D(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(128); + int height = random.nextInt(128); + int arr_len = width * height * 3; + + double[] inArray = new double[arr_len]; + double[] outArray = new double[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = (double)random.nextFloat(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.F64_3(mRS)); + typeBuilder.setX(width).setY(height); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + alloc.copyFrom(inArray); + alloc.copyTo(outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "" + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "Double2D TEST PASSED"); + } else { + failTest(); + } + } + public void testAllocation_Double3_3D(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int w = random.nextInt(32); + int h = random.nextInt(32); + int d = random.nextInt(32); + int arr_len = w * d * h * 3; + + double[] inArray = new double[arr_len]; + double[] outArray = new double[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = (double)random.nextFloat(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.F64_3(mRS)); + typeBuilder.setX(w).setY(h).setZ(d); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + alloc.copyFrom(inArray); + alloc.copyTo(outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "" + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "Double3D TEST PASSED"); + } else { + failTest(); + } + } + + public void testAllocation_Long3_1D(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(512); + int arr_len = width * 3; + + long[] inArray = new long[arr_len]; + long[] outArray = new long[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextLong(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I64_3(mRS)); + typeBuilder.setX(width); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + alloc.copyFrom(inArray); + alloc.copyTo(outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "" + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "Long1D TEST PASSED"); + } else { + failTest(); + } + } + + public void testAllocation_Long3_2D(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(128); + int height = random.nextInt(128); + int arr_len = width * height * 3; + + long[] inArray = new long[arr_len]; + long[] outArray = new long[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextLong(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I64_3(mRS)); + typeBuilder.setX(width).setY(height); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + alloc.copyFrom(inArray); + alloc.copyTo(outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "" + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "Long2D TEST PASSED"); + } else { + failTest(); + } + } + + public void testAllocation_Long3_3D(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int w = random.nextInt(32); + int h = random.nextInt(32); + int d = random.nextInt(32); + int arr_len = w * d * h * 3; + + long[] inArray = new long[arr_len]; + long[] outArray = new long[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextLong(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I64_3(mRS)); + typeBuilder.setX(w).setY(h).setZ(d); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + alloc.copyFrom(inArray); + alloc.copyTo(outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "" + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "Long3D TEST PASSED"); + } else { + failTest(); + } + } + + + public void testAllocation_copy1DRangeTo_Byte3(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(512); + int arr_len = width * 3; + + byte[] inArray = new byte[arr_len]; + byte[] outArray = new byte[arr_len]; + random.nextBytes(inArray); + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I8_3(mRS)); + typeBuilder.setX(width); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + int offset = random.nextInt(width); + int count = width - offset; + alloc.copy1DRangeFrom(offset, count, inArray); + alloc.copy1DRangeTo(offset, count, outArray); + + boolean result = true; + for (int i = 0; i < count * 3; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + for (int i = count * 3; i < arr_len; i++) { + if (outArray[i] != 0) { + result = false; + android.util.Log.v("Alloc Padding Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "copy1DRangeTo_Byte TEST PASSED"); + } else { + failTest(); + } + } + + public void testAllocation_copy1DRangeTo_Short3(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(512); + int arr_len = width * 3; + + short[] inArray = new short[arr_len]; + short[] outArray = new short[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = (short)random.nextInt(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I16_3(mRS)); + typeBuilder.setX(width); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + int offset = random.nextInt(width); + int count = width - offset; + alloc.copy1DRangeFrom(offset, count, inArray); + alloc.copy1DRangeTo(offset, count, outArray); + + boolean result = true; + for (int i = 0; i < count * 3; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + for (int i = count * 3; i < arr_len; i++) { + if (outArray[i] != 0) { + result = false; + android.util.Log.v("Alloc Padding Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "copy1DRangeTo_Short TEST PASSED"); + } else { + failTest(); + } + } + + public void testAllocation_copy1DRangeTo_Int3(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(512); + int arr_len = width * 3; + + int[] inArray = new int[arr_len]; + int[] outArray = new int[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextInt(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I32_3(mRS)); + typeBuilder.setX(width); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + int offset = random.nextInt(width); + int count = width - offset; + alloc.copy1DRangeFrom(offset, count, inArray); + alloc.copy1DRangeTo(offset, count, outArray); + + boolean result = true; + for (int i = 0; i < count * 3; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + for (int i = count * 3; i < arr_len; i++) { + if (outArray[i] != 0) { + result = false; + android.util.Log.v("Alloc Padding Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "copy1DRangeTo_Int TEST PASSED"); + } else { + failTest(); + } + } + + public void testAllocation_copy1DRangeTo_Float3(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(512); + int arr_len = width * 3; + + float[] inArray = new float[arr_len]; + float[] outArray = new float[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextFloat(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.F32_3(mRS)); + typeBuilder.setX(width); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + int offset = random.nextInt(width); + int count = width - offset; + alloc.copy1DRangeFrom(offset, count, inArray); + alloc.copy1DRangeTo(offset, count, outArray); + + boolean result = true; + for (int i = 0; i < count * 3; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + for (int i = count * 3; i < arr_len; i++) { + if (outArray[i] != 0f) { + result = false; + android.util.Log.v("Alloc Padding Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "copy1DRangeTo_Float TEST PASSED"); + } else { + failTest(); + } + } + + public void testAllocation_copy1DRangeTo_Long3(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(512); + int arr_len = width * 3; + + long[] inArray = new long[arr_len]; + long[] outArray = new long[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextLong(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I64_3(mRS)); + typeBuilder.setX(width); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + int offset = random.nextInt(width); + int count = width - offset; + alloc.copy1DRangeFrom(offset, count, inArray); + alloc.copy1DRangeTo(offset, count, outArray); + + boolean result = true; + for (int i = 0; i < count * 3; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + for (int i = count * 3; i < arr_len; i++) { + if (outArray[i] != 0) { + result = false; + android.util.Log.v("Alloc Padding Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "copy1DRangeTo_Long TEST PASSED"); + } else { + failTest(); + } + } + + public void testAllocation_copy2DRangeTo_Byte3(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(128); + int height = random.nextInt(128); + int xoff = random.nextInt(width); + int yoff = random.nextInt(height); + int xcount = width - xoff; + int ycount = height - yoff; + int arr_len = xcount * ycount * 3; + + byte[] inArray = new byte[arr_len]; + byte[] outArray = new byte[arr_len]; + random.nextBytes(inArray); + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I8_3(mRS)); + typeBuilder.setX(width).setY(height); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + alloc.copy2DRangeFrom(xoff, yoff, xcount, ycount, inArray); + alloc.copy2DRangeTo(xoff, yoff, xcount, ycount, outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "copy2DRangeTo_Byte TEST PASSED"); + } else { + failTest(); + } + } + + public void testAllocation_copy2DRangeTo_Short3(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(128); + int height = random.nextInt(128); + int xoff = random.nextInt(width); + int yoff = random.nextInt(height); + int xcount = width - xoff; + int ycount = height - yoff; + int arr_len = xcount * ycount * 3; + + short[] inArray = new short[arr_len]; + short[] outArray = new short[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = (short)random.nextInt(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I16_3(mRS)); + typeBuilder.setX(width).setY(height); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + alloc.copy2DRangeFrom(xoff, yoff, xcount, ycount, inArray); + alloc.copy2DRangeTo(xoff, yoff, xcount, ycount, outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "copy2DRangeTo_Short TEST PASSED"); + } else { + failTest(); + } + } + + public void testAllocation_copy2DRangeTo_Int3(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(128); + int height = random.nextInt(128); + int xoff = random.nextInt(width); + int yoff = random.nextInt(height); + int xcount = width - xoff; + int ycount = height - yoff; + int arr_len = xcount * ycount * 3; + + int[] inArray = new int[arr_len]; + int[] outArray = new int[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextInt(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I32_3(mRS)); + typeBuilder.setX(width).setY(height); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + alloc.copy2DRangeFrom(xoff, yoff, xcount, ycount, inArray); + alloc.copy2DRangeTo(xoff, yoff, xcount, ycount, outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "copy2DRangeTo_Int TEST PASSED"); + } else { + failTest(); + } + } + + public void testAllocation_copy2DRangeTo_Float3(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(128); + int height = random.nextInt(128); + int xoff = random.nextInt(width); + int yoff = random.nextInt(height); + int xcount = width - xoff; + int ycount = height - yoff; + int arr_len = xcount * ycount * 3; + + float[] inArray = new float[arr_len]; + float[] outArray = new float[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextFloat(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.F32_3(mRS)); + typeBuilder.setX(width).setY(height); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + alloc.copy2DRangeFrom(xoff, yoff, xcount, ycount, inArray); + alloc.copy2DRangeTo(xoff, yoff, xcount, ycount, outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "copy2DRangeTo_Float TEST PASSED"); + } else { + failTest(); + } + } + + public void testAllocation_copy2DRangeTo_Long3(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(128); + int height = random.nextInt(128); + int xoff = random.nextInt(width); + int yoff = random.nextInt(height); + int xcount = width - xoff; + int ycount = height - yoff; + int arr_len = xcount * ycount * 3; + + long[] inArray = new long[arr_len]; + long[] outArray = new long[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextLong(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I64_3(mRS)); + typeBuilder.setX(width).setY(height); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + alloc.copy2DRangeFrom(xoff, yoff, xcount, ycount, inArray); + alloc.copy2DRangeTo(xoff, yoff, xcount, ycount, outArray); + + boolean result = true; + for (int i = 0; i < arr_len; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "copy2DRangeTo_Long TEST PASSED"); + } else { + failTest(); + } + } + + + public void testAllocation_copy1DRangeToUnchecked_Byte3(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(512); + int arr_len = width * 3; + + byte[] inArray = new byte[arr_len]; + byte[] outArray = new byte[arr_len]; + random.nextBytes(inArray); + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I8_3(mRS)); + typeBuilder.setX(width); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + int offset = random.nextInt(width); + int count = width - offset; + alloc.copy1DRangeFrom(offset, count, inArray); + alloc.copy1DRangeToUnchecked(offset, count, outArray); + + boolean result = true; + for (int i = 0; i < count * 3; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + for (int i = count * 3; i < arr_len; i++) { + if (outArray[i] != 0) { + result = false; + android.util.Log.v("Alloc Padding Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "copy1DRangeToUnchecked_Byte TEST PASSED"); + } else { + failTest(); + } + } + + public void testAllocation_copy1DRangeToUnchecked_Short3(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(512); + int arr_len = width * 3; + + short[] inArray = new short[arr_len]; + short[] outArray = new short[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = (short)random.nextInt(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I16_3(mRS)); + typeBuilder.setX(width); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + int offset = random.nextInt(width); + int count = width - offset; + alloc.copy1DRangeFrom(offset, count, inArray); + alloc.copy1DRangeToUnchecked(offset, count, outArray); + + boolean result = true; + for (int i = 0; i < count * 3; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + for (int i = count * 3; i < arr_len; i++) { + if (outArray[i] != 0) { + result = false; + android.util.Log.v("Alloc Padding Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "copy1DRangeToUnchecked_Short TEST PASSED"); + } else { + failTest(); + } + } + + public void testAllocation_copy1DRangeToUnchecked_Int3(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(512); + int arr_len = width * 3; + + int[] inArray = new int[arr_len]; + int[] outArray = new int[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextInt(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I32_3(mRS)); + typeBuilder.setX(width); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + int offset = random.nextInt(width); + int count = width - offset; + alloc.copy1DRangeFrom(offset, count, inArray); + alloc.copy1DRangeToUnchecked(offset, count, outArray); + + boolean result = true; + for (int i = 0; i < count * 3; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + for (int i = count * 3; i < arr_len; i++) { + if (outArray[i] != 0) { + result = false; + android.util.Log.v("Alloc Padding Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "copy1DRangeToUnchecked_Int TEST PASSED"); + } else { + failTest(); + } + } + + public void testAllocation_copy1DRangeToUnchecked_Float3(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(512); + int arr_len = width * 3; + + float[] inArray = new float[arr_len]; + float[] outArray = new float[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextFloat(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.F32_3(mRS)); + typeBuilder.setX(width); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + int offset = random.nextInt(width); + int count = width - offset; + alloc.copy1DRangeFrom(offset, count, inArray); + alloc.copy1DRangeToUnchecked(offset, count, outArray); + + boolean result = true; + for (int i = 0; i < count * 3; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + for (int i = count * 3; i < arr_len; i++) { + if (outArray[i] != 0f) { + result = false; + android.util.Log.v("Alloc Padding Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "copy1DRangeToUnchecked_Float TEST PASSED"); + } else { + failTest(); + } + } + + public void testAllocation_copy1DRangeToUnchecked_Long3(RenderScript mRS) { + Random random = new Random(0x172d8ab9); + int width = random.nextInt(512); + int arr_len = width * 3; + + long[] inArray = new long[arr_len]; + long[] outArray = new long[arr_len]; + + for (int i = 0; i < arr_len; i++) { + inArray[i] = random.nextLong(); + } + + Type.Builder typeBuilder = new Type.Builder(mRS, Element.I64_3(mRS)); + typeBuilder.setX(width); + Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); + alloc.setAutoPadding(true); + int offset = random.nextInt(width); + int count = width - offset; + alloc.copy1DRangeFrom(offset, count, inArray); + alloc.copy1DRangeToUnchecked(offset, count, outArray); + + boolean result = true; + for (int i = 0; i < count * 3; i++) { + if (inArray[i] != outArray[i]) { + result = false; + android.util.Log.v("Alloc Padding Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + for (int i = count * 3; i < arr_len; i++) { + if (outArray[i] != 0) { + result = false; + android.util.Log.v("Alloc Padding Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); + break; + } + } + if (result) { + android.util.Log.v("Alloc Padding Test", "copy1DRangeToUnchecked_Long TEST PASSED"); + } else { + failTest(); + } + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_apitest.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_apitest.java new file mode 100644 index 00000000..fd5fc8b6 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_apitest.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_apitest extends UnitTest { + private Resources mRes; + + protected UT_apitest(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "API Test", ctx); + mRes = res; + } + + public void run() { + RenderScript pRS = RenderScript.create(mCtx); + ScriptC_apitest s = new ScriptC_apitest(pRS); + pRS.setMessageHandler(mRsMessage); + Element elem = Element.I8(pRS); + Type.Builder typeBuilder = new Type.Builder(pRS, elem); + + int x = 5; + int y = 7; + int z = 0; // Don't actually setZ() + s.set_x(x); + s.set_y(y); + s.set_z(z); + typeBuilder.setX(x).setY(y); + Type type = typeBuilder.create(); + Allocation alloc = Allocation.createTyped(pRS, type); + Allocation allocDst = Allocation.createTyped(pRS, type); + Sampler sampler = Sampler.CLAMP_NEAREST(pRS); + s.set_elemNonNull(elem); + s.set_typeNonNull(type); + s.set_allocNonNull(alloc); + s.set_allocDst(allocDst); + s.set_samplerNonNull(sampler); + s.set_scriptNonNull(s); + s.bind_allocPtr(alloc); + + s.invoke_api_test(); + pRS.finish(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_array_alloc.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_array_alloc.java new file mode 100644 index 00000000..fc0d0838 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_array_alloc.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_array_alloc extends UnitTest { + private Resources mRes; + + protected UT_array_alloc(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Array Allocation", ctx); + mRes = res; + } + + 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(); + waitForMessage(); + pRS.destroy(); + passTest(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_array_init.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_array_init.java new file mode 100644 index 00000000..023e4747 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_array_init.java @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_array_init extends UnitTest { + private Resources mRes; + + protected UT_array_init(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Array Init", ctx); + mRes = res; + } + + 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(); + waitForMessage(); + pRS.destroy(); + passTest(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_atomic.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_atomic.java new file mode 100644 index 00000000..947bc7d0 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_atomic.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_atomic extends UnitTest { + private Resources mRes; + + protected UT_atomic(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Atomics", ctx); + mRes = res; + } + + public void run() { + RenderScript pRS = RenderScript.create(mCtx); + ScriptC_atomic s = new ScriptC_atomic(pRS); + pRS.setMessageHandler(mRsMessage); + s.invoke_atomic_test(); + pRS.finish(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_bug_char.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_bug_char.java new file mode 100644 index 00000000..c9484d12 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_bug_char.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; +import android.util.Log; +import java.util.Arrays; + +public class UT_bug_char extends UnitTest { + private Resources mRes; + + protected UT_bug_char(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Bug Char", ctx); + mRes = res; + } + + // 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(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_clamp.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_clamp.java new file mode 100644 index 00000000..55317035 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_clamp.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_clamp extends UnitTest { + private Resources mRes; + + protected UT_clamp(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Clamp (Full)", ctx); + mRes = res; + } + + public void run() { + RenderScript pRS = RenderScript.create(mCtx); + ScriptC_clamp s = new ScriptC_clamp(pRS); + pRS.setMessageHandler(mRsMessage); + s.invoke_clamp_test(); + pRS.finish(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_clamp_relaxed.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_clamp_relaxed.java new file mode 100644 index 00000000..ed4ebc77 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_clamp_relaxed.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_clamp_relaxed extends UnitTest { + private Resources mRes; + + protected UT_clamp_relaxed(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Clamp (Relaxed)", ctx); + mRes = res; + } + + 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(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_constant.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_constant.java new file mode 100644 index 00000000..8e6bf6d6 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_constant.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_constant extends UnitTest { + private Resources mRes; + + protected UT_constant(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Const", ctx); + mRes = res; + } + + 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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_convert.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_convert.java new file mode 100644 index 00000000..5e7c60ed --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_convert.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_convert extends UnitTest { + private Resources mRes; + + protected UT_convert(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Convert", ctx); + mRes = res; + } + + public void run() { + RenderScript pRS = RenderScript.create(mCtx); + ScriptC_convert s = new ScriptC_convert(pRS); + pRS.setMessageHandler(mRsMessage); + s.invoke_convert_test(); + pRS.finish(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_convert_relaxed.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_convert_relaxed.java new file mode 100644 index 00000000..02de251b --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_convert_relaxed.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_convert_relaxed extends UnitTest { + private Resources mRes; + + protected UT_convert_relaxed(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Convert (Relaxed)", ctx); + mRes = res; + } + + 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(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_copy_test.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_copy_test.java new file mode 100644 index 00000000..dffea643 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_copy_test.java @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; +import android.util.Log; + +public class UT_copy_test extends UnitTest { + private Resources mRes; + boolean pass = true; + + protected UT_copy_test(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Copy", ctx); + mRes = res; + } + + 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(); + waitForMessage(); + pRS.destroy(); + } +} + diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_element.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_element.java new file mode 100644 index 00000000..4afcb50c --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_element.java @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_element extends UnitTest { + private Resources mRes; + + 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, + }; + + protected UT_element(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Element", ctx); + mRes = res; + } + + 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(); + waitForMessage(); + } + + private void testJavaSide(RenderScript RS) { + + int subElemCount = simpleElem.getSubElementCount(); + _RS_ASSERT("subElemCount == 0", subElemCount == 0); + + subElemCount = complexElem.getSubElementCount(); + _RS_ASSERT("subElemCount == 10", subElemCount == 10); + _RS_ASSERT("complexElem.getSizeBytes() == ScriptField_ComplexStruct.Item.sizeof", + complexElem.getBytesSize() == ScriptField_ComplexStruct.Item.sizeof); + + 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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_foreach.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_foreach.java new file mode 100644 index 00000000..e0d8cb1f --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_foreach.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2011-2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_foreach extends UnitTest { + private Resources mRes; + private Allocation A; + + protected UT_foreach(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "ForEach", ctx); + mRes = res; + } + + 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(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_foreach_bounds.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_foreach_bounds.java new file mode 100644 index 00000000..88f22ac9 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_foreach_bounds.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_foreach_bounds extends UnitTest { + private Resources mRes; + private Allocation A; + + protected UT_foreach_bounds(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "ForEach (bounds)", ctx); + mRes = res; + } + + 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; + 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(2); + s.set_xEnd(5); + s.set_yStart(3); + s.set_yEnd(6); + s.forEach_zero(A); + + 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_foreach_bounds_test(); + pRS.finish(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_fp_mad.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_fp_mad.java new file mode 100644 index 00000000..d16f341c --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_fp_mad.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_fp_mad extends UnitTest { + private Resources mRes; + + protected UT_fp_mad(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Fp_Mad", ctx); + mRes = res; + } + + 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(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_instance.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_instance.java new file mode 100644 index 00000000..2e77e67d --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_instance.java @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_instance extends UnitTest { + private Resources mRes; + + protected UT_instance(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Instance", ctx); + mRes = res; + } + + void assertEquals(int e, int v) { + if (e != v) { + RSTest.log("Assertion failed! Expected: <" + e + "> Got: <" + v + ">"); + failTest(); + } + } + + public void run() { + RenderScript mRS = RenderScript.create(mCtx); + mRS.setMessageHandler(mRsMessage); + + ScriptC_instance instance_1 = new ScriptC_instance(mRS); + ScriptC_instance instance_2 = new ScriptC_instance(mRS); + ScriptC_instance instance_3 = new ScriptC_instance(mRS); + ScriptC_instance instance_4 = new ScriptC_instance(mRS); + ScriptC_instance instance_5 = new ScriptC_instance(mRS); + + Type t = new Type.Builder(mRS, Element.I32(mRS)).setX(1).create(); + Allocation ai1 = Allocation.createTyped(mRS, t); + Allocation ai2 = Allocation.createTyped(mRS, t); + Allocation ai3 = Allocation.createTyped(mRS, t); + Allocation ai4 = Allocation.createTyped(mRS, t); + Allocation ai5 = Allocation.createTyped(mRS, t); + + instance_1.set_i(1); + instance_2.set_i(2); + instance_3.set_i(3); + instance_4.set_i(4); + instance_5.set_i(5); + instance_1.set_ai(ai1); + instance_2.set_ai(ai2); + instance_3.set_ai(ai3); + instance_4.set_ai(ai4); + instance_5.set_ai(ai5); + + // We now check to ensure that the global is not being shared across + // our separate script instances. Our invoke here merely sets the + // instanced allocation with the instanced global variable's value. + // If globals are being shared (i.e. not instancing scripts), then + // both instanced allocations will have the same resulting value + // (depending on the order in which the invokes complete). + instance_1.invoke_instance_test(); + instance_2.invoke_instance_test(); + instance_3.invoke_instance_test(); + instance_4.invoke_instance_test(); + instance_5.invoke_instance_test(); + + int i1[] = new int[1]; + int i2[] = new int[1]; + int i3[] = new int[1]; + int i4[] = new int[1]; + int i5[] = new int[1]; + + ai1.copyTo(i1); + ai2.copyTo(i2); + ai3.copyTo(i3); + ai4.copyTo(i4); + ai5.copyTo(i5); + + assertEquals(1, i1[0]); + assertEquals(2, i2[0]); + assertEquals(3, i3[0]); + assertEquals(4, i4[0]); + assertEquals(5, i5[0]); + assertEquals(1, i1[0]); + assertEquals(2, i2[0]); + assertEquals(3, i3[0]); + assertEquals(4, i4[0]); + assertEquals(5, i5[0]); + passTest(); // Set to pass (as long as existing checks didn't fail). + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_int4.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_int4.java new file mode 100644 index 00000000..6f28372c --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_int4.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_int4 extends UnitTest { + private Resources mRes; + + protected UT_int4(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "int4", ctx); + mRes = res; + } + + public void run() { + RenderScript pRS = RenderScript.create(mCtx); + ScriptC_int4 s = new ScriptC_int4(pRS); + pRS.setMessageHandler(mRsMessage); + s.invoke_int4_test(); + pRS.finish(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_kernel.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_kernel.java new file mode 100644 index 00000000..4b30598a --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_kernel.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; +import android.util.Log; + +public class UT_kernel extends UnitTest { + private Resources mRes; + private Allocation A; + private Allocation B; + + protected UT_kernel(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Kernels (pass-by-value)", ctx); + mRes = res; + } + + 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); + A = Allocation.createTyped(RS, typeBuilder.create()); + s.bind_ain(A); + B = Allocation.createTyped(RS, typeBuilder.create()); + 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(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_kernel_struct.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_kernel_struct.java new file mode 100644 index 00000000..b0f2bbe5 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_kernel_struct.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; +import android.util.Log; + +public class UT_kernel_struct extends UnitTest { + private Resources mRes; + private Allocation A; + private Allocation B; + + protected UT_kernel_struct(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Kernels (struct pass-by-value)", ctx); + mRes = res; + } + + 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(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_math.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_math.java new file mode 100644 index 00000000..8accd46f --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_math.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_math extends UnitTest { + private Resources mRes; + + protected UT_math(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Math", ctx); + mRes = res; + } + + 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(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_math_agree.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_math_agree.java new file mode 100644 index 00000000..5b050cd0 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_math_agree.java @@ -0,0 +1,527 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; +import android.util.Log; +import java.util.Arrays; +import java.util.Random; + +public class UT_math_agree extends UnitTest { + private Resources mRes; + private Random rand; + + protected UT_math_agree(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Math Agreement", ctx); + mRes = res; + 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(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_math_conformance.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_math_conformance.java new file mode 100644 index 00000000..d5935145 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_math_conformance.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_math_conformance extends UnitTest { + private Resources mRes; + + protected UT_math_conformance(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Math Conformance", ctx); + mRes = res; + } + + 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(); + waitForMessage(); + pRS.destroy(); + passTest(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_min.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_min.java new file mode 100644 index 00000000..a9c31a10 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_min.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_min extends UnitTest { + private Resources mRes; + + protected UT_min(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Min (relaxed)", ctx); + mRes = res; + } + + public void run() { + RenderScript pRS = RenderScript.create(mCtx); + ScriptC_min s = new ScriptC_min(pRS); + pRS.setMessageHandler(mRsMessage); + s.invoke_min_test(); + pRS.finish(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_noroot.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_noroot.java new file mode 100644 index 00000000..487e9999 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_noroot.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2011-2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_noroot extends UnitTest { + private Resources mRes; + private Allocation A; + + protected UT_noroot(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "ForEach (no root)", ctx); + mRes = res; + } + + 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(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_primitives.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_primitives.java new file mode 100644 index 00000000..3110b713 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_primitives.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_primitives extends UnitTest { + private Resources mRes; + + protected UT_primitives(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Primitives", ctx); + mRes = res; + } + + 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(); + waitForMessage(); + } + pRS.destroy(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_refcount.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_refcount.java new file mode 100644 index 00000000..8e8b4b50 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_refcount.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_refcount extends UnitTest { + private Resources mRes; + + protected UT_refcount(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Refcount", ctx); + mRes = res; + } + + 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); + Allocation A = Allocation.createTyped(RS, typeBuilder.create()); + s.set_globalA(A); + } + + 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(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_rsdebug.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_rsdebug.java new file mode 100644 index 00000000..8f4976e9 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_rsdebug.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_rsdebug extends UnitTest { + private Resources mRes; + + protected UT_rsdebug(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "rsDebug", ctx); + mRes = res; + } + + 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(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_rstime.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_rstime.java new file mode 100644 index 00000000..0e389245 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_rstime.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_rstime extends UnitTest { + private Resources mRes; + + protected UT_rstime(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "rsTime", ctx); + mRes = res; + } + + 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(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_rstypes.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_rstypes.java new file mode 100644 index 00000000..329a92a6 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_rstypes.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_rstypes extends UnitTest { + private Resources mRes; + + protected UT_rstypes(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "rsTypes", ctx); + mRes = res; + } + + 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(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_sampler.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_sampler.java new file mode 100644 index 00000000..ffba30f4 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_sampler.java @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_sampler extends UnitTest { + private Resources mRes; + + Sampler minification; + Sampler magnification; + Sampler wrapS; + Sampler wrapT; + Sampler anisotropy; + + protected UT_sampler(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Sampler", ctx); + mRes = res; + } + + 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(); + waitForMessage(); + } + + 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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_struct.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_struct.java new file mode 100644 index 00000000..127397ea --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_struct.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_struct extends UnitTest { + private Resources mRes; + + protected UT_struct(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Struct", ctx); + mRes = res; + } + + 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(); + waitForMessage(); + + val = 200; + p.set_x(0, val, true); + p.set_y(0, val, true); + s.invoke_struct_test(val); + pRS.finish(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_unsigned.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_unsigned.java new file mode 100644 index 00000000..d2fb5f32 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_unsigned.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_unsigned extends UnitTest { + private Resources mRes; + + protected UT_unsigned(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Unsigned", ctx); + mRes = res; + } + + 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(); + waitForMessage(); + } + pRS.destroy(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_vector.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_vector.java new file mode 100644 index 00000000..3707cbf1 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UT_vector.java @@ -0,0 +1,318 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; + +import android.content.Context; +import android.content.res.Resources; +import android.support.v8.renderscript.*; + +public class UT_vector extends UnitTest { + private Resources mRes; + + protected UT_vector(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Vector", ctx); + mRes = res; + } + + 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(); + waitForMessage(); + } + pRS.destroy(); + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UnitTest.java b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UnitTest.java new file mode 100644 index 00000000..cb1e7cee --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/UnitTest.java @@ -0,0 +1,144 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.test_compatlegacy; +import android.content.Context; +import android.util.Log; +import android.support.v8.renderscript.RenderScript.RSMessageHandler; + +public class UnitTest extends Thread { + public String name; + private int result; + private ScriptField_ListAllocs_s.Item mItem; + private RSTestCore mRSTC; + private boolean msgHandled; + 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; + + private static int numTests = 0; + public int testID; + + protected UnitTest(RSTestCore rstc, String n, int initResult, Context ctx) { + super(); + mRSTC = rstc; + name = n; + msgHandled = false; + mCtx = ctx; + result = initResult; + testID = numTests++; + } + + protected UnitTest(RSTestCore rstc, String n, Context ctx) { + this(rstc, n, 0, ctx); + } + + protected UnitTest(RSTestCore rstc, Context ctx) { + this (rstc, "<Unknown>", ctx); + } + + protected UnitTest(Context ctx) { + this (null, ctx); + } + + protected void _RS_ASSERT(String message, boolean b) { + if(b == false) { + Log.e(name, message + " FAILED"); + failTest(); + } + } + + private void updateUI() { + if (mItem != null) { + mItem.result = result; + msgHandled = true; + try { + mRSTC.refreshTestResults(); + } + catch (IllegalStateException e) { + /* Ignore the case where our message receiver has been + disconnected. This happens when we leave the application + before it finishes running all of the unit tests. */ + } + } + } + + protected RSMessageHandler mRsMessage = new RSMessageHandler() { + public void run() { + if (result == 0) { + switch (mID) { + case RS_MSG_TEST_PASSED: + result = 1; + break; + case RS_MSG_TEST_FAILED: + result = -1; + break; + default: + RSTest.log("Unit test got unexpected message"); + return; + } + } + + updateUI(); + } + }; + + public void waitForMessage() { + while (!msgHandled) { + yield(); + } + } + + public int getResult() { + return result; + } + + public void failTest() { + result = -1; + updateUI(); + } + + public void passTest() { + if (result != -1) { + result = 1; + } + updateUI(); + } + + public String toString() { + String out = name; + if (result == 1) { + out += " - PASSED"; + } + else if (result == -1) { + out += " - FAILED"; + } + return out; + } + + public void setItem(ScriptField_ListAllocs_s.Item item) { + mItem = item; + } + + public void run() { + /* This method needs to be implemented for each subclass */ + if (mRSTC != null) { + mRSTC.refreshTestResults(); + } + } +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/alloc.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/alloc.rs new file mode 100644 index 00000000..1b5e2ac5 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/alloc.rs @@ -0,0 +1,92 @@ +#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, uint32_t y) { + *o = x + y * dimX; +} + +static bool test_alloc_dims() { + bool failed = false; + int i, j; + + _RS_ASSERT(rsAllocationGetDimX(aRaw) == dimX); + _RS_ASSERT(rsAllocationGetDimY(aRaw) == dimY); + _RS_ASSERT(rsAllocationGetDimZ(aRaw) == dimZ); + + // Test 2D addressing + for (j = 0; j < dimY; j++) { + for (i = 0; i < dimX; i++) { + rsDebug("Verifying ", i + j * dimX); + const void *p = rsGetElementAt(aRaw, i, j); + int val = *(const int *)p; + _RS_ASSERT(val == (i + j * dimX)); + } + } + + // 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); + } + + // Test 3D addressing + for (j = 0; j < dimY; j++) { + for (i = 0; i < dimX; i++) { + rsDebug("Verifying ", i + j * dimX); + const void *p = rsGetElementAt(aRaw, i, j, 0); + int val = *(const int *)p; + _RS_ASSERT(val == (i + j * dimX)); + } + } + + _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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/apitest.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/apitest.rs new file mode 100644 index 00000000..865620f2 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/apitest.rs @@ -0,0 +1,1381 @@ +#include "shared.rsh" + +uint32_t x; +uint32_t y; +uint32_t z; + +rs_element elemNull; +rs_element elemNonNull; +rs_type typeNull; +rs_type typeNonNull; +rs_allocation allocNull; +rs_allocation allocNonNull; +rs_sampler samplerNull; +rs_sampler samplerNonNull; +rs_script scriptNull; +rs_script scriptNonNull; + +volatile rs_data_type dt; +volatile rs_data_kind dk; + +volatile rs_sampler_value rsv; + +volatile rs_time_t rst; +volatile static rs_tm rstm; + +char *allocPtr; +rs_allocation allocDst; + +volatile bool b; +volatile char c; +volatile char2 c2; +volatile char3 c3; +volatile char4 c4; +volatile uchar uc; +volatile uchar2 uc2; +volatile uchar3 uc3; +volatile uchar4 uc4; +volatile short s; +volatile short2 s2; +volatile short3 s3; +volatile short4 s4; +volatile ushort us; +volatile ushort2 us2; +volatile ushort3 us3; +volatile ushort4 us4; +volatile int i; +volatile int2 i2; +volatile int3 i3; +volatile int4 i4; +volatile uint ui; +volatile uint2 ui2; +volatile uint3 ui3; +volatile uint4 ui4; +volatile long l; +volatile long2 l2; +volatile long3 l3; +volatile long4 l4; +volatile ulong ul; +volatile ulong2 ul2; +volatile ulong3 ul3; +volatile ulong4 ul4; +volatile long long ll; +volatile unsigned long long ull; +volatile float f; +volatile float2 f2; +volatile float3 f3; +volatile float4 f4; +volatile double d; +volatile double2 d2; +volatile double3 d3; +volatile double4 d4; +float fa[16]; + +rs_allocation aChar; +rs_allocation aChar2; +rs_allocation aChar3; +rs_allocation aChar4; +rs_allocation aUChar; +rs_allocation aUChar2; +rs_allocation aUChar3; +rs_allocation aUChar4; +rs_allocation aShort; +rs_allocation aShort2; +rs_allocation aShort3; +rs_allocation aShort4; +rs_allocation aUShort; +rs_allocation aUShort2; +rs_allocation aUShort3; +rs_allocation aUShort4; +rs_allocation aInt; +rs_allocation aInt2; +rs_allocation aInt3; +rs_allocation aInt4; +rs_allocation aUInt; +rs_allocation aUInt2; +rs_allocation aUInt3; +rs_allocation aUInt4; +rs_allocation aLong; +rs_allocation aLong2; +rs_allocation aLong3; +rs_allocation aLong4; +rs_allocation aULong; +rs_allocation aULong2; +rs_allocation aULong3; +rs_allocation aULong4; +rs_allocation aFloat; +rs_allocation aFloat2; +rs_allocation aFloat3; +rs_allocation aFloat4; +rs_allocation aDouble; +rs_allocation aDouble2; +rs_allocation aDouble3; +rs_allocation aDouble4; + +rs_matrix2x2 m2x2; +rs_matrix3x3 m3x3; +rs_matrix4x4 m4x4; + +// This function just checks that all of the called functions are +// able to be linked. It is not intended to be executed! +void check_api_presence() { + /******************************** + * DO NOT EXECUTE THIS FUNCTION * + ********************************/ + rsSendToClientBlocking(RS_MSG_TEST_FAILED); + + // rs_allocation.rsh + c = rsGetElementAt_char(aChar, 0); + rsSetElementAt_char(aChar, c, 0); + c = rsGetElementAt_char(aChar, 0, 0); + rsSetElementAt_char(aChar, c, 0, 0); + c = rsGetElementAt_char(aChar, 0, 0, 0); + rsSetElementAt_char(aChar, c, 0, 0, 0); + c2 = rsGetElementAt_char2(aChar2, 0); + rsSetElementAt_char2(aChar2, c2, 0); + c2 = rsGetElementAt_char2(aChar2, 0, 0); + rsSetElementAt_char2(aChar2, c2, 0, 0); + c2 = rsGetElementAt_char2(aChar2, 0, 0, 0); + rsSetElementAt_char2(aChar2, c2, 0, 0, 0); + c3 = rsGetElementAt_char3(aChar3, 0); + rsSetElementAt_char3(aChar3, c3, 0); + c3 = rsGetElementAt_char3(aChar3, 0, 0); + rsSetElementAt_char3(aChar3, c3, 0, 0); + c3 = rsGetElementAt_char3(aChar3, 0, 0, 0); + rsSetElementAt_char3(aChar3, c3, 0, 0, 0); + c4 = rsGetElementAt_char4(aChar4, 0); + rsSetElementAt_char4(aChar4, c4, 0); + c4 = rsGetElementAt_char4(aChar4, 0, 0); + rsSetElementAt_char4(aChar4, c4, 0, 0); + c4 = rsGetElementAt_char4(aChar4, 0, 0, 0); + rsSetElementAt_char4(aChar4, c4, 0, 0, 0); + + uc = rsGetElementAt_uchar(aUChar, 0); + rsSetElementAt_uchar(aUChar, uc, 0); + uc = rsGetElementAt_uchar(aUChar, 0, 0); + rsSetElementAt_uchar(aUChar, uc, 0, 0); + uc = rsGetElementAt_uchar(aUChar, 0, 0, 0); + rsSetElementAt_uchar(aUChar, uc, 0, 0, 0); + uc2 = rsGetElementAt_uchar2(aUChar2, 0); + rsSetElementAt_uchar2(aUChar2, uc2, 0); + uc2 = rsGetElementAt_uchar2(aUChar2, 0, 0); + rsSetElementAt_uchar2(aUChar2, uc2, 0, 0); + uc2 = rsGetElementAt_uchar2(aUChar2, 0, 0, 0); + rsSetElementAt_uchar2(aUChar2, uc2, 0, 0, 0); + uc3 = rsGetElementAt_uchar3(aUChar3, 0); + rsSetElementAt_uchar3(aUChar3, uc3, 0); + uc3 = rsGetElementAt_uchar3(aUChar3, 0, 0); + rsSetElementAt_uchar3(aUChar3, uc3, 0, 0); + uc3 = rsGetElementAt_uchar3(aUChar3, 0, 0, 0); + rsSetElementAt_uchar3(aUChar3, uc3, 0, 0, 0); + uc4 = rsGetElementAt_uchar4(aUChar4, 0); + rsSetElementAt_uchar4(aUChar4, uc4, 0); + uc4 = rsGetElementAt_uchar4(aUChar4, 0, 0); + rsSetElementAt_uchar4(aUChar4, uc4, 0, 0); + uc4 = rsGetElementAt_uchar4(aUChar4, 0, 0, 0); + rsSetElementAt_uchar4(aUChar4, uc4, 0, 0, 0); + + s = rsGetElementAt_short(aShort, 0); + rsSetElementAt_short(aShort, s, 0); + s = rsGetElementAt_short(aShort, 0, 0); + rsSetElementAt_short(aShort, s, 0, 0); + s = rsGetElementAt_short(aShort, 0, 0, 0); + rsSetElementAt_short(aShort, s, 0, 0, 0); + s2 = rsGetElementAt_short2(aShort2, 0); + rsSetElementAt_short2(aShort2, s2, 0); + s2 = rsGetElementAt_short2(aShort2, 0, 0); + rsSetElementAt_short2(aShort2, s2, 0, 0); + s2 = rsGetElementAt_short2(aShort2, 0, 0, 0); + rsSetElementAt_short2(aShort2, s2, 0, 0, 0); + s3 = rsGetElementAt_short3(aShort3, 0); + rsSetElementAt_short3(aShort3, s3, 0); + s3 = rsGetElementAt_short3(aShort3, 0, 0); + rsSetElementAt_short3(aShort3, s3, 0, 0); + s3 = rsGetElementAt_short3(aShort3, 0, 0, 0); + rsSetElementAt_short3(aShort3, s3, 0, 0, 0); + s4 = rsGetElementAt_short4(aShort4, 0); + rsSetElementAt_short4(aShort4, s4, 0); + s4 = rsGetElementAt_short4(aShort4, 0, 0); + rsSetElementAt_short4(aShort4, s4, 0, 0); + s4 = rsGetElementAt_short4(aShort4, 0, 0, 0); + rsSetElementAt_short4(aShort4, s4, 0, 0, 0); + + us = rsGetElementAt_ushort(aUShort, 0); + rsSetElementAt_ushort(aUShort, us, 0); + us = rsGetElementAt_ushort(aUShort, 0, 0); + rsSetElementAt_ushort(aUShort, us, 0, 0); + us = rsGetElementAt_ushort(aUShort, 0, 0, 0); + rsSetElementAt_ushort(aUShort, us, 0, 0, 0); + us2 = rsGetElementAt_ushort2(aUShort2, 0); + rsSetElementAt_ushort2(aUShort2, us2, 0); + us2 = rsGetElementAt_ushort2(aUShort2, 0, 0); + rsSetElementAt_ushort2(aUShort2, us2, 0, 0); + us2 = rsGetElementAt_ushort2(aUShort2, 0, 0, 0); + rsSetElementAt_ushort2(aUShort2, us2, 0, 0, 0); + us3 = rsGetElementAt_ushort3(aUShort3, 0); + rsSetElementAt_ushort3(aUShort3, us3, 0); + us3 = rsGetElementAt_ushort3(aUShort3, 0, 0); + rsSetElementAt_ushort3(aUShort3, us3, 0, 0); + us3 = rsGetElementAt_ushort3(aUShort3, 0, 0, 0); + rsSetElementAt_ushort3(aUShort3, us3, 0, 0, 0); + us4 = rsGetElementAt_ushort4(aUShort4, 0); + rsSetElementAt_ushort4(aUShort4, us4, 0); + us4 = rsGetElementAt_ushort4(aUShort4, 0, 0); + rsSetElementAt_ushort4(aUShort4, us4, 0, 0); + us4 = rsGetElementAt_ushort4(aUShort4, 0, 0, 0); + rsSetElementAt_ushort4(aUShort4, us4, 0, 0, 0); + + i = rsGetElementAt_int(aInt, 0); + rsSetElementAt_int(aInt, i, 0); + i = rsGetElementAt_int(aInt, 0, 0); + rsSetElementAt_int(aInt, i, 0, 0); + i = rsGetElementAt_int(aInt, 0, 0, 0); + rsSetElementAt_int(aInt, i, 0, 0, 0); + i2 = rsGetElementAt_int2(aInt2, 0); + rsSetElementAt_int2(aInt2, i2, 0); + i2 = rsGetElementAt_int2(aInt2, 0, 0); + rsSetElementAt_int2(aInt2, i2, 0, 0); + i2 = rsGetElementAt_int2(aInt2, 0, 0, 0); + rsSetElementAt_int2(aInt2, i2, 0, 0, 0); + i3 = rsGetElementAt_int3(aInt3, 0); + rsSetElementAt_int3(aInt3, i3, 0); + i3 = rsGetElementAt_int3(aInt3, 0, 0); + rsSetElementAt_int3(aInt3, i3, 0, 0); + i3 = rsGetElementAt_int3(aInt3, 0, 0, 0); + rsSetElementAt_int3(aInt3, i3, 0, 0, 0); + i4 = rsGetElementAt_int4(aInt4, 0); + rsSetElementAt_int4(aInt4, i4, 0); + i4 = rsGetElementAt_int4(aInt4, 0, 0); + rsSetElementAt_int4(aInt4, i4, 0, 0); + i4 = rsGetElementAt_int4(aInt4, 0, 0, 0); + rsSetElementAt_int4(aInt4, i4, 0, 0, 0); + + ui = rsGetElementAt_uint(aUInt, 0); + rsSetElementAt_uint(aUInt, ui, 0); + ui = rsGetElementAt_uint(aUInt, 0, 0); + rsSetElementAt_uint(aUInt, ui, 0, 0); + ui = rsGetElementAt_uint(aUInt, 0, 0, 0); + rsSetElementAt_uint(aUInt, ui, 0, 0, 0); + ui2 = rsGetElementAt_uint2(aUInt2, 0); + rsSetElementAt_uint2(aUInt2, ui2, 0); + ui2 = rsGetElementAt_uint2(aUInt2, 0, 0); + rsSetElementAt_uint2(aUInt2, ui2, 0, 0); + ui2 = rsGetElementAt_uint2(aUInt2, 0, 0, 0); + rsSetElementAt_uint2(aUInt2, ui2, 0, 0, 0); + ui3 = rsGetElementAt_uint3(aUInt3, 0); + rsSetElementAt_uint3(aUInt3, ui3, 0); + ui3 = rsGetElementAt_uint3(aUInt3, 0, 0); + rsSetElementAt_uint3(aUInt3, ui3, 0, 0); + ui3 = rsGetElementAt_uint3(aUInt3, 0, 0, 0); + rsSetElementAt_uint3(aUInt3, ui3, 0, 0, 0); + ui4 = rsGetElementAt_uint4(aUInt4, 0); + rsSetElementAt_uint4(aUInt4, ui4, 0); + ui4 = rsGetElementAt_uint4(aUInt4, 0, 0); + rsSetElementAt_uint4(aUInt4, ui4, 0, 0); + ui4 = rsGetElementAt_uint4(aUInt4, 0, 0, 0); + rsSetElementAt_uint4(aUInt4, ui4, 0, 0, 0); + + l = rsGetElementAt_long(aLong, 0); + rsSetElementAt_long(aLong, l, 0); + l = rsGetElementAt_long(aLong, 0, 0); + rsSetElementAt_long(aLong, l, 0, 0); + l = rsGetElementAt_long(aLong, 0, 0, 0); + rsSetElementAt_long(aLong, l, 0, 0, 0); + l2 = rsGetElementAt_long2(aLong2, 0); + rsSetElementAt_long2(aLong2, l2, 0); + l2 = rsGetElementAt_long2(aLong2, 0, 0); + rsSetElementAt_long2(aLong2, l2, 0, 0); + l2 = rsGetElementAt_long2(aLong2, 0, 0, 0); + rsSetElementAt_long2(aLong2, l2, 0, 0, 0); + l3 = rsGetElementAt_long3(aLong3, 0); + rsSetElementAt_long3(aLong3, l3, 0); + l3 = rsGetElementAt_long3(aLong3, 0, 0); + rsSetElementAt_long3(aLong3, l3, 0, 0); + l3 = rsGetElementAt_long3(aLong3, 0, 0, 0); + rsSetElementAt_long3(aLong3, l3, 0, 0, 0); + l4 = rsGetElementAt_long4(aLong4, 0); + rsSetElementAt_long4(aLong4, l4, 0); + l4 = rsGetElementAt_long4(aLong4, 0, 0); + rsSetElementAt_long4(aLong4, l4, 0, 0); + l4 = rsGetElementAt_long4(aLong4, 0, 0, 0); + rsSetElementAt_long4(aLong4, l4, 0, 0, 0); + + ul = rsGetElementAt_ulong(aULong, 0); + rsSetElementAt_ulong(aULong, ul, 0); + ul = rsGetElementAt_ulong(aULong, 0, 0); + rsSetElementAt_ulong(aULong, ul, 0, 0); + ul = rsGetElementAt_ulong(aULong, 0, 0, 0); + rsSetElementAt_ulong(aULong, ul, 0, 0, 0); + ul2 = rsGetElementAt_ulong2(aULong2, 0); + rsSetElementAt_ulong2(aULong2, ul2, 0); + ul2 = rsGetElementAt_ulong2(aULong2, 0, 0); + rsSetElementAt_ulong2(aULong2, ul2, 0, 0); + ul2 = rsGetElementAt_ulong2(aULong2, 0, 0, 0); + rsSetElementAt_ulong2(aULong2, ul2, 0, 0, 0); + ul3 = rsGetElementAt_ulong3(aULong3, 0); + rsSetElementAt_ulong3(aULong3, ul3, 0); + ul3 = rsGetElementAt_ulong3(aULong3, 0, 0); + rsSetElementAt_ulong3(aULong3, ul3, 0, 0); + ul3 = rsGetElementAt_ulong3(aULong3, 0, 0, 0); + rsSetElementAt_ulong3(aULong3, ul3, 0, 0, 0); + ul4 = rsGetElementAt_ulong4(aULong4, 0); + rsSetElementAt_ulong4(aULong4, ul4, 0); + ul4 = rsGetElementAt_ulong4(aULong4, 0, 0); + rsSetElementAt_ulong4(aULong4, ul4, 0, 0); + ul4 = rsGetElementAt_ulong4(aULong4, 0, 0, 0); + rsSetElementAt_ulong4(aULong4, ul4, 0, 0, 0); + + f = rsGetElementAt_float(aFloat, 0); + rsSetElementAt_float(aFloat, f, 0); + f = rsGetElementAt_float(aFloat, 0, 0); + rsSetElementAt_float(aFloat, f, 0, 0); + f = rsGetElementAt_float(aFloat, 0, 0, 0); + rsSetElementAt_float(aFloat, f, 0, 0, 0); + f2 = rsGetElementAt_float2(aFloat2, 0); + rsSetElementAt_float2(aFloat2, f2, 0); + f2 = rsGetElementAt_float2(aFloat2, 0, 0); + rsSetElementAt_float2(aFloat2, f2, 0, 0); + f2 = rsGetElementAt_float2(aFloat2, 0, 0, 0); + rsSetElementAt_float2(aFloat2, f2, 0, 0, 0); + f3 = rsGetElementAt_float3(aFloat3, 0); + rsSetElementAt_float3(aFloat3, f3, 0); + f3 = rsGetElementAt_float3(aFloat3, 0, 0); + rsSetElementAt_float3(aFloat3, f3, 0, 0); + f3 = rsGetElementAt_float3(aFloat3, 0, 0, 0); + rsSetElementAt_float3(aFloat3, f3, 0, 0, 0); + f4 = rsGetElementAt_float4(aFloat4, 0); + rsSetElementAt_float4(aFloat4, f4, 0); + f4 = rsGetElementAt_float4(aFloat4, 0, 0); + rsSetElementAt_float4(aFloat4, f4, 0, 0); + f4 = rsGetElementAt_float4(aFloat4, 0, 0, 0); + rsSetElementAt_float4(aFloat4, f4, 0, 0, 0); + + d = rsGetElementAt_double(aDouble, 0); + rsSetElementAt_double(aDouble, d, 0); + d = rsGetElementAt_double(aDouble, 0, 0); + rsSetElementAt_double(aDouble, d, 0, 0); + d = rsGetElementAt_double(aDouble, 0, 0, 0); + rsSetElementAt_double(aDouble, d, 0, 0, 0); + d2 = rsGetElementAt_double2(aDouble2, 0); + rsSetElementAt_double2(aDouble2, d2, 0); + d2 = rsGetElementAt_double2(aDouble2, 0, 0); + rsSetElementAt_double2(aDouble2, d2, 0, 0); + d2 = rsGetElementAt_double2(aDouble2, 0, 0, 0); + rsSetElementAt_double2(aDouble2, d2, 0, 0, 0); + d3 = rsGetElementAt_double3(aDouble3, 0); + rsSetElementAt_double3(aDouble3, d3, 0); + d3 = rsGetElementAt_double3(aDouble3, 0, 0); + rsSetElementAt_double3(aDouble3, d3, 0, 0); + d3 = rsGetElementAt_double3(aDouble3, 0, 0, 0); + rsSetElementAt_double3(aDouble3, d3, 0, 0, 0); + d4 = rsGetElementAt_double4(aDouble4, 0); + rsSetElementAt_double4(aDouble4, d4, 0); + d4 = rsGetElementAt_double4(aDouble4, 0, 0); + rsSetElementAt_double4(aDouble4, d4, 0, 0); + d4 = rsGetElementAt_double4(aDouble4, 0, 0, 0); + rsSetElementAt_double4(aDouble4, d4, 0, 0, 0); + + uc3.x = rsGetElementAtYuv_uchar_Y(aUChar4, 0, 0); + uc3.y = rsGetElementAtYuv_uchar_U(aUChar4, 0, 0); + uc3.z = rsGetElementAtYuv_uchar_V(aUChar4, 0, 0); + + c3.x = *(char*)rsGetElementAt(aChar3, 0); + c3.y = *(char*)rsGetElementAt(aChar3, 0, 0); + c3.z = *(char*)rsGetElementAt(aChar3, 0, 0, 0); + + rsAllocationIoSend(aInt); + rsAllocationIoReceive(aInt); + + elemNonNull = rsAllocationGetElement(aInt); + + rsAllocationCopy1DRange(allocDst, 0, 0, 0, allocDst, 0, 0); + rsAllocationCopy2DRange(allocDst, 0, 0, 0, 0, 0, 0, allocDst, 0, 0, 0, 0); + + // rsSample routines + f4 += rsSample(allocDst, samplerNonNull, f); + f4 += rsSample(allocDst, samplerNonNull, f, f); + f4 += rsSample(allocDst, samplerNonNull, f2); + f4 += rsSample(allocDst, samplerNonNull, f2, f); + + // rs_atomic.rsh + rsAtomicInc(&i); + rsAtomicDec(&i); + rsAtomicAdd(&i, 1); + rsAtomicSub(&i, 2); + rsAtomicAnd(&i, 3); + rsAtomicOr(&i, 4); + rsAtomicXor(&i, 5); + rsAtomicMin(&i, 6); + rsAtomicMin(&ui, 6); + rsAtomicMax(&i, 7); + rsAtomicMax(&ui, 7); + rsAtomicCas(&i, 8, 9); + rsAtomicCas(&ui, 8, 9); + + // rs_cl.rsh + c2 = convert_char2(c2); + c2 = convert_char2(uc2); + c2 = convert_char2(s2); + c2 = convert_char2(us2); + c2 = convert_char2(i2); + c2 = convert_char2(ui2); + c2 = convert_char2(f2); + c3 = convert_char3(c3); + c3 = convert_char3(uc3); + c3 = convert_char3(s3); + c3 = convert_char3(us3); + c3 = convert_char3(i3); + c3 = convert_char3(ui3); + c3 = convert_char3(f3); + c4 = convert_char4(c4); + c4 = convert_char4(uc4); + c4 = convert_char4(s4); + c4 = convert_char4(us4); + c4 = convert_char4(i4); + c4 = convert_char4(ui4); + c4 = convert_char4(f4); + + uc2 = convert_uchar2(c2); + uc2 = convert_uchar2(uc2); + uc2 = convert_uchar2(s2); + uc2 = convert_uchar2(us2); + uc2 = convert_uchar2(i2); + uc2 = convert_uchar2(ui2); + uc2 = convert_uchar2(f2); + uc3 = convert_uchar3(c3); + uc3 = convert_uchar3(uc3); + uc3 = convert_uchar3(s3); + uc3 = convert_uchar3(us3); + uc3 = convert_uchar3(i3); + uc3 = convert_uchar3(ui3); + uc3 = convert_uchar3(f3); + uc4 = convert_uchar4(c4); + uc4 = convert_uchar4(uc4); + uc4 = convert_uchar4(s4); + uc4 = convert_uchar4(us4); + uc4 = convert_uchar4(i4); + uc4 = convert_uchar4(ui4); + uc4 = convert_uchar4(f4); + + s2 = convert_short2(c2); + s2 = convert_short2(uc2); + s2 = convert_short2(s2); + s2 = convert_short2(us2); + s2 = convert_short2(i2); + s2 = convert_short2(ui2); + s2 = convert_short2(f2); + s3 = convert_short3(c3); + s3 = convert_short3(uc3); + s3 = convert_short3(s3); + s3 = convert_short3(us3); + s3 = convert_short3(i3); + s3 = convert_short3(ui3); + s3 = convert_short3(f3); + s4 = convert_short4(c4); + s4 = convert_short4(uc4); + s4 = convert_short4(s4); + s4 = convert_short4(us4); + s4 = convert_short4(i4); + s4 = convert_short4(ui4); + s4 = convert_short4(f4); + + us2 = convert_ushort2(c2); + us2 = convert_ushort2(uc2); + us2 = convert_ushort2(s2); + us2 = convert_ushort2(us2); + us2 = convert_ushort2(i2); + us2 = convert_ushort2(ui2); + us2 = convert_ushort2(f2); + us3 = convert_ushort3(c3); + us3 = convert_ushort3(uc3); + us3 = convert_ushort3(s3); + us3 = convert_ushort3(us3); + us3 = convert_ushort3(i3); + us3 = convert_ushort3(ui3); + us3 = convert_ushort3(f3); + us4 = convert_ushort4(c4); + us4 = convert_ushort4(uc4); + us4 = convert_ushort4(s4); + us4 = convert_ushort4(us4); + us4 = convert_ushort4(i4); + us4 = convert_ushort4(ui4); + us4 = convert_ushort4(f4); + + i2 = convert_int2(c2); + i2 = convert_int2(uc2); + i2 = convert_int2(s2); + i2 = convert_int2(us2); + i2 = convert_int2(i2); + i2 = convert_int2(ui2); + i2 = convert_int2(f2); + i3 = convert_int3(c3); + i3 = convert_int3(uc3); + i3 = convert_int3(s3); + i3 = convert_int3(us3); + i3 = convert_int3(i3); + i3 = convert_int3(ui3); + i3 = convert_int3(f3); + i4 = convert_int4(c4); + i4 = convert_int4(uc4); + i4 = convert_int4(s4); + i4 = convert_int4(us4); + i4 = convert_int4(i4); + i4 = convert_int4(ui4); + i4 = convert_int4(f4); + + ui2 = convert_uint2(c2); + ui2 = convert_uint2(uc2); + ui2 = convert_uint2(s2); + ui2 = convert_uint2(us2); + ui2 = convert_uint2(i2); + ui2 = convert_uint2(ui2); + ui2 = convert_uint2(f2); + ui3 = convert_uint3(c3); + ui3 = convert_uint3(uc3); + ui3 = convert_uint3(s3); + ui3 = convert_uint3(us3); + ui3 = convert_uint3(i3); + ui3 = convert_uint3(ui3); + ui3 = convert_uint3(f3); + ui4 = convert_uint4(c4); + ui4 = convert_uint4(uc4); + ui4 = convert_uint4(s4); + ui4 = convert_uint4(us4); + ui4 = convert_uint4(i4); + ui4 = convert_uint4(ui4); + ui4 = convert_uint4(f4); + + f2 = convert_float2(c2); + f2 = convert_float2(uc2); + f2 = convert_float2(s2); + f2 = convert_float2(us2); + f2 = convert_float2(i2); + f2 = convert_float2(ui2); + f2 = convert_float2(f2); + f3 = convert_float3(c3); + f3 = convert_float3(uc3); + f3 = convert_float3(s3); + f3 = convert_float3(us3); + f3 = convert_float3(i3); + f3 = convert_float3(ui3); + f3 = convert_float3(f3); + f4 = convert_float4(c4); + f4 = convert_float4(uc4); + f4 = convert_float4(s4); + f4 = convert_float4(us4); + f4 = convert_float4(i4); + f4 = convert_float4(ui4); + f4 = convert_float4(f4); + + // FIXME: No support for long/double (either from/to). + + // math + f = acos(f); + f2 = acos(f2); + f3 = acos(f3); + f4 = acos(f4); + f = acosh(f); + f2 = acosh(f2); + f3 = acosh(f3); + f4 = acosh(f4); + f = acospi(f); + f2 = acospi(f2); + f3 = acospi(f3); + f4 = acospi(f4); + + f = asin(f); + f2 = asin(f2); + f3 = asin(f3); + f4 = asin(f4); + f = asinh(f); + f2 = asinh(f2); + f3 = asinh(f3); + f4 = asinh(f4); + f = asinpi(f); + f2 = asinpi(f2); + f3 = asinpi(f3); + f4 = asinpi(f4); + + f = atan(f); + f2 = atan(f2); + f3 = atan(f3); + f4 = atan(f4); + f = atanh(f); + f2 = atanh(f2); + f3 = atanh(f3); + f4 = atanh(f4); + f = atanpi(f); + f2 = atanpi(f2); + f3 = atanpi(f3); + f4 = atanpi(f4); + + f = atan2(f, f); + f2 = atan2(f2, f2); + f3 = atan2(f3, f3); + f4 = atan2(f4, f4); + f = atan2pi(f, f); + f2 = atan2pi(f2, f2); + f3 = atan2pi(f3, f3); + f4 = atan2(f4, f4); + + f = cbrt(f); + f2 = cbrt(f2); + f3 = cbrt(f3); + f4 = cbrt(f4); + + f = ceil(f); + f2 = ceil(f2); + f3 = ceil(f3); + f4 = ceil(f4); + + f = copysign(f, f); + f2 = copysign(f2, f2); + f3 = copysign(f3, f3); + f4 = copysign(f4, f4); + + f = cos(f); + f2 = cos(f2); + f3 = cos(f3); + f4 = cos(f4); + f = cosh(f); + f2 = cosh(f2); + f3 = cosh(f3); + f4 = cosh(f4); + f = cospi(f); + f2 = cospi(f2); + f3 = cospi(f3); + f4 = cospi(f4); + + f = erfc(f); + f2 = erfc(f2); + f3 = erfc(f3); + f4 = erfc(f4); + f = erf(f); + f2 = erf(f2); + f3 = erf(f3); + f4 = erf(f4); + + f = exp(f); + f2 = exp(f2); + f3 = exp(f3); + f4 = exp(f4); + f = exp2(f); + f2 = exp2(f2); + f3 = exp2(f3); + f4 = exp2(f4); + + f = pow(f, f); + f2 = pow(f2, f2); + f3 = pow(f3, f3); + f4 = pow(f4, f4); + + f = exp10(f); + f2 = exp10(f2); + f3 = exp10(f3); + f4 = exp10(f4); + + f = expm1(f); + f2 = expm1(f2); + f3 = expm1(f3); + f4 = expm1(f4); + + f = fabs(f); + f2 = fabs(f2); + f3 = fabs(f3); + f4 = fabs(f4); + + f = fabs(f); + f2 = fabs(f2); + f3 = fabs(f3); + f4 = fabs(f4); + + f = fdim(f, f); + f2 = fdim(f2, f2); + f3 = fdim(f3, f3); + f4 = fdim(f4, f4); + + f = floor(f); + f2 = floor(f2); + f3 = floor(f3); + f4 = floor(f4); + + f = fma(f, f, f); + f2 = fma(f2, f2, f2); + f3 = fma(f3, f3, f3); + f4 = fma(f4, f4, f4); + + f = fmax(f, f); + f2 = fmax(f2, f2); + f3 = fmax(f3, f3); + f4 = fmax(f4, f4); + + f = fmin(f, f); + f2 = fmin(f2, f2); + f3 = fmin(f3, f3); + f4 = fmin(f4, f4); + + f = fmod(f, f); + f2 = fmod(f2, f2); + f3 = fmod(f3, f3); + f4 = fmod(f4, f4); + + f = fract(f, (float *)&f); + f2 = fract(f2, (float2 *)&f2); + f3 = fract(f3, (float3 *)&f3); + f4 = fract(f4, (float4 *)&f4); + f = fract(f); + f2 = fract(f2); + f3 = fract(f3); + f4 = fract(f4); + + f = frexp(f, (int *)&i); + f2 = frexp(f2, (int2 *)&i2); + f3 = frexp(f3, (int3 *)&i3); + f4 = frexp(f4, (int4 *)&i4); + + f = hypot(f, f); + f2 = hypot(f2, f2); + f3 = hypot(f3, f3); + f4 = hypot(f4, f4); + + i = ilogb(f); + i2 = ilogb(f2); + i3 = ilogb(f3); + i4 = ilogb(f4); + + f = ldexp(f, i); + f2 = ldexp(f2, i2); + f3 = ldexp(f3, i3); + f4 = ldexp(f4, i4); + f2 = ldexp(f2, i); + f3 = ldexp(f3, i); + f4 = ldexp(f4, i); + + f = lgamma(f); + f2 = lgamma(f2); + f3 = lgamma(f3); + f4 = lgamma(f4); + f = lgamma(f, (int *)&i); + f2 = lgamma(f2, (int2 *)&i2); + f3 = lgamma(f3, (int3 *)&i3); + f4 = lgamma(f4, (int4 *)&i4); + + f = log(f); + f2 = log(f2); + f3 = log(f3); + f4 = log(f4); + + f = log10(f); + f2 = log10(f2); + f3 = log10(f3); + f4 = log10(f4); + + f = log2(f); + f2 = log2(f2); + f3 = log2(f3); + f4 = log2(f4); + + f = log1p(f); + f2 = log1p(f2); + f3 = log1p(f3); + f4 = log1p(f4); + + f = logb(f); + f2 = logb(f2); + f3 = logb(f3); + f4 = logb(f4); + + f = mad(f, f, f); + f2 = mad(f2, f2, f2); + f3 = mad(f3, f3, f3); + f4 = mad(f4, f4, f4); + + f = modf(f, (float *)&f); + f2 = modf(f2, (float2 *)&f2); + f3 = modf(f3, (float3 *)&f3); + f4 = modf(f4, (float4 *)&f4); + + f = nan(ui); + + f = nextafter(f, f); + f2 = nextafter(f2, f2); + f3 = nextafter(f3, f3); + f4 = nextafter(f4, f4); + + f = pown(f, i); + f2 = pown(f2, i2); + f3 = pown(f3, i3); + f4 = pown(f4, i4); + + f = powr(f, f); + f2 = powr(f2, f2); + f3 = powr(f3, f3); + f4 = powr(f4, f4); + + f = remainder(f, f); + f2 = remainder(f2, f2); + f3 = remainder(f3, f3); + f4 = remainder(f4, f4); + + f = remquo(f, f, (int *)&i); + f2 = remquo(f2, f2, (int2 *)&i2); + f3 = remquo(f3, f3, (int3 *)&i3); + f4 = remquo(f4, f4, (int4 *)&i4); + + f = rint(f); + f2 = rint(f2); + f3 = rint(f3); + f4 = rint(f4); + + f = rootn(f, i); + f2 = rootn(f2, i2); + f3 = rootn(f3, i3); + f4 = rootn(f4, i4); + + f = round(f); + f2 = round(f2); + f3 = round(f3); + f4 = round(f4); + + f = rsqrt(f); + f2 = rsqrt(f2); + f3 = rsqrt(f3); + f4 = rsqrt(f4); + + f = sin(f); + f2 = sin(f2); + f3 = sin(f3); + f4 = sin(f4); + f = sinh(f); + f2 = sinh(f2); + f3 = sinh(f3); + f4 = sinh(f4); + f = sinpi(f); + f2 = sinpi(f2); + f3 = sinpi(f3); + f4 = sinpi(f4); + + f = sincos(f, (float *)&f); + f2 = sincos(f2, (float2 *)&f2); + f3 = sincos(f3, (float3 *)&f3); + f4 = sincos(f4, (float4 *)&f4); + + f = tan(f); + f2 = tan(f2); + f3 = tan(f3); + f4 = tan(f4); + f = tanh(f); + f2 = tanh(f2); + f3 = tanh(f3); + f4 = tanh(f4); + f = tanpi(f); + f2 = tanpi(f2); + f3 = tanpi(f3); + f4 = tanpi(f4); + + f = tgamma(f); + f2 = tgamma(f2); + f3 = tgamma(f3); + f4 = tgamma(f4); + + f = trunc(f); + f2 = trunc(f2); + f3 = trunc(f3); + f4 = trunc(f4); + + uc = abs(c); + uc2 = abs(c2); + uc3 = abs(c3); + uc4 = abs(c4); + us = abs(s); + us2 = abs(s2); + us3 = abs(s3); + us4 = abs(s4); + ui = abs(i); + ui2 = abs(i2); + ui3 = abs(i3); + ui4 = abs(i4); + + c = clz(c); + c2 = clz(c2); + c3 = clz(c3); + c4 = clz(c4); + uc = clz(uc); + uc2 = clz(uc2); + uc3 = clz(uc3); + uc4 = clz(uc4); + s = clz(s); + s2 = clz(s2); + s3 = clz(s3); + s4 = clz(s4); + us = clz(us); + us2 = clz(us2); + us3 = clz(us3); + us4 = clz(us4); + i = clz(i); + i2 = clz(i2); + i3 = clz(i3); + i4 = clz(i4); + ui = clz(ui); + ui2 = clz(ui2); + ui3 = clz(ui3); + ui4 = clz(ui4); + + c = min(c, c); + c2 = min(c2, c2); + c3 = min(c3, c3); + c4 = min(c4, c4); + uc = min(uc, uc); + uc2 = min(uc2, uc2); + uc3 = min(uc3, uc3); + uc4 = min(uc4, uc4); + s = min(s, s); + s2 = min(s2, s2); + s3 = min(s3, s3); + s4 = min(s4, s4); + us = min(us, us); + us2 = min(us2, us2); + us3 = min(us3, us3); + us4 = min(us4, us4); + i = min(i, i); + i2 = min(i2, i2); + i3 = min(i3, i3); + i4 = min(i4, i4); + ui = min(ui, ui); + ui2 = min(ui2, ui2); + ui3 = min(ui3, ui3); + ui4 = min(ui4, ui4); + f = min(f, f); + f2 = min(f2, f2); + f3 = min(f3, f3); + f4 = min(f4, f4); + f2 = min(f2, f); + f3 = min(f3, f); + f4 = min(f4, f); + + c = max(c, c); + c2 = max(c2, c2); + c3 = max(c3, c3); + c4 = max(c4, c4); + uc = max(uc, uc); + uc2 = max(uc2, uc2); + uc3 = max(uc3, uc3); + uc4 = max(uc4, uc4); + s = max(s, s); + s2 = max(s2, s2); + s3 = max(s3, s3); + s4 = max(s4, s4); + us = max(us, us); + us2 = max(us2, us2); + us3 = max(us3, us3); + us4 = max(us4, us4); + i = max(i, i); + i2 = max(i2, i2); + i3 = max(i3, i3); + i4 = max(i4, i4); + ui = max(ui, ui); + ui2 = max(ui2, ui2); + ui3 = max(ui3, ui3); + ui4 = max(ui4, ui4); + f = max(f, f); + f2 = max(f2, f2); + f3 = max(f3, f3); + f4 = max(f4, f4); + f2 = max(f2, f); + f3 = max(f3, f); + f4 = max(f4, f); + + f = clamp(f, f, f); + f2 = clamp(f2, f2, f2); + f3 = clamp(f3, f3, f3); + f4 = clamp(f4, f4, f4); + f2 = clamp(f2, f, f); + f3 = clamp(f3, f, f); + f4 = clamp(f4, f, f); + // FIXME: other clamps only in 19+ + + f = degrees(f); + f2 = degrees(f2); + f3 = degrees(f3); + f4 = degrees(f4); + + f = mix(f, f, f); + f2 = mix(f2, f2, f2); + f3 = mix(f3, f3, f3); + f4 = mix(f4, f4, f4); + f2 = mix(f2, f2, f); + f3 = mix(f3, f3, f); + f4 = mix(f4, f4, f); + + f = radians(f); + f2 = radians(f2); + f3 = radians(f3); + f4 = radians(f4); + + f = step(f, f); + f2 = step(f2, f2); + f3 = step(f3, f3); + f4 = step(f4, f4); + f2 = step(f2, f); + f3 = step(f3, f); + f4 = step(f4, f); + + f = sign(f); + f2 = sign(f2); + f3 = sign(f3); + f4 = sign(f4); + + f3 = cross(f3, f3); + f4 = cross(f4, f4); + + f = dot(f, f); + f = dot(f2, f2); + f = dot(f3, f3); + f = dot(f4, f4); + + f = length(f); + f = length(f2); + f = length(f3); + f = length(f4); + + f = distance(f, f); + f = distance(f2, f2); + f = distance(f3, f3); + f = distance(f4, f4); + + f = normalize(f); + f2 = normalize(f2); + f3 = normalize(f3); + f4 = normalize(f4); + + f = half_recip(f); + f2 = half_recip(f2); + f3 = half_recip(f3); + f4 = half_recip(f4); + + f = half_sqrt(f); + f2 = half_sqrt(f2); + f3 = half_sqrt(f3); + f4 = half_sqrt(f4); + + f = half_rsqrt(f); + f2 = half_rsqrt(f2); + f3 = half_rsqrt(f3); + f4 = half_rsqrt(f4); + + f = fast_length(f); + f = fast_length(f2); + f = fast_length(f3); + f = fast_length(f4); + + f = fast_distance(f, f); + f = fast_distance(f2, f2); + f = fast_distance(f3, f3); + f = fast_distance(f4, f4); + + f = fast_normalize(f); + f2 = fast_normalize(f2); + f3 = fast_normalize(f3); + f4 = fast_normalize(f4); + + f = native_exp2(f); + f2 = native_exp2(f2); + f3 = native_exp2(f3); + f4 = native_exp2(f4); + + f = native_exp(f); + f2 = native_exp(f2); + f3 = native_exp(f3); + f4 = native_exp(f4); + + f = native_exp10(f); + f2 = native_exp10(f2); + f3 = native_exp10(f3); + f4 = native_exp10(f4); + + f = native_log2(f); + f2 = native_log2(f2); + f3 = native_log2(f3); + f4 = native_log2(f4); + + f = native_log(f); + f2 = native_log(f2); + f3 = native_log(f3); + f4 = native_log(f4); + + f = native_log10(f); + f2 = native_log10(f2); + f3 = native_log10(f3); + f4 = native_log10(f4); + + f = native_powr(f, f); + f2 = native_powr(f2, f2); + f3 = native_powr(f3, f3); + f4 = native_powr(f4, f4); + + // rs_core.rsh + b = rsSendToClient(0); + b = rsSendToClient(0, NULL, 0); + rsSendToClientBlocking(0); + rsSendToClientBlocking(0, NULL, 0); + + rs_script_call_t sc; + rsForEach(scriptNonNull, allocNonNull, allocNonNull, NULL, 0, &sc); + rsForEach(scriptNonNull, allocNonNull, allocNonNull, NULL, 0); + rsForEach(scriptNonNull, allocNonNull, allocNonNull); + + // rs_debug.rsh + rsDebug("", f); + rsDebug("", f, f); + rsDebug("", f, f, f); + rsDebug("", f, f, f, f); + rsDebug("", f2); + rsDebug("", f3); + rsDebug("", f4); + rsDebug("", d); + rsDebug("", &m4x4); + rsDebug("", &m3x3); + rsDebug("", &m2x2); + rsDebug("", i); + rsDebug("", ui); + rsDebug("", l); + rsDebug("", ul); + rsDebug("", ll); + rsDebug("", ull); + rsDebug("", (const void *)&i); + rsDebug("", c); + rsDebug("", c2); + rsDebug("", c3); + rsDebug("", c4); + rsDebug("", uc); + rsDebug("", uc2); + rsDebug("", uc3); + rsDebug("", uc4); + rsDebug("", s); + rsDebug("", s2); + rsDebug("", s3); + rsDebug("", s4); + rsDebug("", us); + rsDebug("", us2); + rsDebug("", us3); + rsDebug("", us4); + rsDebug("", i2); + rsDebug("", i3); + rsDebug("", i4); + rsDebug("", ui2); + rsDebug("", ui3); + rsDebug("", ui4); + rsDebug("", l2); + rsDebug("", l3); + rsDebug("", l4); + rsDebug("", ul2); + rsDebug("", ul3); + rsDebug("", ul4); + + // rs_element.rsh + ui = rsElementGetSubElementCount(elemNonNull); + elemNull = rsElementGetSubElement(elemNonNull, 0); + ui = rsElementGetSubElementNameLength(elemNonNull, 0); + ui = rsElementGetSubElementName(elemNonNull, 0, NULL, 0); + ui = rsElementGetSubElementArraySize(elemNonNull, 0); + ui = rsElementGetSubElementOffsetBytes(elemNonNull, 0); + ui = rsElementGetBytesSize(elemNonNull); + + dt = rsElementGetDataType(elemNonNull); + dk = rsElementGetDataKind(elemNonNull); + + ui = rsElementGetVectorSize(elemNonNull); + + // rs_math.rsh + i = rsRand(i); + i = rsRand(i, i); + f = rsRand(f); + f = rsFrac(f); + ui = rsClamp(ui, ui, ui); + i = rsClamp(i, i, i); + us = rsClamp(us, us, us); + s = rsClamp(s, s, s); + uc = rsClamp(uc, uc, uc); + c = rsClamp(c, c, c); + + // skip always-inlined rsExtractFrustumPlanes + // skip always-inlined rsIsSphereInFrustum + + uc4 = rsPackColorTo8888(f, f, f); + uc4 = rsPackColorTo8888(f, f, f, f); + uc4 = rsPackColorTo8888(f3); + uc4 = rsPackColorTo8888(f4); + f4 = rsUnpackColor8888(uc4); + uc4 = rsYuvToRGBA_uchar4(uc, uc, uc); + f4 = rsYuvToRGBA_float4(uc, uc, uc); + + // rs_matrix.rsh + rsMatrixSet(&m4x4, ui, ui, f); + rsMatrixSet(&m3x3, ui, ui, f); + rsMatrixSet(&m2x2, ui, ui, f); + f = rsMatrixGet(&m4x4, ui, ui); + f = rsMatrixGet(&m3x3, ui, ui); + f = rsMatrixGet(&m2x2, ui, ui); + rsMatrixLoadIdentity(&m4x4); + rsMatrixLoadIdentity(&m3x3); + rsMatrixLoadIdentity(&m2x2); + rsMatrixLoad(&m4x4, fa); + rsMatrixLoad(&m3x3, fa); + rsMatrixLoad(&m2x2, fa); + rsMatrixLoad(&m4x4, &m4x4); + rsMatrixLoad(&m4x4, &m3x3); + rsMatrixLoad(&m4x4, &m2x2); + rsMatrixLoad(&m3x3, &m3x3); + rsMatrixLoad(&m2x2, &m2x2); + rsMatrixLoadRotate(&m4x4, f, f, f, f); + rsMatrixLoadScale(&m4x4, f, f, f); + rsMatrixLoadTranslate(&m4x4, f, f, f); + rsMatrixLoadMultiply(&m4x4, &m4x4, &m4x4); + rsMatrixLoadMultiply(&m3x3, &m3x3, &m3x3); + rsMatrixLoadMultiply(&m2x2, &m2x2, &m2x2); + rsMatrixMultiply(&m4x4, &m4x4); + rsMatrixMultiply(&m3x3, &m3x3); + rsMatrixMultiply(&m2x2, &m2x2); + rsMatrixRotate(&m4x4, f, f, f, f); + rsMatrixScale(&m4x4, f, f, f); + rsMatrixTranslate(&m4x4, f, f, f); + rsMatrixLoadOrtho(&m4x4, f, f, f, f, f, f); + rsMatrixLoadFrustum(&m4x4, f, f, f, f, f, f); + rsMatrixLoadPerspective(&m4x4, f, f, f, f); + f4 = rsMatrixMultiply(&m4x4, f4); + f4 = rsMatrixMultiply(&m4x4, f3); + f4 = rsMatrixMultiply(&m4x4, f2); + f3 = rsMatrixMultiply(&m3x3, f3); + f3 = rsMatrixMultiply(&m3x3, f2); + f2 = rsMatrixMultiply(&m2x2, f2); + b = rsMatrixInverse(&m4x4); + b = rsMatrixInverseTranspose(&m4x4); + rsMatrixTranspose(&m4x4); + rsMatrixTranspose(&m3x3); + rsMatrixTranspose(&m2x2); + + // rs_object.rsh + rsSetObject(&elemNonNull, elemNonNull); + rsSetObject(&typeNonNull, typeNonNull); + rsSetObject(&allocNonNull, allocNonNull); + rsSetObject(&samplerNonNull, samplerNonNull); + rsSetObject(&scriptNonNull, scriptNonNull); + rsClearObject(&elemNonNull); + rsClearObject(&typeNonNull); + rsClearObject(&allocNonNull); + rsClearObject(&samplerNonNull); + rsClearObject(&scriptNonNull); + b = rsIsObject(elemNonNull); + b = rsIsObject(typeNonNull); + b = rsIsObject(allocNonNull); + b = rsIsObject(samplerNonNull); + b = rsIsObject(scriptNonNull); + + // rs_quaternion.rsh skipped because all functions are static. + + // rs_sampler.rsh + rsv = rsSamplerGetMinification(samplerNonNull); + rsv = rsSamplerGetMagnification(samplerNonNull); + rsv = rsSamplerGetWrapS(samplerNonNull); + rsv = rsSamplerGetWrapT(samplerNonNull); + f = rsSamplerGetAnisotropy(samplerNonNull); + + // rs_time.rsh + rst = rsTime(NULL); + rsLocaltime((rs_tm *) &rstm, (rs_time_t *) &rst); + ll = rsUptimeMillis(); + ll = rsUptimeNanos(); + f = rsGetDt(); + + /******************************** + * DO NOT EXECUTE THIS FUNCTION * + ********************************/ +} + +static bool test_obj_api() { + bool failed = false; + + _RS_ASSERT(!rsIsObject(elemNull)); + _RS_ASSERT(rsIsObject(elemNonNull)); + rsSetObject(&elemNull, elemNonNull); + _RS_ASSERT(rsIsObject(elemNull)); + rsClearObject(&elemNull); + _RS_ASSERT(!rsIsObject(elemNull)); + + _RS_ASSERT(!rsIsObject(typeNull)); + _RS_ASSERT(rsIsObject(typeNonNull)); + rsSetObject(&typeNull, typeNonNull); + _RS_ASSERT(rsIsObject(typeNull)); + rsClearObject(&typeNull); + _RS_ASSERT(!rsIsObject(typeNull)); + + _RS_ASSERT(!rsIsObject(allocNull)); + _RS_ASSERT(rsIsObject(allocNonNull)); + rsSetObject(&allocNull, allocNonNull); + _RS_ASSERT(rsIsObject(allocNull)); + rsClearObject(&allocNull); + _RS_ASSERT(!rsIsObject(allocNull)); + + _RS_ASSERT(!rsIsObject(samplerNull)); + _RS_ASSERT(rsIsObject(samplerNonNull)); + rsSetObject(&samplerNull, samplerNonNull); + _RS_ASSERT(rsIsObject(samplerNull)); + rsClearObject(&samplerNull); + _RS_ASSERT(!rsIsObject(samplerNull)); + + _RS_ASSERT(!rsIsObject(scriptNull)); + _RS_ASSERT(rsIsObject(scriptNonNull)); + rsSetObject(&scriptNull, scriptNonNull); + _RS_ASSERT(rsIsObject(scriptNull)); + rsClearObject(&scriptNull); + _RS_ASSERT(!rsIsObject(scriptNull)); + + if (failed) { + rsDebug("test_obj_api FAILED", -1); + } + else { + rsDebug("test_obj_api PASSED", 0); + } + + return failed; +} + + +static bool test_rs_alloc_api() { + bool failed = false; + rs_allocation a = rsGetAllocation(allocPtr); + _RS_ASSERT(rsIsObject(a)); + _RS_ASSERT(rsAllocationGetDimX(a) == x); + _RS_ASSERT(rsAllocationGetDimY(a) == y); + _RS_ASSERT(rsAllocationGetDimZ(a) == z); + _RS_ASSERT(rsAllocationGetDimLOD(a) == 0); + _RS_ASSERT(rsAllocationGetDimFaces(a) == 0); + + rsSetElementAt_char(a, 5, 1, 0); + rsAllocationCopy1DRange(allocDst, 0, 0, x, a, 0, 0); + _RS_ASSERT(rsGetElementAt_char(allocDst, 1, 0) == 5); + + if (failed) { + rsDebug("test_obj_api FAILED", -1); + } + else { + rsDebug("test_obj_api PASSED", 0); + } + + return failed; +} + + +void api_test() { + bool failed = false; + failed |= test_obj_api(); + failed |= test_rs_alloc_api(); + + if (failed) { + rsSendToClientBlocking(RS_MSG_TEST_FAILED); + } + else { + rsSendToClientBlocking(RS_MSG_TEST_PASSED); + } +} + diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/array_alloc.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/array_alloc.rs new file mode 100644 index 00000000..74ffdb16 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/array_alloc.rs @@ -0,0 +1,21 @@ +#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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/array_init.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/array_init.rs new file mode 100644 index 00000000..842249af --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/array_init.rs @@ -0,0 +1,58 @@ +#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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/atomic.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/atomic.rs new file mode 100644 index 00000000..f0a50419 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/atomic.rs @@ -0,0 +1,77 @@ +#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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/bug_char.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/bug_char.rs new file mode 100644 index 00000000..dcd7b727 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/bug_char.rs @@ -0,0 +1,47 @@ +#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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/clamp.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/clamp.rs new file mode 100644 index 00000000..28b00bdc --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/clamp.rs @@ -0,0 +1,56 @@ +#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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/clamp_relaxed.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/clamp_relaxed.rs new file mode 100644 index 00000000..71c65aee --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/clamp_relaxed.rs @@ -0,0 +1,2 @@ +#include "clamp.rs" +#pragma rs_fp_relaxed diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/constant.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/constant.rs new file mode 100644 index 00000000..732eaefa --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/constant.rs @@ -0,0 +1,19 @@ +#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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/convert.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/convert.rs new file mode 100644 index 00000000..e314f2bc --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/convert.rs @@ -0,0 +1,37 @@ +#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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/convert_relaxed.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/convert_relaxed.rs new file mode 100644 index 00000000..81abb9b1 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/convert_relaxed.rs @@ -0,0 +1,2 @@ +#include "convert.rs" +#pragma rs_fp_relaxed diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/copy_test.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/copy_test.rs new file mode 100644 index 00000000..f4243eba --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/copy_test.rs @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2012 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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/element.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/element.rs new file mode 100644 index 00000000..c7a7a87f --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/element.rs @@ -0,0 +1,147 @@ +#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(rsElementGetDataType(simpleElem) == RS_TYPE_FLOAT_32); + _RS_ASSERT(rsElementGetVectorSize(simpleElem) == 3); + + subElemCount = rsElementGetSubElementCount(complexElem); + _RS_ASSERT(subElemCount == 10); + _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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/foreach.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/foreach.rs new file mode 100644 index 00000000..08e6bede --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/foreach.rs @@ -0,0 +1,76 @@ +#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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/foreach_bounds.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/foreach_bounds.rs new file mode 100644 index 00000000..875f2156 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/foreach_bounds.rs @@ -0,0 +1,72 @@ +#include "shared.rsh" + +int dimX; +int dimY; +int xStart = 0; +int xEnd = 0; +int yStart = 0; +int yEnd = 0; + +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); + rsDebug("i: ", i); + rsDebug("j: ", j); + rsDebug("a[j][i]: ", v); + 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 foreach_bounds_test() { + static bool failed = false; + + rs_script_call_t rssc = {0}; + rssc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; + rssc.xStart = xStart; + rssc.xEnd = xEnd; + rssc.yStart = yStart; + rssc.yEnd = yEnd; + + rsForEach(s, ain, aout, NULL, 0, &rssc); + + failed |= test_root_output(); + + if (failed) { + rsSendToClientBlocking(RS_MSG_TEST_FAILED); + } + else { + rsSendToClientBlocking(RS_MSG_TEST_PASSED); + } +} + diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/fp_mad.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/fp_mad.rs new file mode 100644 index 00000000..3e8889ed --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/fp_mad.rs @@ -0,0 +1,168 @@ +#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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/instance.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/instance.rs new file mode 100644 index 00000000..65ce0326 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/instance.rs @@ -0,0 +1,9 @@ +#include "shared.rsh" + +int i; +rs_allocation ai; + +void instance_test() { + // Set our allocation based on the global input value. + rsSetElementAt_int(ai, i, 0); +} diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/int4.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/int4.rs new file mode 100644 index 00000000..c791cabc --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/int4.rs @@ -0,0 +1,29 @@ +#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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/kernel.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/kernel.rs new file mode 100644 index 00000000..6972737e --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/kernel.rs @@ -0,0 +1,47 @@ +#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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/kernel_struct.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/kernel_struct.rs new file mode 100644 index 00000000..83484a2b --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/kernel_struct.rs @@ -0,0 +1,66 @@ +#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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/math.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/math.rs new file mode 100644 index 00000000..aae29a4c --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/math.rs @@ -0,0 +1,436 @@ +#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_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_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(rsClamp); + + 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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/math_agree.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/math_agree.rs new file mode 100644 index 00000000..80f73bef --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/math_agree.rs @@ -0,0 +1,400 @@ +#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) + +#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); + +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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/math_conformance.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/math_conformance.rs new file mode 100644 index 00000000..ae78feba --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/math_conformance.rs @@ -0,0 +1,57 @@ +#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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/min.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/min.rs new file mode 100644 index 00000000..4b92763f --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/min.rs @@ -0,0 +1,20 @@ +#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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/noroot.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/noroot.rs new file mode 100644 index 00000000..2c807bdf --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/noroot.rs @@ -0,0 +1,45 @@ +#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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/primitives.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/primitives.rs new file mode 100644 index 00000000..ce451da8 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/primitives.rs @@ -0,0 +1,61 @@ +#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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/refcount.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/refcount.rs new file mode 100644 index 00000000..4ea70e2e --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/refcount.rs @@ -0,0 +1,13 @@ +#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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/rsdebug.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/rsdebug.rs new file mode 100644 index 00000000..68ac1689 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/rsdebug.rs @@ -0,0 +1,62 @@ +#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; +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("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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/rslist.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/rslist.rs new file mode 100644 index 00000000..62aa6960 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/rslist.rs @@ -0,0 +1,25 @@ +// Copyright (C) 2013 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma version(1) + +#pragma rs java_package_name(com.android.rs.test_compatlegacy) + +typedef struct ListAllocs_s { + rs_allocation text; + int result; +} ListAllocs; + +ListAllocs *gList; + diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/rstime.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/rstime.rs new file mode 100644 index 00000000..7be955d5 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/rstime.rs @@ -0,0 +1,52 @@ +#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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/rstypes.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/rstypes.rs new file mode 100644 index 00000000..afada817 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/rstypes.rs @@ -0,0 +1,70 @@ +#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; + + //allocationTestLocal = allocationTest; + + //allocationTest = allocationTestLocal; + + /*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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/sampler.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/sampler.rs new file mode 100644 index 00000000..ff1c0a74 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/sampler.rs @@ -0,0 +1,63 @@ +#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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/shared.rsh b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/shared.rsh new file mode 100644 index 00000000..11c1f793 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/shared.rsh @@ -0,0 +1,113 @@ +#pragma version(1) + +#pragma rs java_package_name(com.android.rs.test_compatlegacy) + +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) + +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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/struct.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/struct.rs new file mode 100644 index 00000000..1cd728e9 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/struct.rs @@ -0,0 +1,37 @@ +#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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/test_root.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/test_root.rs new file mode 100644 index 00000000..5c14b067 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/test_root.rs @@ -0,0 +1,23 @@ +// Fountain test script +#pragma version(1) + +#pragma rs java_package_name(com.android.rs.test_compatlegacy) + +#pragma stateFragment(parent) + +#include "rs_graphics.rsh" + + +typedef struct TestResult { + rs_allocation name; + bool pass; + float score; +} TestResult_t; +TestResult_t *results; + +int root() { + + return 0; +} + + diff --git a/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/unsigned.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/unsigned.rs new file mode 100644 index 00000000..2c056f49 --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/unsigned.rs @@ -0,0 +1,36 @@ +#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/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/vector.rs b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/vector.rs new file mode 100644 index 00000000..0430a2fc --- /dev/null +++ b/java/tests/RSTest_CompatLibLegacy/src/com/android/rs/test/vector.rs @@ -0,0 +1,198 @@ +#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); + } +} + diff --git a/update_rs_prebuilts.sh b/update_rs_prebuilts.sh index 385c5636..3a5115ee 100755 --- a/update_rs_prebuilts.sh +++ b/update_rs_prebuilts.sh @@ -4,7 +4,7 @@ MY_ANDROID_DIR=$PWD/../../ cd $MY_ANDROID_DIR -if [ $OSTYPE == 'darwin13' ]; +if [ $OSTYPE == 'darwin14' ]; then DARWIN=1 @@ -21,8 +21,8 @@ else SHORT_OSNAME=linux SONAME=so # Target architectures and their system library names. - TARGETS=(arm mips x86) - SYS_NAMES=(generic generic_mips generic_x86) + TARGETS=(arm mips x86 arm64) + SYS_NAMES=(generic generic_mips generic_x86 generic_arm64) NUM_CORES=`cat /proc/cpuinfo | grep processor | tail -n 1 | cut -f 2 -d :` NUM_CORES=$(($NUM_CORES+1)) @@ -66,7 +66,10 @@ build_rs_libs() { cd $MY_ANDROID_DIR/frameworks/rs/driver/runtime && mma -j$NUM_CORES && cd - || exit 1 # Build a sample support application to ensure that all the pieces are up to date. cd $MY_ANDROID_DIR/frameworks/rs/java/tests/RSTest_CompatLib/ && mma -j$NUM_CORES && cd - || exit 2 - + # Build libcompiler-rt.a + cd $MY_ANDROID_DIR/external/compiler-rt && mma -j$NUM_CORES && cd - || exit 3 + # Build the blas libraries. + cd $MY_ANDROID_DIR/external/cblas && mma -j$NUM_CORES && cd - || exit 4 } # Build everything by default @@ -124,8 +127,18 @@ repo start pb_$DATE . if [ $DARWIN -eq 0 ]; then for i in $(seq 0 $((${#TARGETS[@]} - 1))); do t=${TARGETS[$i]} - sys_lib_dir=$MY_ANDROID_DIR/out/target/product/${SYS_NAMES[$i]}/system/lib - obj_lib_dir=$MY_ANDROID_DIR/out/target/product/${SYS_NAMES[$i]}/obj/lib + sys_name=${SYS_NAMES[$i]} + case "$sys_name" in + *64) + sys_lib_dir=$MY_ANDROID_DIR/out/target/product/$sys_name/system/lib64 + ;; + *) + sys_lib_dir=$MY_ANDROID_DIR/out/target/product/$sys_name/system/lib + ;; + esac + obj_lib_dir=$MY_ANDROID_DIR/out/target/product/$sys_name/obj/lib + obj_static_lib_dir=$MY_ANDROID_DIR/out/target/product/$sys_name/obj/STATIC_LIBRARIES + for a in `find renderscript/lib/$t -name \*.so`; do file=`basename $a` cp `find $sys_lib_dir $obj_lib_dir -name $file | head -1` $a || exit 4 @@ -135,6 +148,12 @@ if [ $DARWIN -eq 0 ]; then file=`basename $a` cp `find $HOST_LIB_DIR $HOST_LIB64_DIR $sys_lib_dir $obj_lib_dir -name $file | head -1` $a || exit 5 done + + for a in `find renderscript/lib/$t -name \*.a`; do + file=`basename $a` + cp `find $obj_static_lib_dir -name $file | head -1` $a || exit 4 + done + done # javalib.jar |