命令行选项就是你在敲run cts --plan UI命令时可以再跟一个参数,比如在debug配置参数时加入--help看一下效果。
![](https://box.kancloud.cn/2016-01-09_56911dcf52061.jpg)
![](https://box.kancloud.cn/2016-01-09_56911dcf742e3.jpg)
所以这里面定义的类一般是可以在命令行上加参数的形更改的。先来看一下里面有哪些参数
# 接口
~~~
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.tradefed.command;
/**
* Container for execution options for commands.
*/
public interface ICommandOptions {
public boolean isNeedPrepare();
public void setNeedPrepare(boolean needPrepare);
public boolean isNeedTearDown();
public void setNeedTearDown(boolean needTearDown);
/**
* Returns <code>true</code> if abbreviated help mode has been requested
*/
public boolean isHelpMode();
/**
* Returns <code>true</code> if full detailed help mode has been requested
*/
public boolean isFullHelpMode();
/**
* Return <code>true</code> if we should <emph>skip</emph> adding this command to the queue.
*/
public boolean isDryRunMode();
/**
* Return <code>true</code> if we should print the command out to the console before we
* <emph>skip</emph> adding it to the queue.
*/
public boolean isNoisyDryRunMode();
/**
* Return the loop mode for the config.
*/
public boolean isLoopMode();
/**
* Get the min loop time for the config.
*/
public long getMinLoopTime();
/**
* Sets the loop mode for the command
*
* @param loopMode
*/
public void setLoopMode(boolean loopMode);
/**
* Creates a copy of the {@link ICommandOptions} object.
* @return
*/
public ICommandOptions clone();
/**
* Return true if command should run on all devices.
*/
public boolean runOnAllDevices();
}
~~~
# 实现类
~~~
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.tradefed.command;
import com.android.tradefed.config.ConfigurationException;
import com.android.tradefed.config.Option;
import com.android.tradefed.config.Option.Importance;
import com.android.tradefed.config.OptionCopier;
import com.android.tradefed.log.LogUtil.CLog;
/**
* Implementation of {@link ICommandOptions}.
*/
public class CommandOptions implements ICommandOptions {
@Option(name = "help", description =
"display the help text for the most important/critical options.",
importance = Importance.ALWAYS)
private boolean mHelpMode = false;
@Option(name = "help-all", description = "display the full help text for all options.",
importance = Importance.ALWAYS)
private boolean mFullHelpMode = false;
@Option(name = "dry-run",
description = "build but don't actually run the command. Intended as a quick check " +
"to ensure that a command is runnable.",
importance = Importance.ALWAYS)
private boolean mDryRunMode = false;
@Option(name = "noisy-dry-run",
description = "build but don't actually run the command. This version prints the " +
"command to the console. Intended for cmdfile debugging.",
importance = Importance.ALWAYS)
private boolean mNoisyDryRunMode = false;
@Option(name = "min-loop-time", description =
"the minimum invocation time in ms when in loop mode.")
private long mMinLoopTime = 10 * 60 * 1000;
@Option(name = "loop", description = "keep running continuously.")
private boolean mLoopMode = true;
@Option(name = "all-devices", description =
"fork this command to run on all connected devices.")
private boolean mAllDevices = true;
@Option(name = "need-prepare", description = "is needed to prepare device")
private boolean mNeedPrepare = true;
// @Option(name = "need-flash", description = "is needed to fastboot device")
// private boolean mNeedFlash = true;
@Option(name = "need-tearDown", description = "is needed to clean device")
private boolean mNeedTearDown = true;
public boolean isNeedPrepare() {
return mNeedPrepare;
}
public void setNeedPrepare(boolean needPrepare) {
mNeedPrepare = needPrepare;
}
public boolean isNeedTearDown() {
return mNeedTearDown;
}
public void setNeedTearDown(boolean needTearDown) {
mNeedTearDown = needTearDown;
}
/**
* Set the help mode for the config.
* <p/>
* Exposed for testing.
*/
void setHelpMode(boolean helpMode) {
mHelpMode = helpMode;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isHelpMode() {
return mHelpMode;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isFullHelpMode() {
return mFullHelpMode;
}
/**
* Set the dry run mode for the config.
* <p/>
* Exposed for testing.
*/
void setDryRunMode(boolean dryRunMode) {
mDryRunMode = dryRunMode;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isDryRunMode() {
return mDryRunMode || mNoisyDryRunMode;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isNoisyDryRunMode() {
return mNoisyDryRunMode;
}
/**
* Set the loop mode for the config.
*/
@Override
public void setLoopMode(boolean loopMode) {
mLoopMode = loopMode;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isLoopMode() {
return mLoopMode;
}
/**
* Set the min loop time for the config.
* <p/>
* Exposed for testing.
*/
void setMinLoopTime(long loopTime) {
mMinLoopTime = loopTime;
}
/**
* {@inheritDoc}
*/
@Override
public long getMinLoopTime() {
return mMinLoopTime;
}
@Override
public ICommandOptions clone() {
CommandOptions clone = new CommandOptions();
try {
OptionCopier.copyOptions(this, clone);
} catch (ConfigurationException e) {
CLog.e("failed to clone command options", e);
}
return clone;
}
/**
* {@inheritDoc}
*/
@Override
public boolean runOnAllDevices() {
return mAllDevices;
}
}
~~~
实现类里定义了接口中的方法对应的属性分别是:
help就是你要在命令行后的参数,就如文章一开头我添加的--help模式。如果你添加了就等于mHelpMode = true;打印帮助信息,但是只有注解中importance属性的才打印
~~~
@Option(name = "help", description =
"display the help text for the most important/critical options.",
importance = Importance.ALWAYS)
private boolean mHelpMode = false;
~~~
和上面一样,但是会打印所有option注解的信息,不管有没有importance选项
~~~
@Option(name = "help-all", description = "display the full help text for all options.",
importance = Importance.ALWAYS)
private boolean mFullHelpMode = false;
~~~
测试命令是否可行。
~~~
@Option(name = "dry-run",
description = "build but don't actually run the command. Intended as a quick check " +
"to ensure that a command is runnable.",
importance = Importance.ALWAYS)
private boolean mDryRunMode = false;
@Option(name = "noisy-dry-run",
description = "build but don't actually run the command. This version prints the " +
"command to the console. Intended for cmdfile debugging.",
importance = Importance.ALWAYS)
private boolean mNoisyDryRunMode = false;
~~~
是否循环执行命令以及循环的时间
~~~
@Option(name = "min-loop-time", description =
"the minimum invocation time in ms when in loop mode.")
private long mMinLoopTime = 10 * 60 * 1000;
@Option(name = "loop", description = "keep running continuously.")
private boolean mLoopMode = true;
~~~
是否全设备测试
~~~
@Option(name = "all-devices", description =
"fork this command to run on all connected devices.")
private boolean mAllDevices = true;
~~~
测试前的准备工作和测试后的还原工作
~~~
@Option(name = "need-prepare", description = "is needed to prepare device")
private boolean mNeedPrepare = true;
@Option(name = "need-tearDown", description = "is needed to clean device")
private boolean mNeedTearDown = true;
~~~
- 前言
- (1)-windows下cts配置
- (2)-cts调试环境的搭建
- (3)-基础库tradefederation配置
- (4)-任务的添加
- (5)-9大组件配置
- (6)-任务的执行
- (7)-任务执行的调度室
- (8)-IBuildProvider
- (9)-IDeviceRecovery
- (10)-TestDeviceOptions
- (11)-ICommandOptions
- (12)-ITargetPreparer
- (13)-任务执行过程
- (14)-任务执行过程
- (15)-任务执行完
- (16)-logcat信息收集系统
- (17)-fastboot状态监听器
- (18)-设备恢复
- (19)-设备状态的分类以及恢复模式的分类
- (20)-cts自身log系统
- (21)-测试结果收集系统
- (22)-自动检测设备
- (23)-设备分类
- (24)-case的组织