1 /* 2 * Copyright (C) 2019 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 package com.android.tradefed.testtype.retry; 17 18 import com.android.tradefed.device.DeviceNotAvailableException; 19 import com.android.tradefed.device.ITestDevice; 20 import com.android.tradefed.result.TestRunResult; 21 import com.android.tradefed.retry.IRetryDecision; 22 import com.android.tradefed.testtype.IRemoteTest; 23 import com.android.tradefed.testtype.ITestFilterReceiver; 24 25 import java.util.List; 26 27 /** 28 * Interface for an {@link IRemoteTest} that doesn't implement {@link ITestFilterReceiver} but still 29 * wishes to support auto-retry. 30 * 31 * <p>The recommendation for most runners is to implement {@link ITestFilterReceiver} and give 32 * granular control over what tests are running for the harness to handle. But in some situation, it 33 * might not be possible and some delegated form of retry is necessary. 34 */ 35 public interface IAutoRetriableTest extends IRemoteTest { 36 37 /** 38 * Delegated from {@link IRetryDecision#shouldRetry(IRemoteTest, int, List)}. Decide whether or 39 * not retry should be attempted. Also make any necessary changes to the {@link IRemoteTest} to 40 * be retried (Applying filters, preparing next run, etc.). 41 * 42 * @param attemptJustExecuted The number of the attempt that we just ran. 43 * @param previousResults The list of {@link TestRunResult} of the test that just ran. 44 * @return True if we should retry, False otherwise. 45 * @throws DeviceNotAvailableException Can be thrown during device recovery 46 */ shouldRetry(int attemptJustExecuted, List<TestRunResult> previousResults)47 public default boolean shouldRetry(int attemptJustExecuted, List<TestRunResult> previousResults) 48 throws DeviceNotAvailableException { 49 // No retry by default 50 return false; 51 } 52 53 /** 54 * Recovery attempt on the device to get it a better state before next retry. Will only be 55 * triggered if {@link #shouldRetry(int, List)} returns true. 56 * 57 * @param devices The list of {@link ITestDevice} to apply recovery on. 58 * @param attemptJustExecuted The number of the attempt that we just ran. 59 */ recoverStateOfDevices(List<ITestDevice> devices, int attemptJustExecuted)60 public default void recoverStateOfDevices(List<ITestDevice> devices, int attemptJustExecuted) { 61 // Do nothing by default 62 } 63 } 64