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.NnApiDelegationFailure;
22 import com.android.nn.crashtest.core.test.RunModelsInMultipleProcesses;
23 
24 import org.junit.runner.RunWith;
25 import org.junit.runners.Parameterized;
26 import org.junit.runners.Parameterized.Parameters;
27 
28 import java.time.Duration;
29 import java.util.Arrays;
30 import java.util.List;
31 
32 @RunWith(Parameterized.class)
33 public class NNMultipleProcessInferenceTest extends NNMultipleProcessTest {
NNMultipleProcessInferenceTest(int processCount, int threadCount, Duration duration, int failureRatePercent, String acceleratorName)34     public NNMultipleProcessInferenceTest(int processCount, int threadCount, Duration duration,
35             int failureRatePercent, String acceleratorName) {
36         super(processCount, threadCount, duration, failureRatePercent, acceleratorName);
37     }
38 
39     @Override
getRunModelsInMultipleProcessesConfigIntent()40     protected Intent getRunModelsInMultipleProcessesConfigIntent() {
41         try {
42             Intent result = new Intent();
43             RunModelsInMultipleProcesses
44                     .intentInitializer(mTestName.getMethodName(),
45                             findModelForLivenessTest().get().mModelName,
46                             mProcessCount, mThreadCount, mDuration,
47                             mAcceleratorName, /*justCompileModel=*/false,
48                             mFailureRatePercent)
49                     .addIntentParams(result);
50             return result;
51         } catch (NnApiDelegationFailure nnApiDelegationFailure) {
52             throw new RuntimeException(
53                     "Cannot initialize test, failure looking for supported models, please check "
54                             + "the driver status",
55                     nnApiDelegationFailure);
56         }
57     }
58 
59     @Parameters(name = "{0} processes, {1} threads for {2} on accelerator({4}) with early "
60             + "termination rate({3}%)")
61     public static List<Object[]>
testConfiguration()62     testConfiguration() {
63         return AcceleratorSpecificTestSupport.perAcceleratorTestConfig(
64                 Arrays.asList(new Object[]{6, 10, Duration.ofMinutes(30), 0},
65                         new Object[]{6, 10, Duration.ofMinutes(20), 80}));
66     }
67 }