winIDEA SDK
Loading...
Searching...
No Matches
create_test_report.py
# This script is licensed under BSD License, see file LICENSE.txt, or search for `License` in the SDK online help.
#
# (c) TASKING Germany GmbH, 2023
import isystem.connect as ic
import isystem.itest as it
winidea_id = ''
def createExampleOfLogEntry():
lr = ic.CLogResult(None)
lr.add('counter', '234', ic.CLogResult.E_SECTION_BEFORE_ASSIGN)
lr.add('size', '25', ic.CLogResult.E_SECTION_AFTER_ASSIGN)
return lr
def createExampleOfStubResult(hitNo, stepIdx):
sr = ic.CTestPointResult(None)
sr.setId('fillArray')
sr.setLogResult(createExampleOfLogEntry())
sr.setExecStatus(ic.CTestPointResult.EXECUTED)
sr.setHitNoAndStepIdx(hitNo, stepIdx)
sr.setScriptInfoVar("evaluated all expressions")
sr.setScriptRetVal("") # should be empty to indicate no error
sr.addExpressionError("a == 10", "a = 9")
return sr
def createExampleOfTestPointResult():
sr = ic.CTestPointResult(None)
sr.setId('myTestPointID')
sr.setLocation('src/main.cpp')
sr.setLogResult(createExampleOfLogEntry())
sr.setExecStatus(ic.CTestPointResult.EXECUTED)
sr.setHitNoAndStepIdx(0, 0)
sr.setScriptInfoVar("evaluated all expressions")
# non-empty ret val means error and contains contains error message
sr.setScriptRetVal("Eval. failed!")
return sr
def createExampleOfStackUsage():
su = ic.CStackUsageResult(None)
minExpectedSize = 200
maxExpectedSize = 600
stackUsedBeforeTest = 150
testUsage = 0 # amount of stack used for test, for example creation
# of test local variables for unit tests.
appUsage = 50 # usage of function under test
su.setValues(minExpectedSize, maxExpectedSize, stackUsedBeforeTest,
testUsage, appUsage)
return su
def createExampleOfPreConditionResult(isError):
pc = ic.CTestExprResult(None)
pc.setExpression('a == 2')
pc.addSubexpression('a', '2')
pc.setError(isError)
return pc
def createExampleOfExprResult(expr, subExpr, value, isError):
pc = ic.CTestExprResult(None)
pc.setExpression(expr)
pc.addSubexpression(subExpr, value)
pc.setError(isError)
return pc
def createExampleOfTestResult():
testSpec = ic.CTestSpecification()
testSpec.setTestId('demoTest')
testResult = ic.CTestResult(testSpec)
testResult.setResultComment('This is demo script for test report creation')
testResult.setTargetException(False)
testResult.appendScriptOutput("", "timing OK")
# testResult.appendScriptError("afterTest: ", "size of list is invalid")
testResult.addStubResult(createExampleOfStubResult(0, 0))
# we can add one result per stub or test point hit
testResult.addStubResult(createExampleOfStubResult(1, 0))
testResult.addTestPointResult(createExampleOfTestPointResult())
testResult.setStackUsageResult(createExampleOfStackUsage())
testResult.addExprResult(ic.CTestResult.E_SECTION_PRE_CONDITION,
createExampleOfPreConditionResult(False))
testResult.addExprResult(ic.CTestResult.E_SECTION_ASSERT,
createExampleOfExprResult('a == 4', 'a', '2', True))
testResult.setLogResult(createExampleOfLogEntry())
return testResult
def getWinIDEAVersion():
cm = ic.ConnectionMgr()
cm.connect(ic.CConnectionConfig().instanceId(winidea_id))
ide = ic.CIDEController(cm)
ver = ide.getWinIDEAVersion()
return ver.toString()
def createExampleOfReportConfig():
reportConfig = ic.CTestReportConfig()
reportConfig.setReportContents(ic.CTestReportConfig.RCONFIG_FULL)
reportConfig.setTestIDEAVersion("0.9") # you can set your test script version here
cm = ic.ConnectionMgr()
cm.connect(ic.CConnectionConfig().instanceId(winidea_id))
ide = ic.CIDEController(cm)
reportConfig.setWinIDEAVersion(getWinIDEAVersion())
reportConfig.setOutputFormat(ic.CTestReportConfig.FMT_XML)
reportConfig.setFileName('reportGeneratedByCustomScript.xml')
# Must not be empty string, so let's indicate none was used. Path
# defines output dir for the generated report file, if report file
# name is not given as absolute path
reportConfig.setIYamlFileName("./")
# Use standard isystem XML -> HTML transformation file and style sheet
reportConfig.setXsltForFullReport(it.DEFAULT_XSLT)
reportConfig.setCssFile(it.BLUE_CSS)
reportConfig.setIncludeTestSpec(False)
# report title
reportConfig.setXmlReportHeader("CUSTOM REPORT")
# setAbsPathForLinks(bool iaAbsPathsForLinks)
reportConfig.addUserInfo("date", "2019-04-04")
reportConfig.addUserInfo("testerName", "john")
return reportConfig
def saveTestReport(testResults, reportConfig):
resultContainer = ic.CTestReportContainer()
for testResult in testResults:
resultContainer.putTestResult(ic.CTestSpecification(), testResult)
ic.CTestBench.saveTestResults(resultContainer, reportConfig)
def main():
reportConfig = createExampleOfReportConfig()
testResults = []
testResults.append(createExampleOfTestResult())
saveTestReport(testResults, reportConfig)
# Get standard isystem XML -> HTML transformation file and style sheet.
# Call this method only if XSLT and CSS files were set with
# it.XSLT_BUILT_IN_PREFIX in reportConfig, and file names are set to
# isystem default values
it.copyXsltAndCss(reportConfig)
print("OK")
if __name__ == "__main__":
main()