1 /* 2 * Copyright (C) 2016 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.suite.checker; 17 18 import com.android.tradefed.device.DeviceNotAvailableException; 19 import com.android.tradefed.device.ITestDevice; 20 import com.android.tradefed.suite.checker.StatusCheckerResult.CheckStatus; 21 22 /** 23 * An checker that performs checks on system status and returns a boolean to indicate if the system 24 * is in an expected state. Such check maybe performed either prior to or after a module execution. 25 * 26 * <p>Note: the checker must be reentrant: meaning that the same instance will be called multiple 27 * times for each module executed, so it should not leave a state so as to interfere with the checks 28 * to be performed for the following modules. 29 * 30 * <p>The return {@link StatusCheckerResult} describing the results. May have an error message set 31 * in case of failure. 32 */ 33 public interface ISystemStatusChecker { 34 35 /** 36 * Check system condition before test module execution. Subclass should override this method if 37 * a check is desirable here. Implementation must return a <code>boolean</code> value to 38 * indicate if the status check has passed or failed. 39 * 40 * <p>It's strongly recommended that system status be checked <strong>after</strong> module 41 * execution, and this method may be used for the purpose of caching certain system state prior 42 * to module execution. 43 * 44 * @param device The {@link ITestDevice} on which to run the checks. 45 * @return result of system status check 46 * @throws DeviceNotAvailableException 47 */ preExecutionCheck(ITestDevice device)48 public default StatusCheckerResult preExecutionCheck(ITestDevice device) 49 throws DeviceNotAvailableException { 50 return new StatusCheckerResult(CheckStatus.SUCCESS); 51 } 52 53 /** 54 * Check system condition after test module execution. Subclass should override this method if a 55 * check is desirable here. Implementation must return a <code>boolean</code> value to indicate 56 * if the status check has passed or failed. 57 * 58 * @param device The {@link ITestDevice} on which to run the checks. 59 * @return result of system status check 60 * @throws DeviceNotAvailableException 61 */ postExecutionCheck(ITestDevice device)62 public default StatusCheckerResult postExecutionCheck(ITestDevice device) 63 throws DeviceNotAvailableException { 64 return new StatusCheckerResult(CheckStatus.SUCCESS); 65 } 66 } 67