Skip to content

testing/nettest: add checksum zero-length regression test - #3771

Open
imeghar2408-max wants to merge 1 commit into
apache:masterfrom
imeghar2408-max:fix/checksum-zero-length-test
Open

testing/nettest: add checksum zero-length regression test#3771
imeghar2408-max wants to merge 1 commit into
apache:masterfrom
imeghar2408-max:fix/checksum-zero-length-test

Conversation

@imeghar2408-max

Copy link
Copy Markdown

Summary

Add a CMocka regression test for the zero-length fragment handling issue in
checksum() reported in Apache NuttX issue #20010.

When checksum() is called with len == 0 while an odd byte is pending, the
previous implementation could read data[0] even though the current fragment
contained no valid bytes. It could also clear the pending odd-byte state.

The regression test covers this through the public chksum_iob() path using:

AA BB CC | empty fragment | DD EE

and verifies that the chained checksum matches the checksum of the equivalent
contiguous data:

AA BB CC DD EE

This verifies that an empty fragment does not affect the checksum and that
the pending odd-byte state is preserved across the empty fragment.

Changes

  • Add test_others_chksum() regression test.
  • Register the test in testing/nettest/others/test_others.c.
  • Add its declaration to testing/nettest/others/test_others.h.
  • Add the test source to testing/nettest/Makefile.
  • Add the test source to testing/nettest/CMakeLists.txt.

Impact

This change only adds a regression test to nuttx-apps.
It does not change runtime behavior or production code.

Validation

Regression test with the buggy implementation

The regression test was verified against the implementation without the
zero-length guard and failed as expected:

[ RUN      ] test_others_chksum
[ ERROR    ] --- 30617 != 30396
[ LINE     ] --- others/test_others_chksum.c:52
[  FAILED  ] test_others_chksum
Regression test with the fix applied

With the len == 0 handling fix restored, the test passed:

nsh: mount: mount failed: 20
nsh> cmocka_net_others
[==========] others_tests: Running 2 test(s).
[ RUN      ] test_others_bufpool
[       OK ] test_others_bufpool
[ RUN      ] test_others_chksum
[       OK ] test_others_chksum
[==========] others_tests: 2 test(s) run.
[  PASSED  ] 2 test(s).

The mount failed: 20 message occurs during simulator startup and did not
prevent cmocka_net_others from running successfully.

Checkpatch

The corresponding NuttX fix was checked with the CI-style command:

Used config files:

    1: .codespellrc
✔️ All checks pass.

Add a CMocka regression test for zero-length checksum fragments.
The test verifies that an empty IOB between fragments does not affect
the checksum calculation or pending odd-byte state.

Assisted by: GitHub Copilot
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