1 /* 2 * Copyright (C) 2019 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 com.android.nn.benchmark.core.TestModels; 21 import java.io.IOException; 22 import java.util.ArrayList; 23 import java.util.Collections; 24 import java.util.List; 25 import java.util.stream.Collectors; 26 import org.junit.Test; 27 import org.junit.runner.RunWith; 28 import org.junit.runners.Parameterized; 29 import org.junit.runners.Parameterized.Parameters; 30 31 /** 32 * Tests that ensure stability of NNAPI by running inference for a 33 * prolonged period of time. 34 */ 35 @RunWith(Parameterized.class) 36 public class NNInferenceStressTest extends BenchmarkTestBase { 37 private static final String TAG = NNInferenceStressTest.class.getSimpleName(); 38 39 private static final float WARMUP_SECONDS = 0; // No warmup. 40 private static final float RUNTIME_SECONDS = 60 * 60; // 1 hour. 41 NNInferenceStressTest(TestModels.TestModelEntry model)42 public NNInferenceStressTest(TestModels.TestModelEntry model) { 43 super(model); 44 } 45 46 @Parameters(name = "{0}") modelsList()47 public static List<TestModels.TestModelEntry> modelsList() { 48 return TestModels.modelsList().stream() 49 .map(TestModels.TestModelEntry::withDisabledEvaluation) 50 .collect(Collectors.collectingAndThen( 51 Collectors.toList(), 52 Collections::unmodifiableList)); 53 } 54 55 @Test 56 @LargeTest stressTestNNAPI()57 public void stressTestNNAPI() throws IOException { 58 waitUntilCharged(); 59 setUseNNApi(true); 60 setCompleteInputSet(false); 61 TestAction ta = new TestAction(mModel, WARMUP_SECONDS, RUNTIME_SECONDS); 62 runTest(ta, mModel.getTestName()); 63 } 64 } 65