1 /* 2 * Copyright (C) 2024 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.log.LogUtil.CLog; 19 20 /** Representation in Tradefed of possible statuses for test methods. */ 21 public enum TestStatus { 22 /** Test failed. */ 23 FAILURE, 24 /** Test passed */ 25 PASSED, 26 /** Test started but not ended */ 27 INCOMPLETE, 28 /** Test assumption failure */ 29 ASSUMPTION_FAILURE, 30 /** Test ignored */ 31 IGNORED, 32 /** Test skipped, did not run for a reason */ 33 SKIPPED; 34 35 /** Convert Tradefed status to ddmlib one during the transition of classes. */ convertToDdmlibType( TestStatus status)36 public static com.android.ddmlib.testrunner.TestResult.TestStatus convertToDdmlibType( 37 TestStatus status) { 38 switch (status) { 39 case FAILURE: 40 return com.android.ddmlib.testrunner.TestResult.TestStatus.FAILURE; 41 case PASSED: 42 return com.android.ddmlib.testrunner.TestResult.TestStatus.PASSED; 43 case INCOMPLETE: 44 return com.android.ddmlib.testrunner.TestResult.TestStatus.INCOMPLETE; 45 case ASSUMPTION_FAILURE: 46 return com.android.ddmlib.testrunner.TestResult.TestStatus.ASSUMPTION_FAILURE; 47 case IGNORED: 48 return com.android.ddmlib.testrunner.TestResult.TestStatus.IGNORED; 49 case SKIPPED: 50 CLog.w("Retrofit SKIPPED into PASSED"); 51 return com.android.ddmlib.testrunner.TestResult.TestStatus.PASSED; 52 default: 53 return com.android.ddmlib.testrunner.TestResult.TestStatus.PASSED; 54 } 55 } 56 convertFromDdmlibType( com.android.ddmlib.testrunner.TestResult.TestStatus ddmlibStatus)57 public static TestStatus convertFromDdmlibType( 58 com.android.ddmlib.testrunner.TestResult.TestStatus ddmlibStatus) { 59 switch (ddmlibStatus) { 60 case ASSUMPTION_FAILURE: 61 return TestStatus.ASSUMPTION_FAILURE; 62 case FAILURE: 63 return TestStatus.FAILURE; 64 case IGNORED: 65 return TestStatus.IGNORED; 66 case INCOMPLETE: 67 return TestStatus.INCOMPLETE; 68 case PASSED: 69 return TestStatus.PASSED; 70 default: 71 return TestStatus.PASSED; 72 } 73 } 74 75 /** Convert Tradefed status to a format compatible with Android Partner backend. */ convertToCompatibilityString(TestStatus status)76 public static String convertToCompatibilityString(TestStatus status) { 77 switch (status) { 78 case PASSED: 79 return "pass"; 80 case FAILURE: 81 return "fail"; 82 default: 83 return status.toString(); 84 } 85 } 86 87 /** Convert Tradefed status from a format compatible with Android Partner backend. */ convertFromCompatibilityString(String status)88 public static TestStatus convertFromCompatibilityString(String status) { 89 switch (status) { 90 case "pass": 91 return TestStatus.PASSED; 92 case "fail": 93 return TestStatus.FAILURE; 94 default: 95 return TestStatus.valueOf(status); 96 } 97 } 98 } 99