内容参考1: 从零开始学习CANoe(五)—— CAPL 测试节点_蚂蚁小兵-CSDN博客
内容参考2:《CANoe开发从入门到精通》
在工程建立后(基于第三个仿真工程),有下面两种方式创建CAPL Test Module。
目录
1. 在Test SetUp创建CAPL Test Module
2 基于Simulation Setup创建CAPL Test Module
3. 附录:CAPL代码
1. 在Test SetUp创建CAPL Test Module
1-1 点击Test-TestSetUp,打开Test Setup for Test Modules窗口。
1-2 在窗口右键,创建或使用已经建立好的Test Environment
1-3 选中创建的Test Environment 测试环境,创建CAPL TestModule。
1-4 选中创建的Test Module 右键编辑,进入.can文件,编写CAPL测试用例。
1-5 CAPL编辑完成后,双击Test Module名,可以在窗口看到CAPL中定义的测试用例。启动工程后,点击右下角三角形可以运行测试用例。
1-5 TestModule运行结束后,可以查看测试报告。测试报告的格式可以选择Test Viewer,或者XML/HTML格式打开。
至此,使用TestSetup创建CAPL Test Module完成。
2 基于Simulation Setup创建CAPL Test Module
2-1 直接在仿真工程面板Simulation上,在总线上右键,添加CAPL Test Module
2-2 创建后 会显示一个CAPL节点,右键点击Configuration可配置此节点属性,
2-3 配置完成后可点击小铅笔,编辑CAPL文件编写测试用例,并保存编译通过。
2-4 工程运行后,点击CAPL节点,可打开CAPL TestModule窗口,显示编辑好的CAPL测试用例。点击三角形,可运行TestModule。
2-5 TestModule运行结束后,可以查看测试报告。
至此,使用Simulation Setup创建CAPL Test Module完成。
3. 附录:CAPL代码
3.测试用例——检测未定义报文undefined msg dword gCycCheckId;//声明检测事件的ID int gUndefinedMsgCheckResult;//声明未定义报文的检测结果 const long kMIN_CYCLE_TIME = 40;//一般最小周期时间常量 const long kMAX_CYCLE_TIME = 60;//一般最大周期时间常量 const long Lingh_MIN_CYCLE_TIME = 490;//定义报文Light_Info最小周期时间常量 const long Lingh_MAX_CYCLE_TIME = 510;//定义报文Light_Info最大周期时间常量 const long kTIMEOUT = 4000;//定义测试等待时间常量 CheckMsgCyc(float aCycMinCycleTime, float aCycMaxCycleTime) long lQueryResultProbeAvg;//声明平均时间 long lQueryResultProbeMin;//声明最小测量时间 long lQueryResultProbeMax;//声明最大测量时间 testAddCondition(gCycCheckId);//在该函数中添加事件 testWaitForTimeout(kTIMEOUT);//等待测试时间结束 lQueryResultProbeAvg = ChkQuery_StatProbeIntervalAvg(gCycCheckId); lQueryResultProbeMin = ChkQuery_StatProbeIntervalMin(gCycCheckId); lQueryResultProbeMax = ChkQuery_StatProbeIntervalMax(gCycCheckId); if(ChkQuery_NumEvents(gCycCheckId)>0) snprintf(lbuffer,elCount(lbuffer),'Valid values %.0fms - %.0fms',aCycMinCycleTime,aCycMaxCycleTime); testStepFail('',lbuffer); snprintf(lbuffer,elCount(lbuffer),'Average cycle time: %dms',lQueryResultProbeAvg); testStepFail('',lbuffer); snprintf(lbuffer,elCount(lbuffer),'Min cycle time: %dms',lQueryResultProbeMin); testStepFail('',lbuffer); snprintf(lbuffer,elCount(lbuffer),'Average cycle time: %dms',lQueryResultProbeMax); testStepFail('',lbuffer); snprintf(lbuffer,elCount(lbuffer),'Valid values %.0fms - %.0fms',aCycMinCycleTime,aCycMaxCycleTime); testStepPass('',lbuffer); snprintf(lbuffer,elCount(lbuffer),'Average cycle time: %dms',lQueryResultProbeAvg); testStepPass('',lbuffer); snprintf(lbuffer,elCount(lbuffer),'Min cycle time: %dms',lQueryResultProbeMin); testStepPass('',lbuffer); snprintf(lbuffer,elCount(lbuffer),'Average cycle time: %dms',lQueryResultProbeMax); testStepPass('',lbuffer); ChkControl_Destroy(gCycCheckId);//销毁事件 //TC1:Check Cycle time of msg EngineData testcase CheckMsgEngineData() float lCycMinCycleTime;//声明最小周期时间 float lCycMaxCycleTime;//声明最大周期时间 lCycMinCycleTime = kMIN_CYCLE_TIME;//赋值 lCycMaxCycleTime = kMAX_CYCLE_TIME; testCaseTitle('TC-1','TC-1:Check cycle time of msg EngineData'); gCycCheckId = ChkStart_MsgAbsCycleTimeViolation(EngineData,lCycMinCycleTime,lCycMaxCycleTime); CheckMsgCyc(lCycMinCycleTime,lCycMaxCycleTime);//周期时间检测结果函数 testRemoveCondition(gCycCheckId);//移除测试条件 //TC-2:Check Cycle time of msg VehicleData testcase CheckMsgVehicleData() lCycMinCycleTime = kMIN_CYCLE_TIME; lCycMaxCycleTime = kMAX_CYCLE_TIME; testCaseTitle('TC-2','TC-2:Check cycle time of msg VehicleData'); gCycCheckId = ChkStart_MsgAbsCycleTimeViolation(VehicleData,lCycMinCycleTime,lCycMaxCycleTime); CheckMsgCyc(lCycMinCycleTime,lCycMaxCycleTime); testRemoveCondition(gCycCheckId); //TC-3:Check Cycle time of msg Gear_Info testcase CheckMsgGear_Info() lCycMinCycleTime = kMIN_CYCLE_TIME; lCycMaxCycleTime = kMAX_CYCLE_TIME; testCaseTitle('TC-3','TC-3:Check cycle time of msg Gear_Info'); gCycCheckId = ChkStart_MsgAbsCycleTimeViolation(Gear_Info,lCycMinCycleTime,lCycMaxCycleTime); CheckMsgCyc(lCycMinCycleTime,lCycMaxCycleTime); testRemoveCondition(gCycCheckId); //TC-4:Check Cycle time of msg Ignition_Info testcase CheckMsgIgnition_Info() lCycMinCycleTime = kMIN_CYCLE_TIME; lCycMaxCycleTime = kMAX_CYCLE_TIME; testCaseTitle('TC-4','TC-4:Check cycle time of msg Ignition_Info'); gCycCheckId = ChkStart_MsgAbsCycleTimeViolation(Ignition_Info,lCycMinCycleTime,lCycMaxCycleTime); CheckMsgCyc(lCycMinCycleTime,lCycMaxCycleTime); testRemoveCondition(gCycCheckId); //TC-5:Check Cycle time of msg Light_Inf testcase CheckMsgLight_Info() lCycMinCycleTime = kMIN_CYCLE_TIME; lCycMaxCycleTime = kMAX_CYCLE_TIME; testCaseTitle('TC-5','TC-5:Check cycle time of msg Light_Info'); gCycCheckId = ChkStart_MsgAbsCycleTimeViolation(Light_Info,lCycMinCycleTime,lCycMaxCycleTime); CheckMsgCyc(lCycMinCycleTime,lCycMaxCycleTime); testRemoveCondition(gCycCheckId); testcase CheckDLCLock_Info() testCaseTitle('TC-6','TC-6:Check msg DLC of Lock_Info'); checkId = ChkStart_InconsistentDlc(Lock_Info); testAddCondition(checkId); testWaitForTimeout(kTIMEOUT); testRemoveCondition(checkId); testcase CheckUndefinedMessage() long lEventUndefineMessageId;//声明未定义报文Id gUndefinedMsgCheckResult = 0;//?初始化未定义报文数量为0 testCaseTitle('TC-7','TC-7:Check CAN channel for undefined message'); gCycCheckId = ChkStart_UndefinedMessageReceived('UndefinedMsgCallback'); testWaitForTimeout(kTIMEOUT); switch(gUndefinedMsgCheckResult) lEventUndefineMessageId = ChkQuery_EventMessageId(gCycCheckId); snprintf(lbuffer,elCount(lbuffer),'Undefined message detected: Id 0x%x',lEventUndefineMessageId); testStepFail('',lbuffer); testStepPass('','No undefined message detected!'); ChkControl_Destroy(gCycCheckId);//销毁事件 UndefinedMsgCallback(dword aCheckId) ChkQuery_EventStatusToWrite(aCheckId); gUndefinedMsgCheckResult=1;//将未定义报文个数置为1 testcase CheckEngine_Speed() testCaseTitle('TC-8','TC-8:Check Engine Speed Value'); @Vehicle_Key::Unlock_Car = 1; @Vehicle_Key::Car_Driver = 0; @Vehicle_Key::Key_State = 2; @Vehicle_Control::Eng_Speed = 2000; checkId = ChkStart_MsgSignalValueInvalid(EngineData::EngSpeed,1900,2100); testWaitForTimeout(kTIMEOUT); if(ChkQuery_EventSignalValue(checkId)) testStepPass('','Correct Engine Speed Value'); testStepFail('','Incorrect Engine Speed Value'); testModuleTitle('NetworkTester'); testModuleDescription('Message Specification Test and Function Test Demo.'); testGroupBegin('Check msg cycle time','Check the differ mesage cycle time'); testGroupBegin('Check msg DLC','Check DLC of a message'); testGroupBegin('Check undefined msg','Check the undefined message'); testGroupBegin('Fucntion Test','Check the engine speed after setup'); //初始化仿真工程状态,确保各个模块处于Online @Vehicle_Key::Unlock_Car = 1; @Vehicle_Key::Car_Driver = 0; @Vehicle_Key::Key_State = 2; on sysvar_update Test::IPC_Cluster_Info_off
END
|