• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, String acceleratorName)45     public NNModelLoadingStressTest(TestModels.TestModelEntry model, String acceleratorName) {
46         super(model, acceleratorName);
47     }
48 
49     @Parameters(name = "{0} model on accelerator {1}")
modelsList()50     public static List<Object[]> modelsList() {
51         return BenchmarkTestBase.modelsOnAccelerators().stream()
52             .map( modelAndAccelerator -> {
53                 TestModels.TestModelEntry modelEntry =
54                     (TestModels.TestModelEntry)modelAndAccelerator[0];
55                 return new Object[] { modelEntry.withDisabledEvaluation(), modelAndAccelerator[1] };
56             })
57             .collect(Collectors.collectingAndThen(
58                 Collectors.toList(),
59                 Collections::unmodifiableList));
60     }
61 
62     @Test
63     @LargeTest
stressTestNNAPI()64     public void stressTestNNAPI() throws IOException {
65         waitUntilCharged();
66         setUseNNApi(true);
67         setCompleteInputSet(true);
68         float endTime = stopwatch.runtime(TimeUnit.SECONDS) + RUNTIME_SECONDS;
69         TestAction ta = new TestAction(mModel, WARMUP_SECONDS, INFERENCE_SECONDS);
70         while (stopwatch.runtime(TimeUnit.SECONDS) < endTime) {
71             runTest(ta, mModel.getTestName());
72         }
73     }
74 }
75