1 /* 2 * Copyright (C) 2021 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.targetprep; 18 19 import com.android.tradefed.config.ConfigurationException; 20 import com.android.tradefed.config.IConfiguration; 21 import com.android.tradefed.config.IConfigurationReceiver; 22 import com.android.tradefed.config.Option; 23 import com.android.tradefed.config.OptionClass; 24 import com.android.tradefed.device.DeviceNotAvailableException; 25 import com.android.tradefed.error.HarnessRuntimeException; 26 import com.android.tradefed.invoker.TestInformation; 27 28 import java.util.HashSet; 29 import java.util.Set; 30 31 /** Target preparer to skip retrying known failure. */ 32 @OptionClass(alias = "known-failure-preparer") 33 public class KnownFailurePreparer extends BaseTargetPreparer implements IConfigurationReceiver { 34 35 @Option( 36 name = "known-failure-list", 37 description = "A collection of known failing tests to skip retrying.") 38 private Set<String> mKnownFailureList = new HashSet<>(); 39 40 private IConfiguration mConfig; 41 private static final String SKIP_RETRYING_LIST = "skip-retrying-list"; 42 43 @Override setUp(TestInformation testInfo)44 public void setUp(TestInformation testInfo) 45 throws TargetSetupError, BuildError, DeviceNotAvailableException { 46 if (!mKnownFailureList.isEmpty()) { 47 try { 48 for (String knownFailureModule : mKnownFailureList) { 49 mConfig.injectOptionValue(SKIP_RETRYING_LIST, knownFailureModule); 50 } 51 } catch (ConfigurationException e) { 52 throw new HarnessRuntimeException(e.getMessage(), e); 53 } 54 } 55 } 56 57 @Override setConfiguration(IConfiguration configuration)58 public void setConfiguration(IConfiguration configuration) { 59 mConfig = configuration; 60 } 61 } 62