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.

@acassis

acassis commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

@imeghar2408-max please fix the issues found by the CI,
before submitting the PR you should verify it locally using the checkpatch.sh, please read the contributing guy

@imeghar2408-max
imeghar2408-max force-pushed the fix/checksum-zero-length-test branch from 7eac961 to 682ff30 Compare September 6, 2026 14:47
@imeghar2408-max

Copy link
Copy Markdown
Author

Hi, thanks for pointing that out. I fixed the CI issues and verified the changes locally with checkpatch.sh. The check now passes with all checks passing. I’ve also force-pushed the updated commit.

@imeghar2408-max please fix the issues found by the CI, before submitting the PR you should verify it locally using the checkpatch.sh, please read the contributing guy

xiaoxiang781216
xiaoxiang781216 previously approved these changes Sep 7, 2026
jerpelea
jerpelea previously approved these changes Sep 7, 2026
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

Signed-off-by: Megha Rajput <i.meghar.2408@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants