[PATCH 13/17] test: dm: eth: Add csum_ipv6_magic test

Viacheslav Mitrofanov v.v.mitrofanov at yadro.com
Tue Aug 30 14:31:00 CEST 2022


Test checksum computation. csum_ipv6_magic() uses in upper layer
protocols as TCP/UDP/ICMPv6/etc to calculate payload checksum.

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov at yadro.com>
---
 test/dm/eth.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/test/dm/eth.c b/test/dm/eth.c
index 4cc90cf514..bbfa14ef6d 100644
--- a/test/dm/eth.c
+++ b/test/dm/eth.c
@@ -70,6 +70,35 @@ static int dm_test_string_to_ip6(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_string_to_ip6, 0);
 
+static int dm_test_csum_ipv6_magic(struct unit_test_state *uts)
+{
+	unsigned short csum = 0xBEEF;
+	/* Predefined correct parameters */
+	unsigned short correct_csum = 0xD8AC;
+	struct in6_addr saddr = {.s6_addr32[0] = 0x000080fe,
+				 .s6_addr32[1] = 0x00000000,
+				 .s6_addr32[2] = 0xffe9f242,
+				 .s6_addr32[3] = 0xe8f66dfe};
+	struct in6_addr daddr = {.s6_addr32[0] = 0x000080fe,
+				 .s6_addr32[1] = 0x00000000,
+				 .s6_addr32[2] = 0xffd5b372,
+				 .s6_addr32[3] = 0x3ef692fe};
+	u16 len = 1460;
+	unsigned short proto = 17;
+	unsigned int head_csum = 0x91f0;
+
+	csum = csum_ipv6_magic(&saddr, &daddr, len, proto, head_csum);
+	ut_assert(csum == correct_csum);
+
+	/* Broke a parameter */
+	proto--;
+	csum = csum_ipv6_magic(&saddr, &daddr, len, proto, head_csum);
+	ut_assert(csum != correct_csum);
+
+	return 0;
+}
+DM_TEST(dm_test_csum_ipv6_magic, 0);
+
 static int dm_test_eth(struct unit_test_state *uts)
 {
 	net_ping_ip = string_to_ip("1.1.2.2");
-- 
2.25.1



More information about the U-Boot mailing list