首页 > 其他分享 >CANoe学习笔记-第十四章节-CANoe自动化测试

CANoe学习笔记-第十四章节-CANoe自动化测试

时间:2024-09-29 23:51:14浏览次数:8  
标签:Info gCycCheckId CANoe lCycMinCycleTime 笔记 TC lCycMaxCycleTime 第十四章 lbuffer

前言:利用CANoe的Test Step 功能实现自动化测试,是学习CAPL语言的一个重要目的及目标

新建一个Test工程

第二步骤

3.鼠标右击Test1,选择Configuration,打开CAPL TEST Module Configuration对话框,给Test Script 添加NetworkTester.can文件,文件程序如下:程序来源《CANoe入门到精通教材》

includes
{
  
}

variables
{
  dword gCycCheckId;
  
  int gUndifnedMsgCheckResult;
  
  const long kMIN_CYCLE_TIME = 40;
  const long kMAX_CYCLE_TIME = 60;
  const long Light_MIN_CYCLE_TIME = 490;
  const long Light_MAX_CYCLE_TIME = 510;
  const long kTIMEOUT = 4000;
}

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();
    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("Function Test", "Check the engine speed after setup"); 
    CheckEngine_Speed();
  TestGroupEnd();
}
Init_Test_Condition()
{
  @Vehicle_Key::Unlock_Car =1;
  @Vehicle_Key::Car_Driver=0;
  @Vehicle_Key::Key_State=2;
  testWaitForTimeout(500);
}
testcase CheckMsgEngineData()
{
  float lCycMinCycleTime;  // Minimum relative distance 
  float lCycMaxCycleTime;  // Maximum relative distance
  
  lCycMinCycleTime = kMIN_CYCLE_TIME;
  lCycMaxCycleTime = kMAX_CYCLE_TIME; 
  
  // Information for test report.
  TestCaseTitle("TC-1", "TC-1: Check cycle time of msg EngineData");
  
  
  gCycCheckId = ChkStart_MsgAbsCycleTimeViolation (EngineData,   // Message to supervise
                                    lCycMinCycleTime,            // min-limit
                                    lCycMaxCycleTime);           // max-limit
                                               
  CheckMsgCyc(lCycMinCycleTime, lCycMaxCycleTime);
  testRemoveCondition(gCycCheckId);
 }


testcase CheckMsgVehicledata()
{
  float lCycMinCycleTime;  // Minimum relative distance 
  float lCycMaxCycleTime;  // Maximum relative distance
  
  lCycMinCycleTime = kMIN_CYCLE_TIME;
  lCycMaxCycleTime = kMAX_CYCLE_TIME; 
  
  // Information for test report.
  TestCaseTitle("TC-2", "TC-2: Check cycle time of msg VehicleData");  
  
  gCycCheckId = ChkStart_MsgAbsCycleTimeViolation (VehicleData,   // Message to supervise
                                    lCycMinCycleTime,            // min-limit
                                    lCycMaxCycleTime);           // max-limit
                                               
  CheckMsgCyc(lCycMinCycleTime, lCycMaxCycleTime);
  testRemoveCondition(gCycCheckId);
 }

testcase CheckMsgGear_Info()
{
  float lCycMinCycleTime;  // Minimum relative distance 
  float lCycMaxCycleTime;  // Maximum relative distance
  
  lCycMinCycleTime = kMIN_CYCLE_TIME;
  lCycMaxCycleTime = kMAX_CYCLE_TIME; 
  
  // Information for test report.
  TestCaseTitle("TC-3", "TC-3: Check cycle time of msg Gear_Info");
  
  
  gCycCheckId = ChkStart_MsgAbsCycleTimeViolation (Gear_Info,   // Message to supervise
                                    lCycMinCycleTime,            // min-limit
                                    lCycMaxCycleTime);           // max-limit
                                               
  CheckMsgCyc(lCycMinCycleTime, lCycMaxCycleTime);
  testRemoveCondition(gCycCheckId);
  testWaitForTimeout(500);
}

testcase CheckMsgIgnition_Info()
{
  float lCycMinCycleTime;  // Minimum relative distance 
  float lCycMaxCycleTime;  // Maximum relative distance
  
  lCycMinCycleTime = kMIN_CYCLE_TIME;
  lCycMaxCycleTime = kMAX_CYCLE_TIME; 
  
  // Information for test report.
  TestCaseTitle("TC-4", "TC-4: Check cycle time of msg Ignition_Info");
  
  
  gCycCheckId = ChkStart_MsgAbsCycleTimeViolation (Ignition_Info,   // Message to supervise
                                    lCycMinCycleTime,            // min-limit
                                    lCycMaxCycleTime);           // max-limit
                                               
  CheckMsgCyc(lCycMinCycleTime, lCycMaxCycleTime);
  testRemoveCondition(gCycCheckId);
 }

testcase CheckMsgLight_Info()
{
  float lCycMinCycleTime;  // Minimum relative distance 
  float lCycMaxCycleTime;  // Maximum relative distance
  
  lCycMinCycleTime = Light_MIN_CYCLE_TIME;
  lCycMaxCycleTime = Light_MAX_CYCLE_TIME; 
  
  // Information for test report.
  TestCaseTitle("TC-5", "TC-5: Check cycle time of msg Light_Info");
  
  
  gCycCheckId = ChkStart_MsgAbsCycleTimeViolation (Light_Info,   // Message to supervise
                                    lCycMinCycleTime,            // min-limit
                                    lCycMaxCycleTime);           // max-limit
                                               
  CheckMsgCyc(lCycMinCycleTime, lCycMaxCycleTime);
  testRemoveCondition(gCycCheckId);
}
testcase CheckDLCLock_Info()
{
  dword checkId;  
  // Information for test report.
  TestCaseTitle("TC-6", "TC-6: Check msg DLC of Gear_Info");
  // checks the DLC of the message
  checkId = ChkStart_InconsistentDLC(Gear_Info);
  TestAddCondition(checkId);
  // sequence of different actions and waiting conditions
  TestWaitForTimeout(kTIMEOUT);
  TestRemoveCondition(checkId);
}
testcase CheckUndefinedMessage()
{            
  long lEventUndefineMessageId;             
  char lbuffer[100];

  gUndifnedMsgCheckResult = 0;

  // Information for test report.
  TestCaseTitle("TC-7", "TC-7: Check CAN channel for undefined messages");

  gCycCheckId = ChkStart_UndefinedMessageReceived("UndefinedMsgCallback");

  testWaitForTimeout(kTIMEOUT);

  switch(gUndifnedMsgCheckResult)
  {
    case 1:  
      // Event message ID
      lEventUndefineMessageId = ChkQuery_EventMessageId(gCycCheckId);
      snprintf(lbuffer,elcount(lbuffer),"Undefined message detacted: Id 0x%x", lEventUndefineMessageId);      
      TestStepFail("", lbuffer);
      break; 
    default:
      TestStepPass("","No undefined message detacted");       
      break; 
  }

  ChkControl_Destroy(gCycCheckId);
 }

UndefinedMsgCallback(dword aCheckId)
{
  ChkQuery_EventStatusToWrite(aCheckId);
  gUndifnedMsgCheckResult = 1;
}


CheckMsgCyc(float aCycMinCycleTime, float aCycMaxCycleTime)
{
  long lQueryResultNumProbes;
  long lQueryResultProbeAvg;
  long lQueryResultProbeMin;
  long lQueryResultProbeMax;
  char lbuffer[100];

  TestAddCondition(gCycCheckId);

  testWaitForTimeout(kTIMEOUT);
   
  lQueryResultNumProbes = ChkQuery_StatNumProbes(gCycCheckId);  
  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),"Max 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),"Max cycle time:      %dms", lQueryResultProbeMax);
      TestStepPass("", lbuffer);
  }

  ChkControl_Destroy(gCycCheckId); // Destroy the check
}

testcase CheckEngine_Speed()
{
  dword checkId;  
  // Information for test report.
  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!");  
  }
  else
  {
    TestStepFail("","Uncorrect Engine Speed Value!");  
  }
}

接下来就是执行自动化测试,以及查阅测试报告。具体内容未完善,后续有时间补充 

标签:Info,gCycCheckId,CANoe,lCycMinCycleTime,笔记,TC,lCycMaxCycleTime,第十四章,lbuffer
From: https://blog.csdn.net/m0_54956822/article/details/142645916

相关文章

  • CANoe学习笔记-第十章节-Panel实例
    1.前期准备工作1.1首先创建三个节点1.2添加相关的系统变量如下1.3新建如下dbc文件1.4 按照书中的要求,新建Panel面板2.三个节点的程序分别为2.1Engine 节点程序//EngineNodeCAPLProgramincludes{}variables{}......
  • Windows 笔记本 WiFi 功能消失问题解决
    背景说明许多Windows笔记本用户可能会遇到WiFi功能突然消失的问题。虽然网上有各种说法,但实际上,这个问题通常并非由病毒引起。大多数情况下,问题的根源是驱动程序丢失或笔记本静电干扰导致无线网卡无法正常工作。临时联网在解决WiFi问题期间,需要联网,可以尝试以下方法:使......
  • [Docker学习笔记]Docker的原理&&Docker常见命令
    文章目录什么是DockerDocker的优势Docker的原理Docker的安装Docker的`namespaces`Docker的常见命令`dockerversion`:查看版本信息`dockerinfo`查看docker详细信息我们关注的信息`dockersearch`:镜像搜索`dockerpull`:镜像拉取到本地`dockerpush`:推送本地镜像......
  • CDQ分治学习笔记
    CDQ分治学习笔记k维偏序问题求满足条件的二元组个数题意描述每个元素有\(k\)个值,要求满足(以\(k=2\)为例)\(a_j\lea_i,b_j\leb_i\)的点对个数。分析这实际上就是我们熟悉的逆序对问题,回忆一下我们是怎么处理的,首先来说,当\(a,b\)其中一个的含义是下标的时候可以直......
  • .NET|--WPF|--笔记合集|--依赖项属性|--5.附加属性
    前言附加属性是一个ExtensibleApplicationMarkupLanguage(XAML)概念。附加属性允许为派生自DependencyObject的任何XAML元素设置额外的属性/值对,即使该元素未在其对象模型中定义这些额外的属性。额外的属性可进行全局访问。附加属性通常定义为没有常规属性包装......
  • Windows下绿色安装PostgreSQL笔记
    介绍PostgreSQL,Postgres,以下简称为PG,是一款关系型数据库,本地安装支持两种方式,一键安装和绿色解压安装两种方式下载、解压安装版:https://www.enterprisedb.com/downloads/postgres-postgresql-downloads绿色解压版:https://www.enterprisedb.com/download-postgres......
  • prometheus学习笔记之alertmanager告警配置
    一、安装alertmanager项目地址:https://github.com/prometheus/alertmanager帮助文档:https://prometheus.io/docs/alerting/latest/alertmanager/配置文档:https://prometheus.io/docs/alerting/latest/configuration/wgethttps://github.com/prometheus/alertmanager/releas......
  • Pytorch学习笔记--搭建神经网络以及Sequential的使用
    首先,搭建一个如下图所示的神经网络: 分析图片,inputs输入图片的inchannels=3,尺寸是32*32,经过kernel_size=5的卷积操作后out_channels=32,尺寸32*32,套用下方公式可算出padding=2(默认dilation=1,stride=1):self.conv1=Conv2d(3,32,5,padding=2)  之后再进行池化操作Max-poolin......
  • 扫描线-学习笔记
    扫描线-学习笔记引言:扫描线算法用于解决给出多个矩形组成的图形求解其面积、周长等问题。时间复杂度常见为\(O(n\log_2^n)\)级别,空间复杂度略大于\(O(n)\),属于线段树的一种运用。一、求面积题目:P5490【模板】扫描线&矩形面积并求\(n\)个四边平行于坐标轴的矩形的面积......
  • MySQL数据库初级学习笔记---第一章-数据库概述
    第一章-数据库概述聊聊数据库数据库是一门独立的学科,只要是做软件开发的,数据库都要学。数据库(电子化的文件柜)是“按照数据结构来组织、存储和管理数据的仓库”。是一个长期存储在计算机内的、有组织的、可共享的、统一管理的大量数据的集合。它的存储空间很大,可以存放百万条......