From patchwork Fri Jul 12 05:38:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13731283 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 80A35182A0 for ; Fri, 12 Jul 2024 05:51:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720763481; cv=none; b=Une1TSUiq6pYSBaT/jvKLccHAysSSzghnPR4Nu7JcxmkcIpec8onZ/D3T9UVRH8ZOLOkMX5Z7vZHEdMlEkjwl00x1Zb2M4TNl538mw6EF4Q8PNO9FVY7hC5VYR5rLjNsbFTSC+QRf6xG1vrt6S5YCA+CwkbtmNSBdawkC4QDn0U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720763481; c=relaxed/simple; bh=Ud1CcjKOs+sEQrYwDefKahcPEB3Uedzcz0eHMFs8log=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RouwHXXEGBiP/EVPMDE4L2Be0mv1JYojeL7yhJZce3RmkjzVIPxmrg8lqpKWXgX6L4zdhD3sXX8tIt1P6x1dq7o/pbAN4mLPja9KTB1gRq+CzC4PSiU0hV+CG3SlEPXWGZhQYJM87Tw7ilNsJsbxXuVVExSr3xN0D49nVk0Kot0= 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=kubTuX1x; arc=none smtp.client-ip=209.85.210.175 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="kubTuX1x" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-70b702be5e4so159465b3a.0 for ; Thu, 11 Jul 2024 22:51:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720763478; x=1721368278; 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=cM7SAR5JILsoFVvosMlVXxM2q2+Fn8FnYkBHmSnMvrI=; b=kubTuX1x7KN+FN5TxOmsBLxxiKq0BfDY2JBUr824ZWEJe/qCbnA+HGzjyU8AYPcNhp 6hwOE4tK8+tWAX3lE+I5xsOCNvOIbkZeghT1daqjfJv1nZsnBL0WUwvCrsGPgVoe1DZG EkbHEXhHqJvlOq74N8KxImt2+SyR3rgPq16/188y1mAmBOl0Y4PXSK2fRHbuiZkrvp0X 28KCF0G1vOVO9EqCnsO/vsENdbVkGqNyXrj0clbF1rHO/6RY2iisEjy9xmvCtzgkeqxq ug4+fbEE4GOPaVAobGaz9U8VtGEdUzpULTkEZnRkTF5L2nHKqdmPVXtjVoAabumpalcF tYOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720763478; x=1721368278; 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=cM7SAR5JILsoFVvosMlVXxM2q2+Fn8FnYkBHmSnMvrI=; b=GRj/JCzJYfL7gMdy8gRDNrwY6W5wvP8FpYmqedGPGnILGRTEu+Q/UylBMxaJF6fbhx OvIF5a31rQBnvo+1fNClxxtCW0MlwUhdnm8xjl/ai2CjLHhBwU6AkuNl7f7T6PnHjmgD td3AZFoMXk5sKhIBkZwb+tbu1DIlMyyD1ATAGpFqoatqklMI3XRoE1geCYr/wcLvsHkc mPPPVUxLk72maqgBIlCuOuP5yr590tAjFAzDvehSxWbbRDiNduJd29mJ0pbLtB5rZCWb LsYAVTanE4LjYnkpIV32AoOEYT1HYsslBb7Qqp606A1cgNQ4fcGu9k9rMwMAV4D52qXs 5Lsg== X-Gm-Message-State: AOJu0YxicXdk0DzzgbAquyg40XvlZnvL3lW13MXmhExp2B9PYMJAM5Q6 touQpwZjbnua9bauAFb7CIw8obIYmjurSQcs6HW0kkxBVCzPmkScw+zIYQ== X-Google-Smtp-Source: AGHT+IHSX2BFpgemwXVsO+IaaIi8NkVkCcCLjzJ/iMZ3M65EQo88AJDylZ4l+uTZ5fzmbKfNec6wuA== X-Received: by 2002:a05:6a00:4b12:b0:704:2f65:4996 with SMTP id d2e1a72fcca58-70b43543af1mr12681934b3a.11.1720763477841; Thu, 11 Jul 2024 22:51:17 -0700 (PDT) Received: from Ubuntu.. ([117.96.148.106]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70b4397f475sm6604651b3a.150.2024.07.11.22.51.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 22:51:17 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, chriscool@tuxfamily.org Subject: [PATCH v4 1/7] t: move reftable/merged_test.c to the unit testing framework Date: Fri, 12 Jul 2024 11:08:57 +0530 Message-ID: <20240712055041.6476-2-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240712055041.6476-1-chandrapratap3519@gmail.com> References: <20240711040854.4602-1-chandrapratap3519@gmail.com> <20240712055041.6476-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 reftable/merged_test.c exercises the functions defined in reftable/merged.{c, h}. Migrate reftable/merged_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 according to unit-tests' naming conventions. Also, move strbuf_add_void() and noop_flush() from reftable/test_framework.c to the ported test. This is because both these functions are used in the merged tests and reftable/test_framework.{c, h} is not #included in the ported test. 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-merged.c | 113 +++++++++--------- 4 files changed, 60 insertions(+), 57 deletions(-) rename reftable/merged_test.c => t/unit-tests/t-reftable-merged.c (84%) diff --git a/Makefile b/Makefile index 3eab701b10..e5d1b53991 100644 --- a/Makefile +++ b/Makefile @@ -1340,6 +1340,7 @@ UNIT_TEST_PROGRAMS += t-mem-pool UNIT_TEST_PROGRAMS += t-oidtree UNIT_TEST_PROGRAMS += t-prio-queue UNIT_TEST_PROGRAMS += t-reftable-basics +UNIT_TEST_PROGRAMS += t-reftable-merged UNIT_TEST_PROGRAMS += t-strbuf UNIT_TEST_PROGRAMS += t-strcmp-offset UNIT_TEST_PROGRAMS += t-strvec @@ -2679,7 +2680,6 @@ REFTABLE_OBJS += reftable/writer.o REFTABLE_TEST_OBJS += reftable/block_test.o REFTABLE_TEST_OBJS += reftable/dump.o -REFTABLE_TEST_OBJS += reftable/merged_test.o REFTABLE_TEST_OBJS += reftable/pq_test.o REFTABLE_TEST_OBJS += reftable/record_test.o REFTABLE_TEST_OBJS += reftable/readwrite_test.o diff --git a/reftable/reftable-tests.h b/reftable/reftable-tests.h index 114cc3d053..d5e03dcc1b 100644 --- a/reftable/reftable-tests.h +++ b/reftable/reftable-tests.h @@ -11,7 +11,6 @@ license that can be found in the LICENSE file or at int basics_test_main(int argc, const char **argv); int block_test_main(int argc, const char **argv); -int merged_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 9160bc5da6..0357718fa8 100644 --- a/t/helper/test-reftable.c +++ b/t/helper/test-reftable.c @@ -10,7 +10,6 @@ int cmd__reftable(int argc, const char **argv) tree_test_main(argc, argv); pq_test_main(argc, argv); readwrite_test_main(argc, argv); - merged_test_main(argc, argv); stack_test_main(argc, argv); return 0; } diff --git a/reftable/merged_test.c b/t/unit-tests/t-reftable-merged.c similarity index 84% rename from reftable/merged_test.c rename to t/unit-tests/t-reftable-merged.c index a9d6661c13..78a864a54f 100644 --- a/reftable/merged_test.c +++ b/t/unit-tests/t-reftable-merged.c @@ -6,20 +6,25 @@ license that can be found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd */ -#include "merged.h" - -#include "system.h" +#include "test-lib.h" +#include "reftable/blocksource.h" +#include "reftable/constants.h" +#include "reftable/merged.h" +#include "reftable/reader.h" +#include "reftable/reftable-generic.h" +#include "reftable/reftable-merged.h" +#include "reftable/reftable-writer.h" + +static ssize_t strbuf_add_void(void *b, const void *data, size_t sz) +{ + strbuf_add(b, data, sz); + return sz; +} -#include "basics.h" -#include "blocksource.h" -#include "constants.h" -#include "reader.h" -#include "record.h" -#include "test_framework.h" -#include "reftable-merged.h" -#include "reftable-tests.h" -#include "reftable-generic.h" -#include "reftable-writer.h" +static int noop_flush(void *arg) +{ + return 0; +} static void write_test_table(struct strbuf *buf, struct reftable_ref_record refs[], int n) @@ -49,12 +54,12 @@ static void write_test_table(struct strbuf *buf, for (i = 0; i < n; i++) { uint64_t before = refs[i].update_index; int n = reftable_writer_add_ref(w, &refs[i]); - EXPECT(n == 0); - EXPECT(before == refs[i].update_index); + check_int(n, ==, 0); + check_int(before, ==, refs[i].update_index); } err = reftable_writer_close(w); - EXPECT_ERR(err); + check(!err); reftable_writer_free(w); } @@ -76,11 +81,11 @@ static void write_test_log_table(struct strbuf *buf, for (i = 0; i < n; i++) { int err = reftable_writer_add_log(w, &logs[i]); - EXPECT_ERR(err); + check(!err); } err = reftable_writer_close(w); - EXPECT_ERR(err); + check(!err); reftable_writer_free(w); } @@ -105,12 +110,12 @@ merged_table_from_records(struct reftable_ref_record **refs, err = reftable_new_reader(&(*readers)[i], &(*source)[i], "name"); - EXPECT_ERR(err); + check(!err); reftable_table_from_reader(&tabs[i], (*readers)[i]); } err = reftable_new_merged_table(&mt, tabs, n, GIT_SHA1_FORMAT_ID); - EXPECT_ERR(err); + check(!err); return mt; } @@ -122,7 +127,7 @@ static void readers_destroy(struct reftable_reader **readers, size_t n) reftable_free(readers); } -static void test_merged_between(void) +static void t_merged_single_record(void) { struct reftable_ref_record r1[] = { { .refname = (char *) "b", @@ -150,11 +155,11 @@ static void test_merged_between(void) merged_table_init_iter(mt, &it, BLOCK_TYPE_REF); err = reftable_iterator_seek_ref(&it, "a"); - EXPECT_ERR(err); + check(!err); err = reftable_iterator_next_ref(&it, &ref); - EXPECT_ERR(err); - EXPECT(ref.update_index == 2); + check(!err); + check_int(ref.update_index, ==, 2); reftable_ref_record_release(&ref); reftable_iterator_destroy(&it); readers_destroy(readers, 2); @@ -165,7 +170,7 @@ static void test_merged_between(void) reftable_free(bs); } -static void test_merged(void) +static void t_merged_refs(void) { struct reftable_ref_record r1[] = { { @@ -230,9 +235,9 @@ static void test_merged(void) merged_table_init_iter(mt, &it, BLOCK_TYPE_REF); err = reftable_iterator_seek_ref(&it, "a"); - EXPECT_ERR(err); - EXPECT(reftable_merged_table_hash_id(mt) == GIT_SHA1_FORMAT_ID); - EXPECT(reftable_merged_table_min_update_index(mt) == 1); + check(!err); + check_int(reftable_merged_table_hash_id(mt), ==, GIT_SHA1_FORMAT_ID); + check_int(reftable_merged_table_min_update_index(mt), ==, 1); while (len < 100) { /* cap loops/recursion. */ struct reftable_ref_record ref = { NULL }; @@ -245,9 +250,9 @@ static void test_merged(void) } reftable_iterator_destroy(&it); - EXPECT(ARRAY_SIZE(want) == len); + check_int(ARRAY_SIZE(want), ==, len); for (i = 0; i < len; i++) { - EXPECT(reftable_ref_record_equal(want[i], &out[i], + check(reftable_ref_record_equal(want[i], &out[i], GIT_SHA1_RAWSZ)); } for (i = 0; i < len; i++) { @@ -283,16 +288,16 @@ merged_table_from_log_records(struct reftable_log_record **logs, err = reftable_new_reader(&(*readers)[i], &(*source)[i], "name"); - EXPECT_ERR(err); + check(!err); reftable_table_from_reader(&tabs[i], (*readers)[i]); } err = reftable_new_merged_table(&mt, tabs, n, GIT_SHA1_FORMAT_ID); - EXPECT_ERR(err); + check(!err); return mt; } -static void test_merged_logs(void) +static void t_merged_logs(void) { struct reftable_log_record r1[] = { { @@ -362,9 +367,9 @@ static void test_merged_logs(void) merged_table_init_iter(mt, &it, BLOCK_TYPE_LOG); err = reftable_iterator_seek_log(&it, "a"); - EXPECT_ERR(err); - EXPECT(reftable_merged_table_hash_id(mt) == GIT_SHA1_FORMAT_ID); - EXPECT(reftable_merged_table_min_update_index(mt) == 1); + check(!err); + check_int(reftable_merged_table_hash_id(mt), ==, GIT_SHA1_FORMAT_ID); + check_int(reftable_merged_table_min_update_index(mt), ==, 1); while (len < 100) { /* cap loops/recursion. */ struct reftable_log_record log = { NULL }; @@ -377,19 +382,19 @@ static void test_merged_logs(void) } reftable_iterator_destroy(&it); - EXPECT(ARRAY_SIZE(want) == len); + check_int(ARRAY_SIZE(want), ==, len); for (i = 0; i < len; i++) { - EXPECT(reftable_log_record_equal(want[i], &out[i], + check(reftable_log_record_equal(want[i], &out[i], GIT_SHA1_RAWSZ)); } merged_table_init_iter(mt, &it, BLOCK_TYPE_LOG); err = reftable_iterator_seek_log_at(&it, "a", 2); - EXPECT_ERR(err); + check(!err); reftable_log_record_release(&out[0]); err = reftable_iterator_next_log(&it, &out[0]); - EXPECT_ERR(err); - EXPECT(reftable_log_record_equal(&out[0], &r3[0], GIT_SHA1_RAWSZ)); + check(!err); + check(reftable_log_record_equal(&out[0], &r3[0], GIT_SHA1_RAWSZ)); reftable_iterator_destroy(&it); for (i = 0; i < len; i++) { @@ -405,7 +410,7 @@ static void test_merged_logs(void) reftable_free(bs); } -static void test_default_write_opts(void) +static void t_default_write_opts(void) { struct reftable_write_options opts = { 0 }; struct strbuf buf = STRBUF_INIT; @@ -426,36 +431,36 @@ static void test_default_write_opts(void) reftable_writer_set_limits(w, 1, 1); err = reftable_writer_add_ref(w, &rec); - EXPECT_ERR(err); + check(!err); err = reftable_writer_close(w); - EXPECT_ERR(err); + check(!err); reftable_writer_free(w); block_source_from_strbuf(&source, &buf); err = reftable_new_reader(&rd, &source, "filename"); - EXPECT_ERR(err); + check(!err); hash_id = reftable_reader_hash_id(rd); - EXPECT(hash_id == GIT_SHA1_FORMAT_ID); + check_int(hash_id, ==, GIT_SHA1_FORMAT_ID); reftable_table_from_reader(&tab[0], rd); err = reftable_new_merged_table(&merged, tab, 1, GIT_SHA1_FORMAT_ID); - EXPECT_ERR(err); + check(!err); reftable_reader_free(rd); reftable_merged_table_free(merged); strbuf_release(&buf); } -/* XXX test refs_for(oid) */ -int merged_test_main(int argc, const char *argv[]) +int cmd_main(int argc, const char *argv[]) { - RUN_TEST(test_merged_logs); - RUN_TEST(test_merged_between); - RUN_TEST(test_merged); - RUN_TEST(test_default_write_opts); - return 0; + TEST(t_default_write_opts(), "merged table with default write opts"); + TEST(t_merged_logs(), "merged table with multiple log updates for same ref"); + TEST(t_merged_refs(), "merged table with multiple updates to same ref"); + TEST(t_merged_single_record(), "ref ocurring in only one record can be fetched"); + + return test_done(); } From patchwork Fri Jul 12 05:38:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13731284 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 6677018044 for ; Fri, 12 Jul 2024 05:51:21 +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=1720763483; cv=none; b=uy1dFqnoI4kJHhsIaQiAsUsIHrJExqWqGPygghjkSLcC4bJZOB9HzEp8eL4/sUZXaSh4JYyLpRN7ifgK05nTrJNGOVoXvAucg2rZUdnaJ0q2zGyUGrS9gDWsR1SMaI8vrYyfPTVHyHbFPIIW7MGepvqtwHI9DO3PnSqwg6zkJEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720763483; c=relaxed/simple; bh=x9qTqgFDH8brbGUfMgATpo/0EY6VjEh1JxT3a4iyHjQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gXJM9Rn0vDwzH0r+5UeaWD/zYvZVj6ZdaKAQzhAhZ9r0huL+E6gmWRGc2K4n1GRBElp9daWcR7QbrZPgPw5G0T86v8troM+GfjRmEAH3wuQeJIMsrw5RN2Cmk2SEKQa6GlxcMR63306JzhfWQtkH3WgDjRUcd+drMGttwIr4ch4= 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=jUBuuWll; 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="jUBuuWll" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-70b5117ae06so1257953b3a.2 for ; Thu, 11 Jul 2024 22:51:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720763480; x=1721368280; 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=qZ3CxG+DYTEAVgOP0dqoO8ewH480oDIKciMtDvo1YO0=; b=jUBuuWllIZH/UMZtWSvWwR46D4VyrSTcMWo8kdoKL/bV8zQQ84ezjOpCADwcb4Tb94 uO7Zoq7JfJvelCiMywkFYC/5bBtLBloiSi5I0XrMcsIc5R9UzaVIBL3D1zo9i+2GcG4K ymoyIekpLC/6dPOOfGnRirXh9L6qchU0qLJdEa7o69fot+075xT/u4SO2xqFGv8y6LSW u8KzxfFWx04ivMkNhMvdFVaMocURFN5/RywlJ9qXGbvii6/HGY/b4wrX3to6j9Ll79GN ZAFDCyA9p7rgSH/lfJz1BLV+N7Kuvg3F2XY9NmiVN97O1MYf1M9038usepKCAIK/xdUb 1HNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720763480; x=1721368280; 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=qZ3CxG+DYTEAVgOP0dqoO8ewH480oDIKciMtDvo1YO0=; b=Ht+1LD2ykAcD0yjKgMqziQg2qsFlp2jykNatkbKqdD1xUYj+pvUUO7O44Urya4cD/9 lPiO2Mq2SOjOCk/Dc5pzr+KNoDKXP5Vx0eVPf9nfwKeJnPQAFFUlT4AoczEFtFEWlrRG KafoIGaNH28r7cbTXLdGUpeGtgu65i7lfZFo81EVQ4Lgs21gJUtSgKfHw/lOfqfQynp3 rOsSdqnYYTlLvn9KzB+1S4aYtiCVU8ML7iml/N2CoWvwz/gUlCTvZcV3gNQFgCIKDQit RgB9D03YpGGTRQhKSgKS5fu3GZWOTpzA/XcCaYUpgQzsS4skw5BbBndl/jiCF3WMParq Zv5w== X-Gm-Message-State: AOJu0YyPDRjQ5TxjgzjNp3dMfIyOSxJBRNoAIKQwnhoo7FSocMyAQGgy 2m1cl4in0aABZ7zHtwoF0/Jl7u18PkfzflGM0931oZZ+4nA1C96dCb+bIQ== X-Google-Smtp-Source: AGHT+IFd3fu2EyfTv1XNKpRd552wFF5Hut/dLwgfiIgZICWOZK4tNloK7CABUYTsH3rQcsQRpVJpcQ== X-Received: by 2002:a05:6a00:1810:b0:706:7276:6287 with SMTP id d2e1a72fcca58-70b434f34c8mr13949125b3a.1.1720763480199; Thu, 11 Jul 2024 22:51:20 -0700 (PDT) Received: from Ubuntu.. ([117.96.148.106]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70b4397f475sm6604651b3a.150.2024.07.11.22.51.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 22:51:19 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, chriscool@tuxfamily.org Subject: [PATCH v4 2/7] t: harmonize t-reftable-merged.c with coding guidelines Date: Fri, 12 Jul 2024 11:08:58 +0530 Message-ID: <20240712055041.6476-3-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240712055041.6476-1-chandrapratap3519@gmail.com> References: <20240711040854.4602-1-chandrapratap3519@gmail.com> <20240712055041.6476-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-merged.c with the following guidelines: - Single line control flow statements like 'for' and 'if' must omit curly braces. - Structs must be 0-initialized with '= { 0 }' instead of '= { NULL }'. - Array indices should preferably be of type 'size_t', not 'int'. - It is fine to use C99 initial declaration in 'for' loop. While at it, use 'ARRAY_SIZE(x)' to store the number of elements in an array instead of hardcoding them. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-merged.c | 68 +++++++++++++------------------- 1 file changed, 28 insertions(+), 40 deletions(-) diff --git a/t/unit-tests/t-reftable-merged.c b/t/unit-tests/t-reftable-merged.c index 78a864a54f..9791f53418 100644 --- a/t/unit-tests/t-reftable-merged.c +++ b/t/unit-tests/t-reftable-merged.c @@ -27,11 +27,11 @@ static int noop_flush(void *arg) } static void write_test_table(struct strbuf *buf, - struct reftable_ref_record refs[], int n) + struct reftable_ref_record refs[], size_t n) { uint64_t min = 0xffffffff; uint64_t max = 0; - int i = 0; + size_t i; int err; struct reftable_write_options opts = { @@ -40,12 +40,10 @@ static void write_test_table(struct strbuf *buf, struct reftable_writer *w = NULL; for (i = 0; i < n; i++) { uint64_t ui = refs[i].update_index; - if (ui > max) { + if (ui > max) max = ui; - } - if (ui < min) { + if (ui < min) min = ui; - } } w = reftable_new_writer(&strbuf_add_void, &noop_flush, buf, &opts); @@ -65,10 +63,9 @@ static void write_test_table(struct strbuf *buf, } static void write_test_log_table(struct strbuf *buf, - struct reftable_log_record logs[], int n, + struct reftable_log_record logs[], size_t n, uint64_t update_index) { - int i = 0; int err; struct reftable_write_options opts = { @@ -79,7 +76,7 @@ static void write_test_log_table(struct strbuf *buf, w = reftable_new_writer(&strbuf_add_void, &noop_flush, buf, &opts); reftable_writer_set_limits(w, update_index, update_index); - for (i = 0; i < n; i++) { + for (size_t i = 0; i < n; i++) { int err = reftable_writer_add_log(w, &logs[i]); check(!err); } @@ -93,7 +90,7 @@ static void write_test_log_table(struct strbuf *buf, static struct reftable_merged_table * merged_table_from_records(struct reftable_ref_record **refs, struct reftable_block_source **source, - struct reftable_reader ***readers, int *sizes, + struct reftable_reader ***readers, size_t *sizes, struct strbuf *buf, size_t n) { struct reftable_merged_table *mt = NULL; @@ -121,8 +118,7 @@ merged_table_from_records(struct reftable_ref_record **refs, static void readers_destroy(struct reftable_reader **readers, size_t n) { - int i = 0; - for (; i < n; i++) + for (size_t i = 0; i < n; i++) reftable_reader_free(readers[i]); reftable_free(readers); } @@ -142,15 +138,14 @@ static void t_merged_single_record(void) } }; struct reftable_ref_record *refs[] = { r1, r2 }; - int sizes[] = { 1, 1 }; + size_t sizes[] = { ARRAY_SIZE(r1), ARRAY_SIZE(r2) }; struct strbuf bufs[2] = { STRBUF_INIT, STRBUF_INIT }; struct reftable_block_source *bs = NULL; struct reftable_reader **readers = NULL; struct reftable_merged_table *mt = merged_table_from_records(refs, &bs, &readers, sizes, bufs, 2); - int i; - struct reftable_ref_record ref = { NULL }; - struct reftable_iterator it = { NULL }; + struct reftable_ref_record ref = { 0 }; + struct reftable_iterator it = { 0 }; int err; merged_table_init_iter(mt, &it, BLOCK_TYPE_REF); @@ -164,9 +159,8 @@ static void t_merged_single_record(void) reftable_iterator_destroy(&it); readers_destroy(readers, 2); reftable_merged_table_free(mt); - for (i = 0; i < ARRAY_SIZE(bufs); i++) { + for (size_t i = 0; i < ARRAY_SIZE(bufs); i++) strbuf_release(&bufs[i]); - } reftable_free(bs); } @@ -220,18 +214,18 @@ static void t_merged_refs(void) }; struct reftable_ref_record *refs[] = { r1, r2, r3 }; - int sizes[3] = { 3, 1, 2 }; + size_t sizes[3] = { ARRAY_SIZE(r1), ARRAY_SIZE(r2), ARRAY_SIZE(r3) }; struct strbuf bufs[3] = { STRBUF_INIT, STRBUF_INIT, STRBUF_INIT }; struct reftable_block_source *bs = NULL; struct reftable_reader **readers = NULL; struct reftable_merged_table *mt = merged_table_from_records(refs, &bs, &readers, sizes, bufs, 3); - struct reftable_iterator it = { NULL }; + struct reftable_iterator it = { 0 }; int err; struct reftable_ref_record *out = NULL; size_t len = 0; size_t cap = 0; - int i = 0; + size_t i; merged_table_init_iter(mt, &it, BLOCK_TYPE_REF); err = reftable_iterator_seek_ref(&it, "a"); @@ -240,7 +234,7 @@ static void t_merged_refs(void) check_int(reftable_merged_table_min_update_index(mt), ==, 1); while (len < 100) { /* cap loops/recursion. */ - struct reftable_ref_record ref = { NULL }; + struct reftable_ref_record ref = { 0 }; int err = reftable_iterator_next_ref(&it, &ref); if (err > 0) break; @@ -251,18 +245,15 @@ static void t_merged_refs(void) reftable_iterator_destroy(&it); check_int(ARRAY_SIZE(want), ==, len); - for (i = 0; i < len; i++) { + for (i = 0; i < len; i++) check(reftable_ref_record_equal(want[i], &out[i], GIT_SHA1_RAWSZ)); - } - for (i = 0; i < len; i++) { + for (i = 0; i < len; i++) reftable_ref_record_release(&out[i]); - } reftable_free(out); - for (i = 0; i < 3; i++) { + for (i = 0; i < 3; i++) strbuf_release(&bufs[i]); - } readers_destroy(readers, 3); reftable_merged_table_free(mt); reftable_free(bs); @@ -271,7 +262,7 @@ static void t_merged_refs(void) static struct reftable_merged_table * merged_table_from_log_records(struct reftable_log_record **logs, struct reftable_block_source **source, - struct reftable_reader ***readers, int *sizes, + struct reftable_reader ***readers, size_t *sizes, struct strbuf *buf, size_t n) { struct reftable_merged_table *mt = NULL; @@ -352,18 +343,18 @@ static void t_merged_logs(void) }; struct reftable_log_record *logs[] = { r1, r2, r3 }; - int sizes[3] = { 2, 1, 1 }; + size_t sizes[3] = { ARRAY_SIZE(r1), ARRAY_SIZE(r2), ARRAY_SIZE(r3) }; struct strbuf bufs[3] = { STRBUF_INIT, STRBUF_INIT, STRBUF_INIT }; struct reftable_block_source *bs = NULL; struct reftable_reader **readers = NULL; struct reftable_merged_table *mt = merged_table_from_log_records( logs, &bs, &readers, sizes, bufs, 3); - struct reftable_iterator it = { NULL }; + struct reftable_iterator it = { 0 }; int err; struct reftable_log_record *out = NULL; size_t len = 0; size_t cap = 0; - int i = 0; + size_t i; merged_table_init_iter(mt, &it, BLOCK_TYPE_LOG); err = reftable_iterator_seek_log(&it, "a"); @@ -372,7 +363,7 @@ static void t_merged_logs(void) check_int(reftable_merged_table_min_update_index(mt), ==, 1); while (len < 100) { /* cap loops/recursion. */ - struct reftable_log_record log = { NULL }; + struct reftable_log_record log = { 0 }; int err = reftable_iterator_next_log(&it, &log); if (err > 0) break; @@ -383,10 +374,9 @@ static void t_merged_logs(void) reftable_iterator_destroy(&it); check_int(ARRAY_SIZE(want), ==, len); - for (i = 0; i < len; i++) { + for (i = 0; i < len; i++) check(reftable_log_record_equal(want[i], &out[i], GIT_SHA1_RAWSZ)); - } merged_table_init_iter(mt, &it, BLOCK_TYPE_LOG); err = reftable_iterator_seek_log_at(&it, "a", 2); @@ -397,14 +387,12 @@ static void t_merged_logs(void) check(reftable_log_record_equal(&out[0], &r3[0], GIT_SHA1_RAWSZ)); reftable_iterator_destroy(&it); - for (i = 0; i < len; i++) { + for (i = 0; i < len; i++) reftable_log_record_release(&out[i]); - } reftable_free(out); - for (i = 0; i < 3; i++) { + for (i = 0; i < 3; i++) strbuf_release(&bufs[i]); - } readers_destroy(readers, 3); reftable_merged_table_free(mt); reftable_free(bs); @@ -422,7 +410,7 @@ static void t_default_write_opts(void) .update_index = 1, }; int err; - struct reftable_block_source source = { NULL }; + struct reftable_block_source source = { 0 }; struct reftable_table *tab = reftable_calloc(1, sizeof(*tab)); uint32_t hash_id; struct reftable_reader *rd = NULL; From patchwork Fri Jul 12 05:38:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13731286 Received: from mail-oa1-f49.google.com (mail-oa1-f49.google.com [209.85.160.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD7231B95B for ; Fri, 12 Jul 2024 05:51:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720763485; cv=none; b=m3cDJHQFIJ43Ebi38FAXNqs6gCb7F47M0/g7ggfrF244HK+r10gjBh4wW1KsfxAh9ssNtuSdCJoxhY7WnrG/GtXu5uGSGV50mNuX33/NKHNHheglFc5Ed1lxu0Wg5bnIsayHmkO559TWUvVTHYbKSebo02by5eFEZZ4Jfs00KrE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720763485; c=relaxed/simple; bh=f2Sbh2heCKQcNJ8mb2dmVaRoUS33YqrWMcVpX1q1SMI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ijtqi75V8l8c89LvXBzamQTNWIRneTdj0iZtYi8ViGlFqWkqJzeZu7h8xGzs0T6iBaHi8UuZc/+ofS2e6WZWHizaGdeVcvHP1o27SSb0rnVnouva7/zsSDBmpQjgmN2J/adPszJ4ErEpSJNEr6qLY5h4+U3SbkIhJVMimmWl5IY= 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=CzsO1/8a; arc=none smtp.client-ip=209.85.160.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CzsO1/8a" Received: by mail-oa1-f49.google.com with SMTP id 586e51a60fabf-24c9f6338a4so790310fac.1 for ; Thu, 11 Jul 2024 22:51:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720763483; x=1721368283; 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=lgJJBde9ffSE7VKVjTMj0Hursv5/fM5fL/5VoEKfEgE=; b=CzsO1/8aGtINRQzyUpqP9BI4d03Ei5/klTXq3PgSjHO8qZxLPKTfXNKo5TAExmS9ZN fhJy8DySx2vZvV5ugXufh7xYiZ7+ukEzHB3NHVtgVkhLUGMJGH/HV0Xl6p5e43X+7GYt 8as2keqX89vf5C2iH60ru2Ad66YIzf7Ae3yWsop0e0MGt5+mVsr7ga+y5ssl1RCePMZz RJiEo9WVDMcw0i+FlxLVDtvQDmHKxcUruw/qLlJOZiBtevRCYLN2mIr6X92760DuIIvE o7prvaApLtSitzPtCq2DCs66cLcyQtYDRFJJj+tDuc5hsxRoBJlxQffrrirNI5zAuVnC VqzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720763483; x=1721368283; 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=lgJJBde9ffSE7VKVjTMj0Hursv5/fM5fL/5VoEKfEgE=; b=NTA4gvmikPLez54Hk2gRllg4VXFt4AFfX/zdRCMiN4AN8Yzx8iBNxx+lxyUCS0aTOu hQoTZ/apvj2+xQFKDfCQBGe3dLpqWoDy0Yu3mTcCWmVjlgrh99gPpFuZe0H9+c0+/PzG azP6ZPDD3ja/UcQvWjmni36UQG43ph4Rs2eD7EUAfmLH+dqWmIOAietRjJDq/f33NO6G RNc2XWvyQSN7WK+KWI4WMQ2yoygGqEZznizGz3avnPGNuU4SOWRA1H1tuQ0uUYFtdPeq 6RyToTu3/ksKA7SmEeCRKx8danxU4hkUVVkP8oHDwK8JAmdZ6/ssfjxdWlj2FPd64NRp dohw== X-Gm-Message-State: AOJu0Yz+xE+eA/lhi+n7IvE49sP7TO3wgtCXYYF+tqxLgCDhEpNydPXJ /4ucMFM3vbKauPDNeDnsCOc9gM7AnGLwECkXMgELHe8mjLqstNYZbHewZw== X-Google-Smtp-Source: AGHT+IF+Kf5PDPIsDKf6cVomwJ5pVTMKVQmF/uuP5E0anWYcDEb6shdkJQyoWcirzfgZqcNtM5qCLg== X-Received: by 2002:a05:6870:9112:b0:25e:e94:1e91 with SMTP id 586e51a60fabf-25eaec40487mr8012096fac.58.1720763482534; Thu, 11 Jul 2024 22:51:22 -0700 (PDT) Received: from Ubuntu.. ([117.96.148.106]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70b4397f475sm6604651b3a.150.2024.07.11.22.51.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 22:51:22 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, chriscool@tuxfamily.org Subject: [PATCH v4 3/7] t-reftable-merged: improve the test t_merged_single_record() Date: Fri, 12 Jul 2024 11:08:59 +0530 Message-ID: <20240712055041.6476-4-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240712055041.6476-1-chandrapratap3519@gmail.com> References: <20240711040854.4602-1-chandrapratap3519@gmail.com> <20240712055041.6476-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In t-reftable-merged.c, the test t_merged_single_record() ensures that a ref ('a') which occurs in only one of the records ('r2') can be retrieved. Improve this test by adding another record 'r3' to ensure that ref 'a' only occurs in 'r2' and that merged tables don't simply read the last record. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-merged.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/t/unit-tests/t-reftable-merged.c b/t/unit-tests/t-reftable-merged.c index 9791f53418..f4c14c5d47 100644 --- a/t/unit-tests/t-reftable-merged.c +++ b/t/unit-tests/t-reftable-merged.c @@ -136,14 +136,19 @@ static void t_merged_single_record(void) .update_index = 2, .value_type = REFTABLE_REF_DELETION, } }; + struct reftable_ref_record r3[] = { { + .refname = (char *) "c", + .update_index = 3, + .value_type = REFTABLE_REF_DELETION, + } }; - struct reftable_ref_record *refs[] = { r1, r2 }; - size_t sizes[] = { ARRAY_SIZE(r1), ARRAY_SIZE(r2) }; - struct strbuf bufs[2] = { STRBUF_INIT, STRBUF_INIT }; + struct reftable_ref_record *refs[] = { r1, r2, r3 }; + size_t sizes[] = { ARRAY_SIZE(r1), ARRAY_SIZE(r2), ARRAY_SIZE(r3) }; + struct strbuf bufs[3] = { STRBUF_INIT, STRBUF_INIT, STRBUF_INIT }; struct reftable_block_source *bs = NULL; struct reftable_reader **readers = NULL; struct reftable_merged_table *mt = - merged_table_from_records(refs, &bs, &readers, sizes, bufs, 2); + merged_table_from_records(refs, &bs, &readers, sizes, bufs, 3); struct reftable_ref_record ref = { 0 }; struct reftable_iterator it = { 0 }; int err; @@ -157,7 +162,7 @@ static void t_merged_single_record(void) check_int(ref.update_index, ==, 2); reftable_ref_record_release(&ref); reftable_iterator_destroy(&it); - readers_destroy(readers, 2); + readers_destroy(readers, 3); reftable_merged_table_free(mt); for (size_t i = 0; i < ARRAY_SIZE(bufs); i++) strbuf_release(&bufs[i]); From patchwork Fri Jul 12 05:39:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13731287 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 A196C1C695 for ; Fri, 12 Jul 2024 05:51:26 +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=1720763488; cv=none; b=NinAsiM1KvXPMBesBi8uQ8hC97PGQvGjhnzf/j6PlMvGZdsNlqz76oTM9dMXDlYjuvAWc87N09guj78hBGP9kcUST7X+JpFIHR8RSfK6gJ6YNvhyiR5A7dPPJTOUbxAozMv8ML05udKc07U1WNo4HP4YVBmrG0cTKxYgyndrmAE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720763488; c=relaxed/simple; bh=00e1kN6/SKqHL5GZqiUCqWh9sg5zKKxoH48JjofguzI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VF89q/mbmn701bQiHeYf+tU/8yTylWds+yO1rT4jlkqdBczVHOr7S+pqqkMWVgNiMKePdgcGeG2LH0mDKyao1FWyTRKIpglL42hD/RCFphHulPbFjpXPtiQVLji+bSr20hTs3BekZXjlLi6UNsyJPPVjMo08kca9mzLFzLWbBIQ= 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=I+U8MWzh; 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="I+U8MWzh" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-70b48dfd6a2so1392785b3a.1 for ; Thu, 11 Jul 2024 22:51:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720763485; x=1721368285; 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=mgFjkKLbBIGxt6XBAj88PZ7GtKvgwfaKOYBMfRAL2Xs=; b=I+U8MWzhF4YEBWW8Z4DHErEDCnH+fXf93Z3gHct+pTqIsTN4D4d4TOfZDYAimjqQ5t ubyUPhhse0Y/mJIGLuvWwQl53lfjZ/kKk6GMEu6MAwcE00jj9mPWLK5fOzxulBp0j/nD cFALZY/9W2+/JE/fX1LtkpkXB5UK5o97t6qBf+AZC+aIgKW3bkXucsNbrtpS/bhGgHst ziI+Z4eNCKe1lhV8WxH++ygx9+sczqJU8xJrgEle5Fjg0xHQDW+wB1MF6Uzb06CByzbi rwxT9ErUnbdc82hB/RXONwVIT6WgJOqSyQ/u6GP8f45t42zoEqPLwm8/Zk8UmbQjw4dj Ciew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720763485; x=1721368285; 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=mgFjkKLbBIGxt6XBAj88PZ7GtKvgwfaKOYBMfRAL2Xs=; b=EkIUeuEMa7f7XKNbHqhicN7Rh5vYOXj+RgMEXH8I4WUM51oUedJh++kOSDIHM/WJdd DX6dlpnDlExvAOvo9wVrDP+AnRC3se00nOzyQOmFiD4ryDwVVHCCEW3KiqN6sLlW457G H9R78BupCvh6UX8xr/4TxHr0Z4cMlzJqgP9DiZ2mZ9qfawQGsbaKRxYGPj4iken51KC0 paxGw5p54n94iJWFMB9wImfpY/80a45jSzQqSTKVTk6P6sg3GOna26wFjrCglH7KpPMe xPv+2ACKRzCX9h88FNtvrLQNQesbV7iQDkTfznjXuiCXt7f0RvQ4MO7QVeFRWb8f8d7o UiSA== X-Gm-Message-State: AOJu0Yxz6geavnqkvQwUmvA3RF7j/OhJt9b5NGqvWtjH/qqhRDcCam6g Z3jpGW4YPx9STGCvNoBML0fyIf/tLdrrpCeNDG5/9Dq9llCX/YQO98P6Sw== X-Google-Smtp-Source: AGHT+IH77zDDLvex4epOmpoCOloPMiLiLpje7S0Fy5MY6mEMrgbgQkNBpqDicaihUmPZsGPXiB2hdQ== X-Received: by 2002:a05:6a00:1ad3:b0:70b:1c7e:82af with SMTP id d2e1a72fcca58-70b435ef881mr13273165b3a.25.1720763485031; Thu, 11 Jul 2024 22:51:25 -0700 (PDT) Received: from Ubuntu.. ([117.96.148.106]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70b4397f475sm6604651b3a.150.2024.07.11.22.51.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 22:51:24 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, chriscool@tuxfamily.org Subject: [PATCH v4 4/7] t-reftable-merged: improve the const-correctness of helper functions Date: Fri, 12 Jul 2024 11:09:00 +0530 Message-ID: <20240712055041.6476-5-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240712055041.6476-1-chandrapratap3519@gmail.com> References: <20240711040854.4602-1-chandrapratap3519@gmail.com> <20240712055041.6476-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In t-reftable-merged.c, a number of helper functions used by the tests can be re-defined with parameters made 'const' which makes it easier to understand if they're read-only or not. Re-define these functions along these lines. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-merged.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/t/unit-tests/t-reftable-merged.c b/t/unit-tests/t-reftable-merged.c index f4c14c5d47..ff2f448bb6 100644 --- a/t/unit-tests/t-reftable-merged.c +++ b/t/unit-tests/t-reftable-merged.c @@ -15,7 +15,7 @@ license that can be found in the LICENSE file or at #include "reftable/reftable-merged.h" #include "reftable/reftable-writer.h" -static ssize_t strbuf_add_void(void *b, const void *data, size_t sz) +static ssize_t strbuf_add_void(void *b, const void *data, const size_t sz) { strbuf_add(b, data, sz); return sz; @@ -27,7 +27,7 @@ static int noop_flush(void *arg) } static void write_test_table(struct strbuf *buf, - struct reftable_ref_record refs[], size_t n) + struct reftable_ref_record refs[], const size_t n) { uint64_t min = 0xffffffff; uint64_t max = 0; @@ -62,9 +62,8 @@ static void write_test_table(struct strbuf *buf, reftable_writer_free(w); } -static void write_test_log_table(struct strbuf *buf, - struct reftable_log_record logs[], size_t n, - uint64_t update_index) +static void write_test_log_table(struct strbuf *buf, struct reftable_log_record logs[], + const size_t n, const uint64_t update_index) { int err; @@ -90,8 +89,8 @@ static void write_test_log_table(struct strbuf *buf, static struct reftable_merged_table * merged_table_from_records(struct reftable_ref_record **refs, struct reftable_block_source **source, - struct reftable_reader ***readers, size_t *sizes, - struct strbuf *buf, size_t n) + struct reftable_reader ***readers, const size_t *sizes, + struct strbuf *buf, const size_t n) { struct reftable_merged_table *mt = NULL; struct reftable_table *tabs; @@ -116,7 +115,7 @@ merged_table_from_records(struct reftable_ref_record **refs, return mt; } -static void readers_destroy(struct reftable_reader **readers, size_t n) +static void readers_destroy(struct reftable_reader **readers, const size_t n) { for (size_t i = 0; i < n; i++) reftable_reader_free(readers[i]); @@ -267,8 +266,8 @@ static void t_merged_refs(void) static struct reftable_merged_table * merged_table_from_log_records(struct reftable_log_record **logs, struct reftable_block_source **source, - struct reftable_reader ***readers, size_t *sizes, - struct strbuf *buf, size_t n) + struct reftable_reader ***readers, const size_t *sizes, + struct strbuf *buf, const size_t n) { struct reftable_merged_table *mt = NULL; struct reftable_table *tabs; From patchwork Fri Jul 12 05:39:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13731288 Received: from mail-il1-f172.google.com (mail-il1-f172.google.com [209.85.166.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 33C461CD25 for ; Fri, 12 Jul 2024 05:51:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720763490; cv=none; b=tB09VVE9hHDgQDCZXmb5S8s6sYZvQFDZJYAH2sydpFmNdteWJA1UUbWuV26CXl4AZaHtQL2zMBjmB0psA38VKZROGoY62O8gr3SFmMDPPoIQyqy8JIYNczHz/vW8uBeDFo4Td5tuerY/nSfvgfQm+DfYHVOj0ekJ/59OnDVtkrc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720763490; c=relaxed/simple; bh=8uL1ovLGFPqrVvQqB4HJct0GByQ01ZuFWo3hjVSm2IE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iSPqg+PQ3eJ5nSWMPlj/OOC4f0U3HZMpPp72ao8bFY5XNPPJdCtmXx8XlLdUbrU7+ep0Z/hC4yMlqtRqt1kTIO0j2Jqc1P8UhU6KrnbpULT9DA7NUvFBP/ddD+2PntARJZwrnJr4FXDFrYrOhtC4ddpaA/mw5wa4OIudnH5mwYs= 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=S7AYgbLP; arc=none smtp.client-ip=209.85.166.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="S7AYgbLP" Received: by mail-il1-f172.google.com with SMTP id e9e14a558f8ab-375daa47685so6103495ab.0 for ; Thu, 11 Jul 2024 22:51:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720763488; x=1721368288; 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=Jq9cdbUeyRVisocjN7NMp4rHugUPN2WW0wNv0UDUDb8=; b=S7AYgbLPykX92XR4Es+4XQoJHH7hQUo6Vq5VF5bzDarIUW2HhEsxb15xxEQMSZGDie zcz/BLcdRvEXYD20EWXlO1V0M+imQvwB0Hi1RxaGn7+r1as90LJ/avf0ZuHWImUQJczH MvWnUNii4OyblUMJPwmhVSxjgEhtBC9kCR1WRqEqrgluwKrmxzpxJJICAT3qnByV3d9i FVJ1rQohl0S2voN0AJWAtj0U35jtUUcv+j6TATKyKbX5NT/M8lerXOusQe4G5RiWEYMm iUeFqDjcqNwXiUi55Cg/HxdvvPdnCXEK/gFnMcQTmNAS5MIMhfE0WjK2dLqVuOF7GUif GCtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720763488; x=1721368288; 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=Jq9cdbUeyRVisocjN7NMp4rHugUPN2WW0wNv0UDUDb8=; b=tvrxYhZ33X9wfdoGL6qyy9QB0LsAE5Gd1MomRtafbQ85PLRDyaZ+Knr9BFjAhSNaT9 KsW91SCsmSTj1zHmYShCJpQZTo05dNYMIPwsIs2cSaO/6FwYmCoolE74DtFHyfXfz62v foO0sKWUJ69fxHOmCTWfW7TXeCZ1IEPtodve9ma1w4X3k+j/yDEq36fSSTJIb6kvqmZN VEZHXe/HLmh3oa7hH/XhDYUG/Kz377lsQ4tNx+NneV8z9nI+6UVPu5ObdROYOxTwmFZ0 OVRRYwwp/hy9olYcK/h+knzmt+2FDx65I7BgXq4h/QRFYh4kA0MjqIlSBVOEnrUpThHa BtVQ== X-Gm-Message-State: AOJu0YwQ1FIBmyVP+F2mSOf6HeRY3zr5GBBYAy/MZgaE1Y5Bl53hdfWL DqUNzrWiP2alrQko1/cUMeZWGCM8MkaWszPCYVSzP0PFkM7PUQzedJpNsw== X-Google-Smtp-Source: AGHT+IFCAFcTxAqeKuZvWWl6+YGUDaiAJZ5QjVIQtXmFd8Y7liGJCyfZ9xEJH/+IN7FCSBQyVypuwA== X-Received: by 2002:a05:6e02:12cd:b0:382:c731:8d0c with SMTP id e9e14a558f8ab-38a56d0c2c3mr127589855ab.5.1720763487913; Thu, 11 Jul 2024 22:51:27 -0700 (PDT) Received: from Ubuntu.. ([117.96.148.106]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70b4397f475sm6604651b3a.150.2024.07.11.22.51.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 22:51:27 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, chriscool@tuxfamily.org Subject: [PATCH v4 5/7] t-reftable-merged: add tests for reftable_merged_table_max_update_index Date: Fri, 12 Jul 2024 11:09:01 +0530 Message-ID: <20240712055041.6476-6-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240712055041.6476-1-chandrapratap3519@gmail.com> References: <20240711040854.4602-1-chandrapratap3519@gmail.com> <20240712055041.6476-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 reftable_merged_table_max_update_index() as defined by reftable/ merged.{c, h} returns the maximum update index in a merged table. Since this function is currently unexercised, add tests for it. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-merged.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/t/unit-tests/t-reftable-merged.c b/t/unit-tests/t-reftable-merged.c index ff2f448bb6..065b359200 100644 --- a/t/unit-tests/t-reftable-merged.c +++ b/t/unit-tests/t-reftable-merged.c @@ -236,6 +236,7 @@ static void t_merged_refs(void) check(!err); check_int(reftable_merged_table_hash_id(mt), ==, GIT_SHA1_FORMAT_ID); check_int(reftable_merged_table_min_update_index(mt), ==, 1); + check_int(reftable_merged_table_max_update_index(mt), ==, 3); while (len < 100) { /* cap loops/recursion. */ struct reftable_ref_record ref = { 0 }; @@ -365,6 +366,7 @@ static void t_merged_logs(void) check(!err); check_int(reftable_merged_table_hash_id(mt), ==, GIT_SHA1_FORMAT_ID); check_int(reftable_merged_table_min_update_index(mt), ==, 1); + check_int(reftable_merged_table_max_update_index(mt), ==, 3); while (len < 100) { /* cap loops/recursion. */ struct reftable_log_record log = { 0 }; From patchwork Fri Jul 12 05:39:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13731289 Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12A9F1F946 for ; Fri, 12 Jul 2024 05:51:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720763493; cv=none; b=kAueshzO1fJrAD1YwuMwu6ke2SfLGwomki8Y/6xDCeH0FcHz0hBvMSkD1YjF2x0jalZdspW01WvOdKuIhLUbTPogDB6thSlbuO2xkEsQcUX9EkwEtMSBoUNKcxJzrRMp8uu74K3c/Xy3rpZRGAywBJTD9Sh6mk1fZ0JRmIqY/eQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720763493; c=relaxed/simple; bh=30AJPbiIwqfNc7C6hDVXdA/qfAfUj/zihzMob8vv6Xs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F8yyqGBXMBuCSplJwxfN7p/O/nExuwgkUUFuh6pUwcXtU9pmcHYFYt2ez4azH152sM/+b7aAA44+Cg+LfXh0EfrGUnj68HDp9cLQmcI+KgSCt8mDbsxvT+Bt0h+UuIfda+zxiSnBhWeatZSaRU3rasA+ucQ3OdF4JYcYM7nVCps= 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=Lw2Dy5f7; arc=none smtp.client-ip=209.85.210.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Lw2Dy5f7" Received: by mail-ot1-f53.google.com with SMTP id 46e09a7af769-708b273b437so676176a34.0 for ; Thu, 11 Jul 2024 22:51:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720763490; x=1721368290; 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=GQneeaCpYC1UQtQb8/kuvrITYshgjp5Gi0xSFoVZduc=; b=Lw2Dy5f7qujpZjcF+WzlwF0jLNWIPQaQIRKW/nRWtId60ndvSCGQH2R1Cj8Jzkm2lG nTFWZqTrbODp7RRTPfd6WIh0iyWQVw0xYUnlqgdzdb4zG2qR6Rqxyw3Hd9Q9M2ot9J+S mZUHma8m4TbwtkvyI6iYRz1guTeenKGUUjXIuLmId4J5UG5Cli7LV3UC3bah+K8TUAWy TGiLxFO0qtrBmpTYYvDzoye1cBgSh0wWbH9hmndgBHdyVc6ZF1+wRV5ePYaC2Ft0JsCp Nz3+IDALJHaDdHGYuD23x4z9Ik/wesCBt+IAPcFUnRucxx1jCOQ2YEIWybEkcW7nwznM lHiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720763490; x=1721368290; 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=GQneeaCpYC1UQtQb8/kuvrITYshgjp5Gi0xSFoVZduc=; b=eXxyVi7ckbCtqMFxD2otevZDkMcxKkIhwLhaJvbTuaaGvxRrSCSBTtLokmfRtRy5pT sf0Ji8H3Bwbmh0apx3WKXS/CgQpHXHXN5yASVpbGEQ3G/kZyxjDlTd+MMdxnkOMuq7B5 JGO8FjuL16Ko9aNQQWVen77u/kUpxnREzNA0YiJc6Rnc9CpmqPvcI/iH3MioYtKRxbrx 1KPw8bma5jT8+2depIAPgbTIa3hPrINsPKW5tIKhR1tC3YIAg7F5e84OepA2W4+utGds vBr7EdejtAUGHRN/kSCyGhdOS264B2NUuWBQdeD2/mqjQQxIYcGBIV5QGtRfBUCJSAtZ GjAg== X-Gm-Message-State: AOJu0YwUsfKUWCbxkW3xb1wCkatZOlbm/U7vl7HUavmA0E428UZled9Y Th8C4zcdmp/u6QOmTZnlC4UJdrtSLYPyQgF0jY1noho6FhZNjUeL4JDrFQ== X-Google-Smtp-Source: AGHT+IFVJ36EPGwOYiUcJo9C5s0NG5TwV65tRN4duHCBjIrGSoKRBSqDs93BxiKxQH14XtlJYOe88w== X-Received: by 2002:a05:6830:1e84:b0:703:78b3:841 with SMTP id 46e09a7af769-70378b309f0mr10347858a34.13.1720763490362; Thu, 11 Jul 2024 22:51:30 -0700 (PDT) Received: from Ubuntu.. ([117.96.148.106]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70b4397f475sm6604651b3a.150.2024.07.11.22.51.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 22:51:29 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, chriscool@tuxfamily.org Subject: [PATCH v4 6/7] t-reftable-merged: use reftable_ref_record_equal to compare ref records Date: Fri, 12 Jul 2024 11:09:02 +0530 Message-ID: <20240712055041.6476-7-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240712055041.6476-1-chandrapratap3519@gmail.com> References: <20240711040854.4602-1-chandrapratap3519@gmail.com> <20240712055041.6476-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 test t_merged_single_record() defined in t-reftable-merged.c, the 'input' and 'expected' ref records are checked for equality by comparing their update indices. It is very much possible for two different ref records to have the same update indices. Use reftable_ref_record_equal() instead for a stronger check. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-merged.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/unit-tests/t-reftable-merged.c b/t/unit-tests/t-reftable-merged.c index 065b359200..9f9275f871 100644 --- a/t/unit-tests/t-reftable-merged.c +++ b/t/unit-tests/t-reftable-merged.c @@ -158,7 +158,7 @@ static void t_merged_single_record(void) err = reftable_iterator_next_ref(&it, &ref); check(!err); - check_int(ref.update_index, ==, 2); + check(reftable_ref_record_equal(&r2[0], &ref, GIT_SHA1_RAWSZ)); reftable_ref_record_release(&ref); reftable_iterator_destroy(&it); readers_destroy(readers, 3); From patchwork Fri Jul 12 05:39:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13731290 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 E42D2200CD for ; Fri, 12 Jul 2024 05:51:33 +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=1720763495; cv=none; b=C+3h2NS6C29gNgtxCUjUkxqgG5Bi/lLdIFGNEwYar2xtPa+4uuKDM6sLtkGDBVugUoiueFg86QyVLR81WkRHdIAj14eWHfDYCHI36Uk0ywYd0R/e8wfqrcfLzfZaosQRUhMfHD2ESmo03E9UeicO3IdBwkeXR5PquFwgEDKKbME= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720763495; c=relaxed/simple; bh=JR5r7iQVSvxLkCgajtMpc1PczwyxUN3Wq9L1J5Nly8s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H2cCE06cXdB/EsO1yHJ1fX1Nhqly/Bwt2sTKBP8jPUzVw1c82DXCYiB45FktwKBg3GK8G1b17Xrot9uKFdh1K68DU91VB6OigQl3ZgpqispYQ/ZGEMq+i7c3NHh/0wrvZwQnyv0BVCOSOf++spJvJse1sxgMPbXKZfNCXC5K7yw= 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=M7RgrYU2; 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="M7RgrYU2" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-70af8128081so1352064b3a.1 for ; Thu, 11 Jul 2024 22:51:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720763493; x=1721368293; 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=tes2rrEt5jimF66l6Qoi63X1Ls4v0R/Vf22NjZjjtY4=; b=M7RgrYU2UZlk9do6Zl/5KVTcANuYCVHIAeEVwE4kDn5ZM5XI/DtJff83GahUHSfAIU v+oFW9vf+CuWovi7JvSNq4/KmWQFHLCHII0kNdC6SspzmL/eAO05MdujWwD5KPFxF9LI wYOizorcL2GwIRdsvpdb0J2Uw+HbC4NSPlhokWT0VhBkLyibj3uK74kXOBRzMLwSGCeZ 3cu0BY7zifFXZsddZuH31SN8Oz7evN+1sIlUsc7Bq089w/etJrsev4ItMoNDbpArdp3x MGFJCKH6GQHTbevtBP5C3iI7QpYhqmxWQGYC1iWaL972maF/HG1p6wQQTuL6fNGr9F2+ FxBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720763493; x=1721368293; 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=tes2rrEt5jimF66l6Qoi63X1Ls4v0R/Vf22NjZjjtY4=; b=jKN363YymzmE5oSvE2Lce2lcWvyih/e7NW8/kjpBbVt7wf3P+H5Z+SqwgjU+0Bjh2E 4sX1qCyiN6oj/747nHz6zICqjFrab0efABRyWs8KtMB/7aiw1FwKGHp/TWCfKJy8fg3o ABJaI2M/ksNTkPlF4Nps5RUoOjbmXgbXM6LQQf+YOT5bRlagWzUCqtr+OEFHWSaQdTWu JSztW/5Pfc2hfgyxKVkVm8yDwn57ZFwz4+DZXXI20p0yePHCqsidYKOhbifygKuCqEmv ZGvkmkKQwTSiCx8rwrSHH/dZw6M1g7DJRQlk9MtHtBLuSobYPaLsDJfjeU2qZHnFvqOo rVGQ== X-Gm-Message-State: AOJu0YxsIr0ztqLXx0O87Va2Via9LYcmEOItM29AVKykoDuw8RzUnLhK WuXmdbPgSvDVTofk08MtXtDTzdzgwEm6nqac8+2kFagdyE1OEEK1HZoU4A== X-Google-Smtp-Source: AGHT+IGJZRjlwoIxgiNYrMuYF5EZtRO5V9jvriFKCNNjWRGEiKqtT6wxgqJHvMjqF2c6G83E8PCq1A== X-Received: by 2002:a05:6a00:17a1:b0:70a:ffa5:41ec with SMTP id d2e1a72fcca58-70b43632379mr13676194b3a.25.1720763492788; Thu, 11 Jul 2024 22:51:32 -0700 (PDT) Received: from Ubuntu.. ([117.96.148.106]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70b4397f475sm6604651b3a.150.2024.07.11.22.51.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 22:51:32 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, chriscool@tuxfamily.org Subject: [PATCH v4 7/7] t-reftable-merged: add test for REFTABLE_FORMAT_ERROR Date: Fri, 12 Jul 2024 11:09:03 +0530 Message-ID: <20240712055041.6476-8-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240712055041.6476-1-chandrapratap3519@gmail.com> References: <20240711040854.4602-1-chandrapratap3519@gmail.com> <20240712055041.6476-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When calling reftable_new_merged_table(), if the hash ID of the passed reftable_table parameter doesn't match the passed hash_id parameter, a REFTABLE_FORMAT_ERROR is thrown. This case is currently left unexercised, so add a test for the same. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-merged.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/t/unit-tests/t-reftable-merged.c b/t/unit-tests/t-reftable-merged.c index 9f9275f871..b6263ee8b5 100644 --- a/t/unit-tests/t-reftable-merged.c +++ b/t/unit-tests/t-reftable-merged.c @@ -11,6 +11,7 @@ license that can be found in the LICENSE file or at #include "reftable/constants.h" #include "reftable/merged.h" #include "reftable/reader.h" +#include "reftable/reftable-error.h" #include "reftable/reftable-generic.h" #include "reftable/reftable-merged.h" #include "reftable/reftable-writer.h" @@ -440,6 +441,8 @@ static void t_default_write_opts(void) check_int(hash_id, ==, GIT_SHA1_FORMAT_ID); reftable_table_from_reader(&tab[0], rd); + err = reftable_new_merged_table(&merged, tab, 1, GIT_SHA256_FORMAT_ID); + check_int(err, ==, REFTABLE_FORMAT_ERROR); err = reftable_new_merged_table(&merged, tab, 1, GIT_SHA1_FORMAT_ID); check(!err);