Skip to content

unit/fletcher: test fletcher-2 and fletcher-4 checksums#18747

Open
chrislongros wants to merge 1 commit into
openzfs:masterfrom
chrislongros:unit/fletcher-tests
Open

unit/fletcher: test fletcher-2 and fletcher-4 checksums#18747
chrislongros wants to merge 1 commit into
openzfs:masterfrom
chrislongros:unit/fletcher-tests

Conversation

@chrislongros

@chrislongros chrislongros commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Motivation and Context

Fletcher algorithm is the is checksum and hashing mechanism used in ZFS for error detection and data integrity.

Fletcher checksums have no test coverage. This adds a test_fletcher suite that explicitly tests the Fletcher-2 and Fletcher-4 routines in zfs_fletcher.c, including every SIMD and scalar implementation the host supports.

Description

Adds a test_fletcher suite calling the Fletcher checksum functions:

  • Fletcher-4: known answer test (KAT), incremental vs single-call marching, fletcher_4_native_varsize() vs fletcher_4_native(), native vs byteswap, and equality across every supported implementation (selected by name with fletcher_4_impl_set()).
  • Fletcher-2: known answer test (KAT), and incremental vs single-call matching.

How Has This Been Tested?

make unit T=fletcher:

> make unit T=fletcher
  UNITTEST tests/unit/test_fletcher
Running test suite with seed 0xc3bf5e76...
fletcher.fletcher4_known             [ OK    ] [ 0.00000138 / 0.00000048 CPU ]
fletcher.fletcher4_incremental       [ OK    ] [ 0.00000356 / 0.00000312 CPU ]
fletcher.fletcher4_varsize           [ OK    ] [ 0.00000453 / 0.00000409 CPU ]
fletcher.fletcher4_byteswap          [ OK    ] [ 0.00000360 / 0.00000319 CPU ]
fletcher.fletcher4_impls             [ OK    ] [ 0.00000892 / 0.00000890 CPU ]
fletcher.fletcher2_known             [ OK    ] [ 0.00000052 / 0.00000052 CPU ]
fletcher.fletcher2_incremental       [ OK    ] [ 0.00000235 / 0.00000234 CPU ]
7 of 7 (100%) tests successful, 0 (0%) test skipped.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Quality assurance (non-breaking change which makes the code more robust against bugs)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

  • My code follows the OpenZFS code style requirements.
  • I have updated the documentation accordingly.
  • I have read the contributing document.
  • I have added tests to cover my changes.
  • I have run the ZFS Test Suite with this change applied.
  • All commit messages are properly formatted and contain Signed-off-by.

Cover known answers, incremental vs single-call agreement, varsize,
byteswap, and cross-implementation equality.

Signed-off-by: Christos Longros <chris.longros@gmail.com>
@chrislongros

Copy link
Copy Markdown
Contributor Author

I am also considering a Monte Carlo test that tests bit flipping and random-sized increments.

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.

1 participant