Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 12 Jan 2021 02:10:13 GMT
From:      Alan Somers <asomers@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 292808246db7 - main - ICMP checksum test: Fix for big endian
Message-ID:  <202101120210.10C2ADmg048698@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by asomers:

URL: https://cgit.FreeBSD.org/src/commit/?id=292808246db702b9194deb8938e40fd06914aea9

commit 292808246db702b9194deb8938e40fd06914aea9
Author:     Charlie Root <renato.riolino@eldorado.org.br>
AuthorDate: 2021-01-12 01:56:12 +0000
Commit:     Alan Somers <asomers@FreeBSD.org>
CommitDate: 2021-01-12 02:03:46 +0000

    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
---
 sbin/ping/tests/in_cksum_test.c | 84 ++++++++++-------------------------------
 1 file 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 *)&sum;
+	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 *)&sum;
+	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 *)&sum;
+	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 *)&sum;
+	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());
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202101120210.10C2ADmg048698>