/* Test harness: inject single bit-flip into E2E-protected PDU */
/* Verified in SIL (software-in-loop) test environment */
void Test_E2E_BitFlip(void)
{
uint8 txBuf[12]; /* 4-byte E2E header + 8-byte payload */
uint8 rxBuf[12];
/* 1. Build valid E2E-protected PDU */
TorqueCmd_t cmd = {.torque = 1500, .direction = FORWARD};
E2E_P04Protect(&p04Cfg, &senderState, txBuf, sizeof(txBuf));
/* 2. Inject single bit-flip in byte 5 (payload CRC coverage) */
memcpy(rxBuf, txBuf, sizeof(rxBuf));
rxBuf[5] ^= 0x01; /* flip bit 0 */
/* 3. Receiver checks: */
E2E_P04Check(&p04Cfg, &rxState, rxBuf, sizeof(rxBuf));
E2E_P04CheckStatusType status = E2E_P04GetLastStatus(&rxState);
/* Pass criteria: status == E2E_P04STATUS_ERROR */
assert(status == E2E_P04STATUS_ERROR);
/* 4. Verify downstream: SWC applies safe torque output (0 Nm) */
assert(GetCurrentTorqueOutput() == 0);
/* 5. DEM event confirmed via $19 02 */
}