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     /** Optional for a module configuration, the original name of the module. */
71     private String mModuleName = null;
72 
73     /** Returns the list of suite tags the test is part of. */
getSuiteTags()74     public List<String> getSuiteTags() {
75         return mSuiteTags;
76     }
77 
78     /** Sets the list of suite tags the test is part of. */
setSuiteTags(List<String> suiteTags)79     public void setSuiteTags(List<String> suiteTags) {
80         mSuiteTags = suiteTags;
81     }
82 
83     /** Retrieves all configured metadata and return a copy of the map. */
getAllMetaData()84     public MultiMap<String, String> getAllMetaData() {
85         MultiMap<String, String> copy = new MultiMap<>();
86         copy.putAll(mMetaData);
87         return copy;
88     }
89 
90     /** Get the named metadata entries */
getMetaData(String name)91     public List<String> getMetaData(String name) {
92         return mMetaData.get(name);
93     }
94 
95     @VisibleForTesting
setMetaData(MultiMap<String, String> metadata)96     public void setMetaData(MultiMap<String, String> metadata) {
97         mMetaData = metadata;
98     }
99 
100     /** Returns if the configuration is shardable or not as part of a suite */
isNotShardable()101     public boolean isNotShardable() {
102         return mNotShardable;
103     }
104 
105     /** Returns if the configuration is strict shardable or not as part of a suite */
isNotStrictShardable()106     public boolean isNotStrictShardable() {
107         return mNotStrictShardable;
108     }
109 
110     /** Sets the abi the configuration is going to run against. */
setAbi(IAbi abi)111     public void setAbi(IAbi abi) {
112         mAbi = abi;
113     }
114 
115     /** Returns the abi the configuration is running against if known, null otherwise. */
getAbi()116     public IAbi getAbi() {
117         return mAbi;
118     }
119 
120     /** If this configuration represents a module, we can set the module name associated with it. */
setModuleName(String name)121     public void setModuleName(String name) {
122         mModuleName = name;
123     }
124 
125     /** Returns the module name of the module configuration. */
getModuleName()126     public String getModuleName() {
127         return mModuleName;
128     }
129 
130     /** Returns true if the invocation should run in sandboxed mode. False otherwise. */
shouldUseSandbox()131     public boolean shouldUseSandbox() {
132         return mUseSandboxing;
133     }
134 
135     /** Sets whether or not a config will run in sandboxed mode or not. */
setSandboxed(boolean useSandboxed)136     public void setSandboxed(boolean useSandboxed) {
137         mUseSandboxing = useSandboxed;
138     }
139 }
140