From patchwork Thu Jul 11 03:58:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13729980 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0CF0A36120 for ; Thu, 11 Jul 2024 04:09:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720670978; cv=none; b=PY9U0IxPzWOB6+k+fKvRs6FCZ3mj4otO44pv5Xa2E6ZMiiXTtM7qUehZ+YWdt3T/+lvv83YWaxXILEgc66uRU6y9Lr7ndHuV8XjosAH+kLG+FKV9kaezrW5BnSIfJPrEq63AZC5sKgj/Jsyh5Le5hiGUIsL2HE/mwOX3hLah16A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720670978; c=relaxed/simple; bh=Ud1CcjKOs+sEQrYwDefKahcPEB3Uedzcz0eHMFs8log=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MolOXOUTTdAiY+gREBojYJnNoz8bw5brzWqZmdjjm78Yw/lypPIJTdG+4gKBz9bppZcLGAJpGgL3JESsCl2HuGSFYKBRMc/YfK/+xPQwxkfwGEDRCiyz3aiPXz47IOfgB1ZyIXz4h0btTLaqwiB87pqa7C7Xwgsclz76mfkXe4Q= 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=kn/zln3X; arc=none smtp.client-ip=209.85.215.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kn/zln3X" Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-6e7b121be30so302139a12.1 for ; Wed, 10 Jul 2024 21:09:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720670976; x=1721275776; 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=kn/zln3X0nWZjmrJKwqOt+wnEdJy19kmrZliDCgr/oVNun9DiXdomtJy/h1EBpvQoz g3aLMj/qA5FmokXPCpU6dxa3ZWJ/EAG2xTEG/BUn0NvfQ7fAQIBHa3uBzH4Hklh5DH1p F2u+9RFWphe9aq79ERTDgBsDanoeKn7YsEshWT+yyUL46dnpVh+TUTzCWqdlw4e80LMk M+wD4DdG3kqKAE17z/ItTtbZ179fvyp0cso3btZdziW2nR76k0AH4FXAyPmwbyNWZFGK d2t25npLtc3GFFYqvWduxi/oIL8Ygp00znB9YOdA/iS/RLbEliaoTK6vRJPGX5Fo5Drx R8hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720670976; x=1721275776; 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=Tmp3SgzWKlFk0L/AqIhFE5kJBmMvxRTnZAKAGG7DIDq+K3y+Ka+hloLYM8903a3zbX Klx5d0DtoeFNaJz2eYo/ZYPWD+f3XcA6YF03yn1/GBZhICeq3eglocoebwkzilBfu/hS lBiyF/mW+dq3jTSqUF6nIORVrPMOosco/oaUqZHZkEFVmy13x1lYJXaJTQVZ8Ko35HQT AmLUqdG4cXM2x8jxJ6iJzPap4TgAzzHrX7PdnGfEsQAwK8xAPGsg/bos+YegD3f26kQ2 3mP/aYhUFczz8gDZElp3rEmDMRMZj+qsYC63YXRBHW831VzHvaD8kz+pcwwpQxDUUuBO 1ytQ== X-Gm-Message-State: AOJu0Yw4RUtLz783piQJKfM9IdqukGUrQaJnDaZlsWnq386K3feSVldw M5yCj77fEEwQU5xAt2KI5gg7uGJ2tBpGOCHUqWPoN8Ag2u4BIhw6axtz0+OH X-Google-Smtp-Source: AGHT+IFbUvNZha5QfOMYbmIeTOTL3nQolbZ0VlzUSl+eU5fYwqK3DthzIaSvd3VDAAwwZfyyes5Qnw== X-Received: by 2002:a05:6a20:2445:b0:1c2:8bcc:bb09 with SMTP id adf61e73a8af0-1c298214958mr8434976637.8.1720670975890; Wed, 10 Jul 2024 21:09:35 -0700 (PDT) Received: from Ubuntu.. ([106.206.206.104]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1fbb6abf738sm40808595ad.198.2024.07.10.21.09.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 21:09:35 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, chriscool@tuxfamily.org Subject: [PATCH v3 1/7] t: move reftable/merged_test.c to the unit testing framework Date: Thu, 11 Jul 2024 09:28:30 +0530 Message-ID: <20240711040854.4602-2-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240711040854.4602-1-chandrapratap3519@gmail.com> References: <20240709053847.4453-1-chandrapratap3519@gmail.com> <20240711040854.4602-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 Thu Jul 11 03:58:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13729981 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC5203A260 for ; Thu, 11 Jul 2024 04:09:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720670981; cv=none; b=GRFUiI69Y7rOJJCuMLoIYYSi1KfPv9q7tIkRYaJUtv3LwEQs5NL7QJSNQSZ2UJkQyxr18POVj9n7QWQnl2v01gKQGEJCizsmUeb0GXUVCq7kFtEbMfQ58+X+dPuruvxn5Zsr6/u/aO6b+B4XH5i8bEW05+/zRi8ozboswcsWTjQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720670981; c=relaxed/simple; bh=p9vdsqA8INI6j87KT4tGY3L12nlA/SjVsWGqp3tXw/E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BFTDhMNQAFXCJVDrO8RAb+83J9/dmkPsG7it+kPDOcoanY2Mm4Q+rcl/qWHcSkq3Prb5wo5m4374XQTpOC5WFUXTjORQhmFamHeD4/3d3zpnpTC25Zmb2uueblhPhbDBwgePjqf6Nth+7+5v8Zmaj9wSEYhWKho1fMhGl71YDm4= 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=cdNFyV5i; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cdNFyV5i" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1f4c7b022f8so3008995ad.1 for ; Wed, 10 Jul 2024 21:09:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720670979; x=1721275779; 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=FLo1K34oz7262vJ6ATT0KSQPg/ZkTE1BtTDCT19l9vg=; b=cdNFyV5i097eQmE/UoYrrTSqj4kH2xWrKyaQJAkTOH95Uc2VKWsw54C/s+2QJMBUES uj7O2/xx7hKOTeDcslY8vPn1X4gaNWf7oCKqqrvod/z1S519CGxZ3dvC1a4i2voAh7LB DHRXqQ8ZHt/XzSQf9PTyYJb1dCI/DijUMRMbhl5WQxwK5+IY657lNuLEcmYcpmhIhk4n eW9l3Hg2wqiz/d2ZCRMP95qtTPujTc9Hj0qTVHvVafiwpJnv7OifMR2LO6932krun6WX u+oHnW8EvFRiy1jZ7UsulNs4/ag2K6trCcKxXrgOICnU40Wjw5lkBjB7+kb/ZQAV2vJc tsDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720670979; x=1721275779; 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=FLo1K34oz7262vJ6ATT0KSQPg/ZkTE1BtTDCT19l9vg=; b=C+EyjHfJ0vG0bSQNsR0mrbD4Uk+q8K1IthXDPTW0VnnivwbBKQwPqBM2lII7ywlnsp 5wzI9sacJJZKgbR9+rNLDF2AeNjD4TGw36NS6BTQLr5gozX+J/NTJOYAyXCk2UwrjW0a BK2B9GVVjpBtEKKDVJW3vFXzLo6elQZR+OCSGKbvz+VTZYmEG7YVom8cW7WZ2toG0Mxi zyArT4BdXxtaBepPYLR2sxLi3D8Hn+Po5MTU/tNsBygc2k6CE6mGSoMNMP9yqAEJr5gV 4t4r7EFzqlnjAuo8HTQhldyJHKxUGs4pb7X0BnRYh4SzdBsqYGA/i0JnFvzRei4TNM99 juXA== X-Gm-Message-State: AOJu0YwSuQxIePdklPwdi1rLrMSUPtIkpjijdUlRrXS7K7q5pRflvW6f 8WFkyxDEdgsow1r/lKaDCl9HMbagCj203bXM7fgCDBpCarnp2Bze7MWxcnfI X-Google-Smtp-Source: AGHT+IG8OgkbSmIyqV5W2Z8FrtSyPHkpXb2gBnLbc6iqRHdmJzIYyec4Hekdjx8ze70hySIKi/bZZg== X-Received: by 2002:a17:902:f541:b0:1fb:8864:e20 with SMTP id d9443c01a7336-1fbb6d03e33mr60313995ad.23.1720670978599; Wed, 10 Jul 2024 21:09:38 -0700 (PDT) Received: from Ubuntu.. ([106.206.206.104]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1fbb6abf738sm40808595ad.198.2024.07.10.21.09.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 21:09:38 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, chriscool@tuxfamily.org Subject: [PATCH v3 2/7] t: harmonize t-reftable-merged.c with coding guidelines Date: Thu, 11 Jul 2024 09:28:31 +0530 Message-ID: <20240711040854.4602-3-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240711040854.4602-1-chandrapratap3519@gmail.com> References: <20240709053847.4453-1-chandrapratap3519@gmail.com> <20240711040854.4602-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 must be of type 'size_t', not 'int'. - It is fine to use C99 initial declaration in 'for' loop. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-merged.c | 52 ++++++++++++-------------------- 1 file changed, 20 insertions(+), 32 deletions(-) diff --git a/t/unit-tests/t-reftable-merged.c b/t/unit-tests/t-reftable-merged.c index 78a864a54f..a984116619 100644 --- a/t/unit-tests/t-reftable-merged.c +++ b/t/unit-tests/t-reftable-merged.c @@ -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); @@ -68,7 +66,6 @@ static void write_test_log_table(struct strbuf *buf, struct reftable_log_record logs[], int 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 (int i = 0; i < n; i++) { int err = reftable_writer_add_log(w, &logs[i]); check(!err); } @@ -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); } @@ -148,9 +144,8 @@ static void t_merged_single_record(void) 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); } @@ -226,12 +220,12 @@ static void t_merged_refs(void) 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); @@ -358,12 +349,12 @@ static void t_merged_logs(void) 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 = 0; 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 Thu Jul 11 03:58:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13729982 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 682993EA9A for ; Thu, 11 Jul 2024 04:09:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720670984; cv=none; b=ivZMj3xdU5XmQdHjFhQmCV5XdwpPJNmpsDxp4gen5poBTemoGgyTIEwZ7xsZ//6eS+jv8mmePZ0W43BolFa5NRINOcvQXO6HBnJUQOxPyQziaz7/IdzMf+1Am2SgDAkNiT7YvveNh/x2tWZnMfgCDuIIlBOK2kDiaoYqyWEaQ/8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720670984; c=relaxed/simple; bh=z8R3TRpztrhJoG5bdL+rj059Xb77E1s5ds4ThX/46AA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BSzdleIWShySBMw4i6aQOmmCvTny19daOoLQjnYOC5au+AJfpzjNJoANfsLsAFW+IYnR3vFNGyo7ekM3J411+8m43RJTP2MtAqsdhHTc+Q56VCIOUfIhiw57hDuDZtkU+tdbzoGMHbvXvpMeSiLBgPIsN1ulRoF/8on4Xjxppdo= 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=FQhKNUvG; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FQhKNUvG" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1fb3cf78fcaso2634125ad.1 for ; Wed, 10 Jul 2024 21:09:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720670981; x=1721275781; 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=VpjFXvjBf8E+SMnf3piFFJYNEyLRj9qrl2phkzKNLEU=; b=FQhKNUvG7udWlpgkCPWcB91WVknU9w65kpjKwY7qAyWGK44lZE/EYNEsEmANSKdqnb vUwDvriJRdl4TYg0+vux2DjU+Tcusd6K6AhO6WMewIIirC0q+E7rqybku7Ldcd3vpMqn 8TWXGaJs69M9InNpAwcfk+Y6LtQ7YQEp15PnGUChNFnU/zqECr3MsoqtuneZmSiLHRWo vdnsdCum75SommLNwkrsnV0/tqeQz5LE1c4Ouvo1Aotp4jTLfNbu0UImz01FjEzgCMEQ OM1oMeIOfcTbcwtPoSHqjSwwIH6Ze5OFOxdHxde0yW5goyagaB+F/eTdD+L+JKTfGU2w CezQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720670981; x=1721275781; 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=VpjFXvjBf8E+SMnf3piFFJYNEyLRj9qrl2phkzKNLEU=; b=KRS0WwbkNaL1dz4ZfpO1AGVsYX1W4Fm+7IhvLtWecQ18ekH7G2iCDLkstNZ3/j2jSZ F5tHgEb4eIYFIxlNQLKKvDbcPWurcuqlJLBUMrbUHy7sbBgV6HjeKjTsMOubdGwoFN5w pjmt5r6CZr7X9GcfKimnnXqHNQnQyLpfUPGDgTIGTHQlWBE5ro4gKelhRXVFv4QITcua k35yLwSAZJ5uHNCQrctIXjSQkNFUuaycv8+U4o3vv82Pw4rMKFUSgtKX5XjB6DwRqABo HtNmx2K+RKbeYcOfB2oEfo1swMak5K1Mz/Z62WV6dqz+XEVEVHQEWU5Y6lFCw52jOmCt NAdA== X-Gm-Message-State: AOJu0Yy+4RrNQT3atozrDm4y2JdiOAclOhxG1kYTB619mJDH5MJeC1hw EQ82ZImwxsPwZpotiXcSG4NQ8kLJI1AcDSKbCb/WZk8o52C/jia0u569ZjDL X-Google-Smtp-Source: AGHT+IFDUMC7PndNSBivwun5xW30AouCc16nRsYLH+wfcN9aT+s1f71jVgcEodYl3Th+A4Sf3YoQrw== X-Received: by 2002:a17:902:d50e:b0:1fb:38c0:173d with SMTP id d9443c01a7336-1fbb6d5aac7mr69125315ad.39.1720670981320; Wed, 10 Jul 2024 21:09:41 -0700 (PDT) Received: from Ubuntu.. ([106.206.206.104]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1fbb6abf738sm40808595ad.198.2024.07.10.21.09.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 21:09:40 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, chriscool@tuxfamily.org Subject: [PATCH v3 3/7] t-reftable-merged: improve the test t_merged_single_record() Date: Thu, 11 Jul 2024 09:28:32 +0530 Message-ID: <20240711040854.4602-4-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240711040854.4602-1-chandrapratap3519@gmail.com> References: <20240709053847.4453-1-chandrapratap3519@gmail.com> <20240711040854.4602-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 a984116619..85ebb96aaa 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 }; - int sizes[] = { 1, 1 }; - struct strbuf bufs[2] = { STRBUF_INIT, STRBUF_INIT }; + struct reftable_ref_record *refs[] = { r1, r2, r3 }; + int sizes[] = { 1, 1, 1 }; + 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 Thu Jul 11 03:58:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13729983 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.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 09B9A46525 for ; Thu, 11 Jul 2024 04:09:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720670986; cv=none; b=sT4+9eN2L/NNFPWyZErxvxejgve1NgPDLbQoOxgmmWvi133o+6TnxohujxN2ur06twSacEN2Q3QOG7Cu5O6hM3Q0+YbxVh3oxCrfa/LwBE5kCuWPF+JdXbx6uzxVA8yXXyr6jWfdkS3wle5GjJQwAzzKUab77lSTQ1w7ODrTnRk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720670986; c=relaxed/simple; bh=DbDjM44UTBrQHH9duNJqT0R92lfap9KzIQyTbrG3zAA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NtgGolrPL/D+5xYKagVheZgEui+LhAtClz/2KV0GQAiWeTgee44oABsc4YYXADScLgsslkFFBwZd843OyKswMWXEZ/W2F5kPD+VXqaecS+n28NT7nRMpzy/n4IQ76r+kkwFAZzQ6stJ3CRl34c5NHyVgMd9Htthxv2gJsDDVkk4= 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=g7IvNX2R; arc=none smtp.client-ip=209.85.214.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="g7IvNX2R" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1fb72eb3143so3369045ad.1 for ; Wed, 10 Jul 2024 21:09:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720670984; x=1721275784; 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=M0SahC0FCi1n/BbK98X91PQY4a0Ro2QoUZr/ZjAgUOw=; b=g7IvNX2RCjtZ2QW7ffvMTpYMBwJuj1V8jpigJt5HSVNqZG17E4DILj5GqsGYTbt+jz 3W9rS82vmjsijudDCtoy82ak5aPxb3fVTntLmj2xKs/VigWo8/DjTUb0tiCHwsb8V28J pyqCM0wUWFsiAMZIn7iTF0vPtB+KWHfAlQ0kDXKk4ZrLDibPw4mN3nlWF9bqHlTm4DlP ZxQg/0dCJvE7E49v56B/eF9zSAA9in1+k8BINaWycWqblSLWW58t6SFbLM8If/V8lbwC Cq6k5PyYNysa2sr5ZLg6Vf1wZ298bwOLUjfp108qfDLTrqI+b9456rUwRD51LsZi3hPm CQag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720670984; x=1721275784; 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=M0SahC0FCi1n/BbK98X91PQY4a0Ro2QoUZr/ZjAgUOw=; b=X2v3CSPJLY80WL02LHZz3Dg2zgswdLqxYl9RqweDap0wVMsXkw7gD8freDu779CuQ9 o1puLD3nZU9AUq0RTYPzcO7XWs553K80C3VsZ9TSUGkSlED/Y0v4f+M/jxE+vkXCe8yB dbSRLa2vnqGwRnM6EQqR7AD/5wWOsyUJoazi6vI06N0yy8iX8wQ1VTZH1CCz16woHnpD ZEF55sICnlt9RQg4USGOPsLa05cE6mb27q72Kv24mjiUDjE5/q/vushyR3qk7/kLQwCK pZRn8kUJhPW+zoLqHWKqJDrcYejmH2dzNxcCOX49lINHSGKYHJvWOIXm1M3AZkdBjetI yYWQ== X-Gm-Message-State: AOJu0YwJsRzvG9V2FQv2xr+wmDXvPYl3bu8yrShTdeAdRz43sX2QzpO6 CusVqED6KDkJyUmj5tTRxpXD4skX1vW/UO4CeuM/sZxR4Tf2dQpLkTPw8Zwk X-Google-Smtp-Source: AGHT+IGnevQ23OyivwBrKuCPwZba4sSimPrkuHqr4oB1h80evjNGr47v5zys5SIqKdDz8O/PQTktAA== X-Received: by 2002:a17:902:eb81:b0:1fa:97ec:3a4 with SMTP id d9443c01a7336-1fbdb9e8b0amr23860675ad.8.1720670983970; Wed, 10 Jul 2024 21:09:43 -0700 (PDT) Received: from Ubuntu.. ([106.206.206.104]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1fbb6abf738sm40808595ad.198.2024.07.10.21.09.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 21:09:43 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, chriscool@tuxfamily.org Subject: [PATCH v3 4/7] t-reftable-merged: improve the const-correctness of helper functions Date: Thu, 11 Jul 2024 09:28:33 +0530 Message-ID: <20240711040854.4602-5-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240711040854.4602-1-chandrapratap3519@gmail.com> References: <20240709053847.4453-1-chandrapratap3519@gmail.com> <20240711040854.4602-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 85ebb96aaa..d151d6557b 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[], int n) + struct reftable_ref_record refs[], const int 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[], int n, - uint64_t update_index) +static void write_test_log_table(struct strbuf *buf, struct reftable_log_record logs[], + const int 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, int *sizes, - struct strbuf *buf, size_t n) + struct reftable_reader ***readers, const int *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, int *sizes, - struct strbuf *buf, size_t n) + struct reftable_reader ***readers, const int *sizes, + struct strbuf *buf, const size_t n) { struct reftable_merged_table *mt = NULL; struct reftable_table *tabs; From patchwork Thu Jul 11 03:58:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13729984 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 957A64963F for ; Thu, 11 Jul 2024 04:09:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720670989; cv=none; b=VQjDth3pkLCqvEvkt2Lq6l1zxlwlcKuudwc7lSqTILzw8e5eyyKiY6sdiczYyJuG+HJLk8SckvL0g36VZZFTvW96/Jrzqaq7tQp8C4jHKO8UiRxT6KIDkiXensFU5R1Ktq+6sYszBOw1N5xIa6xDs1xM5vFLquzMcpSfQfPGtmI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720670989; c=relaxed/simple; bh=87klCzSTbrediqyqHtkAjIc+2bmYERhxJvizzC5tyF0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=odAQrgix4aQJrgLHR8eSrxrSJS5hb/GN/Xb6K7MCwVR7A3lueSxyrt7mlj3R9FWtPSbyWxmYzYRYGqiIRQKOapzRXkVM6ezg/99Es6h7Jvnv8uiJZ+R/RRLJaxmelRyDzrhEXM0iPs5ca9VHql/cyNBdYFhH40Tds706hFwHgx8= 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=TqpVPRuj; arc=none smtp.client-ip=209.85.215.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TqpVPRuj" Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-70df213542bso253493a12.3 for ; Wed, 10 Jul 2024 21:09:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720670987; x=1721275787; 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=LdKIEcp7iYQzcciWp7cti3GIS7qLWBiX/oOTwmZ5/VY=; b=TqpVPRujyOWaXOdaKSQNEKQOF2gluraWawtlgkCP2p+SD6HCKhCoVUH/hjE/I/e13S jieJ78wWAE62MPTiqVOm4jxSR1FdzBijm+RHJi+LGGmEbz3uSViJxTsXO71jZQaNHfmo E7dXRl5W1cWWbWgFrDptIDYPvHNHM8WHYuwbVRPkqqPFpZtJ7UIeSY4lDNlgSUz4ThLV mR4gnPpyND7CD7WICNT4lcV1XM22zXZ5m0kisP+4ngY1AJpYm4aNzngTbyp8JfvReTe5 Ge6Zlsd1MhwDBcepf3aTcDV07cNbfgVSjQGHN7+zZUGUCCAjVQ1Q3WK6o2Sj4U1qObVC Qpbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720670987; x=1721275787; 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=LdKIEcp7iYQzcciWp7cti3GIS7qLWBiX/oOTwmZ5/VY=; b=SEcC+fp+VyQB3uwB284S870EBOhnSdf0ENn+1X8bYch7qPO0BZEYTD82aNTbhN5Dq7 YH/w4+/kSdPiAXWWlJURk5mRgOh7CLYsnWdknqblwtZmYIjiWkoqCMPbItX5CCPjRyD5 omh50xuJdkdRuaXYR7paUvVaPyV/74tcdBkZ9HTlI1thDKLmO+9O/ahBaWWNoMM8Xv62 jyFWbDC/8bPo+LMmwilrsbzUGwUYb7V4z3myMuyLfHF9fm82kRCJTqBSDjp/zA7GxDX5 g9nI2ia3IJ/SqMZi7SaKCLRhEYwNRHTqrF9ecGB+kwA11TNr2Uy4yM2GXl65gquLwnr+ x7EA== X-Gm-Message-State: AOJu0Ywx41oHO0TOdG9u1O+m1mturZW/x4I0CuyydVQ3V7o0Sw2Kby0p UDUfciomdk8lYOVAhWH1uu3/ILzdBOfN4FCPDJrSEdeCT77g1w4hgQDCL/5T X-Google-Smtp-Source: AGHT+IFOSnF1yfoqgPsmDcKeaN5h67jywpv5uazJgQ0gOiS8vdiCFxQzhsPtHo+lnBdvZWuju1Zatw== X-Received: by 2002:a05:6a20:a11b:b0:1c2:8cf4:7664 with SMTP id adf61e73a8af0-1c2982438bfmr8230075637.31.1720670986604; Wed, 10 Jul 2024 21:09:46 -0700 (PDT) Received: from Ubuntu.. ([106.206.206.104]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1fbb6abf738sm40808595ad.198.2024.07.10.21.09.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 21:09:46 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, chriscool@tuxfamily.org Subject: [PATCH v3 5/7] t-reftable-merged: add tests for reftable_merged_table_max_update_index Date: Thu, 11 Jul 2024 09:28:34 +0530 Message-ID: <20240711040854.4602-6-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240711040854.4602-1-chandrapratap3519@gmail.com> References: <20240709053847.4453-1-chandrapratap3519@gmail.com> <20240711040854.4602-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 d151d6557b..ffc9bd25d2 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 Thu Jul 11 03:58:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13729985 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7551F38F83 for ; Thu, 11 Jul 2024 04:09:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720670991; cv=none; b=qMMbR0W2gDZQ03O9Pw9nQE8bKC+ow2buUe4eLToPOLWm9JMeodyLDrP+BwMz0hUBzvcd6R271cbAExlDt1I1H6HjdIyjd7Jqq95xjMd7AUPXvMjpW+elydV4zFo+EjLcxIrrmXQ+Lklvbrf2TyKCWujkA9cKrXvMbMHPMXhEA6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720670991; c=relaxed/simple; bh=OD+GO8550twbMVzG9AAs5aAq7KepI+V75WkLQFvA4QQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aSw9OCb1QUT9++9r+nrXBhMCrZS0JzBhPevkm9T4w4YyyZlUkt6sb3DcZoEHnf2Xl4ewkf39S322cLAuupiIchD9/hf+JBqQxTRqNdeiQT/cFO3a5S3hNLPsut+NkMDyPSlj85eTb/vFtaSYCccppyIofbRaUh+xf+R7H4UCXLI= 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=iJur9PEr; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iJur9PEr" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-70b09cb7776so409373b3a.1 for ; Wed, 10 Jul 2024 21:09:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720670989; x=1721275789; 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=FKeqbJfd22/l6XZAYdto0akFbaV3uneX2ubhfZFO1zE=; b=iJur9PEr6chTQwbPiQXbW6dCdFFLSARLYzSUy2dMWQtLOJPsbBA9UUE3u7YzGp2Y1y IMvwIAYjGZT/E+McijypBTEv4ugdDqe8wbZFpftBcj7jLTVYRBx/JzGREAnGVudOd2YT 1wIuTFbP+3ZoccTOP/yWGb0lEZt75Gp6sYZD4kx7OxJExzrmtRCM7HW2kv4SbuiRPhs1 5ghDlu3C5/aIEHqUvdVIcb0Se0JckreSc97tCN3rICOSocwyRKv14H79jVCJt0n5/sS4 gycpj0zjpOTPDDKXDLlpPF6mS30mbiKZfUXGDeGzpX0KoaBWOzkstU2TnQPuqlqGNHWT LJ6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720670989; x=1721275789; 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=FKeqbJfd22/l6XZAYdto0akFbaV3uneX2ubhfZFO1zE=; b=eT1Ixnt/2B95d/k0TnMxVWOMGGDjkubEjZb0fGLUGa1PGaoeDvbpvfDVQLWTuDAjR0 xNhcSzTdBfGRKNZygKda1OxgeQfnYRseeQYnYXRFMW3I6lHsxHW23JaiRzSgMEM74oUV aDPvH029jVLOSX773SYEX+P1pPAPzL0eIIM/dUF21+YEhBvM9CehK/xP6q5eZBxsbzfn ElfkX3lRX6bL/JbjNfPBIcBD/R2/vGUY0tH5tF51Ei+sudaEZkqzzkQF4D5pEuHJpaSD vd+7JGJST2xykDIlOIJHN0CZtAkoxInVPPIA2606avVQDiZpqZiJB5ih6v0OWhcPJ1rD oCUw== X-Gm-Message-State: AOJu0YzTww/PDesb8x9EKrBA+E3OYRAGc/UnbYHsotPLdi3e2fc4cx2a NXuWTaEQMN/tfD5WHNndp3ZWFXNF0Hk3+9iVqYs+BYtFkSULacmi3QWId/Ct X-Google-Smtp-Source: AGHT+IHASsCjtkpCKEsRcWH7847SFSp4yBv/Wlh7bRboKCgLa/nvv6C8crdHOcI6sArxpq8EDtcCfg== X-Received: by 2002:a05:6a20:4320:b0:1c2:8af6:31d3 with SMTP id adf61e73a8af0-1c29820b81dmr9401767637.10.1720670989430; Wed, 10 Jul 2024 21:09:49 -0700 (PDT) Received: from Ubuntu.. ([106.206.206.104]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1fbb6abf738sm40808595ad.198.2024.07.10.21.09.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 21:09:48 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, chriscool@tuxfamily.org Subject: [PATCH v3 6/7] t-reftable-merged: use reftable_ref_record_equal to compare ref records Date: Thu, 11 Jul 2024 09:28:35 +0530 Message-ID: <20240711040854.4602-7-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240711040854.4602-1-chandrapratap3519@gmail.com> References: <20240709053847.4453-1-chandrapratap3519@gmail.com> <20240711040854.4602-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 ffc9bd25d2..e0054e379e 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 Thu Jul 11 03:58:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13729986 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.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 25B8854903 for ; Thu, 11 Jul 2024 04:09:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720670994; cv=none; b=ogJ8DNKzBpkRLqCcPajBved/nQZeCAXT/RRqQHD2sZ8zG2lkQQ7hLI/neba4pVIG2A0toUISuorhQTe6YtuSksuNnKqASQr6H1PnUilSR9rOmPu4VDc3YGWKIeGYKRW6XyIhvGZ058HcFcETnx+yUyEOXuZgc3V9aQOpe6MlydE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720670994; c=relaxed/simple; bh=l5uqwurD+3TOp7t7S3q28Z/Pfk66dmXTC1ZyMCMOlKQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QRlQ2+3A+B6FDWXG8zgLKccO9PFayro1+TGHI4fwsyoSEA0mKsiSVrncZ9z4X9tmief/muaachgp3xdDiUWUrkLVu1XIr+8WgLM/ZVSZ7FmUB9EAPDnCWD+0R85bfIoxjlNlf8wcoTCr27I4gawlbcatik84UT2ZMFB4J7bSURs= 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=hK/6vOHd; arc=none smtp.client-ip=209.85.215.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="hK/6vOHd" Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-7594c490b04so266412a12.3 for ; Wed, 10 Jul 2024 21:09:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720670992; x=1721275792; 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=UVhbZ210atv7iBD7UCwbY0VDecl1P8xa+7T0BYoV9xs=; b=hK/6vOHdsTdKGl+e+H23O1ggu5X0A0WNLHebtc5tut4jcJdYYkqDxQHdEf5f42N0pD D/X2E2EFyHT7vPXNJdn8+QkFtOR4blxx75XVkh4vJ6shvv35yOv9bGIOmHt2NiCfyaHf f7t17bnhk5b+c8u7bq8M1aIThzKN7aKnUjV5EAKiyvGpj9ISddpFWdLyO3v1xz1Th1j8 7psZ+BD0N41oaOVyrbhPJBe28Fr6y34x2LQ5DOgpy8EoiBb2Y54H4GQ0ycw4RqwII83F 68f3s0dnWfaOyLFvRzEWBvcTu3hlZc7MrqppxOxQcQkGPMMZrr9bUmDIoljhISt0DpWG npUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720670992; x=1721275792; 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=UVhbZ210atv7iBD7UCwbY0VDecl1P8xa+7T0BYoV9xs=; b=L9nK19DFPO2CAFnjSsX4AybR1pMDy7tjbW+uR9iHHoYRe+Tp0bkuCddkA7kY6aJzI8 G8IsYcDHMWcXJD57HfpFdMR4EMoEuhv5oz3IXiVWj1x5rkS2GvWV2UsrS9SaAiJDKdgL /Y0sd8fv32Qh0Jq94eHOKaZJlNte84QV5XBMgq43QjMubCnnG2bYd01/AbsLHbOII9/q 5PMsOxQ6UMbH8ngDD1tGoPjlUB0MLPrDoTl8FT79Ul7xQuARN0hU0B1Zw9E32UOVoLj7 1E+YsLsIkCzht6UiIlEjXtyEgfzGa03mrFC2L2eL35IrjaTk35sg5IzipGrjFnb+2bym HEQQ== X-Gm-Message-State: AOJu0Yx+SXmCTJXzxNfhNPk4JbrfbjxSoDBTsOUt9JsADqBvBKY6qnF/ 4lSoFOmyROIEHikO9Pi7nPZ+epK8s/mLWZ27ZdAcfv3Qhzyi4OuzYUxjMOtx X-Google-Smtp-Source: AGHT+IEE2UcEIZWGffXMhzttDE0jOWuG+0MT6tImKa/rCEjtzZLB8BgLMfTZXXL1pq4IDm4jE+lsRQ== X-Received: by 2002:a05:6a20:748d:b0:1c0:f267:11ad with SMTP id adf61e73a8af0-1c29821d031mr10466415637.19.1720670992071; Wed, 10 Jul 2024 21:09:52 -0700 (PDT) Received: from Ubuntu.. ([106.206.206.104]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1fbb6abf738sm40808595ad.198.2024.07.10.21.09.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 21:09:51 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, chriscool@tuxfamily.org Subject: [PATCH v3 7/7] t-reftable-merged: add test for REFTABLE_FORMAT_ERROR Date: Thu, 11 Jul 2024 09:28:36 +0530 Message-ID: <20240711040854.4602-8-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240711040854.4602-1-chandrapratap3519@gmail.com> References: <20240709053847.4453-1-chandrapratap3519@gmail.com> <20240711040854.4602-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 e0054e379e..50047aa90b 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);