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( filters)

新增要排除的測試篩選器 ERROR(/Set)

void addAllIncludeFilters( filters)

新增要納入測試的篩選器 ERROR(/Set)

void addExcludeFilter(String filter)

新增要排除的測試篩選器。

void addIncludeFilter(String filter)

新增要納入的測試篩選條件。

String cleanFilter(String filter)
void clearExcludeFilters()

刪除目前追蹤的所有排除篩選器。

void clearIncludeFilters()

刪除目前追蹤的所有包含篩選器。

IAbi getAbi()
getAfterTestCmd()

取得要在 GTest 後執行的殼層指令。

getBeforeTestCmd()

取得要在 GTest 前執行的 Shell 指令。

getExcludeFilters()

傳回排除篩選器的目前 ERROR(/Set)

getFileExclusionFilterRegex()

取得排除特定檔案執行的 regex。

getGTestFlags()

取得要傳遞至原生測試殼層指令的其他旗標值。

getIncludeFilters()

傳回包含篩選器的目前 ERROR(/Set)

long getMaxTestTimeMs()

取得 gtest 的執行時間上限。

String getModuleName()

取得要執行的 Android 原生測試模組。

boolean getRunDisabledTests()

取得 GTest 是否應執行已停用的測試。

long getRuntimeHint()

以毫秒為單位傳回測試的預期執行時間。

int getShardCount()

傳回目前的分片計數。

int getShardIndex()

取得這項測試的分片索引。

String getTestFilterKey()

取得測試篩選鍵。

String getTestModule()

取得模組名稱。

boolean isCollectTestsOnly()

Gets only invoke the test binary to collect list of applicable test cases or not.

boolean isEnableXmlOutput()

Gets use gtest xml output for test results or not.

boolean isSharded()

取得 isSharded 標記。

void notifyTestExecution(boolean incompleteTestFound, failedTests)

通知父項測試執行作業,以便正確處理重試嘗試的納入/排除篩選條件。

void setAbi(IAbi abi)
void setCollectTestsOnly(boolean shouldCollectTest)

啟用或停用測試收集模式

void setConfiguration(IConfiguration configuration)

注入使用的 IConfiguration

void setModuleName(String moduleName)

設定要執行的 Android 原生測試模組。

void setShardCount(int shardCount)

設定這項測試的分片數。

void setShardIndex(int shardIndex)

設定這項測試的分片索引。

split(int shardCountHint)

split() 的替代版本,也會提供嘗試執行的 shardCount。

受保護的方法

String convertName(String gtestFlagName)
String createFlagFile(String filter)

建立包含篩選器的檔案,透過 --gtest_flagfile 使用,避免 args 大小受到 OS 限制。

void erasePrependedFileName( filters, String filename)
String getAllGTestFlags(String path)

Helper 可取得所有要傳遞至 adb shell 指令的 GTest 旗標。

IConfiguration getConfiguration()

傳回測試設定。

String getExceptionMessage(Exception e)

盡量嘗試擷取指定 Exception 的簡短說明訊息 Exception

String getGTestCmdLine(String fullPath, String flags)

Helper method to build the gtest command to run.

String getGTestCmdLineWrapper(String fullPath, String flags)

Helper,可讓衍生類別將 gtest 指令包裝在其他工具 (chroot、strace、gdb 和類似工具) 下。

String getGTestFilters(String path)

Helper to get the g-test filter of test to run.

ITestInvocationListener getGTestListener(ITestInvocationListener... listeners)

傳回 GTestListener,提供額外的偵錯資訊,例如偵測及回報重複測試 (如果 mDisabledDuplicateCheck 為 false)。

abstract String loadFilter(String path)

定義 get 篩選器方法。

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 ( filters)

新增要排除的測試篩選器 ERROR(/Set)

參數
filters

addAllIncludeFilters

public void addAllIncludeFilters ( filters)

新增要納入測試的篩選器 ERROR(/Set)

參數
filters

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 ()

刪除目前追蹤的所有包含篩選器。

getAbi

public IAbi getAbi ()

傳回
IAbi

getAfterTestCmd

public  getAfterTestCmd ()

取得要在 GTest 後執行的殼層指令。

傳回

getBeforeTestCmd

public  getBeforeTestCmd ()

取得要在 GTest 前執行的 Shell 指令。

傳回

getExcludeFilters

public  getExcludeFilters ()

傳回排除篩選器的目前 ERROR(/Set)

傳回

getFileExclusionFilterRegex

public  getFileExclusionFilterRegex ()

取得排除特定檔案執行的 regex。

傳回

getGTestFlags

public  getGTestFlags ()

取得要傳遞至原生測試殼層指令的其他旗標值。

傳回

getIncludeFilters

public  getIncludeFilters ()

傳回包含篩選器的目前 ERROR(/Set)

傳回

getMaxTestTimeMs

public long getMaxTestTimeMs ()

取得 gtest 的執行時間上限。

傳回
long

getModuleName

public String getModuleName ()

取得要執行的 Android 原生測試模組。

傳回
String 要執行的原生測試模組名稱,如未設定則為空值

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, 
                 failedTests)

通知家長執行測試,以便在重試時正確處理納入/排除篩選條件。

參數
incompleteTestFound boolean

failedTests

setAbi

public void setAbi (IAbi abi)

參數
abi IAbi

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)

設定這項測試的 Shard 索引。

參數
shardIndex int

拆分

public  split (int shardCountHint)

split() 的替代版本,也會提供嘗試執行的 shardCount。這項功能適用於有時無法任意決定的測試執行器。

參數
shardCountHint int:嘗試的 Shard 數量。

傳回
要個別執行的子測試集合,或測試目前無法分片時的 null

受保護的方法

convertName

protected String convertName (String gtestFlagName)

參數
gtestFlagName String

傳回
String

createFlagFile

protected String createFlagFile (String filter)

建立檔案,其中包含要透過 --gtest_flagfile 使用的篩選器,避免 args 大小受到 OS 限制。

參數
filter String:篩選器字串

傳回
String 包含篩選器的檔案路徑。

擲回
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

erasePrependedFileName

protected void erasePrependedFileName ( filters, 
                String filename)

參數
filters

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 ExceptionException

傳回
String 簡短訊息

getGTestCmdLine

protected String getGTestCmdLine (String fullPath, 
                String flags)

建構要執行的 gtest 指令的輔助方法。

參數
fullPath String:裝置上 gtest 二進位檔的絕對檔案系統路徑

flags String:gtest 執行標記

傳回
String 要執行的 gtest 的殼層指令列

getGTestCmdLineWrapper

protected String getGTestCmdLineWrapper (String fullPath, 
                String flags)

這個輔助程式可讓衍生類別將 gtest 指令包裝在其他工具 (chroot、strace、gdb 等) 下。

參數
fullPath String

flags String

傳回
String

getGTestFilters

protected String getGTestFilters (String path)

Helper to get the g-test filter of test to run.

請注意,篩選器只會篩選函式名稱 (例如:Google 測試「測試」),所有 Google 測試「測試案例」都會納入考量。

參數
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 篩選器方法。

子類別必須實作如何取得自己的篩選器。

參數
path String:篩選器檔案的完整路徑。

傳回
String 篩選器字串。

擲回
DeviceNotAvailableException

setRunDisabled

protected void setRunDisabled (boolean runDisabled)

設定 GTest 是否應執行已停用的測試。

參數
runDisabled boolean