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.result.TestRunResult;
20 import com.android.tradefed.retry.IRetryDecision;
21 import com.android.tradefed.testtype.IRemoteTest;
22 import com.android.tradefed.testtype.ITestFilterReceiver;
23 
24 import java.util.List;
25 import java.util.Set;
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      * @param skipList The set of items that shouldn't be retried.
45      * @return True if we should retry, False otherwise.
46      * @throws DeviceNotAvailableException Can be thrown during device recovery
47      */
shouldRetry( int attemptJustExecuted, List<TestRunResult> previousResults, Set<String> skipList)48     public default boolean shouldRetry(
49             int attemptJustExecuted, List<TestRunResult> previousResults, Set<String> skipList)
50             throws DeviceNotAvailableException {
51         // No retry by default
52         return false;
53     }
54 }
55