• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.invoker;
17 
18 import com.android.tradefed.build.IBuildInfo;
19 import com.android.tradefed.config.ConfigurationDescriptor;
20 import com.android.tradefed.device.ITestDevice;
21 import com.android.tradefed.device.ITestDevice.RecoveryMode;
22 import com.android.tradefed.testtype.suite.ITestSuite;
23 import com.android.tradefed.util.MultiMap;
24 import com.android.tradefed.util.UniqueMultiMap;
25 
26 import java.io.Serializable;
27 import java.util.List;
28 import java.util.Map;
29 
30 /**
31  * Holds information about the Invocation for the tests to access if needed. Tests should not modify
32  * the context contained here so only getters will be available, except for the context attributes
33  * for reporting purpose.
34  */
35 public interface IInvocationContext extends Serializable {
36 
37     /** Key used for storing associated invocation ID. */
38     public static final String INVOCATION_ID = "invocation-id";
39 
40     public enum TimingEvent {
41         FETCH_BUILD,
42         SETUP;
43     }
44 
45     /** @return associated invocation ID or {@code null} if not linked to an invocation */
getInvocationId()46     public String getInvocationId();
47 
48     /**
49      * Return the number of devices allocated for the invocation.
50      */
getNumDevicesAllocated()51     public int getNumDevicesAllocated();
52 
53     /**
54      * Add a ITestDevice to be tracked by the meta data when the device is allocated.
55      * will set the build info to null in the map.
56      *
57      * @param deviceName the device configuration name to associate with the {@link ITestDevice}
58      * @param testDevice to be added to the allocated devices.
59      */
addAllocatedDevice(String deviceName, ITestDevice testDevice)60     public void addAllocatedDevice(String deviceName, ITestDevice testDevice);
61 
62     /**
63      * Track a map of configuration device name associated to a {@link ITestDevice}. Doesn't clear
64      * the previous tracking before adding.
65      *
66      * @param deviceWithName the {@link Map} of additional device to track
67      */
addAllocatedDevice(Map<String, ITestDevice> deviceWithName)68     public void addAllocatedDevice(Map<String, ITestDevice> deviceWithName);
69 
70     /**
71      * Return the map of Device/build info association
72      */
getDeviceBuildMap()73     public Map<ITestDevice, IBuildInfo> getDeviceBuildMap();
74 
75     /**
76      * Return all the allocated device tracked for this invocation.
77      */
getDevices()78     public List<ITestDevice> getDevices();
79 
80     /**
81      * Return all the {@link IBuildInfo} tracked for this invocation.
82      */
getBuildInfos()83     public List<IBuildInfo> getBuildInfos();
84 
85     /**
86      * Return the list of serials of the device tracked in this invocation
87      */
getSerials()88     public List<String> getSerials();
89 
90     /**
91      * Return the list of device config names of the device tracked in this invocation
92      */
getDeviceConfigNames()93     public List<String> getDeviceConfigNames();
94 
95     /**
96      * Return the {@link ITestDevice} associated with the device configuration name provided.
97      */
getDevice(String deviceName)98     public ITestDevice getDevice(String deviceName);
99 
100     /**
101      * Returns the {@link ITestDevice} associated with the serial provided.
102      * Refrain from using too much as it's not the fastest lookup.
103      */
getDeviceBySerial(String serial)104     public ITestDevice getDeviceBySerial(String serial);
105 
106     /**
107      * Returns the name of the device set in the xml configuration from the {@link ITestDevice}.
108      * Returns null, if ITestDevice cannot be matched.
109      */
getDeviceName(ITestDevice device)110     public String getDeviceName(ITestDevice device);
111 
112     /**
113      * Returns the name of device set in the xml configuration from the {@link IBuildInfo}. Returns
114      * null if the IBuildInfo cannot be matched
115      */
getBuildInfoName(IBuildInfo info)116     public String getBuildInfoName(IBuildInfo info);
117 
118     /**
119      * Return the {@link IBuildInfo} associated with the device configuration name provided. Returns
120      * null, if the deviceName cannot be matched.
121      */
getBuildInfo(String deviceName)122     public IBuildInfo getBuildInfo(String deviceName);
123 
124     /**
125      * Return the {@link IBuildInfo} associated with the {@link ITestDevice}
126      */
getBuildInfo(ITestDevice testDevice)127     public IBuildInfo getBuildInfo(ITestDevice testDevice);
128 
129     /**
130      * Add a {@link IBuildInfo} to be tracked with the device configuration name.
131      *
132      * @param deviceName the device configuration name
133      * @param buildinfo a {@link IBuildInfo} associated to the device configuration name.
134      */
addDeviceBuildInfo(String deviceName, IBuildInfo buildinfo)135     public void addDeviceBuildInfo(String deviceName, IBuildInfo buildinfo);
136 
137     /**
138      * Add an Invocation attribute.
139      */
addInvocationAttribute(String attributeName, String attributeValue)140     public void addInvocationAttribute(String attributeName, String attributeValue);
141 
142     /** Add several invocation attributes at once through a {@link UniqueMultiMap}. */
addInvocationAttributes(MultiMap<String, String> attributesMap)143     public void addInvocationAttributes(MultiMap<String, String> attributesMap);
144 
145     /** Returns a copy of the map containing all the invocation attributes. */
getAttributes()146     public MultiMap<String, String> getAttributes();
147 
148     /** Add a invocation timing metric. */
addInvocationTimingMetric(TimingEvent timingEvent, Long durationMillis)149     public void addInvocationTimingMetric(TimingEvent timingEvent, Long durationMillis);
150 
151     /** Returns the map containing the invocation timing metrics. */
getInvocationTimingMetrics()152     public Map<TimingEvent, Long> getInvocationTimingMetrics();
153 
154     /** Sets the descriptor associated with the test configuration that launched the invocation */
setConfigurationDescriptor(ConfigurationDescriptor configurationDescriptor)155     public void setConfigurationDescriptor(ConfigurationDescriptor configurationDescriptor);
156 
157     /**
158      * Returns the descriptor associated with the test configuration that launched the invocation
159      */
getConfigurationDescriptor()160     public ConfigurationDescriptor getConfigurationDescriptor();
161 
162     /**
163      * Sets the invocation context of module while being executed as part of a {@link ITestSuite}
164      */
setModuleInvocationContext(IInvocationContext invocationContext)165     public void setModuleInvocationContext(IInvocationContext invocationContext);
166 
167     /**
168      * Returns the invocation context of module while being executed as part of a {@link ITestSuite}
169      */
getModuleInvocationContext()170     public IInvocationContext getModuleInvocationContext();
171 
172     /** Returns the invocation test-tag. */
getTestTag()173     public String getTestTag();
174 
175     /**
176      * Sets the invocation test-tag.
177      */
setTestTag(String testTag)178     public void setTestTag(String testTag);
179 
180     /**
181      * Sets the {@link RecoveryMode} of all the devices part of the context
182      */
setRecoveryModeForAllDevices(RecoveryMode mode)183     public void setRecoveryModeForAllDevices(RecoveryMode mode);
184 
185     /**
186      * Add a serial to be tracked as assigned to one of the shard running some tests.
187      *
188      * @param index the index of the shard using the serials
189      * @param serials The list of serials to be tracked.
190      */
addSerialsFromShard(Integer index, List<String> serials)191     public void addSerialsFromShard(Integer index, List<String> serials);
192 
193     /**
194      * Returns the Map of all tracked serials and their shard involved in sharding. Empty if not a
195      * sharded invocation.
196      */
getShardsSerials()197     public Map<Integer, List<String>> getShardsSerials();
198 
199     /** Serialize a the context instance into a protobuf. */
toProto()200     public com.android.tradefed.invoker.proto.InvocationContext.Context toProto();
201 }
202