Autonomous driving simulation: common API calls for ECU TEST automated testing


提示:以下是本篇文章正文内容,下面案例可供参考

1. API call operating environment

1. Install python 3.6 and above

2. ET API Help Documentation

1. Enter the ET HELP document
insert image description here

2. Enter API HELP
insert image description here

3. Select the API type according to the requirement

insert image description here
insert image description here


3. How to import ET API

1. Obtain the ET API path
注意:调用ET的API之前需要将API路径添加至搜索路径中,这样才能成功调用API:

Method 1: Obtain the API path through the registry

reg = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE\TraceTronic\ECU-TEST 2022.1') #打开注册表;
etDir = winreg.QueryValueEx(reg, 'Path')[0] #查询ET Path的值;
reg.Close() #关闭注册表;
ApiClientPath = os.path.join(etDir, r'Templates\ApiClient') #路径连接;

#注:根据版本更改ECU-TEST 2022.1值

Method 2: Find the API folder in the installation directory (according to the installation location)

ApiClientPath = os.path.join(r'C:\Program Files\ECU-TEST 2022.1\Templates\ApiClient')

2. Add the ApiClient path to the python search path

sys.path.append(ApiClientPath)

3. Import the ApiClient library

from ApiClient import ApiClient

4. API instantiation

self.api = ApiClient()

4. ET common interface

1. Create a Package for adding test steps

insert image description here

1)pkghandle = self.api.PackageApi.CreatePackage()

2. Add a precondition block to the TestStep of the Package

insert image description here

insert image description here

注意:要先创建pkg才能添加precondition,pkghandle是创建pkg返回的句柄;

1)	precondition = self.api.PackageApi.TestStepApi.CreateTsPreconditionBlock() #创建PreconditionBlock;

2)pkghandle.AppendTestStep(precondition) #将block添加到pkg的TestStep中;

3. Add a Block block to the TestStep of the Package

insert image description here
insert image description here

注意:要先创建pkg才能添加Block,pkghandle是创建pkg返回的句柄;

3) actionBlock = self.api.PackageApi.TestStepApi.CreateTsBlock() #创建Block块

4) actionBlock.SetActionColumnText('Action') #设置block的名称;

5) pkghandle.AppendTestStep(actionBlock) #将block添加到pkg的TestStep中;

4. Add the PostconditionBlock block in the TestStep of the Package

insert image description here
insert image description here
注意:要先创建pkg才能添加Postcondition,pkghandle是创建pkg返回的句柄;

1)	postcondition = self.api.PackageApi.TestStepApi.CreateTsPostconditionBlock() #创建PostconditionBlock;

2) pkghandle.AppendTestStep(postcondition)  #将block添加到pkg的TestStep中;

5. Call other packages in the TestStep of the Package

insert image description here

1)Tspkg = self.api.PackageApi.TestStepApi.CreateTsPackage(pkgPath) #创建引用包的调用句柄;

insert image description here

2)Tspkg.SetPackageParameter(paramName,paramValue) #设置被调用package的形参值;

3)block.AppendTestStep(Tspkg) #将Job添加到Block/PostconditionBlock/PreconditionBlock模块;

6. Create the JOB of the co-simulation tool

insert image description here

1)	mappingitem = self.api.PackageApi.MappingApi.CreateJobMappingItem(toolID, JobName, portId=None, checkTarget=True)  #创建工具模型的mappingitem,需要填写ToolID、JobName;

chairs:

insert image description here
JobName:
insert image description here
注意:创建Job之前,需要确保工具的Job MappIngItem已经创建,如上所示;

insert image description here

2)	TsJob = self.api.PackageApi.TestStepApi.CreateTsJob(mappingitem,generateInterface=True) #创建TsJob之前mappingitem需要提前创建;

insert image description here

3)	TsJob.SetParameter(name, Value) #设置Job的参数名称与值;

4) block.AppendTestStep(Tsjob) #将Job添加到Block/PostconditionBlock/PreconditionBlock模块

7. Create a Calculation calculation module

1)	TsCal = self.api.PackageApi.TestStepApi.CreateTsCalculation() #创建Calculation模块;

insert image description here

2)	TsCal.SetFormula(Formula) #设置Calculation模块的公式

insert image description here

3)	TsCal.SetExpectationExpression(ExpectationExpression) #添加期望结果表达式;

4) block.AppendTestStep(TsCal) #将Job添加到Block/PostconditionBlock/PreconditionBlock模块;

8. Create the GlobalMapping of the signal

1)mappingfile = self.api.GlobalMappingApi.CreateMapping() #创建GlobalMapping文件;

insert image description here

2)	mappingItem = self.api.PackageApi.MappingApi.CreateModelMappingItem(systemIdentifier,
targetPath,variableType=None,isSignal=False,referenceName=MappingName,checkTarget=True) 
#需要配置systemIdentifier一般为Plant model(TCF中可以修改名称),targetPath是需要Mapping的信号路径,referenceName是Mapping的名称;

3)	mappingfile.AddItem(mappingItem)  #添加GlobalMapping对象到Mappingfile;

insert image description here

4)mappingfile.Save(filename=””) #保存Mapping文件;

9. Create SignalRecording module

insert image description here

1) SGroupHandle =self.api.PackageApi.SignalRecordingApi.CreateSignalGroup(name='',description='') #创建信号录制组别;

2) pkghandle.AppendSignalGroup(SGroupHandle, defaultRecordingGroup=None, allowNewName=False) #将信号组添加到pkg;

3) RecordingGroup = SGroupHandle.GetRecordingGroups() #获取所有信号组,返回的RecordingGroup是列表;

insert image description here

4for RG in RecordingGroup:  #因为RecordingGroup是列表,返回了多个录制组;
    RG.SetRecordingMode(RG.RECORDING_MODE_AUTO) #将每个组切换自动录制模式

insert image description here

5)SGroupHandle.AppendMappingItem(MappingItem) #需要先创建GlobalMapping,才能将信号添加至信号录制组;

10. Create a Wait time delay module

1)	TsWait= self.api.PackageApi.TestStepApi.CreateTsWait() #创建时间延时模块;

2)	TsWait.SetDelay(value, unit)  #创建延迟时间

3)  block.AppendTestStep(TsWait)  #将TsWait添加到Block/PostconditionBlock/PreconditionBlock模块

11. VERISTAND signal read

注意这里使用的Mapping和GlobalMapping不一样

1)	mappingItem = self.api.PackageApi.MappingApi.CreateGenericMappingItem(referenceName=referenceName) #创建需要读取值的信号Mappingitem;

2) TsRead = self.api.PackageApi.TestStepApi.CreateTsRead(mappingItem) #添加MappingItem到读取步骤;

3) TsRead.SetExpectationExpression(expectation) #添加期望结果;

4)  block.AppendTestStep(TsRead)  #将TsRead添加到Block/PostconditionBlock/PreconditionBlock模块

12. VERISTAND signal write

1)	MappingItem = self.api.PackageApi.MappingApi.CreateGenericMappingItem(referenceName=referenceName)
#创建需要写入值的信号GenericMappingitem;

2)	testStep = self.api.PackageApi.TestStepApi.CreateTsWrite(MappingItem) #添加MappingItem到写入步骤;

3)	testStep.SetValue(value) #设置写入值;

13. ECU TEST TestStep function

Create an IF statement

1)Tsif = self.api.PackageApi.TestStepApi.CreateTsIfThenElse()  # 创建if..else函数

2)block.AppendTestStep(Tsif) # 添加if函数到block块

3)Tsif.SetCondition(condition)  # 添加if..else条件

4)ThenNode = Tsif.GetThenNode()  # 获取Then节点

5)ElseNode = Tsif.GetElseNode()  # 获取Else节点

6)ThenNode.AppendTestStep()/ElseNode.AppendTestStep() #添加TestStep到Then或Else节点;

Create the LOOP statement

1)Tsloop = self.api.PackageApi.TestStepApi.CreateTsLoop()  #创建Loop函数

2)block.AppendTestStep(Tsloop)  # 添加Loop函数到block块

3)Tsloop.SetStartCondition(loopcondition)  # 设置Loop执行条件

4)Tsloop.SetLoopCountExpression(looptimes)  # 设置Loop执行次数

5)Tsloop.SetSaveInVariableName(LoopCounter) # 设置Save counter in的变量

Create a SWITCH CASE statement

1)Tsswitch_case = self.api.PackageApi.TestStepApi.CreateTsSwitchCase() #创建SwitchCase函数;

2)block.AppendTestStep(Tsswitch_case) #添加SwitchCase到block块;

3)Tsswitch_case.SetSwitchValue(switchcondition) #添加SwitchCase的进入条件;

insert image description here

4)SwitchNode = Tsswitch_case.CreateCaseNode(caseValue='0', insPos=None) #创建Case节点;

5)SwitchNode.AppendTestStep() #Case节点添加步骤;

insert image description here

6)GetDefaultNode = Tsswitch_case.GetCaseNode() #获取Default节点

7)GetDefaultNode.AppendTestStep() #Default节点添加步骤;

Above, some commonly used APIs for automation are exemplified;

Guess you like

Origin blog.csdn.net/zataji/article/details/129201761