1 /* 2 * Copyright (C) 2017 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; 17 18 import com.android.tradefed.build.StubBuildProvider; 19 import com.android.tradefed.config.IConfiguration; 20 import com.android.tradefed.config.IDeviceConfiguration; 21 import com.android.tradefed.result.TextResultReporter; 22 23 /** 24 * This class will help validating that the {@link IConfiguration} loaded for the suite are meeting 25 * the expected requirements: - No Build providers - No Result reporters 26 */ 27 public class ValidateSuiteConfigHelper { 28 29 private ValidateSuiteConfigHelper() {} 30 31 /** 32 * Check that a configuration is properly built to run in a suite. 33 * 34 * @param config a {@link IConfiguration} to be checked if valide for suite. 35 * @return True if the config can be run, false otherwise. 36 */ 37 public static boolean validateConfig(IConfiguration config) { 38 if (!config.getBuildProvider().getClass().isAssignableFrom(StubBuildProvider.class)) { 39 return false; 40 } 41 // if a multi device config is presented, ensure none of the devices define a build_provider 42 for (IDeviceConfiguration deviceConfig : config.getDeviceConfig()) { 43 if (!deviceConfig 44 .getBuildProvider() 45 .getClass() 46 .isAssignableFrom(StubBuildProvider.class)) { 47 return false; 48 } 49 } 50 if (config.getTestInvocationListeners().size() != 1) { 51 return false; 52 } 53 if (!config.getTestInvocationListeners() 54 .get(0) 55 .getClass() 56 .isAssignableFrom(TextResultReporter.class)) { 57 return false; 58 } 59 return true; 60 } 61 } 62