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 17 package com.android.tradefed.invoker; 18 19 import com.android.tradefed.clearcut.ClearcutClient; 20 import com.android.tradefed.command.CommandRunner.ExitCode; 21 import com.android.tradefed.config.IConfiguration; 22 import com.android.tradefed.device.DeviceNotAvailableException; 23 import com.android.tradefed.result.ITestInvocationListener; 24 import com.android.tradefed.result.error.ErrorIdentifier; 25 26 /** 27 * Handles one TradeFederation test invocation. 28 */ 29 public interface ITestInvocation { 30 31 /** 32 * Perform the test invocation. 33 * 34 * @param metadata the {@link IInvocationContext} to perform tests. 35 * @param config the {@link IConfiguration} of this test run. 36 * @param rescheduler the {@link IRescheduler}, for rescheduling portions of the invocation for 37 * execution on another resource(s) 38 * @param extraListeners {@link ITestInvocationListener}s to notify, in addition to those in 39 * <var>config</var> 40 * @throws DeviceNotAvailableException if communication with device was lost 41 * @throws Throwable 42 */ invoke(IInvocationContext metadata, IConfiguration config, IRescheduler rescheduler, ITestInvocationListener... extraListeners)43 public void invoke(IInvocationContext metadata, IConfiguration config, 44 IRescheduler rescheduler, ITestInvocationListener... extraListeners) 45 throws DeviceNotAvailableException, Throwable; 46 47 /** 48 * Notify the {@link TestInvocation} that TradeFed has been requested to stop. 49 * 50 * @param message The message associated with stopping the invocation 51 * @param errorId Identifier associated with the forced stop 52 */ notifyInvocationForceStopped(String message, ErrorIdentifier errorId)53 public default void notifyInvocationForceStopped(String message, ErrorIdentifier errorId) {} 54 55 /** 56 * Notify the {@link TestInvocation} that TradeFed will eventually shutdown. 57 * 58 * @param message The message associated with stopping the invocation 59 */ notifyInvocationStopped(String message)60 public default void notifyInvocationStopped(String message) {} 61 62 /** The exit information of the given invocation. */ getExitInfo()63 public default ExitInformation getExitInfo() { 64 return new ExitInformation(); 65 } 66 67 /** Forward the clearcut client to report metrics. */ setClearcutClient(ClearcutClient client)68 public default void setClearcutClient(ClearcutClient client) { 69 // Do nothing by default 70 } 71 72 /** Represents some exit information for an invocation. */ 73 public class ExitInformation { 74 public ExitCode mExitCode = ExitCode.NO_ERROR; 75 public Throwable mStack = null; 76 } 77 } 78