1 /* 2 * 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.android.nn.benchmark.app; 18 19 import android.test.suitebuilder.annotation.LargeTest; 20 import androidx.test.InstrumentationRegistry; 21 import com.android.nn.benchmark.core.TestModels; 22 import java.io.IOException; 23 import org.junit.Test; 24 import org.junit.runner.RunWith; 25 import org.junit.runners.Parameterized; 26 27 /** 28 * NNAPI benchmark test. 29 * To run the test, please use command 30 * 31 * adb shell am instrument 32 * -e class "com.android.nn.benchmark.app.NNCrystalBallTest 33 * -w com.android.nn.benchmark.app/androidx.test.runner.AndroidJUnitRunner 34 * 35 * To run only one model, please run: 36 * adb shell am instrument 37 * -e class "com.android.nn.benchmark.app.NNCrystalBallTest#testNNAPI[MODEL_NAME]" 38 * -w com.android.nn.benchmark.app/androidx.test.runner.AndroidJUnitRunner 39 * 40 */ 41 @RunWith(Parameterized.class) 42 public class NNCrystalBallTest extends BenchmarkTestBase { 43 NNCrystalBallTest(TestModels.TestModelEntry model)44 public NNCrystalBallTest(TestModels.TestModelEntry model) { 45 super(model); 46 } 47 test(boolean useNnapi, boolean useCompleteInputSet)48 private void test(boolean useNnapi, boolean useCompleteInputSet) throws IOException { 49 setUseNNApi(useNnapi); 50 setCompleteInputSet(useCompleteInputSet); 51 enableCompilationCachingBenchmarks(); 52 TestAction ta = new TestAction(mModel, WARMUP_REPEATABLE_SECONDS, 53 useCompleteInputSet ? COMPLETE_SET_TIMEOUT_SECOND : RUNTIME_REPEATABLE_SECONDS); 54 runTest(ta, mModel.getTestName()); 55 56 // Sends metric results to the instrumentation status output. 57 InstrumentationRegistry.getInstrumentation().sendStatus( 58 0, ta.getBenchmark().toBundle(mModel.getTestName())); 59 } 60 61 @Test 62 @LargeTest testTFLite()63 public void testTFLite() throws IOException { 64 test(false, false); 65 } 66 67 @Test 68 @LargeTest testNNAPI()69 public void testNNAPI() throws IOException { 70 test(true, true); 71 } 72 73 } 74