Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2546507lqo; Tue, 14 May 2024 01:52:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVkKmk9UrYyPlDIWJKTXQ1o/6uVpV5V5tJchLOmgInUFOm80EJP0ZRG+lJhOk8Jo14bSuERyFC+yclg0u10/tlaQsOSm0JxdsE4BdZdSw== X-Google-Smtp-Source: AGHT+IE0M1z1DRQcZdWoDZ7lwXNTZtQVeJ2sLSeXR8GosdOJFXPvMqIC2Q+dpfrqs81FUGzr+p0v X-Received: by 2002:a17:906:e20c:b0:a59:aa22:30b8 with SMTP id a640c23a62f3a-a5a2d5c7f13mr895709666b.18.1715676735247; Tue, 14 May 2024 01:52:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715676735; cv=pass; d=google.com; s=arc-20160816; b=XRDwvEkubGoeav3bprsLK9Ma0W5Rg7KsZ/CrQR5tlXtgyuMy2UTn8DCPaYHp9ZHzXr eC1CPqaSlLTaMnDk3pluEnsWt0Nt3q9A/bcHSswyW6vQ0bwd7OjcPtxoSQdHY+fvIsfD 8c9OyB+g8pkojIs0vRtoUlIy2tQ13TWsW6Z2MZO2LGnt9QVL7+VYVMGMbXCagIpXFqRZ jYPY9zK7K8JbQ4cWSHsYGg+6xjWRgIyXFNiVb8hyj8903fsbKQnRX864E69W6ckL44hN 8f/04BwHSJg8br9XjMxPc2P7rJgmyPUFOinUuNS67yAJWtSCD9g35e/2yMthSNLi0Kwc CS/A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=nfNQplMLN+Frp8NNBnHt1wiGD5SxoB711mIx7353U+s=; fh=Fbe/BmjoOpHU7IZsDHZux7fbo0MVRD+Dw3A9ApgZeoQ=; b=TKSf9MyALcgv3mQuKtCBO6ih7HvLjRM0Wuw9yd1NXfsKptkWHbsgbxpDFL/O7PMO5O 9AnFKy1AcAyB+os5GYBH/GYDi20+X4iMEwcv2vgRlVfq6eVS+loDczBjVwhBtrQ5spJz exrwSMADCAjczpUQcGv2bSBNe6AZB/hSZw0O3ul6empi84i7FT0ucWqkzoMLA9bnOLtH XsXn7mkkUDHqm7ExUj/qgxWJmxpvYnUgJXUxVlcxzM10eJF5ErEL15iujdk8KfEJpnOR G6pxz+g/CBOAQMju2nZhmdDw8QzvOhWXTSURsDRM+Znx8n4FU1tLn2SPlBdjYzgCWeBV OdfQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bD4qyzc4; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-178466-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178466-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17c2c163si564512166b.926.2024.05.14.01.52.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 01:52:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-178466-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bD4qyzc4; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-178466-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178466-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id F22A31F22B2A for ; Tue, 14 May 2024 08:52:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 45DA4762DC; Tue, 14 May 2024 08:48:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bD4qyzc4" Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2EC3E381A4; Tue, 14 May 2024 08:48:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715676524; cv=none; b=SzEy7Um+8hJvAhDtg+/ujXt0JLP7jkSCu6+fnRwPuX/8oYJBtYJSGnMCA7hebvByxhqk1Bpf/kgtKaI/kqN0x/Ob3rGLFfwLfvTpBVHfmBJ6f+c5C0oOinOI351ikynd6lsfKwIG6SoZ2a1X29CJmdBHINUMskQ33tYI8pqbl+A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715676524; c=relaxed/simple; bh=6RI5jUBlTt+5u3rxYbD5uAwV2PYZJ9bmstimem/yPPk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XR7el/5Jx9T/nDguwfjcw1ukPWGItarSmjY9lkWIrwawTe+oxTqwXd/Shp2eF4NYLTQ23bvdnZ2+YR01T4EnZyB4/AdLjRZ8xq6EzWiWC+JUE95PEXvv1cfeOi/PTrOrCPAvRgSfGb7i9K/eb6FL9zAHbNNkpBYmRZkZ4zeqYxg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bD4qyzc4; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2b370e63d96so1332569a91.3; Tue, 14 May 2024 01:48:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715676522; x=1716281322; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nfNQplMLN+Frp8NNBnHt1wiGD5SxoB711mIx7353U+s=; b=bD4qyzc4uVivwLgRnlvoR+0qu+8pyybyLIPHNRVkKhx/0aTL4yzoILrGBPVPjFKiQ7 nm9K0/8B2yjCekHLNmppbSktifzr8dQYFUYGezTLRv8BKUJVNeT2TSUGTbSG2ZvotAbi N9kO8r0Gr+9syGJECZeNFoTj2tg9xGnI2x/ETvha+bzf56bTLPzf2TIKAXc4TnUdozbg WqInWyTNTsbW1arLGi2rG8JiNmz6YW4/+YjdukqvNPkpyjwpNT2GUDGJtDfLyFPn72Oh dfDm48gtSJKr/tZbUs9PCV6FekzDUtO824gEjVL+MDOzLj2DCyncoLvoS50MGozgawTO fMJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715676522; x=1716281322; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nfNQplMLN+Frp8NNBnHt1wiGD5SxoB711mIx7353U+s=; b=Lnb9BPn9hb+t9ltj3RiK2R+HFO/jodWbumqOg5C42vKgJm5Vx3dgEdD3RtOCFbE17a 3Jef+8bWqBcGK1UZw3P4AAyGJtzAPSbtM1nMR9AhdsTNI27TrstgiSAKVUIRfxzCGa11 FnOuV5F92BpVebMVrRoCR9z05jGxgzRbjj+bmQVRdOLBYi+jHpd939lXoojdG+YJ1iN/ FCbdTjPEfadnW1enVrtVXn3ROqdEubHcZKRHwFv7ae7e+t+qGewWtS5UC1fgLdVD0+zb 85wWG4TNA8i8kcOlKNlm1YJptX4MRaHVqcFte3376D1CY0glCz/lq2M+QCVs8Wp748Lh PAsg== X-Forwarded-Encrypted: i=1; AJvYcCXaNJa8Pn6M1bR+6qCyFWcz36gpBcX/dx1M2mVfQKkK6P5Q6hHDyjg4ECXRrN/OZPgSZkmczAiU/GqgoDLenMuiQFKTl/NHpwAKveMJTAIBjyK0QeKhi7G/wABhTxdpxlBK1iU+/HlDC1jAjKZEpH7mTwzGcqXB7/pRITud0oRbG5cRUJWZ4A4m+5neXXsOrZRcqA0ZWL6sm2y070TAgBCZs9AZNzAt4iH9zcIt X-Gm-Message-State: AOJu0YwGc3fdIF7ZTxgieHyBBmxVc4SrNCa/Z5UI5C9SNOMaSKx7b5+Q hYWHxd3Nk4D98s4D76OSIBKWoP/mZUNLI6of/JdH35RYjxuLB6Zh X-Received: by 2002:a05:6a21:7896:b0:1af:cefe:dba3 with SMTP id adf61e73a8af0-1afddee489emr15338579637.0.1715676522439; Tue, 14 May 2024 01:48:42 -0700 (PDT) Received: from visitorckw-System-Product-Name.. ([140.113.216.168]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b6711660fdsm9195597a91.16.2024.05.14.01.48.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 01:48:41 -0700 (PDT) From: Kuan-Wei Chiu To: colyli@suse.de, kent.overstreet@linux.dev, msakai@redhat.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, akpm@linux-foundation.org Cc: bfoster@redhat.com, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, bagasdotme@gmail.com, jserv@ccns.ncku.edu.tw, linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, dm-devel@lists.linux.dev, linux-bcachefs@vger.kernel.org, linux-perf-users@vger.kernel.org, Kuan-Wei Chiu Subject: [RESEND PATCH v5 14/16] lib/test_min_heap: Add test for heap_del() Date: Tue, 14 May 2024 16:47:22 +0800 Message-Id: <20240514084724.557100-15-visitorckw@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240514084724.557100-1-visitorckw@gmail.com> References: <20240514084724.557100-1-visitorckw@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add test cases for the min_heap_del() to ensure its functionality is thoroughly tested. Signed-off-by: Kuan-Wei Chiu Reviewed-by: Ian Rogers --- lib/test_min_heap.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/test_min_heap.c b/lib/test_min_heap.c index 0b5037b4bd68..d40851cfd824 100644 --- a/lib/test_min_heap.c +++ b/lib/test_min_heap.c @@ -165,6 +165,40 @@ static __init int test_heap_pop_push(bool min_heap) return err; } +static __init int test_heap_del(bool min_heap) +{ + int values[] = { 3, 1, 2, 4, 0x8000000, 0x7FFFFFF, 0, + -3, -1, -2, -4, 0x8000000, 0x7FFFFFF }; + struct min_heap_test heap; + + min_heap_init(&heap, values, ARRAY_SIZE(values)); + heap.nr = ARRAY_SIZE(values); + struct min_heap_callbacks funcs = { + .less = min_heap ? less_than : greater_than, + .swp = swap_ints, + }; + int i, err; + + /* Test with known set of values. */ + min_heapify_all(&heap, &funcs, NULL); + for (i = 0; i < ARRAY_SIZE(values) / 2; i++) + min_heap_del(&heap, get_random_u32() % heap.nr, &funcs, NULL); + err = pop_verify_heap(min_heap, &heap, &funcs); + + + /* Test with randomly generated values. */ + heap.nr = ARRAY_SIZE(values); + for (i = 0; i < heap.nr; i++) + values[i] = get_random_u32(); + min_heapify_all(&heap, &funcs, NULL); + + for (i = 0; i < ARRAY_SIZE(values) / 2; i++) + min_heap_del(&heap, get_random_u32() % heap.nr, &funcs, NULL); + err += pop_verify_heap(min_heap, &heap, &funcs); + + return err; +} + static int __init test_min_heap_init(void) { int err = 0; @@ -175,6 +209,8 @@ static int __init test_min_heap_init(void) err += test_heap_push(false); err += test_heap_pop_push(true); err += test_heap_pop_push(false); + err += test_heap_del(true); + err += test_heap_del(false); if (err) { pr_err("test failed with %d errors\n", err); return -EINVAL; -- 2.34.1