forked from TriBITSPub/TriBITS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added argument parsing for cdash random failures script (TriBITSPub#600)
Added initial set of arguments for script to take in when ran.
- Loading branch information
Showing
1 changed file
with
166 additions
and
0 deletions.
There are no files selected for viewing
166 changes: 166 additions & 0 deletions
166
tribits/ci_support/cdash_analyze_and_report_random_failures.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import sys | ||
import datetime | ||
import argparse | ||
|
||
# | ||
# Implementation code | ||
# | ||
|
||
# Find the implementation | ||
tribitsDir = os.environ.get("TRIBITS_DIR", "") | ||
if tribitsDir: | ||
sys.path = [os.path.join(tribitsDir, "ci_support")] + sys.path | ||
else: | ||
raise Exception("ERROR, TRIBITS_DIR must be set in the env to 'tribits' base dir!") | ||
|
||
import CreateIssueTrackerFromCDashQuery as CITFCQ | ||
import CDashQueryAnalyzeReport as CDQAR | ||
import cdash_build_testing_date as CBTD | ||
from FindGeneralScriptSupport import * # from tribits/python_utils | ||
|
||
|
||
usageHelp = \ | ||
r""" | ||
TEMPLATEs | ||
""" | ||
|
||
parser = argparse.ArgumentParser("Arguments for cdash_analyze_and_report_random_failures.py") | ||
parser.add_argument("--cdash-site-url", default="") | ||
parser.add_argument("--cdash-project-name", default="") | ||
parser.add_argument("--reference-date", default="yesterday") | ||
parser.add_argument("--group-name", default="Pull%20Request") | ||
parser.add_argument("--cdash-nonpassed-tests-filters", default="") | ||
args = parser.parse_args() | ||
|
||
|
||
|
||
# The main function | ||
def main(): | ||
|
||
cdashProjectTestingDayStartTime = "00:00" | ||
cdashSiteUrl = args.cdash_site_url | ||
cdashProjectName = args.cdash_project_name | ||
date = args.reference_date | ||
groupName = args.group_name | ||
cdashNonpassedTestsFilters = args.cdash_nonpassed_tests_filters | ||
daysOfFailingTestHistory = 3 | ||
|
||
|
||
# A) Setup directories and | ||
|
||
# Construct date range for queryTests filter string | ||
referenceDateDT = CDQAR.convertInputDateArgToYYYYMMDD( | ||
cdashProjectTestingDayStartTime, date | ||
) | ||
dateRange = getDateRangeTuple(referenceDateDT, daysOfFailingTestHistory) | ||
beginEndUrlField = "begin="+dateRange[0]+"&end="+dateRange[1] | ||
|
||
print("\n dateRangeBeginStr: "+dateRange[0]+" dateRangeEndStr: "+dateRange[1]) | ||
|
||
cdashQueriesCacheDir=os.getcwd()+"/test_queries_cache" | ||
createDirsFromPath(cdashQueriesCacheDir) | ||
|
||
# Construct queryTest.php filter for a date range | ||
failingTestQueryFilters = \ | ||
beginEndUrlField+"&"+cdashNonpassedTestsFilters | ||
|
||
|
||
# B) Get data off of CDash and do analysis | ||
|
||
# B.1) Get all failing test result for past week as a list of dictionaries | ||
|
||
print("\nGetting list of nonpassing tests from CDash ...") | ||
|
||
cdashNonpassingTestBrowserUrl = CDQAR.getCDashQueryTestsBrowserUrl( | ||
cdashSiteUrl, cdashProjectName, None, failingTestQueryFilters) | ||
print("\nCDash nonpassing tests browser URL:\n\n"+\ | ||
" "+cdashNonpassingTestBrowserUrl+"\n") | ||
|
||
cdashNonpassingTestsQueryUrl = CDQAR.getCDashQueryTestsQueryUrl( | ||
cdashSiteUrl, cdashProjectName, None, failingTestQueryFilters) | ||
|
||
cdashNonpassingTestsQueryJsonCacheFile = \ | ||
cdashQueriesCacheDir+"/fullCDashNonpassingTests_"+dateRange[0]+"_"+dateRange[1]+".json" | ||
|
||
# List of dictionaries containing the cdash results in rows | ||
fullNonpassingTestsLOD = CDQAR.downloadTestsOffCDashQueryTestsAndFlatten( | ||
cdashNonpassingTestsQueryUrl, cdashNonpassingTestsQueryJsonCacheFile, alwaysUseCacheFileIfExists=True) | ||
|
||
# B.2) Get each failing test and build's test history for past 30 days | ||
|
||
daysOfTestHistory = 30 | ||
dateRange = getDateRangeTuple(referenceDateDT, daysOfTestHistory) | ||
dateBeginEndUrlField = "begin="+dateRange[0]+"&end="+dateRange[1] | ||
|
||
cdashTestBuildNameDir = cdashQueriesCacheDir+"/test_buildname_history_cache" | ||
createDirsFromPath(cdashTestBuildNameDir) | ||
|
||
|
||
|
||
for failedTest in fullNonpassingTestsLOD: | ||
|
||
print("\n Getting history from "+dateRange[0]+" to "+dateRange[1]+" for\n"+\ | ||
" test name: "+failedTest['testname']+"\n"+\ | ||
" build name: "+failedTest['buildName']) | ||
|
||
cdashTestBuildNameFilters = \ | ||
"filtercount=3&showfilters=1&filtercombine=and"+\ | ||
"&field1=testname&compare1=63&value1="+failedTest['testname']+\ | ||
"&field2=groupname&compare2=63&value2="+groupName+\ | ||
"&field3=buildname&compare3=63&value3="+failedTest['buildName'] | ||
|
||
testBuildNameQueryFilters = dateBeginEndUrlField+"&"+cdashTestBuildNameFilters | ||
|
||
cdashTestBuildNameHistoryCacheFile = cdashTestBuildNameDir+"/"+failedTest['testname']+"_"+failedTest['buildName']+".json" | ||
print("\n Creating file to write test history:\n "+cdashTestBuildNameHistoryCacheFile) | ||
|
||
cdashTestBuildNameHistoryBrowserUrl = CDQAR.getCDashQueryTestsBrowserUrl( | ||
cdashSiteUrl, cdashProjectName, None, testBuildNameQueryFilters) | ||
|
||
print("\n CDash TestBuildName browser URL for "+failedTest['testname']+" "+failedTest['buildName']+":\n\n"+\ | ||
" "+cdashTestBuildNameHistoryBrowserUrl) | ||
|
||
cdashTestBuildNameHistoryQueryUrl = CDQAR.getCDashQueryTestsQueryUrl( | ||
cdashSiteUrl, cdashProjectName, None, testBuildNameQueryFilters) | ||
|
||
print("\n CDash TestBuildName query URL for "+failedTest['testname']+" "+failedTest['buildName']+":\n\n"+\ | ||
" "+cdashTestBuildNameHistoryQueryUrl) | ||
|
||
testBuildNameTestsLOD = CDQAR.downloadTestsOffCDashQueryTestsAndFlatten( | ||
cdashTestBuildNameHistoryQueryUrl, cdashTestBuildNameHistoryCacheFile, alwaysUseCacheFileIfExists=True) | ||
|
||
|
||
# print("\n Link: "+testBuildNameTestsLOD[0]['testDetailsLink']) | ||
|
||
|
||
print("\nNumber of failing tests from "+dateRange[0]+" to "+dateRange[1]+": " | ||
+str(len(fullNonpassingTestsLOD))) | ||
|
||
|
||
def getDateRangeTuple(referenceDateTime, dayTimeDelta): | ||
beginDateTime = referenceDateTime - datetime.timedelta(days=(dayTimeDelta-1)) | ||
beginDateTimeStr = CBTD.getDateStrFromDateTime(beginDateTime) | ||
endDateTimeStr = CBTD.getDateStrFromDateTime(referenceDateTime) | ||
return (beginDateTimeStr, endDateTimeStr) | ||
|
||
def getTopicTargetSha1s(buildLink): | ||
# buildLink: cdash link to specific build containing configure output | ||
# - This function use the api/v1/buildSummary.php? to get the raw json of build page | ||
# and parse the configure output for the topic and target sha1s | ||
# - This function should be implemented on a project basis as | ||
# getting sha1 may be different per project | ||
pass | ||
|
||
|
||
|
||
# | ||
# Execute main if this is being run as a script | ||
# | ||
|
||
if __name__ == '__main__': | ||
sys.exit(main()) | ||
|