GTestBase
public
abstract
class
GTestBase
extends Object
implements
IAbiReceiver,
IConfigurationReceiver,
IRemoteTest,
IRuntimeHintProvider,
IShardableTest,
ITestCollector,
ITestFilterReceiver
| java.lang.Object | |
| ↳ | com.android.tradefed.testtype.GTestBase |
gTest 的基类
摘要
常量 | |
|---|---|
String |
FILTER_EXTENSION
|
String |
GTEST_FLAG_FILE
|
String |
GTEST_FLAG_FILTER
|
String |
GTEST_FLAG_LIST_TESTS
|
String |
GTEST_FLAG_PRINT_TIME
|
String |
GTEST_FLAG_RUN_DISABLED_TESTS
|
String |
GTEST_XML_OUTPUT
|
公共构造函数 | |
|---|---|
GTestBase()
|
|
公共方法 | |
|---|---|
void
|
addAllExcludeFilters(Set<String> filters)
添加用于指定要排除哪些测试的过滤条件 |
void
|
addAllIncludeFilters(Set<String> filters)
添加用于指定要包含哪些测试的过滤条件 |
void
|
addExcludeFilter(String filter)
添加用于指定要排除哪些测试的过滤条件。 |
void
|
addIncludeFilter(String filter)
添加用于指定要包含哪些测试的过滤条件。 |
String
|
cleanFilter(String filter)
|
void
|
clearExcludeFilters()
删除当前跟踪的所有排除过滤条件。 |
void
|
clearIncludeFilters()
删除当前跟踪的所有包含过滤条件。 |
IAbi
|
getAbi()
|
List<String>
|
getAfterTestCmd()
获取要在 GTest 之后运行的 shell 命令。 |
List<String>
|
getBeforeTestCmd()
获取要在 GTest 之前运行的 shell 命令。 |
Set<String>
|
getExcludeFilters()
返回当前的排除过滤条件 |
Set<String>
|
getFileExclusionFilterRegex()
获取用于排除特定文件执行的正则表达式。 |
List<String>
|
getGTestFlags()
获取要传递给原生测试的 shell 命令的附加标志值。 |
Set<String>
|
getIncludeFilters()
返回当前的包含过滤条件 |
long
|
getMaxTestTimeMs()
获取 gtest 的最长运行时间。 |
String
|
getModuleName()
获取要运行的 Android 原生测试模块。 |
boolean
|
getRunDisabledTests()
获取 GTest 是否应运行已停用的测试。 |
long
|
getRuntimeHint()
返回测试的预期运行时长(以毫秒为单位)。 |
int
|
getShardCount()
返回当前分片数。 |
int
|
getShardIndex()
获取相应测试的分片索引。 |
String
|
getTestFilterKey()
获取测试过滤条件键。 |
String
|
getTestModule()
获取模块名称。 |
boolean
|
isCollectTestsOnly()
仅调用测试二进制文件以收集适用测试用例的列表,或不调用。 |
boolean
|
isEnableXmlOutput()
获取是否使用 gtest xml 输出作为测试结果。 |
boolean
|
isSharded()
获取 isSharded 标志。 |
void
|
notifyTestExecution(boolean incompleteTestFound, Set<String> failedTests)
通知父级测试作业执行情况,以便在重试时正确处理包含/排除过滤条件。 |
void
|
setAbi(IAbi abi)
|
void
|
setCollectTestsOnly(boolean shouldCollectTest)
启用或停用测试收集模式 |
void
|
setConfiguration(IConfiguration configuration)
注入正在使用的 |
void
|
setModuleName(String moduleName)
将 Android 原生测试模块设置为运行。 |
void
|
setShardCount(int shardCount)
设置相应测试的分片数。 |
void
|
setShardIndex(int shardIndex)
设置相应测试的分片索引。 |
Collection<IRemoteTest>
|
split(int shardCountHint)
|
受保护的方法 | |
|---|---|
String
|
convertName(String gtestFlagName)
|
String
|
createFlagFile(String filter)
创建一个包含将通过 --gtest_flagfile 使用的过滤器的文件,以避免任何操作系统在实参大小方面的限制。 |
void
|
erasePrependedFileName(Set<String> filters, String filename)
|
String
|
getAllGTestFlags(String path)
用于获取要传递到 adb shell 命令中的所有 GTest 标志的辅助程序。 |
IConfiguration
|
getConfiguration()
返回测试配置。 |
String
|
getExceptionMessage(Exception e)
尽最大努力尝试检索给定 |
String
|
getGTestCmdLine(String fullPath, String flags)
用于构建要运行的 gtest 命令的辅助方法。 |
String
|
getGTestCmdLineWrapper(String fullPath, String flags)
辅助类,允许派生类将 gtest 命令封装在其他工具(chroot、strace、gdb 等)下。 |
String
|
getGTestFilters(String path)
用于获取要运行的测试的 g-test 过滤器的辅助程序。 |
ITestInvocationListener
|
getGTestListener(ITestInvocationListener... listeners)
返回提供额外调试信息的 GTestListener,例如检测并报告重复测试(如果 mDisabledDuplicateCheck 为 false)。 |
abstract
String
|
loadFilter(String path)
定义获取过滤条件的方法。 |
void
|
setRunDisabled(boolean runDisabled)
设置 GTest 是否应运行已停用的测试。 |
常量
FILTER_EXTENSION
protected static final String FILTER_EXTENSION
常量值: ".filter"
GTEST_FLAG_FILE
protected static final String GTEST_FLAG_FILE
常量值: "--gtest_flagfile"
GTEST_FLAG_FILTER
protected static final String GTEST_FLAG_FILTER
常量值: "--gtest_filter"
GTEST_FLAG_LIST_TESTS
protected static final String GTEST_FLAG_LIST_TESTS
常量值: "--gtest_list_tests"
GTEST_FLAG_PRINT_TIME
protected static final String GTEST_FLAG_PRINT_TIME
常量值: "--gtest_print_time"
GTEST_FLAG_RUN_DISABLED_TESTS
protected static final String GTEST_FLAG_RUN_DISABLED_TESTS
常量值: "--gtest_also_run_disabled_tests"
GTEST_XML_OUTPUT
protected static final String GTEST_XML_OUTPUT
常量值: "--gtest_output=xml:%s"
公共构造函数
GTestBase
public GTestBase ()
公共方法
addAllExcludeFilters
public void addAllExcludeFilters (Set<String> filters)
添加用于指定要排除哪些测试的过滤条件Set。
| 参数 | |
|---|---|
filters |
Set |
addAllIncludeFilters
public void addAllIncludeFilters (Set<String> filters)
添加用于指定要包含哪些测试的过滤条件Set。
| 参数 | |
|---|---|
filters |
Set |
addExcludeFilter
public void addExcludeFilter (String filter)
添加用于指定要排除哪些测试的过滤条件。
| 参数 | |
|---|---|
filter |
String |
addIncludeFilter
public void addIncludeFilter (String filter)
添加用于指定要包含哪些测试的过滤条件。
| 参数 | |
|---|---|
filter |
String |
cleanFilter
public String cleanFilter (String filter)
| 参数 | |
|---|---|
filter |
String |
| 返回 | |
|---|---|
String |
|
clearExcludeFilters
public void clearExcludeFilters ()
删除当前跟踪的所有排除过滤条件。
clearIncludeFilters
public void clearIncludeFilters ()
删除当前跟踪的所有包含过滤条件。
getAfterTestCmd
public List<String> getAfterTestCmd ()
获取要在 GTest 之后运行的 shell 命令。
| 返回 | |
|---|---|
List<String> |
|
getBeforeTestCmd
public List<String> getBeforeTestCmd ()
获取要在 GTest 之前运行的 shell 命令。
| 返回 | |
|---|---|
List<String> |
|
getFileExclusionFilterRegex
public Set<String> getFileExclusionFilterRegex ()
获取用于排除特定文件的正则表达式。
| 返回 | |
|---|---|
Set<String> |
|
getGTestFlags
public List<String> getGTestFlags ()
获取要传递给原生测试的 shell 命令的附加标志值。
| 返回 | |
|---|---|
List<String> |
|
getMaxTestTimeMs
public long getMaxTestTimeMs ()
获取 gtest 的最长运行时间。
| 返回 | |
|---|---|
long |
|
getModuleName
public String getModuleName ()
获取要运行的 Android 原生测试模块。
| 返回 | |
|---|---|
String |
要运行的原生测试模块的名称,如果未设置,则为 null |
getRunDisabledTests
public boolean getRunDisabledTests ()
获取 GTest 是否应运行已停用的测试。
| 返回 | |
|---|---|
boolean |
如果应运行已停用的测试,则为 true;否则为 false |
getRuntimeHint
public long getRuntimeHint ()
以毫秒为单位返回测试的预期运行时长。 该时间用于对分片执行进行负载均衡
| 返回 | |
|---|---|
long |
|
getShardCount
public int getShardCount ()
返回当前分片数。
| 返回 | |
|---|---|
int |
|
getShardIndex
public int getShardIndex ()
获取相应测试的分片索引。
| 返回 | |
|---|---|
int |
|
getTestFilterKey
public String getTestFilterKey ()
获取测试过滤条件键。
| 返回 | |
|---|---|
String |
|
getTestModule
public String getTestModule ()
获取模块名称。
| 返回 | |
|---|---|
String |
|
isCollectTestsOnly
public boolean isCollectTestsOnly ()
仅获取是否调用测试二进制文件来收集适用测试用例的列表。
| 返回 | |
|---|---|
boolean |
|
isEnableXmlOutput
public boolean isEnableXmlOutput ()
获取是否使用 gtest xml 输出作为测试结果。
| 返回 | |
|---|---|
boolean |
|
isSharded
public boolean isSharded ()
获取 isSharded 标志。
| 返回 | |
|---|---|
boolean |
|
notifyTestExecution
public void notifyTestExecution (boolean incompleteTestFound,
Set<String> failedTests)通知父级测试作业执行情况,以便在重试时正确处理包含/排除过滤条件。
| 参数 | |
|---|---|
incompleteTestFound |
boolean |
failedTests |
Set |
setCollectTestsOnly
public void setCollectTestsOnly (boolean shouldCollectTest)
启用或停用测试收集模式
setConfiguration
public void setConfiguration (IConfiguration configuration)
注入正在使用的 IConfiguration。
| 参数 | |
|---|---|
configuration |
IConfiguration |
setModuleName
public void setModuleName (String moduleName)
设置要运行的 Android 原生测试模块。
| 参数 | |
|---|---|
moduleName |
String:要运行的原生测试模块的名称 |
setShardCount
public void setShardCount (int shardCount)
设置相应测试的分片数量。
| 参数 | |
|---|---|
shardCount |
int |
setShardIndex
public void setShardIndex (int shardIndex)
设置相应测试的分片索引。
| 参数 | |
|---|---|
shardIndex |
int |
分解
public Collection<IRemoteTest> split (int shardCountHint)
split() 的替代版本,还提供尝试运行的 shardCount。这对于有时无法任意决定的某些测试运行程序非常有用。
| 参数 | |
|---|---|
shardCountHint |
int:尝试分片的数量。 |
| 返回 | |
|---|---|
Collection<IRemoteTest> |
要单独执行的子测试集合,如果测试目前无法分片,则为 null |
受保护的方法
convertName
protected String convertName (String gtestFlagName)
| 参数 | |
|---|---|
gtestFlagName |
String |
| 返回 | |
|---|---|
String |
|
createFlagFile
protected String createFlagFile (String filter)
创建一个包含将通过 --gtest_flagfile 使用的过滤器的文件,以避免出现任何操作系统参数大小限制。
| 参数 | |
|---|---|
filter |
String:过滤条件字符串 |
| 返回 | |
|---|---|
String |
包含过滤条件的文件路径。 |
| 抛出 | |
|---|---|
|
com.android.tradefed.device.DeviceNotAvailableException |
DeviceNotAvailableException |
|
erasePrependedFileName
protected void erasePrependedFileName (Set<String> filters,
String filename)| 参数 | |
|---|---|
filters |
Set |
filename |
String |
getAllGTestFlags
protected String getAllGTestFlags (String path)
用于获取所有要传递到 adb shell 命令中的 GTest 标志的辅助程序。
| 参数 | |
|---|---|
path |
String:设备上二进制文件的完整路径。 |
| 返回 | |
|---|---|
String |
应传递给 GTest 的所有 GTest 标志的 String |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getConfiguration
protected IConfiguration getConfiguration ()
返回测试配置。
| 返回 | |
|---|---|
IConfiguration |
IConfiguration |
getExceptionMessage
protected String getExceptionMessage (Exception e)
尽最大努力尝试检索给定 Exception 的有意义的简短描述性消息
| 参数 | |
|---|---|
e |
Exception:Exception |
| 返回 | |
|---|---|
String |
一条简短的消息 |
getGTestCmdLine
protected String getGTestCmdLine (String fullPath,
String flags)用于构建要运行的 gtest 命令的辅助方法。
| 参数 | |
|---|---|
fullPath |
String:设备上 gtest 二进制文件的绝对文件系统路径 |
flags |
String:gtest 执行标志 |
| 返回 | |
|---|---|
String |
要为 gtest 运行的 shell 命令行 |
getGTestCmdLineWrapper
protected String getGTestCmdLineWrapper (String fullPath,
String flags)辅助类,允许派生类将 gtest 命令封装在其他工具(chroot、strace、gdb 等)下。
| 参数 | |
|---|---|
fullPath |
String |
flags |
String |
| 返回 | |
|---|---|
String |
|
getGTestFilters
protected String getGTestFilters (String path)
用于获取要运行的测试的 g-test 过滤器的辅助函数。
请注意,过滤条件仅按函数名称(例如 Google Test“Test”)进行过滤;系统会考虑所有 Google Test“测试用例”。
| 参数 | |
|---|---|
path |
String:设备上二进制文件的完整路径。 |
| 返回 | |
|---|---|
String |
要传递给 G-test 的完整过滤标志,如果没有指定任何过滤标志,则为空字符串 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
getGTestListener
protected ITestInvocationListener getGTestListener (ITestInvocationListener... listeners)
返回提供额外调试信息的 GTestListener,例如检测并报告重复测试(如果 mDisabledDuplicateCheck 为 false)。否则,返回传入的监听器。
| 参数 | |
|---|---|
listeners |
ITestInvocationListener |
| 返回 | |
|---|---|
ITestInvocationListener |
|
loadFilter
protected abstract String loadFilter (String path)
定义 get filter 方法。
子类必须实现如何获取自己的过滤器。
| 参数 | |
|---|---|
path |
String:过滤器文件的完整路径。 |
| 返回 | |
|---|---|
String |
过滤条件字符串。 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
setRunDisabled
protected void setRunDisabled (boolean runDisabled)
设置 GTest 是否应运行已停用的测试。
| 参数 | |
|---|---|
runDisabled |
boolean |