1 /* 2 * Copyright (C) 2010 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.config; 18 19 import com.android.tradefed.build.BuildRetrievalError; 20 import com.android.tradefed.build.IBuildProvider; 21 import com.android.tradefed.command.ICommandOptions; 22 import com.android.tradefed.device.IDeviceRecovery; 23 import com.android.tradefed.device.IDeviceSelection; 24 import com.android.tradefed.device.TestDeviceOptions; 25 import com.android.tradefed.device.metric.IMetricCollector; 26 import com.android.tradefed.log.ILeveledLogOutput; 27 import com.android.tradefed.postprocessor.IPostProcessor; 28 import com.android.tradefed.result.ILogSaver; 29 import com.android.tradefed.result.ITestInvocationListener; 30 import com.android.tradefed.retry.IRetryDecision; 31 import com.android.tradefed.suite.checker.ISystemStatusChecker; 32 import com.android.tradefed.targetprep.ITargetPreparer; 33 import com.android.tradefed.targetprep.multi.IMultiTargetPreparer; 34 import com.android.tradefed.testtype.IRemoteTest; 35 import com.android.tradefed.testtype.coverage.CoverageOptions; 36 import com.android.tradefed.util.keystore.IKeyStoreClient; 37 38 import java.io.File; 39 import java.io.IOException; 40 import java.io.PrintStream; 41 import java.io.PrintWriter; 42 import java.util.Collection; 43 import java.util.List; 44 import java.util.Set; 45 46 /** 47 * Configuration information for a TradeFederation invocation. 48 * 49 * Each TradeFederation invocation has a single {@link IConfiguration}. An {@link IConfiguration} 50 * stores all the delegate objects that should be used during the invocation, and their associated 51 * {@link Option}'s 52 */ 53 public interface IConfiguration { 54 55 /** Returns the name of the configuration. */ getName()56 public String getName(); 57 58 /** 59 * Gets the {@link IBuildProvider} from the configuration. 60 * 61 * @return the {@link IBuildProvider} provided in the configuration 62 */ getBuildProvider()63 public IBuildProvider getBuildProvider(); 64 65 /** 66 * Gets the {@link ITargetPreparer}s from the configuration. 67 * 68 * @return the {@link ITargetPreparer}s provided in order in the configuration 69 */ getTargetPreparers()70 public List<ITargetPreparer> getTargetPreparers(); 71 72 /** 73 * Gets the {@link IRemoteTest}s to run from the configuration. 74 * 75 * @return the tests provided in the configuration 76 */ getTests()77 public List<IRemoteTest> getTests(); 78 79 /** 80 * Gets the {@link ITestInvocationListener}s to use from the configuration. 81 * 82 * @return the {@link ITestInvocationListener}s provided in the configuration. 83 */ getTestInvocationListeners()84 public List<ITestInvocationListener> getTestInvocationListeners(); 85 86 /** 87 * Gets the {@link IDeviceRecovery} to use from the configuration. 88 * 89 * @return the {@link IDeviceRecovery} provided in the configuration. 90 */ getDeviceRecovery()91 public IDeviceRecovery getDeviceRecovery(); 92 93 /** 94 * Gets the {@link TestDeviceOptions} to use from the configuration. 95 * 96 * @return the {@link TestDeviceOptions} provided in the configuration. 97 */ getDeviceOptions()98 public TestDeviceOptions getDeviceOptions(); 99 100 /** 101 * Gets the {@link ILeveledLogOutput} to use from the configuration. 102 * 103 * @return the {@link ILeveledLogOutput} provided in the configuration. 104 */ getLogOutput()105 public ILeveledLogOutput getLogOutput(); 106 107 /** 108 * Gets the {@link ILogSaver} to use from the configuration. 109 * 110 * @return the {@link ILogSaver} provided in the configuration. 111 */ getLogSaver()112 public ILogSaver getLogSaver(); 113 114 /** Returns the {@link IRetryDecision} used for the invocation. */ getRetryDecision()115 public IRetryDecision getRetryDecision(); 116 117 /** 118 * Gets the {@link IMultiTargetPreparer}s from the configuration. 119 * 120 * @return the {@link IMultiTargetPreparer}s provided in order in the configuration 121 */ getMultiTargetPreparers()122 public List<IMultiTargetPreparer> getMultiTargetPreparers(); 123 124 /** 125 * Gets the {@link IMultiTargetPreparer}s from the configuration that should be executed before 126 * any of the devices target_preparers. 127 * 128 * @return the {@link IMultiTargetPreparer}s provided in order in the configuration 129 */ getMultiPreTargetPreparers()130 public List<IMultiTargetPreparer> getMultiPreTargetPreparers(); 131 132 /** 133 * Gets the {@link ISystemStatusChecker}s from the configuration. 134 * 135 * @return the {@link ISystemStatusChecker}s provided in order in the configuration 136 */ getSystemStatusCheckers()137 public List<ISystemStatusChecker> getSystemStatusCheckers(); 138 139 /** Gets the {@link IMetricCollector}s from the configuration. */ getMetricCollectors()140 public List<IMetricCollector> getMetricCollectors(); 141 142 /** Gets the {@link IPostProcessor}s from the configuration. */ getPostProcessors()143 public List<IPostProcessor> getPostProcessors(); 144 145 /** 146 * Gets the {@link ICommandOptions} to use from the configuration. 147 * 148 * @return the {@link ICommandOptions} provided in the configuration. 149 */ getCommandOptions()150 public ICommandOptions getCommandOptions(); 151 152 /** Returns the {@link ConfigurationDescriptor} provided in the configuration. */ getConfigurationDescription()153 public ConfigurationDescriptor getConfigurationDescription(); 154 155 /** 156 * Gets the {@link IDeviceSelection} to use from the configuration. 157 * 158 * @return the {@link IDeviceSelection} provided in the configuration. 159 */ getDeviceRequirements()160 public IDeviceSelection getDeviceRequirements(); 161 162 /** 163 * Gets the {@link CoverageOptions} to use from the configuration. 164 * 165 * @return the {@link CoverageOptions} provided in the configuration. 166 */ getCoverageOptions()167 public CoverageOptions getCoverageOptions(); 168 169 /** 170 * Generic interface to get the configuration object with the given type name. 171 * 172 * @param typeName the unique type of the configuration object 173 * 174 * @return the configuration object or <code>null</code> if the object type with given name 175 * does not exist. 176 */ getConfigurationObject(String typeName)177 public Object getConfigurationObject(String typeName); 178 179 /** 180 * Generic interface to get all the object of one given type name across devices. 181 * 182 * @param typeName the unique type of the configuration object 183 * @return The list of configuration objects of the given type. 184 */ getAllConfigurationObjectsOfType(String typeName)185 public Collection<Object> getAllConfigurationObjectsOfType(String typeName); 186 187 /** 188 * Similar to {@link #getConfigurationObject(String)}, but for configuration 189 * object types that support multiple objects. 190 * 191 * @param typeName the unique type name of the configuration object 192 * 193 * @return the list of configuration objects or <code>null</code> if the object type with 194 * given name does not exist. 195 */ getConfigurationObjectList(String typeName)196 public List<?> getConfigurationObjectList(String typeName); 197 198 /** 199 * Gets the {@link IDeviceConfiguration}s from the configuration. 200 * 201 * @return the {@link IDeviceConfiguration}s provided in order in the configuration 202 */ getDeviceConfig()203 public List<IDeviceConfiguration> getDeviceConfig(); 204 205 /** 206 * Return the {@link IDeviceConfiguration} associated to the name provided, null if not found. 207 */ getDeviceConfigByName(String nameDevice)208 public IDeviceConfiguration getDeviceConfigByName(String nameDevice); 209 210 /** 211 * Inject a option value into the set of configuration objects. 212 * <p/> 213 * Useful to provide values for options that are generated dynamically. 214 * 215 * @param optionName the option name 216 * @param optionValue the option value 217 * @throws ConfigurationException if failed to set the option's value 218 */ injectOptionValue(String optionName, String optionValue)219 public void injectOptionValue(String optionName, String optionValue) 220 throws ConfigurationException; 221 222 /** 223 * Inject a option value into the set of configuration objects. 224 * <p/> 225 * Useful to provide values for options that are generated dynamically. 226 * 227 * @param optionName the option name 228 * @param optionKey the optional key for map options, or null 229 * @param optionValue the map option value 230 * @throws ConfigurationException if failed to set the option's value 231 */ injectOptionValue(String optionName, String optionKey, String optionValue)232 public void injectOptionValue(String optionName, String optionKey, String optionValue) 233 throws ConfigurationException; 234 235 /** 236 * Inject a option value into the set of configuration objects. 237 * <p/> 238 * Useful to provide values for options that are generated dynamically. 239 * 240 * @param optionName the option name 241 * @param optionKey the optional key for map options, or null 242 * @param optionValue the map option value 243 * @param optionSource the source config that provided this option value 244 * @throws ConfigurationException if failed to set the option's value 245 */ injectOptionValueWithSource(String optionName, String optionKey, String optionValue, String optionSource)246 public void injectOptionValueWithSource(String optionName, String optionKey, String optionValue, 247 String optionSource) throws ConfigurationException; 248 249 /** 250 * Inject multiple option values into the set of configuration objects. 251 * <p/> 252 * Useful to inject many option values at once after creating a new object. 253 * 254 * @param optionDefs a list of option defs to inject 255 * @throws ConfigurationException if failed to set option values 256 */ injectOptionValues(List<OptionDef> optionDefs)257 public void injectOptionValues(List<OptionDef> optionDefs) throws ConfigurationException; 258 259 /** 260 * Inject multiple option values into the set of configuration objects without throwing if one 261 * of the option cannot be applied. 262 * 263 * <p>Useful to inject many option values at once after creating a new object. 264 * 265 * @param optionDefs a list of option defs to inject 266 * @throws ConfigurationException if failed to create the {@link OptionSetter} 267 */ safeInjectOptionValues(List<OptionDef> optionDefs)268 public void safeInjectOptionValues(List<OptionDef> optionDefs) throws ConfigurationException; 269 270 /** 271 * Create a shallow copy of this object. 272 * 273 * @return a {link IConfiguration} copy 274 */ clone()275 public IConfiguration clone(); 276 277 /** 278 * Create a base clone from {@link #clone()} then deep clone the list of given config object. 279 * 280 * @param objectToDeepClone The list of configuration object to deep clone. 281 * @param client The keystore client. 282 * @return The partially deep cloned config. 283 * @throws ConfigurationException 284 */ partialDeepClone(List<String> objectToDeepClone, IKeyStoreClient client)285 public IConfiguration partialDeepClone(List<String> objectToDeepClone, IKeyStoreClient client) 286 throws ConfigurationException; 287 288 /** 289 * Replace the current {@link IBuildProvider} in the configuration. 290 * 291 * @param provider the new {@link IBuildProvider} 292 */ setBuildProvider(IBuildProvider provider)293 public void setBuildProvider(IBuildProvider provider); 294 295 /** 296 * Set the {@link ILeveledLogOutput}, replacing any existing value. 297 * 298 * @param logger 299 */ setLogOutput(ILeveledLogOutput logger)300 public void setLogOutput(ILeveledLogOutput logger); 301 302 /** 303 * Set the {@link IRetryDecision}, replacing any existing value. 304 * 305 * @param decisionRetry 306 */ setRetryDecision(IRetryDecision decisionRetry)307 public void setRetryDecision(IRetryDecision decisionRetry); 308 309 /** 310 * Set the {@link ILogSaver}, replacing any existing value. 311 * 312 * @param logSaver 313 */ setLogSaver(ILogSaver logSaver)314 public void setLogSaver(ILogSaver logSaver); 315 316 /** 317 * Set the {@link IDeviceRecovery}, replacing any existing value. 318 * 319 * @param recovery 320 */ setDeviceRecovery(IDeviceRecovery recovery)321 public void setDeviceRecovery(IDeviceRecovery recovery); 322 323 /** 324 * Set the {@link ITargetPreparer}, replacing any existing value. 325 * 326 * @param preparer 327 */ setTargetPreparer(ITargetPreparer preparer)328 public void setTargetPreparer(ITargetPreparer preparer); 329 330 /** 331 * Set the list of {@link ITargetPreparer}s, replacing any existing value. 332 * 333 * @param preparers 334 */ setTargetPreparers(List<ITargetPreparer> preparers)335 public void setTargetPreparers(List<ITargetPreparer> preparers); 336 337 /** 338 * Set a {@link IDeviceConfiguration}, replacing any existing value. 339 * 340 * @param deviceConfig 341 */ setDeviceConfig(IDeviceConfiguration deviceConfig)342 public void setDeviceConfig(IDeviceConfiguration deviceConfig); 343 344 /** 345 * Set the {@link IDeviceConfiguration}s, replacing any existing value. 346 * 347 * @param deviceConfigs 348 */ setDeviceConfigList(List<IDeviceConfiguration> deviceConfigs)349 public void setDeviceConfigList(List<IDeviceConfiguration> deviceConfigs); 350 351 /** 352 * Convenience method to set a single {@link IRemoteTest} in this configuration, replacing any 353 * existing values 354 * 355 * @param test 356 */ setTest(IRemoteTest test)357 public void setTest(IRemoteTest test); 358 359 /** 360 * Set the list of {@link IRemoteTest}s in this configuration, replacing any 361 * existing values 362 * 363 * @param tests 364 */ setTests(List<IRemoteTest> tests)365 public void setTests(List<IRemoteTest> tests); 366 367 /** 368 * Set the list of {@link IMultiTargetPreparer}s in this configuration, replacing any 369 * existing values 370 * 371 * @param multiTargPreps 372 */ setMultiTargetPreparers(List<IMultiTargetPreparer> multiTargPreps)373 public void setMultiTargetPreparers(List<IMultiTargetPreparer> multiTargPreps); 374 375 /** 376 * Convenience method to set a single {@link IMultiTargetPreparer} in this configuration, 377 * replacing any existing values 378 * 379 * @param multiTargPrep 380 */ setMultiTargetPreparer(IMultiTargetPreparer multiTargPrep)381 public void setMultiTargetPreparer(IMultiTargetPreparer multiTargPrep); 382 383 /** 384 * Set the list of {@link IMultiTargetPreparer}s in this configuration that should be executed 385 * before any of the devices target_preparers, replacing any existing values 386 * 387 * @param multiPreTargPreps 388 */ setMultiPreTargetPreparers(List<IMultiTargetPreparer> multiPreTargPreps)389 public void setMultiPreTargetPreparers(List<IMultiTargetPreparer> multiPreTargPreps); 390 391 /** 392 * Convenience method to set a single {@link IMultiTargetPreparer} in this configuration that 393 * should be executed before any of the devices target_preparers, replacing any existing values 394 * 395 * @param multiPreTargPreps 396 */ setMultiPreTargetPreparer(IMultiTargetPreparer multiPreTargPreps)397 public void setMultiPreTargetPreparer(IMultiTargetPreparer multiPreTargPreps); 398 399 /** 400 * Set the list of {@link ISystemStatusChecker}s in this configuration, replacing any 401 * existing values 402 * 403 * @param systemCheckers 404 */ setSystemStatusCheckers(List<ISystemStatusChecker> systemCheckers)405 public void setSystemStatusCheckers(List<ISystemStatusChecker> systemCheckers); 406 407 /** 408 * Convenience method to set a single {@link ISystemStatusChecker} in this configuration, 409 * replacing any existing values 410 * 411 * @param systemChecker 412 */ setSystemStatusChecker(ISystemStatusChecker systemChecker)413 public void setSystemStatusChecker(ISystemStatusChecker systemChecker); 414 415 /** 416 * Set the list of {@link ITestInvocationListener}s, replacing any existing values 417 * 418 * @param listeners 419 */ setTestInvocationListeners(List<ITestInvocationListener> listeners)420 public void setTestInvocationListeners(List<ITestInvocationListener> listeners); 421 422 /** 423 * Convenience method to set a single {@link ITestInvocationListener} 424 * 425 * @param listener 426 */ setTestInvocationListener(ITestInvocationListener listener)427 public void setTestInvocationListener(ITestInvocationListener listener); 428 429 /** Set the list of {@link IMetricCollector}s, replacing any existing values. */ setDeviceMetricCollectors(List<IMetricCollector> collectors)430 public void setDeviceMetricCollectors(List<IMetricCollector> collectors); 431 432 /** Set the list of {@link IPostProcessor}s, replacing any existing values. */ setPostProcessors(List<IPostProcessor> processors)433 public void setPostProcessors(List<IPostProcessor> processors); 434 435 /** 436 * Set the {@link ICommandOptions}, replacing any existing values 437 * 438 * @param cmdOptions 439 */ setCommandOptions(ICommandOptions cmdOptions)440 public void setCommandOptions(ICommandOptions cmdOptions); 441 442 /** 443 * Set the {@link IDeviceSelection}, replacing any existing values 444 * 445 * @param deviceSelection 446 */ setDeviceRequirements(IDeviceSelection deviceSelection)447 public void setDeviceRequirements(IDeviceSelection deviceSelection); 448 449 /** 450 * Set the {@link TestDeviceOptions}, replacing any existing values 451 */ setDeviceOptions(TestDeviceOptions deviceOptions)452 public void setDeviceOptions(TestDeviceOptions deviceOptions); 453 454 /** Set the {@link CoverageOptions}, replacing any existing values. */ setCoverageOptions(CoverageOptions coverageOptions)455 public void setCoverageOptions(CoverageOptions coverageOptions); 456 457 /** 458 * Generic method to set the config object with the given name, replacing any existing value. 459 * 460 * @param name the unique name of the config object type. 461 * @param configObject the config object 462 * @throws ConfigurationException if the configObject was not the correct type 463 */ setConfigurationObject(String name, Object configObject)464 public void setConfigurationObject(String name, Object configObject) 465 throws ConfigurationException; 466 467 /** 468 * Generic method to set the config object list for the given name, replacing any existing 469 * value. 470 * 471 * @param name the unique name of the config object type. 472 * @param configList the config object list 473 * @throws ConfigurationException if any objects in the list are not the correct type 474 */ setConfigurationObjectList(String name, List<?> configList)475 public void setConfigurationObjectList(String name, List<?> configList) 476 throws ConfigurationException; 477 478 /** Returns whether or not a configured device is tagged isFake=true or not. */ isDeviceConfiguredFake(String deviceName)479 public boolean isDeviceConfiguredFake(String deviceName); 480 481 /** 482 * Set the config {@link Option} fields with given set of command line arguments 483 * <p/> 484 * {@link ArgsOptionParser} for expected format 485 * 486 * @param listArgs the command line arguments 487 * @return the unconsumed arguments 488 */ setOptionsFromCommandLineArgs(List<String> listArgs)489 public List<String> setOptionsFromCommandLineArgs(List<String> listArgs) 490 throws ConfigurationException; 491 492 /** 493 * Set the config {@link Option} fields with given set of command line arguments 494 * <p/> 495 * See {@link ArgsOptionParser} for expected format 496 * 497 * @param listArgs the command line arguments 498 * @param keyStoreClient {@link IKeyStoreClient} to use. 499 * @return the unconsumed arguments 500 */ setOptionsFromCommandLineArgs(List<String> listArgs, IKeyStoreClient keyStoreClient)501 public List<String> setOptionsFromCommandLineArgs(List<String> listArgs, 502 IKeyStoreClient keyStoreClient) 503 throws ConfigurationException; 504 505 /** 506 * Set the config {@link Option} fields with given set of command line arguments using a best 507 * effort approach. 508 * 509 * <p>See {@link ArgsOptionParser} for expected format 510 * 511 * @param listArgs the command line arguments 512 * @param keyStoreClient {@link IKeyStoreClient} to use. 513 * @return the unconsumed arguments 514 */ setBestEffortOptionsFromCommandLineArgs( List<String> listArgs, IKeyStoreClient keyStoreClient)515 public List<String> setBestEffortOptionsFromCommandLineArgs( 516 List<String> listArgs, IKeyStoreClient keyStoreClient) throws ConfigurationException; 517 518 /** 519 * Outputs a command line usage help text for this configuration to given printStream. 520 * 521 * @param importantOnly if <code>true</code> only print help for the important options 522 * @param out the {@link PrintStream} to use. 523 * @throws ConfigurationException 524 */ printCommandUsage(boolean importantOnly, PrintStream out)525 public void printCommandUsage(boolean importantOnly, PrintStream out) 526 throws ConfigurationException; 527 528 /** 529 * Validate option values. 530 * <p/> 531 * Currently this will just validate that all mandatory options have been set 532 * 533 * @throws ConfigurationException if config is not valid 534 */ validateOptions()535 public void validateOptions() throws ConfigurationException; 536 537 /** 538 * Resolve options of {@link File} pointing to a remote location. This requires {@link 539 * #cleanConfigurationData()} to be called to clean up the files. 540 * 541 * @param resolver the {@link DynamicRemoteFileResolver} to resolve the files 542 * @throws BuildRetrievalError 543 * @throws ConfigurationException 544 */ resolveDynamicOptions(DynamicRemoteFileResolver resolver)545 public void resolveDynamicOptions(DynamicRemoteFileResolver resolver) 546 throws ConfigurationException, BuildRetrievalError; 547 548 /** Delete any files that was downloaded to resolved Option fields of remote files. */ cleanConfigurationData()549 public void cleanConfigurationData(); 550 551 /** Add files that must be cleaned during {@link #cleanConfigurationData()} */ addFilesToClean(Set<File> toBeCleaned)552 public void addFilesToClean(Set<File> toBeCleaned); 553 554 /** Get the list of files that will be cleaned during {@link #cleanConfigurationData()} */ getFilesToClean()555 public Set<File> getFilesToClean(); 556 557 /** 558 * Sets the command line used to create this {@link IConfiguration}. 559 * This stores the whole command line, including the configuration name, 560 * unlike setOptionsFromCommandLineArgs. 561 * 562 * @param arrayArgs the command line 563 */ setCommandLine(String[] arrayArgs)564 public void setCommandLine(String[] arrayArgs); 565 566 /** 567 * Gets the command line used to create this {@link IConfiguration}. 568 * 569 * @return the command line used to create this {@link IConfiguration}. 570 */ getCommandLine()571 public String getCommandLine(); 572 573 /** 574 * Gets the expanded XML file for the config with all options shown for this 575 * {@link IConfiguration} as a {@link String}. 576 * 577 * @param output the writer to print the xml to. 578 * @throws IOException 579 */ dumpXml(PrintWriter output)580 public void dumpXml(PrintWriter output) throws IOException; 581 582 /** 583 * Gets the expanded XML file for the config with all options shown for this {@link 584 * IConfiguration} minus the objects filters by their key name. 585 * 586 * <p>Filter example: {@link Configuration#TARGET_PREPARER_TYPE_NAME}. 587 * 588 * @param output the writer to print the xml to. 589 * @param excludeFilters the list of object type that should not be dumped. 590 * @throws IOException 591 */ dumpXml(PrintWriter output, List<String> excludeFilters)592 public void dumpXml(PrintWriter output, List<String> excludeFilters) throws IOException; 593 594 /** 595 * Gets the expanded XML file for the config with all options shown for this {@link 596 * IConfiguration} minus the objects filters by their key name. 597 * 598 * <p>Filter example: {@link Configuration#TARGET_PREPARER_TYPE_NAME}. 599 * 600 * @param output the writer to print the xml to. 601 * @param excludeFilters the list of object type that should not be dumped. 602 * @param printDeprecatedOptions Whether or not to print options marked as deprecated 603 * @throws IOException 604 */ dumpXml( PrintWriter output, List<String> excludeFilters, boolean printDeprecatedOptions, boolean printUnchangedOptions)605 public void dumpXml( 606 PrintWriter output, 607 List<String> excludeFilters, 608 boolean printDeprecatedOptions, 609 boolean printUnchangedOptions) 610 throws IOException; 611 } 612