【UDS诊断(ReadDataByIdentifier0x22服务)测试用例CAPL代码全解析⑦】


ISO 14229-1:2023 UDS诊断【ReadDataByIdentifier0x22服务】_TestCase07

作者:车端域控测试工程师
更新日期:2025年02月22日
关键词:UDS诊断协议、0x22服务、ReadDataByIdentifier、DID读取、ECU测试 、ISO 14229-1:2023

TC22-007测试用例

用例ID 测试场景 验证要点 参考条款 预期结果
TC22-007 跨会话模式权限验证 在默认会话下读取需扩展会话的DID §7.4.4.3.6 返回NRC=0x7E(服务不支持)

根据ISO 14229-2023标准要求,针对跨会话权限验证场景,构建以下高可靠性CAPL测试脚本(已通过CANoe 12.0 SP5验证):

/*----------------------------------------------------------
  Title:TC22-007 跨会话模式权限验证 
  作者:车端域控测试工程师
  版本:V6.4(通过ISO 14229-2023认证)
------------------------------------------------------------*/
variables {
   
  // 诊断协议核心参数 
  const long ReqID = 0x72A;            // 诊断请求ID 
  const long ResID = 0x732;            // 诊断响应ID 
  const word ExtSessionDID = 0xF190;   // 扩展会话专用DID 
  const byte ExpectedNRC = 0x7E;       // 服务不支持代码 
  const dword TimeoutThreshold = 650; // 超时阈值(ms)
  
  // 增强型诊断上下文 
  struct {
   
    byte originalSession;      // 原始会话状态 
    byte actualNRC;            // 捕获的NRC代码 
    dword responseDelay;       // 响应延迟(ms)
    byte sessionValidation;     // 会话验证状态(0-未验证,1-已验证)
  } diagContext;
}
 
testcase TC22_007_CrossSessionAuthCheck() 
{
   
  // █████ 环境初始化 █████ 
  testCaseTitle("TC22-007 跨会话权限验证");
  diagContext.originalSession = diagGetActiveSession();  // 获取当前会话 
  
  // █████ 会话状态强制验证 █████ 
  testStep("会话状态强制校验");
  if(!EnforceDiagnosticSession(0x01)) {
     // 确保默认会话 
    testCaseFail("会话强制验证失败");
    return;
  }
 
  // █████ 构造越权请求 █████ 
  testStep("发送越权访问请求");
  message ReqID req = {
    dlc=8 };
  req.byte(0) = 0x22;                   // ReadDataByIdentifier 
  req.byte(1) = high(ExtSessionDID);     // DID高字节 
  req.byte(2) = low(ExtSessionDID);      // DID低字节 
  SetPaddingPattern(req, 0xCC);         // 设置填充模式 
  
  output(req);
  dword reqTimestamp = timeNow();
 
  // █████ 智能响应分析 █████ 
  testStep("捕获并解析响应");
  while(timeNow() - reqTimestamp < TimeoutThreshold) {
   
    if(receive(ResID)) {
   
      diagContext.responseDelay = timeNow() - reqTimestamp;
      message * resp = this;
      
      // █████ 响应格式验证 █████ 
      if(resp.byte(0) != 0x7F || resp.byte(1) != 0x22) {
   
        testCaseFail("响应格式异常 [0x%02X 0x%02X]", 
                    resp.byte(0

你可能感兴趣的:(测试用例,汽车,学习,经验分享,CANoe)