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 NNMultipleProcessModelLoadTest extends NNMultipleProcessTest { NNMultipleProcessModelLoadTest(int processCount, int threadCount, Duration duration, int failureRatePercent, String acceleratorName)34 public NNMultipleProcessModelLoadTest(int processCount, int threadCount, Duration duration, 35 int failureRatePercent, String acceleratorName) { 36 super(processCount, threadCount, duration, failureRatePercent, acceleratorName); 37 } 38 39 @Parameters(name = "{0} processes, {1} threads for {2} on accelerator({4}) with early " 40 + "termination rate({3}%)") testConfiguration()41 public static List<Object[]> testConfiguration() { 42 return AcceleratorSpecificTestSupport.perAcceleratorTestConfig( 43 Arrays.asList(new Object[]{6, 10, Duration.ofMinutes(20), 0}, 44 new Object[]{6, 10, Duration.ofMinutes(20), 50}, 45 new Object[]{6, 10, Duration.ofMinutes(10), 100})); 46 } 47 48 @Override getRunModelsInMultipleProcessesConfigIntent()49 protected Intent getRunModelsInMultipleProcessesConfigIntent() { 50 try { 51 Intent result = new Intent(); 52 RunModelsInMultipleProcesses 53 .intentInitializer(mTestName.getMethodName(), 54 findModelForLivenessTest().get().mModelName, 55 mProcessCount, mThreadCount, mDuration, mAcceleratorName, 56 /*justCompileModel=*/true, mFailureRatePercent) 57 .addIntentParams(result); 58 return result; 59 } catch (NnApiDelegationFailure nnApiDelegationFailure) { 60 throw new RuntimeException( 61 "Cannot initialize test, failure looking for supported models, please check " 62 + "the driver status", 63 nnApiDelegationFailure); 64 } 65 } 66 }