diff options
Diffstat (limited to 'tests')
62 files changed, 5788 insertions, 0 deletions
diff --git a/tests/RenderScriptTests/Fountain_v11/Android.mk b/tests/RenderScriptTests/Fountain_v11/Android.mk new file mode 100644 index 0000000..e51115c --- /dev/null +++ b/tests/RenderScriptTests/Fountain_v11/Android.mk @@ -0,0 +1,32 @@ +# +# Copyright (C) 2008 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. +# + +ifneq ($(TARGET_SIMULATOR),true) + +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := optional + +LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src) +#LOCAL_STATIC_JAVA_LIBRARIES := android.renderscript + +LOCAL_PACKAGE_NAME := Fountain_v11 +LOCAL_SDK_VERSION := 11 + +include $(BUILD_PACKAGE) + +endif diff --git a/tests/RenderScriptTests/Fountain_v11/AndroidManifest.xml b/tests/RenderScriptTests/Fountain_v11/AndroidManifest.xml new file mode 100644 index 0000000..fcb4faf --- /dev/null +++ b/tests/RenderScriptTests/Fountain_v11/AndroidManifest.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.fountain_v11"> + <uses-sdk android:minSdkVersion="11" /> + <application + android:label="Fountain_v11" + android:icon="@drawable/test_pattern"> + <activity android:name="Fountain_v11"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + </application> +</manifest> diff --git a/tests/RenderScriptTests/Fountain_v11/_index.html b/tests/RenderScriptTests/Fountain_v11/_index.html new file mode 100644 index 0000000..223242f --- /dev/null +++ b/tests/RenderScriptTests/Fountain_v11/_index.html @@ -0,0 +1,5 @@ +<p>An example that renders many dots on the screen that follow a user's touch. The dots fall +to the bottom of the screen when the user releases the finger.</p> + + + diff --git a/tests/RenderScriptTests/Fountain_v11/res/drawable/test_pattern.png b/tests/RenderScriptTests/Fountain_v11/res/drawable/test_pattern.png Binary files differnew file mode 100644 index 0000000..e7d1455 --- /dev/null +++ b/tests/RenderScriptTests/Fountain_v11/res/drawable/test_pattern.png diff --git a/tests/RenderScriptTests/Fountain_v11/src/com/android/fountain/FountainRS.java b/tests/RenderScriptTests/Fountain_v11/src/com/android/fountain/FountainRS.java new file mode 100644 index 0000000..e858100 --- /dev/null +++ b/tests/RenderScriptTests/Fountain_v11/src/com/android/fountain/FountainRS.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2008 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.fountain_v11; + +import android.content.res.Resources; +import android.renderscript.*; +import android.util.Log; + + +public class FountainRS { + public static final int PART_COUNT = 50000; + + public FountainRS() { + } + + private Resources mRes; + private RenderScriptGL mRS; + private ScriptC_fountain mScript; + public void init(RenderScriptGL rs, Resources res, int width, int height) { + mRS = rs; + mRes = res; + + ProgramFragmentFixedFunction.Builder pfb = new ProgramFragmentFixedFunction.Builder(rs); + pfb.setVaryingColor(true); + rs.bindProgramFragment(pfb.create()); + + ScriptField_Point points = new ScriptField_Point(mRS, PART_COUNT);// + // Allocation.USAGE_GRAPHICS_VERTEX); + + Mesh.AllocationBuilder smb = new Mesh.AllocationBuilder(mRS); + smb.addVertexAllocation(points.getAllocation()); + smb.addIndexSetType(Mesh.Primitive.POINT); + Mesh sm = smb.create(); + + mScript = new ScriptC_fountain(mRS, mRes, R.raw.fountain); + mScript.set_partMesh(sm); + mScript.bind_point(points); + mRS.bindRootScript(mScript); + } + + boolean holdingColor[] = new boolean[10]; + public void newTouchPosition(float x, float y, float pressure, int id) { + if (id >= holdingColor.length) { + return; + } + int rate = (int)(pressure * pressure * 500.f); + if (rate > 500) { + rate = 500; + } + if (rate > 0) { + mScript.invoke_addParticles(rate, x, y, id, !holdingColor[id]); + holdingColor[id] = true; + } else { + holdingColor[id] = false; + } + + } +} diff --git a/tests/RenderScriptTests/Fountain_v11/src/com/android/fountain/FountainView.java b/tests/RenderScriptTests/Fountain_v11/src/com/android/fountain/FountainView.java new file mode 100644 index 0000000..e82376c --- /dev/null +++ b/tests/RenderScriptTests/Fountain_v11/src/com/android/fountain/FountainView.java @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2008 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.fountain_v11; + +import java.io.Writer; +import java.util.ArrayList; +import java.util.concurrent.Semaphore; + +import android.renderscript.RSSurfaceView; +import android.renderscript.RenderScript; +import android.renderscript.RenderScriptGL; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.os.Handler; +import android.os.Message; +import android.util.AttributeSet; +import android.util.Log; +import android.view.Surface; +import android.view.SurfaceHolder; +import android.view.SurfaceView; +import android.view.KeyEvent; +import android.view.MotionEvent; + +public class FountainView extends RSSurfaceView { + + public FountainView(Context context) { + super(context); + //setFocusable(true); + } + + private RenderScriptGL mRS; + private FountainRS mRender; + + public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { + super.surfaceChanged(holder, format, w, h); + if (mRS == null) { + RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig(); + mRS = createRenderScriptGL(sc); + mRS.setSurface(holder, w, h); + mRender = new FountainRS(); + mRender.init(mRS, getResources(), w, h); + } + } + + @Override + protected void onDetachedFromWindow() { + if (mRS != null) { + mRS = null; + destroyRenderScriptGL(); + } + } + + + @Override + public boolean onTouchEvent(MotionEvent ev) + { + int act = ev.getActionMasked(); + if (act == ev.ACTION_UP) { + mRender.newTouchPosition(0, 0, 0, ev.getPointerId(0)); + return false; + } else if (act == MotionEvent.ACTION_POINTER_UP) { + // only one pointer going up, we can get the index like this + int pointerIndex = ev.getActionIndex(); + int pointerId = ev.getPointerId(pointerIndex); + mRender.newTouchPosition(0, 0, 0, pointerId); + } + int count = ev.getHistorySize(); + int pcount = ev.getPointerCount(); + + for (int p=0; p < pcount; p++) { + int id = ev.getPointerId(p); + mRender.newTouchPosition(ev.getX(p), + ev.getY(p), + ev.getPressure(p), + id); + + for (int i=0; i < count; i++) { + mRender.newTouchPosition(ev.getHistoricalX(p, i), + ev.getHistoricalY(p, i), + ev.getHistoricalPressure(p, i), + id); + } + } + return true; + } +} + + diff --git a/tests/RenderScriptTests/Fountain_v11/src/com/android/fountain/Fountain_v11.java b/tests/RenderScriptTests/Fountain_v11/src/com/android/fountain/Fountain_v11.java new file mode 100644 index 0000000..2c07b27 --- /dev/null +++ b/tests/RenderScriptTests/Fountain_v11/src/com/android/fountain/Fountain_v11.java @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2008 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.fountain_v11; + +import android.renderscript.RSSurfaceView; +import android.renderscript.RenderScript; + +import android.app.Activity; +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.Config; +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 java.lang.Runtime; + +public class Fountain_v11 extends Activity { + //EventListener mListener = new EventListener(); + + private static final String LOG_TAG = "libRS_jni"; + private static final boolean DEBUG = false; + private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV; + + private FountainView mView; + + // get the current looper (from your Activity UI thread for instance + + + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + + // Create our Preview view and set it as the content of our + // Activity + mView = new FountainView(this); + setContentView(mView); + } + + @Override + protected void onResume() { + Log.e("rs", "onResume"); + + // Ideally a game should implement onResume() and onPause() + // to take appropriate action when the activity looses focus + super.onResume(); + mView.resume(); + } + + @Override + protected void onPause() { + Log.e("rs", "onPause"); + + // Ideally a game should implement onResume() and onPause() + // to take appropriate action when the activity looses focus + super.onPause(); + mView.pause(); + + + + //Runtime.getRuntime().exit(0); + } + + + static void log(String message) { + if (LOG_ENABLED) { + Log.v(LOG_TAG, message); + } + } + + +} + diff --git a/tests/RenderScriptTests/Fountain_v11/src/com/android/fountain/fountain.rs b/tests/RenderScriptTests/Fountain_v11/src/com/android/fountain/fountain.rs new file mode 100644 index 0000000..3b6c89a --- /dev/null +++ b/tests/RenderScriptTests/Fountain_v11/src/com/android/fountain/fountain.rs @@ -0,0 +1,69 @@ +// Fountain test script +#pragma version(1) + +#pragma rs java_package_name(com.android.fountain_v11) + +#pragma stateFragment(parent) + +#include "rs_graphics.rsh" + +static int newPart = 0; +rs_mesh partMesh; + +typedef struct __attribute__((packed, aligned(4))) Point { + float2 delta; + float2 position; + uchar4 color; +} Point_t; +Point_t *point; + +int root() { + float dt = min(rsGetDt(), 0.1f); + rsgClearColor(0.f, 0.f, 0.f, 1.f); + const float height = rsgGetHeight(); + const int size = rsAllocationGetDimX(rsGetAllocation(point)); + float dy2 = dt * (10.f); + Point_t * p = point; + for (int ct=0; ct < size; ct++) { + p->delta.y += dy2; + p->position += p->delta; + if ((p->position.y > height) && (p->delta.y > 0)) { + p->delta.y *= -0.3f; + } + p++; + } + + rsgDrawMesh(partMesh); + return 1; +} + +static float4 partColor[10]; +void addParticles(int rate, float x, float y, int index, bool newColor) +{ + if (newColor) { + partColor[index].x = rsRand(0.5f, 1.0f); + partColor[index].y = rsRand(1.0f); + partColor[index].z = rsRand(1.0f); + } + float rMax = ((float)rate) * 0.02f; + int size = rsAllocationGetDimX(rsGetAllocation(point)); + uchar4 c = rsPackColorTo8888(partColor[index]); + + Point_t * np = &point[newPart]; + float2 p = {x, y}; + while (rate--) { + float angle = rsRand(3.14f * 2.f); + float len = rsRand(rMax); + np->delta.x = len * sin(angle); + np->delta.y = len * cos(angle); + np->position = p; + np->color = c; + newPart++; + np++; + if (newPart >= size) { + newPart = 0; + np = &point[newPart]; + } + } +} + diff --git a/tests/RenderScriptTests/tests_v11/Android.mk b/tests/RenderScriptTests/tests_v11/Android.mk new file mode 100644 index 0000000..93a429b --- /dev/null +++ b/tests/RenderScriptTests/tests_v11/Android.mk @@ -0,0 +1,31 @@ +# +# Copyright (C) 2008 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. +# + +ifneq ($(TARGET_SIMULATOR),true) + +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := optional + +LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src) + +LOCAL_PACKAGE_NAME := RSTest_v11 +LOCAL_SDK_VERSION := 11 + +include $(BUILD_PACKAGE) + +endif diff --git a/tests/RenderScriptTests/tests_v11/AndroidManifest.xml b/tests/RenderScriptTests/tests_v11/AndroidManifest.xml new file mode 100644 index 0000000..f4aeda2 --- /dev/null +++ b/tests/RenderScriptTests/tests_v11/AndroidManifest.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.rs.test_v11"> + <uses-sdk android:minSdkVersion="11" /> + <application + android:label="_RS_Test_v11" + android:icon="@drawable/test_pattern"> + <activity android:name="RSTest_v11" + 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/tests/RenderScriptTests/tests_v11/res/drawable/test_pattern.png b/tests/RenderScriptTests/tests_v11/res/drawable/test_pattern.png Binary files differnew file mode 100644 index 0000000..e7d1455 --- /dev/null +++ b/tests/RenderScriptTests/tests_v11/res/drawable/test_pattern.png diff --git a/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/RSTestCore.java b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/RSTestCore.java new file mode 100644 index 0000000..888cfe4 --- /dev/null +++ b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/RSTestCore.java @@ -0,0 +1,206 @@ +/* + * Copyright (C) 2008 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_v11; + +import android.content.Context; +import android.content.res.Resources; +import android.renderscript.*; +import android.util.Log; +import java.util.ArrayList; +import java.util.ListIterator; +import java.util.Timer; +import java.util.TimerTask; + + +public class RSTestCore { + int mWidth; + int mHeight; + Context mCtx; + + public RSTestCore(Context ctx) { + mCtx = ctx; + } + + private Resources mRes; + private RenderScriptGL mRS; + + private Font mFont; + ScriptField_ListAllocs_s mListAllocs; + int mLastX; + int mLastY; + private ScriptC_rslist mScript; + + private ArrayList<UnitTest> unitTests; + private ListIterator<UnitTest> test_iter; + private UnitTest activeTest; + private boolean stopTesting; + + /* Periodic timer for ensuring future tests get scheduled */ + private Timer mTimer; + public static final int RS_TIMER_PERIOD = 100; + + public void init(RenderScriptGL rs, Resources res, int width, int height) { + mRS = rs; + mRes = res; + mWidth = width; + mHeight = height; + stopTesting = false; + + mScript = new ScriptC_rslist(mRS, mRes, R.raw.rslist); + + unitTests = new ArrayList<UnitTest>(); + + unitTests.add(new UT_primitives(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_math(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].result; + mListAllocs.set(listElem, i, false); + uta[i].setItem(listElem); + } + + mListAllocs.copyAll(); + + mScript.bind_gList(mListAllocs); + + mFont = Font.create(mRS, mRes, "serif", Font.Style.BOLD, 8); + mScript.set_gFont(mFont); + + mRS.bindRootScript(mScript); + + 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() { + 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(); + + if (mListAllocs != null && mScript != null && mRS != null) { + mListAllocs.copyAll(); + + mScript.bind_gList(mListAllocs); + mRS.bindRootScript(mScript); + } + } + + 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; + } + + } + + public void newTouchPosition(float x, float y, float pressure, int id) { + } + + public void onActionDown(int x, int y) { + mScript.set_gDY(0.0f); + mLastX = x; + mLastY = y; + refreshTestResults(); + } + + public void onActionMove(int x, int y) { + int dx = mLastX - x; + int dy = mLastY - y; + + if (Math.abs(dy) <= 2) { + dy = 0; + } + + mScript.set_gDY(dy); + + mLastX = x; + mLastY = y; + refreshTestResults(); + } +} diff --git a/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/RSTestView.java b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/RSTestView.java new file mode 100644 index 0000000..b5bebe9 --- /dev/null +++ b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/RSTestView.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2008 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_v11; + +import java.io.Writer; +import java.util.ArrayList; +import java.util.concurrent.Semaphore; + +import android.renderscript.RSSurfaceView; +import android.renderscript.RenderScript; +import android.renderscript.RenderScriptGL; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.os.Handler; +import android.os.Message; +import android.util.AttributeSet; +import android.util.Log; +import android.view.Surface; +import android.view.SurfaceHolder; +import android.view.SurfaceView; +import android.view.KeyEvent; +import android.view.MotionEvent; + +public class RSTestView extends RSSurfaceView { + + private Context mCtx; + + public RSTestView(Context context) { + super(context); + mCtx = context; + //setFocusable(true); + } + + private RenderScriptGL mRS; + private RSTestCore mRender; + + public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { + super.surfaceChanged(holder, format, w, h); + if (mRS == null) { + RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig(); + mRS = createRenderScriptGL(sc); + mRS.setSurface(holder, w, h); + mRender = new RSTestCore(mCtx); + mRender.init(mRS, getResources(), w, h); + } + } + + @Override + protected void onDetachedFromWindow() { + if(mRS != null) { + mRender.cleanup(); + mRS = null; + destroyRenderScriptGL(); + } + } + + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) + { + return super.onKeyDown(keyCode, event); + } + + @Override + public boolean onTouchEvent(MotionEvent ev) + { + boolean ret = false; + int act = ev.getAction(); + if (act == ev.ACTION_DOWN) { + mRender.onActionDown((int)ev.getX(), (int)ev.getY()); + ret = true; + } + else if (act == ev.ACTION_MOVE) { + mRender.onActionMove((int)ev.getX(), (int)ev.getY()); + ret = true; + } + + return ret; + } +} diff --git a/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/RSTest_v11.java b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/RSTest_v11.java new file mode 100644 index 0000000..1dedfce --- /dev/null +++ b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/RSTest_v11.java @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2008 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_v11; + +import android.renderscript.RSSurfaceView; +import android.renderscript.RenderScript; + +import android.app.Activity; +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.Config; +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 java.lang.Runtime; + +public class RSTest_v11 extends Activity { + //EventListener mListener = new EventListener(); + + private static final String LOG_TAG = "libRS_jni"; + private static final boolean DEBUG = false; + private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV; + + private RSTestView mView; + + // get the current looper (from your Activity UI thread for instance + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + + // Create our Preview view and set it as the content of our + // Activity + mView = new RSTestView(this); + setContentView(mView); + } + + @Override + protected void onResume() { + // Ideally a game should implement onResume() and onPause() + // to take appropriate action when the activity loses focus + super.onResume(); + mView.resume(); + } + + @Override + protected void onPause() { + // Ideally a game should implement onResume() and onPause() + // to take appropriate action when the activity loses focus + super.onPause(); + mView.pause(); + } + + static void log(String message) { + if (LOG_ENABLED) { + Log.v(LOG_TAG, message); + } + } + + +} diff --git a/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/UT_fp_mad.java b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/UT_fp_mad.java new file mode 100644 index 0000000..5d72aa6 --- /dev/null +++ b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/UT_fp_mad.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2010 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_v11; + +import android.content.Context; +import android.content.res.Resources; +import android.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, mRes, R.raw.fp_mad); + pRS.setMessageHandler(mRsMessage); + s.invoke_fp_mad_test(0, 0); + pRS.finish(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/UT_math.java b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/UT_math.java new file mode 100644 index 0000000..7e356f8 --- /dev/null +++ b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/UT_math.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2010 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_v11; + +import android.content.Context; +import android.content.res.Resources; +import android.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, mRes, R.raw.math); + pRS.setMessageHandler(mRsMessage); + s.invoke_math_test(0, 0); + pRS.finish(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/UT_primitives.java b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/UT_primitives.java new file mode 100644 index 0000000..dc3efbc --- /dev/null +++ b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/UT_primitives.java @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2010 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_v11; + +import android.content.Context; +import android.content.res.Resources; +import android.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, mRes, R.raw.primitives); + pRS.setMessageHandler(mRsMessage); + if (!initializeGlobals(s)) { + // initializeGlobals failed + result = -1; + } else { + s.invoke_primitives_test(0, 0); + pRS.finish(); + waitForMessage(); + } + pRS.destroy(); + } +} diff --git a/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/UT_rsdebug.java b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/UT_rsdebug.java new file mode 100644 index 0000000..00dbaf5 --- /dev/null +++ b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/UT_rsdebug.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2010 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_v11; + +import android.content.Context; +import android.content.res.Resources; +import android.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, mRes, R.raw.rsdebug); + pRS.setMessageHandler(mRsMessage); + s.invoke_test_rsdebug(0, 0); + pRS.finish(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/UT_rstime.java b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/UT_rstime.java new file mode 100644 index 0000000..5b4c399 --- /dev/null +++ b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/UT_rstime.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2010 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_v11; + +import android.content.Context; +import android.content.res.Resources; +import android.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, mRes, R.raw.rstime); + pRS.setMessageHandler(mRsMessage); + s.invoke_test_rstime(0, 0); + pRS.finish(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/UT_rstypes.java b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/UT_rstypes.java new file mode 100644 index 0000000..72a97c9 --- /dev/null +++ b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/UT_rstypes.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2010 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_v11; + +import android.content.Context; +import android.content.res.Resources; +import android.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, mRes, R.raw.rstypes); + pRS.setMessageHandler(mRsMessage); + s.invoke_test_rstypes(0, 0); + pRS.finish(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/UnitTest.java b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/UnitTest.java new file mode 100644 index 0000000..b62e535 --- /dev/null +++ b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/UnitTest.java @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2010 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_v11; +import android.content.Context; +import android.renderscript.RenderScript.RSMessageHandler; +import android.util.Log; + +public class UnitTest extends Thread { + public String name; + public 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 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: + android.util.Log.v("RenderScript", "Unit test got unexpected message"); + return; + } + } + + 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. */ + } + } + } + }; + + public void waitForMessage() { + while (!msgHandled) { + yield(); + } + } + + 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/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/fp_mad.rs b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/fp_mad.rs new file mode 100644 index 0000000..b6f2b2a --- /dev/null +++ b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/fp_mad.rs @@ -0,0 +1,174 @@ +#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(); + + float total = 0; + // 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(); + + float total = 0; + // 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(); + + float total = 0; + // 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(); + + float total = 0; + // 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(); + + float total = 0; + // 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(); + + float total = 0; + // Do ~100 M ops + for (int ct=0; ct < 1000 * 100 /4; ct++) { + for (int i=0; i < (1000); i++) { + data_f4[i] = clamp(data_f4[i], -1.f, 1.f); + } + } + + float time = end(index); + rsDebug("fp_clamp4 M ops", 100.f / time); +} + +void fp_mad_test(uint32_t index, int test_num) { + int x; + for (x=0; x < 1025; x++) { + data_f1[x] = (x & 0xf) * 0.1f; + data_f4[x].x = (x & 0xf) * 0.1f; + data_f4[x].y = (x & 0xf0) * 0.1f; + data_f4[x].z = (x & 0x33) * 0.1f; + data_f4[x].w = (x & 0x77) * 0.1f; + } + + test_mad4(index); + test_mad(index); + + for (x=0; x < 1025; x++) { + data_f1[x] = (x & 0xf) * 0.1f + 1.f; + data_f4[x].x = (x & 0xf) * 0.1f + 1.f; + data_f4[x].y = (x & 0xf0) * 0.1f + 1.f; + data_f4[x].z = (x & 0x33) * 0.1f + 1.f; + data_f4[x].w = (x & 0x77) * 0.1f + 1.f; + } + + test_norm(index); + test_sincos4(index); + test_sincos(index); + test_clamp4(index); + test_clamp(index); + + // TODO Actually verify test result accuracy + rsDebug("fp_mad_test PASSED", 0); + rsSendToClientBlocking(RS_MSG_TEST_PASSED); +} + + diff --git a/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/math.rs b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/math.rs new file mode 100644 index 0000000..2867be1 --- /dev/null +++ b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/math.rs @@ -0,0 +1,348 @@ +#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 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_FN_FUNC_FN_F(fnc) \ + rsDebug("Testing " #fnc, 0); \ + f1 = fnc(f1, f1); \ + f2 = fnc(f2, f1); \ + f3 = fnc(f3, f1); \ + f4 = fnc(f4, f1); + +#define TEST_FN_FUNC_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_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(copysign); + TEST_FN_FUNC_FN(cos); + TEST_FN_FUNC_FN(cosh); + TEST_FN_FUNC_FN(cospi); + 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_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_PFN(modf); + // nan + TEST_FN_FUNC_FN_FN(nextafter); + TEST_FN_FUNC_FN_FN(pow); + TEST_FN_FUNC_FN_IN(pown); + TEST_FN_FUNC_FN_FN(powr); + 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(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(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; +} + +#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; + +#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; + +DECL_INT(res) +DECL_INT(src1) +DECL_INT(src2) + +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; +} + +#define INIT_PREFIX_TYPE(prefix, type) \ +prefix##_##type##_1 = 1; \ +prefix##_##type##_2.x = 1; \ +prefix##_##type##_2.y = 1; \ +prefix##_##type##_3.x = 1; \ +prefix##_##type##_3.y = 1; \ +prefix##_##type##_3.z = 1; \ +prefix##_##type##_4.x = 1; \ +prefix##_##type##_4.y = 1; \ +prefix##_##type##_4.z = 1; \ +prefix##_##type##_4.w = 1; + +#define INIT_TYPE(type) \ +INIT_PREFIX_TYPE(src1, type) \ +INIT_PREFIX_TYPE(src2, type) \ +INIT_PREFIX_TYPE(res, type) + +#define INIT_ALL \ +INIT_TYPE(c); \ +INIT_TYPE(uc); \ +INIT_TYPE(s); \ +INIT_TYPE(us); \ +INIT_TYPE(i); \ +INIT_TYPE(ui); + +void math_test(uint32_t index, int test_num) { + bool failed = false; + INIT_ALL; + failed |= test_convert(); + failed |= test_fp_math(index); + failed |= test_basic_operators(); + + if (failed) { + rsSendToClientBlocking(RS_MSG_TEST_FAILED); + } + else { + rsSendToClientBlocking(RS_MSG_TEST_PASSED); + } +} + diff --git a/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/primitives.rs b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/primitives.rs new file mode 100644 index 0000000..ce451da --- /dev/null +++ b/tests/RenderScriptTests/tests_v11/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/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/rsdebug.rs b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/rsdebug.rs new file mode 100644 index 0000000..f7942a5 --- /dev/null +++ b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/rsdebug.rs @@ -0,0 +1,56 @@ +#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 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("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/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/rslist.rs b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/rslist.rs new file mode 100644 index 0000000..5b2501f --- /dev/null +++ b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/rslist.rs @@ -0,0 +1,107 @@ +// Copyright (C) 2009 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_v11) + +#include "rs_graphics.rsh" + +float gDY; + +rs_font gFont; + +typedef struct ListAllocs_s { + rs_allocation text; + int result; +} ListAllocs; + +ListAllocs *gList; + +void init() { + gDY = 0.0f; +} + +int textPos = 0; + +int root(int launchID) { + + rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f); + rsgClearDepth(1.0f); + + textPos -= (int)gDY*2; + gDY *= 0.95; + + rsgFontColor(0.9f, 0.9f, 0.9f, 1.0f); + rsgBindFont(gFont); + + rs_allocation listAlloc; + rsSetObject(&listAlloc, rsGetAllocation(gList)); + int allocSize = rsAllocationGetDimX(listAlloc); + + int width = rsgGetWidth(); + int height = rsgGetHeight(); + + int itemHeight = 80; + int totalItemHeight = itemHeight * allocSize; + + /* Prevent scrolling above the top of the list */ + int firstItem = height - totalItemHeight; + if (firstItem < 0) { + firstItem = 0; + } + + /* Prevent scrolling past the last line of the list */ + int lastItem = -1 * (totalItemHeight - height); + if (lastItem > 0) { + lastItem = 0; + } + + if (textPos > firstItem) { + textPos = firstItem; + } + else if (textPos < lastItem) { + textPos = lastItem; + } + + int currentYPos = itemHeight + textPos; + + for(int i = 0; i < allocSize; i ++) { + if(currentYPos - itemHeight > height) { + break; + } + + if(currentYPos > 0) { + switch(gList[i].result) { + case 1: /* Passed */ + rsgFontColor(0.5f, 0.9f, 0.5f, 1.0f); + break; + case -1: /* Failed */ + rsgFontColor(0.9f, 0.5f, 0.5f, 1.0f); + break; + case 0: /* Still Testing */ + rsgFontColor(0.9f, 0.9f, 0.5f, 1.0f); + break; + default: /* Unknown */ + rsgFontColor(0.9f, 0.9f, 0.9f, 1.0f); + break; + } + rsgDrawRect(0, currentYPos - 1, width, currentYPos, 0); + rsgDrawText(gList[i].text, 30, currentYPos - 32); + } + currentYPos += itemHeight; + } + + return 10; +} diff --git a/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/rstime.rs b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/rstime.rs new file mode 100644 index 0000000..5e3e078 --- /dev/null +++ b/tests/RenderScriptTests/tests_v11/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 (only valid for PST localtime) + curTime = 1294438893; + rsLocaltime(&tm, &curTime); + + _RS_ASSERT(tm.tm_sec == 33); + _RS_ASSERT(tm.tm_min == 21); + _RS_ASSERT(tm.tm_hour == 14); + _RS_ASSERT(tm.tm_mday == 7); + _RS_ASSERT(tm.tm_mon == 0); + _RS_ASSERT(tm.tm_year == 111); + _RS_ASSERT(tm.tm_wday == 5); + _RS_ASSERT(tm.tm_yday == 6); + _RS_ASSERT(tm.tm_isdst == 0); + + return failed; +} + +void test_rstime(uint32_t index, int test_num) { + bool failed = false; + failed |= basic_test(index); + + if (failed) { + rsSendToClientBlocking(RS_MSG_TEST_FAILED); + rsDebug("rstime_test FAILED", -1); + } + else { + rsSendToClientBlocking(RS_MSG_TEST_PASSED); + rsDebug("rstime_test PASSED", 0); + } +} + diff --git a/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/rstypes.rs b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/rstypes.rs new file mode 100644 index 0000000..f3bf244 --- /dev/null +++ b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/rstypes.rs @@ -0,0 +1,79 @@ +#include "shared.rsh" +#include "rs_graphics.rsh" + +rs_element elementTest; +rs_type typeTest; +rs_allocation allocationTest; +rs_sampler samplerTest; +rs_script scriptTest; +rs_mesh meshTest; +rs_program_fragment program_fragmentTest; +rs_program_vertex program_vertexTest; +rs_program_raster program_rasterTest; +rs_program_store program_storeTest; +rs_font fontTest; + +rs_matrix4x4 matrix4x4Test; +rs_matrix3x3 matrix3x3Test; +rs_matrix2x2 matrix2x2Test; + +struct my_struct { + int i; + rs_font fontTestStruct; +}; + +static bool basic_test(uint32_t index) { + bool failed = false; + + rs_matrix4x4 matrix4x4TestLocal; + rs_matrix3x3 matrix3x3TestLocal; + rs_matrix2x2 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; + rs_mesh meshTestLocal; + rs_program_fragment program_fragmentTestLocal; + rs_program_vertex program_vertexTestLocal; + rs_program_raster program_rasterTestLocal; + rs_program_store program_storeTestLocal; + rs_font fontTestLocal; + + rs_font fontTestLocalArray[4]; + + rs_font fontTestLocalPreInit = fontTest; + + struct my_struct structTest; + + rsSetObject(&fontTestLocal, fontTest); + //allocationTestLocal = allocationTest; + + rsSetObject(&fontTest, fontTestLocal); + //allocationTest = allocationTestLocal; + + /*for (int i = 0; i < 4; i++) { + rsSetObject(&fontTestLocalArray[i], fontTestLocal); + }*/ + + /*rsSetObject(&fontTest, fontTestLocalArray[3]);*/ + + return failed; +} + +void test_rstypes(uint32_t index, int test_num) { + bool failed = false; + failed |= basic_test(index); + + if (failed) { + rsSendToClientBlocking(RS_MSG_TEST_FAILED); + rsDebug("rstypes_test FAILED", -1); + } + else { + rsSendToClientBlocking(RS_MSG_TEST_PASSED); + rsDebug("rstypes_test PASSED", 0); + } +} + diff --git a/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/shared.rsh b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/shared.rsh new file mode 100644 index 0000000..6d34481 --- /dev/null +++ b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/shared.rsh @@ -0,0 +1,38 @@ +#pragma version(1) + +#pragma rs java_package_name(com.android.rs.test_v11) + +typedef struct TestResult_s { + rs_allocation name; + bool pass; + float score; + int64_t time; +} TestResult; +//TestResult *g_results; + +static int64_t g_time; + +static void start(void) { + g_time = rsUptimeMillis(); +} + +static 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) + +/* These constants must match those in UnitTest.java */ +static const int RS_MSG_TEST_PASSED = 100; +static const int RS_MSG_TEST_FAILED = 101; + diff --git a/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/test_root.rs b/tests/RenderScriptTests/tests_v11/src/com/android/rs/test/test_root.rs new file mode 100644 index 0000000..6dc83ba --- /dev/null +++ b/tests/RenderScriptTests/tests_v11/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) + +#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/tests/RenderScriptTests/tests_v14/Android.mk b/tests/RenderScriptTests/tests_v14/Android.mk new file mode 100644 index 0000000..c4c3a37 --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/Android.mk @@ -0,0 +1,27 @@ +# +# Copyright (C) 2008 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := optional + +LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src) + +LOCAL_PACKAGE_NAME := RSTest_v14 +LOCAL_SDK_VERSION := 14 + +include $(BUILD_PACKAGE) diff --git a/tests/RenderScriptTests/tests_v14/AndroidManifest.xml b/tests/RenderScriptTests/tests_v14/AndroidManifest.xml new file mode 100644 index 0000000..1cd9bbd --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/AndroidManifest.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.rs.test_v14"> + <uses-sdk android:minSdkVersion="14" /> + <application + android:label="_RS_Test_v14" + android:icon="@drawable/test_pattern"> + <activity android:name="RSTest_v14" + 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/tests/RenderScriptTests/tests_v14/res/drawable-nodpi/test_pattern.png b/tests/RenderScriptTests/tests_v14/res/drawable-nodpi/test_pattern.png Binary files differnew file mode 100644 index 0000000..e7d1455 --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/res/drawable-nodpi/test_pattern.png diff --git a/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/RSTestCore.java b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/RSTestCore.java new file mode 100644 index 0000000..f1e81a4 --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/RSTestCore.java @@ -0,0 +1,210 @@ +/* + * Copyright (C) 2008-2011 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_v14; + +import android.content.Context; +import android.content.res.Resources; +import android.renderscript.*; +import android.util.Log; +import java.util.ArrayList; +import java.util.ListIterator; +import java.util.Timer; +import java.util.TimerTask; + + +public class RSTestCore { + int mWidth; + int mHeight; + Context mCtx; + + public RSTestCore(Context ctx) { + mCtx = ctx; + } + + private Resources mRes; + private RenderScriptGL mRS; + + private Font mFont; + ScriptField_ListAllocs_s mListAllocs; + int mLastX; + int mLastY; + private ScriptC_rslist mScript; + + private ArrayList<UnitTest> unitTests; + private ListIterator<UnitTest> test_iter; + private UnitTest activeTest; + private boolean stopTesting; + + /* Periodic timer for ensuring future tests get scheduled */ + private Timer mTimer; + public static final int RS_TIMER_PERIOD = 100; + + public void init(RenderScriptGL rs, Resources res, int width, int height) { + mRS = rs; + mRes = res; + mWidth = width; + mHeight = height; + stopTesting = false; + + mScript = new ScriptC_rslist(mRS, mRes, R.raw.rslist); + + unitTests = new ArrayList<UnitTest>(); + + unitTests.add(new UT_primitives(this, mRes, mCtx)); + unitTests.add(new UT_vector(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_math(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].result; + mListAllocs.set(listElem, i, false); + uta[i].setItem(listElem); + } + + mListAllocs.copyAll(); + + mScript.bind_gList(mListAllocs); + + mFont = Font.create(mRS, mRes, "serif", Font.Style.BOLD, 8); + mScript.set_gFont(mFont); + + mRS.bindRootScript(mScript); + + 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() { + 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(); + + if (mListAllocs != null && mScript != null && mRS != null) { + mListAllocs.copyAll(); + + mScript.bind_gList(mListAllocs); + mRS.bindRootScript(mScript); + } + } + + 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; + } + + } + + public void newTouchPosition(float x, float y, float pressure, int id) { + } + + public void onActionDown(int x, int y) { + mScript.set_gDY(0.0f); + mLastX = x; + mLastY = y; + refreshTestResults(); + } + + public void onActionMove(int x, int y) { + int dx = mLastX - x; + int dy = mLastY - y; + + if (Math.abs(dy) <= 2) { + dy = 0; + } + + mScript.set_gDY(dy); + + mLastX = x; + mLastY = y; + refreshTestResults(); + } +} diff --git a/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/RSTestView.java b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/RSTestView.java new file mode 100644 index 0000000..40192e4 --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/RSTestView.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2008 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_v14; + +import java.io.Writer; +import java.util.ArrayList; +import java.util.concurrent.Semaphore; + +import android.renderscript.RSSurfaceView; +import android.renderscript.RenderScript; +import android.renderscript.RenderScriptGL; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.os.Handler; +import android.os.Message; +import android.util.AttributeSet; +import android.util.Log; +import android.view.Surface; +import android.view.SurfaceHolder; +import android.view.SurfaceView; +import android.view.KeyEvent; +import android.view.MotionEvent; + +public class RSTestView extends RSSurfaceView { + + private Context mCtx; + + public RSTestView(Context context) { + super(context); + mCtx = context; + //setFocusable(true); + } + + private RenderScriptGL mRS; + private RSTestCore mRender; + + public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { + super.surfaceChanged(holder, format, w, h); + if (mRS == null) { + RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig(); + mRS = createRenderScriptGL(sc); + mRS.setSurface(holder, w, h); + mRender = new RSTestCore(mCtx); + mRender.init(mRS, getResources(), w, h); + } + } + + @Override + protected void onDetachedFromWindow() { + if(mRS != null) { + mRender.cleanup(); + mRS = null; + destroyRenderScriptGL(); + } + } + + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) + { + return super.onKeyDown(keyCode, event); + } + + @Override + public boolean onTouchEvent(MotionEvent ev) + { + boolean ret = false; + int act = ev.getAction(); + if (act == ev.ACTION_DOWN) { + mRender.onActionDown((int)ev.getX(), (int)ev.getY()); + ret = true; + } + else if (act == ev.ACTION_MOVE) { + mRender.onActionMove((int)ev.getX(), (int)ev.getY()); + ret = true; + } + + return ret; + } +} diff --git a/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/RSTest_v14.java b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/RSTest_v14.java new file mode 100644 index 0000000..da09691 --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/RSTest_v14.java @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2008 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_v14; + +import android.renderscript.RSSurfaceView; +import android.renderscript.RenderScript; + +import android.app.Activity; +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 java.lang.Runtime; + +public class RSTest_v14 extends Activity { + //EventListener mListener = new EventListener(); + + private static final String LOG_TAG = "RSTest_v14"; + private static final boolean DEBUG = false; + private static final boolean LOG_ENABLED = false; + + private RSTestView mView; + + // get the current looper (from your Activity UI thread for instance + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + + // Create our Preview view and set it as the content of our + // Activity + mView = new RSTestView(this); + setContentView(mView); + } + + @Override + protected void onResume() { + // Ideally a game should implement onResume() and onPause() + // to take appropriate action when the activity loses focus + super.onResume(); + mView.resume(); + } + + @Override + protected void onPause() { + // Ideally a game should implement onResume() and onPause() + // to take appropriate action when the activity loses focus + super.onPause(); + mView.pause(); + } + + @Override + protected void onStop() { + // Actually kill the app if we are stopping. We don't want to + // continue/resume this test ever. It should always start fresh. + finish(); + super.onStop(); + } + + static void log(String message) { + if (LOG_ENABLED) { + Log.v(LOG_TAG, message); + } + } + + +} diff --git a/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_alloc.java b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_alloc.java new file mode 100644 index 0000000..da42b29 --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_alloc.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2011 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_v14; + +import android.content.Context; +import android.content.res.Resources; +import android.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); + + 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, mRes, R.raw.alloc); + pRS.setMessageHandler(mRsMessage); + initializeGlobals(pRS, s); + s.invoke_alloc_test(); + pRS.finish(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_foreach.java b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_foreach.java new file mode 100644 index 0000000..aeb5bb7 --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_foreach.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2011 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_v14; + +import android.content.Context; +import android.content.res.Resources; +import android.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.bind_a(A); + + return; + } + + public void run() { + RenderScript pRS = RenderScript.create(mCtx); + ScriptC_foreach s = new ScriptC_foreach(pRS, mRes, R.raw.foreach); + pRS.setMessageHandler(mRsMessage); + initializeGlobals(pRS, s); + s.forEach_root(A); + s.invoke_foreach_test(); + pRS.finish(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_fp_mad.java b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_fp_mad.java new file mode 100644 index 0000000..239496a --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_fp_mad.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2010 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_v14; + +import android.content.Context; +import android.content.res.Resources; +import android.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, mRes, R.raw.fp_mad); + pRS.setMessageHandler(mRsMessage); + s.invoke_fp_mad_test(0, 0); + pRS.finish(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_math.java b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_math.java new file mode 100644 index 0000000..7b135c4 --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_math.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2010 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_v14; + +import android.content.Context; +import android.content.res.Resources; +import android.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, mRes, R.raw.math); + pRS.setMessageHandler(mRsMessage); + s.invoke_math_test(0, 0); + pRS.finish(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_primitives.java b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_primitives.java new file mode 100644 index 0000000..d3c56f3 --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_primitives.java @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2010 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_v14; + +import android.content.Context; +import android.content.res.Resources; +import android.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, mRes, R.raw.primitives); + pRS.setMessageHandler(mRsMessage); + if (!initializeGlobals(s)) { + // initializeGlobals failed + result = -1; + } else { + s.invoke_primitives_test(0, 0); + pRS.finish(); + waitForMessage(); + } + pRS.destroy(); + } +} diff --git a/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_refcount.java b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_refcount.java new file mode 100644 index 0000000..05a516b --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_refcount.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2011 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_v14; + +import android.content.Context; +import android.content.res.Resources; +import android.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, mRes, R.raw.refcount); + initializeGlobals(pRS, s); + s.invoke_refcount_test(); + pRS.finish(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_rsdebug.java b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_rsdebug.java new file mode 100644 index 0000000..95e92ee --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_rsdebug.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2010 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_v14; + +import android.content.Context; +import android.content.res.Resources; +import android.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, mRes, R.raw.rsdebug); + pRS.setMessageHandler(mRsMessage); + s.invoke_test_rsdebug(0, 0); + pRS.finish(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_rstime.java b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_rstime.java new file mode 100644 index 0000000..a72ede9 --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_rstime.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2010 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_v14; + +import android.content.Context; +import android.content.res.Resources; +import android.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, mRes, R.raw.rstime); + pRS.setMessageHandler(mRsMessage); + s.invoke_test_rstime(0, 0); + pRS.finish(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_rstypes.java b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_rstypes.java new file mode 100644 index 0000000..ab96867 --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_rstypes.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2010 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_v14; + +import android.content.Context; +import android.content.res.Resources; +import android.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, mRes, R.raw.rstypes); + pRS.setMessageHandler(mRsMessage); + s.invoke_test_rstypes(0, 0); + pRS.finish(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_vector.java b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_vector.java new file mode 100644 index 0000000..657413e --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UT_vector.java @@ -0,0 +1,318 @@ +/* + * Copyright (C) 2011 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_v14; + +import android.content.Context; +import android.content.res.Resources; +import android.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, mRes, R.raw.vector); + pRS.setMessageHandler(mRsMessage); + if (!initializeGlobals(s)) { + result = -1; + } else { + s.invoke_vector_test(); + pRS.finish(); + waitForMessage(); + } + pRS.destroy(); + } +} diff --git a/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UnitTest.java b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UnitTest.java new file mode 100644 index 0000000..558a252 --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/UnitTest.java @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2010 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_v14; +import android.content.Context; +import android.util.Log; +import android.renderscript.RenderScript.RSMessageHandler; + +public class UnitTest extends Thread { + public String name; + public 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) { + result = -1; + Log.e(name, message + " FAILED"); + } + } + + protected 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_v14.log("Unit test got unexpected message"); + return; + } + } + + updateUI(); + } + }; + + public void waitForMessage() { + while (!msgHandled) { + yield(); + } + } + + 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/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/alloc.rs b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/alloc.rs new file mode 100644 index 0000000..3116e5a --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/alloc.rs @@ -0,0 +1,94 @@ +#include "shared.rsh" + +int *a; +int dimX; +int dimY; +int dimZ; + +rs_allocation aFaces; +rs_allocation aLOD; +rs_allocation aFacesLOD; + +static bool test_alloc_dims() { + bool failed = false; + int i, j; + + for (j = 0; j < dimY; j++) { + for (i = 0; i < dimX; i++) { + a[i + j * dimX] = i + j * dimX; + } + } + + rs_allocation alloc = rsGetAllocation(a); + _RS_ASSERT(rsAllocationGetDimX(alloc) == dimX); + _RS_ASSERT(rsAllocationGetDimY(alloc) == dimY); + _RS_ASSERT(rsAllocationGetDimZ(alloc) == 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(alloc, i, j); + int val = *(const int *)p; + _RS_ASSERT(val == (i + j * dimX)); + } + } + + // Test 1D addressing + for (i = 0; i < dimX * dimY; i++) { + rsDebug("Verifying ", i); + const void *p = rsGetElementAt(alloc, 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(alloc, 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/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/foreach.rs b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/foreach.rs new file mode 100644 index 0000000..3ba3eef --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/foreach.rs @@ -0,0 +1,42 @@ +#include "shared.rsh" + +int *a; +int dimX; +int dimY; + +void root(int *out, uint32_t x, uint32_t y) { + *out = x + y * dimX; +} + +static bool test_foreach_output() { + bool failed = false; + int i, j; + + for (j = 0; j < dimY; j++) { + for (i = 0; i < dimX; i++) { + _RS_ASSERT(a[i + j * dimX] == (i + j * dimX)); + } + } + + if (failed) { + rsDebug("test_foreach_output FAILED", 0); + } + else { + rsDebug("test_foreach_output PASSED", 0); + } + + return failed; +} + +void foreach_test() { + bool failed = false; + failed |= test_foreach_output(); + + if (failed) { + rsSendToClientBlocking(RS_MSG_TEST_FAILED); + } + else { + rsSendToClientBlocking(RS_MSG_TEST_PASSED); + } +} + diff --git a/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/fp_mad.rs b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/fp_mad.rs new file mode 100644 index 0000000..b6f2b2a --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/fp_mad.rs @@ -0,0 +1,174 @@ +#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(); + + float total = 0; + // 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(); + + float total = 0; + // 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(); + + float total = 0; + // 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(); + + float total = 0; + // 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(); + + float total = 0; + // 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(); + + float total = 0; + // Do ~100 M ops + for (int ct=0; ct < 1000 * 100 /4; ct++) { + for (int i=0; i < (1000); i++) { + data_f4[i] = clamp(data_f4[i], -1.f, 1.f); + } + } + + float time = end(index); + rsDebug("fp_clamp4 M ops", 100.f / time); +} + +void fp_mad_test(uint32_t index, int test_num) { + int x; + for (x=0; x < 1025; x++) { + data_f1[x] = (x & 0xf) * 0.1f; + data_f4[x].x = (x & 0xf) * 0.1f; + data_f4[x].y = (x & 0xf0) * 0.1f; + data_f4[x].z = (x & 0x33) * 0.1f; + data_f4[x].w = (x & 0x77) * 0.1f; + } + + test_mad4(index); + test_mad(index); + + for (x=0; x < 1025; x++) { + data_f1[x] = (x & 0xf) * 0.1f + 1.f; + data_f4[x].x = (x & 0xf) * 0.1f + 1.f; + data_f4[x].y = (x & 0xf0) * 0.1f + 1.f; + data_f4[x].z = (x & 0x33) * 0.1f + 1.f; + data_f4[x].w = (x & 0x77) * 0.1f + 1.f; + } + + test_norm(index); + test_sincos4(index); + test_sincos(index); + test_clamp4(index); + test_clamp(index); + + // TODO Actually verify test result accuracy + rsDebug("fp_mad_test PASSED", 0); + rsSendToClientBlocking(RS_MSG_TEST_PASSED); +} + + diff --git a/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/math.rs b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/math.rs new file mode 100644 index 0000000..e6b37f6 --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/math.rs @@ -0,0 +1,462 @@ +#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; +} + +#define INIT_PREFIX_TYPE(prefix, type) \ +prefix##_##type##_1 = 1; \ +prefix##_##type##_2.x = 1; \ +prefix##_##type##_2.y = 1; \ +prefix##_##type##_3.x = 1; \ +prefix##_##type##_3.y = 1; \ +prefix##_##type##_3.z = 1; \ +prefix##_##type##_4.x = 1; \ +prefix##_##type##_4.y = 1; \ +prefix##_##type##_4.z = 1; \ +prefix##_##type##_4.w = 1; + +#define INIT_TYPE(type) \ +INIT_PREFIX_TYPE(src1, type) \ +INIT_PREFIX_TYPE(src2, type) \ +INIT_PREFIX_TYPE(res, type) + +#define INIT_ALL \ +INIT_TYPE(c); \ +INIT_TYPE(uc); \ +INIT_TYPE(s); \ +INIT_TYPE(us); \ +INIT_TYPE(i); \ +INIT_TYPE(ui); + +void math_test(uint32_t index, int test_num) { + bool failed = false; + INIT_ALL; + failed |= test_convert(); + failed |= test_fp_math(index); + failed |= test_int_math(index); + failed |= test_basic_operators(); + + if (failed) { + rsSendToClientBlocking(RS_MSG_TEST_FAILED); + } + else { + rsSendToClientBlocking(RS_MSG_TEST_PASSED); + } +} + diff --git a/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/math.rs.bak b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/math.rs.bak new file mode 100644 index 0000000..ad802ca --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/math.rs.bak @@ -0,0 +1,423 @@ +#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 "3", i++); \ +res_##type##_3 = src1_##type##_3 op src2_##type##_3; \ + +#define TEST_INT_OP(op) \ +TEST_INT_OP_TYPE(op, c) \ +TEST_INT_OP_TYPE(op, uc) \ + +#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; + rsDebug("Here ", 1); + res_uc_3 = src1_uc_3 / src2_uc_3; + rsDebug("Here ", 2); + failed |= test_basic_operators(); + rsDebug("Here ", 3); + + if (failed) { + rsSendToClientBlocking(RS_MSG_TEST_FAILED); + } + else { + rsSendToClientBlocking(RS_MSG_TEST_PASSED); + } +} + diff --git a/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/math.rs.orig b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/math.rs.orig new file mode 100644 index 0000000..aae29a4 --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/math.rs.orig @@ -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/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/primitives.rs b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/primitives.rs new file mode 100644 index 0000000..ce451da --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/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/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/refcount.rs b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/refcount.rs new file mode 100644 index 0000000..4ea70e2 --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/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/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/rsdebug.rs b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/rsdebug.rs new file mode 100644 index 0000000..f7942a5 --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/rsdebug.rs @@ -0,0 +1,56 @@ +#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 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("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/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/rslist.rs b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/rslist.rs new file mode 100644 index 0000000..b3d8b9e --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/rslist.rs @@ -0,0 +1,107 @@ +// Copyright (C) 2009 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_v14) + +#include "rs_graphics.rsh" + +float gDY; + +rs_font gFont; + +typedef struct ListAllocs_s { + rs_allocation text; + int result; +} ListAllocs; + +ListAllocs *gList; + +void init() { + gDY = 0.0f; +} + +int textPos = 0; + +int root(void) { + + rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f); + rsgClearDepth(1.0f); + + textPos -= (int)gDY*2; + gDY *= 0.95; + + rsgFontColor(0.9f, 0.9f, 0.9f, 1.0f); + rsgBindFont(gFont); + + rs_allocation listAlloc; + listAlloc = rsGetAllocation(gList); + int allocSize = rsAllocationGetDimX(listAlloc); + + int width = rsgGetWidth(); + int height = rsgGetHeight(); + + int itemHeight = 80; + int totalItemHeight = itemHeight * allocSize; + + /* Prevent scrolling above the top of the list */ + int firstItem = height - totalItemHeight; + if (firstItem < 0) { + firstItem = 0; + } + + /* Prevent scrolling past the last line of the list */ + int lastItem = -1 * (totalItemHeight - height); + if (lastItem > 0) { + lastItem = 0; + } + + if (textPos > firstItem) { + textPos = firstItem; + } + else if (textPos < lastItem) { + textPos = lastItem; + } + + int currentYPos = itemHeight + textPos; + + for(int i = 0; i < allocSize; i ++) { + if(currentYPos - itemHeight > height) { + break; + } + + if(currentYPos > 0) { + switch(gList[i].result) { + case 1: /* Passed */ + rsgFontColor(0.5f, 0.9f, 0.5f, 1.0f); + break; + case -1: /* Failed */ + rsgFontColor(0.9f, 0.5f, 0.5f, 1.0f); + break; + case 0: /* Still Testing */ + rsgFontColor(0.9f, 0.9f, 0.5f, 1.0f); + break; + default: /* Unknown */ + rsgFontColor(0.9f, 0.9f, 0.9f, 1.0f); + break; + } + rsgDrawRect(0, currentYPos - 1, width, currentYPos, 0); + rsgDrawText(gList[i].text, 30, currentYPos - 32); + } + currentYPos += itemHeight; + } + + return 10; +} diff --git a/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/rstime.rs b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/rstime.rs new file mode 100644 index 0000000..5e3e078 --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/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 (only valid for PST localtime) + curTime = 1294438893; + rsLocaltime(&tm, &curTime); + + _RS_ASSERT(tm.tm_sec == 33); + _RS_ASSERT(tm.tm_min == 21); + _RS_ASSERT(tm.tm_hour == 14); + _RS_ASSERT(tm.tm_mday == 7); + _RS_ASSERT(tm.tm_mon == 0); + _RS_ASSERT(tm.tm_year == 111); + _RS_ASSERT(tm.tm_wday == 5); + _RS_ASSERT(tm.tm_yday == 6); + _RS_ASSERT(tm.tm_isdst == 0); + + return failed; +} + +void test_rstime(uint32_t index, int test_num) { + bool failed = false; + failed |= basic_test(index); + + if (failed) { + rsSendToClientBlocking(RS_MSG_TEST_FAILED); + rsDebug("rstime_test FAILED", -1); + } + else { + rsSendToClientBlocking(RS_MSG_TEST_PASSED); + rsDebug("rstime_test PASSED", 0); + } +} + diff --git a/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/rstypes.rs b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/rstypes.rs new file mode 100644 index 0000000..22d9c13 --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/rstypes.rs @@ -0,0 +1,79 @@ +#include "shared.rsh" +#include "rs_graphics.rsh" + +rs_element elementTest; +rs_type typeTest; +rs_allocation allocationTest; +rs_sampler samplerTest; +rs_script scriptTest; +rs_mesh meshTest; +rs_program_fragment program_fragmentTest; +rs_program_vertex program_vertexTest; +rs_program_raster program_rasterTest; +rs_program_store program_storeTest; +rs_font fontTest; + +rs_matrix4x4 matrix4x4Test; +rs_matrix3x3 matrix3x3Test; +rs_matrix2x2 matrix2x2Test; + +struct my_struct { + int i; + rs_font fontTestStruct; +}; + +static bool basic_test(uint32_t index) { + bool failed = false; + + rs_matrix4x4 matrix4x4TestLocal; + rs_matrix3x3 matrix3x3TestLocal; + rs_matrix2x2 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; + rs_mesh meshTestLocal; + rs_program_fragment program_fragmentTestLocal; + rs_program_vertex program_vertexTestLocal; + rs_program_raster program_rasterTestLocal; + rs_program_store program_storeTestLocal; + rs_font fontTestLocal; + + rs_font fontTestLocalArray[4]; + + rs_font fontTestLocalPreInit = fontTest; + + struct my_struct structTest; + + fontTestLocal = fontTest; + //allocationTestLocal = allocationTest; + + fontTest = fontTestLocal; + //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/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/shared.rsh b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/shared.rsh new file mode 100644 index 0000000..4a7151f --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/shared.rsh @@ -0,0 +1,38 @@ +#pragma version(1) + +#pragma rs java_package_name(com.android.rs.test_v14) + +typedef struct TestResult_s { + rs_allocation name; + bool pass; + float score; + int64_t time; +} TestResult; +//TestResult *g_results; + +static int64_t g_time; + +static void start(void) { + g_time = rsUptimeMillis(); +} + +static 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) + +/* These constants must match those in UnitTest.java */ +static const int RS_MSG_TEST_PASSED = 100; +static const int RS_MSG_TEST_FAILED = 101; + diff --git a/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/test_root.rs b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/test_root.rs new file mode 100644 index 0000000..88fe34a --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/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_v14) + +#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/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/vector.rs b/tests/RenderScriptTests/tests_v14/src/com/android/rs/test/vector.rs new file mode 100644 index 0000000..0430a2f --- /dev/null +++ b/tests/RenderScriptTests/tests_v14/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); + } +} + |