This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 3c0fdc1ff testing/nettest: add checksum zero-length regression test
3c0fdc1ff is described below
commit 3c0fdc1ff6e0ba7b8b558a0675bf8c4743d740dd
Author: Megha Rajput <[email protected]>
AuthorDate: Fri Sep 4 13:50:30 2026 +0000
testing/nettest: add checksum zero-length regression test
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 <[email protected]>
---
testing/nettest/CMakeLists.txt | 3 +-
testing/nettest/Makefile | 3 +-
testing/nettest/others/test_others.c | 1 +
testing/nettest/others/test_others.h | 1 +
testing/nettest/others/test_others_chksum.c | 76 +++++++++++++++++++++++++++++
5 files changed, 82 insertions(+), 2 deletions(-)
diff --git a/testing/nettest/CMakeLists.txt b/testing/nettest/CMakeLists.txt
index 94fa4557f..6bbf95753 100644
--- a/testing/nettest/CMakeLists.txt
+++ b/testing/nettest/CMakeLists.txt
@@ -77,7 +77,8 @@ if(CONFIG_TESTING_NET_TEST)
set(SRCS
${CMAKE_CURRENT_LIST_DIR}/others/test_others.c
${CMAKE_CURRENT_LIST_DIR}/others/test_others_common.c
- ${CMAKE_CURRENT_LIST_DIR}/others/test_others_bufpool.c)
+ ${CMAKE_CURRENT_LIST_DIR}/others/test_others_bufpool.c
+ ${CMAKE_CURRENT_LIST_DIR}/others/test_others_chksum.c)
nuttx_add_application(
NAME
diff --git a/testing/nettest/Makefile b/testing/nettest/Makefile
index 6f10c3910..3e5f4f22a 100644
--- a/testing/nettest/Makefile
+++ b/testing/nettest/Makefile
@@ -54,7 +54,8 @@ endif
ifeq ($(CONFIG_TESTING_NET_OTHERS),y)
MAINSRC += others/test_others.c
PROGNAME += cmocka_net_others
-CSRCS += others/test_others_common.c others/test_others_bufpool.c
+CSRCS += others/test_others_common.c others/test_others_bufpool.c \
+ others/test_others_chksum.c
endif
endif
diff --git a/testing/nettest/others/test_others.c
b/testing/nettest/others/test_others.c
index b883840d2..994f1eaf9 100644
--- a/testing/nettest/others/test_others.c
+++ b/testing/nettest/others/test_others.c
@@ -39,6 +39,7 @@ int main(int argc, FAR char *argv[])
const struct CMUnitTest others_tests[] =
{
cmocka_unit_test(test_others_bufpool),
+ cmocka_unit_test(test_others_chksum),
};
return cmocka_run_group_tests(others_tests, test_others_group_setup,
diff --git a/testing/nettest/others/test_others.h
b/testing/nettest/others/test_others.h
index f59024e84..621be46a7 100644
--- a/testing/nettest/others/test_others.h
+++ b/testing/nettest/others/test_others.h
@@ -48,5 +48,6 @@ int test_others_group_teardown(FAR void **state);
****************************************************************************/
void test_others_bufpool(FAR void **state);
+void test_others_chksum(FAR void **state);
#endif /* __APPS_TESTING_NETTEST_OTHERS_TEST_OTHERS_H */
diff --git a/testing/nettest/others/test_others_chksum.c
b/testing/nettest/others/test_others_chksum.c
new file mode 100644
index 000000000..ea6fb0903
--- /dev/null
+++ b/testing/nettest/others/test_others_chksum.c
@@ -0,0 +1,76 @@
+/****************************************************************************
+ * apps/testing/nettest/others/test_others_chksum.c
+ *
+ * Included Files
+ ****************************************************************************/
+
+#include <setjmp.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <string.h>
+#include <cmocka.h>
+
+#include <nuttx/mm/iob.h>
+#include <nuttx/net/netdev.h>
+
+#include "test_others.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void test_others_chksum(FAR void **state)
+{
+ struct iob_s iob1;
+ struct iob_s iob2;
+ struct iob_s iob3;
+ uint8_t data1[] =
+ {
+ 0xaa, 0xbb, 0xcc
+ };
+
+ uint8_t data2[] =
+ {
+ 0xdd, 0xee
+ };
+
+ uint8_t data[] =
+ {
+ 0xaa, 0xbb, 0xcc, 0xdd, 0xee
+ };
+
+ uint16_t chained_sum;
+ uint16_t reference_sum;
+
+ memset(&iob1, 0, sizeof(iob1));
+ memset(&iob2, 0, sizeof(iob2));
+ memset(&iob3, 0, sizeof(iob3));
+
+ /* First IOB: odd number of bytes */
+
+ memcpy(iob1.io_data, data1, sizeof(data1));
+ iob1.io_len = sizeof(data1);
+ iob1.io_offset = 0;
+ iob1.io_flink = &iob2;
+
+ /* Second IOB: zero-length */
+
+ iob2.io_data[0] = 0xdd;
+ iob2.io_len = 0;
+ iob2.io_offset = 0;
+ iob2.io_flink = &iob3;
+
+ /* Third IOB: remaining bytes */
+
+ memcpy(iob3.io_data, data2, sizeof(data2));
+ iob3.io_len = sizeof(data2);
+ iob3.io_offset = 0;
+ iob3.io_flink = NULL;
+
+ chained_sum = chksum_iob(0, &iob1, 0);
+ reference_sum = chksum(0, data, sizeof(data));
+
+ assert_int_equal(chained_sum, reference_sum);
+}
+