Add comprehensive unit tests for validation and bit manipulation#1
Open
phillipjohnston wants to merge 3 commits intomainfrom
Open
Add comprehensive unit tests for validation and bit manipulation#1phillipjohnston wants to merge 3 commits intomainfrom
phillipjohnston wants to merge 3 commits intomainfrom
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 correctionrecreate_crc()ensuring valid BCH codewords are generatedvalidateBCH()with various payloadsvalidateWord()including idle pattern handlingattempt_repair()covering single-bit and double-bit error correctionbits_tests.c: Unit tests for bit manipulation utilitiesreverse_bits_32()with edge cases (zero, all ones, single bits, known patterns)count_set_bits()with various bit patternsREVERSE_BITS_8macroTest Infrastructure Improvements
fsk2_1600_tests.c: Refactored to use helper functionsrun_1600_decode_pipeline()helper to reduce code duplicationassert_numeric_biw()andassert_tone_alpha_biw()helpers for BIW validationfsk2_3200_tests.c: Refactored with helper functionsrun_3200_decode_pipeline()helper for phase-aware decodingdecode_address.c: Enhanced with additional unit testssetup_frame()helper to initialize payload from raw datashortBinaryToCapcode(),isAddressLong(), andlongBinaryToCapcode()sync_tests.c: Improved state machine validationSource Code Changes
flex_types.h: AddedTASK_NONEenum value andTASK_VALIDATE_AND_REPAIR_2combined flag for cleaner API usageflex_decoder_biw.c: Updated to use newTASK_VALIDATE_AND_REPAIR_2flag; improved debug output with conditional compilationflex_decoder_vectors.c: Updated to useTASK_REPAIR_BOTHfor consistencymain.c: Integrated new test suites into test runnertests.h: Added declarations for new test functionsmeson.build: Added new test source files to build configurationNotable Implementation Details
https://claude.ai/code/session_01ETpUJpxR4khRGtaAqTbTGW