当前位置:网站首页>Canoe test: two ways to create CAPL test module
Canoe test: two ways to create CAPL test module
2022-07-04 10:51:00 【picoasis】
Content reference 2:《CANoe Development from entry to mastery 》
After the project is established ( Based on the third simulation project ), There are two ways to create CAPL Test Module.
Catalog
1. stay Test SetUp establish CAPL Test Module
2 be based on Simulation Setup establish CAPL Test Module
1. stay Test SetUp establish CAPL Test Module
1-1 Click on Test-TestSetUp, open Test Setup for Test Modules window .
1-2 Right click in the window , Create or use established Test Environment
1-3 Check the created Test Environment Test environment , establish CAPL TestModule.
1-4 Check the created Test Module Right click editing , Get into .can file , To write CAPL The test case .
1-5 CAPL After editing , double-click Test Module name , You can see in the window CAPL Test cases defined in . After starting the project , Click the triangle in the lower right corner to run the test case .
1-5 TestModule At the end of the run , You can view the test report . The format of the test report can be selected Test Viewer, perhaps XML/HTML Format open .
thus , Use TestSetup establish CAPL Test Module complete .
2 be based on Simulation Setup establish CAPL Test Module
2-1 Directly on the simulation engineering panel Simulation On , Right click on the bus , add to CAPL Test Module
2-2 After creation It will display a CAPL node , Right click on the Configuration This node attribute can be configured ,
2-3 After the configuration is completed, click the small pencil , edit CAPL Document test cases , Save and compile .
2-4 After the operation of the project , Click on CAPL node , May open CAPL TestModule window , Display the edited CAPL The test case . Click triangle , Can run TestModule.
2-5 TestModule At the end of the run , You can view the test report .
thus , Use Simulation Setup establish CAPL Test Module complete .
3. appendix :CAPL Code
/*@!Encoding:936*/
/*
1. The test case —— Detect message cycle
2. The test case —— Detect the message length DLC
3. The test case —— Detect undefined message undefined msg
4. The test case —— A functional test
5. The test case —— Test module entry function
*/
includes
{
}
variables
{
//TC1
dword gCycCheckId;// Declare the... Of the detection event ID
int gUndefinedMsgCheckResult;// Declare the detection result of undefined message
const long kMIN_CYCLE_TIME = 40;// General minimum cycle time constant
const long kMAX_CYCLE_TIME = 60;// General maximum cycle time constant
const long Lingh_MIN_CYCLE_TIME = 490;// Define message Light_Info Minimum cycle time constant
const long Lingh_MAX_CYCLE_TIME = 510;// Define message Light_Info Maximum cycle time constant
const long kTIMEOUT = 4000;// Define the test wait time constant
}
// Cycle time detection result function
CheckMsgCyc(float aCycMinCycleTime, float aCycMaxCycleTime)
{
long lQueryResultProbeAvg;// Average declaration time
long lQueryResultProbeMin;// Declare the minimum measurement time
long lQueryResultProbeMax;// Declare the maximum measurement time
char lbuffer[100];
testAddCondition(gCycCheckId);// Add an event to this function
testWaitForTimeout(kTIMEOUT);// Wait for the test time to end
// Statistical average time
lQueryResultProbeAvg = ChkQuery_StatProbeIntervalAvg(gCycCheckId);
// Statistics min Time
lQueryResultProbeMin = ChkQuery_StatProbeIntervalMin(gCycCheckId);
// Statistics max Time
lQueryResultProbeMax = ChkQuery_StatProbeIntervalMax(gCycCheckId);
if(ChkQuery_NumEvents(gCycCheckId)>0)
{
// Count the number of exceptions // Print report
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);
}
else
{
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);// Destruction event
}
//TC1:Check Cycle time of msg EngineData
testcase CheckMsgEngineData()
{
float lCycMinCycleTime;// Declare the minimum cycle time
float lCycMaxCycleTime;// Declare the maximum cycle time
lCycMinCycleTime = kMIN_CYCLE_TIME;// assignment
lCycMaxCycleTime = kMAX_CYCLE_TIME;
// Test report prompt information
testCaseTitle("TC-1","TC-1:Check cycle time of msg EngineData");
// Start to observe the message to be tested
gCycCheckId = ChkStart_MsgAbsCycleTimeViolation(EngineData,lCycMinCycleTime,lCycMaxCycleTime);
CheckMsgCyc(lCycMinCycleTime,lCycMaxCycleTime);// Cycle time detection result function
testRemoveCondition(gCycCheckId);// Remove test conditions
}
//TC-2:Check Cycle time of msg VehicleData
testcase CheckMsgVehicleData()
{
float lCycMinCycleTime;
float lCycMaxCycleTime;
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()
{
float lCycMinCycleTime;
float lCycMaxCycleTime;
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()
{
float lCycMinCycleTime;
float lCycMaxCycleTime;
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()
{
float lCycMinCycleTime;
float lCycMaxCycleTime;
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);
}
//TC6:DLC Message length test
testcase CheckDLCLock_Info()
{
dword checkId;
// Test report prompt information
testCaseTitle("TC-6","TC-6:Check msg DLC of Lock_Info");
// Steward observation message Lock_Info Of DLC
checkId = ChkStart_InconsistentDlc(Lock_Info);
testAddCondition(checkId);
// Wait for the test time to end
testWaitForTimeout(kTIMEOUT);
testRemoveCondition(checkId);
}
//TC-7: Detect undefined signals
testcase CheckUndefinedMessage()
{
long lEventUndefineMessageId;// Declare undefined message Id
char lbuffer[100];
gUndefinedMsgCheckResult = 0;//? The number of initialization undefined messages is 0
testCaseTitle("TC-7","TC-7:Check CAN channel for undefined message");
// Start observing the current bus
gCycCheckId = ChkStart_UndefinedMessageReceived("UndefinedMsgCallback");
// Time delay , That is, measure the time period
testWaitForTimeout(kTIMEOUT);
switch(gUndefinedMsgCheckResult)
{
case 1:
write("Iam case1");
// Get undefined message ID
lEventUndefineMessageId = ChkQuery_EventMessageId(gCycCheckId);
snprintf(lbuffer,elCount(lbuffer),"Undefined message detected: Id 0x%x",lEventUndefineMessageId);
testStepFail("",lbuffer);
break;
default:
write("Iamdefault");
testStepPass("","No undefined message detected!");
break;
}
ChkControl_Destroy(gCycCheckId);// Destruction event
}
UndefinedMsgCallback(dword aCheckId)
{
// Callback function , Call when an undefined message is detected
write("Iam here");
ChkQuery_EventStatusToWrite(aCheckId);
gUndefinedMsgCheckResult=1;// Set the number of undefined messages to 1
}
//TC-8: A functional test
testcase CheckEngine_Speed()
{
dword checkId;
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;
// Start observing , Whether the signal value is within the range
checkId = ChkStart_MsgSignalValueInvalid(EngineData::EngSpeed,1900,2100);
testWaitForTimeout(kTIMEOUT);
if(ChkQuery_EventSignalValue(checkId))
{
testStepPass("","Correct Engine Speed Value");
}
else
{
testStepFail("","Incorrect Engine Speed Value");
}
}
// Test module entry function
void MainTest()
{
testModuleTitle("NetworkTester");
testModuleDescription("Message Specification Test and Function Test Demo.");
testGroupBegin("Check msg cycle time","Check the differ mesage cycle time");
Init_Test_Condition();
CheckMsgEngineData();
CheckMsgVehicleData();
CheckMsgGear_Info();
CheckMsgIgnition_Info();
CheckMsgLight_Info();
testGroupEnd();
testGroupBegin("Check msg DLC","Check DLC of a message");
CheckDLCLock_Info();
testGroupEnd();
testGroupBegin("Check undefined msg","Check the undefined message");
CheckUndefinedMessage();
testGroupEnd();
testGroupBegin("Fucntion Test","Check the engine speed after setup");
CheckEngine_Speed();
testGroupEnd();
}
// Initialize simulation engineering status , Ensure that each module is in Online
Init_Test_Condition()
{
@Vehicle_Key::Unlock_Car = 1;
@Vehicle_Key::Car_Driver = 0;
@Vehicle_Key::Key_State = 2;
testWaitForTimeout(500);
}
on sysvar_update Test::IPC_Cluster_Info_off
{
if (@this==1)
{
}
}
END
边栏推荐
- Using SA token to solve websocket handshake authentication
- Performance features focus & JMeter & LoadRunner advantages and disadvantages
- Read a piece of text into the vector object, and each word is stored as an element in the vector. Convert each word in the vector object to uppercase letters. Output the converted elements in the vect
- [test theory] test the dimension of professional ability
- 2、 Operators and branches
- Add t more space to your computer (no need to add hard disk)
- Evolution from monomer architecture to microservice architecture
- Advanced order of function
- [Galaxy Kirin V10] [desktop] printer
- Network connection (III) functions and similarities and differences of hubs, switches and routers, routing tables and tables in switches, why do you need address translation and packet filtering?
猜你喜欢
XMIND installation
Jemeter script recording
Introduction to tree and binary tree
Sword finger offer 05 (implemented in C language)
RHCE - day one
Four characteristics and isolation levels of database transactions
[Galaxy Kirin V10] [server] iSCSI deployment
[Galaxy Kirin V10] [server] KVM create Bridge
Rhcsa day 9
Knapsack problem and 0-1 knapsack problem
随机推荐
2022 ape circle recruitment project (software development)
From programmers to large-scale distributed architects, where are you (I)
[untitled]
Talk about scalability
Postman interface test
Installation of ES plug-in in Google browser
If you don't know these four caching modes, dare you say you understand caching?
/*Write a loop to output the elements of the list container in reverse order*/
On binary tree (C language)
Jemeter plug-in technology
Rhsca day 11 operation
Static comprehensive experiment ---hcip1
Software testing related resources
Ten key performance indicators of software applications
如果不知道這4種緩存模式,敢說懂緩存嗎?
TS type gymnastics: illustrating a complex advanced type
Linked list operation can never change without its roots
Quick sort (C language)
[Galaxy Kirin V10] [desktop and server] FRP intranet penetration
Snake (C language)