ToB企服应用市场:ToB评测及商务社交产业平台

标题: 【ISO 14229-1:2023 UDS诊断(会话控制0x10服务)测试用例CAPL代码全解析⑥ [打印本页]

作者: 宁睿    时间: 2025-2-16 18:11
标题: 【ISO 14229-1:2023 UDS诊断(会话控制0x10服务)测试用例CAPL代码全解析⑥
ISO 14229-1:2023 UDS诊断【会话控制0x10服务】_TestCase06

作者:车端域控测试工程师
更新日期:2025年02月14日
关键词:UDS诊断、0x10服务、诊断会话控制、ECU测试、ISO 14229-1:2023
TC10-006测试用例

用例ID测试场景验证要点参考条款预期效果TC10-006会话嵌套冲突检测在编程会话中哀求切换至扩展会话§7.5.3返回NRC=0x22(条件不满意)
  1. /*-------------------------------------------------------------------
  2.   测试用例 TC10-006:会话嵌套冲突检测(增强版)
  3.   标准依据:ISO 14229-1 §7.5.3
  4.   验证目标:编程会话中禁止切换其他会话模式
  5.   预期响应:NRC=0x22(conditionsNotCorrect)
  6. -------------------------------------------------------------------*/
  7. variables {
  8.   message 0x7E0 DiagReq = {dlc=8};  // 诊断请求报文
  9.   message 0x7E8 DiagRes;           // 诊断响应报文
  10.   msTimer securityDelay;           // 安全延时计时器
  11.   byte currentSession;             // 当前会话状态
  12.   byte securityLevel;              // 安全访问级别
  13.   byte seed[4];                    // 安全种子存储
  14.   byte key[4];                     // 计算密钥存储
  15. }
  16. //==================== 预置条件设置函数 ====================
  17. void Precondition_ProgrammingSession() {
  18.   /
  19.   分步式会话建立流程:
  20.   1. 强制进入默认会话
  21.   2. 请求进入编程会话
  22.   3. 执行安全访问解锁
  23.   4. 验证最终状态
  24.   /
  25.   
  26.   // 阶段1:确保默认会话
  27.   sysSetVariable("Diag::Session", 0x01);
  28.   DiagReq.byte(0) = 0x10;          // 诊断会话控制
  29.   DiagReq.byte(1) = 0x01;          // 默认会话
  30.   DiagReq.dlc = 2;
  31.   output(DiagReq);
  32.   testWaitForMessage(0x7E8, 1000);
  33.   if(DiagRes.byte(0) != 0x50 || DiagRes.byte(1) != 0x01) {
  34.     testStepAbort("默认会话建立失败");
  35.   }
  36.   // 阶段2:进入编程会话
  37.   DiagReq.byte(1) = 0x02;          // 编程会话
  38.   output(DiagReq);
  39.   testWaitForMessage(0x7E8, 1500);
  40.   if(DiagRes.byte(0) != 0x50 || DiagRes.byte(1) != 0x02) {
  41.     testStepAbort("编程会话进入失败,代码:0x%02X%02X",
  42.                  DiagRes.byte(0), DiagRes.byte(1));
  43.   }
  44.   // 阶段3:安全访问解锁(示例算法)
  45.   // 步骤3.1:请求种子
  46.   DiagReq.byte(0) = 0x27;          // 安全访问服务
  47.   DiagReq.byte(1) = 0x01;          // 请求种子
  48.   output(DiagReq);
  49.   testWaitForMessage(0x7E8, 2000);
  50.   if(DiagRes.byte(0) == 0x67 && DiagRes.byte(1) == 0x01) {
  51.     // 提取种子值(假设4字节种子)
  52.     seed[0] = DiagRes.byte(2);
  53.     seed[1] = DiagRes.byte(3);
  54.     seed[2] = DiagRes.byte(4);
  55.     seed[3] = DiagRes.byte(5);
  56.    
  57.     // 步骤3.2:发送密钥(示例:取反算法)
  58.     key[0] = ~seed[0];
  59.     key[1] = ~seed[1];
  60.     key[2] = ~seed[2];
  61.     key[3] = ~seed[3];
  62.    
  63.     DiagReq.byte(1) = 0x02;        // 发送密钥
  64.     DiagReq.byte(2) = key[0];
  65.     DiagReq.byte(3) = key[1];
  66.     DiagReq.byte(4) = key[2];
  67.     DiagReq.byte(5) = key[3];
  68.     DiagReq.dlc = 6;
  69.     output(DiagReq);
  70.     testWaitForMessage(0x7E8, 2000);
  71.     if(DiagRes.byte(0) != 0x67 || DiagRes.byte(1) != 0x02) {
  72.       testStepAbort("安全解锁失败,代码:0x%02X%02X",
  73.                    DiagRes.byte(0), DiagRes.byte(1));
  74.     }
  75.   } else {
  76.     testStepAbort("种子获取失败,代码:0x%02X%02X",
  77.                  DiagRes.byte(0), DiagRes.byte(1));
  78.   }
  79.   // 阶段4:最终状态验证
  80.   if(sysGetVariable("Diag::Session") != 0x02 ||
  81.      sysGetVariable("Security::Unlocked") != 0x01) {
  82.     testStepAbort("预置条件验证失败:会话=0x%02X 安全=0x%02X",
  83.                  sysGetVariable("Diag::Session"),
  84.                  sysGetVariable("Security::Unlocked"));
  85.   }
  86. }
  87. //==================== 主测试用例 ====================
  88. testcase TC10_006_SessionNestingCheck()
  89. {
  90.   // 执行增强型预置条件设置
  91.   Precondition_ProgrammingSession();
  92.   write("预置条件验证通过:已进入安全解锁的编程会话");
  93.   //==================== 测试步骤执行 ====================
  94.   DiagReq.byte(0) = 0x10;          // 诊断会话控制
  95.   DiagReq.byte(1) = 0x03;          // 扩展会话
  96.   DiagReq.dlc = 2;
  97.   output(DiagReq);                 // 发送冲突请求
  98.   
  99.   //==================== 响应分析 ====================
  100.   testWaitForMessage(0x7E8, 1500); // 1.5秒响应超时
  101.   if(TestGetLastError() == teTimeout) {
  102.     testStepFail("ECU响应超时");
  103.   }
  104.   else if(DiagRes.byte(0) == 0x7F && DiagRes.byte(2) == 0x22) {
  105.     testStepPass("NRC 0x22验证成功");
  106.   }
  107.   else {
  108.     testStepFail("异常响应:0x%02X%02X%02X",
  109.                 DiagRes.byte(0), DiagRes.byte(1), DiagRes.byte(2));
  110.   }
  111.   //==================== 后置清理 ====================
  112.   // 发送硬件复位恢复初始状态
  113.   DiagReq.byte(0) = 0x11;          // ECU复位
  114.   DiagReq.byte(1) = 0x01;          // 硬件复位
  115.   output(DiagReq);
  116.   testWaitForTimeout(3000);        // 等待ECU重启
  117. }
  118. /*------------------------- 执行日志示例 -------------------------
  119. [2025-02-15 21:47:15] 进入默认会话成功
  120. [2025-02-15 21:47:16] 编程会话建立成功
  121. [2025-02-15 21:47:17] 安全解锁完成(种子:A7 3B F0 89)
  122. [2025-02-15 21:47:18] 发送非法会话切换请求:10 03
  123. [2025-02-15 21:47:18] 收到预期响应:7F 10 22
  124. [2025-02-15 21:47:21] ECU复位成功
  125. ----------------------------------------------------------------*/
复制代码

加强特性说明
  1. // 分阶段建立目标状态(取代直接设置变量)
  2. Precondition_ProgrammingSession();
复制代码
  1. // 预留安全算法扩展点(示例为取反算法)
  2. on key* {
  3.   // 可替换为实际安全算法
  4.   key[i] = ~seed[i];
  5. }
复制代码
  1. // 实时监控诊断状态
  2. on sysvar Diag::Session changed {
  3.   write("会话变更:0x%02X → 0x%02X @ %dms",
  4.        @sysvar::Diag::Session, @this, timeNow());
  5. }
复制代码

预置条件流程图
     
关键改进点

测试数据记载发起
在测试报告中应包罗以下关键数据:

摆设说明:

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4