Package generator for projects¶
Advice for use can be found in section Package generator in chapter Projects.
The project package generator interface is documented in the Package Generator API Reference.
Info
The interface is included in the ecu.test Interface Python Library
ecutest-interface.
Info
Each Python file may contain only exactly one PackageGenerator class.
Every CycleData object represents a generated package. In general, the following workflow may be
used for generating packages:
Creating a
CycleDataobject by doingcd = self.CreateCycleData()Creating the test steps on the CycleData object (via
cd.packageInstance).When doing
yield cd, the generated package is passed to trace.check and executed immediately.
These steps can be repeated as often as required, until the desired number of packages has been generated.
Info
In complex use cases it is recommended to first create a package (hereafter referred to as template package) which can be modified by the package generator using the Object API to yield the satisfied packages.
Following this strategy, it must be assured that in each iteration the generator always accesses
the unmodified template package for instance in CreateCycleData. This can be done by
performing all modifications on this package in a try-block followed by a
finally-block in which the template package is closed.
Examples¶
Simple example for the implementation of the API¶
# -*- coding: utf-8 -*-
from tts.interface.projectGenerator.PackageGenerator import PackageGenerator
import os
import wx
class PgTextParser(PackageGenerator):
ID = 'b0905230-d72b-11e2-9566-dc801fb4729d'
NAME = 'Text file parser'
DESCRIPTION = 'Reads a text file line by line'
SERIALIZE = {'filename' : ('FILENAME', 'unicode', r'')}
def __init__(self):
self.filename = r''
self.parameterDicts = []
self.targetItemCount = 0
def GetDialog(self):
return DlgFileSelector(self)
def GetParameterText(self):
return 'Filename: {}'.format(self.filename)
def PreGeneration(self):
self.parameterDicts = []
self.targetItemCount = 0
with open(self.filename, 'r') as fileDescriptor:
for textLine in fileDescriptor.readlines():
comment = "'{0}'".format(textLine.strip())
self.parameterDicts.append({'comment': comment})
self.targetItemCount += 1
def GetTargetItemCount(self):
return self.targetItemCount
def GenerationIterator(self):
for params in self.parameterDicts:
cd = self.CreateCycleData()
testStep = cd.objectApi.PackageApi.TestStepApi.CreateTsComment(params['comment'])
cd.packageInstance.AppendTestStep(testStep)
yield cd
def PostGeneration(self):
pass
def Check(self):
if not os.path.exists(self.filename):
return ['File does not exist!']
return []
class DlgFileSelector(wx.FileDialog):
def __init__(self, generator):
super().__init__(None,
'Select text file',
wildcard='Text files (*.txt)|*.txt',
style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
self.generator = generator
def ShowModal(self):
result = super().ShowModal()
if result == wx.ID_OK:
self.generator.filename = self.Path
return result
Examples provided¶
In order to be able to use the provided example it has to be copied into your workspace.
Select the option Copy examples in the workspace selection dialog. Doing this, the necessary examples are copied into the current workspace.
Package generator example¶
The package generator PkgGenDLC can be found in the folder
<Project generators directory>/PackageGenExample of the example workspace. It shows the basic structure
of a generator and the access to the DataBrowser- and the Internal API of trace.check being used
to gather information as base for the generation.
The generator realizes a basic check for the length of messages on the CAN. The generator provides a dialog to define which bus system will be checked. Hereinafter it uses the description file of this bus defined in the corresponding test configuration to collect information for the generation. It extracts the message id and length (DLC) from the description file and also registers a signal from each message for it to be recorded. The bus communication is recorded within the test case and afterwards the trace analysis (which is also parameterized by the generator) is used to check if the DLC of each message matches the specification.
The generator itself is used in the project ProjectWithPackageGenerator located in the folder
<Package directory>/ExamplePackages/PackageGenExample of the provided example workspace. For its
execution, the project has to be opened in trace.check and the option ‘Generate project’ has to
be chosen from the context menu of the generator DLC check Generator, which is accessible via
right click. After entering a name, the project is generated and can be found in the package
directory of the workspace.
An implicit execution of the generator by executing the project itself is only possible if a test configuration, a test bench configuration, a corresponding bus database and a suitable trace are provided.