命令行選項就是你在敲run cts --plan UI命令時可以再跟一個參數,比如在debug配置參數時加入--help看一下效果。


所以這里面定義的類一般是可以在命令行上加參數的形更改的。先來看一下里面有哪些參數
# 接口
~~~
/*
* 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的組織