From patchwork Wed Jul 3 17:01: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: 13722611 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.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 47D8A1849C9 for ; Wed, 3 Jul 2024 17:12:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720026737; cv=none; b=kRsOjqZZfePrejB4BiJDtaLKpBaR5gQ/kPGZmtzcjEo2XO9gLWvVmfCHCSDfuzMbaIxpC+O00ek/n5wkU2ZToABpq6z5nm+n8YOS4vJnbFcfgzBbGGxALSo78x8qyBXX3G7EiE1JlZrv3m3a3MxTD0dHkLKNv/AIz7yoFvhGMHQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720026737; c=relaxed/simple; bh=4zV6rA+j1h407V4JjTbeK6Ln96j9ayCLZyPa3wAGyN0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pCvqsMv5izICa0QzgDljyisWSwg8UoR6MJa55PXfMDc5UIOZnsOFo4c8UH8Qq/IegFBu0CiekgyaQyKxRDEuk11vp0ErPXiJ8alXVEv0jTOHiQz+h1KpVUs2cHiBnsuJGaSLkWp/bqpAlAYSrlXVkRciDsEhyYjR4fPZFnRI8cU= 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=BR4YC9kQ; arc=none smtp.client-ip=209.85.210.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="BR4YC9kQ" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-706524adf91so4570211b3a.2 for ; Wed, 03 Jul 2024 10:12:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720026735; x=1720631535; 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=pZvhuI93G22Gy3kkwGg3fg10wud/QD0owA06PJDlkgQ=; b=BR4YC9kQlPnEDJ8SNjgo3WHN1BKYv6q1UjcoX9sI10Rj+tX3fJySa4M+1on8RCtK6P Si3+TgNz1LUgZ/92XVbzleyJq4+N7vhSxNTqkkBu0JYDIhlX6DDqlulZ4Trdzw6j0ctQ QJxygz7x9BkAWLoCSnzUH8NVgrXtaOuUNB1BW1LA93SZvi6gqLepQB88GhYpGJCxbF2k 0XGNbbGzBdvY8LF5tPyirYOeaSYr+wOB4ALsbmZDeq4sBFTrLieDLK5ztH2pZgDDvtBO lddUo1Eq+hrkPABmvOLguyQXkxWpcoYJ2V/liPJeIG4+3te2P38zflLwBImUjiOPq6Fs GNEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720026735; x=1720631535; 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=pZvhuI93G22Gy3kkwGg3fg10wud/QD0owA06PJDlkgQ=; b=Pj7VP0N3Zrya+vFniWNG1pTz+ZBrJ3zPBFs63GeraWmWUQJJhYnKy/5OaB6xOO8iEu 39UGURHddr+Tm0mH6gZgCNfN66PvXO0x9OWU6FpePzWJk8R0sbeWLUeZkm9KMH09AmER VFqCYfSpcz7ESGur9QT17jOYaej5FIojfyff7d6OO0HgW/WLzxo9W1bvYZOyGv2oxPCZ YJvUrdBAzG0X1Gl8/Mj/LQHZ7xFz5an1DKeN/OTtliFIsGeUqkMRx0oBjXMhwH0V8Gue P+lry2csLPi/En7n1Gn4E6Ei5ScOHAmshyTVwstYlJR4qssaS3cBvf5ZeyVWGv+1oRj/ Q2/w== X-Gm-Message-State: AOJu0Yyo+xlED8aRuxc/Vjf1rv6VCO77BlgeR0+LJs4UErnW/IM3l+6R xozHHhjtHAFJaqs6uazlEunFtimUEe40ii9c4VWlPuIo1XuuSHIjncy5pQ== X-Google-Smtp-Source: AGHT+IFGYa4HqjmL60bplzygw9QoJZmSJU/3MhI9F4WjVtHkHyG5ljybn+o6lKlUKIZWmQNKalvT3w== X-Received: by 2002:a05:6a00:9290:b0:70a:efd7:ad9b with SMTP id d2e1a72fcca58-70aefd7b02amr2263520b3a.17.1720026734740; Wed, 03 Jul 2024 10:12:14 -0700 (PDT) Received: from Ubuntu.. ([223.176.57.184]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70803ecf966sm10678860b3a.124.2024.07.03.10.12.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 10:12:14 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, chriscool@tuxfamily.org Subject: [PATCH 1/5] t: move reftable/merged_test.c to the unit testing framework Date: Wed, 3 Jul 2024 22:31:41 +0530 Message-ID: <20240703171131.3929-2-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240703171131.3929-1-chandrapratap3519@gmail.com> References: <20240703171131.3929-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 | 112 +++++++++--------- 3 files changed, 60 insertions(+), 55 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..1718489f06 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_between(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(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,23 +431,23 @@ 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); @@ -451,11 +456,12 @@ static void test_default_write_opts(void) /* 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_merged_logs(), "merged table with log records"); + TEST(t_merged_between(), "seek ref in a merged table"); + TEST(t_merged(), "merged table with multiple updates to same ref"); + TEST(t_default_write_opts(), "merged table with default write opts"); + + return test_done(); } From patchwork Wed Jul 3 17:01: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: 13722612 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.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 7BB991849DF for ; Wed, 3 Jul 2024 17:12:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720026740; cv=none; b=ZlJoHeJp05+ARU6edcozaUaVpFBskMUve6uP5lLj/w4EWTMiGL+YI7Zp2GF9h0zk/twaQ9gpvSPmP9NbC4qDl3ZEtcfvd2q7ys4n8ssFlQuYw7XAZxiSmhaH3nuE1T7/8ex6SI9HVl0Kzukp6w+Wu1htvE8ZPwFA8pyf/J82keI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720026740; c=relaxed/simple; bh=Sv8sY0HCo+TNmEWlreQTRco7HIzEiWZfuDUOSLkpolM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Akrs5Cgupma7VpnNERvHDp2PeNIFRsVeZMAZ9W9LEzbw38gfECQDQ47E3ZDGO9Fezg9Tv18H0u4VVQ53qDOptwR29cgJViZdwYcTexV46xBpXMTcbFnpxszghAwo/IoUP1wGsO8eEiP+v3TGZT/gqpPguP9TSOHnaP4EOXK9Yyg= 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=HwsuBX+H; arc=none smtp.client-ip=209.85.215.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="HwsuBX+H" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-70b2421471aso3550613a12.0 for ; Wed, 03 Jul 2024 10:12:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720026737; x=1720631537; 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=dqvizdpcOzly+bK5Xnz5ZpguxaCBrn5V8w7Bq+KOgHY=; b=HwsuBX+Hz+P1CzJlOOxeVw36ZYOMPr0oELiuLQuJCX0Vh201Pa13iHdMmQWUoFhcfn 55baAMF3IerVWucY/JpTcGcwJ2daQyd4jMXIPi1qelzXI/CWDA//S6Q+v8uGPgPOSxXp 513wPiXiSPxIH6pnEPZG7U4P52qt+HhkU2jvS6lET1RqADwaQZmfhBLlRBKtcTLFJws6 h55YQwd/SMwoGU9nJH82MFvuxXJrx/JI4IWElOyXCS4wGp9i1wc95JoWSUm0ioscn9Y/ 6VeomaQLxRTSyRAgJs5qBLMmpve98W0TO36Cq5og+o+gdIGPa3bJFgIWQ4JziiZKBnUX MFNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720026737; x=1720631537; 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=dqvizdpcOzly+bK5Xnz5ZpguxaCBrn5V8w7Bq+KOgHY=; b=nJ+CiUaqEfg0aUvioY2UCwrRIdo5mEcBGQBQDUosjs2dqV6llIf8lJ5g5OTRODio/t AXPJGwIVNU9551oJgkiXPyd8aV+3+ClEqGx2I04FK6Mv7LCn2kM8VcsQJy13IDViubRB HkD5vzfwlls2nJhN85NgITLe6w9xIno6kqFVBmU+UJ10jCRhPG8z3DJEJF4f9oih/3fV qumdGnFI2PQf2yN3/BlD6LHy5lCYmHjvgiNrwhtLclkqn2aAVw8OBj9UWcKV4hh9PhTB Fs66wJch+V0twVl5ucKRqa28niiu2RZJzUn9G62nX6Ox8s2tAbqZBQvnKVoHgof6/nAo C+Sw== X-Gm-Message-State: AOJu0Yyt0W0XSZK929CKX8v2IV6iLEC4xOCQjXw4nzPYhZV7ZP7Zb/yQ 69p9mRkfjY2hJBdNluYBUQp3TSaHIhRVkfDvzmZX0DlEhHifQQeBSKN3+Q== X-Google-Smtp-Source: AGHT+IG2mhJ2gRgaSYntCiPO11Sldu4+wmKpLlUlCJFV+PClEPRnP9BIJZulwCKuNXiLkW82E9XLpA== X-Received: by 2002:a05:6a20:7348:b0:1be:bf38:7b1b with SMTP id adf61e73a8af0-1bef61201a6mr12559932637.33.1720026737214; Wed, 03 Jul 2024 10:12:17 -0700 (PDT) Received: from Ubuntu.. ([223.176.57.184]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70803ecf966sm10678860b3a.124.2024.07.03.10.12.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 10:12:16 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, chriscool@tuxfamily.org Subject: [PATCH 2/5] t: harmonize t-reftable-merged.c with coding guidelines Date: Wed, 3 Jul 2024 22:31:42 +0530 Message-ID: <20240703171131.3929-3-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240703171131.3929-1-chandrapratap3519@gmail.com> References: <20240703171131.3929-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 1718489f06..28bf6f6696 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_between(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_between(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(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(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(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 Wed Jul 3 17:01: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: 13722613 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.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 B114518508B for ; Wed, 3 Jul 2024 17:12:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720026742; cv=none; b=oMgWkZAB7yyQkKwg9NfmOEPAEZ/An3/dopzypoGHJHRWtQln8/WvFINc9kNByjyuW3mDPJUPEh1uEZnsdKTEgZy7L0AGBBeZJ0Tnlf7qQwKrb6LQO0bIGya7g60n6uHBuUajRXyctxFKdcJi7doSEZlQ2fGkhxJYEFVPzqySJNg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720026742; c=relaxed/simple; bh=0l7ymUSnRrwez6kFQt+BJYZOtiGxxbieBfWe0MM7oW4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g3EuzPe63fIW+JDgP6MmQyr8XMrUj0twZwoTMeybUlzAo8tkI3wviOwm9naMyWKHGYy7Ll1uz0aCbXd3Z3sHG3ZhX2U0FHBlx7xs8WAD/vBXZlrFKyeD9pJLsl17l1gMHfEMxLoc/ToWhQMIV+ucl4b0Qvn7H5o7kq0jBgEXihg= 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=hUNYt0co; arc=none smtp.client-ip=209.85.210.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="hUNYt0co" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-70af0684c2bso564350b3a.0 for ; Wed, 03 Jul 2024 10:12:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720026740; x=1720631540; 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=sHAN49AWDvIRtkHLcCZqOaBIWqjwU8eHVQ9Kl7k2dtY=; b=hUNYt0colx1JJkjhllCfxeZhwPfk2CE0fwy1aLcbbquir2cWb0YyvgvcYPuBrn69Sv PoVF9bS0a4HCFuANTqdLpsoe71oKrOuOwAUPibVOHx4iYJJ9QJqPQkgAyjjH/6nl7zhm Ic8xBlwKJxNe0jS/wKdn6k8qk7d/zerLq1rEnkZyzdeibdtikNcxKKCoEzryLTpfSX5h 1aIF1KKtF5ztxWv1J/0rR4BMO3srXyvZxSkdFVLpuFysmdUZyKU4ydXsCxYugnT0xuAJ KQZ1IH1MuYSR77KsuhFTkeC0hycXWO1jQmG9ZNoIsmgm7DC+H3xberj2HhCguKSFGpym W+Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720026740; x=1720631540; 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=sHAN49AWDvIRtkHLcCZqOaBIWqjwU8eHVQ9Kl7k2dtY=; b=BN0xWRAVYKSzAnhLxQfgMsNMQxzm6JQfxkuHkbt45/b0jgN9pGCf2WRl1jNoc5qj8d Jxrl5kI5e2OOcaN0ngiUclG2nDuU0pFsy2S2Ljy230PehORaJxlxz56V4FbPguxvpI3R CGeefUUn7smPsBrXUQY4+/sLM7nX+A0TAlqGbnIeWB6sxbufy2eBulVLNkIa5Ss31MvS xy2Z3PHfegqZw3/3dz+dr/9+Z3Z76A4Zst2ZwxJXkev23fqef5zGpbhwEmqHTgXgdQbw Pah216rWXJyqJ7b/fV2ArTC61dwIYSSz0oLvQU/1D6cyBZnzkW96veOXnCuBNpMMKNwd qDjQ== X-Gm-Message-State: AOJu0Yy7Gs+6pWi4sSXOdis54GWIsMV+CZ0an3nklDrxXDTOuS8rZWN6 uSW6C/CS7ERrJn5mRhlHKJNEhAvQxm/L52Njo4tD+Ek7GHi3TnKCqrhtPw== X-Google-Smtp-Source: AGHT+IHRKU30573sWaF4r8qL76+8kvCerP/+ULx2a8F2mrZYBZK0oi1+Z86Ogz7VhDfBcH4jgZ21Xw== X-Received: by 2002:a05:6a00:80f:b0:705:c029:c9a7 with SMTP id d2e1a72fcca58-70aaad60533mr12873402b3a.15.1720026739642; Wed, 03 Jul 2024 10:12:19 -0700 (PDT) Received: from Ubuntu.. ([223.176.57.184]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70803ecf966sm10678860b3a.124.2024.07.03.10.12.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 10:12:19 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, chriscool@tuxfamily.org Subject: [PATCH 3/5] t-reftable-merged: add tests for reftable_merged_table_max_update_index Date: Wed, 3 Jul 2024 22:31:43 +0530 Message-ID: <20240703171131.3929-4-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240703171131.3929-1-chandrapratap3519@gmail.com> References: <20240703171131.3929-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 28bf6f6696..543113f3d4 100644 --- a/t/unit-tests/t-reftable-merged.c +++ b/t/unit-tests/t-reftable-merged.c @@ -232,6 +232,7 @@ static void t_merged(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 }; @@ -361,6 +362,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 Wed Jul 3 17:01: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: 13722614 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 992851849CA for ; Wed, 3 Jul 2024 17:12:23 +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=1720026744; cv=none; b=K2AaKsXwB7PqxhKIpEaTIYgIUZ/3MPG5e2cQBdz6SaYeeUXkA6m9xorFbWL44qYkt3CFVP0yn/4tCW6Ldxw2DBaccjo2Txm0MZVKNbc0R3EFz5tGE/4gl16PLfA27zrT59G33/Awvqv/Vb/ARyUGCTe9wrSYiBmWIr6NR/DcHSw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720026744; c=relaxed/simple; bh=CFysl9S4LaB00+WmaDMBwCLPw2zOrBQ+Zwwgx7opBqo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Zk7guJH8SzV9TsbESpaEvWyxAk/aPIFQNhe8bbikSwF5X+it6PVqlSxc/yebOlqVlL26pot0nvCTKFe5pzar2yk7Vu1xTVQbEFE5uLi4/T/mnuRRL+g/MEbgMOjkhBsIbg3PtTMSApuaZ5/Y/OEsQ7j6R4a1MQ5ESTW0Dd4awek= 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=J1Bdh4+H; 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="J1Bdh4+H" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-7067435d376so715613b3a.0 for ; Wed, 03 Jul 2024 10:12:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720026742; x=1720631542; 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=xTCzcLSdm+0p5Wx7+tPpfWYCI1X3CqLkTJG7M6ia+s0=; b=J1Bdh4+HaRaEFEtNtwIPslVgUqZx3cU3MqA02MDVOTMiKZXSu9f8RsuzfxhRR/tOTr jXvlK14RlmSpTnd8xD9FKHaUNuS4WUavWK/aSqJyZ96+dQPyA0sTriEwTGeTivcaslJu aFsAZxGv9eustk27hDSxMHgIUY1Bx8mnYjnj4nEUeYtv+zI8k9XTfco03ktrfqnzqv8p uGyQ5N1HH4jtapQjkgN0Njw09mFDLBY+xX8QJFxcdcPJl2zcKJcJMLB60+19f3vrpMEc yaflcrvdvmiA14j5cKoCxfeb7pqT9fu6xy+Z4VkwrfH3+VKl2e64pUfaa/mxnARakW+F gCvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720026742; x=1720631542; 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=xTCzcLSdm+0p5Wx7+tPpfWYCI1X3CqLkTJG7M6ia+s0=; b=GKum1HCblTJTS3kiqCK8Z3jL7HZhefphC5myy1Yk17tfv0mpyxw63Wky4IAQai40Fu hw2VqtPjtSTXoH+3P8wK/7C1RwDR+43s4M47hEzTafiuHZKPIdPJBsKsGNNDLUfTMSSt gHYnWucYKfUaNyjg3tBk44NfrDIR9w0ZUI0yGz3k8TpYPniaRw3On1smtc1oAP97PzHs AGv8Y9c114KiyJlhESLrdz4nIPkishJUU4nMzkoW+gbAhPVQzLq+L1Ro1vUoghX7JrsV ckSeEEg+a3M9teguNn9Hkl6BRdLMnEHKAn56ewnHxIOe5WMFbK7Uh7gpMnE7Pd1tcMFH HSRA== X-Gm-Message-State: AOJu0YwrKrCEaOys6BEA4HIr/Rv7PRdXsZuY3vKQIyQBeZksIiprHDZX +V6dLnKrJsFVN1VEwBzwBRcUap6nVStYtnvQgYb5mSmFqoajrg4chS1l+Q== X-Google-Smtp-Source: AGHT+IG4HFLZEJqhNwhFFqATFNpKH4uPtQihlhJGyd4EZuhWFcVp0pqPkthJk755xSfXW7wXcuD8iw== X-Received: by 2002:a05:6a00:1a90:b0:706:aa39:d5c1 with SMTP id d2e1a72fcca58-70aeb58c08amr3225335b3a.8.1720026742026; Wed, 03 Jul 2024 10:12:22 -0700 (PDT) Received: from Ubuntu.. ([223.176.57.184]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70803ecf966sm10678860b3a.124.2024.07.03.10.12.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 10:12:21 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, chriscool@tuxfamily.org Subject: [PATCH 4/5] t-reftable-merged: use reftable_ref_record_equal to compare ref records Date: Wed, 3 Jul 2024 22:31:44 +0530 Message-ID: <20240703171131.3929-5-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240703171131.3929-1-chandrapratap3519@gmail.com> References: <20240703171131.3929-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 test_merged_between() 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() as well for a stronger check. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-merged.c | 1 + 1 file changed, 1 insertion(+) diff --git a/t/unit-tests/t-reftable-merged.c b/t/unit-tests/t-reftable-merged.c index 543113f3d4..656193550d 100644 --- a/t/unit-tests/t-reftable-merged.c +++ b/t/unit-tests/t-reftable-merged.c @@ -155,6 +155,7 @@ static void t_merged_between(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, 2); From patchwork Wed Jul 3 17:01: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: 13722615 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 805891850A1 for ; Wed, 3 Jul 2024 17:12:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720026746; cv=none; b=C+6vY9D57ZGV6ZFVJcR7XA5b7B8mAMRLMyOZ+pQ3k2ha2KMiJA0YxyQ1z67YIkGX+3HVfZYTL0z90y0TtY7L04qCE+oQDiKfjKZQzwWU4R9dvaVXDT9CaLYidEduk5A30yD3GeXnoDPXKfPjtfDP7x+QCeT8CmzqxlRr5qoRiq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720026746; c=relaxed/simple; bh=t8MIHaqZZqp5SMpRy5CTpJWnLwiteHT8A5oTaMTi/+g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mjQOA+YK73qlJ8j8DXpX9c3BMJ4bkkqELtJjv2JjogxdWqipgI6tuqGHVGUJTtvx4mLFGux/veu9EUL7xQ8CRG4RDALnT9ey49ojZ/wCClpLp24kh9cULRRmzxSPazh1HJ/zcWWYjF7e516jlMNGX+uu5512Axs0XhPk5WUWUi0= 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=VP+uO55a; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VP+uO55a" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-706627ff48dso4229022b3a.1 for ; Wed, 03 Jul 2024 10:12:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720026744; x=1720631544; 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=VWRxxWZbOuEctg3Y6B6rxEiHBerHR8hEwvli43IVFzo=; b=VP+uO55aMtOsa6SgiWHDiKujf8+PBI1hQQahTn8WL5lEXoQwB8n+1Iw8g//AoV/vLT mAobwudT7apUxqKzFTqbPgK9LbyfwRwxWvbqQxDHvWdBusfMkQ8zkJROy47ZkQVo1JdI WuZMX6/FQ2iYxzvXig08PbKBoH53wkUX9hAUaGIkm2LG47PRqs+QPhYNr87ebNVnhruX alL0Yl+3x2oSjgcI88C+UzabNPc9Cz9tmz1YbY2Ygy0n+e+/YVa3RX4vvvuoGOhpbd+s UZS+nE9KDL+mM6fViVbZyr0urDAUgI1Wah3hD+hLMziOheULOhokuO1+EhYJQUd0Qza9 Qbgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720026744; x=1720631544; 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=VWRxxWZbOuEctg3Y6B6rxEiHBerHR8hEwvli43IVFzo=; b=h7q3NoqiTQQ/x865Kab0syFCYn7snDFcUiYwdwJSO/MYNWvT0WEJokro6WfZHjxf6v U15hAIAzoMD0TWr7bEiIy3Kl9tytjEkqOhZMazbxIhOwMtCpN3tQqEdy1M8gr/0BjAcD HAYHNh9OW1Fu9dLOKAGfnkFytimue/ZfZl3HSIT08wtXBgcWE+Km3D5+CoFUFLJJs9Nj csbT7RZBGWKEcSbBtJIGPbBHp3PXpDIYM8GaJcuZfNhaLBVmfKoxt3sV2X2300f7PV1q UEVlLIFOTmqO5D9Mutf6mWnU2rxlh6H2+2nlSfNxUAdp9uoCXLagkfTXApYbqPM3uCit vAMg== X-Gm-Message-State: AOJu0YwCOZz90UQIBCv0YDXxiRh6mJ7kIr/khaYF3K+DyZMVz2kpDMOY hkl7XT3XfhRYRkhRx4a/yFRsxVL7UofJXyY9fwEY9Z9aYKjdrg5RJunPmg== X-Google-Smtp-Source: AGHT+IF6UK1D9pmKPDgpXqyGErlH2vVZD4lBYKYLrsV81ZAWWqStFIpGVno5HGRBTgm5Xpt8+WcirA== X-Received: by 2002:a05:6a00:1915:b0:70a:f22d:caeb with SMTP id d2e1a72fcca58-70af22dccf4mr1776473b3a.4.1720026744414; Wed, 03 Jul 2024 10:12:24 -0700 (PDT) Received: from Ubuntu.. ([223.176.57.184]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70803ecf966sm10678860b3a.124.2024.07.03.10.12.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 10:12:24 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, chriscool@tuxfamily.org Subject: [PATCH 5/5] t-reftable-merged: add test for REFTABLE_FORMAT_ERROR Date: Wed, 3 Jul 2024 22:31:45 +0530 Message-ID: <20240703171131.3929-6-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240703171131.3929-1-chandrapratap3519@gmail.com> References: <20240703171131.3929-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 656193550d..a213867cf5 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" @@ -437,6 +438,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);