1 /* <lambda>null2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.android.renderscript_test 18 19 import android.content.Context 20 import android.util.Log 21 import androidx.test.ext.junit.rules.ActivityScenarioRule 22 import androidx.test.filters.LargeTest 23 import org.junit.Assert.assertTrue 24 import org.junit.Rule 25 import org.junit.Test 26 import org.junit.runner.RunWith 27 import org.junit.runners.Parameterized 28 29 @RunWith(Parameterized::class) 30 @LargeTest 31 class RenderScriptToolkitTest { 32 @ExperimentalUnsignedTypes 33 @get:Rule 34 var activityScenarioRule = ActivityScenarioRule(MainActivity::class.java) 35 36 @Parameterized.Parameter(value = 0) 37 lateinit var intrinsic: Intrinsic 38 39 @ExperimentalUnsignedTypes 40 @Test 41 fun test() { 42 lateinit var thread: Thread 43 var success = false 44 activityScenarioRule.scenario.onActivity { activity -> 45 // Run the test in a new thread to avoid blocking the main thread. 46 thread = Thread{ 47 success = testIntrinsic(activity, intrinsic, validate = true) 48 }.apply { start() } 49 } 50 thread.join() 51 assertTrue(success) 52 } 53 54 @ExperimentalUnsignedTypes 55 private fun testIntrinsic(context: Context, intrinsic: Intrinsic, validate: Boolean): Boolean { 56 val tester = Tester(context, validate) 57 val numberOfIterations = if (validate) 1 else 12 58 val timer = TimingTracker(numberOfIterations, numberOfIterationsToIgnore = 0) 59 val results = Array(numberOfIterations) { i -> 60 Log.i(TAG, "*** Starting iteration ${i + 1} of $numberOfIterations ****") 61 val success = tester.testOne(intrinsic, timer) 62 Log.i(TAG, if (success) timer.report() else "FAILED! FAILED! FAILED! FAILED!") 63 timer.nextIteration() 64 success 65 } 66 tester.destroy() 67 return results.all { it } 68 } 69 70 companion object { 71 private val TAG = "RenderScriptToolkitTest" 72 73 @JvmStatic 74 @Parameterized.Parameters(name = "{0}") 75 fun data(): List<Array<Any>> = Intrinsic.values().map { arrayOf(it) } 76 } 77 } 78