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