1 /* 2 * Copyright (C) 2018 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.testtype.suite.retry; 17 18 import com.android.tradefed.result.TestResult; 19 import com.android.tradefed.result.TestRunResult; 20 import com.android.tradefed.result.TestStatus; 21 import com.android.tradefed.testtype.suite.retry.RetryRescheduler.RetryType; 22 23 import java.util.LinkedHashSet; 24 import java.util.List; 25 import java.util.Set; 26 27 /** Helper class to determine which module or test should run or not. */ 28 public final class RetryResultHelper { 29 30 /** Returns whether or not a module should be re-run. */ shouldRunModule(TestRunResult moduleResults, List<RetryType> types)31 public static boolean shouldRunModule(TestRunResult moduleResults, List<RetryType> types) { 32 if (moduleResults.isRunFailure() && types.contains(RetryType.NOT_EXECUTED)) { 33 // module has not_executed tests that should be re-run 34 return true; 35 } 36 // If module has some states that needs to be retried. 37 for (TestStatus status : getStatusesToRun(types)) { 38 if (moduleResults.getNumTestsInState(status) > 0) { 39 return true; 40 } 41 } 42 return false; 43 } 44 45 /** Returns whether or not a test case should be run or not. */ shouldRunTest(TestResult result, List<RetryType> types)46 public static boolean shouldRunTest(TestResult result, List<RetryType> types) { 47 if (getStatusesToRun(types).contains(result.getResultStatus())) { 48 return true; 49 } 50 return false; 51 } 52 getStatusesToRun(List<RetryType> types)53 private static Set<TestStatus> getStatusesToRun(List<RetryType> types) { 54 Set<TestStatus> statusesToRun = new LinkedHashSet<>(); 55 if (types.contains(RetryType.FAILED)) { 56 statusesToRun.add(TestStatus.FAILURE); 57 statusesToRun.add(TestStatus.SKIPPED); 58 statusesToRun.add(TestStatus.INCOMPLETE); 59 } 60 if (types.contains(RetryType.NOT_EXECUTED)) { 61 statusesToRun.add(TestStatus.INCOMPLETE); 62 statusesToRun.add(TestStatus.SKIPPED); 63 } 64 return statusesToRun; 65 } 66 } 67