From patchwork Tue May 23 23:02:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Stringer X-Patchwork-Id: 766262 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wXWMb0xmkz9sNL for ; Wed, 24 May 2017 09:05:15 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 182F3BEC; Tue, 23 May 2017 23:02:35 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id DE49CBE1 for ; Tue, 23 May 2017 23:02:31 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 74EDE1DE for ; Tue, 23 May 2017 23:02:30 +0000 (UTC) Received: from mfilter11-d.gandi.net (mfilter11-d.gandi.net [217.70.178.131]) by relay5-d.mail.gandi.net (Postfix) with ESMTP id 412A941C086 for ; Wed, 24 May 2017 01:02:29 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter11-d.gandi.net Received: from relay5-d.mail.gandi.net ([IPv6:::ffff:217.70.183.197]) by mfilter11-d.gandi.net (mfilter11-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id kgGcnnZspCqp for ; Wed, 24 May 2017 01:02:27 +0200 (CEST) X-Originating-IP: 64.134.227.17 Received: from archer.hil-sfofhhh02.sfo.wayport.net (ip-64-134-227-17.public.wayport.net [64.134.227.17]) (Authenticated sender: joe@ovn.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 56C2041C08E for ; Wed, 24 May 2017 01:02:26 +0200 (CEST) From: Joe Stringer To: dev@openvswitch.org Date: Tue, 23 May 2017 16:02:16 -0700 Message-Id: <20170523230216.29696-6-joe@ovn.org> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20170523230216.29696-1-joe@ovn.org> References: <20170523230216.29696-1-joe@ovn.org> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH 5/5] test-hash: Reuse structs/functions in 256B check. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org The prior patch introduced a definition for the 32-bit offset u128, and introduced a function for setting bits in this structure so refactor the 256B hash test to reuse this code. Signed-off-by: Joe Stringer --- tests/test-hash.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/tests/test-hash.c b/tests/test-hash.c index 704e4bc72ff9..9e2b1d840763 100644 --- a/tests/test-hash.c +++ b/tests/test-hash.c @@ -28,7 +28,7 @@ OVS_PACKED(struct offset_ovs_u128 { uint32_t a; - ovs_u128 b; + ovs_u128 b[16]; }); static void @@ -66,9 +66,9 @@ set_bit128_unaligned(struct offset_ovs_u128 *values, int bit, int n_bits) memset(values, 0, n_bits/8 + sizeof(values->a)); if (b < 64) { - values->b.u64.lo = UINT64_C(1) << (b % 64); + values->b[bit / 128].u64.lo = UINT64_C(1) << (b % 64); } else { - values->b.u64.hi = UINT64_C(1) << (b % 64); + values->b[bit / 128].u64.hi = UINT64_C(1) << (b % 64); } } @@ -175,10 +175,10 @@ check_hash_bytes128(void (*hash)(const void *, size_t, uint32_t, ovs_u128 *), uint32_t *in0p; ovs_u128 in1; - in0p = &in0.b.u32[0]; + in0p = &in0.b[0].u32[0]; set_bit128_unaligned(&in0, i, n_bits); set_bit128(&in1, i, n_bits); - assert(ovs_u128_equals(in0.b, in1)); + assert(ovs_u128_equals(in0.b[0], in1)); hash(in0p, sizeof(ovs_u128), 0, &out0); hash(&in1, sizeof(ovs_u128), 0, &out1); if (!ovs_u128_equals(out0, out1)) { @@ -221,17 +221,14 @@ check_256byte_hash(void (*hash)(const void *, size_t, uint32_t, ovs_u128 *), int i, j; for (i = 0; i < n_bits; i++) { - OVS_PACKED(struct offset_ovs_u128 { - uint32_t a; - ovs_u128 b[16]; - }) in0_data; - ovs_u128 *in0, in1[16]; + struct offset_ovs_u128 in0; + ovs_u128 in1[16]; ovs_u128 out0, out1; - in0 = in0_data.b; - set_bit128(in0, i, n_bits); - set_bit128(in1, i, n_bits); - hash(in0, sizeof(ovs_u128) * 16, 0, &out0); + set_bit128_unaligned(&in0, i, n_bits); + set_bit128(&in1[0], i, n_bits); + assert(ovs_u128_equals(in0.b[i / 128], in1[i / 128])); + hash(&in0.b, sizeof(ovs_u128) * 16, 0, &out0); hash(in1, sizeof(ovs_u128) * 16, 0, &out1); if (!ovs_u128_equals(out0, out1)) { printf("%s hash not the same for non-64 aligned data "