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