Julien Desprez | ece3f40 | 2016-11-21 15:56:56 +0000 | [diff] [blame] | 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; |
Julien Desprez | 3e4d47d | 2018-05-23 15:53:40 -0700 | [diff] [blame] | 20 | import com.android.tradefed.suite.checker.StatusCheckerResult.CheckStatus; |
Julien Desprez | ece3f40 | 2016-11-21 15:56:56 +0000 | [diff] [blame] | 21 | |
| 22 | /** |
Julien Desprez | 3e4d47d | 2018-05-23 15:53:40 -0700 | [diff] [blame] | 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 |
Julien Desprez | ece3f40 | 2016-11-21 15:56:56 +0000 | [diff] [blame] | 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. |
Julien Desprez | 3e4d47d | 2018-05-23 15:53:40 -0700 | [diff] [blame] | 29 | * |
| 30 | * <p>The return {@link StatusCheckerResult} describing the results. May have an error message set |
| 31 | * in case of failure. |
Julien Desprez | ece3f40 | 2016-11-21 15:56:56 +0000 | [diff] [blame] | 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. |
Julien Desprez | 3e4d47d | 2018-05-23 15:53:40 -0700 | [diff] [blame] | 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. |
Julien Desprez | ece3f40 | 2016-11-21 15:56:56 +0000 | [diff] [blame] | 43 | * |
| 44 | * @param device The {@link ITestDevice} on which to run the checks. |
| 45 | * @return result of system status check |
| 46 | * @throws DeviceNotAvailableException |
| 47 | */ |
Julien Desprez | 3e4d47d | 2018-05-23 15:53:40 -0700 | [diff] [blame] | 48 | public default StatusCheckerResult preExecutionCheck(ITestDevice device) |
Julien Desprez | ece3f40 | 2016-11-21 15:56:56 +0000 | [diff] [blame] | 49 | throws DeviceNotAvailableException { |
Julien Desprez | 3e4d47d | 2018-05-23 15:53:40 -0700 | [diff] [blame] | 50 | return new StatusCheckerResult(CheckStatus.SUCCESS); |
Julien Desprez | ece3f40 | 2016-11-21 15:56:56 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | /** |
Julien Desprez | 3e4d47d | 2018-05-23 15:53:40 -0700 | [diff] [blame] | 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. |
Julien Desprez | ece3f40 | 2016-11-21 15:56:56 +0000 | [diff] [blame] | 57 | * |
| 58 | * @param device The {@link ITestDevice} on which to run the checks. |
| 59 | * @return result of system status check |
| 60 | * @throws DeviceNotAvailableException |
| 61 | */ |
Julien Desprez | 3e4d47d | 2018-05-23 15:53:40 -0700 | [diff] [blame] | 62 | public default StatusCheckerResult postExecutionCheck(ITestDevice device) |
Julien Desprez | ece3f40 | 2016-11-21 15:56:56 +0000 | [diff] [blame] | 63 | throws DeviceNotAvailableException { |
Julien Desprez | 3e4d47d | 2018-05-23 15:53:40 -0700 | [diff] [blame] | 64 | return new StatusCheckerResult(CheckStatus.SUCCESS); |
Julien Desprez | ece3f40 | 2016-11-21 15:56:56 +0000 | [diff] [blame] | 65 | } |
| 66 | } |