From patchwork Tue Jun 11 08:19:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13693254 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (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 AB470174EEB for ; Tue, 11 Jun 2024 08:32:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718094771; cv=none; b=UmswbWG+QyRoNvujyCNlC1yU0qnwkLw4nh/M3HtysFXoa2lfCkzazQyuy/myIr8BUkPbI77q9FBcyUunBH/7ZN8biUQ/jYjuSaN5n/yvUQVN90juzkH+JcvJT3Fk8HACPcu+1LDVbUbx5B0XPuIZm1pxti+xsEX03/FkmGV1ch4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718094771; c=relaxed/simple; bh=YNwb6XiBLk2En9ysJfJB+/zIdFaMUkYO6yPh9qeTuNQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IURxSLxu64KHsJb8VOIZ0a3mszEj18qo8Mek1yOj4HSt3eAki9BSXwlQovDuXvrzg2U+jSUWTMQsRkHSgJus75GHv3BBbuHpx3vBRxX+Kap+ztaGPwglnBJd1VeguYsktG/rxCTekZ0ySI2LEW1TJu3YJJlZdAMD+8FYrvuN6zc= 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=De2WFNRi; arc=none smtp.client-ip=209.85.215.176 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="De2WFNRi" Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-6e40ee57f45so684760a12.0 for ; Tue, 11 Jun 2024 01:32:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718094769; x=1718699569; 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=JYA+d81nX33f4R8F8mbcZz1jsyIqtoLV0FEHoSFJveo=; b=De2WFNRicUjmWvpOlyYg1sA0Rw6NZgUPL6t13K+H/3ZbihQa3bhHZHrInl6NYR5tRH xG5iq+D+Rpr3N3dYPIkc89xkmZZi0xBjpJlbNpwge0/+OPeWFrICDoKAuZ4+p8Hy3p5a 1B9KbYqcwvtCWxrwfuPckGMdJ24RC4MXxgJdHgCM2LEGSdStpAJhRrLuX2v7h8YN0qaP mJaUy+4nehb5VdtnByrfY+JqEKMpHOo1wmYAmwq8+AyiTO5XIh+qcNOc0ikxJA7Hvc8e BLIIlgEPMzwoKLYGBMCncDMi/BND9S8gYwChRQYp1Ch7yiFhbEK7ndXgGpkKMNbYLIwn Tx3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718094769; x=1718699569; 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=JYA+d81nX33f4R8F8mbcZz1jsyIqtoLV0FEHoSFJveo=; b=RnuDGRFz2QJ+SqektcKFgJHp7s5JkBPyP0p2oNb25VcTz05ZbsNzszY0XiCtUsbOxr D25ymN4GNj/O5M9dS+a+8zoRs6PzJs9SiKekqgEiUJ77VaPr5v+qjz4XccNxREsLTbig BDPdTwcViqfB1xKlEa+lIJVoN2N1dkQs3HbP6IuII5j9ipwosB27L3n1A3PUIjPYXXyP T55IWSJKYxRel91vXZkmbbBf+Koca/+sGl6sR2mfZ09sgvhePbUThW9lOs36ggMKLGzq 9kyNUVV2l1axOamLYZEkQCW7uTFEFzyW6V1R1XxGLIuGXr+sShk2J6Qc1uPjfV1aGS1X TkJA== X-Gm-Message-State: AOJu0Yx9DJ/hMY1x65h2mlarzpqENBd3dcGv2p06owOtxqWPzfDOVhNf zi3VwO1fFROHVeYB6fdm+O7bTdD1iJwDe1w9aqMPuUiRqS2wYlomlfKbug== X-Google-Smtp-Source: AGHT+IHjkszVfz4NSUY/s8m10WR5we8odNrX20DRt8kscNFu3HVMtr7w0nnIpwxe8bep+X3IXThO5A== X-Received: by 2002:a05:6a21:3994:b0:1b7:ad9:19fc with SMTP id adf61e73a8af0-1b888a41df7mr1399277637.24.1718094768590; Tue, 11 Jun 2024 01:32:48 -0700 (PDT) Received: from Ubuntu.. ([106.206.199.126]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7041cff68d0sm5776170b3a.185.2024.06.11.01.32.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 01:32:48 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 1/7] reftable: remove unncessary curly braces in reftable/pq.c Date: Tue, 11 Jun 2024 13:49:18 +0530 Message-ID: <20240611083157.9876-2-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240611083157.9876-1-chandrapratap3519@gmail.com> References: <20240606154712.15935-1-chandrapratap3519@gmail.com> <20240611083157.9876-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 According to Documentation/CodingGuidelines, control-flow statements with a single line as their body must omit curly braces. Make reftable/pq.c conform to this guideline. Besides that, remove unnecessary newlines and variable assignment. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- reftable/pq.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/reftable/pq.c b/reftable/pq.c index 7fb45d8c60..1a180c5fa6 100644 --- a/reftable/pq.c +++ b/reftable/pq.c @@ -27,22 +27,16 @@ struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq) pq->heap[0] = pq->heap[pq->len - 1]; pq->len--; - i = 0; while (i < pq->len) { int min = i; int j = 2 * i + 1; int k = 2 * i + 2; - if (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i])) { + if (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i])) min = j; - } - if (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min])) { + if (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min])) min = k; - } - - if (min == i) { + if (min == i) break; - } - SWAP(pq->heap[i], pq->heap[min]); i = min; } @@ -60,12 +54,9 @@ void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry i = pq->len - 1; while (i > 0) { int j = (i - 1) / 2; - if (pq_less(&pq->heap[j], &pq->heap[i])) { + if (pq_less(&pq->heap[j], &pq->heap[i])) break; - } - SWAP(pq->heap[j], pq->heap[i]); - i = j; } } From patchwork Tue Jun 11 08:19:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13693255 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (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 1C832174ED2 for ; Tue, 11 Jun 2024 08:32:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718094774; cv=none; b=A0e2ceEVwRUhpH8NFy7b+R/y1BhyvaBKKnk3+QToRnWxy8oTW0MDxbb9dBA/CMCHTaMgnrMb5Ml27EzVZx7NCizN73lDV4ElPwZOUkT9ecSlmP0QDJ2zpi5IuFY/Zllh90FDjrOHFJB014IUIC2LGU4aRSz+Q8cEq7v/4Z4ysYU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718094774; c=relaxed/simple; bh=1SMy+HLFZaRWGacGhMAscNwlXmzcVFWmTLAuvx9q4/0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WhM+loMIKtBkup/UURRIDlQDk7ug55Tmb6n0HnA0N/R5TXBOXCYWiNNBoyDJA/c6tPtTckaEa1JMalL9U/e9OamV0b7f99vXl7Ab1wyIfhYrfQzIGUwgunRZuU0XrOGZK8Ohg/7LaAMDhBP1gWdFv8U6ow/b23IyM1stxtvUNtc= 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=ADEdSKe0; arc=none smtp.client-ip=209.85.210.173 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ADEdSKe0" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-70435f4c330so688012b3a.1 for ; Tue, 11 Jun 2024 01:32:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718094771; x=1718699571; 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=aqG20YL81BWLyY5VT4U5Fr8w3V6SG4cyQPmHmgVX9AQ=; b=ADEdSKe0bu/zvTvkkDC64PHUTcCTI5aGwv0vNhGoe3qqGbUwP4QJuidugw9boBzFVH u3dl8opcgqx6oWDk2zLHbEeExuhlqI33l5Xnno8savJvdZdTKbWKrH7NtRBjWphh19uN elrh6t4zl0vBEImwAIE/SSKwrLSMTiA8IZ0T16bhxh+zQh3shIf9E+/Lp6MxMswwMmLZ vfqkw6WooDYsdoWMrgmQgivPqQRGrjHYiM00fOlNRKNG08Pz9wWhWhNr9PsKxggfSc0h +1KCujA/JC3sF5chbDxRlqAxTP47Uvsq/Cx3KYE2MKngm9WU6YYuhj+/Z/h0bIf2FTUG SEtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718094771; x=1718699571; 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=aqG20YL81BWLyY5VT4U5Fr8w3V6SG4cyQPmHmgVX9AQ=; b=oqtl6Jv/LLWsh1ZmQIZFOSxOJIkPi/W28ie6QvN8bf6atwwigL+xiJFa9Ea2CoC4wY EYxASZAAxBj8Gaj8zoCyEGYXqYGpdFdwYChz7dtr+Xche+8LFngGiVk1PAoPVIukHxcZ zV+fAs4esMWU0h6I0hRcJh+JnwNwBqNr529hWnH8DUu2Xua/2o+n3mZsdmAFPOhYC2yH jpeqi+1Dxe4xoIDiDqU5dDDaYsL/aj/ETUExoLBjDEWAc6ZK5c7MlJCHHev4hrXdD6K9 mAsGwUmVeAwAUwA2ZeUk5wpAB6PXNCuT+sHqVVo8eXMhiXvn57SJJbPCbLxR3gs8Zv5R 7IdA== X-Gm-Message-State: AOJu0Yyl1H+3+P4nLUV0tC1+kjxpOVU4g4EUwkuO6j0DgwkbfTyl8pgD E+FdYZGdTwuhedzxH7uWuq+cW9LOhhfceG5v6JMVp0akjXRnhiT1zZkzFg== X-Google-Smtp-Source: AGHT+IHQVdraAJZSepzf2a9CIpKrqPIVTMJ6nyBa7upx2jFoY1oIZUz0rExtGEZweC4Tbm6fvV0n6Q== X-Received: by 2002:a05:6a00:3cc2:b0:6f8:b260:ae9b with SMTP id d2e1a72fcca58-7040c72c63cmr11175155b3a.27.1718094771389; Tue, 11 Jun 2024 01:32:51 -0700 (PDT) Received: from Ubuntu.. ([106.206.199.126]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7041cff68d0sm5776170b3a.185.2024.06.11.01.32.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 01:32:50 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 2/7] reftable: change the type of array indices to 'size_t' in reftable/pq.c Date: Tue, 11 Jun 2024 13:49:19 +0530 Message-ID: <20240611083157.9876-3-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240611083157.9876-1-chandrapratap3519@gmail.com> References: <20240606154712.15935-1-chandrapratap3519@gmail.com> <20240611083157.9876-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- reftable/pq.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/reftable/pq.c b/reftable/pq.c index 1a180c5fa6..2b5b7d1c0e 100644 --- a/reftable/pq.c +++ b/reftable/pq.c @@ -22,15 +22,15 @@ int pq_less(struct pq_entry *a, struct pq_entry *b) struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq) { - int i = 0; + size_t i = 0; struct pq_entry e = pq->heap[0]; pq->heap[0] = pq->heap[pq->len - 1]; pq->len--; while (i < pq->len) { - int min = i; - int j = 2 * i + 1; - int k = 2 * i + 2; + size_t min = i; + size_t j = 2 * i + 1; + size_t k = 2 * i + 2; if (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i])) min = j; if (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min])) @@ -46,14 +46,14 @@ struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq) void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e) { - int i = 0; + size_t i = 0; REFTABLE_ALLOC_GROW(pq->heap, pq->len + 1, pq->cap); pq->heap[pq->len++] = *e; i = pq->len - 1; while (i > 0) { - int j = (i - 1) / 2; + size_t j = (i - 1) / 2; if (pq_less(&pq->heap[j], &pq->heap[i])) break; SWAP(pq->heap[j], pq->heap[i]); From patchwork Tue Jun 11 08:19:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13693256 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 86763175549 for ; Tue, 11 Jun 2024 08:32:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718094777; cv=none; b=jwSPHs7hlSF8TMv/AIjT02R7PezIeW2899LrmNB2SOeE5BinFqmecYTE+xzrPduVDh3AbfllFnFbyFTMDXwH2LzJ7t305X6t3WSEkI0c4CxQvJuQiIuItrCpPVX6h/aN0ClVLm4hvXSr3E+E7Bet/5oiUpesa2ffVGoE3eiXULc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718094777; c=relaxed/simple; bh=lDezlVhbx4xsaZZRDTavwaiORNa5S6p3fLN6vjDPF2g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jls1hMTJ4+ZgzJ/64oZbHnRTqPWzpSKfw0ru0WdZ8LWmsNF0a36vl1p31RTiJX1lA5Ac0da+M0FiUJS6hYU+8R6cYSPv6tqWdQ0lBHBDnn0mf3hw7R75nH57EtNh8uYzM1RA2gjzARkT8oVaUB6hM25ByzMU+CsZnLcc6FJqQ28= 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=Oawnktpf; arc=none smtp.client-ip=209.85.210.171 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Oawnktpf" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-70436ac872aso800858b3a.1 for ; Tue, 11 Jun 2024 01:32:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718094774; x=1718699574; 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=QJRxUKvgzPgiuPQGG7wF/Iiv7ARwpsrNISAnWEDh/wg=; b=OawnktpfHySZ/TcQueG94pGrYhxg6COo1OctKS0vLuoOUD1D3AWzCBrUXXTKDjNtrV y0sC8yNNwLWeztWQjMNNti9uPUjdKicn3GF4A1sT+cs3IxoIpsVhWX4/JuvL/CUVFDFp /lON7RA9erDK3vzldUWnKTzXbcTNeNPqgJ7JXu3qSz9cCX+4qBt5SaHMsVqNzwngML1n Ehc2lXFezSYTMcBbpNhiEtfrN+ktre/SCtYl57GhMQSrOoO3ilIXjzATuJXhqozUaQ0J /IliO27PumNKj55L7MM/83ILRD5zzczT5p5I6dC5SRVzhYi3rNs1xjdSh3PGnFYe4vOY SowA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718094774; x=1718699574; 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=QJRxUKvgzPgiuPQGG7wF/Iiv7ARwpsrNISAnWEDh/wg=; b=Dp1gbYU++n+cKVmreDUS05ht9AqASnRYIdd2bXIkyuAsaGz5EuLbCrYK98ZSJINc2R Lay8UdXJq3P3FvbRxJNA7IQFd5bqeQjIKU6O+BQHSmJtUwYt5XHMb/WKrINqepmx6kc+ ZnInrxUVQB7eOIfs5Lw9eUAHellRcrI7gVaRpxivMGVnEL4+k/668SorQX/Y9PkEWKbO f3QGBwZ7XZlRuWfoy1tbR2r6vxNG6upCaeYUsSTiLCAchIlN3tV26uCrsWoe9ucmYd93 uAs7wIV4MNLAQCkzZMSGWzndw1e3dPaiwErPjIzDC+WFtly52kYUh3dIWmZX0+O73FGE BvqA== X-Gm-Message-State: AOJu0YxOgosBf9W5NTG4EO25xZeLSMa1bCGKgpdQIMMjaSYXfvwQ4eoF ufAUmxumLuikjthAzIYjxDuBQw3se4supogXtn6xOucnXSelbsqVAF9HtA== X-Google-Smtp-Source: AGHT+IFq1Ss1Yz98LYRSKnpo5edHcNWEksSkznvoo5DvzA612LBQWZuqzmtwWxwqL/5W2qRI1zrjGA== X-Received: by 2002:a05:6a00:983:b0:704:6ea0:2bba with SMTP id d2e1a72fcca58-7046ea05ad1mr9351326b3a.4.1718094774304; Tue, 11 Jun 2024 01:32:54 -0700 (PDT) Received: from Ubuntu.. ([106.206.199.126]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7041cff68d0sm5776170b3a.185.2024.06.11.01.32.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 01:32:53 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 3/7] t: move reftable/pq_test.c to the unit testing framework Date: Tue, 11 Jun 2024 13:49:20 +0530 Message-ID: <20240611083157.9876-4-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240611083157.9876-1-chandrapratap3519@gmail.com> References: <20240606154712.15935-1-chandrapratap3519@gmail.com> <20240611083157.9876-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 reftable/pq_test.c exercises a priority queue defined by reftable/pq.{c, h}. Migrate reftable/pq_test.c to the unit testing framework. Migration involves refactoring the tests to use the unit testing framework instead of reftable's test framework. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- Makefile | 2 +- t/helper/test-reftable.c | 1 - .../pq_test.c => t/unit-tests/t-reftable-pq.c | 37 ++++++++----------- 3 files changed, 16 insertions(+), 24 deletions(-) rename reftable/pq_test.c => t/unit-tests/t-reftable-pq.c (62%) diff --git a/Makefile b/Makefile index 59d98ba688..1cabe4cc69 100644 --- a/Makefile +++ b/Makefile @@ -1336,6 +1336,7 @@ THIRD_PARTY_SOURCES += sha1dc/% UNIT_TEST_PROGRAMS += t-ctype UNIT_TEST_PROGRAMS += t-mem-pool UNIT_TEST_PROGRAMS += t-prio-queue +UNIT_TEST_PROGRAMS += t-reftable-pq UNIT_TEST_PROGRAMS += t-strbuf UNIT_TEST_PROGRAMS += t-strcmp-offset UNIT_TEST_PROGRAMS += t-trailer @@ -2675,7 +2676,6 @@ REFTABLE_TEST_OBJS += reftable/basics_test.o REFTABLE_TEST_OBJS += reftable/block_test.o REFTABLE_TEST_OBJS += reftable/dump.o REFTABLE_TEST_OBJS += reftable/merged_test.o -REFTABLE_TEST_OBJS += reftable/pq_test.o REFTABLE_TEST_OBJS += reftable/record_test.o REFTABLE_TEST_OBJS += reftable/readwrite_test.o REFTABLE_TEST_OBJS += reftable/stack_test.o diff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c index bae731669c..86a2b0f91a 100644 --- a/t/helper/test-reftable.c +++ b/t/helper/test-reftable.c @@ -9,7 +9,6 @@ int cmd__reftable(int argc, const char **argv) record_test_main(argc, argv); block_test_main(argc, argv); tree_test_main(argc, argv); - pq_test_main(argc, argv); readwrite_test_main(argc, argv); merged_test_main(argc, argv); stack_test_main(argc, argv); diff --git a/reftable/pq_test.c b/t/unit-tests/t-reftable-pq.c similarity index 62% rename from reftable/pq_test.c rename to t/unit-tests/t-reftable-pq.c index b7d3c80cc7..a47a9473f3 100644 --- a/reftable/pq_test.c +++ b/t/unit-tests/t-reftable-pq.c @@ -6,35 +6,28 @@ license that can be found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd */ -#include "system.h" - -#include "basics.h" -#include "constants.h" -#include "pq.h" -#include "record.h" -#include "reftable-tests.h" -#include "test_framework.h" +#include "test-lib.h" +#include "reftable/constants.h" +#include "reftable/pq.h" void merged_iter_pqueue_check(struct merged_iter_pqueue pq) { - int i; - for (i = 1; i < pq.len; i++) { - int parent = (i - 1) / 2; - - EXPECT(pq_less(&pq.heap[parent], &pq.heap[i])); + for (size_t i = 1; i < pq.len; i++) { + size_t parent = (i - 1) / 2; + check(pq_less(&pq.heap[parent], &pq.heap[i])); } } static void test_pq(void) { - struct merged_iter_pqueue pq = { NULL }; + struct merged_iter_pqueue pq = { 0 }; struct reftable_record recs[54]; - int N = ARRAY_SIZE(recs) - 1, i; + size_t N = ARRAY_SIZE(recs) - 1, i; char *last = NULL; for (i = 0; i < N; i++) { struct strbuf refname = STRBUF_INIT; - strbuf_addf(&refname, "%02d", i); + strbuf_addf(&refname, "%02"PRIuMAX, (uintmax_t)i); reftable_record_init(&recs[i], BLOCK_TYPE_REF); recs[i].u.ref.refname = strbuf_detach(&refname, NULL); @@ -48,7 +41,6 @@ static void test_pq(void) merged_iter_pqueue_add(&pq, &e); merged_iter_pqueue_check(pq); - i = (i * 7) % N; } while (i != 1); @@ -56,9 +48,9 @@ static void test_pq(void) struct pq_entry e = merged_iter_pqueue_remove(&pq); merged_iter_pqueue_check(pq); - EXPECT(reftable_record_type(e.rec) == BLOCK_TYPE_REF); + check(reftable_record_type(e.rec) == BLOCK_TYPE_REF); if (last) - EXPECT(strcmp(last, e.rec->u.ref.refname) < 0); + check_int(strcmp(last, e.rec->u.ref.refname), <, 0); last = e.rec->u.ref.refname; } @@ -67,8 +59,9 @@ static void test_pq(void) merged_iter_pqueue_release(&pq); } -int pq_test_main(int argc, const char *argv[]) +int cmd_main(int argc, const char *argv[]) { - RUN_TEST(test_pq); - return 0; + TEST(test_pq(), "pq works"); + + return test_done(); } From patchwork Tue Jun 11 08:19:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13693257 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 20BB5175561 for ; Tue, 11 Jun 2024 08:32:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718094779; cv=none; b=bH33djDe8zItvI9jbzLsWbPBDmfPCIMr9dqSyvXPlUg6zZTch/hj6SwcbCaC/k1FoMap5gO2jfr79FDh1KW99hvk0mdpjSbo68t/fYcLMy9sqyvbyNWmICDFA72T1AhmjUCpWoHl92uH90GeVq/8nnPuS871ebtDOFj7UbgCNv4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718094779; c=relaxed/simple; bh=ZBvpDLNHNjoQCJ3AZJra3cFXcfo2DTAZf2kQPpx1UIA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eu181XY60dOcrcfVy/99zt9wsi0Gbp9axKSlAhHXD0X3+7rruuiWZYksb0XEOPc1lWBQhfa33+Tb+/MkYah/BMwcqLjOXx9aV/fCYAHAvwKfWg89ZnQDKgd/frSZKUQ0DQ7V3ba1Ny3qSV3qwPBhGMqPVaDUlcGo6e3UZSUTDQQ= 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=RXo1DzFW; arc=none smtp.client-ip=209.85.210.177 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RXo1DzFW" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-7041a7d4beeso3046226b3a.2 for ; Tue, 11 Jun 2024 01:32:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718094777; x=1718699577; 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=gOyBXezJzIQcgORZHKSHMuaHcOuwfGm1OzY8yhzYeac=; b=RXo1DzFWghx1ZsfEZfjw/INsaWbqMDjUaxHNh8HhE4cKoOdBtPTkfYm9LwokL82YAo FltkvSte6RwMaLQ+GZeXacpBtxj8iUHn++eZcIbU2fkxawjm9eCVMSpYo9FAcqTDirwo yNfvgDzDL6bBZaL6ycDLirSgGOKSLODFb4aYQQl79zUCwL2Jd3CMrZy5smM+guTm5CTw NEjSbQpIHdHbSXae+nRkfMdiH3H/XPEFGM7vynts63Y/7Zi/XD16F5lhpbZEbYyD1Qjq enjUVIWRdUTJbFysPm1xwJPrkrGQ2+O+DaI1ZBhIe5M0Srd3Ga6NczyIbJSB+Y6Ndyh1 wTHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718094777; x=1718699577; 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=gOyBXezJzIQcgORZHKSHMuaHcOuwfGm1OzY8yhzYeac=; b=P000yix2wz6PZ/6NgCqFLgOiDWGujtZiji0GIfRyCdECaIgcB6Z3CDfs2LHwu1vetB xpqE4dAAvq44TU7eR3AR1bBT6c6aYfKvpCOl68kRg6Vflh23DUM544ZB6mLbD7GoNXYq UGXfZYA49gucz9SkoMC7OHYPHsgsO30QpXuDSh3QG5VCXJsiOonyRcoDrRWXtqpQ6GTa Cj4vlv6sXnU3u48sKVgCBqAAnxoNfWhJb0y5j9MLtHQOmfW2BsKNum1DiSKAMlytyQu4 x9RK5h7RDe9++8qeh1mnOPTfcbtmdRYwq8+l7+hsyqw7Hjoeh4JbygFqBqnifebBUKj/ VPsw== X-Gm-Message-State: AOJu0Yy5mB/0jhxSMn3neIqDQWfsL3C1/3hdruuSply0YWPJCCJdp8js CLmGymZbrXE0dtj5O7ypxOkUj5jGrOZWQ3/ifmR/DdrpueXFXwJ8GI4THA== X-Google-Smtp-Source: AGHT+IHqgumkQkZsfheHVRoD413vyoydp2yGuE1wwJFG9vroJaojG/HnC89fQWeeYlpRQ77OHD3c7w== X-Received: by 2002:a05:6a20:3258:b0:1b5:77db:c77f with SMTP id adf61e73a8af0-1b577dbc8b0mr6290693637.60.1718094777075; Tue, 11 Jun 2024 01:32:57 -0700 (PDT) Received: from Ubuntu.. ([106.206.199.126]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7041cff68d0sm5776170b3a.185.2024.06.11.01.32.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 01:32:56 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 4/7] t-reftable-pq: make merged_iter_pqueue_check() static Date: Tue, 11 Jun 2024 13:49:21 +0530 Message-ID: <20240611083157.9876-5-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240611083157.9876-1-chandrapratap3519@gmail.com> References: <20240606154712.15935-1-chandrapratap3519@gmail.com> <20240611083157.9876-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 merged_iter_pqueue_check() is a function previously defined in reftable/pq_test.c (now t/unit-tests/t-reftable-pq.c) and used in the testing of a priority queue as defined by reftable/pq.{c, h}. As such, this function is only called by reftable/pq_test.c and it makes little sense to expose it to non-testing code via reftable/pq.h. Hence, make this function static and remove its prototype from reftable/pq.h. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- reftable/pq.h | 1 - t/unit-tests/t-reftable-pq.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/reftable/pq.h b/reftable/pq.h index f796c23179..707bd26767 100644 --- a/reftable/pq.h +++ b/reftable/pq.h @@ -22,7 +22,6 @@ struct merged_iter_pqueue { size_t cap; }; -void merged_iter_pqueue_check(struct merged_iter_pqueue pq); struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq); void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e); void merged_iter_pqueue_release(struct merged_iter_pqueue *pq); diff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c index a47a9473f3..7d151f8582 100644 --- a/t/unit-tests/t-reftable-pq.c +++ b/t/unit-tests/t-reftable-pq.c @@ -10,7 +10,7 @@ license that can be found in the LICENSE file or at #include "reftable/constants.h" #include "reftable/pq.h" -void merged_iter_pqueue_check(struct merged_iter_pqueue pq) +static void merged_iter_pqueue_check(struct merged_iter_pqueue pq) { for (size_t i = 1; i < pq.len; i++) { size_t parent = (i - 1) / 2; From patchwork Tue Jun 11 08:19:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13693258 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (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 CCF95175571 for ; Tue, 11 Jun 2024 08:33:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718094782; cv=none; b=Emjf4utb8S3iW3HVi+V5SuwqZ5vE4aOTi7MTk0+8e0QfWXwT3nmoNaXmrpiZf3rP0xuWoOsBN8NM6GQz+Yw86kC61l0YAEN1LPANNa3mx7AuXI0uGrq/igJTA9KA/ZQC/4Hl9fHJ2fnipSVtNE68wvIgsx3MwbnuljQnC5xI4cM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718094782; c=relaxed/simple; bh=L2kOQvVmitR9fKv557cUouCHnCFAU5dqKoO9TVT+NHE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y8VYM8SY0hmxgVfeoHnTFhsq4WisRqXAHF7b6BpXIfrx8epKFDoE1Gk7FW0UUOb9wl1F6MgrXOn5rFwuNSxUTGrvhF6DBGOqZpqyxrG+i8rgRi5AkVUH8RiHEpABBFtmVnehzJhynA/paqVUuzw9/Tatp1I03fnNMi+7vWYWGho= 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=aDAYXEpr; arc=none smtp.client-ip=209.85.210.173 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aDAYXEpr" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-6ff6fe215c6so4644589b3a.3 for ; Tue, 11 Jun 2024 01:33:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718094780; x=1718699580; 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=w84840wpWTiEFCwuNJLf+jbnu/yNvhoCiinN3sTzrPY=; b=aDAYXEprgtT626z4XDQ8666uWGqu1R8NQAiTBno4O/EhNNqX3Pr9ZLUY+OAeOri8pa 2ig4jY2vS609G6XwAnCwVnHuQR1o/CVokw0X/Fmc4t2Gfc6aZPHpDDdJA9+lrK6iRisX D7E4PxPcusSBtjLEDTsz+sE+2rospuRP3fHlbFh7JNl6oMBKlvEV7PJuWfAYYMe3JZUW EEVpE0SyjJLcD75RDGIgKGn8usoqdmZuCk22lfNy1QgrZcFi6Ny6xXs1lriRLIOSqvx9 oKWTrtFOePpJFMLziun3UcOtvDWVofee1pbwsofDH0QJb7BcTpVfw1h53AqZnh9UMT+e cVpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718094780; x=1718699580; 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=w84840wpWTiEFCwuNJLf+jbnu/yNvhoCiinN3sTzrPY=; b=MeSRgiRZ0vhtV631lI5RR9nD7tLAnuZMyBYp5tg5ldklyx+CXxMRasq/zZTE/S2T+D GFxnnfi+G/OZpp5anJK9EXGjS7a7DfolM9YqVUBLwUNTWtavsSY2NpHz5NfDOztrfyF/ BR012S7Qq+bSO1sYv5A63HJEwziSjS21vGsReq7z8gvSOwp3skToNTLuNai0IqbsyrqQ F0+TDgOaOv1jicwYb0Fa9JdmwKN9sSHRYH1NAB2BaJdi+uD6sZUwn2JmIPqsM1dFxIFp NewRn3Bj4upVvAqvO75gyfrofAIS1FMK5nlPKfPphH/8YY8V6JCxYLrkCxeuWGC1K2Rf Q/sg== X-Gm-Message-State: AOJu0Yyu+TivnBmGTiZDKb0ypwE5mlntG7XcR9wwI4RL7X+YSJU7OtyN GrtekHeD0j1uH7s7dwPZPhN4aU3+jO2Pw0cKe6j3/B4fnGCKpjgK3S4j4A== X-Google-Smtp-Source: AGHT+IE1wNCG5YxQeLSKFYFixcI4KC/GgbvLf5tFT+Sw1kfsMHFnSlcibVr4A+84i11goZCEa4Kehw== X-Received: by 2002:a05:6a20:7483:b0:1b7:bdb3:7bc0 with SMTP id adf61e73a8af0-1b7bdb3848amr5389865637.44.1718094779882; Tue, 11 Jun 2024 01:32:59 -0700 (PDT) Received: from Ubuntu.. ([106.206.199.126]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7041cff68d0sm5776170b3a.185.2024.06.11.01.32.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 01:32:59 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 5/7] t-reftable-pq: make merged_iter_pqueue_check() callable by reference Date: Tue, 11 Jun 2024 13:49:22 +0530 Message-ID: <20240611083157.9876-6-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240611083157.9876-1-chandrapratap3519@gmail.com> References: <20240606154712.15935-1-chandrapratap3519@gmail.com> <20240611083157.9876-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 merged_iter_pqueue_check() checks the validity of a priority queue represented by a merged_iter_pqueue struct by asserting the parent-child relation in the struct's heap. Explicity passing a struct to this function means a copy of the entire struct is created, which is inefficient. Make the function accept a pointer to the struct instead. This is safe to do since the function doesn't modify the struct in any way. Make the function parameter 'const' to assert immutability. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-pq.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c index 7d151f8582..774c4194e5 100644 --- a/t/unit-tests/t-reftable-pq.c +++ b/t/unit-tests/t-reftable-pq.c @@ -10,11 +10,11 @@ license that can be found in the LICENSE file or at #include "reftable/constants.h" #include "reftable/pq.h" -static void merged_iter_pqueue_check(struct merged_iter_pqueue pq) +static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq) { - for (size_t i = 1; i < pq.len; i++) { + for (size_t i = 1; i < pq->len; i++) { size_t parent = (i - 1) / 2; - check(pq_less(&pq.heap[parent], &pq.heap[i])); + check(pq_less(&pq->heap[parent], &pq->heap[i])); } } @@ -40,13 +40,13 @@ static void test_pq(void) }; merged_iter_pqueue_add(&pq, &e); - merged_iter_pqueue_check(pq); + merged_iter_pqueue_check(&pq); i = (i * 7) % N; } while (i != 1); while (!merged_iter_pqueue_is_empty(pq)) { struct pq_entry e = merged_iter_pqueue_remove(&pq); - merged_iter_pqueue_check(pq); + merged_iter_pqueue_check(&pq); check(reftable_record_type(e.rec) == BLOCK_TYPE_REF); if (last) From patchwork Tue Jun 11 08:19:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13693259 Received: from mail-ot1-f47.google.com (mail-ot1-f47.google.com [209.85.210.47]) (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 000D8174EFC for ; Tue, 11 Jun 2024 08:33:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718094785; cv=none; b=LY9acveQR4nLwmGnJMKEIxZxgngiCLkYkzfkKaQXC1A2Fm5c296ynRet+hqT1nMo1tWCARyHVvDKYMx7Qvmn3a5rVgyG7ZBn4Kg+ZdkUUiLpTroCKSvaj4kGseJ20iV4lm2O9W6cfIWq6jg/+eT8pc5QacsnV9z8jrQW98Lcllc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718094785; c=relaxed/simple; bh=eziVbiL0LUGaEg6d4C+WXfmKilNXwroxU5hjbTdR3E8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pr2k3qNvtBVj3az2yIbKCxcLMql6BOYiDhDq13VIEXdtuDrzSwEzhIsHQdwvekr60YMrsh4vjTHN9BOpWGzfojNHbipXSXTgbjc861TJr41ET027yO9woHQiGLpzmJXpMavc/n8tHxPwXIO579sxiTUm//S6Rtsn3WOLLUDmb7Y= 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=Xh75z/8x; arc=none smtp.client-ip=209.85.210.47 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Xh75z/8x" Received: by mail-ot1-f47.google.com with SMTP id 46e09a7af769-6f9b5bc97baso954730a34.0 for ; Tue, 11 Jun 2024 01:33:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718094783; x=1718699583; 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=2A1jaJbvylBYtbwBpSmIIsBRdMautt6SxxGgpkJHVVg=; b=Xh75z/8xV9een5SrjoSx6iSPIu4BEOe0V3ZxyMQaLr9FPzx8ndGsP8l1L1OHuxF9kW 2dEsxPib5Ln8CXhWO1fmuGFe1sCBNQ56KbMiyJ3FrEVmPPLU6NT5wb+QuVuGYlbk51o9 dwJCtxtDEVG4YeA5Tj7Tj7TL9amQsBRxrAIU4j/J0V8RSKbL8Usqw5FFm10uqgYI854O dVAtggU9aakZPH9xLzLT55JbaQLZ7u/o2F9bulE5BmSLy5be7VOm0UbO9dNn0DyFYqNY oz0/FbJxMmGv1BVCYa5nI7bcyzhd8k2KkmBXVVbo/qrSeIGgjzLtLB+GGm2Plg7jcm/f xekg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718094783; x=1718699583; 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=2A1jaJbvylBYtbwBpSmIIsBRdMautt6SxxGgpkJHVVg=; b=n+bXLsRAA766yOZYmfKlEoiePB6EKEVLAmKaFUNzgfFBca9KDAkM04XvEk1h39AHEm F+Z08UmfaCPaT4ZuC3d9xud7QwQnQ5bPkJWqhhtXYtHpXNcJ/9BBmUuEJCdfQvLycN8x xN5wm35NTlxHKUTvh/k0GnMsCNY3BiI7Xl/TCJwcMBpZSklJr9cOoNGBbVgZus6DYMdc IRMWgTDPaIfRTVfeIA0Yc3E1WDvofQsAFhWjNatSTFTcOz+UoA7O3ZnGGyhW7Q79b7s5 jszjR3G++0AXYLVatJHVCvuremXfXYdK5E8MqlmpWePuO1e1mi6nPryfgFfux45EdgB4 nIww== X-Gm-Message-State: AOJu0YxgqkMZMHQtV7QXy/LuAAaMsQv14eaqP9VzcongdZJm83Aut/q5 kUgnkvkEMWa6StXAo+HiFWBnd0dz6W91bibulKvsyUnOM8Vix+VGccOZMw== X-Google-Smtp-Source: AGHT+IFTXb0tLkNwc9jVGrQmTXXx84jw251UzYhuKa/9paIlHsclNTn/mescnyNdbiQCvlqR7HWoYw== X-Received: by 2002:a05:6870:ec8d:b0:254:b7d9:2de3 with SMTP id 586e51a60fabf-254b7d94e8emr6349043fac.33.1718094782696; Tue, 11 Jun 2024 01:33:02 -0700 (PDT) Received: from Ubuntu.. ([106.206.199.126]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7041cff68d0sm5776170b3a.185.2024.06.11.01.33.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 01:33:02 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 6/7] t-reftable-pq: add test for index based comparison Date: Tue, 11 Jun 2024 13:49:23 +0530 Message-ID: <20240611083157.9876-7-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240611083157.9876-1-chandrapratap3519@gmail.com> References: <20240606154712.15935-1-chandrapratap3519@gmail.com> <20240611083157.9876-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When comparing two entries, the priority queue as defined by reftable/pq.{c, h} first compares the entries on the basis of their ref-record's keys. If the keys turn out to be equal, the comparison is then made on the basis of their update indices (which are never equal). In the current testing setup, only the case for comparison on the basis of ref-record's keys is exercised. Add a test for index-based comparison as well. Rename the existing test to reflect its nature of only testing record-based comparison. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-pq.c | 43 ++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c index 774c4194e5..e114a8cb0f 100644 --- a/t/unit-tests/t-reftable-pq.c +++ b/t/unit-tests/t-reftable-pq.c @@ -18,7 +18,7 @@ static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq) } } -static void test_pq(void) +static void test_pq_record(void) { struct merged_iter_pqueue pq = { 0 }; struct reftable_record recs[54]; @@ -59,9 +59,48 @@ static void test_pq(void) merged_iter_pqueue_release(&pq); } +static void test_pq_index(void) +{ + struct merged_iter_pqueue pq = { 0 }; + struct reftable_record recs[14]; + char *last = NULL; + size_t N = ARRAY_SIZE(recs), i; + + for (i = 0; i < N; i++) { + reftable_record_init(&recs[i], BLOCK_TYPE_REF); + recs[i].u.ref.refname = xstrdup("refs/heads/master"); + } + + for (i = 0; i < N; i++) { + struct pq_entry e = { + .rec = &recs[i], + .index = i, + }; + + merged_iter_pqueue_add(&pq, &e); + merged_iter_pqueue_check(&pq); + } + + for (i = N - 1; !merged_iter_pqueue_is_empty(pq); i--) { + struct pq_entry e = merged_iter_pqueue_remove(&pq); + merged_iter_pqueue_check(&pq); + + check(reftable_record_type(e.rec) == BLOCK_TYPE_REF); + check_int(e.index, ==, i); + if (last) + check_str(last, e.rec->u.ref.refname); + last = e.rec->u.ref.refname; + } + + for (i = 0; i < N; i++) + reftable_record_release(&recs[i]); + merged_iter_pqueue_release(&pq); +} + int cmd_main(int argc, const char *argv[]) { - TEST(test_pq(), "pq works"); + TEST(test_pq_record(), "pq works with record-based comparison"); + TEST(test_pq_index(), "pq works with index-based comparison"); return test_done(); } From patchwork Tue Jun 11 08:19:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13693260 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (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 20BEE174EEB for ; Tue, 11 Jun 2024 08:33:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718094788; cv=none; b=qxaDpGHfie6Z0FdMIONBYZHZ+fi+GZpbJbDNlYyRjqFWX8/HCYH5eY9WvrDt+/Zsq7ZE6hFlS3PVJy9bq00mwuh1HhXek2pToD5GmSF88E22Z4epV3nzFAN2Uhi/33JxTo1ngsnlOCbUsexT5aemwpixiNndv/oHnJFMJJluOiY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718094788; c=relaxed/simple; bh=M3NmnPJY+UewlcIXn2gNvLekbAtEtQCb1WnANKxJPUA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Sa4K49YFq15h9D/1IcNL79LiiwFVcYi+5PbUvPfn1PK80B7+xuG2n3RjEI52ey/OZxKsSbsSgY9FoEEyHQ8CnieaYWTNAJXlRNGHiTwsTNdDA1LWhrXd4BndWsvGLCcd6fd5TZ+ncyuIlWimv+r8Yvtp3fAKBSexNOwl5OWsRws= 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=OZaQmQzO; arc=none smtp.client-ip=209.85.210.180 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OZaQmQzO" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-6f4603237e0so3496740b3a.0 for ; Tue, 11 Jun 2024 01:33:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718094786; x=1718699586; 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=RTbXFHflckCzDT75U/jzwQ6rjk8DD6Zkca0vVmURxp8=; b=OZaQmQzOD/NnNg7TahQNoVhtyWmKFVg/fxANHjR8oCnHB0kjAFjByLXCeaFYbZHAli it0mVorUQiqIeCagpp93ae9NxK7P7Rr/bbF4+HLerI1V440tPxUF+I2LBOMmwaEd749P 8wjZSodus+kvYoZ9UXNVHwytMBhrPqdQJtw9dOz6E981dSL13j8fh1XACovWRuQxGJFU rSlB3FqR0pzcO+WgkiyWc4laGGFtdPCKrJYOQNocQppyBcrfTckcIiK7lH/z07W3SKlv 99EEBkglCOQ25SRheMeiySa/Rr+lF2kuIq1FhCQSMSa50+cSTUOD2xPTo9MO+xlFplVa FTiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718094786; x=1718699586; 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=RTbXFHflckCzDT75U/jzwQ6rjk8DD6Zkca0vVmURxp8=; b=VVpApJQN1Lu7CaTPTlT55v4JhFsCfzGhUXP6Cf0/4xlN6XlWyf849ecPog1DWiZ9qR RvfTSLgu3U61FL98duYYr8P83BT+z8Fvf4PyN5sGMZa0vk01Hy+DFVhMy5sxxt27pP4m 3jy/Z1xfc5u42C6R3l38tMzWkU/KbZJRZNZpG7Ym8jOzoi9pVH4B28QUE5+KFjoVQOi/ EZhZTRlZ7+ZjHcKdXZL1j9OK2GSYuDlJnzoo3A7yDXiI+KIa775gcGT/kSrCZZJI1J3Y Ffo8gBcRjTBSaaupuQLFjtg695iYZWh7k+91yQVcCbej1swpexE6emCL/GKFa9ULW5Hm s/+Q== X-Gm-Message-State: AOJu0YyGMZxOvSkws6kjPZnG7czdNkNofHBre4be8tabqW/iDFt2qan0 NCeYQOS1H8IyZqz4kvSWWPn+oaNN/1RLH/ViMSUswXevW3yUKSzJKm/xMQ== X-Google-Smtp-Source: AGHT+IEH2oM2zcIBzYBvyGSsOyZog67hc2PiVdRG4a1K4QkDjDYlp18kstXIiJibqxmiYjiYt5RCgw== X-Received: by 2002:a05:6a21:3396:b0:1b6:5b3a:9a4c with SMTP id adf61e73a8af0-1b86bbacd9emr2612254637.2.1718094785587; Tue, 11 Jun 2024 01:33:05 -0700 (PDT) Received: from Ubuntu.. ([106.206.199.126]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7041cff68d0sm5776170b3a.185.2024.06.11.01.33.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 01:33:05 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 7/7] t-reftable-pq: add tests for merged_iter_pqueue_top() Date: Tue, 11 Jun 2024 13:49:24 +0530 Message-ID: <20240611083157.9876-8-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240611083157.9876-1-chandrapratap3519@gmail.com> References: <20240606154712.15935-1-chandrapratap3519@gmail.com> <20240611083157.9876-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 merged_iter_pqueue_top() as defined by reftable/pq.{c, h} returns the element at the top of a priority-queue's heap without removing it. Since there are no tests for this function in the existing setup, add tests for the same. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-pq.c | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c index e114a8cb0f..0e93cc97b1 100644 --- a/t/unit-tests/t-reftable-pq.c +++ b/t/unit-tests/t-reftable-pq.c @@ -18,6 +18,11 @@ static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq) } } +static int pq_entry_equal(struct pq_entry *a, struct pq_entry *b) +{ + return !reftable_record_cmp(a->rec, b->rec) && (a->index == b->index); +} + static void test_pq_record(void) { struct merged_iter_pqueue pq = { 0 }; @@ -45,9 +50,11 @@ static void test_pq_record(void) } while (i != 1); while (!merged_iter_pqueue_is_empty(pq)) { + struct pq_entry top = merged_iter_pqueue_top(pq); struct pq_entry e = merged_iter_pqueue_remove(&pq); merged_iter_pqueue_check(&pq); + check(pq_entry_equal(&top, &e)); check(reftable_record_type(e.rec) == BLOCK_TYPE_REF); if (last) check_int(strcmp(last, e.rec->u.ref.refname), <, 0); @@ -82,9 +89,11 @@ static void test_pq_index(void) } for (i = N - 1; !merged_iter_pqueue_is_empty(pq); i--) { + struct pq_entry top = merged_iter_pqueue_top(pq); struct pq_entry e = merged_iter_pqueue_remove(&pq); merged_iter_pqueue_check(&pq); + check(pq_entry_equal(&top, &e)); check(reftable_record_type(e.rec) == BLOCK_TYPE_REF); check_int(e.index, ==, i); if (last) @@ -97,10 +106,50 @@ static void test_pq_index(void) merged_iter_pqueue_release(&pq); } +static void test_merged_iter_pqueue_top(void) +{ + struct merged_iter_pqueue pq = { 0 }; + struct reftable_record recs[14]; + size_t N = ARRAY_SIZE(recs), i; + + for (i = 0; i < N; i++) { + reftable_record_init(&recs[i], BLOCK_TYPE_REF); + recs[i].u.ref.refname = xstrdup("refs/heads/master"); + } + + for (i = 0; i < N; i++) { + struct pq_entry e = { + .rec = &recs[i], + .index = i, + }; + + merged_iter_pqueue_add(&pq, &e); + merged_iter_pqueue_check(&pq); + } + + for (i = N - 1; !merged_iter_pqueue_is_empty(pq); i--) { + struct pq_entry top = merged_iter_pqueue_top(pq); + struct pq_entry e = merged_iter_pqueue_remove(&pq); + + merged_iter_pqueue_check(&pq); + check(pq_entry_equal(&top, &e)); + check(reftable_record_equal(top.rec, &recs[i], GIT_SHA1_RAWSZ)); + for (size_t j = 0; i < pq.len; j++) { + check(pq_less(&top, &pq.heap[j])); + check_int(top.index, >, j); + } + } + + for (i = 0; i < N; i++) + reftable_record_release(&recs[i]); + merged_iter_pqueue_release(&pq); +} + int cmd_main(int argc, const char *argv[]) { TEST(test_pq_record(), "pq works with record-based comparison"); TEST(test_pq_index(), "pq works with index-based comparison"); + TEST(test_merged_iter_pqueue_top(), "merged_iter_pqueue_top works"); return test_done(); }