Home | History | Annotate | Download | only in config
      1 /*
      2  * Copyright (C) 2016 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.config;
     17 
     18 import com.android.tradefed.build.BuildSerializedVersion;
     19 import com.android.tradefed.testtype.IAbi;
     20 import com.android.tradefed.util.MultiMap;
     21 
     22 import com.google.common.annotations.VisibleForTesting;
     23 
     24 import java.io.Serializable;
     25 import java.util.ArrayList;
     26 import java.util.List;
     27 
     28 /**
     29  * Configuration Object that describes some aspect of the configuration itself. Like a membership
     30  * test-suite-tag. This class cannot receive option values via command line. Only directly in the
     31  * xml.
     32  */
     33 @OptionClass(alias = "config-descriptor")
     34 public class ConfigurationDescriptor implements Serializable {
     35     private static final long serialVersionUID = BuildSerializedVersion.VERSION;
     36 
     37     @Option(name = "test-suite-tag", description = "A membership tag to suite. Can be repeated.")
     38     private List<String> mSuiteTags = new ArrayList<>();
     39 
     40     @Option(name = "metadata", description = "Metadata associated with this configuration, can be "
     41             + "free formed key value pairs, and a key may be associated with multiple values.")
     42     private MultiMap<String, String> mMetaData = new MultiMap<>();
     43 
     44     @Option(
     45         name = "not-shardable",
     46         description =
     47                 "A metadata that allows a suite configuration to specify that it cannot be "
     48                         + "sharded. Not because it doesn't support it but because it doesn't make "
     49                         + "sense."
     50     )
     51     private boolean mNotShardable = false;
     52 
     53     @Option(
     54         name = "not-strict-shardable",
     55         description =
     56                 "A metadata to allows a suite configuration to specify that it cannot be "
     57                         + "sharded in a strict context (independent shards). If a config is already "
     58                         + "not-shardable, it will be not-strict-shardable."
     59     )
     60     private boolean mNotStrictShardable = false;
     61 
     62     @Option(
     63         name = "use-sandboxing",
     64         description = "Option used to notify an invocation that it is running in a sandbox."
     65     )
     66     private boolean mUseSandboxing = false;
     67 
     68     /** Optional Abi information the configuration will be run against. */
     69     private IAbi mAbi = null;
     70 
     71     /** Returns the list of suite tags the test is part of. */
     72     public List<String> getSuiteTags() {
     73         return mSuiteTags;
     74     }
     75 
     76     /** Sets the list of suite tags the test is part of. */
     77     public void setSuiteTags(List<String> suiteTags) {
     78         mSuiteTags = suiteTags;
     79     }
     80 
     81     /** Retrieves all configured metadata */
     82     public MultiMap<String, String> getAllMetaData() {
     83         return mMetaData;
     84     }
     85 
     86     /** Get the named metadata entries */
     87     public List<String> getMetaData(String name) {
     88         return mMetaData.get(name);
     89     }
     90 
     91     @VisibleForTesting
     92     public void setMetaData(MultiMap<String, String> metadata) {
     93         mMetaData = metadata;
     94     }
     95 
     96     /** Returns if the configuration is shardable or not as part of a suite */
     97     public boolean isNotShardable() {
     98         return mNotShardable;
     99     }
    100 
    101     /** Returns if the configuration is strict shardable or not as part of a suite */
    102     public boolean isNotStrictShardable() {
    103         return mNotStrictShardable;
    104     }
    105 
    106     /** Sets the abi the configuration is going to run against. */
    107     public void setAbi(IAbi abi) {
    108         mAbi = abi;
    109     }
    110 
    111     /** Returns the abi the configuration is running against if known, null otherwise. */
    112     public IAbi getAbi() {
    113         return mAbi;
    114     }
    115 
    116     /** Returns true if the invocation should run in sandboxed mode. False otherwise. */
    117     public boolean shouldUseSandbox() {
    118         return mUseSandboxing;
    119     }
    120 
    121     /** Sets whether or not a config will run in sandboxed mode or not. */
    122     public void setSandboxed(boolean useSandboxed) {
    123         mUseSandboxing = useSandboxed;
    124     }
    125 }
    126