def printEnvironmentInfo(ManageProjectName, printData = True): somethingPrinted = False output = "" p = subprocess.Popen(manageCMD + " --project " + ManageProjectName + " --full-status", shell=True, stdout=subprocess.PIPE, universal_newlines=True) out, err = p.communicate() job_list = [] level_list = [] list = out.splitlines() for str in list: if re.match("^ [^\s]",str) is not None: compiler = str.split()[0] elif re.match("^ [^\s]",str) is not None: testsuite = str.split()[0] elif re.match("^ [^\s]",str) is not None and not str.startswith(" Disabled Environment"): env_name = str.split()[0] output += "%s %s %s\n" % (compiler , testsuite , env_name) somethingPrinted = True; with tee_print.TeePrint() as teePrint: printOutput(somethingPrinted, ManageProjectName, output, teePrint) return output
def parse(tb, print_exc=False, compiler="Compiler", testsuite="TestSuite", env="Environment", build_dir="Directory", error_str=" *ERROR: Undefined Error"): lines = tb.split("\n") excDataAPI = False for line in lines: if "vector/apps/DataAPI" in line: excDataAPI = True with tee_print.TeePrint() as teePrint: printTraceback(excDataAPI, compiler, testsuite, env, build_dir, error_str, tb, print_exc, teePrint)
def buildReports(FullManageProjectName=None, level=None, envName=None, generate_individual_reports=True, timing=False, cbtDict=None): if timing: print("Start: " + str(time.time())) saved_level = level saved_envName = envName # make sure the project exists if not os.path.isfile(FullManageProjectName) and not os.path.isfile( FullManageProjectName + ".vcm"): raise IOError(FullManageProjectName + ' does not exist') return manageProjectName = os.path.splitext( os.path.basename(FullManageProjectName))[0] version = readManageVersion(FullManageProjectName) useNewReport = checkUseNewReportsAndAPI() manageEnvs = {} if timing: print("Version Check: " + str(time.time())) with tee_print.TeePrint() as teePrint: cleanupOldBuilds(teePrint) for file in glob.glob("*.csv"): try: os.remove(file) if verbose: print("Removing file: " + file) except Exception as e: teePrint.teePrint( " *INFO: File System Error removing " + file + ". Check console for environment build/execution errors") if print_exc: traceback.print_exc() ### Using new data API - 2019 and beyond if timing: print("Cleanup: " + str(time.time())) if useNewReport and not legacy: try: shutil.rmtree("execution") except: pass manageEnvs = getManageEnvs(FullManageProjectName) if timing: print("Using DataAPI for reporting") print("Get Info: " + str(time.time())) useNewAPI(FullManageProjectName, manageEnvs, level, envName, cbtDict) if timing: print("XML and Individual reports: " + str(time.time())) ### NOT Using new data API else: # parse out the manage project name tcmr2csv.manageProjectName = manageProjectName print("Generating Test Case Management Reports") cmd_prefix = os.environ.get('VECTORCAST_DIR') + os.sep # release locks and create all Test Case Management Report callStr = cmd_prefix + "manage --project " + FullManageProjectName + " --force --release-locks" out_mgt = runManageWithWait(callStr) if level and envName: callStr = cmd_prefix + "manage --project " + FullManageProjectName + " --level " + level + " --environment " + envName + " --clicast-args report custom management" else: callStr = cmd_prefix + "manage --project " + FullManageProjectName + " --clicast-args report custom management" print(callStr) # capture the output of the manage call out_mgt = runManageWithWait(callStr) coverProjectInManageProject = False if "database missing or inaccessible" in out_mgt: coverProjectInManageProject = True elif re.search('Environment directory.*is missing', out_mgt): coverProjectInManageProject = True if coverProjectInManageProject: callStr = callStr.replace("report custom", "cover report") print(callStr) out_mgt2 = runManageWithWait(callStr) out_mgt = out_mgt + "\n" + out_mgt2 if generate_individual_reports: print("Generating Execution Reports") if level and envName: callStr = cmd_prefix + "manage --project " + FullManageProjectName + " --level " + level + " --environment " + envName + " --clicast-args report custom actual" else: callStr = cmd_prefix + "manage --project " + FullManageProjectName + " --clicast-args report custom actual" print(callStr) out_exe = runManageWithWait(callStr) out = out_mgt + "\n" + out_exe else: out = out_mgt if verbose: print(out) # save the output of the manage command for debug purposes with open("build.log", "w") as fd: fd.write(out) copyList = [] jobName = "" level = "" if timing: print("Using report scraping for metrics") print("Individual report generation: " + str(time.time())) if not os.path.exists("management"): os.mkdir("management") if not os.path.exists("execution"): os.mkdir("execution") #loop over each line of the manage command output env = None for line in out.split('\n'): # the TEST_SUITE line will give us information for building a jobName that will be # inserted into the CSV name so it will match with the Jenkins integration job names # Generated jobName ONLY used for reports in a single job if "COMMAND:" in line: info = line.split("-e ") env = info[1].split(" ")[0] if "TEST SUITE" in line: info = line.split(": ") level = info[1].split("/") if len(level) == 2: # Level does not include source and platform jobName = level[0] + "_" + level[1].rstrip() else: # Level includes source and platform jobName = level[2] + "_" + level[3].rstrip() if "DIRECTORY:" in line: directory = line.split(": ")[1].strip() # Get the HTML file name that was created if "HTML report was saved" in line: # strip out anything that isn't the html file name reportName = line.rstrip()[34:-2] if not os.path.isfile(reportName): reportName = os.path.join(directory, env, os.path.basename(reportName)) # setup to save the execution report if 'execution_results_report' in reportName: print("Processing Execution Report: " + reportName) if envName: adjustedReportName = "execution" + os.sep + envName + "_" + jobName + ".html" else: adjustedReportName = "execution" + os.sep + env + "_" + jobName + ".html" # setup to save the management report if 'management_report' in reportName: print("Processing Test Case Management Report: " + reportName) # Create the test_results_ and coverage_results_ csv files testResultName, coverageResultsName = tcmr2csv.run( reportName, level, version) vcastcsv2jenkins.run( test=testResultName, coverage=coverageResultsName, useExecRpt=generate_individual_reports, version=version) if envName: adjustedReportName = "management" + os.sep + jobName + "_" + envName + ".html" else: adjustedReportName = "management" + os.sep + jobName + "_" + env + ".html" # Create a list for later to copy the files over copyList.append([reportName, adjustedReportName]) # Reset env env = None if coverProjectInManageProject: generate_qa_results_xml.genQATestResults(FullManageProjectName, saved_level, saved_envName) failed_count = 0 try: for file in glob.glob("xml_data/test_results_*.xml"): with open(file, "r") as fd: lines = fd.readlines() for line in lines: if "failures" in line: failed_count += int(line.split("\"")[5]) break except: teePrint.teePrint( " *INFO: Problem parsing test results file for unit testcase failure count: " + file) if print_exc: traceback.print_exc() with open("unit_test_fail_count.txt", "w") as fd: failed_str = str(failed_count) try: fd.write(unicode(failed_str)) except: fd.write(failed_str) for file in copyList: if verbose: print("moving %s -> %s" % (file[0], file[1])) shutil.move(file[0], file[1]) if timing: print("QA Results reports: " + str(time.time())) if timing: print("Complete: " + str(time.time()))
". Check console for environment build/execution errors") if print_exc: teePrint.teePrint(tb) def parse(tb, print_exc=False, compiler="Compiler", testsuite="TestSuite", env="Environment", build_dir="Directory", error_str=" *ERROR: Undefined Error"): lines = tb.split("\n") excDataAPI = False for line in lines: if "vector/apps/DataAPI" in line: excDataAPI = True with tee_print.TeePrint() as teePrint: printTraceback(excDataAPI, compiler, testsuite, env, build_dir, error_str, tb, print_exc, teePrint) if __name__ == '__main__': with tee_print.TeePrint() as teePrint: teePrint.teePrint("Hello from main")
def fixup_2020_soup(main_soup): # For Jenkins, we don't need to # - display the contents-block (toc) # - title-bar # - remove the space for toc from the page # - adjust the <th> tags to use style vs class # - adjust the <td> tags to use style vs class for div in main_soup.find_all("div", {'class': 'contents-block'}): div.decompose() for div in main_soup.find_all("div", {'id': 'title-bar'}): div.decompose() #<div class="report-body no-toc" id="main-scroller"> div = main_soup.find("div", {'class': 'report-body'}) try: div['class'] = "report-body no-toc" except: pass for th in main_soup.find_all("th", ): th['style'] = "border-bottom:1px solid #e5e5e5;text-align:left;padding:0.25em;padding-right:1em;" # replace class with style because Jenkins won't be able to use the .css in the build summary area class2style = { 'bold-text': 'font-weight: bold;', 'col_unit': 'word-break:break-all;width:30%;', 'col_subprogram': 'word-break:break-all;width:30%;', 'col_complexity': 'white-space:nowrap;', 'col_metric': 'white-space:nowrap;', 'i0': 'padding-left:0.25em;min-width:11em', 'i1': 'padding-left: 1.25em;min-width: 11em;', 'i2': 'padding-left: 2.25em;', 'i3': 'padding-left: 3.25em;', 'i4': 'padding-left: 4.25em;', 'i5': 'padding-left: 5.25em;', 'success': 'background-color:#c8f0c8;', 'warning': 'background-color:#f5f5c8;', 'danger': 'background-color:#facaca;' } for td in main_soup.find_all("td"): style = 'border-bottom:1px solid #e5e5e5;' try: for item in td['class']: try: style += class2style[item] except: with tee_print.TeePrint() as teePrint: teePrint.teePrint("unhandled class " + item) except: pass try: del (td['class']) td['style'] = style except: pass return main_soup
def addConvertFiles(tf, workspace, nocase): with tee_print.TeePrint() as teePrint: addConvertCoverFile(tf, "cover.db", workspace, nocase, teePrint) addConvertMasterFile(tf, "master.db", workspace, nocase, teePrint)