Home | History | Annotate | Download | only in invoker
      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.util.List;
     27 import java.util.Map;
     28 
     29 /**
     30  * Holds information about the Invocation for the tests to access if needed.
     31  * Tests should not modify the context contained here so only getters will be available, except for
     32  * the context attributes for reporting purpose.
     33  */
     34 public interface IInvocationContext {
     35 
     36     /**
     37      * Return the number of devices allocated for the invocation.
     38      */
     39     public int getNumDevicesAllocated();
     40 
     41     /**
     42      * Add a ITestDevice to be tracked by the meta data when the device is allocated.
     43      * will set the build info to null in the map.
     44      *
     45      * @param deviceName the device configuration name to associate with the {@link ITestDevice}
     46      * @param testDevice to be added to the allocated devices.
     47      */
     48     public void addAllocatedDevice(String deviceName, ITestDevice testDevice);
     49 
     50     /**
     51      * Track a map of configuration device name associated to a {@link ITestDevice}. Doesn't clear
     52      * the previous tracking before adding.
     53      *
     54      * @param deviceWithName the {@link Map} of additional device to track
     55      */
     56     public void addAllocatedDevice(Map<String, ITestDevice> deviceWithName);
     57 
     58     /**
     59      * Return the map of Device/build info association
     60      */
     61     public Map<ITestDevice, IBuildInfo> getDeviceBuildMap();
     62 
     63     /**
     64      * Return all the allocated device tracked for this invocation.
     65      */
     66     public List<ITestDevice> getDevices();
     67 
     68     /**
     69      * Return all the {@link IBuildInfo} tracked for this invocation.
     70      */
     71     public List<IBuildInfo> getBuildInfos();
     72 
     73     /**
     74      * Return the list of serials of the device tracked in this invocation
     75      */
     76     public List<String> getSerials();
     77 
     78     /**
     79      * Return the list of device config names of the device tracked in this invocation
     80      */
     81     public List<String> getDeviceConfigNames();
     82 
     83     /**
     84      * Return the {@link ITestDevice} associated with the device configuration name provided.
     85      */
     86     public ITestDevice getDevice(String deviceName);
     87 
     88     /**
     89      * Returns the {@link ITestDevice} associated with the serial provided.
     90      * Refrain from using too much as it's not the fastest lookup.
     91      */
     92     public ITestDevice getDeviceBySerial(String serial);
     93 
     94     /**
     95      * Returns the name of the device set in the xml configuration from the {@link ITestDevice}.
     96      * Returns null, if ITestDevice cannot be matched.
     97      */
     98     public String getDeviceName(ITestDevice device);
     99 
    100     /** Return the {@link IBuildInfo} associated with the device configuration name provided. */
    101     public IBuildInfo getBuildInfo(String deviceName);
    102 
    103     /**
    104      * Return the {@link IBuildInfo} associated with the {@link ITestDevice}
    105      */
    106     public IBuildInfo getBuildInfo(ITestDevice testDevice);
    107 
    108     /**
    109      * Add a {@link IBuildInfo} to be tracked with the device configuration name.
    110      *
    111      * @param deviceName the device configuration name
    112      * @param buildinfo a {@link IBuildInfo} associated to the device configuration name.
    113      */
    114     public void addDeviceBuildInfo(String deviceName, IBuildInfo buildinfo);
    115 
    116     /**
    117      * Add an Invocation attribute.
    118      */
    119     public void addInvocationAttribute(String attributeName, String attributeValue);
    120 
    121     /** Add several invocation attributes at once through a {@link UniqueMultiMap}. */
    122     public void addInvocationAttributes(UniqueMultiMap<String, String> attributesMap);
    123 
    124     /** Returns the map of invocation attributes. */
    125     public MultiMap<String, String> getAttributes();
    126 
    127     /** Sets the descriptor associated with the test configuration that launched the invocation */
    128     public void setConfigurationDescriptor(ConfigurationDescriptor configurationDescriptor);
    129 
    130     /**
    131      * Returns the descriptor associated with the test configuration that launched the invocation
    132      */
    133     public ConfigurationDescriptor getConfigurationDescriptor();
    134 
    135     /**
    136      * Sets the invocation context of module while being executed as part of a {@link ITestSuite}
    137      */
    138     public void setModuleInvocationContext(IInvocationContext invocationContext);
    139 
    140     /**
    141      * Returns the invocation context of module while being executed as part of a {@link ITestSuite}
    142      */
    143     public IInvocationContext getModuleInvocationContext();
    144 
    145     /** Returns the invocation test-tag. */
    146     public String getTestTag();
    147 
    148     /**
    149      * Sets the invocation test-tag.
    150      */
    151     public void setTestTag(String testTag);
    152 
    153     /**
    154      * Sets the {@link RecoveryMode} of all the devices part of the context
    155      */
    156     public void setRecoveryModeForAllDevices(RecoveryMode mode);
    157 }
    158