Home | History | Annotate | Download | only in multi
      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.targetprep.multi;
     17 
     18 import com.android.tradefed.build.IBuildInfo;
     19 import com.android.tradefed.device.DeviceNotAvailableException;
     20 import com.android.tradefed.device.ITestDevice;
     21 import com.android.tradefed.invoker.IInvocationContext;
     22 import com.android.tradefed.log.LogUtil.CLog;
     23 import com.android.tradefed.targetprep.TargetSetupError;
     24 
     25 import java.util.Map;
     26 import java.util.Map.Entry;
     27 
     28 /**
     29  * An example implementation of a {@link IMultiTargetPreparer}.
     30  */
     31 public class HelloWorldMultiTargetPreparer implements IMultiTargetPreparer {
     32 
     33     /**
     34      * {@inheritDoc}
     35      */
     36     @Override
     37     public void setUp(IInvocationContext context) throws TargetSetupError {
     38         Map<ITestDevice, IBuildInfo> deviceBuildInfo = context.getDeviceBuildMap();
     39         if (deviceBuildInfo.entrySet().size() != 2) {
     40             ITestDevice device = context.getDevices().get(0);
     41             throw new TargetSetupError("The HelloWorldMultiTargetPreparer assumes 2 devices only.",
     42                     device.getDeviceDescriptor());
     43         }
     44         // This would be the perfect place to do setup that requires multiple devices like
     45         // syncing two devices, etc.
     46         for (Entry<ITestDevice, IBuildInfo> entry : deviceBuildInfo.entrySet()) {
     47             CLog.i("Hello World! multi preparer '%s' with build id '%s'",
     48                     entry.getKey().getSerialNumber(), entry.getValue().getBuildId());
     49         }
     50         // Possible look up using the context instead: Getting all the device names configured in
     51         // the xml.
     52         CLog.i("The device names configured are: %s", context.getDeviceConfigNames());
     53     }
     54 
     55     @Override
     56     public void tearDown(IInvocationContext context, Throwable e)
     57             throws DeviceNotAvailableException {
     58         Map<ITestDevice, IBuildInfo> deviceBuildInfo = context.getDeviceBuildMap();
     59         for (Entry<ITestDevice, IBuildInfo> entry : deviceBuildInfo.entrySet()) {
     60             CLog.i("Hello World! multi tear down '%s' with build id '%s'",
     61                     entry.getKey().getSerialNumber(), entry.getValue().getBuildId());
     62         }
     63     }
     64 }
     65