From patchwork Wed Sep 4 14:38:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13791081 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B6651DC75F for ; Wed, 4 Sep 2024 15:01:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725462121; cv=none; b=hM/0yOE06X5dw7JSbOJJP/VM2b+v5eL/M0+CQgWiuQ/RDI6rbskoO41l2OP+JUP13MaDLDtgX/zlYnI8c13p0+c05aApjvivS2RVgWGrSi/w92NKIkgtC1fAbntxbvytJYcMNTgxklinqSR4pX4OnE+xOOfSfHqi4yHDErVb1g8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725462121; c=relaxed/simple; bh=K4jdOw5gZdwuH4M+VQoWHzcbAotAI1xV3J6pc9a3uEs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aQu0+kgeA/3DNwfGzsMYsZ9xqZD8pa2nv1806TuxZzLhV30yv4NuOOYm2L1cgQHQdvhnQ7I7SPXhwhZexOVSeL1DOlt/nvNdZPGF1FiHJKudIqcTOxC6dmCZnETBo8fAxC0+ZbAc+phgjOo1sfuTEKuBwwvDWsCg2XctpTbWXjY= 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=jTgXV/P6; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jTgXV/P6" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1fc47abc040so7982685ad.0 for ; Wed, 04 Sep 2024 08:01:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725462118; x=1726066918; 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=U1fnySPnujthWyNh28Qinon78UZvS/fZPKWzOqixGoU=; b=jTgXV/P6g2/Ht+3r5QPcWeu0NQvZPICa0zth19dRzNZwjA6yxH4IpyXf7FYplB5Ec6 rKga6Z7Ou9B7y12QtLs/aUzflkTPSdex9aO/RO0Ir7Pf0RUPdXm8qkwXAM0rl8HUjb55 mriRC2p53DyB1gavob/gEIgaeQFsSipcc5HI8f5kBlUR46ZCHw1/Ik1MeUbdFc14au5u OKMbU+u7zf36xJvwDgFR72KX3MTQri7qsWS1/v3eDVfqTmKPcVwIZU0TR6p8jWIdUIwX sUyrUCDBvIGobVOjSrGOOdC6vApOKu2fiDam/FcXQ4Xb+7vZxt2H+TaflZi5mUysKkGw S44g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725462118; x=1726066918; 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=U1fnySPnujthWyNh28Qinon78UZvS/fZPKWzOqixGoU=; b=f3GnXb6AIxvpqSQzKIAhnfkVJLl9FDTyIh91WDTIUXjEkdH+rgtsLWUYGJd2GRAZbu ysKeqZPl4vsyrodjo7Bia9Rc4U1Z5zxN5it5YSMA03Wrd7QHUXI1xmFZT/2Y5P+HPao8 NxICQupTA+jWMaDRRgxkM2qs4TlZzlKsuQoSSnB34cvcb7EMKRqTf8dykmZfM3I/Je1x Qy3yr5DrLwW7CtkKdxf4qpoPnnwgeNLs59BgR5QGvGO/8Ay9CB8xADzyqkYoA9nNdFHh RWpEgRLZC6jRrIaJI9MBjQScpQmzmEc2n6qsCXaLAnl+BjYs9zPBYnG/RWUcS11uxyg1 6dFg== X-Gm-Message-State: AOJu0YzXRXrtf1JIdaM7unJudas8LO176KCxspfDbBEhRcuQQteG0xOc POdO+7nEzAovngrYNhafmIaM07LhrP0VmTQOvtDY2onku/rOc3YfzFoc1iN+ X-Google-Smtp-Source: AGHT+IEutdxYGfPx1yBG49uOm/AF2zo2BTw7RzXuZjogKsYpIY3+pW0/DMlkPFZOX/AQGrSN6zlFdQ== X-Received: by 2002:a17:902:d2cd:b0:205:5f54:75a2 with SMTP id d9443c01a7336-2055f5478femr152120115ad.51.1725462117677; Wed, 04 Sep 2024 08:01:57 -0700 (PDT) Received: from Ubuntu.. ([106.194.60.213]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-206aea65fe6sm14549395ad.257.2024.09.04.08.01.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 08:01:57 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v4 1/6] t: move reftable/stack_test.c to the unit testing framework Date: Wed, 4 Sep 2024 20:08:01 +0530 Message-ID: <20240904150132.11567-2-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240904150132.11567-1-chandrapratap3519@gmail.com> References: <20240826173627.4525-1-chandrapratap3519@gmail.com> <20240904150132.11567-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 reftable/stack_test.c exercises the functions defined in reftable/stack.{c, h}. Migrate reftable/stack_test.c to the unit testing framework. Migration involves refactoring the tests to use the unit testing framework instead of reftable's test framework and renaming the tests to be in-line with unit-tests' standards. Since some of the tests use set_test_hash() defined by reftable/test_framework.{c, h} but these files are not '#included' in the test file, copy this function in the ported test file. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap Signed-off-by: Junio C Hamano --- Makefile | 2 +- reftable/reftable-tests.h | 1 - t/helper/test-reftable.c | 1 - .../unit-tests/t-reftable-stack.c | 429 +++++++++--------- 4 files changed, 214 insertions(+), 219 deletions(-) rename reftable/stack_test.c => t/unit-tests/t-reftable-stack.c (76%) diff --git a/Makefile b/Makefile index 91f65d7dc5..1cbc2d61ae 100644 --- a/Makefile +++ b/Makefile @@ -1349,6 +1349,7 @@ UNIT_TEST_PROGRAMS += t-reftable-merged UNIT_TEST_PROGRAMS += t-reftable-pq UNIT_TEST_PROGRAMS += t-reftable-readwrite UNIT_TEST_PROGRAMS += t-reftable-record +UNIT_TEST_PROGRAMS += t-reftable-stack UNIT_TEST_PROGRAMS += t-reftable-tree UNIT_TEST_PROGRAMS += t-strbuf UNIT_TEST_PROGRAMS += t-strcmp-offset @@ -2691,7 +2692,6 @@ REFTABLE_OBJS += reftable/stack.o REFTABLE_OBJS += reftable/tree.o REFTABLE_OBJS += reftable/writer.o -REFTABLE_TEST_OBJS += reftable/stack_test.o REFTABLE_TEST_OBJS += reftable/test_framework.o TEST_OBJS := $(patsubst %$X,%.o,$(TEST_PROGRAMS)) $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS)) diff --git a/reftable/reftable-tests.h b/reftable/reftable-tests.h index 5d725c69c7..05f8d2d5bc 100644 --- a/reftable/reftable-tests.h +++ b/reftable/reftable-tests.h @@ -9,6 +9,5 @@ license that can be found in the LICENSE file or at #ifndef REFTABLE_TESTS_H #define REFTABLE_TESTS_H -int stack_test_main(int argc, const char **argv); #endif diff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c index ce5a94fbd3..d27d7ee798 100644 --- a/t/helper/test-reftable.c +++ b/t/helper/test-reftable.c @@ -12,7 +12,6 @@ int cmd__reftable(int argc, const char **argv) { /* test from simple to complex. */ - stack_test_main(argc, argv); return 0; } diff --git a/reftable/stack_test.c b/t/unit-tests/t-reftable-stack.c similarity index 76% rename from reftable/stack_test.c rename to t/unit-tests/t-reftable-stack.c index 89cb2be19f..de28fac466 100644 --- a/reftable/stack_test.c +++ b/t/unit-tests/t-reftable-stack.c @@ -6,22 +6,18 @@ license that can be found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd */ -#include "stack.h" - -#include "system.h" - -#include "copy.h" -#include "reftable-reader.h" -#include "merged.h" -#include "basics.h" -#include "record.h" -#include "test_framework.h" -#include "reftable-tests.h" -#include "reader.h" - -#include +#include "test-lib.h" +#include "reftable/merged.h" +#include "reftable/reader.h" +#include "reftable/reftable-error.h" +#include "reftable/stack.h" #include +static void set_test_hash(uint8_t *p, int i) +{ + memset(p, (uint8_t)i, hash_size(GIT_SHA1_FORMAT_ID)); +} + static void clear_dir(const char *dirname) { struct strbuf path = STRBUF_INIT; @@ -73,11 +69,11 @@ static char *get_tmp_template(int linenumber) static char *get_tmp_dir(int linenumber) { char *dir = get_tmp_template(linenumber); - EXPECT(mkdtemp(dir)); + check(mkdtemp(dir) != NULL); return dir; } -static void test_read_file(void) +static void t_read_file(void) { char *fn = get_tmp_template(__LINE__); int fd = mkstemp(fn); @@ -87,17 +83,17 @@ static void test_read_file(void) const char *want[] = { "line1", "line2", "line3" }; int i = 0; - EXPECT(fd > 0); + check_int(fd, >, 0); n = write_in_full(fd, out, strlen(out)); - EXPECT(n == strlen(out)); + check_int(n, ==, strlen(out)); err = close(fd); - EXPECT(err >= 0); + check_int(err, >=, 0); err = read_lines(fn, &names); - EXPECT_ERR(err); + check(!err); for (i = 0; names[i]; i++) { - EXPECT(0 == strcmp(want[i], names[i])); + check_str(want[i], names[i]); } free_names(names); (void) remove(fn); @@ -132,7 +128,7 @@ static void write_n_ref_tables(struct reftable_stack *st, set_test_hash(ref.value.val1, i); err = reftable_stack_add(st, &write_test_ref, &ref); - EXPECT_ERR(err); + check(!err); } st->opts.disable_auto_compact = disable_auto_compact; @@ -152,7 +148,7 @@ static int write_test_log(struct reftable_writer *wr, void *arg) return reftable_writer_add_log(wr, wla->log); } -static void test_reftable_stack_add_one(void) +static void t_reftable_stack_add_one(void) { char *dir = get_tmp_dir(__LINE__); struct strbuf scratch = STRBUF_INIT; @@ -171,22 +167,22 @@ static void test_reftable_stack_add_one(void) struct reftable_ref_record dest = { NULL }; struct stat stat_result = { 0 }; err = reftable_new_stack(&st, dir, &opts); - EXPECT_ERR(err); + check(!err); err = reftable_stack_add(st, &write_test_ref, &ref); - EXPECT_ERR(err); + check(!err); err = reftable_stack_read_ref(st, ref.refname, &dest); - EXPECT_ERR(err); - EXPECT(0 == strcmp("master", dest.value.symref)); - EXPECT(st->readers_len > 0); + check(!err); + check_str("master", dest.value.symref); + check_int(st->readers_len, >, 0); #ifndef GIT_WINDOWS_NATIVE strbuf_addstr(&scratch, dir); strbuf_addstr(&scratch, "/tables.list"); err = stat(scratch.buf, &stat_result); - EXPECT(!err); - EXPECT((stat_result.st_mode & 0777) == opts.default_permissions); + check(!err); + check_int((stat_result.st_mode & 0777), ==, opts.default_permissions); strbuf_reset(&scratch); strbuf_addstr(&scratch, dir); @@ -194,8 +190,8 @@ static void test_reftable_stack_add_one(void) /* do not try at home; not an external API for reftable. */ strbuf_addstr(&scratch, st->readers[0]->name); err = stat(scratch.buf, &stat_result); - EXPECT(!err); - EXPECT((stat_result.st_mode & 0777) == opts.default_permissions); + check(!err); + check_int((stat_result.st_mode & 0777), ==, opts.default_permissions); #else (void) stat_result; #endif @@ -207,7 +203,7 @@ static void test_reftable_stack_add_one(void) umask(mask); } -static void test_reftable_stack_uptodate(void) +static void t_reftable_stack_uptodate(void) { struct reftable_write_options opts = { 0 }; struct reftable_stack *st1 = NULL; @@ -233,28 +229,28 @@ static void test_reftable_stack_uptodate(void) by creating two stacks for the same directory. */ err = reftable_new_stack(&st1, dir, &opts); - EXPECT_ERR(err); + check(!err); err = reftable_new_stack(&st2, dir, &opts); - EXPECT_ERR(err); + check(!err); err = reftable_stack_add(st1, &write_test_ref, &ref1); - EXPECT_ERR(err); + check(!err); err = reftable_stack_add(st2, &write_test_ref, &ref2); - EXPECT(err == REFTABLE_OUTDATED_ERROR); + check_int(err, ==, REFTABLE_OUTDATED_ERROR); err = reftable_stack_reload(st2); - EXPECT_ERR(err); + check(!err); err = reftable_stack_add(st2, &write_test_ref, &ref2); - EXPECT_ERR(err); + check(!err); reftable_stack_destroy(st1); reftable_stack_destroy(st2); clear_dir(dir); } -static void test_reftable_stack_transaction_api(void) +static void t_reftable_stack_transaction_api(void) { char *dir = get_tmp_dir(__LINE__); struct reftable_write_options opts = { 0 }; @@ -271,32 +267,32 @@ static void test_reftable_stack_transaction_api(void) struct reftable_ref_record dest = { NULL }; err = reftable_new_stack(&st, dir, &opts); - EXPECT_ERR(err); + check(!err); reftable_addition_destroy(add); err = reftable_stack_new_addition(&add, st); - EXPECT_ERR(err); + check(!err); err = reftable_addition_add(add, &write_test_ref, &ref); - EXPECT_ERR(err); + check(!err); err = reftable_addition_commit(add); - EXPECT_ERR(err); + check(!err); reftable_addition_destroy(add); err = reftable_stack_read_ref(st, ref.refname, &dest); - EXPECT_ERR(err); - EXPECT(REFTABLE_REF_SYMREF == dest.value_type); - EXPECT(0 == strcmp("master", dest.value.symref)); + check(!err); + check_int(REFTABLE_REF_SYMREF, ==, dest.value_type); + check_str("master", dest.value.symref); reftable_ref_record_release(&dest); reftable_stack_destroy(st); clear_dir(dir); } -static void test_reftable_stack_transaction_api_performs_auto_compaction(void) +static void t_reftable_stack_transaction_api_performs_auto_compaction(void) { char *dir = get_tmp_dir(__LINE__); struct reftable_write_options opts = {0}; @@ -305,7 +301,7 @@ static void test_reftable_stack_transaction_api_performs_auto_compaction(void) int i, n = 20, err; err = reftable_new_stack(&st, dir, &opts); - EXPECT_ERR(err); + check(!err); for (i = 0; i <= n; i++) { struct reftable_ref_record ref = { @@ -326,13 +322,13 @@ static void test_reftable_stack_transaction_api_performs_auto_compaction(void) st->opts.disable_auto_compact = i != n; err = reftable_stack_new_addition(&add, st); - EXPECT_ERR(err); + check(!err); err = reftable_addition_add(add, &write_test_ref, &ref); - EXPECT_ERR(err); + check(!err); err = reftable_addition_commit(add); - EXPECT_ERR(err); + check(!err); reftable_addition_destroy(add); @@ -342,16 +338,16 @@ static void test_reftable_stack_transaction_api_performs_auto_compaction(void) * all tables in the stack. */ if (i != n) - EXPECT(st->merged->readers_len == i + 1); + check_int(st->merged->readers_len, ==, i + 1); else - EXPECT(st->merged->readers_len == 1); + check_int(st->merged->readers_len, ==, 1); } reftable_stack_destroy(st); clear_dir(dir); } -static void test_reftable_stack_auto_compaction_fails_gracefully(void) +static void t_reftable_stack_auto_compaction_fails_gracefully(void) { struct reftable_ref_record ref = { .refname = (char *) "refs/heads/master", @@ -366,13 +362,13 @@ static void test_reftable_stack_auto_compaction_fails_gracefully(void) int err; err = reftable_new_stack(&st, dir, &opts); - EXPECT_ERR(err); + check(!err); err = reftable_stack_add(st, write_test_ref, &ref); - EXPECT_ERR(err); - EXPECT(st->merged->readers_len == 1); - EXPECT(st->stats.attempts == 0); - EXPECT(st->stats.failures == 0); + check(!err); + check_int(st->merged->readers_len, ==, 1); + check_int(st->stats.attempts, ==, 0); + check_int(st->stats.failures, ==, 0); /* * Lock the newly written table such that it cannot be compacted. @@ -384,10 +380,10 @@ static void test_reftable_stack_auto_compaction_fails_gracefully(void) ref.update_index = 2; err = reftable_stack_add(st, write_test_ref, &ref); - EXPECT_ERR(err); - EXPECT(st->merged->readers_len == 2); - EXPECT(st->stats.attempts == 1); - EXPECT(st->stats.failures == 1); + check(!err); + check_int(st->merged->readers_len, ==, 2); + check_int(st->stats.attempts, ==, 1); + check_int(st->stats.failures, ==, 1); reftable_stack_destroy(st); strbuf_release(&table_path); @@ -399,7 +395,7 @@ static int write_error(struct reftable_writer *wr UNUSED, void *arg) return *((int *)arg); } -static void test_reftable_stack_update_index_check(void) +static void t_reftable_stack_update_index_check(void) { char *dir = get_tmp_dir(__LINE__); struct reftable_write_options opts = { 0 }; @@ -419,18 +415,18 @@ static void test_reftable_stack_update_index_check(void) }; err = reftable_new_stack(&st, dir, &opts); - EXPECT_ERR(err); + check(!err); err = reftable_stack_add(st, &write_test_ref, &ref1); - EXPECT_ERR(err); + check(!err); err = reftable_stack_add(st, &write_test_ref, &ref2); - EXPECT(err == REFTABLE_API_ERROR); + check_int(err, ==, REFTABLE_API_ERROR); reftable_stack_destroy(st); clear_dir(dir); } -static void test_reftable_stack_lock_failure(void) +static void t_reftable_stack_lock_failure(void) { char *dir = get_tmp_dir(__LINE__); struct reftable_write_options opts = { 0 }; @@ -438,17 +434,17 @@ static void test_reftable_stack_lock_failure(void) int err, i; err = reftable_new_stack(&st, dir, &opts); - EXPECT_ERR(err); + check(!err); for (i = -1; i != REFTABLE_EMPTY_TABLE_ERROR; i--) { err = reftable_stack_add(st, &write_error, &i); - EXPECT(err == i); + check_int(err, ==, i); } reftable_stack_destroy(st); clear_dir(dir); } -static void test_reftable_stack_add(void) +static void t_reftable_stack_add(void) { int i = 0; int err = 0; @@ -466,7 +462,7 @@ static void test_reftable_stack_add(void) int N = ARRAY_SIZE(refs); err = reftable_new_stack(&st, dir, &opts); - EXPECT_ERR(err); + check(!err); for (i = 0; i < N; i++) { char buf[256]; @@ -485,7 +481,7 @@ static void test_reftable_stack_add(void) for (i = 0; i < N; i++) { int err = reftable_stack_add(st, &write_test_ref, &refs[i]); - EXPECT_ERR(err); + check(!err); } for (i = 0; i < N; i++) { @@ -494,18 +490,18 @@ static void test_reftable_stack_add(void) .update_index = reftable_stack_next_update_index(st), }; int err = reftable_stack_add(st, &write_test_log, &arg); - EXPECT_ERR(err); + check(!err); } err = reftable_stack_compact_all(st, NULL); - EXPECT_ERR(err); + check(!err); for (i = 0; i < N; i++) { struct reftable_ref_record dest = { NULL }; int err = reftable_stack_read_ref(st, refs[i].refname, &dest); - EXPECT_ERR(err); - EXPECT(reftable_ref_record_equal(&dest, refs + i, + check(!err); + check(reftable_ref_record_equal(&dest, refs + i, GIT_SHA1_RAWSZ)); reftable_ref_record_release(&dest); } @@ -513,8 +509,8 @@ static void test_reftable_stack_add(void) for (i = 0; i < N; i++) { struct reftable_log_record dest = { NULL }; int err = reftable_stack_read_log(st, refs[i].refname, &dest); - EXPECT_ERR(err); - EXPECT(reftable_log_record_equal(&dest, logs + i, + check(!err); + check(reftable_log_record_equal(&dest, logs + i, GIT_SHA1_RAWSZ)); reftable_log_record_release(&dest); } @@ -523,8 +519,8 @@ static void test_reftable_stack_add(void) strbuf_addstr(&path, dir); strbuf_addstr(&path, "/tables.list"); err = stat(path.buf, &stat_result); - EXPECT(!err); - EXPECT((stat_result.st_mode & 0777) == opts.default_permissions); + check(!err); + check_int((stat_result.st_mode & 0777), ==, opts.default_permissions); strbuf_reset(&path); strbuf_addstr(&path, dir); @@ -532,8 +528,8 @@ static void test_reftable_stack_add(void) /* do not try at home; not an external API for reftable. */ strbuf_addstr(&path, st->readers[0]->name); err = stat(path.buf, &stat_result); - EXPECT(!err); - EXPECT((stat_result.st_mode & 0777) == opts.default_permissions); + check(!err); + check_int((stat_result.st_mode & 0777), ==, opts.default_permissions); #else (void) stat_result; #endif @@ -548,7 +544,7 @@ static void test_reftable_stack_add(void) clear_dir(dir); } -static void test_reftable_stack_log_normalize(void) +static void t_reftable_stack_log_normalize(void) { int err = 0; struct reftable_write_options opts = { @@ -576,27 +572,27 @@ static void test_reftable_stack_log_normalize(void) }; err = reftable_new_stack(&st, dir, &opts); - EXPECT_ERR(err); + check(!err); input.value.update.message = (char *) "one\ntwo"; err = reftable_stack_add(st, &write_test_log, &arg); - EXPECT(err == REFTABLE_API_ERROR); + check_int(err, ==, REFTABLE_API_ERROR); input.value.update.message = (char *) "one"; err = reftable_stack_add(st, &write_test_log, &arg); - EXPECT_ERR(err); + check(!err); err = reftable_stack_read_log(st, input.refname, &dest); - EXPECT_ERR(err); - EXPECT(0 == strcmp(dest.value.update.message, "one\n")); + check(!err); + check_str(dest.value.update.message, "one\n"); input.value.update.message = (char *) "two\n"; arg.update_index = 2; err = reftable_stack_add(st, &write_test_log, &arg); - EXPECT_ERR(err); + check(!err); err = reftable_stack_read_log(st, input.refname, &dest); - EXPECT_ERR(err); - EXPECT(0 == strcmp(dest.value.update.message, "two\n")); + check(!err); + check_str(dest.value.update.message, "two\n"); /* cleanup */ reftable_stack_destroy(st); @@ -604,7 +600,7 @@ static void test_reftable_stack_log_normalize(void) clear_dir(dir); } -static void test_reftable_stack_tombstone(void) +static void t_reftable_stack_tombstone(void) { int i = 0; char *dir = get_tmp_dir(__LINE__); @@ -618,7 +614,7 @@ static void test_reftable_stack_tombstone(void) struct reftable_log_record log_dest = { NULL }; err = reftable_new_stack(&st, dir, &opts); - EXPECT_ERR(err); + check(!err); /* even entries add the refs, odd entries delete them. */ for (i = 0; i < N; i++) { @@ -642,7 +638,7 @@ static void test_reftable_stack_tombstone(void) } for (i = 0; i < N; i++) { int err = reftable_stack_add(st, &write_test_ref, &refs[i]); - EXPECT_ERR(err); + check(!err); } for (i = 0; i < N; i++) { @@ -651,25 +647,25 @@ static void test_reftable_stack_tombstone(void) .update_index = reftable_stack_next_update_index(st), }; int err = reftable_stack_add(st, &write_test_log, &arg); - EXPECT_ERR(err); + check(!err); } err = reftable_stack_read_ref(st, "branch", &dest); - EXPECT(err == 1); + check_int(err, ==, 1); reftable_ref_record_release(&dest); err = reftable_stack_read_log(st, "branch", &log_dest); - EXPECT(err == 1); + check_int(err, ==, 1); reftable_log_record_release(&log_dest); err = reftable_stack_compact_all(st, NULL); - EXPECT_ERR(err); + check(!err); err = reftable_stack_read_ref(st, "branch", &dest); - EXPECT(err == 1); + check_int(err, ==, 1); err = reftable_stack_read_log(st, "branch", &log_dest); - EXPECT(err == 1); + check_int(err, ==, 1); reftable_ref_record_release(&dest); reftable_log_record_release(&log_dest); @@ -682,7 +678,7 @@ static void test_reftable_stack_tombstone(void) clear_dir(dir); } -static void test_reftable_stack_hash_id(void) +static void t_reftable_stack_hash_id(void) { char *dir = get_tmp_dir(__LINE__); struct reftable_write_options opts = { 0 }; @@ -702,47 +698,47 @@ static void test_reftable_stack_hash_id(void) struct reftable_ref_record dest = { NULL }; err = reftable_new_stack(&st, dir, &opts); - EXPECT_ERR(err); + check(!err); err = reftable_stack_add(st, &write_test_ref, &ref); - EXPECT_ERR(err); + check(!err); /* can't read it with the wrong hash ID. */ err = reftable_new_stack(&st32, dir, &opts32); - EXPECT(err == REFTABLE_FORMAT_ERROR); + check_int(err, ==, REFTABLE_FORMAT_ERROR); /* check that we can read it back with default opts too. */ err = reftable_new_stack(&st_default, dir, &opts_default); - EXPECT_ERR(err); + check(!err); err = reftable_stack_read_ref(st_default, "master", &dest); - EXPECT_ERR(err); + check(!err); - EXPECT(reftable_ref_record_equal(&ref, &dest, GIT_SHA1_RAWSZ)); + check(reftable_ref_record_equal(&ref, &dest, GIT_SHA1_RAWSZ)); reftable_ref_record_release(&dest); reftable_stack_destroy(st); reftable_stack_destroy(st_default); clear_dir(dir); } -static void test_suggest_compaction_segment(void) +static void t_suggest_compaction_segment(void) { uint64_t sizes[] = { 512, 64, 17, 16, 9, 9, 9, 16, 2, 16 }; struct segment min = suggest_compaction_segment(sizes, ARRAY_SIZE(sizes), 2); - EXPECT(min.start == 1); - EXPECT(min.end == 10); + check_int(min.start, ==, 1); + check_int(min.end, ==, 10); } -static void test_suggest_compaction_segment_nothing(void) +static void t_suggest_compaction_segment_nothing(void) { uint64_t sizes[] = { 64, 32, 16, 8, 4, 2 }; struct segment result = suggest_compaction_segment(sizes, ARRAY_SIZE(sizes), 2); - EXPECT(result.start == result.end); + check_int(result.start, ==, result.end); } -static void test_reflog_expire(void) +static void t_reflog_expire(void) { char *dir = get_tmp_dir(__LINE__); struct reftable_write_options opts = { 0 }; @@ -757,7 +753,7 @@ static void test_reflog_expire(void) struct reftable_log_record log = { NULL }; err = reftable_new_stack(&st, dir, &opts); - EXPECT_ERR(err); + check(!err); for (i = 1; i <= N; i++) { char buf[256]; @@ -777,30 +773,30 @@ static void test_reflog_expire(void) .update_index = reftable_stack_next_update_index(st), }; int err = reftable_stack_add(st, &write_test_log, &arg); - EXPECT_ERR(err); + check(!err); } err = reftable_stack_compact_all(st, NULL); - EXPECT_ERR(err); + check(!err); err = reftable_stack_compact_all(st, &expiry); - EXPECT_ERR(err); + check(!err); err = reftable_stack_read_log(st, logs[9].refname, &log); - EXPECT(err == 1); + check_int(err, ==, 1); err = reftable_stack_read_log(st, logs[11].refname, &log); - EXPECT_ERR(err); + check(!err); expiry.min_update_index = 15; err = reftable_stack_compact_all(st, &expiry); - EXPECT_ERR(err); + check(!err); err = reftable_stack_read_log(st, logs[14].refname, &log); - EXPECT(err == 1); + check_int(err, ==, 1); err = reftable_stack_read_log(st, logs[16].refname, &log); - EXPECT_ERR(err); + check(!err); /* cleanup */ reftable_stack_destroy(st); @@ -817,7 +813,7 @@ static int write_nothing(struct reftable_writer *wr, void *arg UNUSED) return 0; } -static void test_empty_add(void) +static void t_empty_add(void) { struct reftable_write_options opts = { 0 }; struct reftable_stack *st = NULL; @@ -826,13 +822,13 @@ static void test_empty_add(void) struct reftable_stack *st2 = NULL; err = reftable_new_stack(&st, dir, &opts); - EXPECT_ERR(err); + check(!err); err = reftable_stack_add(st, &write_nothing, NULL); - EXPECT_ERR(err); + check(!err); err = reftable_new_stack(&st2, dir, &opts); - EXPECT_ERR(err); + check(!err); clear_dir(dir); reftable_stack_destroy(st); reftable_stack_destroy(st2); @@ -848,7 +844,7 @@ static int fastlog2(uint64_t sz) return l - 1; } -static void test_reftable_stack_auto_compaction(void) +static void t_reftable_stack_auto_compaction(void) { struct reftable_write_options opts = { .disable_auto_compact = 1, @@ -859,7 +855,7 @@ static void test_reftable_stack_auto_compaction(void) int N = 100; err = reftable_new_stack(&st, dir, &opts); - EXPECT_ERR(err); + check(!err); for (i = 0; i < N; i++) { char name[100]; @@ -872,21 +868,21 @@ static void test_reftable_stack_auto_compaction(void) snprintf(name, sizeof(name), "branch%04d", i); err = reftable_stack_add(st, &write_test_ref, &ref); - EXPECT_ERR(err); + check(!err); err = reftable_stack_auto_compact(st); - EXPECT_ERR(err); - EXPECT(i < 3 || st->merged->readers_len < 2 * fastlog2(i)); + check(!err); + check(i < 3 || st->merged->readers_len < 2 * fastlog2(i)); } - EXPECT(reftable_stack_compaction_stats(st)->entries_written < + check_int(reftable_stack_compaction_stats(st)->entries_written, <, (uint64_t)(N * fastlog2(N))); reftable_stack_destroy(st); clear_dir(dir); } -static void test_reftable_stack_auto_compaction_with_locked_tables(void) +static void t_reftable_stack_auto_compaction_with_locked_tables(void) { struct reftable_write_options opts = { .disable_auto_compact = 1, @@ -897,10 +893,10 @@ static void test_reftable_stack_auto_compaction_with_locked_tables(void) int err; err = reftable_new_stack(&st, dir, &opts); - EXPECT_ERR(err); + check(!err); write_n_ref_tables(st, 5); - EXPECT(st->merged->readers_len == 5); + check_int(st->merged->readers_len, ==, 5); /* * Given that all tables we have written should be roughly the same @@ -918,16 +914,16 @@ static void test_reftable_stack_auto_compaction_with_locked_tables(void) * only compact the newest two tables. */ err = reftable_stack_auto_compact(st); - EXPECT_ERR(err); - EXPECT(st->stats.failures == 0); - EXPECT(st->merged->readers_len == 4); + check(!err); + check_int(st->stats.failures, ==, 0); + check_int(st->merged->readers_len, ==, 4); reftable_stack_destroy(st); strbuf_release(&buf); clear_dir(dir); } -static void test_reftable_stack_add_performs_auto_compaction(void) +static void t_reftable_stack_add_performs_auto_compaction(void) { struct reftable_write_options opts = { 0 }; struct reftable_stack *st = NULL; @@ -936,7 +932,7 @@ static void test_reftable_stack_add_performs_auto_compaction(void) int err, i, n = 20; err = reftable_new_stack(&st, dir, &opts); - EXPECT_ERR(err); + check(!err); for (i = 0; i <= n; i++) { struct reftable_ref_record ref = { @@ -957,7 +953,7 @@ static void test_reftable_stack_add_performs_auto_compaction(void) ref.refname = refname.buf; err = reftable_stack_add(st, &write_test_ref, &ref); - EXPECT_ERR(err); + check(!err); /* * The stack length should grow continuously for all runs where @@ -965,9 +961,9 @@ static void test_reftable_stack_add_performs_auto_compaction(void) * all tables in the stack. */ if (i != n) - EXPECT(st->merged->readers_len == i + 1); + check_int(st->merged->readers_len, ==, i + 1); else - EXPECT(st->merged->readers_len == 1); + check_int(st->merged->readers_len, ==, 1); } reftable_stack_destroy(st); @@ -975,7 +971,7 @@ static void test_reftable_stack_add_performs_auto_compaction(void) clear_dir(dir); } -static void test_reftable_stack_compaction_with_locked_tables(void) +static void t_reftable_stack_compaction_with_locked_tables(void) { struct reftable_write_options opts = { .disable_auto_compact = 1, @@ -986,10 +982,10 @@ static void test_reftable_stack_compaction_with_locked_tables(void) int err; err = reftable_new_stack(&st, dir, &opts); - EXPECT_ERR(err); + check(!err); write_n_ref_tables(st, 3); - EXPECT(st->merged->readers_len == 3); + check_int(st->merged->readers_len, ==, 3); /* Lock one of the tables that we're about to compact. */ strbuf_reset(&buf); @@ -1001,16 +997,16 @@ static void test_reftable_stack_compaction_with_locked_tables(void) * compact all tables. */ err = reftable_stack_compact_all(st, NULL); - EXPECT(err == REFTABLE_LOCK_ERROR); - EXPECT(st->stats.failures == 1); - EXPECT(st->merged->readers_len == 3); + check_int(err, ==, REFTABLE_LOCK_ERROR); + check_int(st->stats.failures, ==, 1); + check_int(st->merged->readers_len, ==, 3); reftable_stack_destroy(st); strbuf_release(&buf); clear_dir(dir); } -static void test_reftable_stack_compaction_concurrent(void) +static void t_reftable_stack_compaction_concurrent(void) { struct reftable_write_options opts = { 0 }; struct reftable_stack *st1 = NULL, *st2 = NULL; @@ -1018,19 +1014,19 @@ static void test_reftable_stack_compaction_concurrent(void) int err; err = reftable_new_stack(&st1, dir, &opts); - EXPECT_ERR(err); + check(!err); write_n_ref_tables(st1, 3); err = reftable_new_stack(&st2, dir, &opts); - EXPECT_ERR(err); + check(!err); err = reftable_stack_compact_all(st1, NULL); - EXPECT_ERR(err); + check(!err); reftable_stack_destroy(st1); reftable_stack_destroy(st2); - EXPECT(count_dir_entries(dir) == 2); + check_int(count_dir_entries(dir), ==, 2); clear_dir(dir); } @@ -1043,7 +1039,7 @@ static void unclean_stack_close(struct reftable_stack *st) FREE_AND_NULL(st->readers); } -static void test_reftable_stack_compaction_concurrent_clean(void) +static void t_reftable_stack_compaction_concurrent_clean(void) { struct reftable_write_options opts = { 0 }; struct reftable_stack *st1 = NULL, *st2 = NULL, *st3 = NULL; @@ -1051,24 +1047,24 @@ static void test_reftable_stack_compaction_concurrent_clean(void) int err; err = reftable_new_stack(&st1, dir, &opts); - EXPECT_ERR(err); + check(!err); write_n_ref_tables(st1, 3); err = reftable_new_stack(&st2, dir, &opts); - EXPECT_ERR(err); + check(!err); err = reftable_stack_compact_all(st1, NULL); - EXPECT_ERR(err); + check(!err); unclean_stack_close(st1); unclean_stack_close(st2); err = reftable_new_stack(&st3, dir, &opts); - EXPECT_ERR(err); + check(!err); err = reftable_stack_clean(st3); - EXPECT_ERR(err); - EXPECT(count_dir_entries(dir) == 2); + check(!err); + check_int(count_dir_entries(dir), ==, 2); reftable_stack_destroy(st1); reftable_stack_destroy(st2); @@ -1077,7 +1073,7 @@ static void test_reftable_stack_compaction_concurrent_clean(void) clear_dir(dir); } -static void test_reftable_stack_read_across_reload(void) +static void t_reftable_stack_read_across_reload(void) { struct reftable_write_options opts = { 0 }; struct reftable_stack *st1 = NULL, *st2 = NULL; @@ -1088,36 +1084,36 @@ static void test_reftable_stack_read_across_reload(void) /* Create a first stack and set up an iterator for it. */ err = reftable_new_stack(&st1, dir, &opts); - EXPECT_ERR(err); + check(!err); write_n_ref_tables(st1, 2); - EXPECT(st1->merged->readers_len == 2); + check_int(st1->merged->readers_len, ==, 2); reftable_stack_init_ref_iterator(st1, &it); err = reftable_iterator_seek_ref(&it, ""); - EXPECT_ERR(err); + check(!err); /* Set up a second stack for the same directory and compact it. */ err = reftable_new_stack(&st2, dir, &opts); - EXPECT_ERR(err); - EXPECT(st2->merged->readers_len == 2); + check(!err); + check_int(st2->merged->readers_len, ==, 2); err = reftable_stack_compact_all(st2, NULL); - EXPECT_ERR(err); - EXPECT(st2->merged->readers_len == 1); + check(!err); + check_int(st2->merged->readers_len, ==, 1); /* * Verify that we can continue to use the old iterator even after we * have reloaded its stack. */ err = reftable_stack_reload(st1); - EXPECT_ERR(err); - EXPECT(st1->merged->readers_len == 1); + check(!err); + check_int(st1->merged->readers_len, ==, 1); err = reftable_iterator_next_ref(&it, &rec); - EXPECT_ERR(err); - EXPECT(!strcmp(rec.refname, "refs/heads/branch-0000")); + check(!err); + check_str(rec.refname, "refs/heads/branch-0000"); err = reftable_iterator_next_ref(&it, &rec); - EXPECT_ERR(err); - EXPECT(!strcmp(rec.refname, "refs/heads/branch-0001")); + check(!err); + check_str(rec.refname, "refs/heads/branch-0001"); err = reftable_iterator_next_ref(&it, &rec); - EXPECT(err > 0); + check_int(err, >, 0); reftable_ref_record_release(&rec); reftable_iterator_destroy(&it); @@ -1126,7 +1122,7 @@ static void test_reftable_stack_read_across_reload(void) clear_dir(dir); } -static void test_reftable_stack_reload_with_missing_table(void) +static void t_reftable_stack_reload_with_missing_table(void) { struct reftable_write_options opts = { 0 }; struct reftable_stack *st = NULL; @@ -1138,12 +1134,12 @@ static void test_reftable_stack_reload_with_missing_table(void) /* Create a first stack and set up an iterator for it. */ err = reftable_new_stack(&st, dir, &opts); - EXPECT_ERR(err); + check(!err); write_n_ref_tables(st, 2); - EXPECT(st->merged->readers_len == 2); + check_int(st->merged->readers_len, ==, 2); reftable_stack_init_ref_iterator(st, &it); err = reftable_iterator_seek_ref(&it, ""); - EXPECT_ERR(err); + check(!err); /* * Update the tables.list file with some garbage data, while reusing @@ -1156,24 +1152,24 @@ static void test_reftable_stack_reload_with_missing_table(void) strbuf_addf(&table_path, "%s.lock", st->list_file); write_file_buf(table_path.buf, content.buf, content.len); err = rename(table_path.buf, st->list_file); - EXPECT_ERR(err); + check(!err); err = reftable_stack_reload(st); - EXPECT(err == -4); - EXPECT(st->merged->readers_len == 2); + check_int(err, ==, -4); + check_int(st->merged->readers_len, ==, 2); /* * Even though the reload has failed, we should be able to continue * using the iterator. */ err = reftable_iterator_next_ref(&it, &rec); - EXPECT_ERR(err); - EXPECT(!strcmp(rec.refname, "refs/heads/branch-0000")); + check(!err); + check_str(rec.refname, "refs/heads/branch-0000"); err = reftable_iterator_next_ref(&it, &rec); - EXPECT_ERR(err); - EXPECT(!strcmp(rec.refname, "refs/heads/branch-0001")); + check(!err); + check_str(rec.refname, "refs/heads/branch-0001"); err = reftable_iterator_next_ref(&it, &rec); - EXPECT(err > 0); + check_int(err, >, 0); reftable_ref_record_release(&rec); reftable_iterator_destroy(&it); @@ -1183,31 +1179,32 @@ static void test_reftable_stack_reload_with_missing_table(void) clear_dir(dir); } -int stack_test_main(int argc UNUSED, const char *argv[] UNUSED) +int cmd_main(int argc UNUSED, const char *argv[] UNUSED) { - RUN_TEST(test_empty_add); - RUN_TEST(test_read_file); - RUN_TEST(test_reflog_expire); - RUN_TEST(test_reftable_stack_add); - RUN_TEST(test_reftable_stack_add_one); - RUN_TEST(test_reftable_stack_auto_compaction); - RUN_TEST(test_reftable_stack_auto_compaction_with_locked_tables); - RUN_TEST(test_reftable_stack_add_performs_auto_compaction); - RUN_TEST(test_reftable_stack_compaction_concurrent); - RUN_TEST(test_reftable_stack_compaction_concurrent_clean); - RUN_TEST(test_reftable_stack_compaction_with_locked_tables); - RUN_TEST(test_reftable_stack_hash_id); - RUN_TEST(test_reftable_stack_lock_failure); - RUN_TEST(test_reftable_stack_log_normalize); - RUN_TEST(test_reftable_stack_tombstone); - RUN_TEST(test_reftable_stack_transaction_api); - RUN_TEST(test_reftable_stack_transaction_api_performs_auto_compaction); - RUN_TEST(test_reftable_stack_auto_compaction_fails_gracefully); - RUN_TEST(test_reftable_stack_update_index_check); - RUN_TEST(test_reftable_stack_uptodate); - RUN_TEST(test_reftable_stack_read_across_reload); - RUN_TEST(test_reftable_stack_reload_with_missing_table); - RUN_TEST(test_suggest_compaction_segment); - RUN_TEST(test_suggest_compaction_segment_nothing); - return 0; + TEST(t_empty_add(), "empty addition to stack"); + TEST(t_read_file(), "read_lines works"); + TEST(t_reflog_expire(), "expire reflog entries"); + TEST(t_reftable_stack_add(), "add multiple refs and logs to stack"); + TEST(t_reftable_stack_add_one(), "add a single ref record to stack"); + TEST(t_reftable_stack_add_performs_auto_compaction(), "addition to stack triggers auto-compaction"); + TEST(t_reftable_stack_auto_compaction(), "stack must form geometric sequence after compaction"); + TEST(t_reftable_stack_auto_compaction_fails_gracefully(), "failure on auto-compaction"); + TEST(t_reftable_stack_auto_compaction_with_locked_tables(), "auto compaction with locked tables"); + TEST(t_reftable_stack_compaction_concurrent(), "compaction with concurrent stack"); + TEST(t_reftable_stack_compaction_concurrent_clean(), "compaction with unclean stack shutdown"); + TEST(t_reftable_stack_compaction_with_locked_tables(), "compaction with locked tables"); + TEST(t_reftable_stack_hash_id(), "read stack with wrong hash ID"); + TEST(t_reftable_stack_lock_failure(), "stack addition with lockfile failure"); + TEST(t_reftable_stack_log_normalize(), "log messages should be normalized"); + TEST(t_reftable_stack_read_across_reload(), "stack iterators work across reloads"); + TEST(t_reftable_stack_reload_with_missing_table(), "stack iteration with garbage tables"); + TEST(t_reftable_stack_tombstone(), "'tombstone' refs in stack"); + TEST(t_reftable_stack_transaction_api(), "update transaction to stack"); + TEST(t_reftable_stack_transaction_api_performs_auto_compaction(), "update transaction triggers auto-compaction"); + TEST(t_reftable_stack_update_index_check(), "update transactions with equal update indices"); + TEST(t_reftable_stack_uptodate(), "stack must be reloaded before ref update"); + TEST(t_suggest_compaction_segment(), "suggest_compaction_segment with basic input"); + TEST(t_suggest_compaction_segment_nothing(), "suggest_compaction_segment with pre-compacted input"); + + return test_done(); } From patchwork Wed Sep 4 14:38:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13791082 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.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 DE4C71D88D5 for ; Wed, 4 Sep 2024 15:02:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725462123; cv=none; b=rY/xiK7vR9JOAlC8FXhyUAwSYoG/FJMgZ1fGKyjWjKTmUp9swLLykBW+lvXgWCsJZX3Ng8+K3q6Y3e3ul525IcqlN66SmTVAKgUX2AqPPISxqS33UHtlZN7xEX7wBTms8VRyDW92G70hcb3DLM7VjgZr0HMBSrTtrEMSmzHmyRA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725462123; c=relaxed/simple; bh=GrSieV5mZaCyH48aU3EcZKk6s5lvG8BD5BhdvRR6Jfw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VJkaA7DQyHJ9oxuPX7pHVfXsT0O8sfuciEOP3dbXgVAKnRTSJHgo0oxiYNJtEzykdq7ub25oKOeFegpP+Nzw6kHL6L5bhk4tLKg99IGTDlMS7JtDfavVu791PfdmMqZMT2lLccbhnTotc8nbIMSzs9fcnithbx6udY2It7YycQI= 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=HS+3wY1V; arc=none smtp.client-ip=209.85.214.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="HS+3wY1V" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2055a3f80a4so26704445ad.2 for ; Wed, 04 Sep 2024 08:02:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725462121; x=1726066921; 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=5Nx6EgotcfCnji/fX78uCBdEQv0nkDKo0eneuBFd8+0=; b=HS+3wY1VEMYNHM7p0SybAkbmIf8KM7cTPRaMI82ChgRnHOPWNvgOWpi/dkSL0+4Y4h CjBxoH3iih7s+QR87ROgylJpNtWlML984W4bS0ZChuQBMMcbLC84yaifkVW+5KV14euo W21Y2HxbHmX+Rymuqs0AmieyIfhLjIKNLN7Bh8hhUL+bnn+Yo6f6oVnteCtyxKuOP47Y oFPZLyTgbiNAlcTcZkX7Efk0l77rv9wjgJBON1m1ZshjS+X6JVgckuCN19mZQFUWsuEt hyU/sZVFB57EeAMqMMPMLMprxUmZXrNqLwil77KDi6BY4QwEg72C1U1vLXLocvuYBfst SRBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725462121; x=1726066921; 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=5Nx6EgotcfCnji/fX78uCBdEQv0nkDKo0eneuBFd8+0=; b=aW3mKQmDek+1CDWKR1xdIyX+cDX5df0HWaS7YQFiVh+/vjOJaZZ6Wi5pP2JIhZc3CQ OpZysTYc9ZD+0tinZHiRemF8kzpcjAM/xazurZPork4ev0nH2u8SJ0xPow0dKOd+iwXK R6oeY5eB5mE9S+xKVLhQAO1rpxjbUdl2xvOKrHBBigdNX5ha9jeiXwcEAYVGTcd6k4Cj BVDXFN4tyaqq1sYZtMCBVcmydFbkuLi4qTX8158OjaO2iRKSatRtFL8bV8e5AH+1zFBg hivHp6yhPm7FGxABDU+/2ovGlmjZ1hYu0+8QT5p6aYvVtOkBJ0VJeVF/sHqVjl8xD+kf ozxA== X-Gm-Message-State: AOJu0YzZGGjJyQYwtbbsZb2T1DLDd3r5H6yfMN2OvD/0vV/4rK3MME0w 44UX9Cqb1s2wc62BWqtDnEA3Sr5t7j3Su8EL6FMXSEujRQId0OmpbaJdA2If X-Google-Smtp-Source: AGHT+IEZSuR15uz9/mpHm5icfudqUqd75lriEMvt4+9YPmA0Si5PQ1NzqKGliVW8fRzmovf4r8kNkw== X-Received: by 2002:a17:903:28f:b0:202:32cf:5dbe with SMTP id d9443c01a7336-205447b07ffmr146666425ad.58.1725462120410; Wed, 04 Sep 2024 08:02:00 -0700 (PDT) Received: from Ubuntu.. ([106.194.60.213]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-206aea65fe6sm14549395ad.257.2024.09.04.08.01.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 08:02:00 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v4 2/6] t: harmonize t-reftable-stack.c with coding guidelines Date: Wed, 4 Sep 2024 20:08:02 +0530 Message-ID: <20240904150132.11567-3-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240904150132.11567-1-chandrapratap3519@gmail.com> References: <20240826173627.4525-1-chandrapratap3519@gmail.com> <20240904150132.11567-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-stack.c with the following guidelines: - Single line 'for' statements must omit curly braces. - Structs must be 0-initialized with '= { 0 }' instead of '= { NULL }'. - Array sizes and indices should preferably be of type 'size_t' and not 'int'. - Function pointers should be passed as 'func' and not '&func'. While at it, remove initialization for those variables that are re-used multiple times, like loop variables. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-stack.c | 110 +++++++++++++++----------------- 1 file changed, 53 insertions(+), 57 deletions(-) diff --git a/t/unit-tests/t-reftable-stack.c b/t/unit-tests/t-reftable-stack.c index de28fac466..c74660a1e2 100644 --- a/t/unit-tests/t-reftable-stack.c +++ b/t/unit-tests/t-reftable-stack.c @@ -81,7 +81,6 @@ static void t_read_file(void) int n, err; char **names = NULL; const char *want[] = { "line1", "line2", "line3" }; - int i = 0; check_int(fd, >, 0); n = write_in_full(fd, out, strlen(out)); @@ -92,9 +91,8 @@ static void t_read_file(void) err = read_lines(fn, &names); check(!err); - for (i = 0; names[i]; i++) { + for (size_t i = 0; names[i]; i++) check_str(want[i], names[i]); - } free_names(names); (void) remove(fn); } @@ -123,7 +121,7 @@ static void write_n_ref_tables(struct reftable_stack *st, }; strbuf_reset(&buf); - strbuf_addf(&buf, "refs/heads/branch-%04u", (unsigned) i); + strbuf_addf(&buf, "refs/heads/branch-%04"PRIuMAX, (uintmax_t)i); ref.refname = buf.buf; set_test_hash(ref.value.val1, i); @@ -164,12 +162,12 @@ static void t_reftable_stack_add_one(void) .value_type = REFTABLE_REF_SYMREF, .value.symref = (char *) "master", }; - struct reftable_ref_record dest = { NULL }; + struct reftable_ref_record dest = { 0 }; struct stat stat_result = { 0 }; err = reftable_new_stack(&st, dir, &opts); check(!err); - err = reftable_stack_add(st, &write_test_ref, &ref); + err = reftable_stack_add(st, write_test_ref, &ref); check(!err); err = reftable_stack_read_ref(st, ref.refname, &dest); @@ -234,16 +232,16 @@ static void t_reftable_stack_uptodate(void) err = reftable_new_stack(&st2, dir, &opts); check(!err); - err = reftable_stack_add(st1, &write_test_ref, &ref1); + err = reftable_stack_add(st1, write_test_ref, &ref1); check(!err); - err = reftable_stack_add(st2, &write_test_ref, &ref2); + err = reftable_stack_add(st2, write_test_ref, &ref2); check_int(err, ==, REFTABLE_OUTDATED_ERROR); err = reftable_stack_reload(st2); check(!err); - err = reftable_stack_add(st2, &write_test_ref, &ref2); + err = reftable_stack_add(st2, write_test_ref, &ref2); check(!err); reftable_stack_destroy(st1); reftable_stack_destroy(st2); @@ -264,7 +262,7 @@ static void t_reftable_stack_transaction_api(void) .value_type = REFTABLE_REF_SYMREF, .value.symref = (char *) "master", }; - struct reftable_ref_record dest = { NULL }; + struct reftable_ref_record dest = { 0 }; err = reftable_new_stack(&st, dir, &opts); check(!err); @@ -274,7 +272,7 @@ static void t_reftable_stack_transaction_api(void) err = reftable_stack_new_addition(&add, st); check(!err); - err = reftable_addition_add(add, &write_test_ref, &ref); + err = reftable_addition_add(add, write_test_ref, &ref); check(!err); err = reftable_addition_commit(add); @@ -298,12 +296,13 @@ static void t_reftable_stack_transaction_api_performs_auto_compaction(void) struct reftable_write_options opts = {0}; struct reftable_addition *add = NULL; struct reftable_stack *st = NULL; - int i, n = 20, err; + size_t n = 20; + int err; err = reftable_new_stack(&st, dir, &opts); check(!err); - for (i = 0; i <= n; i++) { + for (size_t i = 0; i <= n; i++) { struct reftable_ref_record ref = { .update_index = reftable_stack_next_update_index(st), .value_type = REFTABLE_REF_SYMREF, @@ -311,7 +310,7 @@ static void t_reftable_stack_transaction_api_performs_auto_compaction(void) }; char name[100]; - snprintf(name, sizeof(name), "branch%04d", i); + snprintf(name, sizeof(name), "branch%04"PRIuMAX, (uintmax_t)i); ref.refname = name; /* @@ -324,7 +323,7 @@ static void t_reftable_stack_transaction_api_performs_auto_compaction(void) err = reftable_stack_new_addition(&add, st); check(!err); - err = reftable_addition_add(add, &write_test_ref, &ref); + err = reftable_addition_add(add, write_test_ref, &ref); check(!err); err = reftable_addition_commit(add); @@ -355,7 +354,7 @@ static void t_reftable_stack_auto_compaction_fails_gracefully(void) .value_type = REFTABLE_REF_VAL1, .value.val1 = {0x01}, }; - struct reftable_write_options opts = {0}; + struct reftable_write_options opts = { 0 }; struct reftable_stack *st; struct strbuf table_path = STRBUF_INIT; char *dir = get_tmp_dir(__LINE__); @@ -417,10 +416,10 @@ static void t_reftable_stack_update_index_check(void) err = reftable_new_stack(&st, dir, &opts); check(!err); - err = reftable_stack_add(st, &write_test_ref, &ref1); + err = reftable_stack_add(st, write_test_ref, &ref1); check(!err); - err = reftable_stack_add(st, &write_test_ref, &ref2); + err = reftable_stack_add(st, write_test_ref, &ref2); check_int(err, ==, REFTABLE_API_ERROR); reftable_stack_destroy(st); clear_dir(dir); @@ -436,7 +435,7 @@ static void t_reftable_stack_lock_failure(void) err = reftable_new_stack(&st, dir, &opts); check(!err); for (i = -1; i != REFTABLE_EMPTY_TABLE_ERROR; i--) { - err = reftable_stack_add(st, &write_error, &i); + err = reftable_stack_add(st, write_error, &i); check_int(err, ==, i); } @@ -446,7 +445,6 @@ static void t_reftable_stack_lock_failure(void) static void t_reftable_stack_add(void) { - int i = 0; int err = 0; struct reftable_write_options opts = { .exact_log_message = 1, @@ -455,18 +453,18 @@ static void t_reftable_stack_add(void) }; struct reftable_stack *st = NULL; char *dir = get_tmp_dir(__LINE__); - struct reftable_ref_record refs[2] = { { NULL } }; - struct reftable_log_record logs[2] = { { NULL } }; + struct reftable_ref_record refs[2] = { 0 }; + struct reftable_log_record logs[2] = { 0 }; struct strbuf path = STRBUF_INIT; struct stat stat_result; - int N = ARRAY_SIZE(refs); + size_t i, N = ARRAY_SIZE(refs); err = reftable_new_stack(&st, dir, &opts); check(!err); for (i = 0; i < N; i++) { char buf[256]; - snprintf(buf, sizeof(buf), "branch%02d", i); + snprintf(buf, sizeof(buf), "branch%02"PRIuMAX, (uintmax_t)i); refs[i].refname = xstrdup(buf); refs[i].update_index = i + 1; refs[i].value_type = REFTABLE_REF_VAL1; @@ -480,7 +478,7 @@ static void t_reftable_stack_add(void) } for (i = 0; i < N; i++) { - int err = reftable_stack_add(st, &write_test_ref, &refs[i]); + int err = reftable_stack_add(st, write_test_ref, &refs[i]); check(!err); } @@ -489,7 +487,7 @@ static void t_reftable_stack_add(void) .log = &logs[i], .update_index = reftable_stack_next_update_index(st), }; - int err = reftable_stack_add(st, &write_test_log, &arg); + int err = reftable_stack_add(st, write_test_log, &arg); check(!err); } @@ -497,7 +495,7 @@ static void t_reftable_stack_add(void) check(!err); for (i = 0; i < N; i++) { - struct reftable_ref_record dest = { NULL }; + struct reftable_ref_record dest = { 0 }; int err = reftable_stack_read_ref(st, refs[i].refname, &dest); check(!err); @@ -507,7 +505,7 @@ static void t_reftable_stack_add(void) } for (i = 0; i < N; i++) { - struct reftable_log_record dest = { NULL }; + struct reftable_log_record dest = { 0 }; int err = reftable_stack_read_log(st, refs[i].refname, &dest); check(!err); check(reftable_log_record_equal(&dest, logs + i, @@ -575,11 +573,11 @@ static void t_reftable_stack_log_normalize(void) check(!err); input.value.update.message = (char *) "one\ntwo"; - err = reftable_stack_add(st, &write_test_log, &arg); + err = reftable_stack_add(st, write_test_log, &arg); check_int(err, ==, REFTABLE_API_ERROR); input.value.update.message = (char *) "one"; - err = reftable_stack_add(st, &write_test_log, &arg); + err = reftable_stack_add(st, write_test_log, &arg); check(!err); err = reftable_stack_read_log(st, input.refname, &dest); @@ -588,7 +586,7 @@ static void t_reftable_stack_log_normalize(void) input.value.update.message = (char *) "two\n"; arg.update_index = 2; - err = reftable_stack_add(st, &write_test_log, &arg); + err = reftable_stack_add(st, write_test_log, &arg); check(!err); err = reftable_stack_read_log(st, input.refname, &dest); check(!err); @@ -602,16 +600,15 @@ static void t_reftable_stack_log_normalize(void) static void t_reftable_stack_tombstone(void) { - int i = 0; char *dir = get_tmp_dir(__LINE__); struct reftable_write_options opts = { 0 }; struct reftable_stack *st = NULL; int err; - struct reftable_ref_record refs[2] = { { NULL } }; - struct reftable_log_record logs[2] = { { NULL } }; - int N = ARRAY_SIZE(refs); - struct reftable_ref_record dest = { NULL }; - struct reftable_log_record log_dest = { NULL }; + struct reftable_ref_record refs[2] = { 0 }; + struct reftable_log_record logs[2] = { 0 }; + size_t i, N = ARRAY_SIZE(refs); + struct reftable_ref_record dest = { 0 }; + struct reftable_log_record log_dest = { 0 }; err = reftable_new_stack(&st, dir, &opts); check(!err); @@ -637,7 +634,7 @@ static void t_reftable_stack_tombstone(void) } } for (i = 0; i < N; i++) { - int err = reftable_stack_add(st, &write_test_ref, &refs[i]); + int err = reftable_stack_add(st, write_test_ref, &refs[i]); check(!err); } @@ -646,7 +643,7 @@ static void t_reftable_stack_tombstone(void) .log = &logs[i], .update_index = reftable_stack_next_update_index(st), }; - int err = reftable_stack_add(st, &write_test_log, &arg); + int err = reftable_stack_add(st, write_test_log, &arg); check(!err); } @@ -695,12 +692,12 @@ static void t_reftable_stack_hash_id(void) struct reftable_stack *st32 = NULL; struct reftable_write_options opts_default = { 0 }; struct reftable_stack *st_default = NULL; - struct reftable_ref_record dest = { NULL }; + struct reftable_ref_record dest = { 0 }; err = reftable_new_stack(&st, dir, &opts); check(!err); - err = reftable_stack_add(st, &write_test_ref, &ref); + err = reftable_stack_add(st, write_test_ref, &ref); check(!err); /* can't read it with the wrong hash ID. */ @@ -743,21 +740,20 @@ static void t_reflog_expire(void) char *dir = get_tmp_dir(__LINE__); struct reftable_write_options opts = { 0 }; struct reftable_stack *st = NULL; - struct reftable_log_record logs[20] = { { NULL } }; - int N = ARRAY_SIZE(logs) - 1; - int i = 0; + struct reftable_log_record logs[20] = { 0 }; + size_t i, N = ARRAY_SIZE(logs) - 1; int err; struct reftable_log_expiry_config expiry = { .time = 10, }; - struct reftable_log_record log = { NULL }; + struct reftable_log_record log = { 0 }; err = reftable_new_stack(&st, dir, &opts); check(!err); for (i = 1; i <= N; i++) { char buf[256]; - snprintf(buf, sizeof(buf), "branch%02d", i); + snprintf(buf, sizeof(buf), "branch%02"PRIuMAX, (uintmax_t)i); logs[i].refname = xstrdup(buf); logs[i].update_index = i; @@ -772,7 +768,7 @@ static void t_reflog_expire(void) .log = &logs[i], .update_index = reftable_stack_next_update_index(st), }; - int err = reftable_stack_add(st, &write_test_log, &arg); + int err = reftable_stack_add(st, write_test_log, &arg); check(!err); } @@ -800,9 +796,8 @@ static void t_reflog_expire(void) /* cleanup */ reftable_stack_destroy(st); - for (i = 0; i <= N; i++) { + for (i = 0; i <= N; i++) reftable_log_record_release(&logs[i]); - } clear_dir(dir); reftable_log_record_release(&log); } @@ -824,7 +819,7 @@ static void t_empty_add(void) err = reftable_new_stack(&st, dir, &opts); check(!err); - err = reftable_stack_add(st, &write_nothing, NULL); + err = reftable_stack_add(st, write_nothing, NULL); check(!err); err = reftable_new_stack(&st2, dir, &opts); @@ -851,8 +846,8 @@ static void t_reftable_stack_auto_compaction(void) }; struct reftable_stack *st = NULL; char *dir = get_tmp_dir(__LINE__); - int err, i; - int N = 100; + int err; + size_t i, N = 100; err = reftable_new_stack(&st, dir, &opts); check(!err); @@ -865,9 +860,9 @@ static void t_reftable_stack_auto_compaction(void) .value_type = REFTABLE_REF_SYMREF, .value.symref = (char *) "master", }; - snprintf(name, sizeof(name), "branch%04d", i); + snprintf(name, sizeof(name), "branch%04"PRIuMAX, (uintmax_t)i); - err = reftable_stack_add(st, &write_test_ref, &ref); + err = reftable_stack_add(st, write_test_ref, &ref); check(!err); err = reftable_stack_auto_compact(st); @@ -929,7 +924,8 @@ static void t_reftable_stack_add_performs_auto_compaction(void) struct reftable_stack *st = NULL; struct strbuf refname = STRBUF_INIT; char *dir = get_tmp_dir(__LINE__); - int err, i, n = 20; + int err; + size_t i, n = 20; err = reftable_new_stack(&st, dir, &opts); check(!err); @@ -949,10 +945,10 @@ static void t_reftable_stack_add_performs_auto_compaction(void) st->opts.disable_auto_compact = i != n; strbuf_reset(&refname); - strbuf_addf(&refname, "branch-%04d", i); + strbuf_addf(&refname, "branch-%04"PRIuMAX, (uintmax_t)i); ref.refname = refname.buf; - err = reftable_stack_add(st, &write_test_ref, &ref); + err = reftable_stack_add(st, write_test_ref, &ref); check(!err); /* From patchwork Wed Sep 4 14:38:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13791083 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97BF11DCB24 for ; Wed, 4 Sep 2024 15:02:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725462126; cv=none; b=jtDsIxtRpOpnTaU6KDXAnGa5fllyjZwK9IpmALzVsBjEE8Zl0JZGeAy8ipX5uNOexvRYc1cuAXZPVD3a8orEqmCg0/Ng+YT/0CxdprAX49xVDAwTe0JmvUkM3V93fTfvDzCjrv29dFJEbjWRkJ1QQRQ1mEnziUb9LP9zDVVVTZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725462126; c=relaxed/simple; bh=IxEBmaCr9gKSskHj6CAUTBgOfBKs8xP8mvE2mFDGb08=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DkwSSM7f8M9su3vezNhEqyv1ak3aeLrwMBF0arND0Vt9ucTDdbCWfavOlYrvzORpnVWI+9hw0Ca85Tsr6rjjX+FlYwdI+hbXxpumjH4Kv6KRuFsvpggAse2/838oj1djBKVH6SOGZ2SDv4b5EAeS2+TCjR6bCc1I0MWacF8941U= 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=TjCUjV+E; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TjCUjV+E" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2054e22ce3fso33399575ad.2 for ; Wed, 04 Sep 2024 08:02:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725462123; x=1726066923; 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=ciIehjiLqNywTFZ3TwhvbEO/72n4+M71jO883/S1Z4k=; b=TjCUjV+EFGNf284jrkIe2p7bDbAqzBIqgEt7gcXtVpIs0470yi91WpUDgStvP4zjhI pudAyrHnEgpTRKcxwofwLS2YxbYL6tzd6NnUzP3QgcK9mywFW2Q7xAscXste2JmGni6g 0YpF+WRJUfM/6aaG/Vt1Km3MQpzfN4j660galYtIgyzmNNaGC9JTrjac6HZWFjwNSXgb sSIvOH+d1ETPfgFxZ/pkx9bYjlAYcys0FDPJbuTiise73TeIGK22hPUs2C7N//wHKbJF 7mBMAstSL/Pf1YYse2eCsFxjfcbaGzYP6ir0HBhif6xCnkinaZJjFW2K+FB4u09nkb6C DM0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725462123; x=1726066923; 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=ciIehjiLqNywTFZ3TwhvbEO/72n4+M71jO883/S1Z4k=; b=X4QnRZ/8xyTX+qKEEgUzbIr/cUL9Y7Pn33JuBBMPUyUyYM6dNlLgAej30D9iYCih6a svX1nwZz0YDPTwqv/ueoFA4NG6r36Ey4RJ4NIrnDbywGjscSDRDAmKk5H2bI/E11uZxT eIbjteWsqQh4Po3zmY1EUVT1SLY24rvvQtxcDsQKyLUof2lFLNx4Hnr8KAHla0x9RTGE sPS/2rrInYQgWtI8qSL6ZoNnAZJC+DPTPX4jWbqfEulxN0gMCvSn1IA2VgbasLcOHzGY QYt0UcE0PLaDnaXwvg9bwkZ60KqwtRaOJ1lANT3TmVxcwG8lfyAbQCHl3bzMrOA3pEcJ bX4A== X-Gm-Message-State: AOJu0YzF59vQ3Q9AXhKXCdBiibFEaJxX7uK8+cZxOMjfjLRxx+ml/V9T fQI3u6bgsjLdEHD4gVMyBCRPt6P+AB46CEP1PocHCqv4jyq5itvqEVvk/4Ff X-Google-Smtp-Source: AGHT+IHrZXvJdUqMGUB30YUlxJLoSktbRDYqdzsZlBY9pP+VgNhxJU05tlxjlHtzn+nK2grhONDIxQ== X-Received: by 2002:a17:902:fc43:b0:205:9201:b520 with SMTP id d9443c01a7336-20699b37027mr60423675ad.58.1725462123437; Wed, 04 Sep 2024 08:02:03 -0700 (PDT) Received: from Ubuntu.. ([106.194.60.213]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-206aea65fe6sm14549395ad.257.2024.09.04.08.02.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 08:02:02 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v4 3/6] t-reftable-stack: use Git's tempfile API instead of mkstemp() Date: Wed, 4 Sep 2024 20:08:03 +0530 Message-ID: <20240904150132.11567-4-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240904150132.11567-1-chandrapratap3519@gmail.com> References: <20240826173627.4525-1-chandrapratap3519@gmail.com> <20240904150132.11567-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Git's tempfile API defined by $GIT_DIR/tempfile.{c,h} provides a unified interface for tempfile operations. Since reftable/stack.c uses this API for all its tempfile needs instead of raw functions like mkstemp(), make the ported stack test strictly use Git's tempfile API as well. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-stack.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/t/unit-tests/t-reftable-stack.c b/t/unit-tests/t-reftable-stack.c index c74660a1e2..8047e25c48 100644 --- a/t/unit-tests/t-reftable-stack.c +++ b/t/unit-tests/t-reftable-stack.c @@ -76,7 +76,8 @@ static char *get_tmp_dir(int linenumber) static void t_read_file(void) { char *fn = get_tmp_template(__LINE__); - int fd = mkstemp(fn); + struct tempfile *tmp = mks_tempfile(fn); + int fd = get_tempfile_fd(tmp); char out[1024] = "line1\n\nline2\nline3"; int n, err; char **names = NULL; @@ -95,6 +96,7 @@ static void t_read_file(void) check_str(want[i], names[i]); free_names(names); (void) remove(fn); + delete_tempfile(&tmp); } static int write_test_ref(struct reftable_writer *wr, void *arg) From patchwork Wed Sep 4 14:38:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13791084 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 AD7921D88D5 for ; Wed, 4 Sep 2024 15:02:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725462129; cv=none; b=CxnJMqNHj6Hnn+if6+z2YRdX/ACPsOcpTP4D26nPmJOalPHf9iDqh22oDT8q0YltTFbYGEsNUVX0kW8TjyMhVh24qxU75qcpnLx3HdJ/l/NVOhkiJjNS+IKA6CmyVLd1Jer1upD5gONMR4DEVrLFXoWC/pzS4+2xrysTDjhRtNo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725462129; c=relaxed/simple; bh=04EbSP/LvkdTgS/2dPSs0llfA+pfbAVgP+qYVm3wpOw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ffm+KnGPjDXkx+qJOmQ2ixpbHeq/s4HiSKhf1Azz2MtRXI9Dd2UEBSi9ZWDTWnfMuYAP7Z42JwzD2WxN92EjMowaxAM8cpAZkwAgjIFdG4ERJxU7296igNdHzBip90nnHWJruORBoA7UpEpWLN5MXRhwShiUhduhTgtV/L97Kjg= 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=KMFPId6O; arc=none smtp.client-ip=209.85.214.180 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="KMFPId6O" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-205909afad3so27056655ad.2 for ; Wed, 04 Sep 2024 08:02:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725462126; x=1726066926; 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=2hWMeEGPpPBhRdbp2ElETdrQGKzusKxPku43hdOmugw=; b=KMFPId6ORYx+5swnpGJF7HrCImOmJEqIGI8teocLprgR/EXCMvfV1Y609QfHHoyAtu n8zknvcWV0cfqEk1w5k4ZhAB5V9MwQoY85ec8KI6g65sk8hexoXGMxZZOA3uvBUnvQRK IifF3mALkFAPqPQdocbHtmYMPc6P7K1M4xlyeSvG39gZjN4iQGSCT2Z3i3g4/pNLH4mh asetmrscOBtbQUXQRU5M4IWkdSECmsrKFRIhhee59ePG8XnES9ysDxVAh44JroJjU3Cm JQ4dO0oqvLq+fd4KvFmImo7HJMr7wRm1Xv5xl1uTM/qwVjNrGaDlytNOSbKF2C8P2Bi9 angw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725462126; x=1726066926; 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=2hWMeEGPpPBhRdbp2ElETdrQGKzusKxPku43hdOmugw=; b=TlK+0lKg/Y+qoIv82xnMSQh2qyyZuvg5IhpzUccIHikMe84adP9mq7PFd880VYsslB ChV7usXf7IDBOINTmZz46uTyNpGyGzR7aTtN58kTEjJpPg2BgteLTffghFLgziarECwt WZo+5mZHE7OoA0mvWKGYDS74b3FOkjIQE0RfURIqE5SZbLznO+FS/ipOis1yc5SZCU1Z raFEpBuagHzLQ5LyeJ9V0LuvqY2jY+vkw9GT0qzueVI3RZEd/F2OUL/K2n5mI7fpBLfa Zc8wxnoUHpYOADfsgwAQ/iadnZ6kHYetbCeTosd1YfjsRRKLebzY+sGPteO+BgB7imv/ r1zw== X-Gm-Message-State: AOJu0Yy2wvwX0AIaubribuPeXfeYBKuLLgQnZ3LvuimJ/dGKpNuwFOnm qnG0+SIEItjt2RxYdJzq3bO1RGvSnikwSjF6HPbAhNJuq/IS22QQpxxSZ5VW X-Google-Smtp-Source: AGHT+IGIimwbNlb7qUGDWgfbWidg4laQsLcTS8Aj+EZgzcsQZ0Xc2S7xtWjEv8nhxD69ALXmLvDEvg== X-Received: by 2002:a17:902:ecc7:b0:206:c60f:494e with SMTP id d9443c01a7336-206c60f68f1mr14141705ad.23.1725462126044; Wed, 04 Sep 2024 08:02:06 -0700 (PDT) Received: from Ubuntu.. ([106.194.60.213]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-206aea65fe6sm14549395ad.257.2024.09.04.08.02.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 08:02:05 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v4 4/6] t-reftable-stack: use reftable_ref_record_equal() to compare ref records Date: Wed, 4 Sep 2024 20:08:04 +0530 Message-ID: <20240904150132.11567-5-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240904150132.11567-1-chandrapratap3519@gmail.com> References: <20240826173627.4525-1-chandrapratap3519@gmail.com> <20240904150132.11567-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In the current stack tests, ref records are compared for equality by sometimes using the dedicated function for ref-record comparison, reftable_ref_record_equal(), and sometimes by explicity comparing contents of the ref records. Replace the latter instances of ref-record comparison with the former to maintain uniformity throughout the test file. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-stack.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/unit-tests/t-reftable-stack.c b/t/unit-tests/t-reftable-stack.c index 8047e25c48..4f2ef1a8cc 100644 --- a/t/unit-tests/t-reftable-stack.c +++ b/t/unit-tests/t-reftable-stack.c @@ -174,7 +174,7 @@ static void t_reftable_stack_add_one(void) err = reftable_stack_read_ref(st, ref.refname, &dest); check(!err); - check_str("master", dest.value.symref); + check(reftable_ref_record_equal(&ref, &dest, GIT_SHA1_RAWSZ)); check_int(st->readers_len, >, 0); #ifndef GIT_WINDOWS_NATIVE @@ -285,7 +285,7 @@ static void t_reftable_stack_transaction_api(void) err = reftable_stack_read_ref(st, ref.refname, &dest); check(!err); check_int(REFTABLE_REF_SYMREF, ==, dest.value_type); - check_str("master", dest.value.symref); + check(reftable_ref_record_equal(&ref, &dest, GIT_SHA1_RAWSZ)); reftable_ref_record_release(&dest); reftable_stack_destroy(st); From patchwork Wed Sep 4 14:38:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13791085 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 E3C771D88D5 for ; Wed, 4 Sep 2024 15:02:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725462132; cv=none; b=m1S6sp+oOV0stvMX/nXGGRLC1n0X/QegXMme6PWf5KCDPazM3kwB5JAbfunFcP2hS1GI5hFtEmpD0AV+5k+olAL4d/HVo1HZYXP4hbS0+sVIpi4cHtNP0EdgsqmhYWWd/BPDa20R4ItMTn87yo8RCiSk/rP7YjpzfuM+Mixcxjw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725462132; c=relaxed/simple; bh=tiMt8eQ9Wz/dZ4NqLnOpFeE7lFDBFWSkekVpry+AGsM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CUc6tTvptSPig8LIURhuBI/0rXYRR9cMtXj4RJZLrGYRfgnOc66fBhlafnzU/0Gswhjfpw36KpZZPjDovIlmQCg0Y34xnYINW5VjubG042uewHArc6/fuL8jCKoI1OeohGpEQoEgLm7hOaREJ0DRo8teQiL9wINHHfiQYcG2t+o= 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=YzgExYNq; arc=none smtp.client-ip=209.85.214.180 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="YzgExYNq" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2053f6b8201so34649215ad.2 for ; Wed, 04 Sep 2024 08:02:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725462129; x=1726066929; 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=0OO0eIpA11/USeXurWqLSkyt3PnVO+RdsJ8RPpz7mv8=; b=YzgExYNqnoNCO5D7/MCW+HbOcuIiDCA5CQTP2Gga8KrnT6JDed3k6qth+Ws77Enb0F 1kdmmvTxPRQrmyAJavEI3CKNZIWznNmQZiyxFvLyBZ8BrORsq5oO+sdfBWLL+nN9SgEF vu2rq9K9/QUJJNCGKn1ZkmrVEBAu2kiTA+ITWQCMABVJsfUxBFs4XZwtY65zXCjSgIhN NAWtwRN9mBVeToE9U7JoB+d/Tym6e5hN6yLhvoaK3rVn1rt5igcKFW04wNoe9t8A9VDn 0nbue9alxnGK5QRve2TISY1RTRvri5NOyBITRneCM8CJ+G9vCDaYZDa1ifBpvg5p3a1W SeYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725462129; x=1726066929; 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=0OO0eIpA11/USeXurWqLSkyt3PnVO+RdsJ8RPpz7mv8=; b=lxynj1H1jvME4u2smfPv/IE2JRGShomxNfPSVlpSaBU+i8vCNdMO28zrWxwtyYsm9y sBi9ltlKg2zC0Z85lrS+5l4yqbiQPicPKFYDkEHX5xLoqgjXAVMpYITevFQ0gE8ioGBg zKKyrhVbiC5DrT3O3kjy6VB5E0996db8phPfqvPHNV/tZ8z1t+dXlPOURiuZBdXP3nmX kOk2Ayzmvjb3PBiPtXAheGugD0q0xPeAWwLJJBqUhkLIlz6rnoBif8/jIO5HVPNERFad r4alQeJ4D/07EFjt5V79MWYLRuaQM3X+2StUyrAEB9LpjCgQwkTFmxlT7/Btc2TMvj2J FNyQ== X-Gm-Message-State: AOJu0YwkRBuZyLtfeGqLKCDTBw5mDo3GcvcTPrEFyWAciS0JGhkjrQgN zCoqawBhyzt4ESX9L2D5oqS23rMfHsZPLOU2moETRHQm8WueBx7HsGq5s2l5 X-Google-Smtp-Source: AGHT+IFCGkurI6t+DL4+g0dnzA85Eqxq947ZvFnwvAAmbRXPMt3d0B7tvdSWGRSf7w6WfWnzkO4qug== X-Received: by 2002:a17:902:e550:b0:1fa:9c04:946a with SMTP id d9443c01a7336-20545e44a65mr212874075ad.1.1725462128712; Wed, 04 Sep 2024 08:02:08 -0700 (PDT) Received: from Ubuntu.. ([106.194.60.213]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-206aea65fe6sm14549395ad.257.2024.09.04.08.02.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 08:02:08 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v4 5/6] t-reftable-stack: add test for non-default compaction factor Date: Wed, 4 Sep 2024 20:08:05 +0530 Message-ID: <20240904150132.11567-6-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240904150132.11567-1-chandrapratap3519@gmail.com> References: <20240826173627.4525-1-chandrapratap3519@gmail.com> <20240904150132.11567-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In a recent codebase update (commit ae8e378430, merge branch 'ps/reftable-write-options', 2024/05/13) the geometric factor used in auto-compaction of reftable tables was made configurable. Add a test to verify the functionality introduced by this update. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-stack.c | 41 +++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/t/unit-tests/t-reftable-stack.c b/t/unit-tests/t-reftable-stack.c index 4f2ef1a8cc..4acf07ab0c 100644 --- a/t/unit-tests/t-reftable-stack.c +++ b/t/unit-tests/t-reftable-stack.c @@ -831,12 +831,12 @@ static void t_empty_add(void) reftable_stack_destroy(st2); } -static int fastlog2(uint64_t sz) +static int fastlogN(uint64_t sz, uint64_t N) { int l = 0; if (sz == 0) return 0; - for (; sz; sz /= 2) + for (; sz; sz /= N) l++; return l - 1; } @@ -869,11 +869,43 @@ static void t_reftable_stack_auto_compaction(void) err = reftable_stack_auto_compact(st); check(!err); - check(i < 3 || st->merged->readers_len < 2 * fastlog2(i)); + check(i < 2 || st->merged->readers_len < 2 * fastlogN(i, 2)); } check_int(reftable_stack_compaction_stats(st)->entries_written, <, - (uint64_t)(N * fastlog2(N))); + (uint64_t)(N * fastlogN(N, 2))); + + reftable_stack_destroy(st); + clear_dir(dir); +} + +static void t_reftable_stack_auto_compaction_factor(void) +{ + struct reftable_write_options opts = { + .auto_compaction_factor = 5, + }; + struct reftable_stack *st = NULL; + char *dir = get_tmp_dir(__LINE__); + int err; + size_t N = 100; + + err = reftable_new_stack(&st, dir, &opts); + check(!err); + + for (size_t i = 0; i < N; i++) { + char name[20]; + struct reftable_ref_record ref = { + .refname = name, + .update_index = reftable_stack_next_update_index(st), + .value_type = REFTABLE_REF_VAL1, + }; + xsnprintf(name, sizeof(name), "branch%04"PRIuMAX, (uintmax_t)i); + + err = reftable_stack_add(st, &write_test_ref, &ref); + check(!err); + + check(i < 5 || st->merged->readers_len < 5 * fastlogN(i, 5)); + } reftable_stack_destroy(st); clear_dir(dir); @@ -1186,6 +1218,7 @@ int cmd_main(int argc UNUSED, const char *argv[] UNUSED) TEST(t_reftable_stack_add_one(), "add a single ref record to stack"); TEST(t_reftable_stack_add_performs_auto_compaction(), "addition to stack triggers auto-compaction"); TEST(t_reftable_stack_auto_compaction(), "stack must form geometric sequence after compaction"); + TEST(t_reftable_stack_auto_compaction_factor(), "auto-compaction with non-default geometric factor"); TEST(t_reftable_stack_auto_compaction_fails_gracefully(), "failure on auto-compaction"); TEST(t_reftable_stack_auto_compaction_with_locked_tables(), "auto compaction with locked tables"); TEST(t_reftable_stack_compaction_concurrent(), "compaction with concurrent stack"); From patchwork Wed Sep 4 14:38:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13791086 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83D091DB548 for ; Wed, 4 Sep 2024 15:02:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725462133; cv=none; b=TwZCNKqVVwjlnpjnnKyq4pbHccXl7f/oqf+JTwJAGGV3Il3s3xYCAo36ygnrxZohZAGXLFnAjgRyHNbuiHtqe7xoaCfllR0QSw+oUZ48iWFR+4XCxshE3U0EV6cwa8M9V7twYJtx12zMoai+DRVSjpLeNNOGM+f3tNRaDhw72II= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725462133; c=relaxed/simple; bh=sXcZykDbgKoBZpg63KYosbbolzYdzZ/75ZYgUjKAQQ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kJHzW8MENlQCUUc7FLYxzuBY4KE5U8i1CPRLrrdhJDxULE4xBZltf/ShKEXPNEr4hVrA1mrj6VlnzpXAiU0WbyRX16oc8yQv3e0xWNysXcdHwsGmoOtll90TZbv/iFphVk68e1orcyyTaIGu9HyX5cTvzuJ+ifPr2XPaEg/w/Fs= 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=KAJA7hSE; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KAJA7hSE" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2068a7c9286so22399955ad.1 for ; Wed, 04 Sep 2024 08:02:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725462131; x=1726066931; 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=BOqzxdPGbfjryZSvC16y94IhLIMAw5TQfSsAsPzNiHE=; b=KAJA7hSEZ3rI3ZsiBGBTMVQ4M0DVkkJOD8h8LlsJmFl/mb6nTF9JnILfSfOEn+ixRD yphRgm49++Zv1qLI6HBo7VvTrM5Y5EJUAEIQSQw3JdTOs2nVb8Wk3zKaR9sg8glYXFs8 CvZhn8aGE/5QEBdTIjf4cub9Me0fFCG4rcrwUffgyMsYli9cD0QHSJ9EHkpt7ddRyzyb i7MZwuGwVnwEul5qt4ZLpUnIoEqB0KjIbzKV53cNlmR7ovcsWlXYva3NMIRoXka3nZHj OTztPyfatocMs1v6ZfZxJGerJnVt4gSLSA0vchbq6n+dM9tFElkcyRhvIRS8GA0xiLd4 X87Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725462131; x=1726066931; 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=BOqzxdPGbfjryZSvC16y94IhLIMAw5TQfSsAsPzNiHE=; b=ak7HcfCc+Tp8ksvnT78idxwOM7/4RX6BO2iqqVCg90y1oyEc28N23m8vfEEUFeMBcD B81HXHlLoJOwKStyyB4hwns2aB9A33g1KT6a9vLZmdE37fKvsQCcUjA7xSEfsuH6Eht9 PrbA3t1BbrwZIr2ioFE/owlkHk1OI/akDj+LQPIiY+t6CYPIz6FPuO1pnaMy+Tv/5V9+ 6jKZzhK86sGb5bh+JbRFlsgAMCpxNJLSi9b7h3nIeZiPHJclOhMyL0BGzz8LoGyL8F9n gtM2ePH6DaaR0U8KtrQIVvx6FlfdRgDRrGnqg6PMzy5qF9DRsy1wMFjWMFW1AIBRKdpK CtMw== X-Gm-Message-State: AOJu0YzFxU19stXnDpJ1g0Jd57bnyzpqIgD3HCOjEk4uLVzzPXc4i6ZZ ZJ15EIB0aD9P7rXhBRnx2MQvULpfo54eoHk8crjkjErwRBQAq0RN8oqnJp/V X-Google-Smtp-Source: AGHT+IE/vKbjIPVezlDndJ57LhooVS3zUBMd40AKmHdOC4QRD75tjx2/oXODzpwwOxfXhv3LmUjlZA== X-Received: by 2002:a17:903:32c8:b0:205:5a3f:76b5 with SMTP id d9443c01a7336-205841a6315mr124684915ad.28.1725462131386; Wed, 04 Sep 2024 08:02:11 -0700 (PDT) Received: from Ubuntu.. ([106.194.60.213]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-206aea65fe6sm14549395ad.257.2024.09.04.08.02.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 08:02:11 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v4 6/6] t-reftable-stack: add test for stack iterators Date: Wed, 4 Sep 2024 20:08:06 +0530 Message-ID: <20240904150132.11567-7-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240904150132.11567-1-chandrapratap3519@gmail.com> References: <20240826173627.4525-1-chandrapratap3519@gmail.com> <20240904150132.11567-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 reftable_stack_init_ref_iterator and reftable_stack_init_log_iterator as defined by reftable/stack.{c,h} initialize a stack iterator to iterate over the ref and log records in a reftable stack respectively. Since these functions are not exercised by any of the existing tests, add a test for them. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-stack.c | 80 +++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/t/unit-tests/t-reftable-stack.c b/t/unit-tests/t-reftable-stack.c index 4acf07ab0c..e209652031 100644 --- a/t/unit-tests/t-reftable-stack.c +++ b/t/unit-tests/t-reftable-stack.c @@ -544,6 +544,85 @@ static void t_reftable_stack_add(void) clear_dir(dir); } +static void t_reftable_stack_iterator(void) +{ + struct reftable_write_options opts = { 0 }; + struct reftable_stack *st = NULL; + char *dir = get_tmp_dir(__LINE__); + struct reftable_ref_record refs[10] = { 0 }; + struct reftable_log_record logs[10] = { 0 }; + struct reftable_iterator it = { 0 }; + size_t N = ARRAY_SIZE(refs), i; + int err; + + err = reftable_new_stack(&st, dir, &opts); + check(!err); + + for (i = 0; i < N; i++) { + refs[i].refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i); + refs[i].update_index = i + 1; + refs[i].value_type = REFTABLE_REF_VAL1; + set_test_hash(refs[i].value.val1, i); + + logs[i].refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i); + logs[i].update_index = i + 1; + logs[i].value_type = REFTABLE_LOG_UPDATE; + logs[i].value.update.email = xstrdup("johndoe@invalid"); + logs[i].value.update.message = xstrdup("commit\n"); + set_test_hash(logs[i].value.update.new_hash, i); + } + + for (i = 0; i < N; i++) { + err = reftable_stack_add(st, write_test_ref, &refs[i]); + check(!err); + } + + for (i = 0; i < N; i++) { + struct write_log_arg arg = { + .log = &logs[i], + .update_index = reftable_stack_next_update_index(st), + }; + err = reftable_stack_add(st, write_test_log, &arg); + check(!err); + } + + reftable_stack_init_ref_iterator(st, &it); + reftable_iterator_seek_ref(&it, refs[0].refname); + for (i = 0; ; i++) { + struct reftable_ref_record ref = { 0 }; + err = reftable_iterator_next_ref(&it, &ref); + if (err > 0) + break; + check(!err); + check(reftable_ref_record_equal(&ref, &refs[i], GIT_SHA1_RAWSZ)); + reftable_ref_record_release(&ref); + } + check_int(i, ==, N); + + reftable_iterator_destroy(&it); + + reftable_stack_init_log_iterator(st, &it); + reftable_iterator_seek_log(&it, logs[0].refname); + for (i = 0; ; i++) { + struct reftable_log_record log = { 0 }; + err = reftable_iterator_next_log(&it, &log); + if (err > 0) + break; + check(!err); + check(reftable_log_record_equal(&log, &logs[i], GIT_SHA1_RAWSZ)); + reftable_log_record_release(&log); + } + check_int(i, ==, N); + + reftable_stack_destroy(st); + reftable_iterator_destroy(&it); + for (i = 0; i < N; i++) { + reftable_ref_record_release(&refs[i]); + reftable_log_record_release(&logs[i]); + } + clear_dir(dir); +} + static void t_reftable_stack_log_normalize(void) { int err = 0; @@ -1225,6 +1304,7 @@ int cmd_main(int argc UNUSED, const char *argv[] UNUSED) TEST(t_reftable_stack_compaction_concurrent_clean(), "compaction with unclean stack shutdown"); TEST(t_reftable_stack_compaction_with_locked_tables(), "compaction with locked tables"); TEST(t_reftable_stack_hash_id(), "read stack with wrong hash ID"); + TEST(t_reftable_stack_iterator(), "log and ref iterator for reftable stack"); TEST(t_reftable_stack_lock_failure(), "stack addition with lockfile failure"); TEST(t_reftable_stack_log_normalize(), "log messages should be normalized"); TEST(t_reftable_stack_read_across_reload(), "stack iterators work across reloads");