1 /*
2  * Copyright (C) 2015 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 
17 package com.android.compatibility.common.tradefed.targetprep;
18 
19 import com.android.tradefed.config.Option;
20 import com.android.tradefed.device.DeviceNotAvailableException;
21 import com.android.tradefed.invoker.TestInformation;
22 import com.android.tradefed.log.LogUtil.CLog;
23 import com.android.tradefed.targetprep.BaseTargetPreparer;
24 import com.android.tradefed.targetprep.BuildError;
25 import com.android.tradefed.targetprep.ITargetPreparer;
26 import com.android.tradefed.targetprep.TargetSetupError;
27 
28 import java.util.HashSet;
29 import java.util.Set;
30 
31 /**
32  * An {@link ITargetPreparer} that allows a test module to specify tokens that a device must have to
33  * run the tests contained.
34  *
35  * <p>A token is string that is required by a test module and given to a device by the user, they
36  * are used by the scheduler to ensure tests are scheduled on the correct devices. Eg if the user is
37  * sharding the innvocation across 10 devices, they will not want to put a SIM card in every device,
38  * instead they can use a single SIM card and use tokens to tell the scheduler which device should
39  * be used to run the SIM card tests.
40  */
41 public class TokenRequirement extends BaseTargetPreparer {
42 
43     @Option(name = "token", description = "The token a device must have to run this module")
44     private Set<String> mTokens = new HashSet<>();
45 
46     @Override
setUp(TestInformation testInfo)47     public void setUp(TestInformation testInfo)
48             throws TargetSetupError, BuildError, DeviceNotAvailableException {
49         CLog.e("TokenRequirement is not expected to run");
50     }
51 
52     /**
53      * @return the {@link Set} of tokens required by this module.
54      */
getTokens()55     public Set<String> getTokens() {
56         return mTokens;
57     }
58 }
59