Skip to content

Add deterministic UART decoder unit tests for device/serial - #3

Draft
deadsy with Copilot wants to merge 2 commits into
mainfrom
copilot/add-unit-test-suite
Draft

Add deterministic UART decoder unit tests for device/serial#3
deadsy with Copilot wants to merge 2 commits into
mainfrom
copilot/add-unit-test-suite

Conversation

Copilot AI commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

This PR adds a focused test suite for device/serial to cover UART frame decoding behavior without touching production code or requiring a live PTY. It validates normal decode paths and key error/re-sync paths across relevant config combinations.

  • Scope

    • Adds device/serial/uart_test.go only.
    • No changes to uart.go or pty.go.
  • Frame sample builder for decode-driven tests

    • Introduces a helper that emits oversampled serial line levels from (Config, value).
    • Encodes start/data/parity/stop bits with support for:
      • DataBits (5/7/8)
      • StopBits (1/2)
      • Parity (None/Even/Odd)
      • LsbLast and IdleLow
    • Parity generation matches decoder convention (parityAcc seeded from ParityOdd).
  • Round-trip decode matrix coverage

    • Table-driven decode tests feed generated samples into WriteSample and assert:
      • frame detection (gotFrame)
      • decoded value correctness under all combinations above
  • Negative-path coverage

    • Parity mismatch frame → asserts "parity error".
    • Bad stop bit (space instead of mark) → asserts "framing error".
    • Start-bit glitch (line returns high before center sample) → asserts no frame produced.
  • Utility coverage

    • Adds a direct unit test for bool2int(true)==1 and bool2int(false)==0.
samples := emitFrameSamples(*cfg, value, nil, nil)
got, gotFrame, err := feedSamples(u, samples)
if err != nil || !gotFrame || got != want {
	t.Fatalf("cfg=%+v value=0x%x got=%#x frame=%v err=%v want=%#x",
		*cfg, value, got, gotFrame, err, want)
}

Copilot AI changed the title [WIP] Add unit test suite for device/serial package Add deterministic UART decoder unit tests for device/serial Jul 14, 2026
Copilot AI requested a review from deadsy July 14, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants