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.crashtest.app;
18 
19 import android.content.Intent;
20 
21 import com.android.nn.benchmark.core.TestModels;
22 import com.android.nn.crashtest.core.CrashTest;
23 import com.android.nn.crashtest.core.CrashTestCoordinator;
24 import com.android.nn.crashtest.core.test.PerformanceDegradationTest;
25 
26 public class NNPerformanceDegradationTestActivity extends NNCrashTestActivity {
27     private static final String TAG = NNPerformanceDegradationTest.TAG;
28 
29     @Override
getTag()30     protected String getTag() {
31         return TAG;
32     }
33 
34     @Override
getTestName(Intent intent)35     protected String getTestName(Intent intent) {
36         return intent.getStringExtra(PerformanceDegradationTest.TEST_NAME);
37     }
38 
39     @Override
getTestDurationMillis(Intent intent)40     protected long getTestDurationMillis(Intent intent) {
41         final float testBenchmarkRuntimeSeconds = intent.getFloatExtra(
42                 PerformanceDegradationTest.RUN_TIME_SECONDS,
43                 PerformanceDegradationTest.DEFAULT_RUN_TIME_SECONDS);
44         final float testBenchmarkWarmupTimeSeconds = intent.getFloatExtra(
45                 PerformanceDegradationTest.WARMUP_SECONDS,
46                 PerformanceDegradationTest.DEFAULT_WARMUP_SECONDS);
47         // Two cycles of performance measurement are taken, single and multi-threaded,
48         // with a pause in the middle repeated for every available model. We are assuming all are
49         // available
50         long oneModelTestDuration =
51                 (long) (testBenchmarkRuntimeSeconds + testBenchmarkWarmupTimeSeconds) * 1000 * 3;
52         return oneModelTestDuration * TestModels.modelsList().size();
53     }
54 
55     @Override
getIntentInitializer(Intent intent)56     protected CrashTestCoordinator.CrashTestIntentInitializer getIntentInitializer(Intent intent) {
57         return PerformanceDegradationTest.intentInitializer(intent);
58     }
59 
60     @Override
getTestClass()61     protected Class<? extends CrashTest> getTestClass() {
62         return PerformanceDegradationTest.class;
63     }
64 }