/*@!Encoding:936*/
1、TC-1测试引擎转速区间 故障注入函数
2、测试引擎报文长度是否与DBC中定义的一致
3、TC-3测试总线上未定义的报文
4、测试引擎报文的循环时间
5、Tc-5 测试总线错误帧
includes
{
}
variables
{
const KTIMEOUT =5000; //设置常量等待时间为5秒
}
//1.CAPL测试模块
//测试模块入口函数
void MainTest()
{
testModuleTitle("Demo002Test");//测试模块名称
testModuleDescription("这是CAPL自动化测试模块");//测试模块描述
testGroupBegin("Demo002测试组","Demo002测试组包含5个用例");//测试组开始 测试组名 测试组描述
Check001();
CheckEngineSpeed();
CheckEngineStateDLC();
CheckUndefinedMessage();
CheckEngineMsgCycleTimer();
CheckErrorFrame();
testGroupEnd();//测试组结束
}
//测试用例模版
testcase Check001() //自定义一条测试用例
{
write("这是一条测试用例样板");
}
testcase CheckEngineSpeed()
{
dword checkId;
testCaseTitle("TC-1","TC-1测试引擎转速区间");
checkId=ChkStart_MsgSignalValueRangeViolation(Engine::EngineSpeed,800,3500);//测试引擎的转速区间在800~3500
testAddCondition(checkId);//添加测试条件
testWaitForTimeout(KTIMEOUT);//测试等待时间
testRemoveCondition(checkId);//测试后移除测试条件
}
//TC-2测试引擎报文长度是否与DBC中定义的一致
//EngineState
testcase CheckEngineStateDLC()
{
dword checkId;
testCaseTitle("TC-2","TC-2测试引擎报文长度");
checkId=ChkStart_InconsistentDlc(EngineState);//检查DLC长度
testAddCondition(checkId);
testWaitForTimeout(KTIMEOUT);
testRemoveCondition(checkId);
}
//故障注入函数
On key 'z'
{
testSetMsgDlc(EngineState,3);//故障注入 设置报文EngineState的DLC为3
}
//2.3 TC-3测试总线上未定义的报文
testcase CheckUndefinedMessage()
{
dword checkId;
testCaseTitle("TC-3","TC-3:测试总线上未定义的报文");
checkId=ChkStart_UndefinedMessageReceived();//检查总线上未定义的报文
testAddCondition(checkId);
testWaitForTimeout(3000);
testRemoveCondition(checkId);
}
On key's'
{
message *undefinedmsg;//声明未定义的报文
undefinedmsg.can=1;
undefinedmsg.id=0x666;
undefinedmsg.dlc=4;
undefinedmsg.byte(0)=0x60;
undefinedmsg.byte(1)=0x70;
undefinedmsg.byte(2)=0x80;
undefinedmsg.byte(3)=0x90;
output(undefinedmsg);
}
//2.4 测试引擎报文的循环时间
testcase CheckEngineMsgCycleTimer()
{
dword checkId;
float minCycleTime=100;//最小时间
float maxCycleTime=110;//最大时间
testCaseTitle("TC-4","TC-4:测试引擎报文循环时间");
checkId =ChkStart_MsgAbsCycleTimeViolation(Engine::EngineState,minCycleTime,maxCycleTime);
testAddCondition(checkId);//添加测试条件
testWaitForTimeout(3000);//测试等待时间
testRemoveCondition(checkId);//测试后移除测试条件
}
on key 'p'
{
testSetMsgCycleTime(0X150,50);//故障注入,设置引擎报文的循环周期为50ms
}
//2.5Tc-5 测试总线错误帧
testcase CheckErrorFrame()
{
dword checkId;
dword numCheckEvents;//错误帧数量
testCaseTitle("IC-5","TC-5:测试总线错误帧");
checkId=ChkStart_ErrorFramesOccured();//错误帧出现函数
testAddCondition(checkId);
testWaitForTimeout(100000);//测试等待时间
testRemoveCondition(checkId);//测试后移除测试条件
numCheckEvents=ChkQuery_NumEvents(checkId);//统计错误帧数量
if(numCheckEvents>0)
testStepFail("错误帧出现");
else
testStepPass("没有错误帧");
}