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