From patchwork Tue Jul 9 05:28:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13727262 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B3C0139563 for ; Tue, 9 Jul 2024 05:39:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720503564; cv=none; b=mcfxb7I/6LpyB+sb7xq9DgUigwsYhbstrzQxaBjTfkNwEOiF9PVwUQ+5TZx9q2t6dqpLgITdY/5OnH11qv9dZk2pGbXviY8Xj/5L7zudeLs1PHsgac/xfvZmaFOoeEP+q09/UEIxCNNGdE+IMLttSfr4EFz9oR66Kzd5PMe53Og= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720503564; c=relaxed/simple; bh=BGoYmDZMRBN9f62ol2h2jxzdaePCk4fGsxAyDnv5Zao=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QePej0YMY5k/sWc05T8TxYto7BK/sTnZ6YY+teQCsp8vjL8drG2mj/4TaKpCyYoom/vm2O2U2EJbUD8B3wXeeZug+kSzHhBIipqanhTDG+9FRayQR6cmk9pX/ulYvdOm6SEcNIGcaozumhMe0WAsO2XV9BnhLYPWcABivX9pKh0= 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=m5IGH3Tu; arc=none smtp.client-ip=209.85.210.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m5IGH3Tu" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-70b0e7f6f6fso2978333b3a.2 for ; Mon, 08 Jul 2024 22:39:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720503561; x=1721108361; 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=hE1uixrePdArOl6yviRu+ZD9Ce0jxKnobOl1Fs4ne6A=; b=m5IGH3TuhEHxp/2B278L6d+A0lV2jwu9SQViI1ARiaaBJ9HxrJdwqu8jwf6xpkM8c3 UmgAFyQl7xVFW5kCDfBNShkV9Uw+ep9RPK0TaBplyPZ0g+OfgW1oJOb6NYmj7Vx7EiTK 2U/vJn8uTrOx4gsKNuOLpupyNPcnIKvql7vq9D6s0ZgAplunzLSOpe6gixRrOixt8/nH gS9ZqdJcVQE/NpOow+z7GFwKWwj/R7FAxSy5iRogbJ3ajvNCO34m/3GO+KhaZ7Wt7j9a wfG+W9xn4l39E81OXFDyt1W4QqBfA6a6GrM/WAc44b7MHHnv7Q30sOTNw9BRtD9E7av2 Udgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720503561; x=1721108361; 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=hE1uixrePdArOl6yviRu+ZD9Ce0jxKnobOl1Fs4ne6A=; b=W2EoR3s70/gOCiunO2B76hkw6+P/yM5HEauBe7klaHgLupSG7dwzsfpJulsrymhdse a+M376XeNNfJjGDb93Lj961a7U29hp2nXtwWa8TOUhey2I/+f8iL5m81oM2BFA3EQrYp pAaEm/DUjnBKxmr8fVoA7SzWLfkRofq/BqiAAH6pwB85nrvRiVN4/sbfms9u7CPks8A0 62PqmK7NNdSt4rfAlvRic0xmCeNLN9+uJ8PPADxnqe8hVfkMX1j5Tk76SViSUebylTyB Gn7OHJVKpjCoU6MsFlS+UMaifTLa1HYnueQqq56Xbe0DCfl7nu5NmsZgI7hECKIvjQ2V yDtQ== X-Gm-Message-State: AOJu0YzCdwo8M34/XRlDsrTJCdBID+BCzUQ2lcE67U2dq5jzvjobj2dR Zp93yTUWWcA/hDCu6tJ2u3wP3qTIPbpRQqe/ZLqnNeLm/kmz+wAE13c+bQ== X-Google-Smtp-Source: AGHT+IHdyNsCSSi/r3Z1mxxCIPG3kQ83AiScpd9oRa0yCX97PTnYkbzkWZhnFIn9d1OZQE/pY2nz3w== X-Received: by 2002:a05:6a00:2d84:b0:70b:a46:7dd6 with SMTP id d2e1a72fcca58-70b434f3333mr2311323b3a.3.1720503560848; Mon, 08 Jul 2024 22:39:20 -0700 (PDT) Received: from Ubuntu.. ([117.96.144.60]) by smtp.googlemail.com with ESMTPSA id 41be03b00d2f7-77d61922ee6sm718448a12.46.2024.07.08.22.39.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jul 2024 22:39:20 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: chriscool@tuxfamily.org, karthik.188@gmail.com Subject: [PATCH v2 1/7] t: move reftable/merged_test.c to the unit testing framework Date: Tue, 9 Jul 2024 10:58:40 +0530 Message-ID: <20240709053847.4453-2-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240709053847.4453-1-chandrapratap3519@gmail.com> References: <20240703171131.3929-1-chandrapratap3519@gmail.com> <20240709053847.4453-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 +- t/helper/test-reftable.c | 1 - .../unit-tests/t-reftable-merged.c | 113 +++++++++--------- 3 files changed, 60 insertions(+), 56 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/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 Tue Jul 9 05:28:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13727263 Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.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 F0A3F13C699 for ; Tue, 9 Jul 2024 05:39:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720503566; cv=none; b=sTbaxoKAOtWqBso3U6TDb9GbiPpsnUxAJd6Eu3WuInEXfQuYRPe2tRsAP0vNT4zZnkVRqvnjKjr0h4ZMuYv2yr5oTCjSIQjAKd1WNOkKQ1JddaWAAzVMXeWZ14x7cx2wxr7nppVZkbWxnjOpAqeLsQN0muZTfYCK/QiHcghXx68= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720503566; c=relaxed/simple; bh=itnQfu0Oi8TL0VxbM6VKsYi7tx9KSFBzORCo2kprD5s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oKI9Vu1e4YIn8vvDIicGsoQNOoxYb1fhz1RR9RvzvFs7HJyIz9SvQolpDZQaw8z3853pfG4dXGnKT0Ua7kvnb6XkoS9AyRtWujDoHgCRPqWO+alPgj+ZPTvWI19X8l62hTsyVU0NrkeFChwdrRCBJSjCuA5dFY10TXZZtKPBp/s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Weg2WsS/; arc=none smtp.client-ip=209.85.128.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="Weg2WsS/" Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-64f4c11d2c9so37395147b3.2 for ; Mon, 08 Jul 2024 22:39:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720503563; x=1721108363; 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=Yvk7yyAF333g6TbWR0aaykoBlxXr8ejFrK6DYgyVXh4=; b=Weg2WsS/QYECk3Eu/BcmhxzFRIY2wj8ajK5Ub/85R1djGKK0GVbiXk6kDBAWOBAw0c 4mTwkCDZT7hWpQ77d7sNby+W/Y6Isg3Pgq2IAvI5iw9vp4qZaxt2xlguRfNx+By9NUEV vXeQpxuUWTmdBLL7ilVWMsKQQMai6V1IsgwhetIbHa+LnC3ubvgi+NYYstlJglaJbeV1 KaR6V3aj2UIL1cVsHstUEsQCBqBZaP7cZD1vhHRGeE6apETgVcXBtl6QGQDLhqFBLTev c9MfW5otJeRP/X3OzclYQ9lokV5YPUQr9Qrjr+dF4m829LgNuaCFB3sY1fB2QDBGyF+w uCEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720503563; x=1721108363; 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=Yvk7yyAF333g6TbWR0aaykoBlxXr8ejFrK6DYgyVXh4=; b=Y+7aw9PeTDiNIX5wSd+e9maJpMCOVX4Dkd31L/4EhGhcPGCL30fb33/S7y8MJmyk97 3TIlZclzdmDcBvRq7pqStB88c9YEoCT2PhhkRgaEiAgxiOH6q3+1F8PwNqoxI1/lIvbS fFZUkroFj1/fK21fRGDyBjl61I8s3/WqOfjhEFpJFS3EpvC2VQUS/XLJj5atHPym9vP1 f9ibW0w+bdvQ2YnyBlZJaa4aGkfmJM+pgasenL2GHKdt7u61bH7Ea7HNR6I3f1m1jlt0 H2pNSSboI0tvGmxMEmbipPOEHNN8zXKqD669M2Xw1ljTpgUxKV+3zJmEGAr9DqFEpg/I FoOg== X-Gm-Message-State: AOJu0Yz9n2T/XYsPYl377iDUju3phmUkoOZcp2SBOIkkbMtf+dxyMZmn VXNrl8Hy+Ld0x92a63iDroc1oMhD5eZnA2eMzQvZHy8Q6EeooSwO7vR+CQ== X-Google-Smtp-Source: AGHT+IGwukvIqcsRyGCN546k6vro4TGhvt5i0E7iKvcybaUyrpYwpA8qjc88XwShYuGvk+k1vg/9zg== X-Received: by 2002:a05:690c:b8d:b0:650:11d9:b65a with SMTP id 00721157ae682-658f09d2252mr23397907b3.32.1720503563355; Mon, 08 Jul 2024 22:39:23 -0700 (PDT) Received: from Ubuntu.. ([117.96.144.60]) by smtp.googlemail.com with ESMTPSA id 41be03b00d2f7-77d61922ee6sm718448a12.46.2024.07.08.22.39.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jul 2024 22:39:22 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: chriscool@tuxfamily.org, karthik.188@gmail.com Subject: [PATCH v2 2/7] t: harmonize t-reftable-merged.c with coding guidelines Date: Tue, 9 Jul 2024 10:58:41 +0530 Message-ID: <20240709053847.4453-3-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240709053847.4453-1-chandrapratap3519@gmail.com> References: <20240703171131.3929-1-chandrapratap3519@gmail.com> <20240709053847.4453-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 Tue Jul 9 05:28:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13727264 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51A8813D516 for ; Tue, 9 Jul 2024 05:39:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720503568; cv=none; b=Par8uWpDy06K8uG94Ju/I33hc7iAaon0dMHj6VteDqhyGlgmrIv12EQzEoeCD+UtmgEmRUzqndJBuoRha8bYkKhgK33E19AnHus014y9oy7iYrNgIY1yE5wY9lNcaokWnhlNe0JXAreQljlTFbq+TEs4TN0o6mc0RiY/T3HvAnI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720503568; c=relaxed/simple; bh=SBC4j23TKqNQEOoJltnSzX7uGoPUaqtKhjdAukHsbug=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bUiebnSMA35YTQRuGnlXY6PzD38/LjtMgvyX5dMb685/EIFzmgw/uPFawh8R8u5TSAqWTc0UZpVjHuqNYFwikIEsB/pYdIi/6gecFDo5IVDkxDJHBudPR1F9mOSib5xvL+7w4BlebkyE7GUtMT/vcBYGLR2Vb0prDVj01aTds28= 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=Uj3XqhQd; arc=none smtp.client-ip=209.85.210.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Uj3XqhQd" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-706a1711ee5so2751992b3a.0 for ; Mon, 08 Jul 2024 22:39:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720503566; x=1721108366; 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=MVve2uX7NQmpNx21gMmznjyJyKMUr40krED/uuYLUqA=; b=Uj3XqhQdaNBvPCAS9gu1vOz5vIvaC8eP2EbNN54NBqdoz6mEpVg5gVGrrp2R5v919P 2MN4CCgMSzkOEF7cKJg4gfJjewt/m/m20464ynNgzKGxCwGDRTAeAwVY+SDUaQ9dPh9u w9DFzgnGl9Jbuw06i/aMgF/3iIPINE8Br1YeJe5hu/aZOmAiTfnQdJZdc0i4MR2dmbZH QTCqrs1zyEraaJOcix/A577bnTZWC1lh4yjAePyn/7UFxu6Vwfq4d2MrshCep+FlDKC0 to76sqakqjW7PvUu639ipd2+g3iaoJgYEEM/MChHbb12pOp0lG43OMI8bohJvPWYf0EL vGkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720503566; x=1721108366; 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=MVve2uX7NQmpNx21gMmznjyJyKMUr40krED/uuYLUqA=; b=QvMOe97PxzWb9FV8zR5DfWa6OMIbveEGY6N0ZVnF5DVvlFSvFIpSUKL01Z1FYlZORo 1HmcBQi9r0YEzB64ne8so+oT/9f3ZSt6pDYjwpzVKELnRGBPt+1cw8fltCU6Sf59fcko ixkT+39tdN+8qaRy6niQVH7ICQ7qaiemh6O6wE9mJniBmQDoi7yYgXhcFlTmS5gOO8XG lDXYC0bGEg4yCdy52/nJlVMCM8q19xfk7SVWIEmxX4Bd9m6X67KbFi1NjCHxQrMVx+Hn ayXCqJYXa9Jauy/+azooA4csllb1qgLef9jR+P552Yl5i5ozwW8lnd/MwAWxPRGwF6lq e34w== X-Gm-Message-State: AOJu0YyNeBsfq003B1sj6GN43SIW0NY2D8B0QtwAqKK8fxvHE3b16w2k visAR3H4kbQ7shVrAwN2WJSKINo5AfnWi/AXwE7kibP4jhNeD3GHPui2Cg== X-Google-Smtp-Source: AGHT+IGuBn4V/HaV+eKQ47jJQwy7IWYb1JtgJz1HNG7W1Gz3KNBzc2L5BWF0UC5UWMISVyZuKsANiw== X-Received: by 2002:a05:6a00:1249:b0:70a:9672:c3a2 with SMTP id d2e1a72fcca58-70b43632384mr1722608b3a.24.1720503565738; Mon, 08 Jul 2024 22:39:25 -0700 (PDT) Received: from Ubuntu.. ([117.96.144.60]) by smtp.googlemail.com with ESMTPSA id 41be03b00d2f7-77d61922ee6sm718448a12.46.2024.07.08.22.39.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jul 2024 22:39:25 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: chriscool@tuxfamily.org, karthik.188@gmail.com Subject: [PATCH v2 3/7] t-reftable-merged: improve the test t_merged_single_record() Date: Tue, 9 Jul 2024 10:58:42 +0530 Message-ID: <20240709053847.4453-4-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240709053847.4453-1-chandrapratap3519@gmail.com> References: <20240703171131.3929-1-chandrapratap3519@gmail.com> <20240709053847.4453-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 Tue Jul 9 05:28:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13727265 Received: from mail-il1-f176.google.com (mail-il1-f176.google.com [209.85.166.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 A094F13D8BF for ; Tue, 9 Jul 2024 05:39:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720503571; cv=none; b=LsNY3BzZs3Ud1OglkZfTwrxRr+L3yYlb5ZhQj7S4gqzQnSSLDW8LqzDE34WyYxwX9VUJ/5kgl8Mys1OsPAo5o4BJFrlFqoPP+TLyBqbhqNIAl0UPkk9bpOiIVfu42GJWRjRwnw1Wb7BuC/dh6HvxyZS1Efklm44O2CrdLDmzLS0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720503571; c=relaxed/simple; bh=wdY4rbt9T8EYAx9TI09RrVo7QZ/qHqCI0oaCNEIBAN0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ForJE3giMg2104SBwIJrUVQa9YqoQcjORpl3iVBoikDiN+3feOoSD+mJqIejJaGSsC7feTsfuZGIMkHCAJ9t1CuJkqEVXXutcC29g8yZqDQ3RpRKrUkFeSZwBmywHZnlikUhf+RgoLRcQY92TPj+YUaTmtOi+oXcQ2FILN/A6uc= 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=Euy/SCKk; arc=none smtp.client-ip=209.85.166.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="Euy/SCKk" Received: by mail-il1-f176.google.com with SMTP id e9e14a558f8ab-36dd56cf5f5so17965045ab.3 for ; Mon, 08 Jul 2024 22:39:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720503568; x=1721108368; 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=Pb1pmm0NzfzvlKCYkjSJOAkVlPjk8a1r8uay8brZ7Zc=; b=Euy/SCKkqUv+hwbpS/QYaEhWZ+OhNejFXD6/pFS0XTQiCPqr6VZxCr9mfZIx7zxXIc o/R2ywcltKT2zpPvbV4umsAOxWk+kmtg/oFkGM1QJxHl8CWJiuTYbFAfqsy5hQIaGlDj wbVPBhqpwr1iUvn2x7s4Eoj0XorZlMsYMm75Q/b4IedDrp3OQ7K0uae7fGouW61uX8jw PQaE7uexJ19QBDsVj8scnnusH50A7vs6j0AjMkX25ndtYL4v47JFtNPwhesDVS6RFBIA tPkgZKm8bDgDiFqwYXR3QhYtIBedkCalyzt5BMSepKlZCrwoyeyU30ntkC3H2FE8Z7f6 /wrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720503568; x=1721108368; 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=Pb1pmm0NzfzvlKCYkjSJOAkVlPjk8a1r8uay8brZ7Zc=; b=VuMfyqglLkDWhyDQdB6t2XQINAhGwVAzxxSDY8fgSkjH523QbKmsHa0l9BPkou3ZSC jpCYDvLgm0e6jSyE80gawc3AckDXDJt76QEULV/Zb871YNrCvC3EXxOum8KlW5KGDQgw HXA24D8pEGXqJtl97WtjGYnNzp6hyMKl2VCHW8DaWQ2yaCiGKrMIRagtrpWy+CscoEfn Ni5crIS5B5aUsEf1wmZjzLU634CkYK68IGZOQAc2v5Oscb30HdrE4Uv4MUKX47R01ERN odmejaZBb0vYtfPDLNt/jJb4hJV4cPKsoGglNmqK6PSNosiQW6Zb4lbTC+Xj7DnPkN/z nu0Q== X-Gm-Message-State: AOJu0YylLfisEgEUGGdEPtNoTUe9CDia7Gz2wsD5RzTdHj3EgCEUq4mh UgbVwNy4ErHHV3aVC1FtC5+3+1+MApL8K2Swh1Wp3K5RjpaOmOtj9JFYQw== X-Google-Smtp-Source: AGHT+IF/lr/WdSnThFgK0Z5fu6w9ViZGr8QkDgHlkkysVOGFzmYQ5ag6gQRx1dpNNmb0UK0Cn5WXFw== X-Received: by 2002:a05:6e02:1a08:b0:376:24b1:174c with SMTP id e9e14a558f8ab-38a57213341mr20700805ab.3.1720503568103; Mon, 08 Jul 2024 22:39:28 -0700 (PDT) Received: from Ubuntu.. ([117.96.144.60]) by smtp.googlemail.com with ESMTPSA id 41be03b00d2f7-77d61922ee6sm718448a12.46.2024.07.08.22.39.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jul 2024 22:39:27 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: chriscool@tuxfamily.org, karthik.188@gmail.com Subject: [PATCH v2 4/7] t-reftable-merged: improve the const-correctness of helper functions Date: Tue, 9 Jul 2024 10:58:43 +0530 Message-ID: <20240709053847.4453-5-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240709053847.4453-1-chandrapratap3519@gmail.com> References: <20240703171131.3929-1-chandrapratap3519@gmail.com> <20240709053847.4453-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 Tue Jul 9 05:28:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13727266 Received: from mail-oi1-f179.google.com (mail-oi1-f179.google.com [209.85.167.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 B8A6D13211E for ; Tue, 9 Jul 2024 05:39:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720503575; cv=none; b=Qi53PlGJDkySK7e3i2DorXnUGLZVPkiFJlxz7Z0RNg6ryYwvRLXhhMk9VZNqiQiyy4k/OOgH97TNn7ub3TSDeA2N+z0/SBjPftbVyaV782wfyuLq0eziBZu1yyRqEDHTTSTBExcE5PQ/WaCb+UT56jazzBRAArd07B4SMR8QDyk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720503575; c=relaxed/simple; bh=Sa/2HiYImtRrFY9FizaEfTvncKypvhdHl6djbY6lbZ8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ohSPZkYZ6Pkkzx/wiYPlrv8aLH9mjRU7UQOubF6LKkwWQpykfEw9p85bS2/yUPcboR8aI9QvDlUF7xOGm2ZtYNJZpExOfJF6vDj/8TWIZi/B/CiP1EILy2ag6IW5cZHvkKk+rNoPk6epKSgKndQQbwtOdSTEm1RgF0YhR6X43Vc= 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=QNiyeQAY; arc=none smtp.client-ip=209.85.167.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="QNiyeQAY" Received: by mail-oi1-f179.google.com with SMTP id 5614622812f47-3d92bbadfd6so1351133b6e.3 for ; Mon, 08 Jul 2024 22:39:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720503572; x=1721108372; 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=+TuNQAnHDOlUzacIPBFcgqMbfhHZm0oOlkOemNNHgIE=; b=QNiyeQAY3xUzvUfXoyIw9ffAQsaFPahAsNN4B2sEIvDgVJqFG926YPavoipDRYnoO1 LswnpA8Ok/HkreckxhfMlOewDZlT5CwKkzZWYm+oWcrbNTLRsmaGWeP0J5BotiQUHnxW 6j0KulZs8bFKQDP7hPExtS0Zcn67XGh1HW/ooUDmL/dNlG4WZRmdIq4wANBNwBcXT18d O0CoKIDSecrn5Us1DKJGDJmQHQNrqkMPSyqY4sD1/gX3+0DtuPVZqBE1222kNlWhSXZ8 16pvQhBADo5TuviesyQF1IzUPplXrUfZE27U6c0HyCC1o+KxjKgOvlKg3iFLNLLC3mnv R6Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720503572; x=1721108372; 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=+TuNQAnHDOlUzacIPBFcgqMbfhHZm0oOlkOemNNHgIE=; b=p1Gv0pNMWP5287XWt4bmOwTwGyzqQ/vjJ8ZWu/vbwtjMR6CG0Yylys4t0eyygF/pEa oYoiW32soaln1l5UW9Gu8j+LZYovPpTNw2JsPcrGG2sjDad8naqj77tqgVUgSALdEGX7 6F0gcOkzSdHhnaGhWFpVQM1oC+EKHDjVmWyUIOJKYLNQexNtbNQpBezS+Dg0sHFM1EHV 3ubjRmGpzGAI2EfTLl0dVX/GFHPeTAUXP6eMzLxgzsYfJYg4dv4lvBefIQUrCMPaC/wD CpFRMWazKkVXIw2hdS5/Lm7Xq0LyHZRTjcYiSwRbFnK6sdtfSiSp8d6Dhhxe40mFaH5f TMqw== X-Gm-Message-State: AOJu0Yy++UsuvMNfZyWAtfLMXMrgbwtyHrfmWKcrlATKZ94AHiXeNKfc jFj8a7nc8L2UOXjbJ3cLTZuVP0T0Mag3Mq4SGcwccleVrKA6/xqVaL54sg== X-Google-Smtp-Source: AGHT+IEjol10BH+8uCRww+MgSL0hLth4UoX6KWejrUEZ6uKGPpV3Km38LAm2yZYyHcHoG+lsgJC9mQ== X-Received: by 2002:a05:6808:1b2c:b0:3d9:29c1:be5c with SMTP id 5614622812f47-3d93bee8ad5mr1815282b6e.12.1720503570554; Mon, 08 Jul 2024 22:39:30 -0700 (PDT) Received: from Ubuntu.. ([117.96.144.60]) by smtp.googlemail.com with ESMTPSA id 41be03b00d2f7-77d61922ee6sm718448a12.46.2024.07.08.22.39.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jul 2024 22:39:30 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: chriscool@tuxfamily.org, karthik.188@gmail.com Subject: [PATCH v2 5/7] t-reftable-merged: add tests for reftable_merged_table_max_update_index Date: Tue, 9 Jul 2024 10:58:44 +0530 Message-ID: <20240709053847.4453-6-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240709053847.4453-1-chandrapratap3519@gmail.com> References: <20240703171131.3929-1-chandrapratap3519@gmail.com> <20240709053847.4453-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 Tue Jul 9 05:28:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13727267 Received: from mail-ot1-f43.google.com (mail-ot1-f43.google.com [209.85.210.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBF6613213A for ; Tue, 9 Jul 2024 05:39:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720503576; cv=none; b=CRmHsKlXwIite45bWYns7mMv6n4qOO2qW7zaxUMbh3iMla3qQGwuIdQm3NfNYysSv3mjMxY1oxVupEUHMgVz4bpfa5X7JzJzHDXXTWgslQhE6/wLa54XmGUue4dP/ejh/XLYlbnCcxathTvF6fGe+NcHvc+Tf9pRyZS7gwZz0ww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720503576; c=relaxed/simple; bh=YGe8pze5q+b4jKpydQ7OkP24+FlYAGDlTUNh5OY1vlg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sU6U7dT5PCYV+0o+a3faxg219yVNIJOLbI2wUkEZJTQexdDuvEmljE6jChTewvlOjLttW0qS9kK7g3sw7TkKt0QwiBjuafcjnTtqFBlqqB9EHzZrF6EgoT0hHNTsakXLc9pJESUacEq9Y4lFEjE56pxm8tRw7uUZu0qxNe2jB/M= 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=Hz1WWCfM; arc=none smtp.client-ip=209.85.210.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Hz1WWCfM" Received: by mail-ot1-f43.google.com with SMTP id 46e09a7af769-6f8d0a1e500so4337980a34.3 for ; Mon, 08 Jul 2024 22:39:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720503573; x=1721108373; 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=aVjcw9U0YRb6Z7P5tNfEtoFkMcmH/GucwULlZQ3hCgI=; b=Hz1WWCfMegH7lGn/A6n3MWYBoZbw/j32yeMiezwoclNvnHUuOpvDMsXn7O4NdlwFca gN3lCwN+PBprFOfahwKGohBnGVYQ8GYqdwAxfn0w70eJ8m1DHdh9GCuobA56lQGw2nnW TQNeny/CPj77Bu5opIWpuGYJuYneKfPK//xW80GQZgqqo1MPImODcgS491UCYmC8Ag0x i0w2HZznuW4GgQQA6DxBrEpGLlMekc3c9tiRNm7D4iGA+oWwsiYfb4PVpZ1PILSG+dbg rB9D3Sb9Gto923BzXu4ymHg3jKL92EdXC8pqyUcyFJcj4aRF4xeDMIB7uHqVjFAzypp6 hrGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720503573; x=1721108373; 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=aVjcw9U0YRb6Z7P5tNfEtoFkMcmH/GucwULlZQ3hCgI=; b=faE5nO9u61enB1eBLDjkvEjgAvdcCscgDlO1nDyUuPcZemwHlL9vJFrR3M/rRQKdCA cJ+stuC4uj5F7hOYNZVFTB+qZjeT/vltUsdOw1Mys80KMwixF43x9GZYMqRtye2xOaLb X5RUKkKrFDC65htVJPPgPBwa4NhphRRnZ3uY7ml9TLSXouZDaxsRT+6Vi0GG6MmaTqox /PN3medKJy2urudDOcTjJ5ARPwN0NIVe+HF6KDgsRLMmt875wIv2ey+jHoaI0bWFuiuK vjB3zjA8KYs9TpWtOYKTeHC7YF94VI/i4ka7MMvE+VvQ4A9/F4H7It7MqCz4qR8KKnwN shkQ== X-Gm-Message-State: AOJu0YwV+d2cgvDZjrlL4QpI39fm0QEwbBOqWKnmHmIrDRuMuhB9Bdwy Ze8agkEThLL+mWRpTLFWqmPBxNikBvGNOhmPCsIsfOdlqHW0uPUPxmaAxA== X-Google-Smtp-Source: AGHT+IHFkr2Qt0ziLuQCF6F17sz/PEz4bPMuKoFbqpb8b6wh+qp6xeiqUnX+OEr8o+8hetpPVBD5tg== X-Received: by 2002:a05:6830:1389:b0:703:5d25:659a with SMTP id 46e09a7af769-703759faa1fmr1909868a34.8.1720503573201; Mon, 08 Jul 2024 22:39:33 -0700 (PDT) Received: from Ubuntu.. ([117.96.144.60]) by smtp.googlemail.com with ESMTPSA id 41be03b00d2f7-77d61922ee6sm718448a12.46.2024.07.08.22.39.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jul 2024 22:39:32 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: chriscool@tuxfamily.org, karthik.188@gmail.com Subject: [PATCH v2 6/7] t-reftable-merged: use reftable_ref_record_equal to compare ref records Date: Tue, 9 Jul 2024 10:58:45 +0530 Message-ID: <20240709053847.4453-7-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240709053847.4453-1-chandrapratap3519@gmail.com> References: <20240703171131.3929-1-chandrapratap3519@gmail.com> <20240709053847.4453-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 Tue Jul 9 05:28:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13727268 Received: from mail-oa1-f47.google.com (mail-oa1-f47.google.com [209.85.160.47]) (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 B59E713213A for ; Tue, 9 Jul 2024 05:39:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720503579; cv=none; b=LLW6SvK8Sc5firHtREQA/uYA7EwbzZy0G9zeiDe6SMkPd1lM777LnxssKhG2A1LRJ7Wlr68GIg+QfrWDyRWRVAaXq6CRue5z6ygZVYqBAVIaM9GKd5CoaLT57TmEMOf77Vcw8mdRYWDE1WVMQuoJFsYMibLoQZOWTfJY0zyw9Ko= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720503579; c=relaxed/simple; bh=bKyNNqkunT7MSXJ5o9xsmRqfxJFuS9Q3A9/phvSI8W0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MTM/cSQExKKOsb3TP9gEmFhpF4Kchg/Bxjf46KdqMIZUazsVHhtJZUnypuw3ed5fyRC+FQ4yNuo6oXVzDVbSpv0ySXworpnKrM1mKpJDxq9tPmNUbKTK3TMDG8JppdyN12i6i+bemtDRsurNtjLhN+EfHxTbfPBWI6pOellmGMc= 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=ShpJ38Ws; arc=none smtp.client-ip=209.85.160.47 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="ShpJ38Ws" Received: by mail-oa1-f47.google.com with SMTP id 586e51a60fabf-2598001aae7so2380437fac.2 for ; Mon, 08 Jul 2024 22:39:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720503576; x=1721108376; 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=U8y6UNrFd3/6BUDhlXb8VSUHrm8G92ZU3xaEH/MoZSc=; b=ShpJ38WsbqWAcdNp5Gsx7hG8o1i9VHhIfE/YJgXSQVatYTbIiCSRjZa4OwsF3xjl+u h8eTzhq+6Yq+OM8mfk7AjCoKXwGuwOHsQ506BZGdf9CuTSerJSjfSj8u4THyp8Hen1hC uwq+z4MwTU9OJMiD1M3lN9n10gWlomJIyKofHkEPUyGDBFyNbU1Va+yISUpCGai4soZo /GWTauxJqxz4p2HUJer/2ARLqWkiHHmc8D3vVAF+UdwpRF5rCBZaSdF0Cnzt4eUHqdp4 HKcacpI6tJLgmA7LhSwuMeDoiqNof9Vy/B6WghN/5FqG4iA6eTbmfr1r5+i6rHRDgGwY k4vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720503576; x=1721108376; 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=U8y6UNrFd3/6BUDhlXb8VSUHrm8G92ZU3xaEH/MoZSc=; b=kDs4xu7hk7tNxKg8zf8ByKOgniDO0eg4u2/xVvEb8oSSEwTBHUvcnkIqu4gmyn/lH0 0k7bL+9SGOalRsYuC0c6OQ4hoPKP9CRxMegPyzqtZfqvDV7Vy8fJ4RKcCiNUwRlTwLbj EgWuIafiqd0rkD6EYfNPc959mCOJ4ZQ43E1s9a3q2bH1rrD/aBZQQs25qTBgzKXm4ydz aYTfxp5zWarA+gd8u3DidcmtQMMkr4xNEhAIjDZP/cQ70meNaq798dgAlwnelRjQTM6i YfTh4ALiyvquEj9kdQNKCUvOgof/N3CP6QR9jTb07o/UNOvEZ72a5vDVrkRRJ/7mITws kXkA== X-Gm-Message-State: AOJu0YxUv34XSwg1rJUA9UgiXmJOIW/Wdqe6eT6DOYv/BEDHIykhVv9J TfLqziiItQZhoofSOFDyTgcrPrVgf/WyzZLcWavD3JLaL421NaYa4dcrkw== X-Google-Smtp-Source: AGHT+IGRX81cvo+i9zBo3qwfzDVY16RXF9HWIWK5wUBsh/ROZ8BaalYWJzDD/pacj8Ux0avnOi6MGw== X-Received: by 2002:a05:6870:d892:b0:25e:2072:b1c with SMTP id 586e51a60fabf-25eae81302dmr1200548fac.25.1720503575828; Mon, 08 Jul 2024 22:39:35 -0700 (PDT) Received: from Ubuntu.. ([117.96.144.60]) by smtp.googlemail.com with ESMTPSA id 41be03b00d2f7-77d61922ee6sm718448a12.46.2024.07.08.22.39.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jul 2024 22:39:35 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: chriscool@tuxfamily.org, karthik.188@gmail.com Subject: [PATCH v2 7/7] t-reftable-merged: add test for REFTABLE_FORMAT_ERROR Date: Tue, 9 Jul 2024 10:58:46 +0530 Message-ID: <20240709053847.4453-8-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240709053847.4453-1-chandrapratap3519@gmail.com> References: <20240703171131.3929-1-chandrapratap3519@gmail.com> <20240709053847.4453-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 passsed 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);