From patchwork Fri Aug 16 17:25:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13766712 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.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 8C4DF1C3F25 for ; Fri, 16 Aug 2024 17:54:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723830898; cv=none; b=Ll1+PNHmWkyZdMJT2jKruSgabbcma1E+X5oqTJe3s0Udnr2mFbMoxCNAyxm4a18w/+DC1zk6v9gmqVy6kwcdOZ18MN32CFabXRt76I/lpon716inNcyYg4zASIzdrc6y3SKNLG8jAZcs9p038G+amSoHonlAcvTUJamKgOEEXY8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723830898; c=relaxed/simple; bh=agZnrMOtyNjNzuJqUc7XskvIpJQwL7dokPxm5FKsbaU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nhUbDC8eGSk+wgi/+EqA0JqeYW1O5HEmqeD2Hp5DTVvDu/M+4w5VS7OMjOJeb+Mufqs/AFH0sc3CLiR7TDtDhVCwyvcA58siOnul5AfVOhkWBeIoZNNfZQSlZCW+FnhLijaNZCISNxjeu0xfa8bCSX+IL2AKHF7lXkttEamfeeI= 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=mO7UH4Fu; arc=none smtp.client-ip=209.85.215.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="mO7UH4Fu" Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-7b594936e9bso1562717a12.1 for ; Fri, 16 Aug 2024 10:54:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723830895; x=1724435695; 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=mO7UH4FuXZzd2BQVXpT1KVyx24blX/YPTO7vd2oe+xC2CtYQCl7t/raTMIGMozT6W7 riINcXAti42gej5BNBuCySdNJ4oKH1XYLchLZAmP5XiOHG8Jjok1d9KQJlAi+aU0BNbm KyAcw4lPQDTQ7obnG/kF3P+SmqMOj9jxB4/b975Ghwq66oTPaCzkv+9dqOAfuyzMKoCg U0EcZ5Zzu0dRa+pJNB2SB85GfsrKPpC6pNnzayXeU/pvEunbMDmbnJSNWq0k0mgSA6ww k2DGngXMpQ5h3roMVYGnrauQTfn6FpghGG+5IrkyzGoG50Xo6Q/QP0LmgK4LhJ2TFMcH 2nEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723830895; x=1724435695; 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=kFDVcbQyatFlI9nWhjJCd1RSCpftAuC7Svw9FUKIcHTT7mGLLXafD61q2eSbSVvnLC UtscnNBJpphaNqjTkyUR+fu4iFAd06UdjZVx0j+ApmBSgC7meR9xW4S3jzPQ1VG6OJt5 jDX2jqdcsVJpO8j5Si8Cd31u5S/Uf9kIXsRi1lNBvRUlA7YfAsaZ+n+TIffYTX3sP4HC ZATyQzjeoXLyYOmPXqDQ5pg5R5vYy1QS7GNjD5q2yFbgcLW5kZYvCtk+xX2D3RZVLifS YjOZzcpY3j2yKS4OByLcLOZm6ie6E5H4zqEakHWi+f9/vcsC5j8zET7rcbAetwA+keLC bhtw== X-Gm-Message-State: AOJu0YxkZPdX2qmo3r7x220h695DQe2caXrhwTM1Y5crE/YZgbnK+yQg mPZ5aVqGouP1HxfIPPDrfL22aB/LpeVEIlsUu+FyRqciV7U9Ulc0Wqfk5Q== X-Google-Smtp-Source: AGHT+IGnmFnR0UPv8IY1+icuWOF8SeHRojsIXEDV+7YBWFFXvNIVqRjSkiGU39YJBXT5GyI/31GJhg== X-Received: by 2002:a05:6a20:ac43:b0:1c0:e9dd:1197 with SMTP id adf61e73a8af0-1caa3625859mr467054637.22.1723830895295; Fri, 16 Aug 2024 10:54:55 -0700 (PDT) Received: from Ubuntu.. ([117.99.60.209]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7127af1e907sm2985600b3a.173.2024.08.16.10.54.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 10:54:54 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v2 01/11] t: move reftable/block_test.c to the unit testing framework Date: Fri, 16 Aug 2024 22:55:24 +0530 Message-ID: <20240816175414.5169-2-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240816175414.5169-1-chandrapratap3519@gmail.com> References: <20240814121122.4642-1-chandrapratap3519@gmail.com> <20240816175414.5169-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 Fri Aug 16 17:25:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13766713 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (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 51F211C5790 for ; Fri, 16 Aug 2024 17:54:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723830900; cv=none; b=N2CqINZl5uB85bFQTHh/Wv5n0ugC5toVn9uI5YVEDyB9vlx4RWf2qYI4pLhuTeSQFd4pdcSMFplIewCYp3FDnBjpIv5JPveSkaqk09/3aU0kBAd9GuEswCTRbRE30vsozRck9EW/MCtiaHgRkFuWLf4hIY2GC6BIo/wPthWI3aQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723830900; c=relaxed/simple; bh=61cKOBkwMaN3Pb6Bz8j2jjKcVO5mWqMNJZdQ2PWxCm8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EO7UiDe267GijQUB1bcF0aVFrsswKRs6kJEqunH8iFIFKTN+jt1AfYjJMYhY1hxYb0DPshvieBha7ACHTdW3j45D9BiCUv9yqhOPTjS1HdIbDz73vxdmi6NsxQuLV8OcnKpzzqX+9gtNx4TwLk03QYdl0uEMh/5UHrICb/eFXrA= 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=FoOxM3Y4; arc=none smtp.client-ip=209.85.210.172 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="FoOxM3Y4" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-70d2b921c48so1786934b3a.1 for ; Fri, 16 Aug 2024 10:54:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723830898; x=1724435698; 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=FoOxM3Y4lm4Xm8V1ralixICR06SxUTf9VtXSLy+FTbp2LYePG0m4jjV265qpiwieI8 PIPREsXOhMgvGbE1fTA1F6mCjN6HUURXIcfIkDQrjUIyKUoQD5UD46QibMBFivlNELXw zifhgs7M8i94mtcACQapUof2jtSeAIJBMj3MDJMhNdyhv66Okqhmh4Woc3l3n896IijX CTAkMHZAwS7FgcEz20oYcN+RCCp6vAbNoDZRpPKtoWXJFAJLXt8Ge48GT8JGyRts8Km/ uGsKx8faatMrO2iToBTjUgzU28mFkgDdawRjtEtEyurVMX5gYnVLy4uYX4JB4qq9Zu26 zm2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723830898; x=1724435698; 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=fVAU43SdMbJkzJ2oVeGA2DSUZe9e85bNTEzI9v6feEFmyEKWFTjfOOXEPfiw+XCmYS vFHvqLPZjxpc70iw2RtZAbHULId9+6Bl92/2FVHd7lzs0hCe8Y0OTWIlmSUwQP5XsxhP bCW1e9TAxTUBFTUh43v2j9VTXUxizjkQYE9EwiBItEuH2IXE7jx0/gDDI/mTwEB42EzN gCdL7B2A0abO6VrkYnaGBC6DPuuO8zwnv/atm4OKboHxbPCoi2x5/+Z056fUDLMRPYgI y/f/UXPXYnWDbNkhL5bz0+TrpwCYW6CaUO+umr7zFMP2UJ4YueUesvBm22Mh4HO2Cxm0 9UnA== X-Gm-Message-State: AOJu0YyQcsMLjkj7wKyrwLuXufLNb7jBwBE2ZczODlehexFze6mYMrqp 2//sC7ZaGiO/HPalfZjJTAwtv3QUMVL4yOXu03i6/TsRiTYbeg/7MKI8kg== X-Google-Smtp-Source: AGHT+IEpxzrRrrhRxgqy5ZiPcAN2Iwu7R/cEmHWycBxTe/GRn0Rt/usR4Lyiw12GtTis1vkp9xvk6w== X-Received: by 2002:a05:6a00:6f06:b0:710:66ca:5e83 with SMTP id d2e1a72fcca58-713c4dbec26mr3970667b3a.5.1723830898025; Fri, 16 Aug 2024 10:54:58 -0700 (PDT) Received: from Ubuntu.. ([117.99.60.209]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7127af1e907sm2985600b3a.173.2024.08.16.10.54.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 10:54:57 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v2 02/11] t: harmonize t-reftable-block.c with coding guidelines Date: Fri, 16 Aug 2024 22:55:25 +0530 Message-ID: <20240816175414.5169-3-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240816175414.5169-1-chandrapratap3519@gmail.com> References: <20240814121122.4642-1-chandrapratap3519@gmail.com> <20240816175414.5169-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 Fri Aug 16 17:25:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13766714 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (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 EA8C61C3780 for ; Fri, 16 Aug 2024 17:55:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723830903; cv=none; b=M/+5AxXqinUV3pZhAIoQJfoeqqFy56MWaXEUvJN3v/S3PjrqZmZAKbaA4mhVNNtv1LWlQWU42u27+8fLXqqNTjxZeMrjZUI22j2dZNTwJfXgId2UKHP68RwNEB0831zeoKYTUKQNbiB591Izmvsqv4UaeF82CB7kZwgcxJkWoRk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723830903; c=relaxed/simple; bh=kuNMT+Mz/B48UOGZINSIcyE+FXrNDfjXrncrh0vdxZI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I4DBrmt4TWahB4DrahvVJsK2Z7c4KTPsQ1FVJskHjEDkCDeGBv0fR5+anH17M2bcGCz/2TgfEXgKRetSyUjMAuyETMcKLwoUzCQpm5iCQ2qSqPjECkeWgvterbUIgx3vc+nsPHrV/D1GW5rzA8uRMegtHbkxC87ZhA+WKmprgNM= 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=hhNsA7xg; arc=none smtp.client-ip=209.85.215.172 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="hhNsA7xg" Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-7c6b4222fe3so1433961a12.3 for ; Fri, 16 Aug 2024 10:55:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723830901; x=1724435701; 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=hhNsA7xgONv7oyiqVHc2hTMr4EZd+alqFN3ymldFJixXDEtRzmrO7bpozC/6BRP1oH lCuh3AbXf1dMeCmOBXzgWPX+e2pLkXws5/YM93qtOiczY1dHQIdmRBw5PHX/if94EMx1 jRgnrXWDzjGHaahw0E7ijXjJR9odQ/+aon2rXl79pvNLGSE/ZuWd8nIVZhcyAheA2iKm H49tlVyaR1vXeRSP5EwmPJTQWQeV9tq/80WEgKWx++ugw946T6qi3vy6a5/v86zBC4uj KxokfoGbXD7XSy+XmGDeul62BIO4md3VmjBCf3msBnlZ76HHwrwBMkFYtWhhkio1XTwN YKyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723830901; x=1724435701; 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=fG4NoYJdiAr0ErZo5ZJqtga7/oqCTITpRpFB+dWV3ukdS09+ssb7MpWtoJVrC7rvZq HkLRqFBB0mTiZ+8imYOAjhqdANtoizDLe6Pzo5iV8V5kD9LQaH+Xf6OY+klbg89ZsnWI cOJLbrEmQRtxZPTyG/Pz081k9ghX6AvYJguOZ+QoJcwA6xo/V2tC21hDUiYEN1vrvBZ8 2yX34seLp9ZQLmXd/LmG3MPN9UAkDtCt0IMCzpdMxJ2o3OpA/MKuKm1UKPKTW8yxSiXQ 4Dez+s1A4okR7vzo4BCCLKfqR1L0Ev1fU7CjmHObGo4gfujwnxo+7dAh9hpZ/RQQwFh+ qlZA== X-Gm-Message-State: AOJu0YxUA+deE/C6Ie2GYX+h8TZDHrnKQ7Nwb2E1hiJ6cUK4etO3O6MO UkNn5KtwvU5+WEknhjscO9f+jp+vjM8XZ6blG2LRnPfwzbTYcBKU0HM+Vw== X-Google-Smtp-Source: AGHT+IGPjRnbo04QVvnz+FbzB9gYfEm+DkmrsyIjL2CVldU96g6ej4kpzx8Bz//vJ7x701ZmcyUTiA== X-Received: by 2002:a05:6a20:6f08:b0:1c2:9070:90ce with SMTP id adf61e73a8af0-1c905025edfmr4625568637.43.1723830900819; Fri, 16 Aug 2024 10:55:00 -0700 (PDT) Received: from Ubuntu.. ([117.99.60.209]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7127af1e907sm2985600b3a.173.2024.08.16.10.54.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 10:55:00 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v2 03/11] t-reftable-block: release used block reader Date: Fri, 16 Aug 2024 22:55:26 +0530 Message-ID: <20240816175414.5169-4-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240816175414.5169-1-chandrapratap3519@gmail.com> References: <20240814121122.4642-1-chandrapratap3519@gmail.com> <20240816175414.5169-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 Fri Aug 16 17:25:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13766715 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (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 CCE2E1C3780 for ; Fri, 16 Aug 2024 17:55:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723830906; cv=none; b=Dt5VfY7FRBWIT3TmZKlthfKJ9JUXkFxFfuuMChBBKvpQJDyuJnPqAzawIR3znWatVtftlH/woFTPLf0RadQdC8WWSXXLTZOWV5SSdA1eZ6UnQ+PlaDnUw0GSHp4wzKSZ8JhBs8sa3e1MXeL+nJH72rjWcceRHrQipUenXyfgsn0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723830906; c=relaxed/simple; bh=AFFKBAJ5Q++FqG+OBgl0aHym6OgHA2PnBKd6KKwGxZg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hEfV7CbhlekXwfbXFx6DK60I9jrTgumqjdtGKbO8gjkW0hxu+BihJl7lDABCR7RRLGANa2kyx8m78wvsD2Vna8MzpGJTi/VHu8AtLXMgWRnxT1hFHV5q3RIKuUxyFOa+HXnw1G56oZLsoFBB55rKXv3BTcX4luDJjiGC9PEKbj8= 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=UyGTCxcI; arc=none smtp.client-ip=209.85.215.182 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="UyGTCxcI" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-7a1843b4cdbso1704411a12.2 for ; Fri, 16 Aug 2024 10:55:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723830904; x=1724435704; 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=UyGTCxcIjVu2QUk6pFI2olWsRtpD0JlKAOy/L8UlgTiqOODKC6QxE5+2sgZA9JDa/Y hrMrHMl+sWb2raxfuOWhbzaxY8PijTF8h0OOvnULYqEDB8o467H+RAS7lNk9F77djz2L m3thT5GrX2i8MuellQPOnJUl0ENE1isn/kricgjbUCqLOiBdfkzl9/E+HjHrq0mhdb+d Ca7fKu3IWCDflI1xVGL+pzuFd2XGhEjUQY2jrcW8CFrtFTNvKYeT576eTZ6duNQwO9qH M0ht4sS1XvFxi9rtn7mGdvUxLieHlrWk6pxsdUlQFNFx/GESCFWq9XWKq8M3uFAaiQL0 NIqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723830904; x=1724435704; 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=ZYUzbT19g9X01ZVZ8Phx0Yak+MIJqRCARHxtUr199S7ADqJJvbj+amPYj5ESWemf3s RZ1ktqAQZKJ3lB1j31TgXcvKKXVdrpRrcPOuZ3B6AZW45orki2ZX2Sxa8VQaYsfGP7T4 CRp/p/i5YpWUBPvyTRXGTbKmmZ1WnHO6lY+a7BbnI7jyV0mubXNRk6J2O8gB3TMUJed/ X6s4e4BJyinFSf93sJCrW81+vsAF4+dVXVIfYDBu+w0uDYlQFOKjyNaYMHxhsi8vRE+e cqHmpUf4Hrt7LXX1w2c4zGlK1+w91ID6CJADXfd3weY1rV+Bb8caG7Gp5og8/pot8FOh h6xw== X-Gm-Message-State: AOJu0Ywgmml1nZmfmvQ+DGflEIqf587JaUu/cgxd5dZsa86G5fQUlTmn gqDo6qkvH1fh/Frlb4QXdhXxVez+F/IqLxdevh0IJmC6ZcgC5REgxOxnmQ== X-Google-Smtp-Source: AGHT+IF+1/j6kKKCfKuYNk/k6x/DwHv3teVREp3JFrA+tfk5tdw3UTJZiY+BBi+H1KOI6eOGcidWIw== X-Received: by 2002:a05:6a20:1b14:b0:1ca:a3aa:e5d9 with SMTP id adf61e73a8af0-1caa3aae5ffmr308362637.0.1723830903573; Fri, 16 Aug 2024 10:55:03 -0700 (PDT) Received: from Ubuntu.. ([117.99.60.209]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7127af1e907sm2985600b3a.173.2024.08.16.10.55.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 10:55:03 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v2 04/11] t-reftable-block: use reftable_record_equal() instead of check_str() Date: Fri, 16 Aug 2024 22:55:27 +0530 Message-ID: <20240816175414.5169-5-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240816175414.5169-1-chandrapratap3519@gmail.com> References: <20240814121122.4642-1-chandrapratap3519@gmail.com> <20240816175414.5169-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 Fri Aug 16 17:25:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13766716 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.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 E403D1C2326 for ; Fri, 16 Aug 2024 17:55:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723830909; cv=none; b=a/HtXsXoXbaRagBur3VVPQvbBT+c0UJPImpEJPIoUsrSdydPYE014QtIfaIg1cGP9dMBu3BlI/TthcjCiSNUXDyJg3PM5Hgr3hJzZCLjTi1Nn6e3/Cr3gbKcX0vAeARGQPNMGYshdzYO8EhGhwKT6gnuUWqA2SPCuAAZGbibSPo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723830909; c=relaxed/simple; bh=aWca99CbvjawBPMs86vKGxOb+c2Z8Fsf3MkweJ9hQAg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QMJ4kOhw/bMj1VGviQV7/QCqvNtD0suNWVQPFPAcCiBpPjVpRZuR1ivyKz204MJj+8yjM2LqYaFiukysShSJV0xFKSbMp4W9w2HYnUjA49OPjSmhEGMz4cbVbTJPu6RzwbWgR0Q9R+Yfph94Q3/tFWBHV+hczcTGZmOnAe6vH6A= 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=GjBBwL47; arc=none smtp.client-ip=209.85.210.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="GjBBwL47" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-70f5ef740b7so2031955b3a.2 for ; Fri, 16 Aug 2024 10:55:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723830907; x=1724435707; 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=GjBBwL470yZu1uKtfrq++V12YgqpLs4bVx0IH0LMYkhAhP8Nza6XAsXT1daJS+Rw2i jkScqCBl7wEAoc2petwKwIandygRfOStL7yba+KyF/1+7lt4QzIW/BHF86LjO0Jl9Eh2 LCaGaqrQNvGtnyNk83x+jv4m9ZsgaSwEHdvwB+zZhJH09PUGLTeJ8scJQ7RVejN7M3Ee 8+GRKmtJxeOayTgBzrWEjuxGTsjYCrUI+gUZ9b9kGyYrLsi07+dXfU7fk0kpuwm0rH4B nyptvI9byPxzfQNPhmtu1atXEe3HNSkJS3qeg+woh/fX7GnP6uP2oCq/rkwi/TTNzZpv /m4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723830907; x=1724435707; 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=bISAo0zJftmnHSF+FxPgx5dYb6CnDdEd7uWtAS92X6oaSg6SzveBn0FvmyK0Ba4Eox DbRKFKZZ39JxSlVCM0VKST3Iqfw2atLVIdFbZCDVQzRDlwMaVKvjF7ZF6cfPsP+fSKib M7WvSDPav09YP3PIV6hYP2p4KjMh7QTlQiQ2IcfAjV2lh/Q27V/Y9e3vK2jnnoE6RVu1 VipQurQzRpNurwjJYhob1akTfaDTCMf64jEyqEjSlOTys+d7C+TQpsikA/fVoWOV3Adu l0/vE5ZWOXJbwGGVXSrihQ4bhwRTAFHH2NoeuwaoPFhfTB0Mf02FBQI6v+i1yJs6/W2p isHA== X-Gm-Message-State: AOJu0Yw7T+tbLPZsEbNX34nCxtS93U3NPkv2MeGDAIQC1U0Va4hd8Fo9 +1fPnYVNvjvyjjo92gq51YSB8uHGnOmgW9a+JPX/N/PoyO2xMRzTNGBTTQ== X-Google-Smtp-Source: AGHT+IEMvRrJ2Y/MR6p1+T8xGVKcBWIYK441ynS43P6OPDvZZgZVqNU4DMO9uyMHPEOxcVyso7M9tQ== X-Received: by 2002:a05:6a00:66dc:b0:704:2f65:4996 with SMTP id d2e1a72fcca58-713c4e2a5e9mr4415468b3a.11.1723830906609; Fri, 16 Aug 2024 10:55:06 -0700 (PDT) Received: from Ubuntu.. ([117.99.60.209]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7127af1e907sm2985600b3a.173.2024.08.16.10.55.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 10:55:05 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v2 05/11] t-reftable-block: use reftable_record_key() instead of strbuf_addstr() Date: Fri, 16 Aug 2024 22:55:28 +0530 Message-ID: <20240816175414.5169-6-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240816175414.5169-1-chandrapratap3519@gmail.com> References: <20240814121122.4642-1-chandrapratap3519@gmail.com> <20240816175414.5169-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 Fri Aug 16 17:25:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13766717 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.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 587FE1C57B3 for ; Fri, 16 Aug 2024 17:55:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723830911; cv=none; b=ddZHxIxdi5FL45ZLxWM5CBBw+PAOSYncpgcREU/wqnpYAi/seo/1fi/owCcTJD2CA1wevQCUW9Qf3HS+oAUqhLLcahfzlPd44J2PD4oPMcNU5YLYTkCndbf1jPMbiH8VgvgOMCQK9Q85XWEhW/LsArqiS1gHbXOnLAmb0LXFWeY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723830911; c=relaxed/simple; bh=PsOooERAZjZyHL3/j9gPbuqa1tYlDESA7VjO0KeY37k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KM/U/UmmvMkLv26HcztBNF1zKhWQDQINFS+cXWfzrAbzwLV/6W/+8p4N5mPqeb+zfCy9PiKKxkVh98271NMbsIcn+cyHqzanYSKaFsNC8KkfZOte0vWN4wrCPfkseMRaYb2Hoe70AxP+fX11fxxREr8XH42rezTa/jl5MTYIRwg= 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=l1qdApMy; arc=none smtp.client-ip=209.85.210.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="l1qdApMy" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-710d1de6ee5so1951228b3a.0 for ; Fri, 16 Aug 2024 10:55:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723830909; x=1724435709; 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=l1qdApMymHCamrCnPu35tSuB719L+eP8doQ+qaxzHnYl8Z8YiqY14HxLxYdg3b+L5o ALMQePrmPF9kJsSpFcCYW5KRtprWbUmgigh+bwUX5CzwzGrNdE3Z5cxIG/n30QeKp0rO V1NrKeALC8xrPNp6kF4+ElR1ZjsS7mkvCpWoZYnBra1RoLe9+vILcv7Bmr5TX7wd6xTq wjN2/0J8L5qy3z/I0JTOJnvSDhrVoaG8C1IK4J6Zfy+weDSq58aKR5C1kCLEgaHO5AuM EOajiOpzIRLVpqWxX5p4ldJ+oirCUMZZN43IEWd5ZJYmF4/ySUTt14DOZxxvNEJO1JHe 7ikg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723830909; x=1724435709; 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=rI+TqO8VYBJi706OKUb8TextBITzcGZicqVq07oDHoBGLWAxkKl7IxFpcyxSXxYF/j iVWN9UgfZwDOAolZ6YVZzDtccCQtklMqfwZSnV9bHcX6oDPwAtQj8elHSfiP+Wh9TD+R qbveH5yJOZ6Fw77Szrugst6tIU/uVQcmgAF8F/UZ4P74JiZ/cT+2qzcMP2l6fiWVTPTA arsY4f4hC8ppeEACP1RJjjfPYSbpDbgUTlIuwS3X6U1p9Mvc3hIP4HsyEryYHlq9U0bg US8XsDa0AWjWb+PZgcYJr6v/AYgjYIT2c8U+vhq5bC7HeOm8EKhNkvH95qfJsZv3kKay Q2ow== X-Gm-Message-State: AOJu0YwHgQVVNUVRgBkb6TQ9FvKhUmNvhT9kfNEMDMGLkXP+u9aOzg6Y OjDwWl9dSFEphaJxHQYMs/UlkUfIsOV0Y2Yme8c+ekDc9JNfzEVpB3eXvQ== X-Google-Smtp-Source: AGHT+IGDukUHRM/2G+sUrsfVdP9qSFC1viMdkcxsOJ6liqOGJS56IGjAda5BNDa8sUjSpbsTY9fjzQ== X-Received: by 2002:a05:6a20:6ca9:b0:1ca:837f:f4eb with SMTP id adf61e73a8af0-1ca837ff563mr2190934637.2.1723830909247; Fri, 16 Aug 2024 10:55:09 -0700 (PDT) Received: from Ubuntu.. ([117.99.60.209]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7127af1e907sm2985600b3a.173.2024.08.16.10.55.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 10:55:08 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v2 06/11] t-reftable-block: use block_iter_reset() instead of block_iter_close() Date: Fri, 16 Aug 2024 22:55:29 +0530 Message-ID: <20240816175414.5169-7-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240816175414.5169-1-chandrapratap3519@gmail.com> References: <20240814121122.4642-1-chandrapratap3519@gmail.com> <20240816175414.5169-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 Fri Aug 16 17:25:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13766718 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (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 59F511C2326 for ; Fri, 16 Aug 2024 17:55:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723830915; cv=none; b=NS9Hb30k2ELa45mEb40gDH+Na1nsLgHcS7J24DR9fWluxLNc/cc2OWjdgHtFX5hEGPUm23kPdMqiOvOCVWKLiddmV+H7R0upF5lU6+GmAjQwFIYuFMhImiVaV/jSKJDMDZZnA/RjL5bDSbFf0ZtYszxZ1ScKrFS+/Y/neYUhuhg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723830915; c=relaxed/simple; bh=F6Ll+kebVEWNfVCewmYyA3w1aLfK5yHdCCiWyt+qaQ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lVrP87VSFJ9KF3SZ9fP/tL33dwbSRxUsFBqdYeX8bATDXcsBPxyolDtOb4b/yACofKatgajCvmupEZXxCmvkaf0kt/0S+xmymWrriVjmjM/M17jqEww5S4pX+wYKh0a6pT4bBKLSH0MUZ6dOFCxGDpZYNFz6B3Zslh90Tvh+BeE= 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=L2D4gDlc; arc=none smtp.client-ip=209.85.215.172 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="L2D4gDlc" Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-7a18ba4143bso1724230a12.2 for ; Fri, 16 Aug 2024 10:55:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723830913; x=1724435713; 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=L2D4gDlcBrQETqquFMXuqQQDbgpa/0+Xlcc09FLXhR500ohjj/8wn52jyKeS5yFe88 z+yT0bVmRJ1+ba46N9oBHUAYNoRJRZP3HJrAgJPw5+sY2H1xLnsVeGj2xymXjjQUj6b+ SxKmR4MFJbi79/ZLDMRWSXoNwzrXfhxqU1XnsvdwOx2FV1Dm2r4ktA1kjkW9QMmGVbLZ 1bOFrKekPc7XxhzGPCzyCNISwtsjcOZHcZHPf0DR7gL05eR1DQ2po/vEfHu4qbuOaO4m 5ayL3hMQjypwSatTL1AfRbBt/jVt040dmDlS2TcvYuI0ZndgpsotYez+pIUsggNyFKDQ 8JLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723830913; x=1724435713; 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=Gx6asauIU57AgAj4+QMrku9+Efx9sIvPUIctDi9ow6DiAX7W2g9Y1GLkwnpoZ9beIg d6ak6BQmegPhaOFXiXGZJWd5X6d0v8L2TOVGz4FByzPHiGwmLYNod/KOMzbLvca8BzR9 IAeXIWNPHc5aj6SgiN71ONbNsMGpwilRHrHiaydRtrezsOeFN7eT+jhKGI9GCM3s9fnj dY8cSjVQV8FEXtzhT/DI2E4G+KV959NAs2bPaJslc3CoWrTFmZi/lkcqI/8h6kvYTw+T Xyg/cR2Z4JSX6Wcjwg1ppgur+L7PJfVhdqzOhfGTNEZnNua7exMUuRdtTCDN3JfCd6jI n8YQ== X-Gm-Message-State: AOJu0YyJ07HYqpv6XusWh4U9oTLWSe5ElNopZEJFSempn8++GzW1PvLw yM4cESdLmtyjAugdyhPFcEYlg0iSvprgzBZp9H5Gi47X5O+F+JavOB9afA== X-Google-Smtp-Source: AGHT+IGLke90s2xN2qKzkELNqPsqRTTc6uHaC68wQSMg1gurINqflHkqo/vJ685uMmaok5iR53WnkQ== X-Received: by 2002:a05:6a20:9f89:b0:1c4:230b:5ec7 with SMTP id adf61e73a8af0-1c904f89275mr4908861637.15.1723830912649; Fri, 16 Aug 2024 10:55:12 -0700 (PDT) Received: from Ubuntu.. ([117.99.60.209]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7127af1e907sm2985600b3a.173.2024.08.16.10.55.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 10:55:11 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v2 07/11] t-reftable-block: use xstrfmt() instead of xstrdup() Date: Fri, 16 Aug 2024 22:55:30 +0530 Message-ID: <20240816175414.5169-8-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240816175414.5169-1-chandrapratap3519@gmail.com> References: <20240814121122.4642-1-chandrapratap3519@gmail.com> <20240816175414.5169-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 Fri Aug 16 17:25:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13766719 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8714B1C6880 for ; Fri, 16 Aug 2024 17:55:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723830917; cv=none; b=pDtzO4c5vAQJ7c4lyVwNyXSd4XmAFsAp7N4i1fvKpCpOiOzwfZKQRH/lkUPwyeUjZ0Jma1LoHVedz4TZ5J7j8XB/H+ehdrqi8C2k+xnfOegZsgHq4xYuo6PWLD7e5pq6+/nIlg6z6tDH7IHY6ntl2NfDlSTcXIIn/uMEdk0v3nc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723830917; c=relaxed/simple; bh=fYVq6x6OTAxVrRyB9SNlLxuuV5rAOds4y2R7OPJDboE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I/xJEN4O+3Aae8Xf2LRbBuT4ahmtssSQmNTGJP01NDv6JH20FpWhEdB0yFQ0Z6AnoRYW2AdO7uANykEITOBtB1gEgIcaU+QDmbEb0MbTaVIKn46GGWMRwtWP+btKNB2vacm1Lo+p6+VitSXcrKSsPTHNkLTalLB5etUgiELupLw= 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=l4ilstEo; arc=none smtp.client-ip=209.85.210.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="l4ilstEo" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-70d1d6369acso2174830b3a.0 for ; Fri, 16 Aug 2024 10:55:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723830915; x=1724435715; 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=l4ilstEo7ejP6eW8+8iw2wihgRUPH74dBOOoYD9HbP6VRtyDPfnYXTpisgbAEFo3wW Se4lLM/wEPu499jMyMNshSaBc7dJKShp9o3WzGkHG5GS/7C0aA9Yc0LX5W6f14rcJeKX ydjz3fUNyHC+rr1INOvtOZe0lsURrLQR60mwW0GvEGhLlTnKb0hZan3Dg6WKR2HzuVju YI7vlfMP/Lfs2LecApa+3XRz+PgPRe0LKpbM+hAXh2M7EBHznxQrYZT9zYnc94/A7Kf9 QgjfTpnKSQckxmzv/6Bw7ao5wtCoNKdqicLwP1NJ2i+heWJKFQJNqgtZBLe7qKSmqg9r /t6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723830915; x=1724435715; 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=vW6X8wo2rngNVFYQctSdFWTUEu1YyvF372YOrmnoAxNYoMbXt1Q++c0sntgtBLuBef yqeuATPGsvwRd3ezqRQMhd5SLJNtuBDIILMGgpaTKGzM/baNnbk21rABd9x1uhaDX47X sSFyT9yXLPx3r3GZe1R4TeTsGn9q9SL3Ti3R3abKQqQUsMY+O4+ktb70OAzVmablQqV4 6v8DQBs8MdlCPjeyAZxd7n+oTAJkAfRDlgsfxW8SmLtprSyvnfbn4JUJ/A8z5YPKk2Xp v8rM9Br/AkAUabGoZulOUgUSM5zfy5qmFVN9+2Kg8i86FhYcst6mU0Dr6ZBKG/6zfHhq iz9g== X-Gm-Message-State: AOJu0Ywcxe7tA7wVpu6P2/LBPRNZRL7e4BB53VgkBcRWxMlXPKKPKsl9 eMbNI/0nMudPf1K8vHGBhADmYZD6mlKPzL2I2XnbuRzY9mRRse10W7gjqw== X-Google-Smtp-Source: AGHT+IFwsckwnepyxSGabYe4cd8KGO+j6o1GmghR4l5FK4vO1sQylGDeRgefumWjg+3h063UHtY/BA== X-Received: by 2002:a05:6a20:9d92:b0:1c4:85a2:9958 with SMTP id adf61e73a8af0-1c9aad2cf8amr4734041637.25.1723830915457; Fri, 16 Aug 2024 10:55:15 -0700 (PDT) Received: from Ubuntu.. ([117.99.60.209]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7127af1e907sm2985600b3a.173.2024.08.16.10.55.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 10:55:14 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v2 08/11] t-reftable-block: remove unnecessary variable 'j' Date: Fri, 16 Aug 2024 22:55:31 +0530 Message-ID: <20240816175414.5169-9-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240816175414.5169-1-chandrapratap3519@gmail.com> References: <20240814121122.4642-1-chandrapratap3519@gmail.com> <20240816175414.5169-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 Fri Aug 16 17:25:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13766720 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.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 6D3AD1C6894 for ; Fri, 16 Aug 2024 17:55:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723830920; cv=none; b=PN+GZjm/Kiotl5QSnxFxeqR8sAI35FgpiIRET5nuJRdfp4WW9Eh2EKQIyElNfDh384TFTXcc/gRnZ/Exkp6P1YTlQesun9WkVLexMtphHmN6omu/8hp+cSxuhOJ54/YM5Jwq3f7lyfdqrhotmy0EQ6E4q5vEddGO5g1OtB+A49o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723830920; c=relaxed/simple; bh=6BDAIqOVJbw+Q+aCwGDSA1w/XbzURRuCetAT0vKiknE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pEHdzOQ5O/jQ+nuPAUUaL0cXMxs8M9vqG3unk88XLU90my1jCCCxn+7zJZoohHPcYYFctWvtIypQ5P6HycjoYs7aHz+avCkywlj/ov7EhDsSCFdNahPGeGrfbgPjbf1C3laJB7p3sRprHnSmTUQCiJ7k2PPfKj+ET5FQiC+Sm2Q= 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=mgxPSTEL; arc=none smtp.client-ip=209.85.210.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="mgxPSTEL" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-70eae5896bcso1979766b3a.2 for ; Fri, 16 Aug 2024 10:55:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723830918; x=1724435718; 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=+o2DCqXbPz9PCa0342XN1fugFDXb2RorhmLWbOzFed4=; b=mgxPSTELSSNrM//FYzIokK18BsvdfYYl1CxxpwZxeoBaYUHGLQ+xWE0H2qBpYc6gYP YmCPbSiXqJQQM4tH2PE8fefQLrAHf+DXN1pbznt/90fELcKWWsxDTjSwYA2+9hu1dX3Z cyavRnLIUIft77qIBsdVQ0Sqg9zC5VU3cBkpRfkytJc1HcZ4XM/q9miwqZYI4VUGnOVU olKAq9XUlDcVMjh+kE2g5rSMCbZgjovCw3E5ezr//FHYvwtOBmwHAiIaATiTmFP5e5KN XixqplogFoagDtVDHVifScoMfWYwaXU6m/YOQt0EhWqnhqDnU7Kcm9efT+qGnFmEtVEH gWGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723830918; x=1724435718; 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=+o2DCqXbPz9PCa0342XN1fugFDXb2RorhmLWbOzFed4=; b=K/psLeGt97cRxrjg0rtuVfbvg/7FYSpuEfuqSZvVnXkxzPTTPvWKez82Xo5l3nVa0S Ikp482/BAkmAGzMEdmiyrmmaoRGif+q82WvsvQl5gv8M78esPI2wbN2jnZA9poDwH3Kt 6RMEjC5UguAsQZpc9zopa0ilvZe6Fzgn9toJnhX13eElyaEWAZTwbRhgA0sL6e871lPU oi6b21v3c5QHUsH4dZF6AAolnveD0XWvZZcX3HxQXRj5z55W83EGrkEx0deGq9f5zhUz MCsxqWFr5XN5B2audyHR8Ol0U2zwOQkBI0FLvuZqZWZ2LM4RyBBpl1+pqppWm7/14Xtv gn4Q== X-Gm-Message-State: AOJu0Yxbg73SmMAmu8SvzJtkaQ2ZGIrhszh0W1czR5bznhX72VfDNzpM PU0iAMTeMoGBd/cFBVAZU0A2ShDqiuTueVrjdpUn90v+RuZoynTD+d79jg== X-Google-Smtp-Source: AGHT+IE7qIZJOIJOuISREPSD8AFTDQgQpE1uU5xRjEEamKbBYb/J2VezYYXWcncBcrXKf7HnMQXgfQ== X-Received: by 2002:a05:6a20:c90e:b0:1be:e265:81fa with SMTP id adf61e73a8af0-1c90501facamr4670938637.35.1723830918171; Fri, 16 Aug 2024 10:55:18 -0700 (PDT) Received: from Ubuntu.. ([117.99.60.209]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7127af1e907sm2985600b3a.173.2024.08.16.10.55.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 10:55:17 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v2 09/11] t-reftable-block: add tests for log blocks Date: Fri, 16 Aug 2024 22:55:32 +0530 Message-ID: <20240816175414.5169-10-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240816175414.5169-1-chandrapratap3519@gmail.com> References: <20240814121122.4642-1-chandrapratap3519@gmail.com> <20240816175414.5169-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 | 92 ++++++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 2 deletions(-) diff --git a/t/unit-tests/t-reftable-block.c b/t/unit-tests/t-reftable-block.c index 6aa86a3edf..1256c7df6a 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,97 @@ 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; + + REFTABLE_CALLOC_ARRAY(block.data, block_size); + block.len = block_size; + block.source = malloc_block_source(); + 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); + 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 Fri Aug 16 17:25:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13766721 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE84E1C37A3 for ; Fri, 16 Aug 2024 17:55:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723830923; cv=none; b=YeHwR2K3uq5OPf3G6yhIVm4AVL70a0e9+1gvD/EKX3E4WvQGRG+nLsLZOvvvsRxCKEkyN6TX5Fa/cNVIa0Aph/zrzMoCZfzi99iy0CnwvoN0pCC4yToAXxaufqfZpIF9anIEDD80D1kiEgqNbSOLPfLEoz3OHdd50Z2MI6TGFrk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723830923; c=relaxed/simple; bh=00DSGfPLW/XvZDWPOGM0q9ycacB+83y8Yf9tdtfmb6E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ncg69zFYFQBhoFLjzw5QlT8MoUxE52Gbx/JR+uCaXkg4LSe7sEg59nOHtAYEpr8/bX6UYNMTLj9gAn/tiZ+zoFMyHRSdutohtaM8LVmBVpB92cuOKeZ50OlByogyYoSaRi2NRNyHgNL/ZRLmle1pfh720htwqayfmKWZQzw2cKY= 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=MmMAiZwW; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MmMAiZwW" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-70d2b921c48so1787113b3a.1 for ; Fri, 16 Aug 2024 10:55:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723830921; x=1724435721; 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=sIpeNtuc1TErdzaJjKxPmo3P9FdzNmjqrFWjOhfJBIw=; b=MmMAiZwWVSa9PY9v3fj1x06yTPjtIYb70G4twiZ6CqEYK/LySFmsLMYby3YEokV9H3 Ykx/uWavUT4frMLKX0aSO/EWv7jNpyP1TcRuSpzu7bOqZdvbCbJaZHpZnOPgFpuTLJVb YKPqnQjEDUKaLJig3xrtIw+oNnsUEqVnpYAKsbrkGdlQr/Ia26OccCESeDK8usuYMHlk /SdZ+nOVN0bwOQfIvSkU9y3uHSr9W2RtpMZqSbjLQitRIh6SAn+UgdYXop5vhXWvahd9 HP9Jo7Gdvm+6AsdwkSlIdRxG7eQ3LzWeiT9s13OvhbUhM4yhAsl4VbEENjyNWFW8pEvH fjSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723830921; x=1724435721; 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=sIpeNtuc1TErdzaJjKxPmo3P9FdzNmjqrFWjOhfJBIw=; b=ZSiZGm0MmXDVDwNLvFtTRJob6R6pdK6M8Go6jS/p2wKM3WRSdpmRAwvdAWGr/keF2A G5MjmdX96QgtpzCebFNMxNqJULObE8an8YdYAIEhi8/7VgPMIEdhV0j+ib2RupUX9Zoz TR6cDrUWjaCOK3dbgqHEgCPKnoOPHLMyt85rttsY5NYEnhLUld93VCMUyD1YFeBcRbTN 06XNpSHDDspEX1oYvDooK4n0ajpWo1KgDvFHveT1eQShWXAJOfSAj6WzxgUYvkfDV4vx +LTNEtu5/WjYy6+eSiNFZPBNeAMmmefWzlvqg0f8cw3va90rtwQ78QDDFFjQVtyzeWvq nFMA== X-Gm-Message-State: AOJu0Yxtt1GlhheT8llWaZh1fLc3iR81DHctVXrjnnG715urN+WFB9Cn c9rRKRYKOQ+7W+8xbg1v8a/toajhAgeCOo+I2D2nyMHaAkOcIU+YTmgvIQ== X-Google-Smtp-Source: AGHT+IHuo9qeKhlt6ruINufh5JH1cVgLq7RhrtXGnJ8fA3B/XNpVjDvXpDZn3e9+Pf7KbJblozBQCQ== X-Received: by 2002:a05:6a00:4649:b0:70d:347e:713c with SMTP id d2e1a72fcca58-713c4f37f15mr4414574b3a.28.1723830920722; Fri, 16 Aug 2024 10:55:20 -0700 (PDT) Received: from Ubuntu.. ([117.99.60.209]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7127af1e907sm2985600b3a.173.2024.08.16.10.55.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 10:55:20 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v2 10/11] t-reftable-block: add tests for obj blocks Date: Fri, 16 Aug 2024 22:55:33 +0530 Message-ID: <20240816175414.5169-11-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240816175414.5169-1-chandrapratap3519@gmail.com> References: <20240814121122.4642-1-chandrapratap3519@gmail.com> <20240816175414.5169-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 1256c7df6a..7671a40969 100644 --- a/t/unit-tests/t-reftable-block.c +++ b/t/unit-tests/t-reftable-block.c @@ -190,9 +190,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; + + REFTABLE_CALLOC_ARRAY(block.data, block_size); + block.len = block_size; + block.source = malloc_block_source(); + 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; + allocated = reftable_malloc(ARRAY_SIZE(bytes)); + 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); + 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 Fri Aug 16 17:25:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13766722 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 9B4771C68A5 for ; Fri, 16 Aug 2024 17:55:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723830926; cv=none; b=KIAfqjYkMdCucjNqglXRTqngFXMnotCbP+ikwS5GkLmUYqjMtFuG1bLxbYqy3McsNqxL+ulPLg14tAtw1ULOA0o1M7yvNhUeBUD3Ve4S/Seiv91QXdKOkxHWs1EftY5kgD7sTMX6YXmTZoekVJJr0SGE6hiPFC/2NmjthupWjPI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723830926; c=relaxed/simple; bh=jWCvz37HxYRsW1HkF37FzDUtF3hxdTUH3I+E5qapNCI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RtHQcT8wC91TozEpLlLpJ5myoWKp7FC9q0y3zNez1pSDBgHhtwAigjyw+p/XBN+9GE0NhlJejdQ4VjinX9SjobkB6xWWBqwVWPgSVDzlm5a1b/Me0sosV1ZJ4MeCoo7POUOCdJdyYGValCXDrbZF3TJASIbx1vd9z0cpmsnHwl4= 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=eQBDOYqN; arc=none smtp.client-ip=209.85.210.170 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="eQBDOYqN" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-7126d62667bso1466172b3a.3 for ; Fri, 16 Aug 2024 10:55:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723830923; x=1724435723; 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=fBAGzow4IBdSCx+zdMkCm4RQTjz4LEzlEDC2srhwpbE=; b=eQBDOYqNUIDerQINPwhb+WvMMpHRDWLXASxI0PxKwI0hX/uXNEudILqVqWpuYuHO4q 18ZXMWGRq8i0sNBXVaxrggqPg5h15ToRu00N6LA7Jxk6Ro11Y7eyuROyI6Wh5/ikcQBq 6D5gX9DX+C4zup3WU4fNAj2GiX7sG0pqNPSw8JYjE1ajCRqfzqYho6nCk2y7rf8CbvaQ KmiLkd3f6w6DcR8EjyJ26UkZbTU9BGnBXhBaNRxPYj/864oyDrygGgq1emJzQmG/Earm lvFfG1aJcZ7FgpENp7UM8EnxQskb4fSBHQwc85ASvfypiq73MV2pkjufJAYPADYZ2WDy azLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723830923; x=1724435723; 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=fBAGzow4IBdSCx+zdMkCm4RQTjz4LEzlEDC2srhwpbE=; b=AtDDZADK0kyqYbYd/OkGQYQSim98kdE/BE/DYXuLccm2bCg0Imgd8Wgk79ZLGirA3a JCbQ4ZU5BcgJ+jjDvCdfjLx9viWmsibbgn7KUNvp/PqhFlevJTA1ApxodeVzVbFDlk4k VFmLkjL8qRIz5NJJVvrBHWY13ulZsYmrSf83oCWy3YCClghW/s05QQY9yi6JWhmR3s3X sIuN2dP4KWO0km6K9D18QpUU64An9cTYr9d65+ToU/94Dujzc94m5anFMivwzhNaqOFY s7mH/LLaXTKUEkK7p57LSBJSiBaTLQlrDKjlC6zZiKSvuWxazIDvDovRLANI2g1wh9M5 yu/A== X-Gm-Message-State: AOJu0YzcGKZOgRekI0Vk6MsInMO+9+RhRbQCHZA9nL+mRtnazxXbVilY 3Cjfv4v0/g2eyl3usZUBAxG/z5XpOY2ee9qyzJJdPZWailQyyqCKyqm3HA== X-Google-Smtp-Source: AGHT+IF/7EQc1b/0WgrQhWG1EoKIEqhsOZhfloAgAVDAw9JPCZe1faHs3B3sjJF8OQUT3bVxSfIdzg== X-Received: by 2002:a05:6a00:85a9:b0:70d:39d9:4523 with SMTP id d2e1a72fcca58-713c4e08726mr3455541b3a.7.1723830923392; Fri, 16 Aug 2024 10:55:23 -0700 (PDT) Received: from Ubuntu.. ([117.99.60.209]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7127af1e907sm2985600b3a.173.2024.08.16.10.55.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 10:55:23 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v2 11/11] t-reftable-block: add tests for index blocks Date: Fri, 16 Aug 2024 22:55:34 +0530 Message-ID: <20240816175414.5169-12-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240816175414.5169-1-chandrapratap3519@gmail.com> References: <20240814121122.4642-1-chandrapratap3519@gmail.com> <20240816175414.5169-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 | 87 +++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/t/unit-tests/t-reftable-block.c b/t/unit-tests/t-reftable-block.c index 7671a40969..c2b67a11bc 100644 --- a/t/unit-tests/t-reftable-block.c +++ b/t/unit-tests/t-reftable-block.c @@ -271,8 +271,95 @@ 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; + + REFTABLE_CALLOC_ARRAY(block.data, block_size); + block.len = block_size; + block.source = malloc_block_source(); + 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); + 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");