diff options
author | Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com> | 2022-12-02 12:18:10 +0300 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2022-12-05 12:47:17 -0500 |
commit | d9f5c41e9ac64c255a88832488a425d6d4f275ae (patch) | |
tree | 9b5b2054c0c4e06289655e09e958246a6d6f3673 | |
parent | 184ded4becced88170ed7c3296c97e6b1a174896 (diff) | |
download | u-boot-d9f5c41e9ac64c255a88832488a425d6d4f275ae.zip u-boot-d9f5c41e9ac64c255a88832488a425d6d4f275ae.tar.gz u-boot-d9f5c41e9ac64c255a88832488a425d6d4f275ae.tar.bz2 |
test: dm: eth: Add csum_ipv6_magic test
Test checksum computation. csum_ipv6_magic() uses in upper layer
protocols as TCP/UDP/ICMPv6/etc to calculate payload checksum.
Series-changes: 3
- Fixed style problems
Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
-rw-r--r-- | test/dm/eth.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/dm/eth.c b/test/dm/eth.c index a3d4fc0..5ffa0c4 100644 --- a/test/dm/eth.c +++ b/test/dm/eth.c @@ -75,6 +75,35 @@ static int dm_test_string_to_ip6(struct unit_test_state *uts) return 0; } 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_asserteq(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); #endif static int dm_test_eth(struct unit_test_state *uts) |