aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXusong Wang <xusongw@google.com>2021-11-01 15:32:03 -0700
committerXusong Wang <xusongw@google.com>2021-11-02 10:42:59 -0700
commit598692ab79f7706c102ff395bdbd50c91a0ced64 (patch)
treec73f357bebf628d81baed9a8ef75fe8634f48678
parent9a70eae6f1b9c7dd25f36f80487efea0c0b39658 (diff)
downloadrenderscript-intrinsics-replacement-toolkit-598692ab79f7706c102ff395bdbd50c91a0ced64.tar.gz
Convert test-app into Android instrumented test.
-rw-r--r--test-app/build.gradle2
-rw-r--r--test-app/src/androidTest/java/com/google/android/renderscript_test/RenderScriptToolkitTest.kt77
-rw-r--r--test-app/src/main/AndroidManifest.xml2
-rw-r--r--test-app/src/main/java/com/google/android/renderscript_test/AllTests.kt48
-rw-r--r--test-app/src/main/java/com/google/android/renderscript_test/MainActivity.kt40
-rw-r--r--test-app/src/main/res/layout/activity_main.xml25
6 files changed, 111 insertions, 83 deletions
diff --git a/test-app/build.gradle b/test-app/build.gradle
index de1d8d7..c7de909 100644
--- a/test-app/build.gradle
+++ b/test-app/build.gradle
@@ -9,7 +9,7 @@ android {
defaultConfig {
applicationId "com.google.android.renderscript_test"
- minSdkVersion 16
+ minSdkVersion 21
targetSdkVersion 31
versionCode 1
versionName "1.0"
diff --git a/test-app/src/androidTest/java/com/google/android/renderscript_test/RenderScriptToolkitTest.kt b/test-app/src/androidTest/java/com/google/android/renderscript_test/RenderScriptToolkitTest.kt
new file mode 100644
index 0000000..0afa54b
--- /dev/null
+++ b/test-app/src/androidTest/java/com/google/android/renderscript_test/RenderScriptToolkitTest.kt
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2021 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.google.android.renderscript_test
+
+import android.content.Context
+import android.util.Log
+import androidx.test.ext.junit.rules.ActivityScenarioRule
+import androidx.test.filters.LargeTest
+import org.junit.Assert.assertTrue
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.Parameterized
+
+@RunWith(Parameterized::class)
+@LargeTest
+class RenderScriptToolkitTest {
+ @ExperimentalUnsignedTypes
+ @get:Rule
+ var activityScenarioRule = ActivityScenarioRule(MainActivity::class.java)
+
+ @Parameterized.Parameter(value = 0)
+ lateinit var intrinsic: Intrinsic
+
+ @ExperimentalUnsignedTypes
+ @Test
+ fun test() {
+ lateinit var thread: Thread
+ var success = false
+ activityScenarioRule.scenario.onActivity { activity ->
+ // Run the test in a new thread to avoid blocking the main thread.
+ thread = Thread{
+ success = testIntrinsic(activity, intrinsic, validate = true)
+ }.apply { start() }
+ }
+ thread.join()
+ assertTrue(success)
+ }
+
+ @ExperimentalUnsignedTypes
+ private fun testIntrinsic(context: Context, intrinsic: Intrinsic, validate: Boolean): Boolean {
+ val tester = Tester(context, validate)
+ val numberOfIterations = if (validate) 1 else 12
+ val timer = TimingTracker(numberOfIterations, numberOfIterationsToIgnore = 0)
+ val results = Array(numberOfIterations) { i ->
+ Log.i(TAG, "*** Starting iteration ${i + 1} of $numberOfIterations ****")
+ val success = tester.testOne(intrinsic, timer)
+ Log.i(TAG, if (success) timer.report() else "FAILED! FAILED! FAILED! FAILED!")
+ timer.nextIteration()
+ success
+ }
+ tester.destroy()
+ return results.all { it }
+ }
+
+ companion object {
+ private val TAG = "RenderScriptToolkitTest"
+
+ @JvmStatic
+ @Parameterized.Parameters(name = "{0}")
+ fun data(): List<Array<Any>> = Intrinsic.values().map { arrayOf(it) }
+ }
+}
diff --git a/test-app/src/main/AndroidManifest.xml b/test-app/src/main/AndroidManifest.xml
index c9d3307..14fcf76 100644
--- a/test-app/src/main/AndroidManifest.xml
+++ b/test-app/src/main/AndroidManifest.xml
@@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.renderscript_test">
+ <uses-sdk android:minSdkVersion="21" />
+
<application
android:allowBackup="true"
android:label="@string/app_name"
diff --git a/test-app/src/main/java/com/google/android/renderscript_test/AllTests.kt b/test-app/src/main/java/com/google/android/renderscript_test/AllTests.kt
index 1025504..934456f 100644
--- a/test-app/src/main/java/com/google/android/renderscript_test/AllTests.kt
+++ b/test-app/src/main/java/com/google/android/renderscript_test/AllTests.kt
@@ -57,6 +57,18 @@ val commonLayoutsToTry = listOf(
*/
)
+enum class Intrinsic {
+ BLEND,
+ BLUR,
+ COLOR_MATRIX,
+ CONVOLVE,
+ HISTOGRAM,
+ LUT,
+ LUT3D,
+ RESIZE,
+ YUV_TO_RGB,
+}
+
class Tester(context: Context, private val validate: Boolean) {
private val renderscriptContext = RenderScript.create(context)
@@ -83,30 +95,20 @@ class Tester(context: Context, private val validate: Boolean) {
renderscriptContext.destroy()
}
+ // Test one single intrinsic. Return true on success and false on failure.
@ExperimentalUnsignedTypes
- fun testAll(timer: TimingTracker): String {
- val tests = listOf(
- Pair("blend", ::testBlend),
- Pair("blur", ::testBlur),
- Pair("colorMatrix", ::testColorMatrix),
- Pair("convolve", ::testConvolve),
- Pair("histogram", ::testHistogram),
- Pair("lut", ::testLut),
- Pair("lut3d", ::testLut3d),
- Pair("resize", ::testResize),
- Pair("yuvToRgb", ::testYuvToRgb),
- )
- val results = Array(tests.size) { "" }
- for (i in tests.indices) {
- val (name, test) = tests[i]
- println("Doing $name")
- val success = test(timer)
- results[i] = "$name " + if (success) "succeeded" else "FAILED! FAILED! FAILED! FAILED!"
- println(" ${results[i]}")
- }
-
- return results.joinToString("\n")
- }
+ fun testOne(intrinsic: Intrinsic, timer: TimingTracker) =
+ when(intrinsic) {
+ Intrinsic.BLEND -> ::testBlend
+ Intrinsic.BLUR -> ::testBlur
+ Intrinsic.COLOR_MATRIX -> ::testColorMatrix
+ Intrinsic.CONVOLVE -> ::testConvolve
+ Intrinsic.HISTOGRAM -> ::testHistogram
+ Intrinsic.LUT -> ::testLut
+ Intrinsic.LUT3D -> ::testLut3d
+ Intrinsic.RESIZE -> ::testResize
+ Intrinsic.YUV_TO_RGB -> ::testYuvToRgb
+ }.let { test -> test(timer) }
@ExperimentalUnsignedTypes
private fun testBlend(timer: TimingTracker): Boolean {
diff --git a/test-app/src/main/java/com/google/android/renderscript_test/MainActivity.kt b/test-app/src/main/java/com/google/android/renderscript_test/MainActivity.kt
index 30eac4e..10ea5f7 100644
--- a/test-app/src/main/java/com/google/android/renderscript_test/MainActivity.kt
+++ b/test-app/src/main/java/com/google/android/renderscript_test/MainActivity.kt
@@ -17,14 +17,11 @@
package com.google.android.renderscript_test
import android.os.Bundle
-import android.text.method.ScrollingMovementMethod
-import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
@ExperimentalUnsignedTypes
class MainActivity : AppCompatActivity() {
-
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
@@ -38,42 +35,5 @@ class MainActivity : AppCompatActivity() {
} catch (e: ReflectiveOperationException) {
throw RuntimeException(e)
}
-
- startTests(this)
- }
-
- private fun startTests(activity: MainActivity) {
- object : Thread() {
- override fun run() {
- val view = findViewById<TextView>(R.id.sample_text)
- view.movementMethod = ScrollingMovementMethod()
- val validate = true
- val tester = Tester(activity, validate)
- val numberOfIterations = if (validate) 1 else 12
- val t = TimingTracker(numberOfIterations, 0)
- for (i in 1..numberOfIterations) {
- val tag = "*** Starting iteration $i of $numberOfIterations ****\n"
- print(tag)
- runOnUiThread(Runnable { view.append(tag) })
- //startMethodTracing("myTracing")
- //startMethodTracingSampling("myTracing_sample", 8000000, 10)
- val result = tester.testAll(t)
- //stopMethodTracing()
- runOnUiThread(Runnable { view.append("$result\n\n${t.report()}\n") })
- t.nextIteration()
- }
- tester.destroy()
- /*
- while (i++ < 1000) {
- try {
- runOnUiThread(Runnable { btn.setText("#$i") })
- sleep(300)
- } catch (e: InterruptedException) {
- e.printStackTrace()
- }
- }
- */
- }
- }.start()
}
}
diff --git a/test-app/src/main/res/layout/activity_main.xml b/test-app/src/main/res/layout/activity_main.xml
index ca83aaf..eb5586c 100644
--- a/test-app/src/main/res/layout/activity_main.xml
+++ b/test-app/src/main/res/layout/activity_main.xml
@@ -1,20 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
-<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".MainActivity">
-
- <TextView
- android:id="@+id/sample_text"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text=""
- android:scrollbars = "vertical"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintLeft_toLeftOf="parent"
- app:layout_constraintRight_toRightOf="parent"
- app:layout_constraintTop_toTopOf="parent" />
-
-</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ tools:context=".MainActivity"/> \ No newline at end of file