From patchwork Fri Jun 14 09:48:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13698444 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.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 854591922FE for ; Fri, 14 Jun 2024 09:52:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718358726; cv=none; b=qsLsggaI9dj8NnK6QY8DUtPoJRTb3QQrT3TRHWpjT54PFKC4g3mv3Sfz15gIv1WUTCDB7UdW+2ssR6jvEYhX7QxLhDstldQ49EI+kWiJ6D+qVxEtcwX6ATUca9c7Q5D1JPmDFWxD6lOrpcKSoo8HhtmnxXZiU8WK10RdbNveLq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718358726; c=relaxed/simple; bh=YNwb6XiBLk2En9ysJfJB+/zIdFaMUkYO6yPh9qeTuNQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NoW2IxbZn5VBMYdcLMdAKVAve4HUMstFc0fnWtbqIoLIrkvl4rp7xEBZk32SjVzBrhIquoj5l8nMOJs1Xy9Ea7V/VJqIe15OYcPL2oig4eBzGfjR1Pk2VhlxWAWxtsOLIhfdr9dpXx+1uz8iTdQ0zf9GjjGHWmvbDFM3sJ4JiZA= 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=TRJHt7Xi; arc=none smtp.client-ip=209.85.215.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="TRJHt7Xi" Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-6c4926bf9baso1661444a12.2 for ; Fri, 14 Jun 2024 02:52:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718358724; x=1718963524; 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=TRJHt7XiYVR7y0kPP4kGKvb5PeHfMquyqEYW6oib2OJ5crroW4/DB5jm4R9BSlFnhY FavYjHh8pye1ffL6njxETBy/cZutx/G6npSMmV30R0SOWRsm9Es5ByvRimH2srVBj4Hn p6onMTL379g384pOFICpczG4LT3qOijzaZCAsZy+vevszBrTQMMqo3FG3cDwexmQLQ5k Ji7Bz//cinojj8/uZxUq3lla0I/0ff4MXJD7yYA4XZiEqtz4mOiknD72B8eaOSf8/2DM 9gT9WP3ueZ8jERZvSPeanHvoGWGV+7Ol8sdLRzLSYXj/aN5yLvV5eczhzcQXlsn98v+l LAww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718358724; x=1718963524; 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=vhRlmpArS7jZS25wFq+8dQGfA2WabJ9R3mYvXAbzk/ChgaL7n59qJUfsZd9zoYwPbN FqhAdNFzmOzvuaUp5Thhe+Duf54BAwTdm+SLXnAhshkf2/rW+yv0cLY3redx/AX5KUhT OEAs0CyyiRdTyd7NJuU6ElRYJ0deNXgUMXHycbIzk2WNoWgb7tDzt5mFHftLj4YLCvvu +6LWc3fDNDnyDWby+8/czKIqwWPPf1cJdNsp1K8xipqdr1SIwKrcFKEXcfBKdvlGH0PK Tv1vRnkHeS7tNIzAcxgEXBMhYADLP0Znxfd19o7pmvc8IseVpvms5qrQSwF1d42wPDtY kH/g== X-Gm-Message-State: AOJu0Yx1uq3NE0u4DhF0krqRgaJwrYVkr5TsFtMFEp3TlLBF3mZVmT/+ WZ9T7RDl4LW3XS5bWdHkcQ8bln7n+oJ2G+GjG8eRZo5eq6OXfBheyxZ/vsi3NUY= X-Google-Smtp-Source: AGHT+IFQtVlXLY7f0+D8/bNKE8qiTRuD22BZXQoYWhHdsezfoOq1lwRhjfHBmWjvg6DrqNnuyigmOA== X-Received: by 2002:a05:6a20:7288:b0:1b1:c77f:56c3 with SMTP id adf61e73a8af0-1bae7e0c23dmr2695180637.7.1718358723890; Fri, 14 Jun 2024 02:52:03 -0700 (PDT) Received: from Ubuntu.. ([117.96.146.43]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f868b83afesm9230005ad.156.2024.06.14.02.52.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 02:52:03 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v4 1/7] reftable: remove unncessary curly braces in reftable/pq.c Date: Fri, 14 Jun 2024 15:18:01 +0530 Message-ID: <20240614095136.12052-2-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240614095136.12052-1-chandrapratap3519@gmail.com> References: <20240611083157.9876-1-chandrapratap3519@gmail.com> <20240614095136.12052-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 Fri Jun 14 09:48:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13698445 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.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 DE40A199222 for ; Fri, 14 Jun 2024 09:52:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718358729; cv=none; b=Wx740UyoXETpBrxBGQeqE5lnGeCDiSCgaS/QX7R9iy5XI7Zw+f7c5wffK2kuqyFwbXB3jEu4FNawuIK5is/wNfmTcSFWqg80TGtvpRggT3BV8mKf/I220pKZyPQhRJmTMZAwDAv5z/7+Zw/lqamxuu3j9apkAqF+8u3UPRtxhMY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718358729; c=relaxed/simple; bh=CH1nLTeOv7Bi4qpnrV1pGphhYJhb70s++MWgX94QalE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GgQgDt0KXElGxiuIg7MvzkpzhC8D06+weo8VAfTAUU0aXjRPj+A8gX01SFzYbuc+Zx5O3UxrDOIeCR+oeXwIzogECHKcdWo268qjfFQwxLeLqpPQoMjlRzRiznlTjp9kZOYsmmvjUjnd3wR4QftlVWTR1W8z0D2NKuXBngyeWhQ= 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=frRHlhUD; arc=none smtp.client-ip=209.85.214.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="frRHlhUD" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1f65a3abd01so18033465ad.3 for ; Fri, 14 Jun 2024 02:52:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718358727; x=1718963527; 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=H0fYVwNKYu1/eayMVZNM0L/hPabLRg+e4eJSmnX7zCk=; b=frRHlhUDg1vEOWGj83QgBliZKdor4NNaVpXLSihH+VidLT8aRPwInlw0sr+wKj0n8L vf18n+6p59gdN5+B9emcJPoFTqPinGGSRmoMsY/Vkv6Ew71wfyc+WHhmcE4Jau6alZXL PubL8rHZG6j50MH6++XwwBO6GLBhTppi/3DSQANH+Sobp4y4ZWjrCRSsTQ6EPOoyVxHJ V2ZEenbY+pq5p+nUHqffYo/ZklmQACv2Id/oxx0huf4pESohDKNxYGf9nObnalLvQoHQ 4QuEhnoG2O8HcQV4oR5JF01haWSdXtlQXxJKjm9YeXq7ER4hyqk+NrqFttNnb86c1cKO BrLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718358727; x=1718963527; 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=H0fYVwNKYu1/eayMVZNM0L/hPabLRg+e4eJSmnX7zCk=; b=He/LbwB2pdlQZPA9kRungntJky2rnl05zaSD5QxfRKg4EJ9ESRq0Q0i3I1ZOqa0tAr aGzygjM6w/8RrPm7axlBajSiLulQFT2oPV4MCDP8Dffc60riuotIF/fmKvEdV0SOEWad 8+9cellz7IGF1hvGCsXyzm/RD7FdfKcmtePIdxxvCWK1pu5ItdZwudFJ+KUTD3oIPlRT 6lj3sFjD7AAgqE9EOZLM8NdqP6HDNobeXTVdINGKWENQ9/NSDIDrEqOMqrzQgf2YsZG7 0mT1HvZK+nCAuPrK7Vvrzoc1ZimIWoUMOLeL+UlI4W3MEDDhgRA8YIuCU0LjJ0yXc3YO jN3g== X-Gm-Message-State: AOJu0YyIAzBaO2NQE8+IbPJ5/it8qRcc30iCIeFLFv2CxOVTtkEA+UzE l2i13CVzEDkSY59fVRJClQJPjpyR39IYdzYj61P5wevYuwzxQTrtWITN40Uqif4= X-Google-Smtp-Source: AGHT+IHyaQDaFf9mIvA7iM/slfJf4CIxmWly77e1kkcvWDKdNzAYrUExY1bs5UnrLVmzOrcNHLF6WQ== X-Received: by 2002:a17:902:ea11:b0:1f7:1fb3:14cc with SMTP id d9443c01a7336-1f8625ce900mr29299315ad.18.1718358726823; Fri, 14 Jun 2024 02:52:06 -0700 (PDT) Received: from Ubuntu.. ([117.96.146.43]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f868b83afesm9230005ad.156.2024.06.14.02.52.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 02:52:06 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v4 2/7] reftable: change the type of array indices to 'size_t' in reftable/pq.c Date: Fri, 14 Jun 2024 15:18:02 +0530 Message-ID: <20240614095136.12052-3-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240614095136.12052-1-chandrapratap3519@gmail.com> References: <20240611083157.9876-1-chandrapratap3519@gmail.com> <20240614095136.12052-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The variables 'i', 'j', 'k' and 'min' are used as indices for 'pq->heap', which is an array. Additionally, 'pq->len' is of type 'size_t' and is often used to assign values to these variables. Hence, change the type of these variables from 'int' to 'size_t'. 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 Fri Jun 14 09:48:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13698446 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (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 7B5251922FE for ; Fri, 14 Jun 2024 09:52:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718358732; cv=none; b=celAPCOMs4MdLz94Ll/Tsjf4ZB6IcJw2seMV/za/ed4vmZqQ7QBpy04xaZ++7hStsyhDPpyQM6RJ9YhnCuNULxIVezJDRJo4uY5IYJ0sKZcZD/pzFdjjIBLmzasmsKOmncnxtIYJtrThLDYSpLhLkBxykC1+NRjw7Fh5mgu6Qpg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718358732; c=relaxed/simple; bh=lDezlVhbx4xsaZZRDTavwaiORNa5S6p3fLN6vjDPF2g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C7imb48yBMEUBleHWV5WsT9kIZuYgtejFN5MnyOjH6mN/RgEIMvzW92Oq9fLI0ETvkNP+EnYZ1ZkY62K+dcDLOMJ4kevOcPpqwjFuOuqSn8IgL0mxOHKCePt/z1D6wEaPrf/JzwuhNK61foul2uhagexfjC+JTDsRd1IHNxaijk= 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=STIR10JE; arc=none smtp.client-ip=209.85.210.179 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="STIR10JE" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-704189f1225so1867366b3a.0 for ; Fri, 14 Jun 2024 02:52:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718358730; x=1718963530; 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=STIR10JEH04HFcU24rBHzE3OvAJMKxtS7RXZ2t/kuzs8Dsk5EG4gnkgysyGvwCbCZC r5+V/fhs5rmf9UzjQQearHbL5EJna9UDnAewmz7bw/h+hROmHlaRrEAKsu80TenOhGHO C8su7Dgkk3yN1spxoMs6gCbVRp9slXoe3xS910fiDOfpUdZdL6pb7aFE9h5YhRosucnY QsJUlncRmSVfyKKHvA1a5ivTCXpGlg7rb5vbt5Jh+BdxFQkvA25Wt0/utLvbZCvV6UXs mhMBdO/PKrghmUjw5U+ku9qpY6jbUkA8sWsNoEr/CiQub7ylcoQVW6YWu8eqqk1R0+TS GNHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718358730; x=1718963530; 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=VxgDKnuNIQ8skIxFdQeY8obnsWxmhAMFwXSdDK4y0IkqaNVAh6/tgaG1nCvJCCsBqU 4hB0bUUae+vqzTN1xhzVSlo0jE+454GorYb/o0D65vPKtdQ9LQSx5jwljfv725MZSp1R 9m+kYwkIG4BwA2f7I5zUlS3vWyGQ5T+yk4LCKM4KSprvshp0KLQG1eLMEg7CIq9Q5/gi bs+1YlMmnVTWceApxdeOiaTgRRNi1nS6A/dJYe5r8SW15eiYCcYVw/N/uM7tF767DTpE QKtdy2ShCw+87zyrMN2Q/SpFAQapaoriebT6waWcBVHyNW8aJt3rjNLH8PH5N6zQL6rn mgpQ== X-Gm-Message-State: AOJu0Yyvu43mYxVjk+LfOLM/PdfHZI3lOjLcG86rnj6ZGoceLSLa7I89 kGjeTxnyB8ilEKyxoN6lkYX2Jf8pN1/MjQjBHv8mtu0CtJE2GdEYSpX4hoqWNtE= X-Google-Smtp-Source: AGHT+IHEY8EOu4m7ti4L6DOr1JuvxhnOjnr6fEXd6Tm89MRXy+nglm8JQz39psLuKptqpttozsQ/IA== X-Received: by 2002:a05:6a20:430d:b0:1b7:82b4:a380 with SMTP id adf61e73a8af0-1bae7e93639mr3002271637.29.1718358729845; Fri, 14 Jun 2024 02:52:09 -0700 (PDT) Received: from Ubuntu.. ([117.96.146.43]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f868b83afesm9230005ad.156.2024.06.14.02.52.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 02:52:09 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v4 3/7] t: move reftable/pq_test.c to the unit testing framework Date: Fri, 14 Jun 2024 15:18:03 +0530 Message-ID: <20240614095136.12052-4-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240614095136.12052-1-chandrapratap3519@gmail.com> References: <20240611083157.9876-1-chandrapratap3519@gmail.com> <20240614095136.12052-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 Fri Jun 14 09:48:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13698447 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.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 C10B6199E8C for ; Fri, 14 Jun 2024 09:52:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718358735; cv=none; b=Auf6+wVqAlyq6mVa6Vhc4CTwLofwYPL6Qifc+5JQaZ33ApPNiJX9L5QYYe+psIMj3Xw1xV7+WT9byHZMiDImFP84VwONUyHDagw/GzhbSgiEcvph/+0cH8erwN7zmwxuL2c8/KySnzGlF3jb5xIPbf2s+dLfqd9W66PwXn+hVwI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718358735; c=relaxed/simple; bh=ZBvpDLNHNjoQCJ3AZJra3cFXcfo2DTAZf2kQPpx1UIA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f2mIF3vmPP1YemuJw1r92Aqxp2BbwxHvA04Apm8BjYurBXWMz1rh1TzCtiGM/JYx0qiPRR5x4GSwcjwZosK1BJp6aPGj9tR8pnkRZXizPBaRvEpBDLpHjUPnLHm6ndFgnVyJLVsEetDAG1Xvha6MJN+C8RWUwSB20QPsSwseykk= 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=i4oI1GZa; arc=none smtp.client-ip=209.85.214.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="i4oI1GZa" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1f70509b811so14962675ad.1 for ; Fri, 14 Jun 2024 02:52:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718358733; x=1718963533; 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=i4oI1GZa36JxhhmhGLJ2z8I98wcDeR6f+hfOVXkREMgpBbtrwAjl98ZyBmeMdLmCFX hJtGLEMpISV48B5sCsZw3KV7/BiHhu8zsvHRQghGS1/Xt5IQsQXG/34b1rYMjDQjEZdF h1nz+RgHMZ5hXMh6zDLXonIbvAHqmx/5uu+AAaJ7MW7ILe4WFwzPW/TMKFf0KBBfzK0w pgQpZoaeFA86jcLD0FKlU2HVv/nRS/cJeBUZcokh+FGH0GEwluAnH71N5tO3B60aHzKL FcFpj2K42Yl0YLmsPHTl+0dVEvQrXrDYQdtGKwhKuN1VvDZAF4t1m8+3cfUYXczapHS+ Mz0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718358733; x=1718963533; 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=Fw2aiuY1QfG6EOK3VTjo9FatUUfvgYwg0HN4u6zwX5ifq/7ZaOF4d9d8eLrQcAHnDH gzp40G2eFLpqGFFRCktPYGypBUFhDNjN/Us35SxR6PTbJrKJYoq3yhaoiY/VSn5pNwXF IHeTRj9zQjJkBjaxE+SQZ0WBl2uL8QLulgjUkCE/4IdIyHGoJ5kUA6o7WBnWoq0JjvHH C8bGraeJgPycYTYph1DQhR4tSC3mUD2gCXEbhIjgaWzKNmEqU5F8JsIHV4/ghr1xtQq2 G9EN7e1hZfWBP+Yj0ygLJhsJ/C4HuFQuVTlexEiAXXgI+phWcQneVAu9/Rzfd3HJ4LFC 9Osw== X-Gm-Message-State: AOJu0YxLhGHLM4kzcHnTqLxKV2J0ucXr+O4yZ3tGudrB0n/jMB1uzC54 fO4VxaPz5aQYwukFVZH7Navud9+fPDbZNZk59v6JcuFG/NWDxc4DerQIwZEHZQ8= X-Google-Smtp-Source: AGHT+IGwtSqlfEZ1cadv6UDyH5fnkPgZhJXr6oJ/8E/rZTBQ5lWCGIxpuukVlUoKWvnsHHQyvXftBg== X-Received: by 2002:a17:902:ce89:b0:1f7:13db:527b with SMTP id d9443c01a7336-1f8625c3579mr28259905ad.7.1718358732635; Fri, 14 Jun 2024 02:52:12 -0700 (PDT) Received: from Ubuntu.. ([117.96.146.43]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f868b83afesm9230005ad.156.2024.06.14.02.52.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 02:52:12 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v4 4/7] t-reftable-pq: make merged_iter_pqueue_check() static Date: Fri, 14 Jun 2024 15:18:04 +0530 Message-ID: <20240614095136.12052-5-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240614095136.12052-1-chandrapratap3519@gmail.com> References: <20240611083157.9876-1-chandrapratap3519@gmail.com> <20240614095136.12052-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 Fri Jun 14 09:48:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13698448 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.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 679D519A29F for ; Fri, 14 Jun 2024 09:52:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718358738; cv=none; b=W0BecXQCq+P7Q9l003gHtTkPKtT/V+jpBZTJ3mzdp6/FRpbpd4KzECjIDnPTNt9WUjMHO9arBbPCXzQ1bBk08LOa7ZYtK/BUhR5h4bwSmzWA0H112sTRbygZ1ipI5K2SUU0v3eU+FHyXqhaafxvhB+h0TyDaF7ZJKPTszLVCgN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718358738; c=relaxed/simple; bh=L2kOQvVmitR9fKv557cUouCHnCFAU5dqKoO9TVT+NHE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UN+LQmGjFyr9f0QO56u4um1+DnwKEkALLq0YiqryK/8bX+p3bE/WGLF+0g94om9NJdvWjhKAJNyLaYPus7ycESq08oapFQU2bao8lzSuzNJVH+P/FGKwdGgHy7N4tFj17qN/nQ5dBm3gDPOf5JVdwvXfzxA+McHNDTjjXe3H5Ms= 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=IPpl1Iji; arc=none smtp.client-ip=209.85.214.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="IPpl1Iji" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1f717b3f2d8so22192565ad.1 for ; Fri, 14 Jun 2024 02:52:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718358736; x=1718963536; 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=IPpl1IjiCe6vkUqUHE4f/HtTJQiXEePqmoMqs3ov25CxTH3Dzq01UNVLvLoybgA1VP HG2q+vo8pznjRyMHtug1SFxOB7KjLG9WeXwAc3BW/d7ZvmuM6KLu1mmM78mKWJTx7bOm AItC1Iz48WEiSWNmyqxLSo1oaXsnILdaEGnjOphyTt09zMEOF9TvmiTJu4MeTXFCsXNB YQWhXpTLYev7pULSiFRDl6PyHy/OH0RjGT8qWBbQplpJtYtY0a8Lixuqgulemdt/30QR ENns7Cu961SNwo7aVEQnZ3P+2IgAB+gnCbbKle6owd5+79h/H2QgffjESMyvkx4tZiJH 3FAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718358736; x=1718963536; 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=R+fd8Q0nIwsSEWDAkq4rUKzQEXKxgQKP0zA4Wp5AkrDdwgZuiV91CI6xBoGE8DZdND kckydS8h1sW65MUiHr+omNsAXMf8239Rsl6BG8MID0T0Nxok5s+8plnolDjsBXBrbkr0 tvDfNIqBUuy3ssaPSk27CEtNEYOxBYBnKrGgJwlQle+oGc79n392n5BLXpZ552gPm/if abelikTEf+xclkbbQ8gPHwr52jIg13HX66Sj6uPTiICWCFB0TFmYl4bErRRJw2Y7Bl5M l1IMbwiFzs7FIlXmNFVXGUFLtBbcdEIQ3IuKbo8bqc76WI7xtuC8B3QXutjMi23amrCC lNRQ== X-Gm-Message-State: AOJu0Ywb1e5R521Lh75gr0pLUOJ8rt+iW7l1oqDLrH9n3ctKDeyh5PqK QSu4pUoHWTKyFaBJYmo5p3vHLK9uW1kgFkEPfv9c0gQmcMZNMsDqMfWZ5dQxzfA= X-Google-Smtp-Source: AGHT+IGXgCiRmOIrOwxusqUIxJ0VHOmzXLmN3ll02GrgNI0IUtUuJoVAl3BbbZAgrGFSNVm2dsSjbw== X-Received: by 2002:a17:903:187:b0:1f6:521a:ba30 with SMTP id d9443c01a7336-1f84e1d315emr84956955ad.15.1718358735796; Fri, 14 Jun 2024 02:52:15 -0700 (PDT) Received: from Ubuntu.. ([117.96.146.43]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f868b83afesm9230005ad.156.2024.06.14.02.52.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 02:52:15 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v4 5/7] t-reftable-pq: make merged_iter_pqueue_check() callable by reference Date: Fri, 14 Jun 2024 15:18:05 +0530 Message-ID: <20240614095136.12052-6-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240614095136.12052-1-chandrapratap3519@gmail.com> References: <20240611083157.9876-1-chandrapratap3519@gmail.com> <20240614095136.12052-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 Fri Jun 14 09:48:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13698449 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.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 8230219A29F for ; Fri, 14 Jun 2024 09:52:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718358741; cv=none; b=SSPzVAVrXNh8Jl/OxpcvIOd58XtQ6ulIAOXVTxhXh5K7f4+fRME2cM1BiC8eqDtPZW6djwiDT8gXiE2ztHZjcMeT7tV9FldAXX0LT+qdl1OEvoSqyr+s7Z7H+tnXmpiYqeKjfLhZ6+eM+MrgR1pJg9FXK7GsmBC19ySRteaL0Jw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718358741; c=relaxed/simple; bh=eziVbiL0LUGaEg6d4C+WXfmKilNXwroxU5hjbTdR3E8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bJbi3zql0AfPkHqjwGZYrwh91aNlNbWQK7gayKsN9wPZ9ZByOmcj3pJTcbIzMfKlfpJz1+NI0P4WMzIad5/r72NceTbN1UcFkTkGCowSttvFayQLxunC9GxHAfTGSsG3zIBc7wIPV+RVHtBt2b9qyn59JV2ikLOgX3NQFzyMRNc= 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=OV5vDwY1; arc=none smtp.client-ip=209.85.214.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="OV5vDwY1" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1f7028196f2so17030595ad.2 for ; Fri, 14 Jun 2024 02:52:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718358739; x=1718963539; 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=OV5vDwY1EwUVRuRB5ikDkuzPxvGN9HB6wG0jCtGcWVnpiO/rNsQuDmW+xO7ipz8MWR 563NxELHyaKQ28uoEvw7LMWRhFAoZ2eU0yVp1UpyV57E6ae/swuBCfqeWByFQuHRlihj O0J/E5yYOzTsxY1kYjfUsl3WD+1zzcFjOUCP4QytpBgulreipj6eLO2kPEJKoz1Vtiuk j1nmbpFVUlIQMWSx6zSQe4oevRmXhj9wAXsQVesEBOcHQOodA7VUssq5NPtgwacU0C/4 85WxvrQTK/aD4yPuFItd9rk9n/bSG7VNzXwb/5JVP0Pw3TxOxahjYJveJkRBYXocTle0 /qZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718358739; x=1718963539; 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=iRKGVqMNeMXjtVNRX4IpRpOqQI5jU6qNA2larcriosiP5KpiCTNxdjN6YbvN1soKlJ K+a9fulD8YCSNqAbDj9Wr1XfrwraWj3Uv+E2JXYXZRn9tquFhyL1awhZKTZEyxXq5Mwe SSr3c2nTwn1e/xBNWE8KWukDc134I/ncb8ZH+7tsASuKWe+QtMlf5J0THvTCeloJHt4k mxC1t4faiyeTwT2Wjx8KploVfWNzcoFgOAaZVY97KBSwvfwF079Kdp1C0rRlf5Fvfngi 5zf3X0LpLxovPBBEaB31Au9gdXNuqBX/Vazf/2Rk0R4atdeFtlyXFaLcHNlHPzK0g7pz PAGA== X-Gm-Message-State: AOJu0YxozIjF7PtNnU+lp4V9dG5nhBGEqE1qhKuVcZkKj7+UYwXC6/KB pYu27MGO/AyWWFX4WSXpyPG/8Yi5e+m6zQAJr5qxePEo1ajuZFvNbU8NXiVnM1U= X-Google-Smtp-Source: AGHT+IFFlGa/N7f9jIXFLJDTbeeyt6Vf8VtYXpML75+KPzRleeGSwFMHn6dDhDhLfQLCoNPunOrQBw== X-Received: by 2002:a17:902:d2c6:b0:1f4:71ef:98f8 with SMTP id d9443c01a7336-1f8625ce864mr25301415ad.16.1718358738884; Fri, 14 Jun 2024 02:52:18 -0700 (PDT) Received: from Ubuntu.. ([117.96.146.43]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f868b83afesm9230005ad.156.2024.06.14.02.52.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 02:52:18 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v4 6/7] t-reftable-pq: add test for index based comparison Date: Fri, 14 Jun 2024 15:18:06 +0530 Message-ID: <20240614095136.12052-7-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240614095136.12052-1-chandrapratap3519@gmail.com> References: <20240611083157.9876-1-chandrapratap3519@gmail.com> <20240614095136.12052-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 Fri Jun 14 09:48:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13698450 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.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 3B59C19AA6A for ; Fri, 14 Jun 2024 09:52:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718358744; cv=none; b=j7KhgGQyoA6vMBqyoXJl3iSE6mxwa/YbXHISsW+zwSEmzVuGrzhj6saRe/7uREB9leihSnR1Mc/7r8ZULT5Z27KxfdhrBpN3Mpe8kTqTh0wFmZMudCsgZRX8C9jAAfvT9f4q3puA8Z1nY4clUQwYVIsuxR1yXf5KzSM7UsnFWW8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718358744; c=relaxed/simple; bh=M3NmnPJY+UewlcIXn2gNvLekbAtEtQCb1WnANKxJPUA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LbD0ORz1F1IGv5L92XtU3DIUN74RFUFHj3sMHxAAzj3ebaQapWsJS3qkmads/No9yXWT8VBJRnlWZlOgzyeeFIT6QaylH17TZWEZ9BfzzlbD0OR8aoeP8KtCdYGe3u7frZfOAm4WJa2gVYFjQ5A+ElY4cbWylFN6refq+5LXDyE= 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=A2npOs8i; arc=none smtp.client-ip=209.85.214.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="A2npOs8i" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1f7274a453bso18031125ad.2 for ; Fri, 14 Jun 2024 02:52:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718358742; x=1718963542; 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=A2npOs8iqJ42OIZ+f44GcGIwJKL3h4uovku6NQ3iYkw8fb/nYwx6NHVyx/Y/nJevyv gd4MQ2qWgbMorVtIVfvqp1iVw25C3NPsPqE6ADs+qFFEgfwhIsm7xX8LU5vKUojC68yl ab5bqcJfXAW4O/FIL4MlifbZ4aSfMJZ8GYSMReOnaklbwAURgDV8eL0oaEppcRolA+hZ lCJbgJgsM/7x/Psf5RKwlMCrbsqm40bGcNqHiG4BnmpdLeTh7vZKvS5M12vINbquZIGD FIF+5GqcwFbLqv0LFxhEnXf62QfeEOAdaMk++1+TiZztgzo+9pQLU3K6l0onzEyv/Cvv /S6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718358742; x=1718963542; 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=ueXWGj0w/t7XYbihcnZsNUf/X8MsCkiQkJdYgpIuFIy7dFEKsYrcZS6T459L7+oAnm LaI0IJ4oLhLghjzQH29VWL9sPsN3meztUDRQCjgvLa4epUqv3+x71EupHp8NfEa0PS5A V79VeQCvqsAK7aRsK9L+sRQdSScGUuhLkoWZpFNyua5Xt4gM1KJWWZy2u0EUC3QwWIAN EJ0S53UWOg6mdjgKdqe7X9OuSfs+ElCHHdCBbJHieRmyQcRvIu6x57rs7AW07exU7WKb zXO+qLfkOQ9URxv4HYZSv4y6ILAWNPEgidKkZnFVwhdYEsVdoE2Pg1GB+Ifoa+ueRZvF xFcA== X-Gm-Message-State: AOJu0YzUptjOwnkrzmjltNZ7w91Rk6sSGbAosihhwEA49EX/kwyemwwb NaWJqSKiw2rWZ6SqbvRjPufLdEsK4CzFEyZz5sEnP03kj5YWyvAm9aW3jkFW4dk= X-Google-Smtp-Source: AGHT+IHpJ9r3tS+lkT23tOwbBNNzOyJbeX40IIqMuayqM/BPhpBVhIg07KYIpEtue4IC2G3+IFtSfg== X-Received: by 2002:a17:903:2290:b0:1f7:2a3a:dda2 with SMTP id d9443c01a7336-1f8627d473emr22860495ad.32.1718358742098; Fri, 14 Jun 2024 02:52:22 -0700 (PDT) Received: from Ubuntu.. ([117.96.146.43]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f868b83afesm9230005ad.156.2024.06.14.02.52.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 02:52:21 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v4 7/7] t-reftable-pq: add tests for merged_iter_pqueue_top() Date: Fri, 14 Jun 2024 15:18:07 +0530 Message-ID: <20240614095136.12052-8-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240614095136.12052-1-chandrapratap3519@gmail.com> References: <20240611083157.9876-1-chandrapratap3519@gmail.com> <20240614095136.12052-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(); }