From patchwork Wed Sep 26 18:36:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 147635 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp1071223lji; Wed, 26 Sep 2018 11:42:52 -0700 (PDT) X-Google-Smtp-Source: ACcGV60S4PHXBGnqPN7KsdoXM+FYJAf/rFKtxmF3ozlovmdpqA4V0oul5TRBfrLRnJ5ds2z2qD1u X-Received: by 2002:a0c:d6c3:: with SMTP id l3-v6mr5180863qvi.154.1537987372850; Wed, 26 Sep 2018 11:42:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537987372; cv=none; d=google.com; s=arc-20160816; b=VEBfv/hhVAl0loTZJ7/n4MmgsQF03RnMG1JV5ZDx7h3k7iXYFL1z9I4/rQNhsxPILt vIMA0+wCBFrI7p4n2w/7Mkix3lIQFyylwJRw/kiTmROTwkDua6NC+WT1US+wwY+rinz4 TUs5tz+PNOneEUdsDBu958AThBieWtReyLebsXCw9keAvPA86WwYqkcO2jwIDbXUxWtM FR4RrEk9LsnwT4R83Hcz92P9C59S/WCWBY1tnwUoCDj2PXhFhcfuRB2TsSlcL1Ef6ypV eq+sgJRmB0KCCwbdNNPptBe/fK6AThQfIKOHqpIgBbupxp/AyKkkXUuH5dPebnvsEsrp RR2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=HlAdm22NwgWiCMqOGDVe9uJhUUayKuKdvSW/1SB+VTA=; b=u8lFOoUUk4+/0mUAN5GXmjToo0fS8eJf/cvwewO2gXHb1OLsWr4cj18XjuRLH1Wgd3 R+peaUCqpv0wpgNhf78rlAsdEK8A4VYnz0CtHenxyMaPsuNziQj0nXwpx+hU9WwywMlP Tsbkju0o9CEBNK9AyVnfbebNYziwH4GV/PKYXvN3w8yk+uBAE8x2WBbxSkeG/FH6ZNGX gQ32Z49JuzrIrmzYmEwnb8S8qD5d1iAwoziYwP9zhCghDaliXG5SjtT4fziCJhKWR+Fj +Q1bndAOR2/rtn/vqpy+TzJKX5dAcwyUXN4pAEEFBS+oeR6mT4jMrlJX6gOGiO9uFWdF q0Cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=bWLWVMwK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id k93-v6si46161qtd.396.2018.09.26.11.42.52 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 26 Sep 2018 11:42:52 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=bWLWVMwK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60188 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5Elw-0007w2-81 for patch@linaro.org; Wed, 26 Sep 2018 14:42:52 -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) 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-Received: by 2002:a62:aa17:: with SMTP id e23-v6mr7481020pff.211.1537987036881; Wed, 26 Sep 2018 11:37:16 -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) 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 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" Reviewed-by: Alex Bennée Signed-off-by: Emilio G. Cota Signed-off-by: Richard Henderson --- tests/test-qht.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) -- 2.17.1 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, ==, count); } +static void sum_func(struct qht *ht, void *p, uint32_t hash, void *userp) +{ + uint32_t *sum = userp; + uint32_t a = *(uint32_t *)p; + + *sum += a; +} + +static void iter_sum_check(unsigned int expected) +{ + unsigned int sum = 0; + + qht_iter(&ht, sum_func, &sum); + g_assert_cmpuint(sum, ==, expected); +} + +static bool rm_mod_func(struct qht *ht, void *p, uint32_t hash, void *userp) +{ + uint32_t a = *(uint32_t *)p; + unsigned int mod = *(unsigned int *)userp; + + return a % mod == 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 = 0; + unsigned int i; + + for (i = 0; i < N; i++) { + if (i % mod == 0) { + continue; + } + expected += 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); - 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);