1.工程实例
1.1检测报文周期的测试用例
1.1.1相关函数
使用方法:声明一个dword类型变量gcyccheckID,调用第一个函数将其返回值赋值于gcyccheckID,开始观测指定报文,gcyccheckID再作为实参传递给后几个函数用于检测指定报文的属性
1.1.2例子
includes
{
// 此处添加头文件
)
variables
{
dword gcyccheckId; //声明检测事件ID
int gUndifnedMsgCheckResult; // 声明未定义报文检测结果
const long kMIN_CYCLE_TIME = 40; // 定义一般最小周期时间常量
const long kMAX_CYCLE_TIME = 60; // 定义一般最大周期时间常量
const long Light_MIN_CYCLE_TIME= 490;//定义报文Light_Info最小周期时间常量
const long Light_MAX_CYCLE_TIME= 510;//定义报文Light_Info 最大周期时间常量
const long kTIMEOUT =4000;// 定义测试等待时间常量
}
// Tc-1:Check cycle time of msg EngineData 测试用例1
testcase CheckMsgEngineData()
{
float lcycMincycleTime;// 声明最小周期时间
float 1cycMaxCycleTime;//声明最大周期时间
1cycMincycleTime = kMIN_CYCLE_TIME; //最小周期时间赋值
1cycMaxCycleTime = kMAX_CYCLE_TIME;// 最大周期时间赋值
//测试报告提示信息
TestCaseTitle("TC-1","TC-1:Check cycle time of msg EngineData");
//开始观察待测报文
gcycCheckId = Chkstart_MsgAbscycleTimeViolation(EngineData,// 待测报文
1cycMincycleTime, //最小周期时间
1CycMaxCycleTime); //最大周期时间
CheckMsgcyc(1CycMinCycleTime,1CycMaxCycleTime);// 周期时间检测结果函数
testRemoveCondition(gcycCheckId); //移除测试条件
}
// Tc-2:Check cycle time of msg VehicleData 测试用例2
testcase CheckMsgVehicledata()
{
float lcyeMincycleTime; // 声明最小周期时间
float 1cycMaxCycleTime; // 声明最大周期时间
1cycMincycleTime = kMIN_CYCLE_TIME; // 最小周期时间赋值
1CycMaxCycleTime = kMAX_CYCLE_TIME; // 最大周期时间赋值
// 测试报告提示信息
TestCaseTitle("TC-2","TC-2:Check cycle time of msg VehicleData");
gcycCheckId = Chkstart_MsgAbsCycleTimeViolation(VehicleData,// 待测报文
1cycMinCycleTime, // 最小周期时间
1CycMaxCycleTime); // 最大周期时间
CheckMsgcyc(1cycMincycleTime,1CyeMaxCycleTime);
testRemoveCondition(gCyccheckId);
}
// Tc-3:Check cycle time of msg Gear_Info 测试用例3
testcase CheckMsgGear_Info()
{
float 1cycMincycleTime; //声明最小周期时间
float 1CycMaxCycleTime; // 声明最大周期时间
1cycMincycleTime = kMIN_CYCLE_TIME; // 最小周期时间赋值
1cycMaxCycleTime = kMAX_CYCLE_TIME; // 最大周期时间赋值
//测试报告提示信息
TestCaseTitle("TC-3","TC-3:Check cycle time of msg Gear_Info");
gcyccheckId = Chkstart_MsgAbscycleTimeViolation(Gear_Info,// 待测报文
1cyeMincycleTime, // 最小周期时间
1cycMaxCycleTime); // 最大周期时间
CheckMsgcyc(1cycMincycleTime,1CycMaxCycleTime);
testRemoveCondition(gcyccheckId);
testWaitForTimeout(500);
}
// Tc-4: Check cycle time of msg Ignition_Info 测试用例4
testcase CheckMsgIgnition_Info()
{
float 1cycMinCycleTime;
float 1cycMaxCycleTime;
// 声明最小周期时间
// 声明最大周期时间
1cycMinCycleTime = kMIN_CYCLE_TIME;
1CycMaxCycleTime = kMAX_CYCLE_TIME;
// 最小周期时间赋值
// 最大周期时间赋值
//测试报告提示信息
TestCaseTitle("TC-4","TC-4:Check cycle time of msg Ignition_Info");
gcyccheckId = Chkstart_MsgAbsCycleTimeViolation(Ignition_Info,// 待测报文
1cycMincycleTime, // 最小周期时间
1cycMaxCycleTime); //最大周期时间
CheckMsgcyc(1cycMincycleTime,1CycMaxCycleTime);
testRemoveCondition(gCycCheckId);
}
// TC-5:Check cycle time of msg Light_Info 测试用例5
testcase CheckMsglight_Info()
{
float lcycMinCycleTime;
float 1CycMaxCycleTime;
//声明最小周期时间
//声明最大周期时间
1cycMinCycleTime = Light_MIN_CYCLE_TIME; //最小周期时间赋值
1CycMaxCycleTime = Light_MAX_CYCLE_TIME; //最大周期时间赋值
//测试报告提示信息
TestCaseTitle("TC-5","TC-5:Check cycle time of msg Light_Info");
gcycCheckId = Chkstart_MsgAbsCycleTimeViolation(Light_Info,// 待测报文
1cycMinCycleTime, //最小周期时间
1CycMaxCycleTime); //最大周期时间
CheckMsgcyc(1CyeMinCycleTime,1CycMaxCycleTime);
testRemoveCondition(gCycCheckId);
}
// 周期时间检测结果函数
CheckMsgcyc(float acycMincycleTime, float aCycMaxCycleTime)
long lQueryResultProbeAvg; // 声明平均时间
long 1QueryResultProbeMin; // 声明最小测量时间
long lQueryResultProbeMax; //声明最大测量时间
char lbuffer[100];
TestAddCondition(gcyccheckId); //在该函数体中添加事件
testWaitForTimeout(kTIMEOUT); // 等待测试时间结束
// 统计平均时间
1QueryResultProbeAvg = ChkQuery_statProbeIntervalAvg(gcycCheckId);
// 统计最小时间
1QueryResultProbeMin = ChkQuery_StatProbeIntervalMin(gCycCheckId);
// 统计最大时间
1QueryResultProbeMax = ChkQuery_statProbeIntervalMax(gCycCheckId);
if(ChkQuery_NumEvents(gCycCheckId)>0) //统计异常次数
{//打印报告
snprintf(lbuffer,elcount(lbuffer),"Valid values 8.0fms - 8.0fms",
aCycMinCycleTime,aCycMaxCycleTime);
TestStepFail("",lbuffer);
snprintf(lbuffer,elcount(lbuffer),"Average cycle time: 8dms",
lQueryResultProbeAvg);
TeststepFail("",lbuffer);
snprintf(lbuffer,elcount(lbuffer),"Min cycle time: 8dms",
1QueryResultProbeMin);
TeststepFail("",lbuffer);
snprintf(lbuffer,elcount(lbuffer),"Max cycle time: 8dms",
1QueryResultProbeMax);
TeststepFail("",lbuffer);
}
else
{
snprintf(lbuffer,elcount(lbuffer),"Valid values 8.0fms - 8.0fms",
aCycMinCycleTime,aCycMaxCycleTime);
TeststepPass("",lbuffer);
snprintf(lbuffer,elcount(lbuffer),"Average cycle time: 8dms",
lQueryResultProbeAvg);
TeststepPass("",lbuffer);
snprintf(1buffer,elcount(lbuffer),"Min cycle time: 8dms",
1QueryResultProbeMin);
TestStepPass("",lbuffer);
snprintf(lbuffer,elcount(lbuffer),"Max cycle time: 8dms",
lQueryResultProbeMax);
TestStepPass("",lbuffer);
}
ChkControl_Destroy(gCycCheckId);// 销毁事件
}
1.2检测报文长度的测试用例
1.1.1相关函数
1.1.2例子
testcase CheckDLCLock_Info()
{
dword checkId;
// 测试报告提示信息
TestCaseTitle("TC-6","TC-6:Check msg DLC of Lock_Info");
//开始观测报文 Lock_Info 的 DLC
checkId = Chkstart_InconsistentDLc(Lock_Info);
TestAddCondition(checkId);
// 等待测试时间结束
TestWaitForTimeout(kTIMEOUT);
TestRemoveCondition(checkId);
}
1.3检测未定义报文的测试用例
1.3.1相关函数
1.3.2例子
testcase CheckUndefinedMessage()
{
long 1EventUndefineMessageId;// 声明未定义报文 ID
char lbuffer[100];
gUndifnedMsgCheckResult = 0; // 初始化未定义报文数量为零
// 测试报告提示信息
TestCaseTitle("TC-7","TC-7:Check CAN channel for undefined messages");
//开始观测当前总线
gcyccheckId = Chkstart_undefinedMessageReceived("UndefinedMsgCallback");
//延时,即测量该时间段
testWaitForTimeout(kTIMEOUT);
switch(gUndifnedMsgCheckResult)
{
case 1:
// 获取未定义报文 ID
1EventUndefineMessageId = ChkQuery_EventMessageId(gCycCheckId);
snprintf(lbuffer,elcount(lbuffer),"Undefined message detected: Id
0x8x",1EventUndefineMessageId);
TestStepFail("", lbuffer);
break;
default:
TeststepPass("","No undefined message detected!");
break;
}
ChkControl_Destroy(gcycCheckId);
}
// 销毁事件
UndefinedMsgCallback(dword aCheckId) //回调函数,检测到未定义报文时调用
ChkQuery_EventStatusToWrite(aCheckId);
gUndifnedMsgCheckResult = 1; //将未定义报文个数置1
}
1.4功能测试的测试用例
1.4.1相关函数
1.4.2例子
testcase CheckEngine_Speed()
{
dword checkId;
//测试报告提示信息
TestCaseTitle("TC-8","TC-8:Check Engine Speed Value");
QVehicle_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!");
}
else
{
TeststepFail("","Incorrect Engine Speed Value!");
}
}
1.5主函数代码
在.can文件中主函数的代码部分如下。
//测试模块入口函数
void MainTest()
{
//测试模块信息报告
TestModuleTitle("NetworkTester");
TestModuleDescription("Message Specication Test and Function Test Demo.");
//测试分组-开始-第一组
TestGroupBegin("Check msg cycle time", "Check the differ message cycle time");
Init_Test_Condition();
//调用TC-1
CheckMsgEngineData();
//调用TC-2
CheckMsgVehicledata();
//调用TC-23
CheckMsgGear_Info();
//调用TC-4
CheckMsgIgnition_Info();
//调用TC-5
CheckMsgLight_Info();
//测试分组-结束-第一组
TestGroupEnd ();
//测试分组-开始-第二组
TestGroupBegin("Check msg Dlc","Check DLC of a message");
//调用TC-6
CheckDLcLock_Info();
//测试分组-结束-第二组
TestGroupEnd ();
//测试分组-开始-第三组
TestGroupBegin("Check undefined msg","Check the undefined message");
//调用TC-7
CheckUndefinedMessage();
//测试分组-结束-第三组
TestGroupEnd ();
//测试分组-开始-第四组
TestGroupBegin("Function Test","Check the engine speed after setup");
//调用TC-8
CheckEngine_Speed();
//测试分组-结束-第四组
TestGroupEnd();
}
//初始化仿真工程状态,确保各个模块处于Online
Init_Test_Condition()
{
@Vehicle_Key::Unlock_Car =1;
@Vehicle_Key::Car_Driver=0;
@Vehicle_Key::Key_State=2;
testWaitForTimeout(500);
}