• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.retry;
17 
18 import com.android.tradefed.device.DeviceNotAvailableException;
19 import com.android.tradefed.invoker.IInvocationContext;
20 import com.android.tradefed.result.TestRunResult;
21 import com.android.tradefed.testtype.IRemoteTest;
22 import com.android.tradefed.testtype.suite.ModuleDefinition;
23 
24 import java.util.List;
25 
26 /**
27  * Interface driving the retry decision and applying the filter on the class for more targeted
28  * retry.
29  */
30 public interface IRetryDecision {
31 
32     /** Whether or not to enable auto-retry. */
isAutoRetryEnabled()33     public boolean isAutoRetryEnabled();
34 
35     /** The {@link com.android.tradefed.retry.RetryStrategy} used during auto-retry. */
getRetryStrategy()36     public RetryStrategy getRetryStrategy();
37 
38     /** Whether or not to reboot the device before the last attempt. */
rebootAtLastAttempt()39     public boolean rebootAtLastAttempt();
40 
41     /** The maximum number of attempts per test run during auto-retry. */
getMaxTestRunAttempts()42     public int getMaxTestRunAttempts();
43 
44     /** The maximum number of attempts per test run for a given module during
45      * auto-retry. */
getMaxTestRunAttempts(ModuleDefinition module)46     public int getMaxTestRunAttempts(ModuleDefinition module);
47 
48     /** The maximum number of attempts per test run during auto-retry. */
getMaxTestCaseAttempts()49     public int getMaxTestCaseAttempts();
50 
51     /** The maximum number of attempts per test run for a given module during
52      * auto-retry. */
getMaxTestCaseAttempts(ModuleDefinition module)53     public int getMaxTestCaseAttempts(ModuleDefinition module);
54 
55     /** Returns true if we should use the updated reporting. */
useUpdatedReporting()56     public boolean useUpdatedReporting();
57 
58     /** Decide whether or not the module preparation should be retried. */
shouldRetryPreparation( ModuleDefinition module, int attempt, int maxAttempt)59     public RetryPreparationDecision shouldRetryPreparation(
60             ModuleDefinition module, int attempt, int maxAttempt);
61 
62     /** Set the current invocation context. */
setInvocationContext(IInvocationContext context)63     public void setInvocationContext(IInvocationContext context);
64 
65     /**
66      * Decide whether or not retry should be attempted. Also make any necessary changes to the
67      * {@link IRemoteTest} to be retried (Applying filters, etc.).
68      *
69      * @param test The {@link IRemoteTest} that just ran.
70      * @param attemptJustExecuted The number of the attempt that we just ran.
71      * @param previousResults The list of {@link TestRunResult} of the test that just ran.
72      * @return True if we should retry, False otherwise.
73      * @throws DeviceNotAvailableException Can be thrown during device recovery
74      */
shouldRetry( IRemoteTest test, int attemptJustExecuted, List<TestRunResult> previousResults)75     public boolean shouldRetry(
76             IRemoteTest test, int attemptJustExecuted, List<TestRunResult> previousResults)
77             throws DeviceNotAvailableException;
78 
79     /**
80      * Decide whether or not retry should be attempted. Also make any necessary changes to the
81      * {@link IRemoteTest} to be retried (Applying filters, etc.).
82      *
83      * @param test The {@link IRemoteTest} that just ran.
84      * @param module The {@link ModuleDefinition} object for the test module.
85      * @param attemptJustExecuted The number of the attempt that we just ran.
86      * @param previousResults The list of {@link TestRunResult} of the test that just ran.
87      * @param dnae The {@link DeviceNotAvailableException} of device not available exception.
88      * @return True if we should retry, False otherwise.
89      * @throws DeviceNotAvailableException Can be thrown during device recovery
90      */
shouldRetry( IRemoteTest test, ModuleDefinition module, int attemptJustExecuted, List<TestRunResult> previousResults, DeviceNotAvailableException dnae)91     public boolean shouldRetry(
92             IRemoteTest test,
93             ModuleDefinition module,
94             int attemptJustExecuted,
95             List<TestRunResult> previousResults,
96             DeviceNotAvailableException dnae)
97             throws DeviceNotAvailableException;
98 
99     /**
100      * {@link #shouldRetry(IRemoteTest, int, List)} will most likely be called before the last retry
101      * attempt, so we might be missing the very last attempt results for statistics purpose. This
102      * method allows those results to be provided for proper statistics calculations.
103      *
104      * @param lastResults
105      */
addLastAttempt(List<TestRunResult> lastResults)106     public void addLastAttempt(List<TestRunResult> lastResults);
107 
108     /** Returns the {@link RetryStatistics} representing the retry. */
getRetryStatistics()109     public RetryStatistics getRetryStatistics();
110 
111     /** Add an entry to skip retrying it. */
addToSkipRetryList(String filterEntry)112     public default void addToSkipRetryList(String filterEntry) {
113         // Empty by default on purpose
114     }
115 
116     /** Returns the command line args for the retry decision. */
getCommandLineArgs()117     public List<String> getCommandLineArgs();
118 }
119