尧图建网站 尧图建网站 YAOTU WEB BUILD 免费咨询
ARTICLE DETAIL

资讯详情

深耕网站建设与建站编程的一线实战洞察。

CAN 通信冒烟测试

CAN 通信冒烟测试 主要针对CAN的message ID/DLC和周期时间进行测试CAN需求文档例如CAN1的两帧数据Message IDMessage NameMessage TypeMessage LengthMessage Send TypeCycle Time(ms)0x109DoorAndLockStsCANFD_Standard8Cyclic100x300LockSettingStCANFD_Standard8Cyclic100两帧数据DoorAndLockSts 的Message ID 是0x109DLC是8周期发送发送周期是10LockSettingSt 的Message ID 是0x300DLC是8周期发送发送周期是100需要针对以上内容进行测试测试脚本/*!Encoding:936*/ includes { } variables { int res; // 文本事件等待返回结果 // Body_FD_CAN // ---- 帧 DoorAndLockSts (0x109) ---- int collect_DoorAndLockSts; dword timelist_DoorAndLockSts[8]; int idx_DoorAndLockSts; dword id_DoorAndLockSts; int dlc_DoorAndLockSts; // ---- 帧 LockSettingSt (0x300) ---- int collect_LockSettingSt; dword timelist_LockSettingSt[8]; int idx_LockSettingSt; dword id_LockSettingSt; } // ---------- 甯?DoorAndLockSts (0x109) : 鏈熸湜 DLC8, 鍛ㄦ湡10ms, 鍙戦€佹柟CVC_CP1 ---------- on message DoorAndLockSts { if (collect_DoorAndLockSts) { if (idx_DoorAndLockSts 4) { timelist_DoorAndLockSts[idx_DoorAndLockSts] timeNow(); idx_DoorAndLockSts; } else { TestSupplyTextEvent(DoorAndLockSts collect finished.); } id_DoorAndLockSts this.id; dlc_DoorAndLockSts this.dlc; } } export testcase Test_BODY_FD_Cycle_DoorAndLockSts_Period() { dword interval; collect_DoorAndLockSts 1; idx_DoorAndLockSts 0; res TestWaitForTextEvent(DoorAndLockSts collect finished., (10*6)); if (res ! 1) { testStepFail(msgCallBack, DoorAndLockSts(0x109) do not recv 4 within (10*6)ms, real recv %d times, idx_DoorAndLockSts); } if (id_DoorAndLockSts 0x109) { testStepPass(frameID Check, ID of DoorAndLockSts except 0x109, real 0x%x, id_DoorAndLockSts); } else { testStepFail(frameID Check, ID of DoorAndLockSts except 0x109, real 0x%x, id_DoorAndLockSts); } id_DoorAndLockSts -1; if (dlc_DoorAndLockSts 8) { testStepPass(frameDLC Check, DLC of DoorAndLockSts except 8, real %d, dlc_DoorAndLockSts); } else { testStepFail(frameDLC Check, DLC of DoorAndLockSts except 8, real %d, dlc_DoorAndLockSts); } dlc_DoorAndLockSts -1; for(; idx_DoorAndLockSts 1; idx_DoorAndLockSts--) { interval timelist_DoorAndLockSts[idx_DoorAndLockSts-1] - timelist_DoorAndLockSts[idx_DoorAndLockSts-2]; if(interval (10*90) interval (10*110)) { testStepPass(interval Check, DoorAndLockSts(0x109) interval No.%d [except: 10/-10%% || real: %d ms], 5-idx_DoorAndLockSts, interval/100); } else { testStepFail(interval Check, DoorAndLockSts(0x109) interval No.%d [except: 10/-10%% || real: %d ms], 5-idx_DoorAndLockSts, interval/100); } } idx_DoorAndLockSts 0; collect_DoorAndLockSts 0; } // ---------- 甯?LockSettingSt (0x300) : 鏈熸湜 DLC8, 鍛ㄦ湡100ms, 鍙戦€佹柟CVC_CP1 ---------- on message LockSettingSt { if (collect_LockSettingSt) { if (idx_LockSettingSt 4) { timelist_LockSettingSt[idx_LockSettingSt] timeNow(); idx_LockSettingSt; } else { TestSupplyTextEvent(LockSettingSt collect finished.); } id_LockSettingSt this.id; dlc_LockSettingSt this.dlc; } } export testcase Test_BODY_FD_Cycle_LockSettingSt_Period() { dword interval; collect_LockSettingSt 1; idx_LockSettingSt 0; // 绛夊緟閲囬泦瀹屾垚浜嬩欢, 瓒呮椂鍙栧懆鏈?6 浣滀负浣欓噺 res TestWaitForTextEvent(LockSettingSt collect finished., (100*6)); if (res ! 1) { testStepFail(msgCallBack, LockSettingSt(0x300) do not recv 4 within (100*6)ms, real recv %d times, idx_LockSettingSt); } // ID 鏍獙 if (id_LockSettingSt 0x300) { testStepPass(frameID Check, ID of LockSettingSt except 0x300, real 0x%x, id_LockSettingSt); } else { testStepFail(frameID Check, ID of LockSettingSt except 0x300, real 0x%x, id_LockSettingSt); } id_LockSettingSt -1; // DLC 鏍獙 if (dlc_LockSettingSt 8) { testStepPass(frameDLC Check, DLC of LockSettingSt except 8, real %d, dlc_LockSettingSt); } else { testStepFail(frameDLC Check, DLC of LockSettingSt except 8, real %d, dlc_LockSettingSt); } dlc_LockSettingSt -1; // 鍛ㄦ湡鏍獙: 瀹瑰樊 100ms /-10% - [100*90, 100*110] (timeNow 鍗曚綅) for(; idx_LockSettingSt 1; idx_LockSettingSt--) { interval timelist_LockSettingSt[idx_LockSettingSt-1] - timelist_LockSettingSt[idx_LockSettingSt-2]; if(interval (100*90) interval (100*110)) { testStepPass(interval Check, LockSettingSt(0x300) interval No.%d [except: 100/-10%% || real: %d ms], 5-idx_LockSettingSt, interval/100); } else { testStepFail(interval Check, LockSettingSt(0x300) interval No.%d [except: 100/-10%% || real: %d ms], 5-idx_LockSettingSt, interval/100); } } idx_LockSettingSt 0; collect_LockSettingSt 0; // 澶嶄綅閲囬泦寮€鍏? 閬垮厤褰卞搷鍚庣画鐢ㄤ緥 }更新版本/*!Encoding:936*/ // Optimized CAN smoke-test: data-driven refactor. // All per-frame state expected values live in one struct/map. // Each on message delegates to CollectFrame(); each testcase calls CheckPeriod(). includes { } variables { int res; // TestWaitForTextEvent return value struct FrameCfg { int collect; // collection switch dword timelist[8]; // timestamps int idx; // collected count dword id; // actual frame id int dlc; // actual dlc dword expId; // expected frame id int expDlc; // expected dlc int period; // expected period (ms): used for timeout tolerance }; struct FrameCfg gFrames[char]; // keyed by frame name } // ---------- one-line collectors (message name resolves its own network/channel) ---------- on message DoorAndLockSts { CollectFrame(DoorAndLockSts, this.id, this.dlc); } on message LockSettingSt { CollectFrame(LockSettingSt, this.id, this.dlc); } } // ---------- testcases: 3 lines each ---------- export testcase Test_BODY_FD_Cycle_DoorAndLockSts_Period() { gFrames[DoorAndLockSts].collect 1; gFrames[DoorAndLockSts].idx 0; CheckPeriod(DoorAndLockSts); } export testcase Test_BODY_FD_Cycle_LockSettingSt_Period() { gFrames[LockSettingSt].collect 1; gFrames[LockSettingSt].idx 0; CheckPeriod(LockSettingSt); }
返回列表