From nobody Tue Feb 10 04:55:14 2026 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; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537987330119139.551286637442; Wed, 26 Sep 2018 11:42:10 -0700 (PDT) Received: from localhost ([::1]:60184 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5ElB-0005kZ-Fa for importer@patchew.org; Wed, 26 Sep 2018 14:42:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5Egj-0001Q8-05 for qemu-devel@nongnu.org; Wed, 26 Sep 2018 14:37:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5Ege-0007IH-PI for qemu-devel@nongnu.org; Wed, 26 Sep 2018 14:37:26 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]:37387) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g5Egb-00079k-1u for qemu-devel@nongnu.org; Wed, 26 Sep 2018 14:37:22 -0400 Received: by mail-pg1-x535.google.com with SMTP id c10-v6so7418125pgq.4 for ; Wed, 26 Sep 2018 11:37:18 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-8-179.tukw.qwest.net. [97.113.8.179]) by smtp.gmail.com with ESMTPSA id b14-v6sm9735952pfc.178.2018.09.26.11.37.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 26 Sep 2018 11:37:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HlAdm22NwgWiCMqOGDVe9uJhUUayKuKdvSW/1SB+VTA=; b=bWLWVMwKf87yTnhnsKc/EgN8CG3nGaErIM7IE19ze/m6mw3zhmXpFNtsn3o3iCwcX4 VTEE9Bs70DNSUEZai3S3UV7N4F5l0FunNDaXnfO0tAe7eJ5Q/er5n5Ol5Hz00vicuvZF q7iJl99RgjlSjeQWgsAClFvwsbjG7Q+Rq/eKk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HlAdm22NwgWiCMqOGDVe9uJhUUayKuKdvSW/1SB+VTA=; b=ku8OHHsywIcQ2GhQHLgDIDd5oAl3wocos1ci+QNxXxO/nJEQhdcQffda06zLFYX2Xc gTFZcMMm9gozxLkwMe7xJ7IqQBqX/bopNCkX7Lk46Pu8DPPYPcZlXRyLogENYk+8OBaD mHt9QS84f8D5fkrkkTF9vyr4ZS8xhgHY2+GxQL+MPzVhlljWfqXnllsSKibMxtet1nf2 AzmARDWfiihjItFunHNONTVvzJgzKOv+dzcjoFlA1PZmSS5oZSUS6iZiPXAhHh6t3IZj D3MDaKynYAWW03ShFyQaOnS+d572ZpWqOZ4vtRCTyWBoTkhuiifvVAh7zxMMVconNPAn 3Rhg== X-Gm-Message-State: ABuFfohMXE4Vos4pJ5Xe3ip53vKeTJaq5z+UgvbtHatHfona9HlQBS4X 9Of1h2ToSgndiardOQAtOfEG4N5arCk= X-Google-Smtp-Source: ACcGV63CIE10okfSijUFm3xQkXyv14HWQvNZ7CAVjvHpH3bpLQ40r7BpThPBYwdGoCdpLJUDCIzXAA== X-Received: by 2002:a62:aa17:: with SMTP id e23-v6mr7481020pff.211.1537987036881; Wed, 26 Sep 2018 11:37:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:36:59 -0700 Message-Id: <20180926183709.21293-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180926183709.21293-1-richard.henderson@linaro.org> References: <20180926183709.21293-1-richard.henderson@linaro.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: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::535 Subject: [Qemu-devel] [PULL 03/13] 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: peter.maydell@linaro.org, "Emilio G. Cota" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 From: "Emilio G. Cota" Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Emilio G. Cota Signed-off-by: Richard Henderson --- 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