From patchwork Wed Aug 21 12:30:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13771352 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) (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 5E352190472 for ; Wed, 21 Aug 2024 12:42:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724244140; cv=none; b=uk2o+ztiF56riGnpC3Hdqk1o6qIxh7C9TUQYBZinvIglbEzPEQnxPxHcXOrNUAgRObziKBcd7t9vEwrbqmmmFgdM+TzfX5lrki6nDyh36lAvj23NCs0ErZ4xhCTlcstEqvTzGyMw4vPogAn+M4KoxdN7H7cig+NMUKgK+BtNgwc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724244140; c=relaxed/simple; bh=agZnrMOtyNjNzuJqUc7XskvIpJQwL7dokPxm5FKsbaU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T71SltXlX1LjptSSKajgcu2iIrCyg1dz2w5SimrNQl+gbjNtuI0jqRMSk1Yqytqd3iDXr06CZyzwBfykkqzp56/c6aXIxkajizpke7R6H9SNOi6gsV5p0j181GJCIM/f2FmbHnBI2YfULbaGXjyZZ8sIw59RIzFx5r6CPxBb9ME= 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=kjXiYJml; arc=none smtp.client-ip=209.85.215.181 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="kjXiYJml" Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-7cd895682fcso248223a12.0 for ; Wed, 21 Aug 2024 05:42:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724244138; x=1724848938; 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=lPViukUUlapprpV9Rr9pSwpDCDAk1R+nEMTnVCtTuyk=; b=kjXiYJml9lyXJnXTRPUniorRC6SnS4UIaJd1ut4r73haYhdicu6O6S3M3B2x44e4CG Ll8XdTt1WVoRSPaG8HXSCIDKCoGhFABMc7ObaM9YUgHIZgD29O4yPOHi9SPSobgqYUGQ w5INwaFC5tJq7jT5A+2qa2l8JZ3a0nsMWY8UxaAg9HVv+4PCHUxtosLoUDkCW+A60oKT Iz2JMC/wqHrGLiphvNkr2uHfHMkuZzKfF7CqK/4TzNSdziKXpxZ/A9OdGCdBfDGKmPb3 RbWZI+5PvUdedKJNAMlL+t8mqsLZB2EcgIYO4Ppvcd3EFogUnGv7wNeCYxbMEyzx1uxY 4r/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724244138; x=1724848938; 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=lPViukUUlapprpV9Rr9pSwpDCDAk1R+nEMTnVCtTuyk=; b=sbSDjRiOPb+CyDdPI+bmaJZnEpLOVGHxcRATc6KXGVUP9wyXV9GaZUGpIy3kGIb1yl JJkYtHaAOgfIIy/r/f9v6/2CJ1FsyYxd6o2Bupx8irQlJUMuRMmFDBPeVkixQSBZhRip EO46X9owv91iG7YjRpzoUv9M1QFscOBRTTGAziXD2Ke1OB2REqQmpP4nhpZq5vGPXwEX HNiPQJdW98Ecr9yaYhscr18fI01VmZCM7Rrnb+YUG7dLW9LvLCh0T1MKi+92rVxqmLVV gnS1LqE+ewfAJtE3MPP957ybCQK81Q48mf3B63S96FeOmMN6acaCFjOYkLmyNK2Vj65t Lx4Q== X-Gm-Message-State: AOJu0Yy6hokY4oWDb50xakF6WfY2zMJULeNPH6kvm+cVct2/IPn7A9Bi sjYgAoMGGZLGTk5lntOaDJZFgIRqyTiFrovvWjK/FwcqjSlnYCQQh3GL10VD X-Google-Smtp-Source: AGHT+IH8CAnPpnb9Kupr/8IF7nwGjTEFrFgwQ4kMMkhlV8tfX1Jb5EFftM/gFm+TsBBE418wgxAzQQ== X-Received: by 2002:a17:90a:c68d:b0:2c9:649c:5e08 with SMTP id 98e67ed59e1d1-2d5e99f84e8mr2094972a91.15.1724244137969; Wed, 21 Aug 2024 05:42:17 -0700 (PDT) Received: from Ubuntu.. ([27.59.95.0]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2d5ebba8853sm1670963a91.56.2024.08.21.05.42.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 05:42:17 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 01/11] t: move reftable/block_test.c to the unit testing framework Date: Wed, 21 Aug 2024 18:00:51 +0530 Message-ID: <20240821124150.4463-2-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240821124150.4463-1-chandrapratap3519@gmail.com> References: <20240816175414.5169-1-chandrapratap3519@gmail.com> <20240821124150.4463-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 reftable/block_test.c exercises the functions defined in reftable/block.{c, h}. Migrate reftable/block_test.c to the unit testing framework. Migration involves refactoring the tests to use the unit testing framework instead of reftable's test framework and renaming the tests to follow the unit-tests' naming conventions. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- Makefile | 2 +- reftable/reftable-tests.h | 1 - t/helper/test-reftable.c | 1 - .../unit-tests/t-reftable-block.c | 45 +++++++++---------- 4 files changed, 22 insertions(+), 27 deletions(-) rename reftable/block_test.c => t/unit-tests/t-reftable-block.c (76%) diff --git a/Makefile b/Makefile index 13890710f8..a30cd636f8 100644 --- a/Makefile +++ b/Makefile @@ -1340,6 +1340,7 @@ UNIT_TEST_PROGRAMS += t-oidmap UNIT_TEST_PROGRAMS += t-oidtree UNIT_TEST_PROGRAMS += t-prio-queue UNIT_TEST_PROGRAMS += t-reftable-basics +UNIT_TEST_PROGRAMS += t-reftable-block UNIT_TEST_PROGRAMS += t-reftable-merged UNIT_TEST_PROGRAMS += t-reftable-pq UNIT_TEST_PROGRAMS += t-reftable-record @@ -2681,7 +2682,6 @@ REFTABLE_OBJS += reftable/stack.o REFTABLE_OBJS += reftable/tree.o REFTABLE_OBJS += reftable/writer.o -REFTABLE_TEST_OBJS += reftable/block_test.o REFTABLE_TEST_OBJS += reftable/dump.o REFTABLE_TEST_OBJS += reftable/readwrite_test.o REFTABLE_TEST_OBJS += reftable/stack_test.o diff --git a/reftable/reftable-tests.h b/reftable/reftable-tests.h index 4b666810af..3d9118b91b 100644 --- a/reftable/reftable-tests.h +++ b/reftable/reftable-tests.h @@ -10,7 +10,6 @@ license that can be found in the LICENSE file or at #define REFTABLE_TESTS_H int basics_test_main(int argc, const char **argv); -int block_test_main(int argc, const char **argv); int record_test_main(int argc, const char **argv); int readwrite_test_main(int argc, const char **argv); int stack_test_main(int argc, const char **argv); diff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c index 623cf3f0f5..7bdd18430b 100644 --- a/t/helper/test-reftable.c +++ b/t/helper/test-reftable.c @@ -5,7 +5,6 @@ int cmd__reftable(int argc, const char **argv) { /* test from simple to complex. */ - block_test_main(argc, argv); readwrite_test_main(argc, argv); stack_test_main(argc, argv); return 0; diff --git a/reftable/block_test.c b/t/unit-tests/t-reftable-block.c similarity index 76% rename from reftable/block_test.c rename to t/unit-tests/t-reftable-block.c index 90aecd5a7c..f2b9a8a6f4 100644 --- a/reftable/block_test.c +++ b/t/unit-tests/t-reftable-block.c @@ -6,17 +6,13 @@ license that can be found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd */ -#include "block.h" +#include "test-lib.h" +#include "reftable/block.h" +#include "reftable/blocksource.h" +#include "reftable/constants.h" +#include "reftable/reftable-error.h" -#include "system.h" -#include "blocksource.h" -#include "basics.h" -#include "constants.h" -#include "record.h" -#include "test_framework.h" -#include "reftable-tests.h" - -static void test_block_read_write(void) +static void t_block_read_write(void) { const int header_off = 21; /* random */ char *names[30]; @@ -45,7 +41,7 @@ static void test_block_read_write(void) rec.u.ref.refname = (char *) ""; rec.u.ref.value_type = REFTABLE_REF_DELETION; n = block_writer_add(&bw, &rec); - EXPECT(n == REFTABLE_API_ERROR); + check_int(n, ==, REFTABLE_API_ERROR); for (i = 0; i < N; i++) { char name[100]; @@ -59,11 +55,11 @@ static void test_block_read_write(void) n = block_writer_add(&bw, &rec); rec.u.ref.refname = NULL; rec.u.ref.value_type = REFTABLE_REF_DELETION; - EXPECT(n == 0); + check_int(n, ==, 0); } n = block_writer_finish(&bw); - EXPECT(n > 0); + check_int(n, >, 0); block_writer_release(&bw); @@ -73,11 +69,11 @@ static void test_block_read_write(void) while (1) { int r = block_iter_next(&it, &rec); - EXPECT(r >= 0); + check_int(r, >=, 0); if (r > 0) { break; } - EXPECT_STREQ(names[j], rec.u.ref.refname); + check_str(names[j], rec.u.ref.refname); j++; } @@ -90,20 +86,20 @@ static void test_block_read_write(void) strbuf_addstr(&want, names[i]); n = block_iter_seek_key(&it, &br, &want); - EXPECT(n == 0); + check_int(n, ==, 0); n = block_iter_next(&it, &rec); - EXPECT(n == 0); + check_int(n, ==, 0); - EXPECT_STREQ(names[i], rec.u.ref.refname); + check_str(names[i], rec.u.ref.refname); want.len--; n = block_iter_seek_key(&it, &br, &want); - EXPECT(n == 0); + check_int(n, ==, 0); n = block_iter_next(&it, &rec); - EXPECT(n == 0); - EXPECT_STREQ(names[10 * (i / 10)], rec.u.ref.refname); + check_int(n, ==, 0); + check_str(names[10 * (i / 10)], rec.u.ref.refname); block_iter_close(&it); } @@ -116,8 +112,9 @@ static void test_block_read_write(void) } } -int block_test_main(int argc, const char *argv[]) +int cmd_main(int argc, const char *argv[]) { - RUN_TEST(test_block_read_write); - return 0; + TEST(t_block_read_write(), "read-write operations on blocks work"); + + return test_done(); } From patchwork Wed Aug 21 12:30:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13771353 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (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 6046D18C929 for ; Wed, 21 Aug 2024 12:42:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724244143; cv=none; b=losSX8ppeHMBbAMzlf9sFWFD8xLrUsu444mkntF0+6TvTxXx4cdNecAdWFmq0Q2Ol7kNkrcYIlyqqBOytCN7V8l2hBduWca2Yo3Qxp2GXSTZ1tKVnMy9K1ijzHihwP1YZJ+JylKixWYU2zfllNQP4QLWYFWq2gZOK9JmibtMUMs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724244143; c=relaxed/simple; bh=61cKOBkwMaN3Pb6Bz8j2jjKcVO5mWqMNJZdQ2PWxCm8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tBiKAaFl7HrnhSjSpa7WxmCJgljTYNjwo3reUbr/0cLNXiVEEpSysPJMZ9DunahhK//munOwqOklrugou5fEiQGn2Ycw6WY6c0LK4r01r/K3b01kko9qpHnFVbHAHN2KptGgf2JkFv6mgdf2v3mjWLBP0YEq4ltArsZGtGpXa+E= 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=lWKge1CE; arc=none smtp.client-ip=209.85.215.178 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="lWKge1CE" Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-7cd895682fcso248236a12.0 for ; Wed, 21 Aug 2024 05:42:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724244141; x=1724848941; 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=x/AOHJYi9/WQuiiiDcao3F43bozZGndvsf3LEuJHY1M=; b=lWKge1CEtnhfuHS4rVec3G1Gw9YXtL7tFgYT1g/6Zskc8yx96ePETh6VH5WJ4VQvmL SETbkMJioX5khroYlU78iFVMZZR2xTr3j26n7sg5Wiwptfx6ggpRqRID6Ccfnol1vXsB Ya3OPV6g78SLHWGF/e8IJEyewIC1j6zpQ+5ZxdjpBCX/PFOAWzolY8CZjwhclCrPDJNY GoqfbiivtXDD+DbGZuzZhn1RXkksl9DY2hiTRBGQy3e4LEhPxZKgNK7X6+r+XY0m2/Yi pzjdBO5eb3pLEyG/CXwX0lxkxq6iPGb62PB1UQgxWUYgVnsrl7+slZMilnkbHGxeT6sI sHfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724244141; x=1724848941; 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=x/AOHJYi9/WQuiiiDcao3F43bozZGndvsf3LEuJHY1M=; b=VcnHXl+1nRqnFfQkhs4zFKUU9dASe28bMm67NWcH62Xs9k+GpMQgiRMFEdGI4xHWx6 3FLeu/QoqFF2mRpXJ8linQTVBgiw5JkJPumjRLVbHpMIQrWGr3SPtctiLV4NqFN91kD3 9KRq1Z6XAwkbtWhLwbhKQ76htIhGZaYigygB4ZLJlmWmsneC4gaybrxcTywGJ4fQ/wX8 kE0aZ6KXuXz9hkPnRYxSfwder+xhkxWqioR9DFFjvdgiOiceqJKgg0kh3BBIlId+ZT4s KZk4U/2no8f8Cne1sWH1CG2r8EXpJbv0SOvTgL6bqbHmOaMXyRVdjKZaq0aZjBgWWUnn E6LQ== X-Gm-Message-State: AOJu0YzWCVE3HMA3MvoM3W3Qownvi+ANmBXHqymJEtXnQUy3jMJ1L1do YDN6Iy1QwbDnA8kwMIHcLaVURvS8EMCQC+GqNPGqLUqSmIHKzFyp7BQitTJ1 X-Google-Smtp-Source: AGHT+IHvQveZ8cnGwnXFS94gXdH47oWKF8Y73EcsYbsSbCW2HojB2IuP7ghsjNTi4AGyZ+wKS2WvUw== X-Received: by 2002:a05:6a21:2d07:b0:1c4:21c0:ea0f with SMTP id adf61e73a8af0-1cad8352b99mr2928611637.33.1724244141086; Wed, 21 Aug 2024 05:42:21 -0700 (PDT) Received: from Ubuntu.. ([27.59.95.0]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2d5ebba8853sm1670963a91.56.2024.08.21.05.42.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 05:42:20 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 02/11] t: harmonize t-reftable-block.c with coding guidelines Date: Wed, 21 Aug 2024 18:00:52 +0530 Message-ID: <20240821124150.4463-3-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240821124150.4463-1-chandrapratap3519@gmail.com> References: <20240816175414.5169-1-chandrapratap3519@gmail.com> <20240821124150.4463-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Harmonize the newly ported test unit-tests/t-reftable-block.c with the following guidelines: - Single line 'for' statements must omit curly braces. - Structs must be 0-initialized with '= { 0 }' instead of '= { NULL }'. - Array sizes and indices should preferably be of type 'size_t'and not 'int'. - Return code variable should preferably be named 'ret', not 'n'. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-block.c | 52 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/t/unit-tests/t-reftable-block.c b/t/unit-tests/t-reftable-block.c index f2b9a8a6f4..b1b238ac2a 100644 --- a/t/unit-tests/t-reftable-block.c +++ b/t/unit-tests/t-reftable-block.c @@ -16,20 +16,20 @@ static void t_block_read_write(void) { const int header_off = 21; /* random */ char *names[30]; - const int N = ARRAY_SIZE(names); - const int block_size = 1024; - struct reftable_block block = { NULL }; + const size_t N = ARRAY_SIZE(names); + const size_t block_size = 1024; + struct reftable_block block = { 0 }; struct block_writer bw = { .last_key = STRBUF_INIT, }; struct reftable_record rec = { .type = BLOCK_TYPE_REF, }; - int i = 0; - int n; + size_t i = 0; + int ret; struct block_reader br = { 0 }; struct block_iter it = BLOCK_ITER_INIT; - int j = 0; + size_t j = 0; struct strbuf want = STRBUF_INIT; REFTABLE_CALLOC_ARRAY(block.data, block_size); @@ -40,26 +40,26 @@ static void t_block_read_write(void) rec.u.ref.refname = (char *) ""; rec.u.ref.value_type = REFTABLE_REF_DELETION; - n = block_writer_add(&bw, &rec); - check_int(n, ==, REFTABLE_API_ERROR); + ret = block_writer_add(&bw, &rec); + check_int(ret, ==, REFTABLE_API_ERROR); for (i = 0; i < N; i++) { char name[100]; - snprintf(name, sizeof(name), "branch%02d", i); + snprintf(name, sizeof(name), "branch%02"PRIuMAX, (uintmax_t)i); rec.u.ref.refname = name; rec.u.ref.value_type = REFTABLE_REF_VAL1; memset(rec.u.ref.value.val1, i, GIT_SHA1_RAWSZ); names[i] = xstrdup(name); - n = block_writer_add(&bw, &rec); + ret = block_writer_add(&bw, &rec); rec.u.ref.refname = NULL; rec.u.ref.value_type = REFTABLE_REF_DELETION; - check_int(n, ==, 0); + check_int(ret, ==, 0); } - n = block_writer_finish(&bw); - check_int(n, >, 0); + ret = block_writer_finish(&bw); + check_int(ret, >, 0); block_writer_release(&bw); @@ -68,9 +68,10 @@ static void t_block_read_write(void) block_iter_seek_start(&it, &br); while (1) { - int r = block_iter_next(&it, &rec); - check_int(r, >=, 0); - if (r > 0) { + ret = block_iter_next(&it, &rec); + check_int(ret, >=, 0); + if (ret > 0) { + check_int(i, ==, N); break; } check_str(names[j], rec.u.ref.refname); @@ -85,20 +86,20 @@ static void t_block_read_write(void) strbuf_reset(&want); strbuf_addstr(&want, names[i]); - n = block_iter_seek_key(&it, &br, &want); - check_int(n, ==, 0); + ret = block_iter_seek_key(&it, &br, &want); + check_int(ret, ==, 0); - n = block_iter_next(&it, &rec); - check_int(n, ==, 0); + ret = block_iter_next(&it, &rec); + check_int(ret, ==, 0); check_str(names[i], rec.u.ref.refname); want.len--; - n = block_iter_seek_key(&it, &br, &want); - check_int(n, ==, 0); + ret = block_iter_seek_key(&it, &br, &want); + check_int(ret, ==, 0); - n = block_iter_next(&it, &rec); - check_int(n, ==, 0); + ret = block_iter_next(&it, &rec); + check_int(ret, ==, 0); check_str(names[10 * (i / 10)], rec.u.ref.refname); block_iter_close(&it); @@ -107,9 +108,8 @@ static void t_block_read_write(void) reftable_record_release(&rec); reftable_block_done(&br.block); strbuf_release(&want); - for (i = 0; i < N; i++) { + for (i = 0; i < N; i++) reftable_free(names[i]); - } } int cmd_main(int argc, const char *argv[]) From patchwork Wed Aug 21 12:30:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13771354 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (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 DED5F192D80 for ; Wed, 21 Aug 2024 12:42:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724244146; cv=none; b=LV6T1TPG8eHrs/yN0TBonvbsCNJrXBccmPaGAt63kVzp+08pAuph1A4qflDuu+1o9C38JcBGRq57vJxZ92M/MkMtx31Gu+A2W682UXq6aWNZCC0jfW9D1i73bSTZKsOQQlKaxXMlAB9EY1/H5ETjDp66PWzdKL1N5OdmIX3eLxM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724244146; c=relaxed/simple; bh=kuNMT+Mz/B48UOGZINSIcyE+FXrNDfjXrncrh0vdxZI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JbXLmv9fs5VvVlmHCp3PWEHpKMR12ypHD7ntcrALsC+1XW4YICtpnKmk0ZexMsWUnG+nA/lK4yljd4eInbF8mEucJt6017gCEBGuMkl7XiII/gsJr6yquLZPuStzBmJukBC8Ej5+/WZmN7O03oQzAc6kHNw+9jfxlBR4a0fvhXc= 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=dtgDDedL; arc=none smtp.client-ip=209.85.215.174 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="dtgDDedL" Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-7bb75419123so4443769a12.3 for ; Wed, 21 Aug 2024 05:42:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724244144; x=1724848944; 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=yIhWqQC8cOCl9rCuLpzbSL3YED3IjToOqwNVrWzcNB4=; b=dtgDDedLevhNLU+AekEBzdCGCZLoD4a/XqLSgWSNfq67XxKQHYBGIw2VE92Kptx8PO ihQJuWvo1IdbdGGKiExnaUeBG6YShvJnCkFnXgsqosylnFmKAIUZ/KTrqjnswZwaY4tL RIiuIv9jszt4+59LmSAPAt9I6OQATpo//wHOuyXvxe7iAdxiP1kaWkMdKuINvgEubhQC XOtOjTWHARJKkVNxwME29J8FGKjTRvNpy4nFTq4PNjlAq0DAeDzq0NDBKl7jCcQjx+XI ZxTkKO1Q/FlMBZz8MtihQh/d3jxHcHOqWkAwzSsw+rlxTmuHLGdZc2DsvlkVWJ9suvdV 9dDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724244144; x=1724848944; 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=yIhWqQC8cOCl9rCuLpzbSL3YED3IjToOqwNVrWzcNB4=; b=L5ufggSi11Vj19bC14TCrkQFM2gp0OP1HQopzipBymzMs/0d4OnxDoSk+svQvpJVzp ILf6gPlhzJyYwbr1VGF6UGY1KUd5+fc9VCpaRXlGD6ivGviZCyfXfzqWK8vsCNL1Ndhl 4U4rGq45FX0IQISIqs1qrXqPBqoBgVN9pdRwd2kKPSbL+o9ALAc4hSawhRnjPlmF+GJQ aYduKPo0xPfPmLR5GWIBONuuB3NgZbQfRjspC2e8qSDLkDXVj1b9yQEBf1ls3URHBgmv lsYcfeNruNjHkex9f9Oh4dZqlGDJY4yiCZSAU3nhrR2F9uoEiQqytFdyeO8CAEcMZmGv fIhQ== X-Gm-Message-State: AOJu0Yw5nCBZYyxJrTiA+vLFZji1Yo0Pqj8Q+m+22205QWf3oPskGopu KJnBfuyRRPZgmIEtWrlaFmykhfrPv7MeOoB2EHF3QNFQewJnJOheu4BuExNC X-Google-Smtp-Source: AGHT+IF2Czw/wV9fEvArBhzgUGIT5VlxmGNwIwFUn1cjiqyxCBLfub6bGKjTihI4goz5m5ZCyGKBkQ== X-Received: by 2002:a17:90b:282:b0:2d3:b1d1:b63a with SMTP id 98e67ed59e1d1-2d5e9a2ae04mr2460306a91.22.1724244143780; Wed, 21 Aug 2024 05:42:23 -0700 (PDT) Received: from Ubuntu.. ([27.59.95.0]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2d5ebba8853sm1670963a91.56.2024.08.21.05.42.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 05:42:23 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 03/11] t-reftable-block: release used block reader Date: Wed, 21 Aug 2024 18:00:53 +0530 Message-ID: <20240821124150.4463-4-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240821124150.4463-1-chandrapratap3519@gmail.com> References: <20240816175414.5169-1-chandrapratap3519@gmail.com> <20240821124150.4463-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Used block readers must be released using block_reader_release() to prevent the occurence of a memory leak. Make test_block_read_write() conform to this statement. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-block.c | 1 + 1 file changed, 1 insertion(+) diff --git a/t/unit-tests/t-reftable-block.c b/t/unit-tests/t-reftable-block.c index b1b238ac2a..eafe1fdee9 100644 --- a/t/unit-tests/t-reftable-block.c +++ b/t/unit-tests/t-reftable-block.c @@ -105,6 +105,7 @@ static void t_block_read_write(void) block_iter_close(&it); } + block_reader_release(&br); reftable_record_release(&rec); reftable_block_done(&br.block); strbuf_release(&want); From patchwork Wed Aug 21 12:30:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13771355 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.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 E299B18E34B for ; Wed, 21 Aug 2024 12:42:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724244149; cv=none; b=unD4dh4g/xf9VMKHw76pOAwnt19zS6mBYdmsp73I48C371BYI1gzBYuYW3l3vuW8GE9juBJ4TJFX+XaHPmiNjmxv5CkB82xXxp7XxhFUnDPT3VQ/0Ut4cL86kiRZBdRkA5EdxBmyasufQ5oLDNdPVPEnjCUtIGQ3ndhWwlqe2j8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724244149; c=relaxed/simple; bh=AFFKBAJ5Q++FqG+OBgl0aHym6OgHA2PnBKd6KKwGxZg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ScpOjzBYtAlZHgUZwkKcr+zK751fqfR/k63Jw5OnniilGWrkOgIxA8QIKCFLF8vOK/GbaxMGBvpka2eOSe82QAYNgu2KjUCq4bKdtWMonMtIzOUkM0KxcTbZYt8v75QRplVXiUs7LuNMb/rdELjfhb7dha4fpERoF1kSb55WtUk= 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=QmoRcyja; arc=none smtp.client-ip=209.85.215.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="QmoRcyja" Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-7cd830e0711so663043a12.0 for ; Wed, 21 Aug 2024 05:42:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724244147; x=1724848947; 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=1jfhaCnbxJpZdGs0IIOV1vnMpU20Pn9A130jjmjoGBI=; b=QmoRcyjajRlUn/NfoCeT9LQYSGiHvumJa+ixkRkioxIQejju0gcQw9KozvpntenHkZ nBv7Rdx5cIumWSIEX2kWYQA71hMpjgLqRaNqvtCSfEbgJ+N9/9ZgO4VJvMnWWJLllMdU 4WkMvxiMl6miIPI8DqbxJts5QrBf2wXU0Xhfe1tqLixJEQ5UxkQExJmrrdMsABE3hyYY yN6EWeFGKjX6RKXdrmQ6L26jhuUpMhoiXgLBsnRpz0kc/CZOGbL7iDz4QpgZfTH101gL xnqPl3soI0C+KB2baavTlfGR+2fyCOi48COJBcLAGmG8kEpSkJRi4v+EQGEKIvUA4qFH 2Cjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724244147; x=1724848947; 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=1jfhaCnbxJpZdGs0IIOV1vnMpU20Pn9A130jjmjoGBI=; b=pVFLEbcqQ3VRyRTUAwqu+QRaAKurbiUg8zPeMXDcmckcq0EHSh1E8qhy6xtR9uy4bq 7qLI99ZibCakAu3Xx/E5wWLQaYjY3+fDgfc94Ma7tiO1R32XgDhqWDCpU/UezXGQnOSV wyZksDUgaiot91o4vbEBKf51NRG8HFiPjVUFV0mEOjuEHr0C+R3PxQYakjhqhMw0tvxK Lv42wpnP7oJkEbQn+aCXkvCCHVAQ+6jRV3v1Z2Ik/NQH5ypOiTzKt0eFhRWyvcJ0VxAn T4w7y77tqhaagic5GMVWKKUHl2VhPwNeKwPJFVJL+2S/ciEzdGtuyZ1eUfdYd0V8ztv+ VseQ== X-Gm-Message-State: AOJu0YxtCcrSzAIfF7vfEK4u23gaFSP2y4c1P0Cpk1BbxH43bAzkXTeC wLlYe/usfvVQ9DoN84V/kuznKoMnBs0Llihp1xbBB73aG1FQ56FoXf0HhiiS X-Google-Smtp-Source: AGHT+IHT5Kl/az2IZyWSC0CVz0REh3UkDUMgJ7w2WU6KQ9LqIVGJu8EdNHzdS9OaJUdiS6it12SOMw== X-Received: by 2002:a17:90b:33c5:b0:2c9:7343:71f1 with SMTP id 98e67ed59e1d1-2d5e9a419dbmr3624164a91.14.1724244146619; Wed, 21 Aug 2024 05:42:26 -0700 (PDT) Received: from Ubuntu.. ([27.59.95.0]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2d5ebba8853sm1670963a91.56.2024.08.21.05.42.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 05:42:26 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 04/11] t-reftable-block: use reftable_record_equal() instead of check_str() Date: Wed, 21 Aug 2024 18:00:54 +0530 Message-ID: <20240821124150.4463-5-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240821124150.4463-1-chandrapratap3519@gmail.com> References: <20240816175414.5169-1-chandrapratap3519@gmail.com> <20240821124150.4463-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In the current testing setup, operations like read and write for reftable blocks as defined by reftable/block.{c, h} are verified by comparing only the keys of input and output reftable records. This is not ideal because there can exist inequal reftable records with the same key. Use the dedicated function for record comparison, reftable_record_equal(), instead of key-based comparison. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-block.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/t/unit-tests/t-reftable-block.c b/t/unit-tests/t-reftable-block.c index eafe1fdee9..b106d3c1e4 100644 --- a/t/unit-tests/t-reftable-block.c +++ b/t/unit-tests/t-reftable-block.c @@ -15,8 +15,8 @@ license that can be found in the LICENSE file or at static void t_block_read_write(void) { const int header_off = 21; /* random */ - char *names[30]; - const size_t N = ARRAY_SIZE(names); + struct reftable_record recs[30]; + const size_t N = ARRAY_SIZE(recs); const size_t block_size = 1024; struct reftable_block block = { 0 }; struct block_writer bw = { @@ -47,11 +47,11 @@ static void t_block_read_write(void) char name[100]; snprintf(name, sizeof(name), "branch%02"PRIuMAX, (uintmax_t)i); - rec.u.ref.refname = name; + rec.u.ref.refname = xstrdup(name); rec.u.ref.value_type = REFTABLE_REF_VAL1; memset(rec.u.ref.value.val1, i, GIT_SHA1_RAWSZ); - names[i] = xstrdup(name); + recs[i] = rec; ret = block_writer_add(&bw, &rec); rec.u.ref.refname = NULL; rec.u.ref.value_type = REFTABLE_REF_DELETION; @@ -74,7 +74,7 @@ static void t_block_read_write(void) check_int(i, ==, N); break; } - check_str(names[j], rec.u.ref.refname); + check(reftable_record_equal(&recs[j], &rec, GIT_SHA1_RAWSZ)); j++; } @@ -84,7 +84,7 @@ static void t_block_read_write(void) for (i = 0; i < N; i++) { struct block_iter it = BLOCK_ITER_INIT; strbuf_reset(&want); - strbuf_addstr(&want, names[i]); + strbuf_addstr(&want, recs[i].u.ref.refname); ret = block_iter_seek_key(&it, &br, &want); check_int(ret, ==, 0); @@ -92,7 +92,7 @@ static void t_block_read_write(void) ret = block_iter_next(&it, &rec); check_int(ret, ==, 0); - check_str(names[i], rec.u.ref.refname); + check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ)); want.len--; ret = block_iter_seek_key(&it, &br, &want); @@ -100,7 +100,7 @@ static void t_block_read_write(void) ret = block_iter_next(&it, &rec); check_int(ret, ==, 0); - check_str(names[10 * (i / 10)], rec.u.ref.refname); + check(reftable_record_equal(&recs[10 * (i / 10)], &rec, GIT_SHA1_RAWSZ)); block_iter_close(&it); } @@ -110,7 +110,7 @@ static void t_block_read_write(void) reftable_block_done(&br.block); strbuf_release(&want); for (i = 0; i < N; i++) - reftable_free(names[i]); + reftable_record_release(&recs[i]); } int cmd_main(int argc, const char *argv[]) From patchwork Wed Aug 21 12:30:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13771356 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (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 D5F96199935 for ; Wed, 21 Aug 2024 12:42:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724244153; cv=none; b=OA2ZbOMlBOyuQtRo+4FlGWvw4B2gaYYjx9yfrlQAnv2W0igGIySUqh1zhpu1+PkfSPGPRLrGS+eD88r23FIvt1+KtIiqfqMWhjWsFW9VBTe3SGHsMgBfj71rrgi+U6nTjaIP+jIRi2JPBIhloxYSlDfHefLdtyn9IpOmgeX4AVs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724244153; c=relaxed/simple; bh=aWca99CbvjawBPMs86vKGxOb+c2Z8Fsf3MkweJ9hQAg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YkDvYIYqJbDkOla6l9Y0b60FGILjNxq5OY1AijOK9xTSvvd8Nc0m6YgTPW/9OX9z1DMS1FLq/R+vno3TlKeRrcjLKUQXJO6Ev4U1nNthM/h9SogU3ZfRyNuiWCO+5TjflEhRpWasP29ktBe2SRiGiUQZZZWkkqc9lqvGh5qZtlI= 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=UwjHGZmT; arc=none smtp.client-ip=209.85.216.45 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="UwjHGZmT" Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-2d3ce556df9so4165060a91.0 for ; Wed, 21 Aug 2024 05:42:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724244150; x=1724848950; 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=H2oZiqewD+NWCsYSxzcctnFWWSaZ1IPuB/5e1X8qvfA=; b=UwjHGZmTjaXnveRPwRsDAgGs5sUFT0yZwW43wsCZ/9MMXmsQuBht0Pwh8IkoXo/Ua0 IqPEFe/zFrNmvH8IGvaFl6F80EXSFiuTm0TeQqY0ICo7QndiTlhYowmedpPLBIm/comZ Cf8c9j180fQdfh+VXnE/eRGROYLd9486jZvfbVRec3OGF9nvh7DJ0HN/DEfaUbxgWXoN ixBIigWB0JagwswPbe/zsu/UEcYMpnf3351w3lAJloDYcYATxTLx5NGpFt7cwR2+dkCr 0G2rmydpdDfUc52HtH2MatbUiC875mlRVNJ8tLfpSISVuxT0anLh4nwgZareA9hb5tPo oCbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724244150; x=1724848950; 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=H2oZiqewD+NWCsYSxzcctnFWWSaZ1IPuB/5e1X8qvfA=; b=gLdPhkw7YP7rAtJFC7Eb1k0bf/yAS7lkhdfBBZ08wvk9clz0EsQX17DaalXwcaofZ+ eEmVL7A7Nz5W8hwV+x33QwbMrmD7uiIeI7rXjLNx/0+UdVL/9T9rTncRC8D7iY4Ggk3i 16Ind8HU8+acUzoYtWjv5IKFXjlkEDoiJFiQk46KFD9KZKTklKCSp6tSKvkw2S9yyrmF VgACcDRUKKl4fDHPi7piZryafbBmIShaWrwWpkeM5NFr1suwiDi7O6vBeJZMIqqrw75W leCC2Ug0eRpkuwMo4RIj5nYICxuqE+fhuZYR5lAPRSzYSqhIVPV6aHEJCNu+Rvw+zEF/ cJiw== X-Gm-Message-State: AOJu0Yz1d+MGwq4LLDMTGSsXgvPfSCYeMFQBVwFWdqidscpt3h1zy0GE Pt046b3jkZ8gmOyA4os3T6SKWyqpwx0+pfwEfzhqHrkGMLDCMfV/DXr67mQ+ X-Google-Smtp-Source: AGHT+IHmPEQZ5c4yG8N4ccAdrChHLcSr84yHn+eeHmQmzpp0AVKXzZ12rE1eu1Y4FaRebRYN8rHtMA== X-Received: by 2002:a17:90a:c210:b0:2d1:b36c:6bc1 with SMTP id 98e67ed59e1d1-2d5e99e0d08mr2057365a91.2.1724244149603; Wed, 21 Aug 2024 05:42:29 -0700 (PDT) Received: from Ubuntu.. ([27.59.95.0]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2d5ebba8853sm1670963a91.56.2024.08.21.05.42.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 05:42:29 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 05/11] t-reftable-block: use reftable_record_key() instead of strbuf_addstr() Date: Wed, 21 Aug 2024 18:00:55 +0530 Message-ID: <20240821124150.4463-6-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240821124150.4463-1-chandrapratap3519@gmail.com> References: <20240816175414.5169-1-chandrapratap3519@gmail.com> <20240821124150.4463-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In the current testing setup, the record key required for many block iterator functions is manually stored in a strbuf struct and then passed to these functions. This is not ideal when there exists a dedicated function to encode a record's key into a strbuf, namely reftable_record_key(). Use this function instead of manual encoding. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-block.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/t/unit-tests/t-reftable-block.c b/t/unit-tests/t-reftable-block.c index b106d3c1e4..5887e9205d 100644 --- a/t/unit-tests/t-reftable-block.c +++ b/t/unit-tests/t-reftable-block.c @@ -83,8 +83,7 @@ static void t_block_read_write(void) for (i = 0; i < N; i++) { struct block_iter it = BLOCK_ITER_INIT; - strbuf_reset(&want); - strbuf_addstr(&want, recs[i].u.ref.refname); + reftable_record_key(&recs[i], &want); ret = block_iter_seek_key(&it, &br, &want); check_int(ret, ==, 0); From patchwork Wed Aug 21 12:30:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13771357 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (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 8FB3619994D for ; Wed, 21 Aug 2024 12:42:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724244155; cv=none; b=HdIqVHny/WoVHA4Vb2Cz0VobtVjtz5rVYiV1L+eG1JRntjckCNREXiR7PvdypS5bMBSq4O8mOwP5eH3Xy99lYRpaaA9hzIe82fsNDlw85jTQdKxWJAeT607XayBBNdNHuLBdibIlzOwBzpg45b8F2Y9Jym7R00heWClENbPkuwc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724244155; c=relaxed/simple; bh=PsOooERAZjZyHL3/j9gPbuqa1tYlDESA7VjO0KeY37k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rEOK0hC3QO/r8yInRwpOyklLD28FfbychC+DP8WbYXjL5Aig9/x1wPjAnmgvvSWYBUzyAgBbNE5PBa5jnqfIWvr/WgqnPII1KHfDAX0fKabsCVGI+tI6Xy9DGndXOyyl9NURDVwUNJThQFDJjcwF2Pl0CN+dr7KFVScRWc0RWiU= 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=mzHLQoa4; arc=none smtp.client-ip=209.85.216.49 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="mzHLQoa4" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2d3b595c18dso545966a91.0 for ; Wed, 21 Aug 2024 05:42:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724244152; x=1724848952; 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=dMJHWmO4DYLCJNkhQovtJqi+UPTsbUpUjWKqfJ2dsAM=; b=mzHLQoa4yYTDui4y+7PgJUyaFzjYu25Ah2VJ2TobKRHgoRddXl+aHdlrVdRoWwhB6G 93J6waHsPUZUgKvVqQ44gxP2oZ0NJuye8sKxXHFHI7VIa5w3eu8MPFFLjGmxDJFjkJjR 7V+EIcaRJpgeUh6XQO/lXTJTN36xO5DbclBfnTSEnv55UdSjqCoNUh1nhqZ0xVP2YNOL oOaISGkiLl45IxNuZZ92L00XIB6HpTkkUeZzcCsYUViHOuC8McbjPoppzXDHc8/ZbHsu Mp9mY0zHEYoWzKmeSN8jzmCNnVlhHo4C4LL6+68MfG13HPfNZ3KylCmNR+YqtSL6KBJJ n1LQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724244152; x=1724848952; 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=dMJHWmO4DYLCJNkhQovtJqi+UPTsbUpUjWKqfJ2dsAM=; b=n4naJ6PKIbDlRyhJWqD5Xx4BmuZsn2+uQ0uqe47KREGHBuJUBBFHEQReKMjKEp0fzz k1Ba/0aagfVXBRR+Wqy3SsOxwGNrGNHNgoQlg6WZH6GDrlv6M8n7Rq98YFXoYP/DU1V5 ollisD5My2FXAm9A1VP7zuqt9J85e5TyUMcc6+vWF9teE2DH38FYT7s+i8FYlgyqcJmG u6zDHyuH12wXPxTfPbHgA3utdd/e++hBNfIufpdW1pYU6vvBURgHXW51eF0wszVuklEJ l6Po2yrVQHIW86M+QV9jaAJkAHZ0WWAuEXPp2+D3gTCXxkgesM9RmmdeUE7ewoqv5v4Z vovg== X-Gm-Message-State: AOJu0YxB7d+TJ4Km3OhlhtpOsuoEE8HnMoC4NzWBt5nD6amNPvJtIxzT mRYWlQhbbXDIOGIMM92vwuqw8wnKG5vH1+4Iy2Rm73vbOnKDS8Aczy44sUls X-Google-Smtp-Source: AGHT+IHXpcgPfZT9CTt7mPR65Ju6SnltKcRsjxH4zLyg4q4YrkROPOSjwLTjxBfkmivxGwAF9Gnr4A== X-Received: by 2002:a17:90a:70c1:b0:2c8:4250:66a1 with SMTP id 98e67ed59e1d1-2d5e995c991mr3863006a91.3.1724244152415; Wed, 21 Aug 2024 05:42:32 -0700 (PDT) Received: from Ubuntu.. ([27.59.95.0]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2d5ebba8853sm1670963a91.56.2024.08.21.05.42.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 05:42:31 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 06/11] t-reftable-block: use block_iter_reset() instead of block_iter_close() Date: Wed, 21 Aug 2024 18:00:56 +0530 Message-ID: <20240821124150.4463-7-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240821124150.4463-1-chandrapratap3519@gmail.com> References: <20240816175414.5169-1-chandrapratap3519@gmail.com> <20240821124150.4463-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 block_iter_reset() restores a block iterator to its state at the time of initialization without freeing any memory while block_iter_close() deallocates the memory for the iterator. In the current testing setup, a block iterator is allocated and deallocated for every iteration of a loop, which hurts performance. Improve upon this by using block_iter_reset() at the start of each iteration instead. This has the added benifit of testing block_iter_reset(), which currently remains untested. Similarly, remove reftable_record_release() for a reftable record that is still in use. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-block.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/t/unit-tests/t-reftable-block.c b/t/unit-tests/t-reftable-block.c index 5887e9205d..ad3d128ea7 100644 --- a/t/unit-tests/t-reftable-block.c +++ b/t/unit-tests/t-reftable-block.c @@ -78,11 +78,8 @@ static void t_block_read_write(void) j++; } - reftable_record_release(&rec); - block_iter_close(&it); - for (i = 0; i < N; i++) { - struct block_iter it = BLOCK_ITER_INIT; + block_iter_reset(&it); reftable_record_key(&recs[i], &want); ret = block_iter_seek_key(&it, &br, &want); @@ -100,11 +97,10 @@ static void t_block_read_write(void) ret = block_iter_next(&it, &rec); check_int(ret, ==, 0); check(reftable_record_equal(&recs[10 * (i / 10)], &rec, GIT_SHA1_RAWSZ)); - - block_iter_close(&it); } block_reader_release(&br); + block_iter_close(&it); reftable_record_release(&rec); reftable_block_done(&br.block); strbuf_release(&want); From patchwork Wed Aug 21 12:30:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13771358 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 8293D199956 for ; Wed, 21 Aug 2024 12:42:36 +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=1724244157; cv=none; b=U5kAEadVMj77VdtBY0F0ncBThGVhtJAFOWL1yv2eEfocVc6Y7QH6BiTR5Z2IT9nO8Vq9pYzbb7U6vloACS0Hinz5wP6oDrtCKh++yGMvjs6Id7wTryOAgYurgsCnkvZpOKvDdP9oTPK+vnVvBv3T+bI6bmhuBVwqUmtYChWK/wQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724244157; c=relaxed/simple; bh=F6Ll+kebVEWNfVCewmYyA3w1aLfK5yHdCCiWyt+qaQ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kqpHuqrfP1XEDiBqJA2H3CjQndMWcN5c07tPhdZSpoZDiswzs3F+jnSCKcq8hUdcTwoXZNdGyWK7jB3kME6O2o8JlKf6ji3zaZJbdakCd4Ag1osk4WbPamGglxUiddbhSfS0rK353e5yEWA7hs0pa6bv+q/zDNeCG1nnN5JL2e8= 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=R6lZij7c; 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="R6lZij7c" Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-7a264a24ea7so4834380a12.3 for ; Wed, 21 Aug 2024 05:42:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724244155; x=1724848955; 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=Djhsm1ZWS+CvJVfKqGt3b/MT7c/o2mK2WpsPEkOb1sg=; b=R6lZij7cX7bldli4JLg2OS+bA+txRYLh2Bnp2WuozJZ1uGFegg1KSvOBmcjl9ZifJ6 eLUORuC8yrSuyb8DRZqCvMOXtwD8Lwuw3i26/pF5FyI1aaXCxMMtdvPWBTq7aUJjE/fn fV7gVIj3mQ9gYVIyVcmcKc6wR43+TolrTQCmz2A8jwvRD1JDuDYS8dHhqh2xsTDPvDsX a+u+i1TMtPw2OdmWl/3f8W9+KHBLwaAIN27ZkTF4kbUwfTpi46xKkw2KwE9eCx7YtYmv aA/T06mi97uyKifx+FQcX05TqZztCZgWX+nwxQjYadNzU+DIeN0FCx11QvtDr5U8QaNC XAeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724244155; x=1724848955; 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=Djhsm1ZWS+CvJVfKqGt3b/MT7c/o2mK2WpsPEkOb1sg=; b=FmETdFqM1wZJKcQujpRaBAPr9mp+8qgcMIS4DnsJ9hcUmFJsW2ZFPucwweFg4931fH qIPB7XGqgd/Wf4bEnRCUe9zrXWtA9XxvpatkVMSB9215we7waKlgDB4iea1jibs8rQCR 3xi8iTNBcEwipkjRbzeky7C4aKfKY/nsTTJI7XyVEtQct1yvp14RjtUZWvy/AL+4dKsq CzpLDDogIQzn4pvkfUnVRuPTEelPaYbhKzswv1pA2BkHEIIzYkSrbunIuVIhcaIguEM3 NjSf1dElXhRB+GgDJBwBjqFDlSs4zkzswuOIhHZmSvQD0IUrk3AUT4SbUAoYYw19wE+8 rmHw== X-Gm-Message-State: AOJu0YxMGmRH3g2stCzH1DkI7zlC1qT5ecGpeGW1qpuXLn0DPXS7tpQS tngyWJxL06d2ODzGkhHwnfJiKfHhJUaMV1uFuFhREt4pkemRQRXseOSRVanY X-Google-Smtp-Source: AGHT+IH8ydquhJbW2CFO6ljXuDKDb49ZXsBoznKVd4ZOpj+YoSVr1PQ7T/oGUOcFHD4DuJ/OZC/ETA== X-Received: by 2002:a17:90a:8cc:b0:2d3:c31f:c822 with SMTP id 98e67ed59e1d1-2d5e9a1f56emr2404232a91.21.1724244155418; Wed, 21 Aug 2024 05:42:35 -0700 (PDT) Received: from Ubuntu.. ([27.59.95.0]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2d5ebba8853sm1670963a91.56.2024.08.21.05.42.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 05:42:34 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 07/11] t-reftable-block: use xstrfmt() instead of xstrdup() Date: Wed, 21 Aug 2024 18:00:57 +0530 Message-ID: <20240821124150.4463-8-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240821124150.4463-1-chandrapratap3519@gmail.com> References: <20240816175414.5169-1-chandrapratap3519@gmail.com> <20240821124150.4463-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use xstrfmt() to assign a formatted string to a ref record's refname instead of xstrdup(). This helps save the overhead of a local 'char' buffer as well as makes the test more compact. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-block.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/t/unit-tests/t-reftable-block.c b/t/unit-tests/t-reftable-block.c index ad3d128ea7..81484bc646 100644 --- a/t/unit-tests/t-reftable-block.c +++ b/t/unit-tests/t-reftable-block.c @@ -44,10 +44,7 @@ static void t_block_read_write(void) check_int(ret, ==, REFTABLE_API_ERROR); for (i = 0; i < N; i++) { - char name[100]; - snprintf(name, sizeof(name), "branch%02"PRIuMAX, (uintmax_t)i); - - rec.u.ref.refname = xstrdup(name); + rec.u.ref.refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i); rec.u.ref.value_type = REFTABLE_REF_VAL1; memset(rec.u.ref.value.val1, i, GIT_SHA1_RAWSZ); From patchwork Wed Aug 21 12:30:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13771359 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.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 56967188CBC for ; Wed, 21 Aug 2024 12:42:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724244160; cv=none; b=gUFw13oJ1aA0glTswi4H/CyI28QcwVQBDTXkLjPEehGInwZyWnZA9wVS/hRRt07WYMKXTpHeTsXZKxdMapgd4T53A7EpfWWdbOMtiVUJY1nlQQhoH8/gnQK87gItBlUDwS5nZSn+Ii/aIajPKINDbFC9w9HI3ae1CjgChxVVGao= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724244160; c=relaxed/simple; bh=fYVq6x6OTAxVrRyB9SNlLxuuV5rAOds4y2R7OPJDboE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kSK9rzCknMsoyPQ0lNBR5IieHK22frcXPRIJj7Mtv84a5VW6491l9RBUWK/fm227bSDgVGNuMZasYcPYRKASM1YvCAOcw1EqVi1ShJlQKFfTnQJj3xW0ykE87yi+qUyb5bCawvqHWxz3rwb0p6IjhDUHcIV9E8uzFZindjZlyww= 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=MH3cE/nA; arc=none smtp.client-ip=209.85.210.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="MH3cE/nA" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-7141285db14so1239574b3a.1 for ; Wed, 21 Aug 2024 05:42:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724244158; x=1724848958; 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=M1usnlTgK4r1JKqKCnaxdmYmZV0LRBT8lm6vrlKlxjM=; b=MH3cE/nAIVkaGtU9Flk8uGSLPydvwfGFNeqmBVRGFUs+tAZmMenr6kcj3H0y8MgE98 N3I82nPJRtM8ZobZlxUY+y2ArfAYg2Lh/VO8FdAsO/ALmsMl6Pa9EAi4ScD0hePL3Uvc jMvAwtxh6KSwRLsPAwcAx7hVYE6y3tW4GUu5YOYSmFJJeQKu0YpGSF9ioXOq/IaBmIjH OeL224welDTCof7vXH6/bFnzJKOcVBbOvT5/h1HQhIulHd2rnw5r5//Ovox6KeOfMQv2 F6n0W11eR0H/PdyD+Y5qwDSNYxDaIAMkFwClX8IL57aVtP/Aux932hffQIucR8gem3hC utlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724244158; x=1724848958; 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=M1usnlTgK4r1JKqKCnaxdmYmZV0LRBT8lm6vrlKlxjM=; b=Dlc4KzbJqcqOgsHlYOgCyqcTdQqlm7PQhpQJ8ikeU1mP2LctgyBFmz8cd/iimCFENi xOFsmB1sXjw0N9DgO9rf8/jeqVbwb0Zu1CWojnjBlHNfEFCYe0gkp/nvH77aiIx76Ydy e0ICWAsVDdD9Cv7OhPSaWjCpO8tsM4Q78AJUdTirRgXoz4PDJH+oQXGg2d2jwIf1vQX7 8TTfFhNIPWxJhw3BWUSbUDh8BNabtAh64J0WXguuWtjk6tSKGL6TzBgIGT/8alI5YXOS DPUm6N2ykodYcxEN23fYVxWfYx6Ogi9C6vYqpVWahPKMZehRnRuXuoePYa0J3OlNSrmK 9VFQ== X-Gm-Message-State: AOJu0YyqNO30+Do8EajJ9U3xq1SJO/8Re4zeGRHnTpEHpqQrejvusACk l1aVRR037nm39yUoU5Rnh5qogMsmDA+BHnnlNtgQSTn/7Iywe0SG8RphAIj5 X-Google-Smtp-Source: AGHT+IH3dDZvLQyVmtWgOjyHSWJUchmKdBN6AoDnjcwiNTqPOTBAQFsEWo2BXKIEBDa+ac8+TFjtcw== X-Received: by 2002:a05:6a20:9e4e:b0:1c4:b8a1:6d54 with SMTP id adf61e73a8af0-1cad8145eeamr2933582637.36.1724244158183; Wed, 21 Aug 2024 05:42:38 -0700 (PDT) Received: from Ubuntu.. ([27.59.95.0]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2d5ebba8853sm1670963a91.56.2024.08.21.05.42.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 05:42:37 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 08/11] t-reftable-block: remove unnecessary variable 'j' Date: Wed, 21 Aug 2024 18:00:58 +0530 Message-ID: <20240821124150.4463-9-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240821124150.4463-1-chandrapratap3519@gmail.com> References: <20240816175414.5169-1-chandrapratap3519@gmail.com> <20240821124150.4463-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently, there are two variables for array indices, 'i' and 'j'. The variable 'j' is used only once and can be easily replaced with 'i'. Get rid of 'j' and replace its occurence with 'i'. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-block.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/t/unit-tests/t-reftable-block.c b/t/unit-tests/t-reftable-block.c index 81484bc646..6aa86a3edf 100644 --- a/t/unit-tests/t-reftable-block.c +++ b/t/unit-tests/t-reftable-block.c @@ -29,7 +29,6 @@ static void t_block_read_write(void) int ret; struct block_reader br = { 0 }; struct block_iter it = BLOCK_ITER_INIT; - size_t j = 0; struct strbuf want = STRBUF_INIT; REFTABLE_CALLOC_ARRAY(block.data, block_size); @@ -64,15 +63,14 @@ static void t_block_read_write(void) block_iter_seek_start(&it, &br); - while (1) { + for (i = 0; ; i++) { ret = block_iter_next(&it, &rec); check_int(ret, >=, 0); if (ret > 0) { check_int(i, ==, N); break; } - check(reftable_record_equal(&recs[j], &rec, GIT_SHA1_RAWSZ)); - j++; + check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ)); } for (i = 0; i < N; i++) { From patchwork Wed Aug 21 12:30:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13771360 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 2CC9D199FAE for ; Wed, 21 Aug 2024 12:42:41 +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=1724244163; cv=none; b=QqqG8Y0NYpII4IcsKmXKifVbc2lE2TirS8UrJHQLtDpUsuAiAITAhiZpDUF0kef8gpMDEQGvPT9Yn7m5J4aty2aktNeKNQhd+rEFH2ujuyNBppq6d7gqXGW5mQS1r4rLriG80wC0ro9ut2Lq+02tg+MKBX2Vcmjv1dtnAVREHF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724244163; c=relaxed/simple; bh=Hd4wOug/0b1JQdE7wz2KGghHzvolfW+D+YQltMKcWrA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s2VMcU0gAAeHyF/uE/gCKqQSD6jjdPoHzcWp6ybDVAL37+2Hp4diwI768pI83Q66xyl6cu3ZjF+OsAxRRIbZlp31wV6ZBB4Q2n4Tj6KBwYajgBFTYzL9XWiU5PcUdz/tN/2bfJND1MP6rhyOWG583mcrpgKweowZRTGo0/0o8GU= 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=eg4DSkau; 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="eg4DSkau" Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-7c3d9a5e050so4261109a12.2 for ; Wed, 21 Aug 2024 05:42:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724244161; x=1724848961; 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=frzvWvpMMvPReCU9NkAAFFb+E44xKvgtTgqnqaYEuXg=; b=eg4DSkauvFXcT9WsFurm/fFylpJOC89EIpg95ljJnowIHum2+/UvPHO/Tq0Zx7SPgO MRGYfZxPh1QfpFHOL55SfzrbivV3VaNKQeI3YPdHwwWt+BaYYH/sbsMUqaWOynsWMiei hqpri5gJseZdF3KVszBJTZ1VsrEAMDtY2kP+YfPkv45q2dinIiVkvSxyw/DPICgyUjOh wp6j0vNiSp/qucMJ+tlEGYMFAHULMpOmkAsTzvcck7jxnP1DnE89B7Bv9gbNEbv2aOR1 HNy+rbALbFLp0rTI7YzMNsgCucfqNrmTSj5rwO5v9aZNDRnomKsp5xp8tZ/rgI6DtpWa ZzHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724244161; x=1724848961; 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=frzvWvpMMvPReCU9NkAAFFb+E44xKvgtTgqnqaYEuXg=; b=ed9PqR3DX4tdsXNFq7gk5ax850Qut7uoTGesTprjFxu/ARuR6QD59/Xb4xI5ocApdh 70wlE/+6u0STcTMYybizit90RqGiflbwyU4t8u7corlhuVnFaKeNwaicw6lthekQ0x16 7VK2w7QMdy5mBCovw9yHVBLMu0OYqETSy8f/gtH75ePjnqa4Iw11qdJN4HUNdGfxifue pguRwTY6bFq8857viN2E1Tle+SHAnp5R1aLfl2oZ/+WTO6j9PROV5wXkNEIGe32rcSb1 xN5tczuf8DRs57Ipep2WvsL5xFNdJ6TostREssc7oUlkzrz9ATQ9hdhf/tqVESb8UMnv 0yuQ== X-Gm-Message-State: AOJu0YzU9+x9N/vct3zwTDB2duWF3hutZ2wQZ65cRROsPr4NjMC5MAuo gL8qeECV4khckAaaQ8AiJD79Bvd3PCEkmpOf/b9F5IHhQRm6xf7f6ShYY5Xr X-Google-Smtp-Source: AGHT+IEd50VbjaQ5nAdED2oLNeVa5bF+Dxj4RzQnBcMC9t+5usc+hplVk9fqWSnuuppuV+ICzgyVCQ== X-Received: by 2002:a05:6a20:6b9e:b0:1ca:da95:d49b with SMTP id adf61e73a8af0-1cada95d6bfmr1705813637.2.1724244160907; Wed, 21 Aug 2024 05:42:40 -0700 (PDT) Received: from Ubuntu.. ([27.59.95.0]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2d5ebba8853sm1670963a91.56.2024.08.21.05.42.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 05:42:40 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 09/11] t-reftable-block: add tests for log blocks Date: Wed, 21 Aug 2024 18:00:59 +0530 Message-ID: <20240821124150.4463-10-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240821124150.4463-1-chandrapratap3519@gmail.com> References: <20240816175414.5169-1-chandrapratap3519@gmail.com> <20240821124150.4463-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In the current testing setup, block operations are only exercised for ref blocks. Add another test that exercises these operations for log blocks as well. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-block.c | 93 ++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 2 deletions(-) diff --git a/t/unit-tests/t-reftable-block.c b/t/unit-tests/t-reftable-block.c index 6aa86a3edf..4c4fb39ab4 100644 --- a/t/unit-tests/t-reftable-block.c +++ b/t/unit-tests/t-reftable-block.c @@ -12,7 +12,7 @@ license that can be found in the LICENSE file or at #include "reftable/constants.h" #include "reftable/reftable-error.h" -static void t_block_read_write(void) +static void t_ref_block_read_write(void) { const int header_off = 21; /* random */ struct reftable_record recs[30]; @@ -103,9 +103,98 @@ static void t_block_read_write(void) reftable_record_release(&recs[i]); } +static void t_log_block_read_write(void) +{ + const int header_off = 21; + struct reftable_record recs[30]; + const size_t N = ARRAY_SIZE(recs); + const size_t block_size = 2048; + struct reftable_block block = { 0 }; + struct block_writer bw = { + .last_key = STRBUF_INIT, + }; + struct reftable_record rec = { + .type = BLOCK_TYPE_LOG, + }; + size_t i = 0; + int ret; + struct block_reader br = { 0 }; + struct block_iter it = BLOCK_ITER_INIT; + struct strbuf want = STRBUF_INIT, buf = STRBUF_INIT; + + REFTABLE_CALLOC_ARRAY(block.data, block_size); + block.len = block_size; + block_source_from_strbuf(&block.source ,&buf); + block_writer_init(&bw, BLOCK_TYPE_LOG, block.data, block_size, + header_off, hash_size(GIT_SHA1_FORMAT_ID)); + + for (i = 0; i < N; i++) { + rec.u.log.refname = xstrfmt("branch%02"PRIuMAX , (uintmax_t)i); + rec.u.log.update_index = i; + rec.u.log.value_type = REFTABLE_LOG_UPDATE; + + recs[i] = rec; + ret = block_writer_add(&bw, &rec); + rec.u.log.refname = NULL; + rec.u.log.value_type = REFTABLE_LOG_DELETION; + check_int(ret, ==, 0); + } + + ret = block_writer_finish(&bw); + check_int(ret, >, 0); + + block_writer_release(&bw); + + block_reader_init(&br, &block, header_off, block_size, GIT_SHA1_RAWSZ); + + block_iter_seek_start(&it, &br); + + for (i = 0; ; i++) { + ret = block_iter_next(&it, &rec); + check_int(ret, >=, 0); + if (ret > 0) { + check_int(i, ==, N); + break; + } + check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ)); + } + + for (i = 0; i < N; i++) { + block_iter_reset(&it); + strbuf_reset(&want); + strbuf_addstr(&want, recs[i].u.log.refname); + + ret = block_iter_seek_key(&it, &br, &want); + check_int(ret, ==, 0); + + ret = block_iter_next(&it, &rec); + check_int(ret, ==, 0); + + check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ)); + + want.len--; + ret = block_iter_seek_key(&it, &br, &want); + check_int(ret, ==, 0); + + ret = block_iter_next(&it, &rec); + check_int(ret, ==, 0); + check(reftable_record_equal(&recs[10 * (i / 10)], &rec, GIT_SHA1_RAWSZ)); + } + + block_reader_release(&br); + block_iter_close(&it); + reftable_record_release(&rec); + reftable_block_done(&br.block); + strbuf_release(&want); + strbuf_release(&buf); + for (i = 0; i < N; i++) + reftable_record_release(&recs[i]); +} + int cmd_main(int argc, const char *argv[]) { - TEST(t_block_read_write(), "read-write operations on blocks work"); + TEST(t_log_block_read_write(), "read-write operations on log blocks work"); + TEST(t_ref_block_read_write(), "read-write operations on ref blocks work"); return test_done(); } From patchwork Wed Aug 21 12:31:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13771361 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 23E75192586 for ; Wed, 21 Aug 2024 12:42:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724244166; cv=none; b=hS0iCFq5LU3S/yZ/sbYkz857ejm61kMODucbP3C+8GttKPekozgxwbjc78wFdE9sgEs2QM/bungcNi+k/4zTjY7fvLels2YJh5K0Y0bhOXB9Wc/KRTTYhb3dePW3rxEUsfqUYeTfLzI1tXxwsBmcbWDgtlPM25VWbmXBOx+Y6KA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724244166; c=relaxed/simple; bh=iYKk8okwqT1ZkmPxBCL3Wet376IZ225JAdtS2YmzSeM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Fk0g7OhymdnomFaNO1teMVLqwRij9m1TVnChdiLJOxySWQOpfzKp0Bm8MGKkhy8tSuJ71K2B5PG5hR5kAtvZ9PqojKLCurNFE+1l6gPMJBVFKlIN0JQNBamd1KhdmZQFkM3QDIwYRIxBlDOXwYq5V5UL+OCw//TrryMIqAgRdxM= 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=XhphyUen; arc=none smtp.client-ip=209.85.216.53 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="XhphyUen" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-2d5f5d8cc01so273854a91.0 for ; Wed, 21 Aug 2024 05:42:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724244164; x=1724848964; 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=+vu4GWyumjCarjjyBZsK9jums+9obFUPQeiyxHTI7TI=; b=XhphyUenCLULlYI8PZhYmgi99KQ94VAm9OQhz+Y8yMLEHARMBrkS0qWLyB6e0RGH5W MPjKDjYpsK5B5kTO7vkTKi8a01uON5WC4xQy9BNpa7E6MGdK+bwfrKE6xkBs+E0ktPWM BMFBqnNe4OwaPaBLkJLdGpf/wAAqXiVSNF/BVP9Cc6oOBwHz0OYYcfFddgoy7sAJBjmL JK8k0h1msoBaF5Gj9HhgNFWXBdFTivx+E82347BxJq28YvMGamQe9dQ8AQOxfxWo0yGH iXU8X6GS2RhTiwLFQO1uaxA9Ns6JINCmf3vbCN9Mp5abnc4wvNg5tChXA0bnZ+kTMPwY JlaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724244164; x=1724848964; 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=+vu4GWyumjCarjjyBZsK9jums+9obFUPQeiyxHTI7TI=; b=KnwELscy6B4wpIFDM1W9dmgkOGhhJAov5aVzoyjxjtVGFASEPG37ebI7P8V/+W7oU9 Q/BC9chL6pXKiLNnnXSOF9iObtDxaPmZMBCgKsPx2UsFF73yn19mV7NzwufHoLz/ZDTi n+7GI+ds+MLM57mFEzd8Z65bBtrXipgrJQ/PTrAcZrQnqVMSsauQNrikNxrRcCqasR7Q XgoTRJkXuqNM5IKZ1ZaQe5P+M1ROfw3NfbHbX4jYE3QFa5tHDQsMynw44eg6E+25DNF4 GkxKJIhY26fX+H+lkVcAmOVz9ZMZ9f+DW2E5d7+npg0HnWVEFjBD7qAqOxJeSi2iW5fX pryg== X-Gm-Message-State: AOJu0YxSwxYdluAx5JCeKXrIaBu59tjsEAjEuKb7uTsuC/8z6+kqPyW0 ii9OQ2DcfbHcyOCHoOVQtnUXXZO5UVLJ3Kj1XfXV/npxNTHbMd3yB1LxufBJ X-Google-Smtp-Source: AGHT+IGT24ch0PpBUCqtiTNeC3faUIDLHALK6qQh/yT1EWmKSJ2mvJR+t1DYx4DwhMRH4+AyfGnmrg== X-Received: by 2002:a17:90a:70c1:b0:2c8:4250:66a1 with SMTP id 98e67ed59e1d1-2d5e995c991mr3863788a91.3.1724244163941; Wed, 21 Aug 2024 05:42:43 -0700 (PDT) Received: from Ubuntu.. ([27.59.95.0]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2d5ebba8853sm1670963a91.56.2024.08.21.05.42.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 05:42:43 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 10/11] t-reftable-block: add tests for obj blocks Date: Wed, 21 Aug 2024 18:01:00 +0530 Message-ID: <20240821124150.4463-11-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240821124150.4463-1-chandrapratap3519@gmail.com> References: <20240816175414.5169-1-chandrapratap3519@gmail.com> <20240821124150.4463-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In the current testing setup, block operations are left unexercised for obj blocks. Add a test that exercises these operations for obj blocks. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-block.c | 82 +++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/t/unit-tests/t-reftable-block.c b/t/unit-tests/t-reftable-block.c index 4c4fb39ab4..beb2d6f81b 100644 --- a/t/unit-tests/t-reftable-block.c +++ b/t/unit-tests/t-reftable-block.c @@ -191,9 +191,91 @@ static void t_log_block_read_write(void) reftable_record_release(&recs[i]); } +static void t_obj_block_read_write(void) +{ + const int header_off = 21; + struct reftable_record recs[30]; + const size_t N = ARRAY_SIZE(recs); + const size_t block_size = 1024; + struct reftable_block block = { 0 }; + struct block_writer bw = { + .last_key = STRBUF_INIT, + }; + struct reftable_record rec = { + .type = BLOCK_TYPE_OBJ, + }; + size_t i = 0; + int ret; + struct block_reader br = { 0 }; + struct block_iter it = BLOCK_ITER_INIT; + struct strbuf want = STRBUF_INIT, buf = STRBUF_INIT; + + REFTABLE_CALLOC_ARRAY(block.data, block_size); + block.len = block_size; + block_source_from_strbuf(&block.source, &buf); + block_writer_init(&bw, BLOCK_TYPE_OBJ, block.data, block_size, + header_off, hash_size(GIT_SHA1_FORMAT_ID)); + + for (i = 0; i < N; i++) { + uint8_t bytes[] = { i, i + 1, i + 2, i + 3, i + 5 }, *allocated; + DUP_ARRAY(allocated, bytes, ARRAY_SIZE(bytes)); + + rec.u.obj.hash_prefix = allocated; + rec.u.obj.hash_prefix_len = 5; + + recs[i] = rec; + ret = block_writer_add(&bw, &rec); + rec.u.obj.hash_prefix = NULL; + rec.u.obj.hash_prefix_len = 0; + check_int(ret, ==, 0); + } + + ret = block_writer_finish(&bw); + check_int(ret, >, 0); + + block_writer_release(&bw); + + block_reader_init(&br, &block, header_off, block_size, GIT_SHA1_RAWSZ); + + block_iter_seek_start(&it, &br); + + for (i = 0; ; i++) { + ret = block_iter_next(&it, &rec); + check_int(ret, >=, 0); + if (ret > 0) { + check_int(i, ==, N); + break; + } + check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ)); + } + + for (i = 0; i < N; i++) { + block_iter_reset(&it); + reftable_record_key(&recs[i], &want); + + ret = block_iter_seek_key(&it, &br, &want); + check_int(ret, ==, 0); + + ret = block_iter_next(&it, &rec); + check_int(ret, ==, 0); + + check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ)); + } + + block_reader_release(&br); + block_iter_close(&it); + reftable_record_release(&rec); + reftable_block_done(&br.block); + strbuf_release(&want); + strbuf_release(&buf); + for (i = 0; i < N; i++) + reftable_record_release(&recs[i]); +} + int cmd_main(int argc, const char *argv[]) { TEST(t_log_block_read_write(), "read-write operations on log blocks work"); + TEST(t_obj_block_read_write(), "read-write operations on obj blocks work"); TEST(t_ref_block_read_write(), "read-write operations on ref blocks work"); return test_done(); From patchwork Wed Aug 21 12:31: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: 13771362 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (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 D94DF199FC3 for ; Wed, 21 Aug 2024 12:42:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724244169; cv=none; b=lXQE6ZuHrjaNGiP5X5JTAvKIVLJE+pNxiTtGsHQ7JKgEUf0Vh+ferirB/0TBfNp+yqMhg0x7I8cBR8lLRYtUjZG3lUfYU6DeaG4gjI6r+1LY7bS72/VPHEfNkan/Wfukc9lQ9LD6FvdygLfPL3qb9nUO0H5WAcb0W0Hmv4tVh4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724244169; c=relaxed/simple; bh=wJKV2tdiOT/dOv8NgoPzyKm7m3SyNM9m5l5q7KkpsKM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AvXpPmgBhxWiwOG3EeJVw/qtq1pOipQyzgh51UOWRiCydA/2Pr+O2+/0xq6poGyyndeKQCM2sS5N1V3IIVvdwtCAfHHO1WwnyKJcp8Jmsus0/XpqixQwhVcHfO+EKnopcJMsSKZI0wCEGGCF1GP2uVtyyMzGqd8063rvA5JQbTY= 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=ig4dx189; arc=none smtp.client-ip=209.85.215.169 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="ig4dx189" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-7aa7703cf08so4789105a12.2 for ; Wed, 21 Aug 2024 05:42:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724244167; x=1724848967; 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=lA2MIQWXsrevxhhnoP/S3q0wxA4C/2w9mZem0FNtT4s=; b=ig4dx189YnTfZVY1fWADxEo+8b9kcikNzpvsHzMDWkMStUXNbbEt+JmLKVOoEggb7K rtvj1y1Ac0I9vJ4qqVYPCIuMjyHCtCKu4Ppgl5q4lQzsre3Zhdpfr6yzAjGY01btZ3px T862yXZ0wTbGXaJJsXQZXB/Y7UQC9RfhT25SsBJrg/nu2SJgf/0Q+KnrgH7LLcdLfCx1 sRPL4qN7LrKsV9prkTgNCWHPZXgCxzYbqmSu3PVGvZlEVEvAA/ay8K/iDd8dLNwVSutR LCyuRN8NQLGT2XhwPbuyzugpq0fTWnOwoMI4U99QbHOr52eW+ft5omm0xSn2PLJFqLJq JTkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724244167; x=1724848967; 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=lA2MIQWXsrevxhhnoP/S3q0wxA4C/2w9mZem0FNtT4s=; b=QxHrMA7uxUUZD7Ynhlp7clgBsB1CaooohmK5tnfpR3ak6rry70nqrpvUKfjsSYTX9u qCtEKgbbgyNXL3xxzE5H+1oQEcr0ERJjZroOrLlyx8WYQsmUr+yED+q5uCZoMc4bd2RP VXGgHpGKTBF5K4/qSKn81gs5a5veXypfKZ4KbkGdm3kmL9pzIcLPewi6Yzx4NfzG98E6 fnxs5uCfWB7j2Xr93tSJ6Z6JGsysM9h7eppn9jNTOXQC9IEmvEFT10/DdZ7HIOKbE+79 RsHK3fmucawk4ge/J3xE8sxEvGdLUwEjbAgjD2iWC8UBHrO8lIRCsC5CJTIrQVC8dicW E3BA== X-Gm-Message-State: AOJu0YwSu5tTqkJwZAgd7jR+JQoP8U8Ki0qvsk9+nSgktwkUioeUQBmO tJzCwmYuvp5j/FuilZwtEBj+gqxu5I9RCGSW+soRKIryZFG63RjvvNDTLpq7 X-Google-Smtp-Source: AGHT+IF9np0YEMPaOouSIqgp2OjrqlAMsFITexRWT5lY1Sb+z3iTiSKqXYVkAppOd5xyIrkJbPaNUg== X-Received: by 2002:a05:6a21:920b:b0:1c6:fbc8:670d with SMTP id adf61e73a8af0-1cada148a32mr2563704637.43.1724244166758; Wed, 21 Aug 2024 05:42:46 -0700 (PDT) Received: from Ubuntu.. ([27.59.95.0]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2d5ebba8853sm1670963a91.56.2024.08.21.05.42.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 05:42:46 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 11/11] t-reftable-block: add tests for index blocks Date: Wed, 21 Aug 2024 18:01:01 +0530 Message-ID: <20240821124150.4463-12-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240821124150.4463-1-chandrapratap3519@gmail.com> References: <20240816175414.5169-1-chandrapratap3519@gmail.com> <20240821124150.4463-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In the current testing setup, block operations are left unexercised for index blocks. Add a test that exercises these operations for index blocks. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-block.c | 88 +++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/t/unit-tests/t-reftable-block.c b/t/unit-tests/t-reftable-block.c index beb2d6f81b..582a8e6036 100644 --- a/t/unit-tests/t-reftable-block.c +++ b/t/unit-tests/t-reftable-block.c @@ -272,8 +272,96 @@ static void t_obj_block_read_write(void) reftable_record_release(&recs[i]); } +static void t_index_block_read_write(void) +{ + const int header_off = 21; + struct reftable_record recs[30]; + const size_t N = ARRAY_SIZE(recs); + const size_t block_size = 1024; + struct reftable_block block = { 0 }; + struct block_writer bw = { + .last_key = STRBUF_INIT, + }; + struct reftable_record rec = { + .type = BLOCK_TYPE_INDEX, + .u.idx.last_key = STRBUF_INIT, + }; + size_t i = 0; + int ret; + struct block_reader br = { 0 }; + struct block_iter it = BLOCK_ITER_INIT; + struct strbuf want = STRBUF_INIT, buf = STRBUF_INIT; + + REFTABLE_CALLOC_ARRAY(block.data, block_size); + block.len = block_size; + block_source_from_strbuf(&block.source, &buf); + block_writer_init(&bw, BLOCK_TYPE_INDEX, block.data, block_size, + header_off, hash_size(GIT_SHA1_FORMAT_ID)); + + for (i = 0; i < N; i++) { + strbuf_init(&recs[i].u.idx.last_key, 9); + + recs[i].type = BLOCK_TYPE_INDEX; + strbuf_addf(&recs[i].u.idx.last_key, "branch%02"PRIuMAX, (uintmax_t)i); + recs[i].u.idx.offset = i; + + ret = block_writer_add(&bw, &recs[i]); + check_int(ret, ==, 0); + } + + ret = block_writer_finish(&bw); + check_int(ret, >, 0); + + block_writer_release(&bw); + + block_reader_init(&br, &block, header_off, block_size, GIT_SHA1_RAWSZ); + + block_iter_seek_start(&it, &br); + + for (i = 0; ; i++) { + ret = block_iter_next(&it, &rec); + check_int(ret, >=, 0); + if (ret > 0) { + check_int(i, ==, N); + break; + } + check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ)); + } + + for (i = 0; i < N; i++) { + block_iter_reset(&it); + reftable_record_key(&recs[i], &want); + + ret = block_iter_seek_key(&it, &br, &want); + check_int(ret, ==, 0); + + ret = block_iter_next(&it, &rec); + check_int(ret, ==, 0); + + check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ)); + + want.len--; + ret = block_iter_seek_key(&it, &br, &want); + check_int(ret, ==, 0); + + ret = block_iter_next(&it, &rec); + check_int(ret, ==, 0); + check(reftable_record_equal(&recs[10 * (i / 10)], &rec, GIT_SHA1_RAWSZ)); + } + + block_reader_release(&br); + block_iter_close(&it); + reftable_record_release(&rec); + reftable_block_done(&br.block); + strbuf_release(&want); + strbuf_release(&buf); + for (i = 0; i < N; i++) + reftable_record_release(&recs[i]); +} + int cmd_main(int argc, const char *argv[]) { + TEST(t_index_block_read_write(), "read-write operations on index blocks work"); TEST(t_log_block_read_write(), "read-write operations on log blocks work"); TEST(t_obj_block_read_write(), "read-write operations on obj blocks work"); TEST(t_ref_block_read_write(), "read-write operations on ref blocks work");