From patchwork Wed Aug 14 12:03:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13763417 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.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 88AF81AC43D for ; Wed, 14 Aug 2024 12:12:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723637532; cv=none; b=Qk5WOiVqpysR9KXxhyrpeAcMm8ljt+FvDXE9L8gvt9yvxSbJjMd9OGMRfF00xTZ+f3ClKHWMhVEcWOdz8wEHn7VZQDCgSr4HZa3f1P3q7aUpxBHazVWBOWl25aodkCBa8RWs0yBmAsNbnG5/5X5jdg22S0h/mM+zyifznO27l8Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723637532; c=relaxed/simple; bh=18yXRcBLiJJ2igaJh0Rk6h9YF+bh8km+/CpCJuWg+XY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mc1Th96XqiLYsssn3iDaz4Z0V8ddzZbEDM0FoEWCnJYTKiOlQMRxA9MavC5tjAC332lAh1KSWNjT+jZcFsTQlDO6eLBeP3Hmvrd0NSJ6cZVN1H0LkSPjRG3OoDcazPni2xNz8hJUVwQfpDWwlu8pVfUydYjS9TQVxWHuWhDMwLI= 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=aTJAkNEC; arc=none smtp.client-ip=209.85.210.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="aTJAkNEC" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-70d1a74a43bso4769294b3a.1 for ; Wed, 14 Aug 2024 05:12:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723637529; x=1724242329; 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=aqZOuJ5ACdlNnI1FAuOh7cyhyLosrMPjPOwxyONccbE=; b=aTJAkNECDEMk2T2IHVFJpwSGRrvHwhNBgyi2ih4cpMq1dfMvR01pdUmoQqJC9AYEb7 mNpYrpbWfnhTeHM2Okl55hEjuwC9LZjwTqZ3t+x9CPXCuzLDXN5VNi8fXMs9l6m2jvCU T37hO3xhYczdkOzeVYAKuEezsRwG20pXywuqiXO1LVfq09vcOJGqboam/2LD/wzqokuF 7mAYLoULJF1HdHq6QgtE6SnoDWsqjdM+2tgRQpRyD0TEnuelFl9NTNMqs4pgI6pH520b jPwArgYi43CJKx+mAB8DYKvHr2F/JrfTyTrYVIAZLS5epaRHXX79Q3by53rio9DFkA0B eHSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723637529; x=1724242329; 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=aqZOuJ5ACdlNnI1FAuOh7cyhyLosrMPjPOwxyONccbE=; b=f/836pO4bghivgS5+zrRSzAyLnshobMvLmXEae2p+s0S1ryd9+iqUuGv6oyuswVny5 loJva31btTn6EYM8YBkiRRYUVxMIsleobGqhPJicJTZqIXEWW6dMgJAmIhhtnNQ4jTS/ focBqhOaeIYJXE3bNwLiu4PyvVR78OTUPg7XH1OTYtG/LPAkFZJIWb551YtpDWNxdnS9 bVSOrVAcKh6OMmxKp0gjlH/r5vXNFgdUx62pzTs38vJ1+VPdRmsNRFLXNsyqvytroocW DPLVqo3wmbGG4xVfcC/PxPIC6rJILMZ4MgNtOJMmX/VN7seMIe4CdUxfMEH/YnDzJZuU +oXw== X-Gm-Message-State: AOJu0Yyhrxcl1Ui1TCun8DmJlvoiITFEMx4WLd8Ret6IEXTmrtQOav7+ CNqCZLmyyU1LkMHIp5MNhexb/kTL6kFIToUOJGz65UlJVjxjXA8womhvvgaqoFQ= X-Google-Smtp-Source: AGHT+IGReuzc0byiD4dmhtA9WCyfBDgNyiPTOnpwfi41OYxcBUYb/vy1MKNkv+FDoCM0ijOCCoxNPA== X-Received: by 2002:a05:6a00:130e:b0:70d:2ba1:2402 with SMTP id d2e1a72fcca58-712673ee157mr2912183b3a.29.1723637529143; Wed, 14 Aug 2024 05:12:09 -0700 (PDT) Received: from Ubuntu.. ([106.205.236.194]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-710e5875200sm7195450b3a.37.2024.08.14.05.12.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 05:12:08 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 01/10] t: move reftable/block_test.c to the unit testing framework Date: Wed, 14 Aug 2024 17:33:09 +0530 Message-ID: <20240814121122.4642-2-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240814121122.4642-1-chandrapratap3519@gmail.com> References: <20240814121122.4642-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. While at it, ensure structs are 0-initialized with '= { 0 }' instead of '= { NULL }' and array indices have type 'size_t' instead of 'int'. 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 | 63 +++++++++---------- 4 files changed, 30 insertions(+), 37 deletions(-) rename reftable/block_test.c => t/unit-tests/t-reftable-block.c (67%) diff --git a/Makefile b/Makefile index 3863e60b66..f030283447 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-record UNIT_TEST_PROGRAMS += t-strbuf @@ -2679,7 +2680,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/pq_test.o REFTABLE_TEST_OBJS += reftable/readwrite_test.o diff --git a/reftable/reftable-tests.h b/reftable/reftable-tests.h index d5e03dcc1b..e25ca86ede 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 pq_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); diff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c index 9d378427da..4eda545fad 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); tree_test_main(argc, argv); pq_test_main(argc, argv); readwrite_test_main(argc, argv); diff --git a/reftable/block_test.c b/t/unit-tests/t-reftable-block.c similarity index 67% rename from reftable/block_test.c rename to t/unit-tests/t-reftable-block.c index 90aecd5a7c..8ab3ff9ebe 100644 --- a/reftable/block_test.c +++ b/t/unit-tests/t-reftable-block.c @@ -6,34 +6,30 @@ 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]; - 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; + size_t i = 0; int n; 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); @@ -45,11 +41,11 @@ 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]; - 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; @@ -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,10 @@ static void test_block_read_write(void) while (1) { int r = block_iter_next(&it, &rec); - EXPECT(r >= 0); - if (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 +85,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); } @@ -111,13 +106,13 @@ static void test_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 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 14 12:03:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13763418 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 39FD61B0115 for ; Wed, 14 Aug 2024 12:12:13 +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=1723637534; cv=none; b=GHsk9luoLvE2Yy5A2QDBwhM2a3hGU1peiJescOOQt3f1r88EcEsAaiVtwSkGnoS3wI+c0lOD9AdCt3nc6CZ/EhG4Ot8AWb9T4Ph8zrtMjvXuMX7QNm+I5Mc5cCfpLyltxcNRTinWqJFyvviNYtlO2M07zEBlqh1Euxlwkpo8AeY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723637534; c=relaxed/simple; bh=ffiFLBpeTuxHH85vAR7Mtrt67fzWVtkw8vQccpRJkTc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hDXduaIjo8MQv/iZzuq/xLSqBACLK1xaE3we12o7znR4zv4wl22f7YkAu9KLGb0t3ulg+RHA3l+KBFY419HHB1ya7SAv8t+44Rm9PhbemvwxSzJmnOYlI0StY8nKgOZDRa9/LRB125a0HJ9XR3PKMGye7jFIxTww6nxsJmlqV84= 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=frTRK/B2; 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="frTRK/B2" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-710cad5778fso5286456b3a.3 for ; Wed, 14 Aug 2024 05:12:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723637532; x=1724242332; 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=g+OMgJ1DTTaUsnbA54b3jnVl67k9qUgFGmxXetH5pNs=; b=frTRK/B2vG0xr6ip9z4SBwYFm9gszdEAdixoldTFdLtvAt8hsf5i4X0UYy+mlkfu7w WufWFnnqjY0tIaxlOWPrsYhH4zhu38KgjyUFOHyapM14MwPgmr+u24UT0Ya0lB6uhnN4 kL2bdoiwjRFXxZOMXZi4bu3asB+fdQWTPEhfHFwk4IbOEG+nXs5lY2z1egbHpY+JOxjj W4YkR0vlWt3pSE7kVV/fCYoWlwg1qyXUxhc2Jbu7InVvgDSIs9nbmRHx9dugY2Fhzey+ xQvvHDtQlqT5Xjvibw/7M5vKea/s/dot4et90Inb2h2jWmvVFxtuhQeqVfYZP70eoTUp sIbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723637532; x=1724242332; 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=g+OMgJ1DTTaUsnbA54b3jnVl67k9qUgFGmxXetH5pNs=; b=K9Zv3o2HdhXLLbZ29RiJbCcmQDWSqdynuEDweCyMj7Z2xr5jA5SrGLe513N61YW1TM 8IgvGYlMvwwpP7Q6TwRnObeB/Ib32L5P4EPvdbKBZp9SCItMZo+wsDBBMFLXuMnDOpkg MP0cLh9oAWccVDQah9HM4cTKkZhds+AB7YBMvtW0L8Y1VFvETr1yaFxbLsQGWzb7bdpB anlXQvM9QBeFTem4XPuL2CzkNow61jsdSfAmvn4n+BC0g7Jfn2DCOAFDQ55l7kWMESmZ ZwvPWE/gc9NMHamq4bDO1qJhLjrxtncalos0Nc2/ml4rk6fRLVZlYXbGXoGTphTjsWfE ckrw== X-Gm-Message-State: AOJu0YzvKXU2P0sxyg42zwRF90bohgX3NltEycJMS0P+DMr8Z/qb05db cBQj7G9ISWG1mKijFOMgH3hETsInNVCFxUNliXBYX8JhERx70Ps0HFxuriAjw/c= X-Google-Smtp-Source: AGHT+IHYiBxmymtM1/lhUfFfCbwAIBufBiqWp99+egVlUls1FCQYArcD1508PwfoyeNKXPXa7Yn8xQ== X-Received: by 2002:a05:6a00:2311:b0:710:da27:f176 with SMTP id d2e1a72fcca58-7126710224fmr3733598b3a.12.1723637531954; Wed, 14 Aug 2024 05:12:11 -0700 (PDT) Received: from Ubuntu.. ([106.205.236.194]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-710e5875200sm7195450b3a.37.2024.08.14.05.12.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 05:12:11 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 02/10] t-reftable-block: release used block reader Date: Wed, 14 Aug 2024 17:33:10 +0530 Message-ID: <20240814121122.4642-3-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240814121122.4642-1-chandrapratap3519@gmail.com> References: <20240814121122.4642-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 8ab3ff9ebe..31d179a50a 100644 --- a/t/unit-tests/t-reftable-block.c +++ b/t/unit-tests/t-reftable-block.c @@ -103,6 +103,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 14 12:03:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13763419 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 031201B1401 for ; Wed, 14 Aug 2024 12:12:15 +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=1723637537; cv=none; b=ANx/380gGqRpn9xzS9593J9Q0WFjbemRlurMpr7FT1YGZ1US8CfE0WSWmEzd+hyR3fWKKsfpu54X5kl4trUckj1kffVbcdKDD6pdO22aWQ++Qu60JEVvmgJp/fmlPSbM6CzjjV1UvtkNGUsLIXMh9f7g8hQ3OZUh6e2AMZuRXAQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723637537; c=relaxed/simple; bh=vCui7XsXJjFCiKnjX84iAM65Zp46VDWAhOoGASLdgsA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SaSy99Skf80VVkgzH6p3TMnmLg6SeZR1FxBJOtVkWT5vLnps7I+/g0jwnu2uHUH+eduiIk0zMKQZyydS2npQcX8PGC/9BNtGNTRf41nTNb9MDdfTdDcvj5NqizGM/PzROZ37+/OPM79EKAHL7jRsOAmBLh+0nL/TJkS+ckiJbb8= 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=VD0vsbxj; 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="VD0vsbxj" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-710dc3015bfso632419b3a.0 for ; Wed, 14 Aug 2024 05:12:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723637535; x=1724242335; 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=g93O2EouZZlxjPMeKRhXphz580Gg4HHT2WpJpDctWMc=; b=VD0vsbxjGdQYs/egA7GSXl6uU+M/zDJjQKhm0JJg2m90q+7yIsBq/pcCbp0lniVBMF NGHFzRiDw53ss8LeJwfDRrE6qISi2YXL+Oqg1L5/CofBqbqfC4Iz0gVnVxyk3oTwxEH0 Md8F95AbftODzntXi+oyYGwcSf01tLEowstwMSapX3wzCS4oK58MqhW+MM8DVX1pTbFj uZEFr+OXjY9/3gd0ovtZJ9oyjMILT1sw7GcCdvyTFKKiDIyMGNtkNiOZm1XAI0B0a+js PA2DlV+6NDCQPPekocSEtpVOOSlqCMSlwlcyLeTbcIAnRFwkgkLPQzGHd/0zE0y0+VTl NXvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723637535; x=1724242335; 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=g93O2EouZZlxjPMeKRhXphz580Gg4HHT2WpJpDctWMc=; b=VxOiql1yRXsMQOpbnaBgMOh4PQb0X/EBFXwnTtfScDWOabLgt75oVocDpJ6ZXSK1dj P5pnp4GLNbgwBegpcj4Z5ScVI6KBL1uzJsL8akDH6LaCAsidsroXnxXIMi9HvdaWb3+P kUuHT0DWYkzQnfgU5H7uWiZ/6Axm5MpNBG/QoduFQBl/1xKUq8BopYnbcDJQa1B+EzmQ xePmNzl5f1+RDrzwDNgcLCa48X/EnQ/6yLxkhRhl34vjBal0Q9e9TlXl6ynfGT0cGVlB WcRKMQWfH5csaLF+UcsXF76a72Wh7BYGvDHqaHzVwS8OEt1XL3p4IYtTe9Gs3y0KJPJN 9KiQ== X-Gm-Message-State: AOJu0Yw6n2qS1j7iR9ceQ3j5rg5KTfJvpx3oCe6iTEb/7uPLeIOBqfJQ rsAsYZdly0c7gHp+FSdbKnwRFAC5otNQoa9XuosENw1ckTyjIaGt/a64Zrwkp4c= X-Google-Smtp-Source: AGHT+IGE032GFbmZPdknRzhmjIv0FfaPfUL0dt9w9RlwibtIIfJdvk3Y/1bmtdsHoMGyDMtjVGzTBw== X-Received: by 2002:a05:6a20:1e49:b0:1c8:ef0b:fcd7 with SMTP id adf61e73a8af0-1c8ef0bfce5mr2020586637.1.1723637534667; Wed, 14 Aug 2024 05:12:14 -0700 (PDT) Received: from Ubuntu.. ([106.205.236.194]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-710e5875200sm7195450b3a.37.2024.08.14.05.12.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 05:12:14 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 03/10] t-reftable-block: use reftable_record_equal() instead of check_str() Date: Wed, 14 Aug 2024 17:33:11 +0530 Message-ID: <20240814121122.4642-4-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240814121122.4642-1-chandrapratap3519@gmail.com> References: <20240814121122.4642-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 31d179a50a..baeb9c8b07 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; n = block_writer_add(&bw, &rec); rec.u.ref.refname = NULL; rec.u.ref.value_type = REFTABLE_REF_DELETION; @@ -72,7 +72,7 @@ static void t_block_read_write(void) check_int(r, >=, 0); if (r > 0) break; - check_str(names[j], rec.u.ref.refname); + check(reftable_record_equal(&recs[j], &rec, GIT_SHA1_RAWSZ)); j++; } @@ -82,7 +82,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); n = block_iter_seek_key(&it, &br, &want); check_int(n, ==, 0); @@ -90,7 +90,7 @@ static void t_block_read_write(void) n = block_iter_next(&it, &rec); check_int(n, ==, 0); - check_str(names[i], rec.u.ref.refname); + check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ)); want.len--; n = block_iter_seek_key(&it, &br, &want); @@ -98,7 +98,7 @@ static void t_block_read_write(void) n = block_iter_next(&it, &rec); check_int(n, ==, 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); } @@ -108,7 +108,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 14 12:03:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13763420 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA0BB1B141B for ; Wed, 14 Aug 2024 12:12:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723637540; cv=none; b=V1f8qZJYyDv0uCkK1VmRTn16ymgWraBwiz6BQaSnE0ziL8KTt3FBmECsy2wyjFwIHGUnrIzNi+pNWmaFRS9vBIS4LQfPhJR+mnB4SUfTlKoGh8Ci35CuoE9M2P4LPSzo2rRWX83dKs9p1R9O5PHMy+H1l2IfuUC55rYlT8S88+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723637540; c=relaxed/simple; bh=y8QWuzeMWkgAWO7Y0RUnKScNW38Ug9IKuBAyw556y3Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AhrcFxubHRx4PsCUNlS1pOdVNpyMBWB4XARALp0zpeNWe3XmcjYtsYBTE90bh44GX7GekTlPpi+NZts96HErDRJbTX3q37ixgImqEk0oTa2mBmXTOP/gaxeboo4LwW9iEFJgHBojJZhHwrY8qJDnOruw1w6yjQeHq9yVGFgOslg= 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=BY2YvrFM; arc=none smtp.client-ip=209.85.210.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BY2YvrFM" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-712603f7ba5so1260278b3a.3 for ; Wed, 14 Aug 2024 05:12:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723637538; x=1724242338; 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=r+c1XQHel+XDlSH4E90quDkE0tj80881AMnfI2bc++Y=; b=BY2YvrFMWx4ds8WmoJO2iOtqXQXtLW9nG+LUA2e7yz85mGw/6MkY+bnkGmDGPVyPuO 2ZNK5SWB8LQzxJNxLwDuK5PO2HLJiT8mRmdwxwLtLZ98eFRwJHKEbvIVAsjMuSPv+l7w skkm/LpjtM3K+OlAzTlNT6D/5usYHWZptadi5MOC7UPyvKb4TSrpdGdI4XhsYnfCM/lP WpRBRvmBDE+AYZsvlST2Qtqi+BSfrViHlO1BNwmEENcNYLbNVLQj6iCqC4g8fHi5xwau JtMEnRxu4C77ltZoBNi9z/KwerO0w9Y2gXtP2LpuA/KpdZxwwDrcxm6cKbbvhh1WPyDY bIQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723637538; x=1724242338; 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=r+c1XQHel+XDlSH4E90quDkE0tj80881AMnfI2bc++Y=; b=i2FU84QcFHDfR8oCU95FJ9RubUqJsbvdDsnckUELZMLvmw41qgXXWWGuJv+YH+SN1T 8Is6LCps1homi+ViOV2dEfAmOm84lN7Pli9L+wXEdnsfoqSaBn/cXbAgmbciQbEV0hCv EpeUwheNl19T4fSgAKHqg/GqTSn1lYEaB/iBWtdm8FfNUrBsZzv5eJHJaND43kf2aLsh FhC4RWpnUgniZWdQZENScskwtyERif6R+w5Hq3P+Z/gcYwoV0rQ3JzikBm2BzMcmnUCY BDCG9S+sFWIrm45RhtFdPMrpQZiAILJ9MVpxZjQN0DV2cwgfoe912516DskNqbZ8yeqA G7kQ== X-Gm-Message-State: AOJu0YxQ7BrTTgpJIQhd+T5yUJ0QSnS3xVZBKHAvTKNtqROnFiLXJvDo bGUznhAhN2RA2bJglAzGnjeQj42IdAgVm+NX7vsLhxZdcWESTca4R6W+ej3pWow= X-Google-Smtp-Source: AGHT+IHlrwwkGwy06q+t0tEA95neRwAjhSlsFcm1hQmSQwhU8BZ/eUX9Otm+0tWhEFzX61/areffzg== X-Received: by 2002:a05:6a00:23d3:b0:70d:87e0:9e7 with SMTP id d2e1a72fcca58-712673e8f7bmr3449277b3a.25.1723637537652; Wed, 14 Aug 2024 05:12:17 -0700 (PDT) Received: from Ubuntu.. ([106.205.236.194]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-710e5875200sm7195450b3a.37.2024.08.14.05.12.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 05:12:17 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 04/10] t-reftable-block: use reftable_record_key() instead of strbuf_addstr() Date: Wed, 14 Aug 2024 17:33:12 +0530 Message-ID: <20240814121122.4642-5-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240814121122.4642-1-chandrapratap3519@gmail.com> References: <20240814121122.4642-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 baeb9c8b07..0d73fb98d6 100644 --- a/t/unit-tests/t-reftable-block.c +++ b/t/unit-tests/t-reftable-block.c @@ -81,8 +81,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); n = block_iter_seek_key(&it, &br, &want); check_int(n, ==, 0); From patchwork Wed Aug 14 12:03:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13763421 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 E75861B0107 for ; Wed, 14 Aug 2024 12:12:21 +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=1723637543; cv=none; b=MU+my4G/oRlj956hiBb24O6KZU5HJ9rb4eUJJyS0Rdcm9fxvwECxAL5mUaQU4jI9N1dfWU4XV5nS7XMmWLNPkV8IQjQg9JcYSE3e05lKu4EPD+E7Kd1lPiMGGJK3DLdeR9n5fpxjNQ508WpjV2iA7TmcS5Liam5twWVgl1vowyA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723637543; c=relaxed/simple; bh=1smM/cAQL8nw54vdniZByCCCLuflaeq0PrwTE6hutPc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ehOeIS6ARZMh+AU2kX65W94IsQuUis/nMB1busvwTvzQL4Aee1e7GTVKKccQ4xZgPeZ9gPqiI4X3vVlEsTfl3UTCZ36Gir922THgw1Z+yeTGV10NIzYcl4HuSucoc8YNj1cTocT2lKeHbfiTVr5ScjGHLD9/XR4v5SqZtjUbpAw= 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=jKerikQY; 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="jKerikQY" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-70d2b921cd1so5986200b3a.1 for ; Wed, 14 Aug 2024 05:12:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723637541; x=1724242341; 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=4xrFjut8JjgOetgEstqcCA9rNOpSVMl67RvsAlmxJzU=; b=jKerikQYy7WI5L+R6lPH7aLXx0yBEveLfzW9KzECWOJlmxbzMYoy3qViNh9/QeOGDc cKMWKsMjGjvbCr9Z16DetaphbUXCvfTBmglis5k/hQG3AIoDemhSAhOqJFtUSDvUyYjK Qi2kkNtRJWYCprqCFDkY7KtnLWBrhKDdLSpg1cANXmp5F87SroomtSZ8l0YB36sv7rfO S8usUANqCmqJpsMO+xl6vKxlRdFXJe+wjJTJWn585PyApjbr4XaUqPzSttU+/SlW8Ht9 RyRdir94lsrBISVbVoVD/g+eJZoVrrcOAPtm0GJ3obJH1/udb+h95dCyuY1H0hsriKso 6Udw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723637541; x=1724242341; 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=4xrFjut8JjgOetgEstqcCA9rNOpSVMl67RvsAlmxJzU=; b=IWzTvskEKz9Ylw8hRwK+DNpARxy4ACw+L+tW9Pzqi1l5jrJTinEfW3KsmNBN1DKHQj B4YB+YqX8GabGsz3aIkjSkipAqq6TjI7I4R/hv638/tzPihbniHUjqvPgcK7bU9t0jYM +UZ8GmWTdYVev6akYDMIHTgMhQACiw8M6udsGJgGFx+Izd08iWmpa3WtmFiBMXA2jcQ/ 26oqx2Ypgym69vHGHLIhVzskpEc5E+t6s1pLNDUZK3nnjE1/Yac6iSWzhUOg3XBUvFSw 2BehYajALa4nGSryXLKNosN6QMan5nV6c2M+JJYOd6UM4AKf8ZNm8aMJKfJgWK7ysL6y CSdg== X-Gm-Message-State: AOJu0YxEDFcsL9uWjyre5EOrT4FHtEQ08xza9G2oizQTuu4rzkpObYoD JyNA0/ueFTOEu1Fo2k9c2C6OTEY2tVaLWECP/OmadRtr6V5eJnYtQcfMUlpsv+w= X-Google-Smtp-Source: AGHT+IHvJVgaiqO1yGxIsPfXWf4rlMd+TbRL+IvLO6eVFXI/txEuDJCKn8eWkHgYcqRp3TVrhyEoLQ== X-Received: by 2002:a05:6a21:b8a:b0:1c6:edfb:431f with SMTP id adf61e73a8af0-1c8eaf8c17bmr3114683637.44.1723637540604; Wed, 14 Aug 2024 05:12:20 -0700 (PDT) Received: from Ubuntu.. ([106.205.236.194]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-710e5875200sm7195450b3a.37.2024.08.14.05.12.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 05:12:20 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 05/10] t-reftable-block: use block_iter_reset() instead of block_iter_close() Date: Wed, 14 Aug 2024 17:33:13 +0530 Message-ID: <20240814121122.4642-6-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240814121122.4642-1-chandrapratap3519@gmail.com> References: <20240814121122.4642-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 0d73fb98d6..dfb7262a65 100644 --- a/t/unit-tests/t-reftable-block.c +++ b/t/unit-tests/t-reftable-block.c @@ -76,11 +76,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); n = block_iter_seek_key(&it, &br, &want); @@ -98,11 +95,10 @@ static void t_block_read_write(void) n = block_iter_next(&it, &rec); check_int(n, ==, 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 14 12:03:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13763422 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 083DA1AED37 for ; Wed, 14 Aug 2024 12:12:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723637547; cv=none; b=DLsL3JumA3MkgslMioLH768F9vHIKTx/tPNStkwPpXB8CY6e25PXN6GKGzfQf76Smvk2aX2W98TWyLmrPFYFSV7hcwe/7Bk4XbwyPUvJ23NujbmEBApzZN1YrjgNV+po/HzXG3UC3kjTyiMNAY/+Mhdg8NJ1LK5E8jKb2lT3lxY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723637547; c=relaxed/simple; bh=46spoNG4u9mAlTmXupv1e8rIawPDMsH9kZHdBrZQ3gY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FiGQLvFk/vzCzOk1VyEjVTDl2oWm/PkPo2eixuVIwhfDHZ7MKHKNsGA/bzM8BEL6L3mPfao/q6UCh5BiSJWMvR+bHK9zpR4woIOGplovIrRyzlATkqtnSSST7cQ8+Kjf0ysF6iYqk/UC1D3quawWu+nCVkAwiJYjtAmqr4VdofQ= 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=iXAP1rwJ; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iXAP1rwJ" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-710d1de6ee5so5232844b3a.0 for ; Wed, 14 Aug 2024 05:12:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723637545; x=1724242345; 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=tojuI0+mu7UKoZesL8YaT3fhKoLlaYzvyRRQYad9BGo=; b=iXAP1rwJU7Y1udV2FBaq7gRENRcLFVSR2Tx2+jeorca/7/mx32Y1tmidIp909d/9Gu 2HT7xwKVej0GAgIPjpT9jNnMa+E6uwVO4Wqgfx5x03tCl0+37kohldOUbfg4TTK1b/oX sQeTHmSBkyn8BYJbFIDwJQYhuizVmfcA4cWr7faqyTEf3u4jWot5a9h/Rw5PoXujzcBq NcKvjmY8J2m2J/D3v7mdA+ydhxFiW43pcEx6/47Z6CoRgvRHTSgLXxYWkJMjNMt9TNFO +ti5ohUQ306UnEUVp+YgK/6jR9GBn0bQEie57gavDaWOWfI3VfszkjCSaxEpdYHIDAfU rtrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723637545; x=1724242345; 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=tojuI0+mu7UKoZesL8YaT3fhKoLlaYzvyRRQYad9BGo=; b=CzVevXk7ysmwB/mOdvbXpOWDpejtlL61zqYrOZvmWD2NpCG1We97EpKmZCjoF4bINR bSQZ+YSNLBO2c4mgvayNCuDqzF8wf7/+7wt/uSwP5sbIsc6KXtQLtXzqCQ44DBMVc4wi aepTBjMf4/K0IAPmbkivReNwnQu8uJv5boHhREyz2j1/iRG9acwWAqIztvgR/ogSL/lP rNNdsUR6VsEzSgpQ5eyXGnUPhf0bKjuoQumeDIWp2ErgMT3GgNByWbyK7F8vfzp5oL9C ei9l+RcUECA05+73uCUwPGsPs+KiTD3Tcv7sdAPSND+3GSfHn4T/p0YqnR9Gm6bk8zeY Byqg== X-Gm-Message-State: AOJu0YxWRHmkYKQXTW6fmYY0oXBgs/mMqgbLAuFAyLU+TtrsO5YiDwu0 69BUZXnYaRFJbiavXRy8Lc/A1gB4eXAi3GhYeA1wwlkP9n6jEZBN2WCrwKo48I0= X-Google-Smtp-Source: AGHT+IHtyXdw9VpLRGQFS91cu8dGzirlGHtWJ07TV1QKDCR5BMf0Z9rqdLS2mdO+CRJ+lJTeiM5iAQ== X-Received: by 2002:a05:6a20:ce47:b0:1c3:a63a:cee3 with SMTP id adf61e73a8af0-1c8eae6f3b6mr3431933637.13.1723637544777; Wed, 14 Aug 2024 05:12:24 -0700 (PDT) Received: from Ubuntu.. ([106.205.236.194]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-710e5875200sm7195450b3a.37.2024.08.14.05.12.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 05:12:22 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 06/10] t-reftable-block: use xstrfmt() instead of xstrdup() Date: Wed, 14 Aug 2024 17:33:14 +0530 Message-ID: <20240814121122.4642-7-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240814121122.4642-1-chandrapratap3519@gmail.com> References: <20240814121122.4642-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 dfb7262a65..d762980589 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(n, ==, 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 14 12:03:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13763423 Received: from mail-oa1-f54.google.com (mail-oa1-f54.google.com [209.85.160.54]) (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 63F0B1AED37 for ; Wed, 14 Aug 2024 12:12:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723637550; cv=none; b=H4gnA9sfcTaevMiY9n6AgNURj+MW5aaEiY7zojHVHx4yz9SkLNR9LSnsTwTuGOHcsDPzYZtAMmeBfP+UTLynK/RDA4caygY6vyN5xfnRi5V2l7Sd/MrtexCuAW2rcAXZxus6JCNXcQKwlc76UyObh24DgAZdVRLiUzfn3n196cM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723637550; c=relaxed/simple; bh=Ql1RLguFhvUoAkW0a6q+TUK7Qjf8JMfO9d+stX6/2+I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TrhtED+B81B/7RwjJTz47/7qaqybZ+MvBVo5uSxLchc9pmq5lrNjL1S9KQ3V2ZNVmu0sSO7ifOezhgwY/jE/HDjZiovnwtGMfgSEnKcIdLxGhRUL0G+CfUYeR358Wfm6BAtcnN6p0aNXcNMYVAmjRFCzh6210vN1VliKFqUJs+s= 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=OPZ0I/38; arc=none smtp.client-ip=209.85.160.54 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="OPZ0I/38" Received: by mail-oa1-f54.google.com with SMTP id 586e51a60fabf-268daf61e8bso2835434fac.0 for ; Wed, 14 Aug 2024 05:12:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723637548; x=1724242348; 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=gAM1R0UwBXgNUfJHMnHJc4z2goyBuj4toSzbAz7L61s=; b=OPZ0I/38DqiNDT5J5QTfmixqlZ8FYLHG1ysBdjC3Pohxj2wlISO+CfYS707cMUkTAi Z1+CoCR5kK1ibNlGiMeVfQGXgB/rfEWpcnRqo+9Gz2ZhjM8Xm0shIo0bCKbXJlTIDmvI VAISI4bojwDQKVsUeWelFEqtlNt2XUoV+QHegOc7B24FsJA7r4/eWA13vteum5sING/j 7ni0bopsaeDZHQ61+8NPd26lZg8CEDTnVE2ocuOmkq9JBw1OtGQ+eaM8LbbaB39daxVu m6PYv8gxtOsOulSdi8u/qxGQhkbJUBGlX9Z65CQWpMEEFhWtAR2KjCmZFSZY20wE7QlU 3R6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723637548; x=1724242348; 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=gAM1R0UwBXgNUfJHMnHJc4z2goyBuj4toSzbAz7L61s=; b=fhlWcX9BCvSOdbS9jK9OvogpjdsI5tDi1zFEU4VxbkZ8/uVBrkj5n9fi1H88/sZHg4 TXTUBX6e7UhZZIWe6uBv+xg4IeENMzlqqXK7xmyAdhR3yU2aneLLH3OHZQMFHCgBXvtN XHtlRXH3a9SqgoBdiniYjQr9nJgJNcK0eu7D/jKTSTwZM95nr6izZMnqKONN4UlvKFIw jik1BPHlyyezKNwJpRmMdRhfpvQf2I5GAVb+KggfHkOhwEZslc3wld8m/crhXwWdOqn8 swOBAmSv2Y1026Jl086B51usyvxvP9PEOSlkfJYwZExjNiyG/TaX+I4UcBC7pjZ4iDvu Z/RA== X-Gm-Message-State: AOJu0YxFRYNM7sOCh+iPLoy1P4McTN+ikBr4P1jU2Ke/Ee4PoHhJo26Y HjCXhGpUahyZSctqCFkulHltBJe0BpI6N3k+KMmSBWHSsMGsTBfnzGzBd2VfKXk= X-Google-Smtp-Source: AGHT+IFYJiK5ETGds0+AUOENFg0POR0oUHzjysFTNLDwHLPbCgj69AkpR1fqjZhOUpB3L6p+cY4R9Q== X-Received: by 2002:a05:6870:d109:b0:261:1deb:f0ee with SMTP id 586e51a60fabf-26fe5a3d155mr3216160fac.13.1723637548053; Wed, 14 Aug 2024 05:12:28 -0700 (PDT) Received: from Ubuntu.. ([106.205.236.194]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-710e5875200sm7195450b3a.37.2024.08.14.05.12.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 05:12:27 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 07/10] t-reftable-block: remove unnecessary variable 'j' Date: Wed, 14 Aug 2024 17:33:15 +0530 Message-ID: <20240814121122.4642-8-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240814121122.4642-1-chandrapratap3519@gmail.com> References: <20240814121122.4642-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 d762980589..fa289e10f2 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 n; 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,13 +63,12 @@ static void t_block_read_write(void) block_iter_seek_start(&it, &br); - while (1) { + for (i = 0; ; i++) { int r = block_iter_next(&it, &rec); check_int(r, >=, 0); if (r > 0) 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 14 12:03:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13763424 Received: from mail-oa1-f43.google.com (mail-oa1-f43.google.com [209.85.160.43]) (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 517941AED37 for ; Wed, 14 Aug 2024 12:12:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723637553; cv=none; b=Rp+nTZehAwMesf6sDp9F2cgSSWGm9fHzkbGCwLloU2ReeQrkDhDh6B1tHIoEeT0glatkGRh+A70APreueW3Ov05t4m1vk2EIpbxNR1wjEzhC4KnXdOXPpJF5L9srXIOnr0QEn4gJWDFPKsLiJztBd3NoTutfgUHAibPKSJxaeXA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723637553; c=relaxed/simple; bh=Ov4eLVtm6yT9uOUCtV5vJuXg3nTmt8xFArm/NwqQ/hQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hSJL1IUgzMxVs8paoY1xKg3wK4ggpm+1WlII4sq0kmNPEb7tofMwPkZrSVAlNvYOHyp0Vz3PIMzhatmf7ROg8tossLz/MxPV5Juh6ZakCWgDHS62kBXzZjQHNv4XzLaPL8czTFuqS+xCtyt/NXQuwTfQTitwWA0ln6GcsIVGLb4= 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=NEdRpoT3; arc=none smtp.client-ip=209.85.160.43 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="NEdRpoT3" Received: by mail-oa1-f43.google.com with SMTP id 586e51a60fabf-268a9645e72so4525772fac.1 for ; Wed, 14 Aug 2024 05:12:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723637551; x=1724242351; 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=kKZXsDt2QUTqx5KDs/S2P2rC9mkkY4fDIDIWexniHKE=; b=NEdRpoT3YuR11dIbfAhjh3tipl343aUz6808qmtI4XEHg9lxqIciqV6OhqSVwR+RhQ cZA7l/GtkRUTJpaEVL3QxCo9gbYH5Y27ZTQGV9KhT1GDGTQWHkTSR6QHtAIt+1UoNZyk /VZH6E9dGoAAEnWIId/JxuQF6xabjJyKwXAGf6BT2ozGt6jO45zFlI5lZIueb/h3lukz zBksP+I+8Wau0bNPMFnXPTKbfzT+LQ8BudhOJWGz2sMBot5C8dqVQLBnaAsk+W8jaYgn 21lGRZVuKj+my0iPmC4FGwr7RHNNQqMmCwCmTCbD6czD/semT9YK1yMvVxJ+I0Y+f9Jq vlhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723637551; x=1724242351; 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=kKZXsDt2QUTqx5KDs/S2P2rC9mkkY4fDIDIWexniHKE=; b=vlKHdt7t1zh7GYgQTVRxG3azns37zH8+FWtjPflP7TE6IOX6aiEzP6Fa8iNGOSYn3o u1mLTrytnvLUQlBfDcdn9U9wAoebFN4nNAxlZyblucLSnRGHMlxIcWK0SCf3Zo4Z+RN0 SP3dBfKxuaWf4xDROyBJn+6EyxI3mZwjfwwP4EJY7KKkwXbdljrYi6shnHXXYqkqUKCR qKUD1WstdIGaWtb/PheHgzgLwSH/EFXxuL85Jof7BgdalkGgGqkKVAqxfFb1grG7p0rU pf2jqrh1+KiIKurgTd5gTXHTVVwCOnjGyBZ0lZSa2JYVqBinNjWqGEj+KzEgCNXzBSlH b2+w== X-Gm-Message-State: AOJu0YzAgLyed2QSLjlNh4GE5w1ruHSzcdDxHKJsHNcQjIqFspPbqiUr /LnX6DT/X+d7o/o56yPJERty/2ewq4Pcqj6uM2LpjogdygfHog/ifU2IoqMOBHo= X-Google-Smtp-Source: AGHT+IH6xYKtLQLMn2uyTM6Wc+rn9nv3CScz/9M7CNpwx0JUodfWuvYZtVBa97VUYKABozkF2w8ezg== X-Received: by 2002:a05:6870:4722:b0:260:f97d:6473 with SMTP id 586e51a60fabf-26fe5bb929fmr2595677fac.38.1723637551023; Wed, 14 Aug 2024 05:12:31 -0700 (PDT) Received: from Ubuntu.. ([106.205.236.194]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-710e5875200sm7195450b3a.37.2024.08.14.05.12.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 05:12:30 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 08/10] t-reftable-block: add tests for log blocks Date: Wed, 14 Aug 2024 17:33:16 +0530 Message-ID: <20240814121122.4642-9-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240814121122.4642-1-chandrapratap3519@gmail.com> References: <20240814121122.4642-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 | 90 ++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 2 deletions(-) diff --git a/t/unit-tests/t-reftable-block.c b/t/unit-tests/t-reftable-block.c index fa289e10f2..01ef10e7a6 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]; @@ -101,9 +101,95 @@ 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 n; + 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; + n = block_writer_add(&bw, &rec); + rec.u.log.refname = NULL; + rec.u.log.value_type = REFTABLE_LOG_DELETION; + check_int(n, ==, 0); + } + + n = block_writer_finish(&bw); + check_int(n, >, 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++) { + int r = block_iter_next(&it, &rec); + check_int(r, >=, 0); + if (r > 0) + 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); + + n = block_iter_seek_key(&it, &br, &want); + check_int(n, ==, 0); + + n = block_iter_next(&it, &rec); + check_int(n, ==, 0); + + check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ)); + + want.len--; + n = block_iter_seek_key(&it, &br, &want); + check_int(n, ==, 0); + + n = block_iter_next(&it, &rec); + check_int(n, ==, 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 Wed Aug 14 12:03:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13763425 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 CA1291B14E0 for ; Wed, 14 Aug 2024 12:12:34 +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=1723637556; cv=none; b=LDCNwMocSYbrOeLfGGKlNdCqRs68jSliPjK6rW/K9sQ3RNSGufBU/IScVHI6Dfts6PbQmByViDbCTEeZXkw92xm6UPwdk4gtNH0LzUcmQEAo31JKRRmRHUhaQHzrzyVbyOtRAnHRLT9N26iuuu64ZoYEE/tsGngQ6U3N+8C2ANA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723637556; c=relaxed/simple; bh=jCmSlQsEALm46t1imMVvfax0xwT6yTFSzu5OXBU/zPs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qUStu+4L4fcd9ZWqj/bP1HbgRTwjURRuUhZhoCdR0K5NGGCRZ0f6N+ymnjYChGQQ2u8Q0V4FPcBtJg4IsP02Eqgmd5IhOpjL6dVW2UTQWEeth6uQPbj4RskHHLgzFZ1nzDrncrNpLn6UntgzUOgpTwa7pnOhj8aa7owEN1whX3E= 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=Koz5mXVe; 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="Koz5mXVe" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-710dc3015bfso632605b3a.0 for ; Wed, 14 Aug 2024 05:12:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723637554; x=1724242354; 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=SalHpdCC/cBvZJeQzsN38DRBcGIUfg1wbGKqy+JZGqk=; b=Koz5mXVeTVRjxCLD90P6S97aEM4gRKbbo2zlszT7a1FjkbqQnV2yfkOf1ko6vE1tKV 6cQxj1q34i3Wox5BhbBgWWIwmZlacHcHN892eY0CD3CWdLXXOLvfiHTn5zorbDQewDSv DZZQXiP6nL9/pN3wSijLvM93Et+MnFbxMXGBEQr9uzudWH1frjYTqGCopWwdv3F8gOq4 0//Z4Ddrn0A3VfwQ66QKyg5ISUQcH++ja2hrtMCDjEQC15+5/vyVd8OPj1V4DWsecaSS khSoP+ID8PpnVGfQLARlgGl0B3piJMWh8a4OViP0tY+qezjYxXYYTPEI4BSTQwoS+g0f SPsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723637554; x=1724242354; 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=SalHpdCC/cBvZJeQzsN38DRBcGIUfg1wbGKqy+JZGqk=; b=N2GPOub0PKWbPVZrmbWgDW4a/SPLesF7xFIcIpaknzngp7ssEs6M1R9WS23euiBUPZ r6b++PrzXIO943ab0k/IlV2E5urb3R5gQx+gOo9TE5sOk8/cWXKWVD0gRO29q5P3oZ7X Ie8FRBaZBVcceGyiX4Y9jRXZfC7I/tNPPFm40EoDSQIJNgnUkLoNb2bjgXJomSnblzsN nRBfTCiSSWNrItS3R+hbl2tEuP6El/mDe7cZvTtkh7TJxVHtR78sDRcZwE2ULJ//30e7 otVsgZ9w4ALt5FThTp74hvKLzdyaB745c5LtkHi4Vfbj0BMd3jLuqGbOM9lVCiEhwulP stCQ== X-Gm-Message-State: AOJu0Yyc/aMkaRzrOTjhtH8bTK5xhapDWUbpgDf+euq2hrf82RHHQh9F kAyH4VLmiqXzqjbBDfWInz7hA/iIDxJ4jp0IftFuLyn/Vvbyp9fiyKsi2nKsWsE= X-Google-Smtp-Source: AGHT+IF18BHzIaZhR2ikYC64/1x2dhGiou6nFXH33V4UXkB9OKdiniYY033mSEe4y54NLL6vUhshvQ== X-Received: by 2002:aa7:88cd:0:b0:70d:2709:3b53 with SMTP id d2e1a72fcca58-7126a42247cmr3522777b3a.4.1723637553680; Wed, 14 Aug 2024 05:12:33 -0700 (PDT) Received: from Ubuntu.. ([106.205.236.194]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-710e5875200sm7195450b3a.37.2024.08.14.05.12.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 05:12:33 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 09/10] t-reftable-block: add tests for obj blocks Date: Wed, 14 Aug 2024 17:33:17 +0530 Message-ID: <20240814121122.4642-10-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240814121122.4642-1-chandrapratap3519@gmail.com> References: <20240814121122.4642-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 | 79 +++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/t/unit-tests/t-reftable-block.c b/t/unit-tests/t-reftable-block.c index 01ef10e7a6..34d37fe1a7 100644 --- a/t/unit-tests/t-reftable-block.c +++ b/t/unit-tests/t-reftable-block.c @@ -186,9 +186,88 @@ 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 n; + 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 = reftable_malloc(sizeof(uint8_t[5])); + memcpy(bytes, (uint8_t[]){i, i+1, i+2, i+3, i+5}, sizeof(uint8_t[5])); + + rec.u.obj.hash_prefix = bytes; + rec.u.obj.hash_prefix_len = 5; + + recs[i] = rec; + n = block_writer_add(&bw, &rec); + rec.u.obj.hash_prefix = NULL; + rec.u.obj.hash_prefix_len = 0; + check_int(n, ==, 0); + } + + n = block_writer_finish(&bw); + check_int(n, >, 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++) { + int r = block_iter_next(&it, &rec); + check_int(r, >=, 0); + if (r > 0) + 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); + + n = block_iter_seek_key(&it, &br, &want); + check_int(n, ==, 0); + + n = block_iter_next(&it, &rec); + check_int(n, ==, 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 Wed Aug 14 12:03:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13763426 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.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 4E4BF1B14F0 for ; Wed, 14 Aug 2024 12:12:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723637559; cv=none; b=liQu++a7/8jWIPcqS4GXn21EArN5HWX+nzOMll5UdH7FsWQSooxYkzNLggGk5hFTpZFls7is5yQld5TI36S+U9GtelSis+7yIag9un8v2ag+XvlqMYCoyYDQnqxXgFfZ+Wa9mC2PZELYb2q5qhWVS+taf9QPbEP6P2bdyBumoYY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723637559; c=relaxed/simple; bh=r/orRq5NVdr0A+yc+fafHvC7uvFN9YSPa15/C+bevEM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ks4nN5HQrXVL+4uaYwPFa/Y5C3YjoZ6/Dlisx0rnvNLChQGSCpf7DmRX8XwK6xVqCshfC/MvC+xfjjEu3aj84cC9FKluSayWfQFkouFe9c25nwnhNSfpfKOUtCLhQuCxIpoaam5jzD2ITJXDNFmthPtIAYUDgM+IpNxBRCBt6/w= 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=c/chfrBu; arc=none smtp.client-ip=209.85.210.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="c/chfrBu" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-7106e2d0ec1so4646939b3a.2 for ; Wed, 14 Aug 2024 05:12:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723637557; x=1724242357; 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=q/6ISN2bUz//ZFk79xAly2edYb7RZ/ZpJ9d6HEFUWZc=; b=c/chfrBu8aKZbPIjlnXFHZMEAUpPkOUQlZmm9rOhMUvmEFXVdnheJ3d07MR9neLHhp W+CI5PMHu2RawLtRbZskeQFLa/eNn74bpvlMl/qe/VxbGxvw/bHlEdC206YUKnAAYtW7 PJv9i6Vsg1wCXPmn+PMOULQafh/kF4zeLzfAFR0POS45bXVcvMiTE6MIq+C9ESqHGatb 6dlh5bIFJGBEPN//0pSRmJk3i8ARd21OhZwRVkg9gb8Ab//66Qc/1AOHz9pkVorHGSs9 Muz7Jfx7n5CClI4k7uXsRXueIRUF24E0esFCry04fIDeGyMo6Hs6eb88PPE6HT4rIusQ 7wfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723637557; x=1724242357; 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=q/6ISN2bUz//ZFk79xAly2edYb7RZ/ZpJ9d6HEFUWZc=; b=t5ZeBH2zkw/+F8IlzTy+oGmOP5y2GcQjC/B6uMjPiQkwmeO0tZqL/0ri8P+xvXnbRJ SYNRAGzg9nsqiP2ZEHmmOFJQx8X6PUpwYyspcis3cTdRCYkQwyzVoYwbfyJj/AGO67rK +TYYzFK0HKgS+jw6562Emo5XVkORzLM0bEj3/ajBdtkMU5wLKaHTosXdP8Hw5w24XZLr yhWkfGOY6IFE2ajB+vd29Q0Vm6m9Dk0O+s3j/LJg79I5KAQbsuovAJM+Rgkja/rROfoI IZ6rQnqYU5Osh4Gk0EyC1xa2xYdWtYVl7X5bn5EeUyReHquhi5yPFN1jDG/P1SNgURLF Aslw== X-Gm-Message-State: AOJu0YzURTbLbWQxH3SxuoLQesb7sNOp0mV1/3UUoHkXL9WEMmmhkrr+ t+m4NdHXDSL4+MG1fQHBC2GsPyLzJrzC8luRRqNoSnPGm8QyJNyEvLxzvX85mXc= X-Google-Smtp-Source: AGHT+IGhDlZrLEVp2vvOyekK0kES2fDogNFUfD37x3Qk3nq+DlS67XZ4a6hEjvpjt2fj96XVE5gL3Q== X-Received: by 2002:a05:6a00:2193:b0:706:726b:ae60 with SMTP id d2e1a72fcca58-712671242c5mr3149369b3a.17.1723637557258; Wed, 14 Aug 2024 05:12:37 -0700 (PDT) Received: from Ubuntu.. ([106.205.236.194]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-710e5875200sm7195450b3a.37.2024.08.14.05.12.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 05:12:36 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 10/10] t-reftable-block: add tests for index blocks Date: Wed, 14 Aug 2024 17:33:18 +0530 Message-ID: <20240814121122.4642-11-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240814121122.4642-1-chandrapratap3519@gmail.com> References: <20240814121122.4642-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 | 85 +++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/t/unit-tests/t-reftable-block.c b/t/unit-tests/t-reftable-block.c index 34d37fe1a7..bbf6a5371e 100644 --- a/t/unit-tests/t-reftable-block.c +++ b/t/unit-tests/t-reftable-block.c @@ -264,8 +264,93 @@ 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 n; + 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; + + n = block_writer_add(&bw, &recs[i]); + check_int(n, ==, 0); + } + + n = block_writer_finish(&bw); + check_int(n, >, 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++) { + int r = block_iter_next(&it, &rec); + check_int(r, >=, 0); + if (r > 0) + 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); + + n = block_iter_seek_key(&it, &br, &want); + check_int(n, ==, 0); + + n = block_iter_next(&it, &rec); + check_int(n, ==, 0); + + check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ)); + + want.len--; + n = block_iter_seek_key(&it, &br, &want); + check_int(n, ==, 0); + + n = block_iter_next(&it, &rec); + check_int(n, ==, 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");