From nobody Wed Nov 5 13:32:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15366061335671009.1870619074775; Mon, 10 Sep 2018 12:02:13 -0700 (PDT) Received: from localhost ([::1]:53541 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fzRRh-0002cd-FT for importer@patchew.org; Mon, 10 Sep 2018 15:02:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49207) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fzRPS-0001JO-IT for qemu-devel@nongnu.org; Mon, 10 Sep 2018 14:59:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fzRPP-0001Dz-Kg for qemu-devel@nongnu.org; Mon, 10 Sep 2018 14:59:42 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:51329) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fzRPP-0000zK-93 for qemu-devel@nongnu.org; Mon, 10 Sep 2018 14:59:39 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 648AE21F2E; Mon, 10 Sep 2018 14:59:07 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 10 Sep 2018 14:59:07 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id C5502102A1; Mon, 10 Sep 2018 14:59:06 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=mesmtp; bh=yRwg9YcszVBM4yNeMgy8ySbTYq F5e2vF1rKtNXRnXuQ=; b=nY9Utf4QJh0j8KXQLxdDBvvjP9fc1OgAlXMNKByuHo 5pkTloMg2gs6bxAjx3/bON0deQfygczk9EB1frZI5fmtrwYH7mnq97fg4wjP/dCz dxgPYP3/xIGnFrZrg+IrDsbOKkg8qi/YwAqlJKSxNiSC9f6C61sp+FAldl8U0wU9 k= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=yRwg9Y cszVBM4yNeMgy8ySbTYqF5e2vF1rKtNXRnXuQ=; b=koDH4sP6phMXxV5h6I3bKM 4hVn90WMHJQLv3I/LI2UQoA9iwjPQa4MymliXji9xr8C/x9nQUf3UquCWcwf7C/B RV5ZYWoqlgXkJdyuMFdTXza0rm+PoixsLyWcXh6gL8P+o5+fHhL3/vM7UxT7mkOu VCIkvq2m7ydWxA9JfbaDCMZrO42otj9tCLbExW/wJWbwt4Xiln9tA7OCw5LJcujp QMqUbhbsQ6edERqJ87mr0MGMzx06r1We5vMpnr3mCJtBpztrT+pihRhKZ+Er/ePT OUHu31DJDNiJWgwAldO2/mPab0u2+kdT0QtLEBNPQ4G34Ku3/QeuRvXJss8MOoBQ == X-ME-Proxy: X-ME-Sender: From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Mon, 10 Sep 2018 14:58:50 -0400 Message-Id: <20180910185859.27917-4-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180910185859.27917-1-cota@braap.org> References: <20180910185859.27917-1-cota@braap.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.25 Subject: [Qemu-devel] [PATCH v2 03/12] test-qht: test qht_iter_remove X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Emilio G. Cota --- tests/test-qht.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/tests/test-qht.c b/tests/test-qht.c index dda6a067be..283fb3db39 100644 --- a/tests/test-qht.c +++ b/tests/test-qht.c @@ -108,6 +108,49 @@ static void iter_check(unsigned int count) g_assert_cmpuint(curr, =3D=3D, count); } =20 +static void sum_func(struct qht *ht, void *p, uint32_t hash, void *userp) +{ + uint32_t *sum =3D userp; + uint32_t a =3D *(uint32_t *)p; + + *sum +=3D a; +} + +static void iter_sum_check(unsigned int expected) +{ + unsigned int sum =3D 0; + + qht_iter(&ht, sum_func, &sum); + g_assert_cmpuint(sum, =3D=3D, expected); +} + +static bool rm_mod_func(struct qht *ht, void *p, uint32_t hash, void *user= p) +{ + uint32_t a =3D *(uint32_t *)p; + unsigned int mod =3D *(unsigned int *)userp; + + return a % mod =3D=3D 0; +} + +static void iter_rm_mod(unsigned int mod) +{ + qht_iter_remove(&ht, rm_mod_func, &mod); +} + +static void iter_rm_mod_check(unsigned int mod) +{ + unsigned int expected =3D 0; + unsigned int i; + + for (i =3D 0; i < N; i++) { + if (i % mod =3D=3D 0) { + continue; + } + expected +=3D i; + } + iter_sum_check(expected); +} + static void qht_do_test(unsigned int mode, size_t init_entries) { /* under KVM we might fetch stats from an uninitialized qht */ @@ -138,8 +181,11 @@ static void qht_do_test(unsigned int mode, size_t init= _entries) insert(10, 150); check_n(N); =20 - rm(1, 2); - check_n(N - 1); + qht_reset(&ht); + insert(0, N); + iter_rm_mod(10); + iter_rm_mod_check(10); + check_n(N * 9 / 10); qht_reset_size(&ht, 0); check_n(0); check(0, N, false); --=20 2.17.1