Skip to content

Add comprehensive unit tests for validation and bit manipulation#1

Open
phillipjohnston wants to merge 3 commits intomainfrom
claude/add-new-tests-vGVJW
Open

Add comprehensive unit tests for validation and bit manipulation#1
phillipjohnston wants to merge 3 commits intomainfrom
claude/add-new-tests-vGVJW

Conversation

@phillipjohnston
Copy link
Member

Summary

This PR adds extensive unit test coverage for the FLEX decoder's validation and bit manipulation utilities, along with improvements to existing integration tests. The changes include new test suites for BCH validation, error correction, and bit operations, plus refactoring of existing tests to use helper functions and improve maintainability.

Key Changes

New Test Suites

  • validation_tests.c: Comprehensive tests for BCH validation and error correction

    • Tests for recreate_crc() ensuring valid BCH codewords are generated
    • Tests for validateBCH() with various payloads
    • Tests for validateWord() including idle pattern handling
    • Tests for attempt_repair() covering single-bit and double-bit error correction
  • bits_tests.c: Unit tests for bit manipulation utilities

    • Tests for reverse_bits_32() with edge cases (zero, all ones, single bits, known patterns)
    • Tests for count_set_bits() with various bit patterns
    • Tests for REVERSE_BITS_8 macro

Test Infrastructure Improvements

  • fsk2_1600_tests.c: Refactored to use helper functions

    • Added run_1600_decode_pipeline() helper to reduce code duplication
    • Added assert_numeric_biw() and assert_tone_alpha_biw() helpers for BIW validation
    • Added new test cases for tone and alphanumeric messages
  • fsk2_3200_tests.c: Refactored with helper functions

    • Added run_3200_decode_pipeline() helper for phase-aware decoding
    • Expanded test coverage with separate tests for BIW, address, and vector count validation
  • decode_address.c: Enhanced with additional unit tests

    • Added setup_frame() helper to initialize payload from raw data
    • New tests for shortBinaryToCapcode(), isAddressLong(), and longBinaryToCapcode()
    • Added boundary condition tests for address encoding
  • sync_tests.c: Improved state machine validation

    • Tests now verify state transitions and mode setting
    • Added test for invalid sync payload length handling

Source Code Changes

  • flex_types.h: Added TASK_NONE enum value and TASK_VALIDATE_AND_REPAIR_2 combined flag for cleaner API usage
  • flex_decoder_biw.c: Updated to use new TASK_VALIDATE_AND_REPAIR_2 flag; improved debug output with conditional compilation
  • flex_decoder_vectors.c: Updated to use TASK_REPAIR_BOTH for consistency
  • main.c: Integrated new test suites into test runner
  • tests.h: Added declarations for new test functions
  • meson.build: Added new test source files to build configuration

Notable Implementation Details

  • Helper functions reduce code duplication and improve test maintainability
  • Tests use realistic payload data from actual FLEX captures
  • BCH error correction tests verify both single-bit and double-bit error recovery
  • Bit manipulation tests include roundtrip verification and boundary conditions
  • State machine tests now verify both state transitions and payload mode configuration

https://claude.ai/code/session_01ETpUJpxR4khRGtaAqTbTGW

claude added 3 commits March 18, 2026 01:28
…der pipeline

- New test/bits_tests.c: 16 tests for reverse_bits_32(), count_set_bits(),
  and REVERSE_BITS_8 macro with known bit-pattern I/O pairs and roundtrip
  verification.

- New test/validation_tests.c: 13 tests covering recreate_crc() idempotency,
  validateBCH() correctness, validateWord() idle-word handling, and
  attempt_repair() single/double bit error correction.

- test/decode_address.c: 8 additional tests for shortBinaryToCapcode(),
  isAddressLong() boundary conditions, longBinaryToCapcode() known values,
  and checkForLongAddress() verified against real payload data.

- test/fsk2_1600_tests.c: All 4 stub functions now run the full decode
  pipeline (convert_to_blocks → validate_blocks → process_biw) with BIW
  field assertions and decoded capcode checks. Added 4 more test cases for
  tone, short-numeric, alphanumeric, and vec-count validation.

- test/fsk2_3200_tests.c: Stub replaced with 5 tests covering phase-A BIW
  fields, address decoding, vector count, and phase-B BIW/address for the
  short_addr_phase_b dataset.

- test/sync_tests.c: Completed fsk2_3200_sync_test with state/mode
  assertions; added invalid-length test that verifies WAIT_FOR_RX is kept.

- test/tests.h / test/main.c / test/meson.build: Register bits_tests() and
  validation_tests() and run sync_tests() alongside the existing suites.

Total: 81 tests pass (was 30).

https://claude.ai/code/session_01ETpUJpxR4khRGtaAqTbTGW
- Add named combined enum values (TASK_VALIDATE_AND_REPAIR_2,
  TASK_REPAIR_BOTH) to flex_val_task_t to eliminate EnumCastOutOfRange
  at all OR-combined call sites
- Initialize digit, byte, and hdr.signature to zero in
  flex_decoder_vectors.c to fix UndefinedBinaryOperatorResult and
  CallAndMessage warnings from uninitialized use before first assignment
- Wrap dead-store variables in process_biw_extra() inside #ifdef DEBUG
  guards since month/day/year/seconds/minutes/hour are only consumed by
  debug_printf which expands to nothing in non-debug builds
- Update all call sites in biw and vectors to use the new named constants

https://claude.ai/code/session_01ETpUJpxR4khRGtaAqTbTGW
- validation_tests.c: remove test_validateWord_valid_bch_word_passes
  (duplicated recreate_crc test) and test_attempt_repair_task1_only_single_bit
  (merged VALIDATE_REPAIRED_1 check into single_bit_corrects); remove
  defensive if(!validateBCH) guards from no-task tests so assertions are
  unconditional; simplify preserve_data_bits assertion to >> 11 comparison
- decode_address.c: remove test_long_binary_to_capcode_always_long
  (isAddressLong check now folded into roundtrip test); introduce
  setup_frame() helper to deduplicate the offset/len/sync-strip/convert
  pattern used in two tests; remove file-scoped offset/len globals
- fsk2_1600_tests.c: introduce assert_numeric_biw() and assert_tone_alpha_biw()
  helpers to replace identical 5-assertion blocks duplicated across 7 tests;
  remove fsk2_1600_test_vec_count_positive (vec_count derivable from the
  BIW values already asserted elsewhere); replace assert_int_not_equal(addr,0)
  with assert_true(addr != 0) for clearer intent
- sync_tests.c: register fsk2_3200_sync_test which was defined but never
  added to the test list (dead test)
- bits_tests.c: merge test_count_set_bits_single_bit and
  test_count_set_bits_nibble into test_count_set_bits_boundary_values;
  add explanatory comment to REVERSE_BITS_8 macro test about why & 0xFF
  mask is required (macro returns 64-bit intermediate)

https://claude.ai/code/session_01ETpUJpxR4khRGtaAqTbTGW
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