Creating stream-based trace step templatesΒΆ
The procedure for creating a new trace step template has been explained before in section General approach. While the creation of signals and parameters is identical for all kinds of templates, the implementation of the actual analysis instructions is distinctly different.
Stream-based trace step templates enable the user to introduce his own Python code which is then carried out exactly one time per analysis run.
The following example demonstrates how recordings are passed to an external program:
By default, ecu.test provides the function Handle. That function may not be renamed or
deleted because ecu.test always uses it as entry point. It has four parameters:
recordingInfos:Allows access to recordings of the current analysis run. That object is always a list, even if there is only one recording in the current analysis run.
dataContainer:Allows access to ecu.test variables. The description of the interface of that object can be found in the Trace Analysis API documentation.
parameters:A python dictionary containing names of the parameters as keys and their respective values as values.
report:Allows access to the test report. The description of the interface of that object can be found in the Trace Analysis API documentation.
To pass a given task to an external program first find out the file name and path for the recording:
for recordingInfo in recordingInfos:
path = recordingInfo.GetPath()
for recordingInfo in recordingInfos iterates across all RecordingInfo objects of the current
analysis run and recordingInfo.GetPath() returns the file path of the recording.
To pass the task now to an external program you can use the Python module os.system:
import os
cmdLine = '"C:/Programme/Programm.exe" -c "%s"'
...
result += os.system(cmdLine % path)
In our example the path of the recording with parameter c is passed to the program Programm.exe.
That program call causes a return value to be sent back (mostly 0 for failed and 1 for successfully concluded).
That return value is added to the variable result.
Finally the result of the trace step is to be adapted in the test report, according to the value of
result, and a short comment should be issued.
if result > 0:
report.SetResultId(report.RESULT_ID_ERROR)
report.SetResultText("Some ERRORs occurred!")
else:
report.SetResultId(report.RESULT_ID_SUCCESS)
report.SetResultText("All checks SUCCESSful!")
As explained, the test report can be accessed via the report object.
While the function SetResultId fixes the result, the function SetResultText releases its value
directly in the test report (for details see the reference).