• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 import com.android.tradefed.command.ICommandScheduler;
19 import com.android.tradefed.invoker.IInvocationContext;
20 import com.android.tradefed.log.ITestLogger;
21 import com.android.tradefed.testtype.suite.ITestSuite;
22 
23 /**
24  * Listener for test results from the test invocation.
25  *
26  * <p>A test invocation can itself include multiple test runs, so the sequence of calls will be
27  *
28  * <ul>
29  *   <li>invocationStarted(BuildInfo)
30  *   <li>testRunStarted
31  *   <li>testStarted
32  *   <li>[testFailed]
33  *   <li>testEnded
34  *   <li>...
35  *   <li>testRunEnded
36  *   <li>...
37  *   <li>testRunStarted
38  *   <li>...
39  *   <li>testRunEnded
40  *   <li>[invocationFailed]
41  *   <li>[testLog+]
42  *   <li>invocationEnded
43  *   <li>getSummary
44  * </ul>
45  */
46 public interface ITestInvocationListener extends ITestLogger, ITestLifeCycleReceiver {
47 
48     /**
49      * Reports the start of the test invocation.
50      *
51      * <p>Will be automatically called by the TradeFederation framework. Reporters need to override
52      * this method to support multiple devices reporting.
53      *
54      * @param context information about the invocation
55      */
invocationStarted(IInvocationContext context)56     public default void invocationStarted(IInvocationContext context) {}
57 
58     /**
59      * Reports that the invocation has terminated, whether successfully or due to some error
60      * condition.
61      * <p/>
62      * Will be automatically called by the TradeFederation framework.
63      *
64      * @param elapsedTime the elapsed time of the invocation in ms
65      */
invocationEnded(long elapsedTime)66     default public void invocationEnded(long elapsedTime) { }
67 
68     /**
69      * Reports an incomplete invocation due to some error condition.
70      * <p/>
71      * Will be automatically called by the TradeFederation framework.
72      *
73      * @param cause the {@link Throwable} cause of the failure
74      */
invocationFailed(Throwable cause)75     default public void invocationFailed(Throwable cause) { }
76 
77     /**
78      * Allows the InvocationListener to return a summary.
79      *
80      * @return A {@link TestSummary} summarizing the run, or null
81      */
getSummary()82     default public TestSummary getSummary() { return null; }
83 
84     /**
85      * Called on {@link ICommandScheduler#shutdown()}, gives the invocation the opportunity to do
86      * something before terminating.
87      */
invocationInterrupted()88     default public void invocationInterrupted() {
89         // do nothing in default implementation.
90     }
91 
92     /**
93      * Reports the beginning of a module running. This callback is associated with {@link
94      * #testModuleEnded()} and is optional in the sequence. It is only used during a run that uses
95      * modules: {@link ITestSuite} based runners.
96      *
97      * @param moduleContext the {@link IInvocationContext} of the module.
98      */
testModuleStarted(IInvocationContext moduleContext)99     public default void testModuleStarted(IInvocationContext moduleContext) {}
100 
101     /** Reports the end of a module run. */
testModuleEnded()102     public default void testModuleEnded() {}
103 }
104