blob: 462f375927b1f3a1961c2122fa09b4ac94e444ec [file] [log] [blame]
Brett Chabot74121d82010-01-28 20:14:27 -08001/*
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 */
16package com.android.tradefed.result;
17
Julien Desprez53353e62016-08-12 15:24:33 +010018import com.android.tradefed.invoker.IInvocationContext;
Guang Zhudc19f702016-03-22 17:52:03 -070019import com.android.tradefed.log.ITestLogger;
Brett Chabot74121d82010-01-28 20:14:27 -080020
Brett Chabot74121d82010-01-28 20:14:27 -080021/**
22 * Listener for test results from the test invocation.
jdesprez4de2f552018-02-02 14:38:13 -080023 *
24 * <p>A test invocation can itself include multiple test runs, so the sequence of calls will be
25 *
Brett Chabotffcc9182011-05-12 15:05:24 -070026 * <ul>
jdesprez4de2f552018-02-02 14:38:13 -080027 * <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 Chabotffcc9182011-05-12 15:05:24 -070042 * </ul>
Brett Chabot74121d82010-01-28 20:14:27 -080043 */
jdesprez4de2f552018-02-02 14:38:13 -080044public interface ITestInvocationListener extends ITestLogger, ITestLifeCycleReceiver {
Brett Chabot74121d82010-01-28 20:14:27 -080045
46 /**
47 * Reports the start of the test invocation.
48 *
Julien Desprez245b1b52017-01-31 09:07:19 +000049 * <p>Will be automatically called by the TradeFederation framework. Reporters need to override
50 * this method to support multiple devices reporting.
Julien Desprez53353e62016-08-12 15:24:33 +010051 *
52 * @param context information about the invocation
53 */
Julien Desprez245b1b52017-01-31 09:07:19 +000054 public default void invocationStarted(IInvocationContext context) {}
Brett Chabot74121d82010-01-28 20:14:27 -080055
56 /**
Omari Stephens203296c2010-09-02 18:20:45 -070057 * Reports that the invocation has terminated, whether successfully or due to some error
58 * condition.
Brett Chabotffcc9182011-05-12 15:05:24 -070059 * <p/>
60 * Will be automatically called by the TradeFederation framework.
Brett Chabot3759c852010-07-13 17:36:31 -070061 *
62 * @param elapsedTime the elapsed time of the invocation in ms
Brett Chabot74121d82010-01-28 20:14:27 -080063 */
Allen Hairead9d922016-10-25 15:36:28 -070064 default public void invocationEnded(long elapsedTime) { }
Brett Chabot74121d82010-01-28 20:14:27 -080065
Brett Chabot1b808f22010-03-16 11:17:12 -070066 /**
Omari Stephens203296c2010-09-02 18:20:45 -070067 * Reports an incomplete invocation due to some error condition.
Brett Chabotffcc9182011-05-12 15:05:24 -070068 * <p/>
69 * Will be automatically called by the TradeFederation framework.
Brett Chabotfe88a152010-08-02 17:52:59 -070070 *
Brett Chabot1b808f22010-03-16 11:17:12 -070071 * @param cause the {@link Throwable} cause of the failure
72 */
Allen Hairead9d922016-10-25 15:36:28 -070073 default public void invocationFailed(Throwable cause) { }
Omari Stephens203296c2010-09-02 18:20:45 -070074
75 /**
Julien Desprez496b9742020-04-16 15:26:51 -070076 * 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 Desprez7fc54252020-04-30 15:08:45 -070082 default void invocationFailed(FailureDescription failure) {
Julien Desprez496b9742020-04-16 15:26:51 -070083 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 Stephens203296c2010-09-02 18:20:45 -070093 * Allows the InvocationListener to return a summary.
94 *
95 * @return A {@link TestSummary} summarizing the run, or null
96 */
Allen Hairead9d922016-10-25 15:36:28 -070097 default public TestSummary getSummary() { return null; }
Brett Chabot1b808f22010-03-16 11:17:12 -070098
Julien Desprez5e264142016-03-21 13:47:27 +000099 /**
Julien Desprezb2e61ee2019-06-28 13:33:41 -0700100 * Called on scheduler shutdown, gives the invocation the opportunity to do something before
101 * terminating.
Julien Desprez5e264142016-03-21 13:47:27 +0000102 */
Julien Desprezb2e61ee2019-06-28 13:33:41 -0700103 public default void invocationInterrupted() {
Julien Desprez5e264142016-03-21 13:47:27 +0000104 // do nothing in default implementation.
105 }
Allen Hairead9d922016-10-25 15:36:28 -0700106
107 /**
jdesprez51beee82017-08-23 15:28:42 -0700108 * 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 Desprezb2e61ee2019-06-28 13:33:41 -0700110 * modules: suite based runners.
jdesprez51beee82017-08-23 15:28:42 -0700111 *
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 Chabot74121d82010-01-28 20:14:27 -0800118}