From patchwork Mon Aug 26 17:29: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: 13778291 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1921D6F2E0 for ; Mon, 26 Aug 2024 17:37:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724693828; cv=none; b=k5MvXZPI1sHz82pNqwX6E47VfiOmkCc36OmVblr+641h5oURVt5ME4ED+OSFKOWuOjJiZt9Jkrkq/cNKiREKRh8Om/jBzgBCPyta1AJHx7/uULkn2zbsMvSdbv4KERTYk79wcMlHnPH7h5i5QkkZzpHuvDcwOtonPtx0lF2pea0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724693828; c=relaxed/simple; bh=RIq4Aszl0kvcpFP1pN11VSTX9AoZ1V+qcQ/flrFD7zY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CgReG9SuI7KlZSUvyfkmJZYlLo0so7RCJf/85Ti8N+PKjU0lG1JZy2xX9PkXdA/Sjg9oNVg1VdVV9tN6/idECTbZCHHpJIIzS5Uh6pc03hCr8RiFjo7aD5hzkpg59gCyAOA18jnSemtgcrOEFqIpQAvp2eD07Ybqil2upY6Z23Q= 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=YVLHBkJy; arc=none smtp.client-ip=209.85.210.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YVLHBkJy" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-7141e20e31cso3864925b3a.3 for ; Mon, 26 Aug 2024 10:37:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724693825; x=1725298625; 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=TB0zrUSpV1vUkdhES+59KLen130rqZtxea8oLCFrVKE=; b=YVLHBkJy7jrvNzkr3CDTNdmzBz+5m8ZaQTdolIcySgrfXjOzW/NZQPZz1N/1sOla5Y zmZ3XSdoEdRFmg/Jej/U54Xfaj1HQJ/EkbRqSyyW2ry+HHjr+MYxl3K/jgeaV2Y/xy5R +8tf9r9CRR8de9KqvozrXD0qlAIlvygPRruNHMe4ucsmqb8kADTJecJgcq7iPXN+Vkll p2WhdqNOwHJz5ybeN+ZPeC3JAcUWqbfFaUVAVO4Pdsx3U2WJMGjxxOg62rfoxW0gaBj5 q5SHoxHlnQjCWql/OA1PH7dF1AxGUeGdmdcxl2lHmajmAio6NA8MWInvkp8nCIt+xg1Z tuyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724693825; x=1725298625; 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=TB0zrUSpV1vUkdhES+59KLen130rqZtxea8oLCFrVKE=; b=KJozBKW37g4brHzDkpgyPW9/wCRKNxjOPLwcwEIBeLbXbfybyncICF//M9CD/7YxqX P2H0xOIi6mhA07a4oLtIks5ZVuA/m5YwozXY4/G79UUsP1stPt6UO9BEwDsiL9FPCrvn DbCwRXDOJp7UmnY2/cbS4Sd3TafS+61BAuJWhFzumeIBYrIDCy4jX2ETExKtiXGHKAWj yHeJBuONqGY4toAynYUBCfcOR/9Hk+bC3E378EPpIOmEzlSUl0g6p1tGQ4toxFqC/yvk XvDYGiI9yH/p5YVYTysKMkvVwz35FkquOeuxe1gP5drbSsh4RftmC2hqLcysPN291Tfb A0Ng== X-Gm-Message-State: AOJu0YzoBd78njXbDBXRDYpOjrCztfB404jf5LnpWSsa+902atAc+bSL ShL5FQd6rWjn4kUyLsxqLf9ZYNKVjCNPWIPh0AHKRqvHO4lhLMBLusG8BeUL X-Google-Smtp-Source: AGHT+IESx9NPzwatFUT8kUJ+cjq7eos7wgJxWkftoYGsTqqSRKG8fgm8S6uOd0s0YUNx+7TJUAkkDQ== X-Received: by 2002:a05:6a00:1acf:b0:70b:2233:f43b with SMTP id d2e1a72fcca58-715bffff2a7mr410998b3a.13.1724693824515; Mon, 26 Aug 2024 10:37:04 -0700 (PDT) Received: from Ubuntu.. ([106.216.108.198]) by smtp.googlemail.com with ESMTPSA id 41be03b00d2f7-7cd9acdd9casm7997999a12.53.2024.08.26.10.37.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 10:37:04 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 1/6] t: move reftable/stack_test.c to the unit testing framework Date: Mon, 26 Aug 2024 22:59:41 +0530 Message-ID: <20240826173627.4525-2-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240826173627.4525-1-chandrapratap3519@gmail.com> References: <20240823120514.11070-1-chandrapratap3519@gmail.com> <20240826173627.4525-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 --- Makefile | 2 +- reftable/reftable-tests.h | 1 - t/helper/test-reftable.c | 1 - .../unit-tests/t-reftable-stack.c | 374 +++++++++--------- 4 files changed, 187 insertions(+), 191 deletions(-) rename reftable/stack_test.c => t/unit-tests/t-reftable-stack.c (77%) diff --git a/Makefile b/Makefile index a87e18b317..a63b3d8381 100644 --- a/Makefile +++ b/Makefile @@ -1344,6 +1344,7 @@ UNIT_TEST_PROGRAMS += t-reftable-basics UNIT_TEST_PROGRAMS += t-reftable-merged UNIT_TEST_PROGRAMS += t-reftable-pq 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 @@ -2685,7 +2686,6 @@ REFTABLE_OBJS += reftable/writer.o REFTABLE_TEST_OBJS += reftable/block_test.o REFTABLE_TEST_OBJS += reftable/dump.o REFTABLE_TEST_OBJS += reftable/readwrite_test.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 4b666810af..2ed2aa7a86 100644 --- a/reftable/reftable-tests.h +++ b/reftable/reftable-tests.h @@ -13,7 +13,6 @@ int basics_test_main(int argc, const char **argv); int block_test_main(int argc, const char **argv); int record_test_main(int argc, const char **argv); int readwrite_test_main(int argc, const char **argv); -int stack_test_main(int argc, const char **argv); int reftable_dump_main(int argc, char *const *argv); #endif diff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c index 623cf3f0f5..8a817ca9d9 100644 --- a/t/helper/test-reftable.c +++ b/t/helper/test-reftable.c @@ -7,7 +7,6 @@ int cmd__reftable(int argc, const char **argv) /* test from simple to complex. */ block_test_main(argc, argv); readwrite_test_main(argc, argv); - stack_test_main(argc, argv); return 0; } diff --git a/reftable/stack_test.c b/t/unit-tests/t-reftable-stack.c similarity index 77% rename from reftable/stack_test.c rename to t/unit-tests/t-reftable-stack.c index 8c36590ff0..cae86b4b91 100644 --- a/reftable/stack_test.c +++ b/t/unit-tests/t-reftable-stack.c @@ -6,21 +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 "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; @@ -72,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); @@ -86,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); @@ -130,7 +127,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; @@ -150,7 +147,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; @@ -169,29 +166,29 @@ 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); printf("testing print functionality:\n"); err = reftable_stack_print_directory(dir, GIT_SHA1_FORMAT_ID); - EXPECT_ERR(err); + check(!err); err = reftable_stack_print_directory(dir, GIT_SHA256_FORMAT_ID); - EXPECT(err == REFTABLE_FORMAT_ERROR); + check_int(err, ==, REFTABLE_FORMAT_ERROR); #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); @@ -199,8 +196,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 @@ -212,7 +209,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; @@ -238,28 +235,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 }; @@ -276,32 +273,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}; @@ -310,7 +307,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 = { @@ -331,13 +328,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); @@ -347,16 +344,16 @@ static void test_reftable_stack_transaction_api_performs_auto_compaction(void) * all tables in the stack. */ if (i != n) - EXPECT(st->merged->stack_len == i + 1); + check_int(st->merged->stack_len, ==, i + 1); else - EXPECT(st->merged->stack_len == 1); + check_int(st->merged->stack_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", @@ -371,13 +368,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->stack_len == 1); - EXPECT(st->stats.attempts == 0); - EXPECT(st->stats.failures == 0); + check(!err); + check_int(st->merged->stack_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. @@ -389,10 +386,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->stack_len == 2); - EXPECT(st->stats.attempts == 1); - EXPECT(st->stats.failures == 1); + check(!err); + check_int(st->merged->stack_len, ==, 2); + check_int(st->stats.attempts, ==, 1); + check_int(st->stats.failures, ==, 1); reftable_stack_destroy(st); strbuf_release(&table_path); @@ -404,7 +401,7 @@ static int write_error(struct reftable_writer *wr, 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 }; @@ -424,18 +421,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 }; @@ -443,17 +440,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; @@ -471,7 +468,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]; @@ -490,7 +487,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++) { @@ -499,18 +496,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); } @@ -518,8 +515,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); } @@ -528,8 +525,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); @@ -537,8 +534,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 @@ -553,7 +550,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 = { @@ -581,27 +578,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); @@ -609,7 +606,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__); @@ -623,7 +620,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++) { @@ -647,7 +644,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++) { @@ -656,25 +653,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); @@ -687,7 +684,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 }; @@ -707,47 +704,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 }; @@ -762,7 +759,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]; @@ -782,30 +779,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); @@ -822,7 +819,7 @@ static int write_nothing(struct reftable_writer *wr, void *arg) 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; @@ -831,13 +828,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); @@ -853,7 +850,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, @@ -864,7 +861,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]; @@ -877,21 +874,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->stack_len < 2 * fastlog2(i)); + check(!err); + check(i < 3 || st->merged->stack_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, @@ -902,10 +899,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->stack_len == 5); + check_int(st->merged->stack_len, ==, 5); /* * Given that all tables we have written should be roughly the same @@ -923,16 +920,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->stack_len == 4); + check(!err); + check_int(st->stats.failures, ==, 0); + check_int(st->merged->stack_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; @@ -941,7 +938,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 = { @@ -962,7 +959,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 @@ -970,9 +967,9 @@ static void test_reftable_stack_add_performs_auto_compaction(void) * all tables in the stack. */ if (i != n) - EXPECT(st->merged->stack_len == i + 1); + check_int(st->merged->stack_len, ==, i + 1); else - EXPECT(st->merged->stack_len == 1); + check_int(st->merged->stack_len, ==, 1); } reftable_stack_destroy(st); @@ -980,7 +977,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, @@ -991,10 +988,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->stack_len == 3); + check_int(st->merged->stack_len, ==, 3); /* Lock one of the tables that we're about to compact. */ strbuf_reset(&buf); @@ -1006,16 +1003,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->stack_len == 3); + check_int(err, ==, REFTABLE_LOCK_ERROR); + check_int(st->stats.failures, ==, 1); + check_int(st->merged->stack_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; @@ -1023,19 +1020,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); } @@ -1050,7 +1047,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; @@ -1058,24 +1055,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); @@ -1084,29 +1081,30 @@ static void test_reftable_stack_compaction_concurrent_clean(void) clear_dir(dir); } -int stack_test_main(int argc, const char *argv[]) +int cmd_main(int argc, const char *argv[]) { - 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_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_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 Mon Aug 26 17:29: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: 13778292 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6637A198E69 for ; Mon, 26 Aug 2024 17:37:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724693830; cv=none; b=ggw+fb/HeM/jLdDvMneSU+hexGg05xfw+qcsXhBEkCfbB5PdRBiNqC/h6hbn9YB1Zetl0gon99w6Lw/Chw2AL9BN/yKcskjaSuvqR9w1/cVMMiKN5RIrkeo6EcMeIPTLPiTThtc3J62jvMEDdzNtTzau7jxmZDCzccFOa5PgNDU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724693830; c=relaxed/simple; bh=8ETfd9mM8eOu6HG919Nb9nNFYqnjS6+94QLqvRb/CRY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F8dRLaDVT7np1s5w4wTNRGI09GQaCBJ9pdDoIlARCOwFoPy+605GDnO+wzlqVwCVoE9/90UAb4lz9Hxipt2S5X5UQt1g80Lm/MY8Zaiq4PDlpK9rtD/FdMVv0bZZVEXMWpK0wf376gLru4AmHrfUAQiiR2GfZFVvd2ew4GR/LSs= 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=gGvwBQYj; arc=none smtp.client-ip=209.85.210.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gGvwBQYj" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-7142e002aceso3721855b3a.2 for ; Mon, 26 Aug 2024 10:37:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724693827; x=1725298627; 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=Md9gPusq+spw4nb0UpGXgWfeXZxTIjgqilP+tZyNq8k=; b=gGvwBQYj2fOEpCGBFNP7q2e+glpx4KJfDbvXRiqkcNNStr5vqCNXLYvw3iAMjvVGu7 Sr/WT8coWZ4bQfnfqWWXUNx/3aPScrZJQNqeYHxcNY8qeerADlPZRQ9e1QnMzqQSzE0J R/RBqnGYfSHbKQC4jgNtdtMuiUYB5d3p5r2BPpUHAi8oQTh1CcdHWwvDmvoc2IBeV7cW CxIsdiCeyT9jCGK8oueyh8pblQvsxfnx6EreR7pnUxKvLy8+U0rg/duFkHTMFYjawy0b CrzhgYHRX0dge5Jvt7cWuhW2SMRnR4ZFTNdm5SC6CzaeXbzZ9bmNhaIcBbt9By/ymDib ZZ4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724693827; x=1725298627; 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=Md9gPusq+spw4nb0UpGXgWfeXZxTIjgqilP+tZyNq8k=; b=WSE8+TvAt/DOlFGdkpceWs219ZeyKoSPaPozgXOefKskyd2ajODAa043lQp5MDpKt/ kXvg5LlaCBSkk0q7tduXVCRHs/ZewxDqLhhcyBCZzJt9O6VLvnLY1l/4Woc0HUSXl6SR +KAyM/YCWNc51PTwn9dskBtqf2ZN32TEUaFF2FZhwV4+XH+Yv/rcsen/F3X9A/jaK9nD 7qsUKC+mTCSNUWjPpexyQqL6PNHBgzNbpKzAF1v/Pe9UblZqyHzi5krxb447V/j5c7aH vBHGg/OTbm47H3KRXj1vKzr3P1bwA4WHNPpVGP4bnuWfw+BuC1PAcJHw7t9jCkxasaHL K6lw== X-Gm-Message-State: AOJu0YynmZpeSb+Y0GqVYkEgm4XVHzhDC7X73hpB/2irNDePRwooHpOQ 71DJn37QcRedEWoqHVdbd8PvX/R0UXJPNpHQNOiLxwLe5h+PuI58x04j6E2r X-Google-Smtp-Source: AGHT+IH0CaOHWttnm3RhRMf7BjJE1bWFNHMd2EJmzTKTKQaZazqdkcZJcYqTjSmGlHQ1pcE75DGBHQ== X-Received: by 2002:a05:6a00:8d0:b0:70e:a42e:3417 with SMTP id d2e1a72fcca58-715bffc4582mr447698b3a.10.1724693827181; Mon, 26 Aug 2024 10:37:07 -0700 (PDT) Received: from Ubuntu.. ([106.216.108.198]) by smtp.googlemail.com with ESMTPSA id 41be03b00d2f7-7cd9acdd9casm7997999a12.53.2024.08.26.10.37.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 10:37:06 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 2/6] t: harmonize t-reftable-stack.c with coding guidelines Date: Mon, 26 Aug 2024 22:59:42 +0530 Message-ID: <20240826173627.4525-3-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240826173627.4525-1-chandrapratap3519@gmail.com> References: <20240823120514.11070-1-chandrapratap3519@gmail.com> <20240826173627.4525-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 | 114 +++++++++++++++----------------- 1 file changed, 54 insertions(+), 60 deletions(-) diff --git a/t/unit-tests/t-reftable-stack.c b/t/unit-tests/t-reftable-stack.c index cae86b4b91..3ae7478fbf 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); } @@ -122,7 +120,7 @@ static void write_n_ref_tables(struct reftable_stack *st, .value_type = REFTABLE_REF_VAL1, }; - 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); @@ -163,12 +161,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); @@ -240,16 +238,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); @@ -270,7 +268,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); @@ -280,7 +278,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); @@ -304,12 +302,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, @@ -317,7 +316,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; /* @@ -330,7 +329,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); @@ -361,7 +360,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__); @@ -423,10 +422,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); @@ -442,7 +441,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); } @@ -452,7 +451,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, @@ -461,18 +459,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; @@ -486,7 +484,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); } @@ -495,7 +493,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); } @@ -503,7 +501,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); @@ -513,7 +511,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, @@ -581,11 +579,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); @@ -594,7 +592,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); @@ -608,16 +606,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); @@ -643,7 +640,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); } @@ -652,7 +649,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); } @@ -701,12 +698,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. */ @@ -749,21 +746,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; @@ -778,7 +774,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); } @@ -806,9 +802,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); } @@ -830,7 +825,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); @@ -857,8 +852,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); @@ -871,9 +866,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); @@ -935,7 +930,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); @@ -955,10 +951,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); /* @@ -1039,10 +1035,8 @@ static void t_reftable_stack_compaction_concurrent(void) static void unclean_stack_close(struct reftable_stack *st) { /* break abstraction boundary to simulate unclean shutdown. */ - int i = 0; - for (; i < st->readers_len; i++) { + for (size_t i = 0; i < st->readers_len; i++) reftable_reader_free(st->readers[i]); - } st->readers_len = 0; FREE_AND_NULL(st->readers); } From patchwork Mon Aug 26 17:29: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: 13778293 Received: from mail-oa1-f45.google.com (mail-oa1-f45.google.com [209.85.160.45]) (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 060151990AF for ; Mon, 26 Aug 2024 17:37:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724693832; cv=none; b=qIrYNv2ntkmPdqc5I6Esom/P/4lX0sZg4749CuZKu5sZq14LjsMRONaAyRUahJaR31vGNKi70po9muXH2xJE78+pEvDG4rsdqCZjqYQbgUDlav4bjsF6FAnDDb2dntdHMkqrnYRzzCjyDTQfd6zlkqpLBoKNaJK/Vr/Qcu5DaVc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724693832; c=relaxed/simple; bh=DSl7hekdMnDoAjHiqUYtbINHq85mKyh0e02cyFZrG4A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ABbF50MF+ag8vDsCd8CetgyG9zFnTAqQSiJrmXRkO6nqahVCfkEadK3dGP6QFvZSMDgqA3Ord9312gWJAUv1xouZTLGgNui3/AYU7PutQJLY18QlQ9s7QLWPS1rHKFeYQMHTEO+9o6BNiGTla9jzZTz7Qm5EExkDfo6x5RTRZ58= 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=C/OeyDSA; arc=none smtp.client-ip=209.85.160.45 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="C/OeyDSA" Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-2705dd4ba64so3195345fac.3 for ; Mon, 26 Aug 2024 10:37:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724693830; x=1725298630; 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=A1i/3k0KHYI1ce0MUl5K+nAbVW+OuadxhAW6a07t+jU=; b=C/OeyDSAjqKwP00fxYurV2T0KBZSNJ6O+fajid7jx8gV4AG1/TfItTOkpwaAmKf8Ro o0U3p4D5KFnX3rbDDzyx97SG1tM/Ns/ak96jzb58msSgzz3eeZyQO9BFLwYy8B2VB79n eVDP6JXEE9cmyFPVRB8kBl7OdASjy2r80BIkoEOQI2eJB/gtD/9TsU49tIqRXRzJG+zF Cfwem0ySZvdRf19A/6OImfvAcj2bvI3yHVzM9Zrponydjhi8jZFn093kt8fG3n60/R14 dsfSRrroqEFai3HXfdTHucHlH5yB/T1eIJMhlG2oWjJfOpHHzow3X8+QiE4rO8Xf9YPf HaAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724693830; x=1725298630; 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=A1i/3k0KHYI1ce0MUl5K+nAbVW+OuadxhAW6a07t+jU=; b=UK86bkIJVMY16y0043h+jxSFv8bJVite6Fa79URmjFW9ZAiIzkitSfukOxC+wSM5lG fYzH1J84p6U69cpK/XHvwudTJe6mCa51AbaJUtYE664pWkr7SYM3SaU5nDmhGTC9CIOT +FF6X0bgmPtREjnamC+LlBWYELinadReDAHl1PBzo4VyRY2rwGG353G7jsDtE4Kk+gM8 Kp2i/ZDmzuCTxXbABMQz3hy/h3XL2GGGBKk8yiLUB+EVzcSY8Cbp98ZxPjrszDE3TTgC 046Z3Ve9xzNrqcfBJ7Bz5gLlgSx50qm6f2sojZvqS+a6onf1ytDjft6U66/eOf5KjfBY qVPg== X-Gm-Message-State: AOJu0YyudzyXTAPd56NefuZKVCz8nIFIiiCA0waUojR1CiWrHXdoaidt DBIX6uWOznsmI6ke1wbd+NYCV7cQmBVSQfb79EQ1NzkUP/TFJCMCF2/eEY80 X-Google-Smtp-Source: AGHT+IGimoJvDytFA2xKhkwrhQA0/zvqjeSqd4Wny74n8BIBwlv4aYfG6QIXc1eXw3/JYxMgwNyAog== X-Received: by 2002:a05:6871:286:b0:260:fd20:a880 with SMTP id 586e51a60fabf-273e674bcc8mr11232830fac.42.1724693829712; Mon, 26 Aug 2024 10:37:09 -0700 (PDT) Received: from Ubuntu.. ([106.216.108.198]) by smtp.googlemail.com with ESMTPSA id 41be03b00d2f7-7cd9acdd9casm7997999a12.53.2024.08.26.10.37.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 10:37:09 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 3/6] t-reftable-stack: use Git's tempfile API instead of mkstemp() Date: Mon, 26 Aug 2024 22:59:43 +0530 Message-ID: <20240826173627.4525-4-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240826173627.4525-1-chandrapratap3519@gmail.com> References: <20240823120514.11070-1-chandrapratap3519@gmail.com> <20240826173627.4525-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 3ae7478fbf..5cb79ad8fd 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 Mon Aug 26 17:29: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: 13778294 Received: from mail-il1-f169.google.com (mail-il1-f169.google.com [209.85.166.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 9651D1990CD for ; Mon, 26 Aug 2024 17:37:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724693835; cv=none; b=iT+M2BZoJySM5ZsH/Y8F8mZ7FrXHU4AeqiMEfo5jc3GpK3jc6r29fsgoRg+UMqESuY9FT3q/97ATnLhN6KqSH0SIXm5vbskaiSCt35jrV9H+pGDhHQVnAybA8VY/gLSJZYqqbsZkNO8JIC3yo3xitkjCigBG0ZD2dg+SXvvqeh0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724693835; c=relaxed/simple; bh=sJ0VRYRsLodHWSLlqAz+pI4KocJX3VDyz8I3NvYooBo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JD8BYmq9hrB1DJiuD0Vn6zVHWzcDSogRWrBp+E9WbDuSZrhLx0n6dgz459tF9uhwD5WBEBu3qXXjjVMTXNr0Rl5Kg9Jy9ZjRCyxjBrzOD93g+AqRIkUX53VCH6F3ASiMZcFCtgvNcTbp42PBdrGwTr3GgwcnWKYCimh9L7EBh7c= 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=aZTh9yEC; arc=none smtp.client-ip=209.85.166.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="aZTh9yEC" Received: by mail-il1-f169.google.com with SMTP id e9e14a558f8ab-39d34be8ca2so15261955ab.3 for ; Mon, 26 Aug 2024 10:37:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724693832; x=1725298632; 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=Ay0rvFNOxyfWnPotrmwILeHZOojUSwYE49paGRiLrm8=; b=aZTh9yECUNqifw8rfSi63fzmWnfwmwt4tNGfo85/UGhnuri9avXNzYTqH2IMmBm5ge AK6WLLEKx1ourGQYbO8Fxe8Mrj3eqDBF7P98MZGbxt227KelPE+AkIfwSIqx2NomKs28 hqL3xAFxoOOW2/JwUtlVwwsqnt4UIdwvExL6UXLWGXAR4m4lGUGBSLnduqFMBz6dsayg 8FUkvyBYPljuDbEAFRsuJnaCzZoZRtZxPtpaSFC2w0SxdDF3hHS67xUEXp5ifoVUP891 ogcVR/bTfL0I2KCHoE4wsem2guG68fD+6neMY6wKQ6Z3GOPfpO/ArzkqGEp6gxi/F8DF unGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724693832; x=1725298632; 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=Ay0rvFNOxyfWnPotrmwILeHZOojUSwYE49paGRiLrm8=; b=oAfwLqzaOgtm2mrX18REGw+bzHn/Y1wpbymf0yQXirBgn3BYy9bRja/5bPMbMkHrPm SG5KgBF1kSR7imv0lB8N6XDzXwp4Qv+RecGjBq5DXiau3edf4qWNlQf8DAqxID9g2HPZ iTwkqdIjGX8fULNtIPbQJLYvbwux1hYFYwsVfHb6NfAonzc46mvkLwOsHTPoELD/lHQg SIBRb8ZjJJFNxpT7Yg9v3PnA+ZQTosMpzFxI5ghhsIEur0Kf+a06rJi+zUh0uBe+5RBY 14wDSdLj86mGo8QzC2Pn62zNNF5+hMwvyupje/AwTlBFeToQLjPLAShFbzJW/XkR1SFC 0Y+w== X-Gm-Message-State: AOJu0Yx3AFROYHdICEA2FHle3Y6WRQYGwqqb6iuVkmOQllvwsqK9xSKf 8xXV9ca5XfLkceB5YJaUGFdY9tHqcTqvimRVROsxG6KcpaASqpMCADpcakam X-Google-Smtp-Source: AGHT+IEVXyE+1HnopvxvTwghmI6nNZmhj3aH4I9QH6sfdyAz3sKNBHUizvb/mhPCIF50hLqDCI1xJQ== X-Received: by 2002:a05:6e02:b2c:b0:397:2dcd:80e5 with SMTP id e9e14a558f8ab-39e3c9ee72cmr100840065ab.27.1724693832308; Mon, 26 Aug 2024 10:37:12 -0700 (PDT) Received: from Ubuntu.. ([106.216.108.198]) by smtp.googlemail.com with ESMTPSA id 41be03b00d2f7-7cd9acdd9casm7997999a12.53.2024.08.26.10.37.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 10:37:11 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 4/6] t-reftable-stack: use reftable_ref_record_equal() to compare ref records Date: Mon, 26 Aug 2024 22:59:44 +0530 Message-ID: <20240826173627.4525-5-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240826173627.4525-1-chandrapratap3519@gmail.com> References: <20240823120514.11070-1-chandrapratap3519@gmail.com> <20240826173627.4525-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 5cb79ad8fd..4c694329e8 100644 --- a/t/unit-tests/t-reftable-stack.c +++ b/t/unit-tests/t-reftable-stack.c @@ -173,7 +173,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); printf("testing print functionality:\n"); @@ -291,7 +291,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 Mon Aug 26 17:29: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: 13778295 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8D901991CD for ; Mon, 26 Aug 2024 17:37:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724693837; cv=none; b=bOhvurEgHwkLFYv/JZCuid1m0qRg8aTu/PffL5Pf+e+owWg7b+OtIR0fb5F0qoGKuin4wdAAFM7JmBNdMltBYzu5Gqu7j9eXkNezn1xJs7t9GLBu03wkKcjMZ7CzfFyRx9rq/UmsgGiUrv1eQZ6mHtSc3JpfA0TISq2oXPN7g5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724693837; c=relaxed/simple; bh=arSn3QATBz3eY0o8IS2dA7wBiqRTfVzXe4siGWshL88=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Sntal9j2AJ2CPcQ5tTvvxjWpg6oYdbevYZDWgXCIDfE+StDrISZ4srX+U4hMhLQn5Y8p0RnlxHsblJEXNsQIxkS0JsXWEaa6t/IbUQaDt0mbIiaktk5DtW65+1SVY27smowe05iXbveEdxB46e0Eq3qtIizNIuI8yzP84GWBUC0= 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=IN8O4jFE; arc=none smtp.client-ip=209.85.210.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IN8O4jFE" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-714262f1bb4so3291360b3a.3 for ; Mon, 26 Aug 2024 10:37:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724693835; x=1725298635; 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=7rjbKDHhyqTyeDZiqbcbkK2OhtNmaAgd080tOfwqLi4=; b=IN8O4jFEMKAF1piXicHX5M15CaDpVqmj5T/uOotrozL2t4m0JPUXrQi93iN8PaGVFW 0jApOG+bVdG4thX8P4cJI6DpnfNM5eYqgJUUld5qvbxatgFPvzA2EDBwc6PJnUYPr6+p C2IdBEpVF/aIP17a+vgONGaHkBUzhkqprVAM2VJACmDME8Q7LzVUIkVgRieHZlUi7TK9 cAwLVhN8heXNfWY1GLcibsyCLUGtmaTN0gviOVEzbYfXSrEYDQoqMQyi/nAKdJbZ8iuH 3x0lKL571avh0ddMb3w0VRyetSXjCUcc5Pnaf8FokFyCbTer3VkbwG8DCtF7oZmVG8Nf Z0OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724693835; x=1725298635; 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=7rjbKDHhyqTyeDZiqbcbkK2OhtNmaAgd080tOfwqLi4=; b=q6LvkkbFWessvVpkCvWg4RZDfDAoerQtp9paIiQce5jX8cB8JJGhJAJEcNVxIdHWVy vTTXi3aJcNlbvSTwY3/4snLirU1EHdWks7E3yw7qd7PVZUS5SlFQ1u3G9/bKcOZDodzR 6AQDGJo/mT92nC88B6wUBPeoww/CWxOSXSzy6VqY8wL/K60+YnkbHNT68XaC8ZWJVbx8 nGSYJrGJT4hBjsuu7xuGHeI87h4/6uf7JIr0LsXQv1pgjXeC11/sFe6lbWG8eqDByHbp avYmY6NOLN3LNSkp1DcCJVrJnuNiGtmmlsp2M1N6Z+pSyzj4OLaLyAQNqqmnaBApeFlq Rv2w== X-Gm-Message-State: AOJu0YwAe/Vpr/5B67NNRkkvSbIIyHZwD1fbCgSL97hKRGr4ReUJfyKZ 4unasRlV3xnKzRUrhrGceMrrDCDkOB2odGGLihOrI1/PS6NXX83E22xW777T X-Google-Smtp-Source: AGHT+IGcMdwDmy6R5QG9B4QbqJRwt1dUvW61q3p98qnbvIFVFbD5YN4NG/1BsJjJfkdlmaX00ROpSQ== X-Received: by 2002:a05:6a00:66d1:b0:714:186a:ae0b with SMTP id d2e1a72fcca58-71445e77f21mr10192990b3a.24.1724693834856; Mon, 26 Aug 2024 10:37:14 -0700 (PDT) Received: from Ubuntu.. ([106.216.108.198]) by smtp.googlemail.com with ESMTPSA id 41be03b00d2f7-7cd9acdd9casm7997999a12.53.2024.08.26.10.37.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 10:37:14 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 5/6] t-reftable-stack: add test for non-default compaction factor Date: Mon, 26 Aug 2024 22:59:45 +0530 Message-ID: <20240826173627.4525-6-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240826173627.4525-1-chandrapratap3519@gmail.com> References: <20240823120514.11070-1-chandrapratap3519@gmail.com> <20240826173627.4525-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 4c694329e8..e8c137529e 100644 --- a/t/unit-tests/t-reftable-stack.c +++ b/t/unit-tests/t-reftable-stack.c @@ -837,12 +837,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; } @@ -875,11 +875,43 @@ static void t_reftable_stack_auto_compaction(void) err = reftable_stack_auto_compact(st); check(!err); - check(i < 3 || st->merged->stack_len < 2 * fastlog2(i)); + check(i < 2 || st->merged->stack_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->stack_len < 5 * fastlogN(i, 5)); + } reftable_stack_destroy(st); clear_dir(dir); @@ -1086,6 +1118,7 @@ int cmd_main(int argc, const char *argv[]) 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 Mon Aug 26 17:29:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13778296 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC312198E78 for ; Mon, 26 Aug 2024 17:37:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724693840; cv=none; b=ZFzj8rVp+inOvMx+Klf/5Nua+QvY1MYdCMT0Ri+nXn/yotNX/zt+q7/I7/TIdUDAXiiFuhKu8a4QPcETOSIUh0W49oXVKhbe4OD9NyFXE09f/vXWgukaBGcFlrH7dylIaEk33jx7+q0h5VBfJERg3iHW+RTNMmqiDS+Cmlfz6gM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724693840; c=relaxed/simple; bh=+A81j1hXTU3M5zWvaAx8OX09ByLcsinJL5ksIhevRUY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fbdp5qenVtzUGy59VmufGsTcNIjPIalzCmDgDHPabLWwkbrVM8NDlMD73Yt1nDhJHcJIR/F7+EXOz01HTfj3pXbxGmSSooYyHXCro2jNSAqUfeZRlhCTBluwgcQBlmBHzA120EdM1l8Z+5L9I4o1E6lQcqM3yLeon9C8/fBKn6A= 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=SkS3uB2W; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SkS3uB2W" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-71446fefddfso2373552b3a.0 for ; Mon, 26 Aug 2024 10:37:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724693838; x=1725298638; 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=yPFBB2CsyDpZri3yDeIYmswVsiCiviDjXrSdcq8r22M=; b=SkS3uB2W1EX5TSNQZC1WJX1eEkVnJclEKPkdL6+b7I09HEWFzJE9Rnxz0qePZ+OVD8 JX2F/StM/XnXPJWomQm1TI7Iu/6GPbCaCmipBhnQmmyYaReBu/77CEmsBKui/f44tcE6 ZWS1HTn5e7W79HOP15mfKqDrRt9/cowzHpZyG5mYVOd47ry41yahlJElAiDhRuvrTruS AEHoajl78jd3ok+Cz/ENkuo26fRdrYB25DQAZbEQJpvzZVxX7hOIM0YdvlZIrmfdeHm3 bmfAkSafH6xoQVNX0vAK4IURyjhjPZ9O8MwSPYOiymf74wXmJBKn7PkLd8TIZn/M9W4T Osag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724693838; x=1725298638; 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=yPFBB2CsyDpZri3yDeIYmswVsiCiviDjXrSdcq8r22M=; b=tgHHwMjE9I+8L0DtsmrBk9hFEeS/C1Ldm96EbHneyPYSAN8H8r1gYBjANEG23t0IQM a9WT/NnezayfqHklj+Zv6Iy4cHr17w4Gz5NtxomYsLgrd6v/v9ny8SRGb7kXclbUKmOY TPAXAA7jI7IKclEdR93+DKbe2XiYqdItn3K9d4wMiGEHw4XUuB1oj9qEkRd9mS3uvq16 DcUoKmGUGs90UwQcpbpnHPRhVTxJBC/mkjrWkjfKpRtA4TojTBCk6WlAwBwCT1T4AH0K ZoniPuVomnm5LeO0VgfqVkSfhSRnQA6xVe+I5zzry/XXGRHYTaWl63AZlBp2hIbFXsqV hPFQ== X-Gm-Message-State: AOJu0YyA6WvExL8Kf6w8sEgkqKPrBSl5G8seE79GPE7al6TXVKID6JCA wIZdH84Fjv7JOTzHhBpJqn0eBVmLmfz4vqbXUmO8waKBB/HvFmaubqK94kzS X-Google-Smtp-Source: AGHT+IGSviC3fpjP22QiqCTT5t3b895mUh0S6WffXeF0CrHmLR62LiJVojqwvD5htyKxQ9gUckfrag== X-Received: by 2002:a05:6a21:386:b0:1c0:f315:ec7e with SMTP id adf61e73a8af0-1cc89dbac4fmr11270333637.28.1724693837448; Mon, 26 Aug 2024 10:37:17 -0700 (PDT) Received: from Ubuntu.. ([106.216.108.198]) by smtp.googlemail.com with ESMTPSA id 41be03b00d2f7-7cd9acdd9casm7997999a12.53.2024.08.26.10.37.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 10:37:17 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 6/6] t-reftable-stack: add test for stack iterators Date: Mon, 26 Aug 2024 22:59:46 +0530 Message-ID: <20240826173627.4525-7-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240826173627.4525-1-chandrapratap3519@gmail.com> References: <20240823120514.11070-1-chandrapratap3519@gmail.com> <20240826173627.4525-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 e8c137529e..112d954afd 100644 --- a/t/unit-tests/t-reftable-stack.c +++ b/t/unit-tests/t-reftable-stack.c @@ -550,6 +550,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; @@ -1125,6 +1204,7 @@ int cmd_main(int argc, const char *argv[]) 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_tombstone(), "'tombstone' refs in stack");