Hardware interview practice
Verify editable command-trace frames
Write the edit oracle and framing checks for two bounded command streams where each '#' byte removes the previous surviving byte, if any.
Starting point
Question code
typedef enum { EDIT_OK, EDIT_BAD_ARG, EDIT_HW_ERROR, EDIT_TIMEOUT } edit_status_t;
edit_status_t compare_edited(const uint8_t *a, uint8_t na,
const uint8_t *b, uint8_t nb,
bool *equal, uint32_t timeout);
// A_FIFO/B_FIFO{DATA,LAST}, CMD{A_LEN,B_LEN,START,ABORT}
// STATUS{A_READY,B_READY,BUSY,DONE,ERR}, RESULT{EQUAL}Reviewed example
Work through one case
Input
frame A="ab#c"; frame B="ad#c"Expected output
survivors A="ac", B="ac"; equal=1Each # removes the immediately previous surviving byte, so both bounded stack models finish with the same sequence.
What to cover
Requirements
- Validate pointers and lengths before MMIO and send each nonempty frame only while its FIFO is ready.
- Require LAST only on the declared final byte; empty frames perform no FIFO write.
- Process accepted bytes with bounded stacks and change the caller's equal result only after successful DONE.
- Flush both frames after malformed framing, early START, timeout, abort, or reset and prevent partial results from escaping.
