From nobody Thu Oct 07 17:41:37 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id CB35812D4E6B; Thu, 7 Oct 2021 17:41:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HQJXd5SGsz4TZ4; Thu, 7 Oct 2021 17:41:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9C8A417E3E; Thu, 7 Oct 2021 17:41:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 197Hfblr003359; Thu, 7 Oct 2021 17:41:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 197HfbxF003358; Thu, 7 Oct 2021 17:41:37 GMT (envelope-from git) Date: Thu, 7 Oct 2021 17:41:37 GMT Message-Id: <202110071741.197HfbxF003358@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alan Somers Subject: git: d55574c91830 - stable/12 - ICMP checksum test: Fix for big endian List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: asomers X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: d55574c91830d12b308664e4a165accffad22e06 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=d55574c91830d12b308664e4a165accffad22e06 commit d55574c91830d12b308664e4a165accffad22e06 Author: Charlie Root AuthorDate: 2021-01-12 01:56:12 +0000 Commit: Alan Somers CommitDate: 2021-10-07 17:38:50 +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 Reviewed By: asomers Differential Revision: https://reviews.freebsd.org/D23193 (cherry picked from commit 292808246db702b9194deb8938e40fd06914aea9) --- 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 *)∑ + 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()); }