1 /* 2 * Copyright (C) 2017 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.device.metric; 17 18 import com.android.tradefed.build.IBuildInfo; 19 import com.android.tradefed.device.ITestDevice; 20 import com.android.tradefed.invoker.IInvocationContext; 21 import com.android.tradefed.metrics.proto.MetricMeasurement.Metric; 22 import com.android.tradefed.result.ITestInvocationListener; 23 import com.android.tradefed.result.TestDescription; 24 import com.android.tradefed.util.IDisableable; 25 26 import java.util.List; 27 import java.util.Map; 28 29 /** 30 * This interface will be added as a decorator when reporting tests results in order to collect 31 * matching metrics. 32 * 33 * <p>This interface cannot be used as a <result_reporter> even it extends {@link 34 * ITestInvocationListener}. The configuration checking will reject it. It must be used as a 35 * "metrics_collector". 36 * 37 * <p>Collectors are not expected to keep an internal state as they may be re-used in several 38 * places. If an internal state really must be used, then it should be cleaned on {@link 39 * #init(IInvocationContext, ITestInvocationListener)}. 40 */ 41 public interface IMetricCollector extends ITestInvocationListener, IDisableable { 42 43 /** 44 * Initialization of the collector with the current context and where to forward results. Will 45 * only be called once per instance, and the collector is expected to update its internal 46 * context and listener. Init will never be called during a test run always before. 47 * 48 * <p>Do not override unless you know what you are doing. 49 * 50 * @param context the {@link IInvocationContext} for the invocation in progress. 51 * @param listener the {@link ITestInvocationListener} where to put results. 52 * @return the new listener wrapping the original one. 53 */ init( IInvocationContext context, ITestInvocationListener listener)54 public ITestInvocationListener init( 55 IInvocationContext context, ITestInvocationListener listener); 56 57 /** Returns the list of devices available in the invocation. */ getDevices()58 public List<ITestDevice> getDevices(); 59 60 /** Returns the list of build information available in the invocation. */ getBuildInfos()61 public List<IBuildInfo> getBuildInfos(); 62 63 /** Returns the original {@link ITestInvocationListener} where we are forwarding the results. */ getInvocationListener()64 public ITestInvocationListener getInvocationListener(); 65 66 /** 67 * Callback when a test run is started. 68 * 69 * @param runData the {@link DeviceMetricData} holding the data for the run. 70 */ onTestRunStart(DeviceMetricData runData)71 public void onTestRunStart(DeviceMetricData runData); 72 73 /** 74 * Callback when a test run is ended. This should be the time for clean up. 75 * 76 * @param runData the {@link DeviceMetricData} holding the data for the run. Will be the same 77 * object as during {@link #onTestRunStart(DeviceMetricData)}. 78 * @param currentRunMetrics the current map of metrics passed to {@link #testRunEnded(long, 79 * Map)}. 80 */ onTestRunEnd(DeviceMetricData runData, final Map<String, Metric> currentRunMetrics)81 public void onTestRunEnd(DeviceMetricData runData, final Map<String, Metric> currentRunMetrics); 82 83 /** 84 * Callback when a test case is started. 85 * 86 * @param testData the {@link DeviceMetricData} holding the data for the test case. 87 */ onTestStart(DeviceMetricData testData)88 public void onTestStart(DeviceMetricData testData); 89 90 /** 91 * Callback when a test case fails. 92 * 93 * @param testData the {@link DeviceMetricData} holding the data for the test case. 94 * @param test the {@link TestDescription} of the test case in progress. 95 */ onTestFail(DeviceMetricData testData, TestDescription test)96 public void onTestFail(DeviceMetricData testData, TestDescription test); 97 98 /** 99 * Callback when a test case fails with assumption failure. 100 * 101 * @param testData the {@link DeviceMetricData} holding the data for the test case. 102 * @param test the {@link TestDescription} of the test case in progress. 103 */ onTestAssumptionFailure(DeviceMetricData testData, TestDescription test)104 public void onTestAssumptionFailure(DeviceMetricData testData, TestDescription test); 105 106 /** 107 * Callback when a test case is ended. This should be the time for clean up. 108 * 109 * @param testData the {@link DeviceMetricData} holding the data for the test case. Will be the 110 * same object as during {@link #onTestStart(DeviceMetricData)}. 111 * @param currentTestCaseMetrics the current map of metrics passed to {@link 112 * #testEnded(TestDescription, Map)}. 113 */ onTestEnd( DeviceMetricData testData, final Map<String, Metric> currentTestCaseMetrics)114 public void onTestEnd( 115 DeviceMetricData testData, final Map<String, Metric> currentTestCaseMetrics); 116 117 /** 118 * Callback when a test case is ended. This should be the time for clean up. 119 * 120 * @param testData the {@link DeviceMetricData} holding the data for the test case. Will be the 121 * same object as during {@link #onTestStart(DeviceMetricData)}. 122 * @param currentTestCaseMetrics the current map of metrics passed to {@link 123 * #testEnded(TestDescription, Map)}. 124 * @param test the {@link TestDescription} of the test case in progress. 125 */ onTestEnd( DeviceMetricData testData, final Map<String, Metric> currentTestCaseMetrics, TestDescription test)126 public void onTestEnd( 127 DeviceMetricData testData, 128 final Map<String, Metric> currentTestCaseMetrics, 129 TestDescription test); 130 } 131