diff options
author | Charlie Root <renato.riolino@eldorado.org.br> | 2021-01-12 01:56:12 +0000 |
---|---|---|
committer | Alan Somers <asomers@FreeBSD.org> | 2021-01-12 02:03:46 +0000 |
commit | 292808246db702b9194deb8938e40fd06914aea9 (patch) | |
tree | adb48361d0ed2b15da1d6d236fc86ada6b758506 | |
parent | 7eaea04a5bb1dc86c43ce046311e1c1a042994d3 (diff) | |
download | src-292808246db702b9194deb8938e40fd06914aea9.tar.gz src-292808246db702b9194deb8938e40fd06914aea9.zip |
ICMP checksum test: Fix for big endian
The in_cksum tests originally tried to simulate a BE environment by
swapping the byte order of the input. But that's overcomplicated, and
didn't actually work on real BE hardware. The correct testing strategy
is just to test on the native endianness, and run the tests in both BE
and LE environments.
Submitted by: Renato Riolino <renato.riolino@eldorado.org.br>
Reviewed By: asomers
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D23193
-rw-r--r-- | sbin/ping/tests/in_cksum_test.c | 84 |
1 files changed, 20 insertions, 64 deletions
diff --git a/sbin/ping/tests/in_cksum_test.c b/sbin/ping/tests/in_cksum_test.c index fc266545b432..597f6ac20722 100644 --- a/sbin/ping/tests/in_cksum_test.c +++ b/sbin/ping/tests/in_cksum_test.c @@ -39,92 +39,52 @@ __FBSDID("$FreeBSD$"); * Test cases. */ -ATF_TC_WITHOUT_HEAD(aligned_even_length_big_endian); -ATF_TC_BODY(aligned_even_length_big_endian, tc) +ATF_TC_WITHOUT_HEAD(aligned_even_length); +ATF_TC_BODY(aligned_even_length, tc) { u_char data[] __aligned(sizeof(u_short)) = {0x12, 0x34, 0x56, 0x78}; u_short sum; sum = in_cksum(data, nitems(data)); - ATF_REQUIRE(sum == 0x5397); + u_char *c_sum = (u_char *)∑ + ATF_REQUIRE(c_sum[0] == 0x97 && c_sum[1] == 0x53); } -ATF_TC_WITHOUT_HEAD(aligned_odd_length_big_endian); -ATF_TC_BODY(aligned_odd_length_big_endian, tc) +ATF_TC_WITHOUT_HEAD(aligned_odd_length); +ATF_TC_BODY(aligned_odd_length, tc) { u_char data[] __aligned(sizeof(u_short)) = {0x12, 0x34, 0x56, 0x78, 0x9a}; u_short sum; sum = in_cksum(data, nitems(data)); - ATF_REQUIRE(sum == 0x52fd); + u_char *c_sum = (u_char *)∑ + ATF_REQUIRE(c_sum[0] == 0xfd && c_sum[1] == 0x52); } -ATF_TC_WITHOUT_HEAD(aligned_even_length_little_endian); -ATF_TC_BODY(aligned_even_length_little_endian, tc) -{ - u_char data[] __aligned(sizeof(u_short)) = - {0x34, 0x12, 0x78, 0x56}; - u_short sum; - - sum = in_cksum(data, nitems(data)); - ATF_REQUIRE_MSG(sum == 0x9753, "%d", sum); -} - -ATF_TC_WITHOUT_HEAD(aligned_odd_length_little_endian); -ATF_TC_BODY(aligned_odd_length_little_endian, tc) -{ - u_char data[] __aligned(sizeof(u_short)) = - {0x34, 0x12, 0x78, 0x56, 0x00, 0x9a}; - u_short sum; - - sum = in_cksum(data, nitems(data)); - ATF_REQUIRE(sum == 0xfd52); -} - -ATF_TC_WITHOUT_HEAD(unaligned_even_length_big_endian); -ATF_TC_BODY(unaligned_even_length_big_endian, tc) +ATF_TC_WITHOUT_HEAD(unaligned_even_length); +ATF_TC_BODY(unaligned_even_length, tc) { u_char data[] __aligned(sizeof(u_short)) = {0x00, 0x12, 0x34, 0x56, 0x78}; u_short sum; sum = in_cksum(data + 1, nitems(data) - 1); - ATF_REQUIRE(sum == 0x5397); + u_char *c_sum = (u_char *)∑ + ATF_REQUIRE(c_sum[0] == 0x97 && c_sum[1] == 0x53); } -ATF_TC_WITHOUT_HEAD(unaligned_odd_length_big_endian); -ATF_TC_BODY(unaligned_odd_length_big_endian, tc) +ATF_TC_WITHOUT_HEAD(unaligned_odd_length); +ATF_TC_BODY(unaligned_odd_length, tc) { u_char data[] __aligned(sizeof(u_short)) = {0x00, 0x12, 0x34, 0x56, 0x78, 0x9a}; u_short sum; sum = in_cksum(data + 1, nitems(data) - 1); - ATF_REQUIRE(sum == 0x52fd); -} - -ATF_TC_WITHOUT_HEAD(unaligned_even_length_little_endian); -ATF_TC_BODY(unaligned_even_length_little_endian, tc) -{ - u_char data[] __aligned(sizeof(u_short)) = - {0x00, 0x34, 0x12, 0x78, 0x56}; - u_short sum; - - sum = in_cksum(data + 1, nitems(data) - 1); - ATF_REQUIRE_MSG(sum == 0x9753, "%d", sum); -} - -ATF_TC_WITHOUT_HEAD(unaligned_odd_length_little_endian); -ATF_TC_BODY(unaligned_odd_length_little_endian, tc) -{ - u_char data[] __aligned(sizeof(u_short)) = - {0x00, 0x34, 0x12, 0x78, 0x56, 0x00, 0x9a}; - u_short sum; - - sum = in_cksum(data + 1, nitems(data) - 1); - ATF_REQUIRE(sum == 0xfd52); + u_char *c_sum = (u_char *)∑ + ATF_REQUIRE(c_sum[0] == 0xfd && c_sum[1] == 0x52); } /* @@ -133,14 +93,10 @@ ATF_TC_BODY(unaligned_odd_length_little_endian, tc) ATF_TP_ADD_TCS(tp) { - ATF_TP_ADD_TC(tp, aligned_even_length_big_endian); - ATF_TP_ADD_TC(tp, aligned_odd_length_big_endian); - ATF_TP_ADD_TC(tp, aligned_even_length_little_endian); - ATF_TP_ADD_TC(tp, aligned_odd_length_little_endian); - ATF_TP_ADD_TC(tp, unaligned_even_length_big_endian); - ATF_TP_ADD_TC(tp, unaligned_odd_length_big_endian); - ATF_TP_ADD_TC(tp, unaligned_even_length_little_endian); - ATF_TP_ADD_TC(tp, unaligned_odd_length_little_endian); + ATF_TP_ADD_TC(tp, aligned_even_length); + ATF_TP_ADD_TC(tp, aligned_odd_length); + ATF_TP_ADD_TC(tp, unaligned_even_length); + ATF_TP_ADD_TC(tp, unaligned_odd_length); return (atf_no_error()); } |