Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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.result; |
| 17 | |
Julien Desprez | 53353e6 | 2016-08-12 15:24:33 +0100 | [diff] [blame] | 18 | import com.android.tradefed.invoker.IInvocationContext; |
Guang Zhu | dc19f70 | 2016-03-22 17:52:03 -0700 | [diff] [blame] | 19 | import com.android.tradefed.log.ITestLogger; |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 20 | |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 21 | /** |
| 22 | * Listener for test results from the test invocation. |
jdesprez | 4de2f55 | 2018-02-02 14:38:13 -0800 | [diff] [blame] | 23 | * |
| 24 | * <p>A test invocation can itself include multiple test runs, so the sequence of calls will be |
| 25 | * |
Brett Chabot | ffcc918 | 2011-05-12 15:05:24 -0700 | [diff] [blame] | 26 | * <ul> |
jdesprez | 4de2f55 | 2018-02-02 14:38:13 -0800 | [diff] [blame] | 27 | * <li>invocationStarted(BuildInfo) |
| 28 | * <li>testRunStarted |
| 29 | * <li>testStarted |
| 30 | * <li>[testFailed] |
| 31 | * <li>testEnded |
| 32 | * <li>... |
| 33 | * <li>testRunEnded |
| 34 | * <li>... |
| 35 | * <li>testRunStarted |
| 36 | * <li>... |
| 37 | * <li>testRunEnded |
| 38 | * <li>[invocationFailed] |
| 39 | * <li>[testLog+] |
| 40 | * <li>invocationEnded |
| 41 | * <li>getSummary |
Brett Chabot | ffcc918 | 2011-05-12 15:05:24 -0700 | [diff] [blame] | 42 | * </ul> |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 43 | */ |
jdesprez | 4de2f55 | 2018-02-02 14:38:13 -0800 | [diff] [blame] | 44 | public interface ITestInvocationListener extends ITestLogger, ITestLifeCycleReceiver { |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * Reports the start of the test invocation. |
| 48 | * |
Julien Desprez | 245b1b5 | 2017-01-31 09:07:19 +0000 | [diff] [blame] | 49 | * <p>Will be automatically called by the TradeFederation framework. Reporters need to override |
| 50 | * this method to support multiple devices reporting. |
Julien Desprez | 53353e6 | 2016-08-12 15:24:33 +0100 | [diff] [blame] | 51 | * |
| 52 | * @param context information about the invocation |
| 53 | */ |
Julien Desprez | 245b1b5 | 2017-01-31 09:07:19 +0000 | [diff] [blame] | 54 | public default void invocationStarted(IInvocationContext context) {} |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 55 | |
| 56 | /** |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 57 | * Reports that the invocation has terminated, whether successfully or due to some error |
| 58 | * condition. |
Brett Chabot | ffcc918 | 2011-05-12 15:05:24 -0700 | [diff] [blame] | 59 | * <p/> |
| 60 | * Will be automatically called by the TradeFederation framework. |
Brett Chabot | 3759c85 | 2010-07-13 17:36:31 -0700 | [diff] [blame] | 61 | * |
| 62 | * @param elapsedTime the elapsed time of the invocation in ms |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 63 | */ |
Allen Hair | ead9d92 | 2016-10-25 15:36:28 -0700 | [diff] [blame] | 64 | default public void invocationEnded(long elapsedTime) { } |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 65 | |
Brett Chabot | 1b808f2 | 2010-03-16 11:17:12 -0700 | [diff] [blame] | 66 | /** |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 67 | * Reports an incomplete invocation due to some error condition. |
Brett Chabot | ffcc918 | 2011-05-12 15:05:24 -0700 | [diff] [blame] | 68 | * <p/> |
| 69 | * Will be automatically called by the TradeFederation framework. |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 70 | * |
Brett Chabot | 1b808f2 | 2010-03-16 11:17:12 -0700 | [diff] [blame] | 71 | * @param cause the {@link Throwable} cause of the failure |
| 72 | */ |
Allen Hair | ead9d92 | 2016-10-25 15:36:28 -0700 | [diff] [blame] | 73 | default public void invocationFailed(Throwable cause) { } |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 74 | |
| 75 | /** |
Julien Desprez | 496b974 | 2020-04-16 15:26:51 -0700 | [diff] [blame] | 76 | * Reports an incomplete invocation due to some error condition. |
| 77 | * |
| 78 | * <p>Will be automatically called by the TradeFederation framework. |
| 79 | * |
| 80 | * @param failure the {@link FailureDescription} describing the cause of the failure |
| 81 | */ |
Julien Desprez | 7fc5425 | 2020-04-30 15:08:45 -0700 | [diff] [blame^] | 82 | default void invocationFailed(FailureDescription failure) { |
Julien Desprez | 496b974 | 2020-04-16 15:26:51 -0700 | [diff] [blame] | 83 | if (failure.getCause() != null) { |
| 84 | invocationFailed(failure.getCause()); |
| 85 | } else { |
| 86 | invocationFailed( |
| 87 | new RuntimeException( |
| 88 | String.format("ConvertedFailure: %s", failure.getErrorMessage()))); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | /** |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 93 | * Allows the InvocationListener to return a summary. |
| 94 | * |
| 95 | * @return A {@link TestSummary} summarizing the run, or null |
| 96 | */ |
Allen Hair | ead9d92 | 2016-10-25 15:36:28 -0700 | [diff] [blame] | 97 | default public TestSummary getSummary() { return null; } |
Brett Chabot | 1b808f2 | 2010-03-16 11:17:12 -0700 | [diff] [blame] | 98 | |
Julien Desprez | 5e26414 | 2016-03-21 13:47:27 +0000 | [diff] [blame] | 99 | /** |
Julien Desprez | b2e61ee | 2019-06-28 13:33:41 -0700 | [diff] [blame] | 100 | * Called on scheduler shutdown, gives the invocation the opportunity to do something before |
| 101 | * terminating. |
Julien Desprez | 5e26414 | 2016-03-21 13:47:27 +0000 | [diff] [blame] | 102 | */ |
Julien Desprez | b2e61ee | 2019-06-28 13:33:41 -0700 | [diff] [blame] | 103 | public default void invocationInterrupted() { |
Julien Desprez | 5e26414 | 2016-03-21 13:47:27 +0000 | [diff] [blame] | 104 | // do nothing in default implementation. |
| 105 | } |
Allen Hair | ead9d92 | 2016-10-25 15:36:28 -0700 | [diff] [blame] | 106 | |
| 107 | /** |
jdesprez | 51beee8 | 2017-08-23 15:28:42 -0700 | [diff] [blame] | 108 | * Reports the beginning of a module running. This callback is associated with {@link |
| 109 | * #testModuleEnded()} and is optional in the sequence. It is only used during a run that uses |
Julien Desprez | b2e61ee | 2019-06-28 13:33:41 -0700 | [diff] [blame] | 110 | * modules: suite based runners. |
jdesprez | 51beee8 | 2017-08-23 15:28:42 -0700 | [diff] [blame] | 111 | * |
| 112 | * @param moduleContext the {@link IInvocationContext} of the module. |
| 113 | */ |
| 114 | public default void testModuleStarted(IInvocationContext moduleContext) {} |
| 115 | |
| 116 | /** Reports the end of a module run. */ |
| 117 | public default void testModuleEnded() {} |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 118 | } |