From nobody Wed Nov 5 13:13:04 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 153454956180639.33594652917975; Fri, 17 Aug 2018 16:46:01 -0700 (PDT) Received: from localhost ([::1]:36801 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqoRI-0006PT-Rv for importer@patchew.org; Fri, 17 Aug 2018 19:45:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57745) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqoPE-0004vU-Gy for qemu-devel@nongnu.org; Fri, 17 Aug 2018 19:43:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqoBj-0003Hh-Ow for qemu-devel@nongnu.org; Fri, 17 Aug 2018 19:29:55 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:45909) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fqoBj-0003H6-Hl for qemu-devel@nongnu.org; Fri, 17 Aug 2018 19:29:51 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 58B37225A9; Fri, 17 Aug 2018 19:29:51 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Fri, 17 Aug 2018 19:29:51 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id E309B10273; Fri, 17 Aug 2018 19:29:50 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=mesmtp; bh=iVB3otnAoUMS5A XKH1XbRmjf7QkdZZPUT+7het1x1Yo=; b=K1u7R8tdR6Vi7cMxXLm+Fw4LiEN61z AFwTruftvewZbLFheoYgQyOM6Vex0yNJitXckqoKHOFfwuSYEU+4QKLofqSDrscA xLIrGBXvyUqqvr17mzSxgwMX7P4lfarNY2IBw0Cz+EN5jBIzrHO5gFSMoMvMN5zL HsZbYitj/LiHs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=iVB3otnAoUMS5AXKH1XbRmjf7QkdZZPUT+7het1x1Yo=; b=ieO0Y4WM DGeTcdNhKwFc5lB+9sHXqRL07biXKOwnfZaYGs8ygt0Ny3iGregmM/3yJiak1AlC K5JRjMTru/4e46sly3YFjHQjMF8oDcTOAbZMr3FXB3P7HNHuMpR6FmkcmGmVjX/b uwm1bV2AAI5/xSJfeMlETN46MoFBJ8Uebn88Lq1Q7bUMymZ6SMM52tTOnoOUoOod yAaViaHcXECF9r4Q2c43aedeWz1/8ywKR6CeejKJfzF2yjpjA/jllncu5EfEGf04 08gjrydu2od6oAtAIRqf20uF9Xd05jXzZjMoGqL46DsDkaF0CHPFjDXtYIbjlw6D HSmfslNEnXGBQQ== X-ME-Proxy: X-ME-Sender: From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Fri, 17 Aug 2018 19:29:20 -0400 Message-Id: <20180817232923.28899-4-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180817232923.28899-1-cota@braap.org> References: <20180817232923.28899-1-cota@braap.org> 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 3/6] 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 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Emilio G. Cota Reviewed-by: Alex Benn=C3=A9e --- 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