summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java3
-rw-r--r--tests/ActivityTests/src/com/google/android/test/activity/SingleUserProvider.java4
-rw-r--r--tests/ActivityTests/src/com/google/android/test/activity/SingleUserReceiver.java3
-rw-r--r--tests/ActivityTests/src/com/google/android/test/activity/UserTarget.java3
-rw-r--r--tests/MemoryUsage/Android.mk16
-rw-r--r--tests/MemoryUsage/AndroidManifest.xml12
-rw-r--r--tests/MemoryUsage/src/com/android/tests/memoryusage/MemoryUsageInstrumentation.java38
-rw-r--r--tests/MemoryUsage/src/com/android/tests/memoryusage/MemoryUsageTest.java235
-rw-r--r--tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/BallsView.java2
-rw-r--r--tests/RenderScriptTests/ComputeBenchmark/Android.mk27
-rw-r--r--tests/RenderScriptTests/ComputeBenchmark/AndroidManifest.xml30
-rw-r--r--tests/RenderScriptTests/ComputeBenchmark/res/layout/main.xml31
-rw-r--r--tests/RenderScriptTests/ComputeBenchmark/src/com/example/android/rs/computebench/Benchmark.java39
-rw-r--r--tests/RenderScriptTests/ComputeBenchmark/src/com/example/android/rs/computebench/ComputeBench.java37
-rw-r--r--tests/RenderScriptTests/ComputeBenchmark/src/com/example/android/rs/computebench/compute_benchmark.rs408
-rw-r--r--tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/Fisheye.java40
-rw-r--r--tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java40
-rw-r--r--tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye.rsh55
-rw-r--r--tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx.rsh58
-rw-r--r--tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx_full.rs21
-rw-r--r--tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx_relaxed.rs22
-rw-r--r--tests/RenderScriptTests/ImageProcessing2/Android.mk4
-rw-r--r--tests/RenderScriptTests/ImageProcessing2/AndroidManifest.xml5
23 files changed, 1074 insertions, 59 deletions
diff --git a/tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java b/tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java
index 0577dbb..9599b19 100644
--- a/tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java
+++ b/tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java
@@ -30,6 +30,7 @@ import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
+import android.os.UserHandle;
import android.graphics.Bitmap;
import android.widget.ImageView;
import android.widget.LinearLayout;
@@ -187,7 +188,7 @@ public class ActivityTestMain extends Activity {
menu.add("Send to user 1!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(ActivityTestMain.this, UserTarget.class);
- sendOrderedBroadcastToUser(intent, 1, new BroadcastResultReceiver(),
+ sendOrderedBroadcastAsUser(intent, new UserHandle(1), new BroadcastResultReceiver(),
null, Activity.RESULT_OK, null, null);
return true;
}
diff --git a/tests/ActivityTests/src/com/google/android/test/activity/SingleUserProvider.java b/tests/ActivityTests/src/com/google/android/test/activity/SingleUserProvider.java
index 83785e4..1e7b8f4 100644
--- a/tests/ActivityTests/src/com/google/android/test/activity/SingleUserProvider.java
+++ b/tests/ActivityTests/src/com/google/android/test/activity/SingleUserProvider.java
@@ -21,7 +21,7 @@ import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
-import android.os.Process;
+import android.os.UserHandle;
public class SingleUserProvider extends ContentProvider {
static final String AUTHORITY = "com.google.android.test.activity.single_user";
@@ -60,7 +60,7 @@ public class SingleUserProvider extends ContentProvider {
@Override
public Bundle call(String method, String arg, Bundle extras) {
Bundle res = new Bundle();
- res.putInt("user", Process.myUserHandle());
+ res.putInt("user", UserHandle.myUserId());
return res;
}
}
diff --git a/tests/ActivityTests/src/com/google/android/test/activity/SingleUserReceiver.java b/tests/ActivityTests/src/com/google/android/test/activity/SingleUserReceiver.java
index 9295cf4..8afa478 100644
--- a/tests/ActivityTests/src/com/google/android/test/activity/SingleUserReceiver.java
+++ b/tests/ActivityTests/src/com/google/android/test/activity/SingleUserReceiver.java
@@ -21,12 +21,13 @@ import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Process;
+import android.os.UserHandle;
public class SingleUserReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Bundle res = getResultExtras(true);
- res.putInt("user", Process.myUserHandle());
+ res.putInt("user", UserHandle.myUserId());
setResultExtras(res);
}
}
diff --git a/tests/ActivityTests/src/com/google/android/test/activity/UserTarget.java b/tests/ActivityTests/src/com/google/android/test/activity/UserTarget.java
index 9c6a9f1..47539a1 100644
--- a/tests/ActivityTests/src/com/google/android/test/activity/UserTarget.java
+++ b/tests/ActivityTests/src/com/google/android/test/activity/UserTarget.java
@@ -21,6 +21,7 @@ import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Process;
+import android.os.UserHandle;
import android.util.Log;
public class UserTarget extends BroadcastReceiver {
@@ -28,7 +29,7 @@ public class UserTarget extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Log.i("ActivityTest", "Received: " + intent);
Bundle res = getResultExtras(true);
- res.putInt("user", Process.myUserHandle());
+ res.putInt("user", UserHandle.myUserId());
setResultExtras(res);
}
}
diff --git a/tests/MemoryUsage/Android.mk b/tests/MemoryUsage/Android.mk
new file mode 100644
index 0000000..e7bfb4f
--- /dev/null
+++ b/tests/MemoryUsage/Android.mk
@@ -0,0 +1,16 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := tests
+
+# Only compile source java files in this apk.
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := MemoryUsage
+
+LOCAL_SDK_VERSION := 7
+
+include $(BUILD_PACKAGE)
+
+# Use the following include to make our test apk.
+include $(call all-makefiles-under,$(LOCAL_PATH)) \ No newline at end of file
diff --git a/tests/MemoryUsage/AndroidManifest.xml b/tests/MemoryUsage/AndroidManifest.xml
new file mode 100644
index 0000000..3932e5b
--- /dev/null
+++ b/tests/MemoryUsage/AndroidManifest.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.tests.memoryusage">
+ <instrumentation android:label="Memory usage instrumentation"
+ android:name="com.android.tests.memoryusage.MemoryUsageInstrumentation"
+ android:targetPackage="com.android.tests.memoryusage" />
+
+ <application android:label="Memory Usage Test">
+ <uses-library android:name="android.test.runner" />
+ </application>
+</manifest> \ No newline at end of file
diff --git a/tests/MemoryUsage/src/com/android/tests/memoryusage/MemoryUsageInstrumentation.java b/tests/MemoryUsage/src/com/android/tests/memoryusage/MemoryUsageInstrumentation.java
new file mode 100644
index 0000000..ed6d7e6
--- /dev/null
+++ b/tests/MemoryUsage/src/com/android/tests/memoryusage/MemoryUsageInstrumentation.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.tests.memoryusage;
+
+import android.os.Bundle;
+import android.test.InstrumentationTestRunner;
+
+/**
+ * InstrumentationTestRunner for use with the {@link MemoryUsageTest}.
+ */
+public class MemoryUsageInstrumentation extends InstrumentationTestRunner {
+
+ private Bundle arguments;
+
+ @Override
+ public void onCreate(Bundle arguments) {
+ this.arguments = arguments;
+ super.onCreate(arguments);
+ }
+
+ public Bundle getBundle() {
+ return arguments;
+ }
+
+}
diff --git a/tests/MemoryUsage/src/com/android/tests/memoryusage/MemoryUsageTest.java b/tests/MemoryUsage/src/com/android/tests/memoryusage/MemoryUsageTest.java
new file mode 100644
index 0000000..f26edc6
--- /dev/null
+++ b/tests/MemoryUsage/src/com/android/tests/memoryusage/MemoryUsageTest.java
@@ -0,0 +1,235 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.tests.memoryusage;
+
+import android.app.ActivityManager;
+import android.app.ActivityManager.ProcessErrorStateInfo;
+import android.app.ActivityManager.RunningAppProcessInfo;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.ResolveInfo;
+import android.os.Bundle;
+import android.os.Debug.MemoryInfo;
+import android.test.InstrumentationTestCase;
+import android.util.Log;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * This test is intended to measure the amount of memory applications use when
+ * they start. Names of the applications are passed in command line, and the
+ * test starts each application, waits until its memory usage is stabilized and
+ * reports the total PSS in kilobytes of each processes.
+ * The instrumentation expects the following key to be passed on the command line:
+ * apps - A list of applications to start and their corresponding result keys
+ * in the following format:
+ * -e apps <app name>^<result key>|<app name>^<result key>
+ */
+public class MemoryUsageTest extends InstrumentationTestCase {
+
+ private static final int SLEEP_TIME = 1000;
+ private static final int THRESHOLD = 1024;
+ private static final int MAX_ITERATIONS = 10;
+ private static final int MIN_ITERATIONS = 4;
+
+ private static final String TAG = "MemoryUsageInstrumentation";
+ private static final String KEY_APPS = "apps";
+
+ private Map<String, Intent> nameToIntent;
+ private Map<String, String> nameToProcess;
+ private Map<String, String> nameToResultKey;
+
+ public void testMemory() {
+ MemoryUsageInstrumentation instrumentation =
+ (MemoryUsageInstrumentation) getInstrumentation();
+ Bundle args = instrumentation.getBundle();
+
+ createMappings();
+ parseArgs(args);
+
+ Bundle results = new Bundle();
+ for (String app : nameToResultKey.keySet()) {
+ String processName;
+ try {
+ processName = startApp(app);
+ measureMemory(app, processName, results);
+ } catch (NameNotFoundException e) {
+ Log.i(TAG, "Application " + app + " not found");
+ }
+
+ }
+ instrumentation.sendStatus(0, results);
+ }
+
+ private void parseArgs(Bundle args) {
+ nameToResultKey = new HashMap<String, String>();
+ String appList = args.getString(KEY_APPS);
+
+ if (appList == null)
+ return;
+
+ String appNames[] = appList.split("\\|");
+ for (String pair : appNames) {
+ String[] parts = pair.split("\\^");
+ if (parts.length != 2) {
+ Log.e(TAG, "The apps key is incorectly formatted");
+ fail();
+ }
+
+ nameToResultKey.put(parts[0], parts[1]);
+ }
+ }
+
+ private void createMappings() {
+ nameToIntent = new HashMap<String, Intent>();
+ nameToProcess = new HashMap<String, String>();
+
+ PackageManager pm = getInstrumentation().getContext()
+ .getPackageManager();
+ Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
+ intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
+ List<ResolveInfo> ris = pm.queryIntentActivities(intentToResolve, 0);
+ if (ris == null || ris.isEmpty()) {
+ Log.i(TAG, "Could not find any apps");
+ } else {
+ for (ResolveInfo ri : ris) {
+ Log.i(TAG, "Name: " + ri.loadLabel(pm).toString()
+ + " package: " + ri.activityInfo.packageName
+ + " name: " + ri.activityInfo.name);
+ Intent startIntent = new Intent(intentToResolve);
+ startIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+ | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
+ startIntent.setClassName(ri.activityInfo.packageName,
+ ri.activityInfo.name);
+ nameToIntent.put(ri.loadLabel(pm).toString(), startIntent);
+ nameToProcess.put(ri.loadLabel(pm).toString(),
+ ri.activityInfo.processName);
+ }
+ }
+ }
+
+ private String startApp(String appName) throws NameNotFoundException {
+ Log.i(TAG, "Starting " + appName);
+
+ if (!nameToProcess.containsKey(appName))
+ throw new NameNotFoundException("Could not find: " + appName);
+
+ String process = nameToProcess.get(appName);
+ Intent startIntent = nameToIntent.get(appName);
+ getInstrumentation().getContext().startActivity(startIntent);
+ return process;
+ }
+
+ private void measureMemory(String appName, String processName,
+ Bundle results) {
+ List<Integer> pssData = new ArrayList<Integer>();
+ int pss = 0;
+ int iteration = 0;
+ while (iteration < MAX_ITERATIONS) {
+ sleep();
+ pss = getPss(processName);
+ Log.i(TAG, appName + "=" + pss);
+ if (pss < 0) {
+ reportError(appName, processName, results);
+ return;
+ }
+ pssData.add(pss);
+ if (iteration >= MIN_ITERATIONS && stabilized(pssData)) {
+ results.putInt(nameToResultKey.get(appName), pss);
+ return;
+ }
+ iteration++;
+ }
+
+ Log.w(TAG, appName + " memory usage did not stabilize");
+ results.putInt(appName, average(pssData));
+ }
+
+ private int average(List<Integer> pssData) {
+ int sum = 0;
+ for (int sample : pssData) {
+ sum += sample;
+ }
+
+ return sum / pssData.size();
+ }
+
+ private boolean stabilized(List<Integer> pssData) {
+ if (pssData.size() < 3)
+ return false;
+ int diff1 = Math.abs(pssData.get(pssData.size() - 1) - pssData.get(pssData.size() - 2));
+ int diff2 = Math.abs(pssData.get(pssData.size() - 2) - pssData.get(pssData.size() - 3));
+
+ Log.i(TAG, "diff1=" + diff1 + " diff2=" + diff2);
+
+ return (diff1 + diff2) < THRESHOLD;
+ }
+
+ private void sleep() {
+ try {
+ Thread.sleep(SLEEP_TIME);
+ } catch (InterruptedException e) {
+ // ignore
+ }
+ }
+
+ private void reportError(String appName, String processName, Bundle results) {
+ ActivityManager am = (ActivityManager) getInstrumentation()
+ .getContext().getSystemService(Context.ACTIVITY_SERVICE);
+ List<ProcessErrorStateInfo> crashes = am.getProcessesInErrorState();
+ if (crashes != null) {
+ for (ProcessErrorStateInfo crash : crashes) {
+ if (!crash.processName.equals(processName))
+ continue;
+
+ Log.w(TAG, appName + " crashed: " + crash.shortMsg);
+ results.putString(nameToResultKey.get(appName), crash.shortMsg);
+ return;
+ }
+ }
+
+ results.putString(nameToResultKey.get(appName),
+ "Crashed for unknown reason");
+ Log.w(TAG, appName
+ + " not found in process list, most likely it is crashed");
+ }
+
+ private int getPss(String processName) {
+ ActivityManager am = (ActivityManager) getInstrumentation()
+ .getContext().getSystemService(Context.ACTIVITY_SERVICE);
+ List<RunningAppProcessInfo> apps = am.getRunningAppProcesses();
+
+ for (RunningAppProcessInfo proc : apps) {
+ if (!proc.processName.equals(processName)) {
+ continue;
+ }
+
+ int[] pids = {
+ proc.pid };
+
+ MemoryInfo meminfo = am.getProcessMemoryInfo(pids)[0];
+ return meminfo.getTotalPss();
+
+ }
+ return -1;
+ }
+}
diff --git a/tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/BallsView.java b/tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/BallsView.java
index b3b3756..041782d 100644
--- a/tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/BallsView.java
+++ b/tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/BallsView.java
@@ -105,7 +105,7 @@ public class BallsView extends RSSurfaceView {
}
void setAccel(float x, float y, float z) {
- if (mRender == null) {
+ if ((mRender == null) || (mRS == null)) {
return;
}
mRender.setAccel(x, -y);
diff --git a/tests/RenderScriptTests/ComputeBenchmark/Android.mk b/tests/RenderScriptTests/ComputeBenchmark/Android.mk
new file mode 100644
index 0000000..8d47e89
--- /dev/null
+++ b/tests/RenderScriptTests/ComputeBenchmark/Android.mk
@@ -0,0 +1,27 @@
+#
+# Copyright (C) 2012 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := tests
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src) \
+ $(call all-renderscript-files-under, src)
+
+LOCAL_PACKAGE_NAME := RsComputeBenchmark
+
+include $(BUILD_PACKAGE)
diff --git a/tests/RenderScriptTests/ComputeBenchmark/AndroidManifest.xml b/tests/RenderScriptTests/ComputeBenchmark/AndroidManifest.xml
new file mode 100644
index 0000000..c8fcc17
--- /dev/null
+++ b/tests/RenderScriptTests/ComputeBenchmark/AndroidManifest.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.rs.computebench">
+
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <uses-sdk android:minSdkVersion="17" />
+ <application android:label="_RS_Compute_Bench">
+ <activity android:name="ComputeBench">
+ <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/ComputeBenchmark/res/layout/main.xml b/tests/RenderScriptTests/ComputeBenchmark/res/layout/main.xml
new file mode 100644
index 0000000..9e9dab8
--- /dev/null
+++ b/tests/RenderScriptTests/ComputeBenchmark/res/layout/main.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <ImageView
+ android:id="@+id/displayin"
+ android:layout_width="320dip"
+ android:layout_height="266dip" />
+
+ <ImageView
+ android:id="@+id/displayout"
+ android:layout_width="320dip"
+ android:layout_height="266dip" />
+
+</LinearLayout>
diff --git a/tests/RenderScriptTests/ComputeBenchmark/src/com/example/android/rs/computebench/Benchmark.java b/tests/RenderScriptTests/ComputeBenchmark/src/com/example/android/rs/computebench/Benchmark.java
new file mode 100644
index 0000000..ec80719
--- /dev/null
+++ b/tests/RenderScriptTests/ComputeBenchmark/src/com/example/android/rs/computebench/Benchmark.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.rs.computebench;
+import android.content.Context;
+import android.content.res.Resources;
+import android.renderscript.*;
+
+public class Benchmark implements Runnable {
+ private final RenderScript mRS;
+ private ScriptC_compute_benchmark mScript;
+
+ public Benchmark(RenderScript rs, Resources res) {
+ mRS = rs;
+ mScript = new ScriptC_compute_benchmark(mRS, res, R.raw.compute_benchmark);
+ }
+
+ public void run() {
+ long t = java.lang.System.currentTimeMillis();
+ mScript.invoke_bench();
+ mRS.finish();
+ t = java.lang.System.currentTimeMillis() - t;
+ android.util.Log.v("ComputeBench", "Total benchmark took " + t + " ms");
+ }
+
+}
diff --git a/tests/RenderScriptTests/ComputeBenchmark/src/com/example/android/rs/computebench/ComputeBench.java b/tests/RenderScriptTests/ComputeBenchmark/src/com/example/android/rs/computebench/ComputeBench.java
new file mode 100644
index 0000000..2d3e843
--- /dev/null
+++ b/tests/RenderScriptTests/ComputeBenchmark/src/com/example/android/rs/computebench/ComputeBench.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.rs.computebench;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.renderscript.RenderScript;
+
+public class ComputeBench extends Activity {
+ private RenderScript mRS;
+ private Benchmark mBenchmark;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+
+ mRS = RenderScript.create(this);
+
+ mBenchmark = new Benchmark(mRS, getResources());
+ mBenchmark.run();
+ }
+}
diff --git a/tests/RenderScriptTests/ComputeBenchmark/src/com/example/android/rs/computebench/compute_benchmark.rs b/tests/RenderScriptTests/ComputeBenchmark/src/com/example/android/rs/computebench/compute_benchmark.rs
new file mode 100644
index 0000000..7b8ec04
--- /dev/null
+++ b/tests/RenderScriptTests/ComputeBenchmark/src/com/example/android/rs/computebench/compute_benchmark.rs
@@ -0,0 +1,408 @@
+// Copyright (C) 2012 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#pragma version(1)
+#pragma rs java_package_name(com.example.android.rs.computebench)
+
+// Test configuration (accessible from Java)
+uint priming_runs = 1000000;
+uint timing_runs = 5000000;
+
+// Reused variables
+
+static volatile int64_t bench_time;
+static float inv_timing_runs;
+
+#define DECL_VAR_SET(prefix) \
+static volatile float prefix##_f_1 = 1; \
+static volatile float2 prefix##_f_2 = 1; \
+static volatile float3 prefix##_f_3 = 1; \
+static volatile float4 prefix##_f_4 = 1; \
+static volatile char prefix##_c_1 = 1; \
+static volatile char2 prefix##_c_2 = 1; \
+static volatile char3 prefix##_c_3 = 1; \
+static volatile char4 prefix##_c_4 = 1; \
+static volatile uchar prefix##_uc_1 = 1; \
+static volatile uchar2 prefix##_uc_2 = 1; \
+static volatile uchar3 prefix##_uc_3 = 1; \
+static volatile uchar4 prefix##_uc_4 = 1; \
+static volatile short prefix##_s_1 = 1; \
+static volatile short2 prefix##_s_2 = 1; \
+static volatile short3 prefix##_s_3 = 1; \
+static volatile short4 prefix##_s_4 = 1; \
+static volatile ushort prefix##_us_1 = 1; \
+static volatile ushort2 prefix##_us_2 = 1; \
+static volatile ushort3 prefix##_us_3 = 1; \
+static volatile ushort4 prefix##_us_4 = 1; \
+static volatile int prefix##_i_1 = 1; \
+static volatile int2 prefix##_i_2 = 1; \
+static volatile int3 prefix##_i_3 = 1; \
+static volatile int4 prefix##_i_4 = 1; \
+static volatile uint prefix##_ui_1 = 1; \
+static volatile uint2 prefix##_ui_2 = 1; \
+static volatile uint3 prefix##_ui_3 = 1; \
+static volatile uint4 prefix##_ui_4 = 1; \
+static volatile long prefix##_l_1 = 1; \
+static volatile long2 prefix##_l_2 = 1; \
+static volatile long3 prefix##_l_3 = 1; \
+static volatile long4 prefix##_l_4 = 1; \
+static volatile ulong prefix##_ul_1 = 1; \
+static volatile ulong2 prefix##_ul_2 = 1; \
+static volatile ulong3 prefix##_ul_3 = 1; \
+static volatile ulong4 prefix##_ul_4 = 1; \
+
+DECL_VAR_SET(res)
+DECL_VAR_SET(src1)
+DECL_VAR_SET(src2)
+DECL_VAR_SET(src3)
+
+
+// Testing macros
+
+#define RUN_BENCH(line, op) \
+ for (int i = priming_runs - 1; i >= 0; --i) { \
+ line; \
+ } \
+ bench_time = rsUptimeMillis(); \
+ for (int i = timing_runs - 1; i >= 0; --i) { \
+ line; \
+ } \
+ bench_time = rsUptimeMillis() - bench_time; \
+ rsDebug(" " op " took ns", (float)bench_time * inv_timing_runs);
+
+#define BENCH_BASIC_OP_TYPE(op, type) \
+ RUN_BENCH(res_##type##_1 = src1_##type##_1 op src2_##type##_1, #type "1 " #op " " #type "1") \
+ RUN_BENCH(res_##type##_2 = src1_##type##_2 op src2_##type##_2, #type "2 " #op " " #type "2") \
+ RUN_BENCH(res_##type##_3 = src1_##type##_3 op src2_##type##_3, #type "3 " #op " " #type "3") \
+ RUN_BENCH(res_##type##_4 = src1_##type##_4 op src2_##type##_4, #type "4 " #op " " #type "4") \
+
+#define BENCH_BASIC_INT_OP(op) \
+ rsDebug("Testing basic operation " #op, 0); \
+ BENCH_BASIC_OP_TYPE(op, c) \
+ BENCH_BASIC_OP_TYPE(op, uc) \
+ BENCH_BASIC_OP_TYPE(op, s) \
+ BENCH_BASIC_OP_TYPE(op, us) \
+ BENCH_BASIC_OP_TYPE(op, i) \
+ BENCH_BASIC_OP_TYPE(op, ui) \
+ RUN_BENCH(res_l_1 = src1_l_1 op src2_l_1, "l1 " #op " l1") \
+ RUN_BENCH(res_ul_1 = src1_ul_1 op src2_ul_1, "ul1 " #op " ul1")
+
+#define BENCH_BASIC_OP(op) \
+ BENCH_BASIC_INT_OP(op) \
+ BENCH_BASIC_OP_TYPE(op, f)
+
+#define BENCH_CVT(to, from, type) \
+ rsDebug("Testing convert from " #from " to " #to, 0); \
+ RUN_BENCH(res_##to##_1 = (type)src1_##from##_1, "(" #to ")" #from) \
+ RUN_BENCH(res_##to##_2 = convert_##type##2(src1_##from##_2), #to "2 convert_" #type "2(" #from "2)") \
+ RUN_BENCH(res_##to##_3 = convert_##type##3(src1_##from##_3), #to "3 convert_" #type "3(" #from "3)") \
+ RUN_BENCH(res_##to##_4 = convert_##type##4(src1_##from##_4), #to "4 convert_" #type "4(" #from "4)")
+
+#define BENCH_CVT_MATRIX(to, type) \
+ BENCH_CVT(to, c, type); \
+ BENCH_CVT(to, uc, type); \
+ BENCH_CVT(to, s, type); \
+ BENCH_CVT(to, us, type); \
+ BENCH_CVT(to, i, type); \
+ BENCH_CVT(to, ui, type); \
+ BENCH_CVT(to, f, type); \
+
+#define BENCH_XN_FUNC_YN(typeout, fnc, typein) \
+ RUN_BENCH(res_##typeout##_1 = fnc(src1_##typein##_1);, #typeout "1 " #fnc "(" #typein "1)") \
+ RUN_BENCH(res_##typeout##_2 = fnc(src1_##typein##_2);, #typeout "2 " #fnc "(" #typein "2)") \
+ RUN_BENCH(res_##typeout##_3 = fnc(src1_##typein##_3);, #typeout "3 " #fnc "(" #typein "3)") \
+ RUN_BENCH(res_##typeout##_4 = fnc(src1_##typein##_4);, #typeout "4 " #fnc "(" #typein "4)")
+
+#define BENCH_XN_FUNC_XN_XN(type, fnc) \
+ RUN_BENCH(res_##type##_1 = fnc(src1_##type##_1, src2_##type##_1), #type "1 " #fnc "(" #type "1, " #type "1)") \
+ RUN_BENCH(res_##type##_2 = fnc(src1_##type##_2, src2_##type##_2), #type "2 " #fnc "(" #type "2, " #type "2)") \
+ RUN_BENCH(res_##type##_3 = fnc(src1_##type##_3, src2_##type##_3), #type "3 " #fnc "(" #type "3, " #type "3)") \
+ RUN_BENCH(res_##type##_4 = fnc(src1_##type##_4, src2_##type##_4), #type "4 " #fnc "(" #type "4, " #type "4)") \
+
+#define BENCH_X_FUNC_X_X_X(type, fnc) \
+ RUN_BENCH(res_##type##_1 = fnc(src1_##type##_1, src2_##type##_1, src3_##type##_1), #type "1 " #fnc "(" #type "1, " #type "1, " #type "1)")
+
+#define BENCH_IN_FUNC_IN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ BENCH_XN_FUNC_YN(uc, fnc, uc) \
+ BENCH_XN_FUNC_YN(c, fnc, c) \
+ BENCH_XN_FUNC_YN(us, fnc, us) \
+ BENCH_XN_FUNC_YN(s, fnc, s) \
+ BENCH_XN_FUNC_YN(ui, fnc, ui) \
+ BENCH_XN_FUNC_YN(i, fnc, i)
+
+#define BENCH_UIN_FUNC_IN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ BENCH_XN_FUNC_YN(uc, fnc, c) \
+ BENCH_XN_FUNC_YN(us, fnc, s) \
+ BENCH_XN_FUNC_YN(ui, fnc, i) \
+
+#define BENCH_IN_FUNC_IN_IN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ BENCH_XN_FUNC_XN_XN(uc, fnc) \
+ BENCH_XN_FUNC_XN_XN(c, fnc) \
+ BENCH_XN_FUNC_XN_XN(us, fnc) \
+ BENCH_XN_FUNC_XN_XN(s, fnc) \
+ BENCH_XN_FUNC_XN_XN(ui, fnc) \
+ BENCH_XN_FUNC_XN_XN(i, fnc)
+
+#define BENCH_I_FUNC_I_I_I(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ BENCH_X_FUNC_X_X_X(uc, fnc) \
+ BENCH_X_FUNC_X_X_X(c, fnc) \
+ BENCH_X_FUNC_X_X_X(us, fnc) \
+ BENCH_X_FUNC_X_X_X(s, fnc) \
+ BENCH_X_FUNC_X_X_X(ui, fnc) \
+ BENCH_X_FUNC_X_X_X(i, fnc)
+
+#define BENCH_FN_FUNC_FN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ RUN_BENCH(res_f_1 = fnc(src1_f_1), "f1 " #fnc "(f1)") \
+ RUN_BENCH(res_f_2 = fnc(src1_f_2), "f2 " #fnc "(f2)") \
+ RUN_BENCH(res_f_3 = fnc(src1_f_3), "f3 " #fnc "(f3)") \
+ RUN_BENCH(res_f_4 = fnc(src1_f_4), "f4 " #fnc "(f4)")
+
+#define BENCH_FN_FUNC_FN_PFN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ RUN_BENCH(res_f_1 = fnc(src1_f_1, (float*) &src2_f_1), "f1 " #fnc "(f1, f1*)") \
+ RUN_BENCH(res_f_2 = fnc(src1_f_2, (float2*) &src2_f_2), "f2 " #fnc "(f2, f2*)") \
+ RUN_BENCH(res_f_3 = fnc(src1_f_3, (float3*) &src2_f_3), "f3 " #fnc "(f3, f3*)") \
+ RUN_BENCH(res_f_4 = fnc(src1_f_4, (float4*) &src2_f_4), "f4 " #fnc "(f4, f4*)")
+
+#define BENCH_FN_FUNC_FN_FN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ RUN_BENCH(res_f_1 = fnc(src1_f_1, src2_f_1), "f1 " #fnc "(f1, f1)") \
+ RUN_BENCH(res_f_2 = fnc(src1_f_2, src2_f_2), "f2 " #fnc "(f2, f2)") \
+ RUN_BENCH(res_f_3 = fnc(src1_f_3, src2_f_3), "f3 " #fnc "(f3, f3)") \
+ RUN_BENCH(res_f_4 = fnc(src1_f_4, src2_f_4), "f4 " #fnc "(f4, f4)")
+
+#define BENCH_F34_FUNC_F34_F34(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ RUN_BENCH(res_f_3 = fnc(src1_f_3, src2_f_3), "f3 " #fnc "(f3, f3)") \
+ RUN_BENCH(res_f_4 = fnc(src1_f_4, src2_f_4), "f4 " #fnc "(f4, f4)")
+
+#define BENCH_FN_FUNC_FN_F(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ RUN_BENCH(res_f_1 = fnc(src1_f_1, src2_f_1), "f1 " #fnc "(f1, f1)") \
+ RUN_BENCH(res_f_2 = fnc(src1_f_2, src2_f_1), "f2 " #fnc "(f2, f1)") \
+ RUN_BENCH(res_f_3 = fnc(src1_f_3, src2_f_1), "f3 " #fnc "(f3, f1)") \
+ RUN_BENCH(res_f_4 = fnc(src1_f_4, src2_f_1), "f4 " #fnc "(f4, f1)")
+
+#define BENCH_F_FUNC_FN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ RUN_BENCH(res_f_1 = fnc(src1_f_1), "f1 " #fnc "(f1)") \
+ RUN_BENCH(res_f_1 = fnc(src1_f_2), "f1 " #fnc "(f2)") \
+ RUN_BENCH(res_f_1 = fnc(src1_f_3), "f1 " #fnc "(f3)") \
+ RUN_BENCH(res_f_1 = fnc(src1_f_4), "f1 " #fnc "(f4)")
+
+#define BENCH_F_FUNC_FN_FN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ RUN_BENCH(res_f_1 = fnc(src1_f_1, src2_f_1), "f1 " #fnc "(f1, f1)") \
+ RUN_BENCH(res_f_1 = fnc(src1_f_2, src2_f_2), "f1 " #fnc "(f2, f2)") \
+ RUN_BENCH(res_f_1 = fnc(src1_f_3, src2_f_3), "f1 " #fnc "(f3, f3)") \
+ RUN_BENCH(res_f_1 = fnc(src1_f_4, src2_f_4), "f1 " #fnc "(f4, f4)")
+
+#define BENCH_FN_FUNC_FN_IN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ RUN_BENCH(res_f_1 = fnc(src1_f_1, src1_i_1), "f1 " #fnc "(f1, i1)") \
+ RUN_BENCH(res_f_2 = fnc(src1_f_2, src1_i_2), "f2 " #fnc "(f2, i2)") \
+ RUN_BENCH(res_f_3 = fnc(src1_f_3, src1_i_3), "f3 " #fnc "(f3, i3)") \
+ RUN_BENCH(res_f_4 = fnc(src1_f_4, src1_i_4), "f4 " #fnc "(f4, i4)")
+
+#define BENCH_FN_FUNC_FN_I(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ RUN_BENCH(res_f_1 = fnc(src1_f_1, src1_i_1), "f1 " #fnc "(f1, i1)") \
+ RUN_BENCH(res_f_2 = fnc(src1_f_2, src1_i_1), "f2 " #fnc "(f2, i1)") \
+ RUN_BENCH(res_f_3 = fnc(src1_f_3, src1_i_1), "f3 " #fnc "(f3, i1)") \
+ RUN_BENCH(res_f_4 = fnc(src1_f_4, src1_i_1), "f4 " #fnc "(f4, i1)")
+
+#define BENCH_FN_FUNC_FN_FN_FN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ RUN_BENCH(res_f_1 = fnc(src1_f_1, src2_f_1, src3_f_1), "f1 " #fnc "(f1, f1, f1)") \
+ RUN_BENCH(res_f_2 = fnc(src1_f_2, src2_f_2, src3_f_2), "f2 " #fnc "(f2, f2, f2)") \
+ RUN_BENCH(res_f_3 = fnc(src1_f_3, src2_f_3, src3_f_3), "f3 " #fnc "(f3, f3, f3)") \
+ RUN_BENCH(res_f_4 = fnc(src1_f_4, src2_f_4, src3_f_4), "f4 " #fnc "(f4, f4, f4)")
+
+#define BENCH_FN_FUNC_FN_FN_F(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ RUN_BENCH(res_f_1 = fnc(src1_f_1, src2_f_1, src3_f_1), "f1 " #fnc "(f1, f1, f1)") \
+ RUN_BENCH(res_f_2 = fnc(src1_f_2, src2_f_2, src3_f_1), "f2 " #fnc "(f2, f2, f1)") \
+ RUN_BENCH(res_f_3 = fnc(src1_f_3, src2_f_3, src3_f_1), "f3 " #fnc "(f3, f3, f1)") \
+ RUN_BENCH(res_f_4 = fnc(src1_f_4, src2_f_4, src3_f_1), "f4 " #fnc "(f4, f4, f1)")
+
+#define BENCH_FN_FUNC_FN_PIN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ RUN_BENCH(res_f_1 = fnc(src1_f_1, (int*) &src1_i_1), "f1 " #fnc "(f1, i1*)") \
+ RUN_BENCH(res_f_2 = fnc(src1_f_2, (int2*) &src1_i_2), "f2 " #fnc "(f2, i2*)") \
+ RUN_BENCH(res_f_3 = fnc(src1_f_3, (int3*) &src1_i_3), "f3 " #fnc "(f3, i3*)") \
+ RUN_BENCH(res_f_4 = fnc(src1_f_4, (int4*) &src1_i_4), "f4 " #fnc "(f4, i4*)")
+
+#define BENCH_FN_FUNC_FN_FN_PIN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ RUN_BENCH(res_f_1 = fnc(src1_f_1, src2_f_1, (int*) &src1_i_1), "f1 " #fnc "(f1, f1, i1*)") \
+ RUN_BENCH(res_f_2 = fnc(src1_f_2, src2_f_2, (int2*) &src1_i_2), "f2 " #fnc "(f2, f2, i2*)") \
+ RUN_BENCH(res_f_3 = fnc(src1_f_3, src2_f_3, (int3*) &src1_i_3), "f3 " #fnc "(f3, f3, i3*)") \
+ RUN_BENCH(res_f_4 = fnc(src1_f_4, src2_f_4, (int4*) &src1_i_4), "f4 " #fnc "(f4, f4, i4*)")
+
+#define BENCH_IN_FUNC_FN(fnc) \
+ rsDebug("Testing " #fnc, 0); \
+ RUN_BENCH(res_i_1 = fnc(src1_f_1), "i1 " #fnc "(f1)") \
+ RUN_BENCH(res_i_2 = fnc(src1_f_2), "i2 " #fnc "(f2)") \
+ RUN_BENCH(res_i_3 = fnc(src1_f_3), "i3 " #fnc "(f3)") \
+ RUN_BENCH(res_i_4 = fnc(src1_f_4), "i4 " #fnc "(f4)")
+
+
+// Testing functions
+
+static void bench_basic_operators() {
+ int i = 0;
+ BENCH_BASIC_OP(+);
+ BENCH_BASIC_OP(-);
+ BENCH_BASIC_OP(*);
+ BENCH_BASIC_OP(/);
+ BENCH_BASIC_INT_OP(%);
+ BENCH_BASIC_INT_OP(<<);
+ BENCH_BASIC_INT_OP(>>);
+}
+
+static void bench_convert() {
+ BENCH_CVT_MATRIX(c, char);
+ BENCH_CVT_MATRIX(uc, uchar);
+ BENCH_CVT_MATRIX(s, short);
+ BENCH_CVT_MATRIX(us, ushort);
+ BENCH_CVT_MATRIX(i, int);
+ BENCH_CVT_MATRIX(ui, uint);
+ BENCH_CVT_MATRIX(f, float);
+}
+
+static void bench_int_math() {
+ BENCH_UIN_FUNC_IN(abs);
+ BENCH_IN_FUNC_IN(clz);
+ BENCH_IN_FUNC_IN_IN(min);
+ BENCH_IN_FUNC_IN_IN(max);
+ BENCH_I_FUNC_I_I_I(rsClamp);
+}
+
+static void bench_fp_math() {
+ BENCH_FN_FUNC_FN(acos);
+ BENCH_FN_FUNC_FN(acosh);
+ BENCH_FN_FUNC_FN(acospi);
+ BENCH_FN_FUNC_FN(asin);
+ BENCH_FN_FUNC_FN(asinh);
+ BENCH_FN_FUNC_FN(asinpi);
+ BENCH_FN_FUNC_FN(atan);
+ BENCH_FN_FUNC_FN_FN(atan2);
+ BENCH_FN_FUNC_FN(atanh);
+ BENCH_FN_FUNC_FN(atanpi);
+ BENCH_FN_FUNC_FN_FN(atan2pi);
+ BENCH_FN_FUNC_FN(cbrt);
+ BENCH_FN_FUNC_FN(ceil);
+ BENCH_FN_FUNC_FN_FN_FN(clamp);
+ BENCH_FN_FUNC_FN_FN_F(clamp);
+ BENCH_FN_FUNC_FN_FN(copysign);
+ BENCH_FN_FUNC_FN(cos);
+ BENCH_FN_FUNC_FN(cosh);
+ BENCH_FN_FUNC_FN(cospi);
+ BENCH_F34_FUNC_F34_F34(cross);
+ BENCH_FN_FUNC_FN(degrees);
+ BENCH_F_FUNC_FN_FN(distance);
+ BENCH_F_FUNC_FN_FN(dot);
+ BENCH_FN_FUNC_FN(erfc);
+ BENCH_FN_FUNC_FN(erf);
+ BENCH_FN_FUNC_FN(exp);
+ BENCH_FN_FUNC_FN(exp2);
+ BENCH_FN_FUNC_FN(exp10);
+ BENCH_FN_FUNC_FN(expm1);
+ BENCH_FN_FUNC_FN(fabs);
+ BENCH_FN_FUNC_FN_FN(fdim);
+ BENCH_FN_FUNC_FN(floor);
+ BENCH_FN_FUNC_FN_FN_FN(fma);
+ BENCH_FN_FUNC_FN_FN(fmax);
+ BENCH_FN_FUNC_FN_F(fmax);
+ BENCH_FN_FUNC_FN_FN(fmin);
+ BENCH_FN_FUNC_FN_F(fmin);
+ BENCH_FN_FUNC_FN_FN(fmod);
+ BENCH_FN_FUNC_FN_PFN(fract);
+ BENCH_FN_FUNC_FN_PIN(frexp);
+ BENCH_FN_FUNC_FN_FN(hypot);
+ BENCH_IN_FUNC_FN(ilogb);
+ BENCH_FN_FUNC_FN_IN(ldexp);
+ BENCH_FN_FUNC_FN_I(ldexp);
+ BENCH_F_FUNC_FN(length);
+ BENCH_FN_FUNC_FN(lgamma);
+ BENCH_FN_FUNC_FN_PIN(lgamma);
+ BENCH_FN_FUNC_FN(log);
+ BENCH_FN_FUNC_FN(log2);
+ BENCH_FN_FUNC_FN(log10);
+ BENCH_FN_FUNC_FN(log1p);
+ BENCH_FN_FUNC_FN(logb);
+ BENCH_FN_FUNC_FN_FN_FN(mad);
+ BENCH_FN_FUNC_FN_FN(max);
+ BENCH_FN_FUNC_FN_F(max);
+ BENCH_FN_FUNC_FN_FN(min);
+ BENCH_FN_FUNC_FN_F(min);
+ BENCH_FN_FUNC_FN_FN_FN(mix);
+ BENCH_FN_FUNC_FN_FN_F(mix);
+ BENCH_FN_FUNC_FN_PFN(modf);
+ BENCH_FN_FUNC_FN_FN(nextafter);
+ BENCH_FN_FUNC_FN(normalize);
+ BENCH_FN_FUNC_FN_FN(pow);
+ BENCH_FN_FUNC_FN_IN(pown);
+ BENCH_FN_FUNC_FN_FN(powr);
+ BENCH_FN_FUNC_FN(radians);
+ BENCH_FN_FUNC_FN_FN(remainder);
+ BENCH_FN_FUNC_FN_FN_PIN(remquo);
+ BENCH_FN_FUNC_FN(rint);
+ BENCH_FN_FUNC_FN_IN(rootn);
+ BENCH_FN_FUNC_FN(round);
+ BENCH_FN_FUNC_FN(rsqrt);
+ BENCH_FN_FUNC_FN(sign);
+ BENCH_FN_FUNC_FN(sin);
+ BENCH_FN_FUNC_FN_PFN(sincos);
+ BENCH_FN_FUNC_FN(sinh);
+ BENCH_FN_FUNC_FN(sinpi);
+ BENCH_FN_FUNC_FN(sqrt);
+ BENCH_FN_FUNC_FN_FN(step);
+ BENCH_FN_FUNC_FN_F(step);
+ BENCH_FN_FUNC_FN(tan);
+ BENCH_FN_FUNC_FN(tanh);
+ BENCH_FN_FUNC_FN(tanpi);
+ BENCH_FN_FUNC_FN(tgamma);
+ BENCH_FN_FUNC_FN(trunc);
+}
+
+static void bench_approx_math() {
+ BENCH_FN_FUNC_FN(approx_recip);
+ BENCH_FN_FUNC_FN(approx_sqrt);
+ BENCH_FN_FUNC_FN(approx_rsqrt);
+ BENCH_FN_FUNC_FN(approx_length);
+ BENCH_FN_FUNC_FN_FN(approx_distance);
+ BENCH_FN_FUNC_FN(approx_normalize);
+ BENCH_FN_FUNC_FN(approx_atan);
+}
+
+void bench() {
+ rsDebug("RS Compute Benchmark", 0);
+ rsDebug("Current configuration:", 0);
+ rsDebug("Priming runs", priming_runs);
+ rsDebug("Timing runs", timing_runs);
+ rsDebug("Beginning test", 0);
+ inv_timing_runs = 1000000.f / (float)timing_runs;
+ bench_basic_operators();
+ bench_convert();
+ bench_int_math();
+ bench_fp_math();
+ bench_approx_math();
+}
+
diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/Fisheye.java b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/Fisheye.java
index bf68f91..81868b1 100644
--- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/Fisheye.java
+++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/Fisheye.java
@@ -26,12 +26,16 @@ import android.widget.TextView;
public class Fisheye extends TestBase {
private ScriptC_fisheye_full mScript_full = null;
private ScriptC_fisheye_relaxed mScript_relaxed = null;
+ private ScriptC_fisheye_approx_full mScript_approx_full = null;
+ private ScriptC_fisheye_approx_relaxed mScript_approx_relaxed = null;
+ private final boolean approx;
private final boolean relaxed;
private float center_x = 0.5f;
private float center_y = 0.5f;
private float scale = 0.5f;
- public Fisheye(boolean relaxed) {
+ public Fisheye(boolean approx, boolean relaxed) {
+ this.approx = approx;
this.relaxed = relaxed;
}
@@ -68,7 +72,18 @@ public class Fisheye extends TestBase {
}
private void do_init() {
- if (relaxed)
+ if (approx) {
+ if (relaxed)
+ mScript_approx_relaxed.invoke_init_filter(
+ mInPixelsAllocation.getType().getX(),
+ mInPixelsAllocation.getType().getY(), center_x,
+ center_y, scale);
+ else
+ mScript_approx_full.invoke_init_filter(
+ mInPixelsAllocation.getType().getX(),
+ mInPixelsAllocation.getType().getY(), center_x,
+ center_y, scale);
+ } else if (relaxed)
mScript_relaxed.invoke_init_filter(
mInPixelsAllocation.getType().getX(),
mInPixelsAllocation.getType().getY(), center_x, center_y,
@@ -81,7 +96,19 @@ public class Fisheye extends TestBase {
}
public void createTest(android.content.res.Resources res) {
- if (relaxed) {
+ if (approx) {
+ if (relaxed) {
+ mScript_approx_relaxed = new ScriptC_fisheye_approx_relaxed(mRS,
+ res, R.raw.fisheye_approx_relaxed);
+ mScript_approx_relaxed.set_in_alloc(mInPixelsAllocation);
+ mScript_approx_relaxed.set_sampler(Sampler.CLAMP_LINEAR(mRS));
+ } else {
+ mScript_approx_full = new ScriptC_fisheye_approx_full(mRS, res,
+ R.raw.fisheye_approx_full);
+ mScript_approx_full.set_in_alloc(mInPixelsAllocation);
+ mScript_approx_full.set_sampler(Sampler.CLAMP_LINEAR(mRS));
+ }
+ } else if (relaxed) {
mScript_relaxed = new ScriptC_fisheye_relaxed(mRS, res,
R.raw.fisheye_relaxed);
mScript_relaxed.set_in_alloc(mInPixelsAllocation);
@@ -96,7 +123,12 @@ public class Fisheye extends TestBase {
}
public void runTest() {
- if (relaxed)
+ if (approx) {
+ if (relaxed)
+ mScript_approx_relaxed.forEach_root(mOutPixelsAllocation);
+ else
+ mScript_approx_full.forEach_root(mOutPixelsAllocation);
+ } else if (relaxed)
mScript_relaxed.forEach_root(mOutPixelsAllocation);
else
mScript_full.forEach_root(mOutPixelsAllocation);
diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
index 3eec7f5..07626a3 100644
--- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
+++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
@@ -144,30 +144,36 @@ public class ImageProcessingActivity extends Activity
mTest = new Grain();
break;
case 7:
- mTest = new Fisheye(false);
+ mTest = new Fisheye(false, false);
break;
case 8:
- mTest = new Fisheye(true);
+ mTest = new Fisheye(false, true);
break;
case 9:
- mTest = new Vignette(false, false);
+ mTest = new Fisheye(true, false);
break;
case 10:
- mTest = new Vignette(false, true);
+ mTest = new Fisheye(true, true);
break;
case 11:
- mTest = new Vignette(true, false);
+ mTest = new Vignette(false, false);
break;
case 12:
- mTest = new Vignette(true, true);
+ mTest = new Vignette(false, true);
break;
case 13:
- mTest = new GroupTest(true);
+ mTest = new Vignette(true, false);
break;
case 14:
- mTest = new GroupTest(false);
+ mTest = new Vignette(true, true);
break;
case 15:
+ mTest = new GroupTest(true);
+ break;
+ case 16:
+ mTest = new GroupTest(false);
+ break;
+ case 17:
mTest = new Intrinsics(0);
break;
}
@@ -182,7 +188,7 @@ public class ImageProcessingActivity extends Activity
}
void setupTests() {
- mTestNames = new String[16];
+ mTestNames = new String[18];
mTestNames[0] = "Levels Vec3 Relaxed";
mTestNames[1] = "Levels Vec4 Relaxed";
mTestNames[2] = "Levels Vec3 Full";
@@ -192,13 +198,15 @@ public class ImageProcessingActivity extends Activity
mTestNames[6] = "Grain";
mTestNames[7] = "Fisheye Full";
mTestNames[8] = "Fisheye Relaxed";
- mTestNames[9] = "Vignette Full";
- mTestNames[10] = "Vignette Relaxed";
- mTestNames[11] = "Vignette Approximate Full";
- mTestNames[12] = "Vignette Approximate Relaxed";
- mTestNames[13] = "Group Test (emulated)";
- mTestNames[14] = "Group Test (native)";
- mTestNames[15] = "Intrinsics Convolve 3x3";
+ mTestNames[9] = "Fisheye Approximate Full";
+ mTestNames[10] = "Fisheye Approximate Relaxed";
+ mTestNames[11] = "Vignette Full";
+ mTestNames[12] = "Vignette Relaxed";
+ mTestNames[13] = "Vignette Approximate Full";
+ mTestNames[14] = "Vignette Approximate Relaxed";
+ mTestNames[15] = "Group Test (emulated)";
+ mTestNames[16] = "Group Test (native)";
+ mTestNames[17] = "Intrinsics Convolve 3x3";
mTestSpinner.setAdapter(new ArrayAdapter<String>(
this, R.layout.spinner_layout, mTestNames));
}
diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye.rsh b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye.rsh
index 4dcfc1d..3809912 100644
--- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye.rsh
+++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye.rsh
@@ -17,46 +17,41 @@
rs_allocation in_alloc;
rs_sampler sampler;
-static float2 center, dimensions;
-static float2 scale;
-static float alpha;
-static float radius2;
-static float factor;
-
-void init_filter(uint32_t dim_x, uint32_t dim_y, float focus_x, float focus_y, float k) {
- center.x = focus_x;
- center.y = focus_y;
- dimensions.x = (float)dim_x;
- dimensions.y = (float)dim_y;
+static float2 center, neg_center, inv_dimensions, axis_scale;
+static float alpha, radius2, factor;
+void init_filter(uint32_t dim_x, uint32_t dim_y, float center_x, float center_y, float k) {
+ center.x = center_x;
+ center.y = center_y;
+ neg_center = -center;
+ inv_dimensions.x = 1.f / (float)dim_x;
+ inv_dimensions.y = 1.f / (float)dim_y;
alpha = k * 2.0 + 0.75;
- float bound2 = 0.25;
- if (dim_x > dim_y) {
- scale.x = 1.0;
- scale.y = dimensions.y / dimensions.x;
- bound2 *= (scale.y*scale.y + 1);
- } else {
- scale.x = dimensions.x / dimensions.y;
- scale.y = 1.0;
- bound2 *= (scale.x*scale.x + 1);
- }
+
+ axis_scale = (float2)1.f;
+ if (dim_x > dim_y)
+ axis_scale.y = (float)dim_y / (float)dim_x;
+ else
+ axis_scale.x = (float)dim_x / (float)dim_y;
+
+ const float bound2 = 0.25 * (axis_scale.x*axis_scale.x + axis_scale.y*axis_scale.y);
const float bound = sqrt(bound2);
const float radius = 1.15 * bound;
radius2 = radius*radius;
- const float max_radian = 0.5f * M_PI - atan(alpha / bound * sqrt(radius2 - bound2));
+ const float max_radian = M_PI_2 - atan(alpha / bound * sqrt(radius2 - bound2));
factor = bound / max_radian;
}
void root(uchar4 *out, uint32_t x, uint32_t y) {
// Convert x and y to floating point coordinates with center as origin
- float2 coord;
- coord.x = (float)x / dimensions.x;
- coord.y = (float)y / dimensions.y;
- coord -= center;
- const float dist = length(scale * coord);
- const float radian = M_PI_2 - atan((alpha * sqrt(radius2 - dist * dist)) / dist);
- const float scalar = radian * factor / dist;
- const float2 new_coord = coord * scalar + center;
+ const float2 inCoord = {(float)x, (float)y};
+ const float2 coord = mad(inCoord, inv_dimensions, neg_center);
+ const float2 scaledCoord = axis_scale * coord;
+ const float dist2 = scaledCoord.x*scaledCoord.x + scaledCoord.y*scaledCoord.y;
+ const float inv_dist = rsqrt(dist2);
+ const float radian = M_PI_2 - atan((alpha * sqrt(radius2 - dist2)) * inv_dist);
+ const float scalar = radian * factor * inv_dist;
+ const float2 new_coord = mad(coord, scalar, center);
const float4 fout = rsSample(in_alloc, sampler, new_coord);
*out = rsPackColorTo8888(fout);
}
diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx.rsh b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx.rsh
new file mode 100644
index 0000000..008acbe
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx.rsh
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+rs_allocation in_alloc;
+rs_sampler sampler;
+
+static float2 center, neg_center, inv_dimensions, axis_scale;
+static float alpha, radius2, factor;
+
+void init_filter(uint32_t dim_x, uint32_t dim_y, float center_x, float center_y, float k) {
+ center.x = center_x;
+ center.y = center_y;
+ neg_center = -center;
+ inv_dimensions.x = 1.f / (float)dim_x;
+ inv_dimensions.y = 1.f / (float)dim_y;
+ alpha = k * 2.0 + 0.75;
+
+ axis_scale = (float2)1.f;
+ if (dim_x > dim_y)
+ axis_scale.y = (float)dim_y / (float)dim_x;
+ else
+ axis_scale.x = (float)dim_x / (float)dim_y;
+
+ const float bound2 = 0.25 * (axis_scale.x*axis_scale.x + axis_scale.y*axis_scale.y);
+ const float bound = sqrt(bound2);
+ const float radius = 1.15 * bound;
+ radius2 = radius*radius;
+ const float max_radian = M_PI_2 - atan(alpha / bound * sqrt(radius2 - bound2));
+ factor = bound / max_radian;
+}
+
+void root(uchar4 *out, uint32_t x, uint32_t y) {
+ // Convert x and y to floating point coordinates with center as origin
+ const float2 inCoord = {(float)x, (float)y};
+ const float2 coord = mad(inCoord, inv_dimensions, neg_center);
+ const float2 scaledCoord = axis_scale * coord;
+ const float dist2 = scaledCoord.x*scaledCoord.x + scaledCoord.y*scaledCoord.y;
+ const float inv_dist = approx_rsqrt(dist2);
+ const float radian = M_PI_2 - approx_atan((alpha * approx_sqrt(radius2 - dist2)) * inv_dist);
+ const float scalar = radian * factor * inv_dist;
+ const float2 new_coord = mad(coord, scalar, center);
+ const float4 fout = rsSample(in_alloc, sampler, new_coord);
+ *out = rsPackColorTo8888(fout);
+}
+
diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx_full.rs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx_full.rs
new file mode 100644
index 0000000..1ea37db
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx_full.rs
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma version(1)
+#pragma rs java_package_name(com.android.rs.image)
+
+#include "fisheye_approx.rsh"
+
diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx_relaxed.rs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx_relaxed.rs
new file mode 100644
index 0000000..3e76368
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx_relaxed.rs
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma version(1)
+#pragma rs java_package_name(com.android.rs.image)
+#pragma rs_fp_relaxed
+
+#include "fisheye_approx.rsh"
+
diff --git a/tests/RenderScriptTests/ImageProcessing2/Android.mk b/tests/RenderScriptTests/ImageProcessing2/Android.mk
index c81fd93..e05a518 100644
--- a/tests/RenderScriptTests/ImageProcessing2/Android.mk
+++ b/tests/RenderScriptTests/ImageProcessing2/Android.mk
@@ -25,6 +25,10 @@ LOCAL_SRC_FILES := $(call all-java-files-under, src) \
LOCAL_STATIC_JAVA_LIBRARIES := android.support.v8.renderscript
LOCAL_PACKAGE_NAME := ImageProcessing2
+LOCAL_SDK_VERSION := 8
+LOCAL_RENDERSCRIPT_TARGET_API := 17
+LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE := $(TOPDIR)external/clang/lib/Headers \
+ $(TOPDIR)frameworks/rs/scriptc
LOCAL_RENDERSCRIPT_FLAGS := -rs-package-name=android.support.v8.renderscript
LOCAL_REQUIRED_MODULES := librsjni
diff --git a/tests/RenderScriptTests/ImageProcessing2/AndroidManifest.xml b/tests/RenderScriptTests/ImageProcessing2/AndroidManifest.xml
index 1ef04c2..20ee053 100644
--- a/tests/RenderScriptTests/ImageProcessing2/AndroidManifest.xml
+++ b/tests/RenderScriptTests/ImageProcessing2/AndroidManifest.xml
@@ -2,9 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.rs.image2">
- <uses-sdk android:minSdkVersion="11" />
- <application android:label="IP GB"
- android:hardwareAccelerated="true">
+ <uses-sdk android:minSdkVersion="8" />
+ <application android:label="IP GB">
<activity android:name="ImageProcessingActivity2">
<intent-filter>
<action android:name="android.intent.action.MAIN" />