From patchwork Tue Aug 6 14:13:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13754957 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 47E6E18D64A for ; Tue, 6 Aug 2024 14:20:48 +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=1722954050; cv=none; b=L1qP7xA3VFQB/F8uOmSxnElT5YCcKFG6xdDZ0RY0alPOZdp0cZ7H4t5yivydpcgTir/etmRh6KSwd0nK8jfIB6Opu1nPpZnuf6eQ3QGIElL33QtUmR+D00g3MIgMgaFzsKkOQuVSn+w/pe3SM1pJ629IAZVwdVpN+OqifqMTr9c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722954050; c=relaxed/simple; bh=n7V9ieUfF+0a5Gqlz/Kzeg3qYnNy0R0mkSLK8TWeJho=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l3LO/E/votrnSuv+PzHokOoXgDzL5GvlIlIiqkJdrHfsNz0dlV84oMJPupnW1XQTm4hzeD7oB/NBUL+oAV//ptMx6tKfHTGA894I/L6oP8JUvFzEr00STmqOMaKJO5utByMKjTIi9tHiACD7F9n4ujvfKUpGHUD5xfoNYe8DIzQ= 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=achY4W6K; 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="achY4W6K" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-70eec5f2401so524969b3a.3 for ; Tue, 06 Aug 2024 07:20:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722954047; x=1723558847; 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=A1RfCfJA+Z3PV949vkgfL/6WT7ffNsER6FKvXR0gfMY=; b=achY4W6KElxaqafxypXIoV5cue+0kpX31/JIdhPm4TaTg7Gu8qfCClxu4KcDWeSF6u MAn9sMnnMMJxGrcE7CAm57M2Xs97taTH66h6ccSrt75ADCha38PNn2biRgMdCgYkOR9k OUWBn+FC4MKKZI1DtRONYtt+M4hELlUu+YlpYmC+Fa7xlCLLoEUlaPjfEhi7noDwTydC L7f6PP32OgaMyTvkOeVo+ZaDz3F8BrcvWkRRnJsioUj8JN7nNeodslP+/L3QipAnV3Un RJttUM9LoAC1x14i5zJHn/5a4y3fQKNDnlrnK2JBgvVf+bCHsDF3PTMPkkGI+OCDa6Vt 1Uzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722954047; x=1723558847; 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=A1RfCfJA+Z3PV949vkgfL/6WT7ffNsER6FKvXR0gfMY=; b=hmT1Oz9Cia09uDteZ5ISKL5wWe8voh5tYCbfFhIbZnvKVKEqYlI1xbOvEwRx8/AVw8 r3TPTaf5VyQCwqdPWWxM1ZZTBT3SfFpTJh7pqAvOtLig5q4TAeHh87qbOQBC8lKXzh/T kDLSoxaTlR2+sDFwvntlXp0DoX/JfjKC+pnqKek5nvF2MvK9RMMro6fYq+Vvy0kLwlwt vW9mLBKA6sys+rcMWMgrZGj3Q+5rXxXFcpBDqpnGLJvTxQIV9KolSPVV1vvsBpcMRgCe OpUUXNNoxvcZP5GWclT/ayU10H1K4e8sfDFBFTJUl8Q8oa4XSlIiWnWulN10ljsgPWMd El1w== X-Gm-Message-State: AOJu0YxR8ulwp8+cK/IDIa3N7esUrc/poWNh4b/s2Ply3JriT6d0CSiW oiEhdx4EHHqK+LQezm2IO0yOkMx4AoGxlpyZW7+qWFGPcn7mEHdH7AA+2i3xu2eclA== X-Google-Smtp-Source: AGHT+IG2tX3WdBVl1l3eNZCHzobIRkKfcZLTaPsvqM0kW4RNdoOzjRLo5nlRmuIQPLLV+4XSR4g62Q== X-Received: by 2002:a05:6a20:9189:b0:1c3:3436:a234 with SMTP id adf61e73a8af0-1c69959f1d2mr23215083637.12.1722954046636; Tue, 06 Aug 2024 07:20:46 -0700 (PDT) Received: from Ubuntu.. ([27.59.87.1]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7106ec416aasm7040563b3a.70.2024.08.06.07.20.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 07:20:45 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 1/6] t: move reftable/stack_test.c to the unit testing framework Date: Tue, 6 Aug 2024 19:43:37 +0530 Message-ID: <20240806142020.4615-2-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240806142020.4615-1-chandrapratap3519@gmail.com> References: <20240806142020.4615-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 | 350 +++++++++--------- 4 files changed, 175 insertions(+), 179 deletions(-) rename reftable/stack_test.c => t/unit-tests/t-reftable-stack.c (77%) diff --git a/Makefile b/Makefile index 3863e60b66..464a17e11a 100644 --- a/Makefile +++ b/Makefile @@ -1342,6 +1342,7 @@ UNIT_TEST_PROGRAMS += t-prio-queue UNIT_TEST_PROGRAMS += t-reftable-basics UNIT_TEST_PROGRAMS += t-reftable-merged UNIT_TEST_PROGRAMS += t-reftable-record +UNIT_TEST_PROGRAMS += t-reftable-stack UNIT_TEST_PROGRAMS += t-strbuf UNIT_TEST_PROGRAMS += t-strcmp-offset UNIT_TEST_PROGRAMS += t-strvec @@ -2683,7 +2684,6 @@ REFTABLE_TEST_OBJS += reftable/block_test.o REFTABLE_TEST_OBJS += reftable/dump.o REFTABLE_TEST_OBJS += reftable/pq_test.o REFTABLE_TEST_OBJS += reftable/readwrite_test.o -REFTABLE_TEST_OBJS += reftable/stack_test.o REFTABLE_TEST_OBJS += reftable/test_framework.o REFTABLE_TEST_OBJS += reftable/tree_test.o diff --git a/reftable/reftable-tests.h b/reftable/reftable-tests.h index d5e03dcc1b..28fe1be72e 100644 --- a/reftable/reftable-tests.h +++ b/reftable/reftable-tests.h @@ -14,7 +14,6 @@ int block_test_main(int argc, const char **argv); int pq_test_main(int argc, const char **argv); int record_test_main(int argc, const char **argv); int readwrite_test_main(int argc, const char **argv); -int stack_test_main(int argc, const char **argv); int tree_test_main(int argc, const char **argv); int reftable_dump_main(int argc, char *const *argv); diff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c index 9d378427da..f35db442ae 100644 --- a/t/helper/test-reftable.c +++ b/t/helper/test-reftable.c @@ -9,7 +9,6 @@ int cmd__reftable(int argc, const char **argv) tree_test_main(argc, argv); pq_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 e3c11e6a6e..c578659017 100644 --- a/reftable/stack_test.c +++ b/t/unit-tests/t-reftable-stack.c @@ -6,19 +6,11 @@ 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 clear_dir(const char *dirname) @@ -29,6 +21,11 @@ static void clear_dir(const char *dirname) strbuf_release(&path); } +static void set_test_hash(uint8_t *p, int i) +{ + memset(p, (uint8_t)i, hash_size(GIT_SHA1_FORMAT_ID)); +} + static int count_dir_entries(const char *dirname) { DIR *dir = opendir(dirname); @@ -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); @@ -122,7 +119,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; @@ -141,29 +138,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); @@ -171,8 +168,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 @@ -184,7 +181,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; @@ -210,28 +207,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 }; @@ -248,32 +245,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}; @@ -282,7 +279,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 = { @@ -303,13 +300,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); @@ -319,16 +316,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", @@ -343,13 +340,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. @@ -361,10 +358,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); @@ -376,7 +373,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 }; @@ -396,18 +393,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 }; @@ -415,17 +412,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; @@ -443,7 +440,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]; @@ -462,7 +459,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++) { @@ -471,18 +468,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); } @@ -490,8 +487,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); } @@ -500,8 +497,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); @@ -509,8 +506,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 @@ -525,7 +522,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 = { @@ -553,27 +550,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); @@ -581,7 +578,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__); @@ -595,7 +592,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++) { @@ -619,7 +616,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++) { @@ -628,25 +625,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); @@ -659,7 +656,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 }; @@ -679,47 +676,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 }; @@ -734,7 +731,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]; @@ -754,30 +751,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); @@ -794,7 +791,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; @@ -803,13 +800,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); @@ -825,7 +822,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, @@ -836,7 +833,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]; @@ -849,21 +846,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 < - (uint64_t)(N * fastlog2(N))); + 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_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; @@ -872,7 +869,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 = { @@ -893,7 +890,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 @@ -901,9 +898,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); @@ -911,7 +908,7 @@ static void test_reftable_stack_add_performs_auto_compaction(void) 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; @@ -920,7 +917,7 @@ static void test_reftable_stack_compaction_concurrent(void) int N = 3; err = reftable_new_stack(&st1, dir, &opts); - EXPECT_ERR(err); + check(!err); for (i = 0; i < N; i++) { char name[100]; @@ -933,19 +930,19 @@ static void test_reftable_stack_compaction_concurrent(void) snprintf(name, sizeof(name), "branch%04d", i); err = reftable_stack_add(st1, &write_test_ref, &ref); - EXPECT_ERR(err); + check(!err); } 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); } @@ -960,7 +957,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; @@ -969,7 +966,7 @@ static void test_reftable_stack_compaction_concurrent_clean(void) int N = 3; err = reftable_new_stack(&st1, dir, &opts); - EXPECT_ERR(err); + check(!err); for (i = 0; i < N; i++) { char name[100]; @@ -982,24 +979,24 @@ static void test_reftable_stack_compaction_concurrent_clean(void) snprintf(name, sizeof(name), "branch%04d", i); err = reftable_stack_add(st1, &write_test_ref, &ref); - EXPECT_ERR(err); + check(!err); } 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); @@ -1008,27 +1005,28 @@ 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_add_performs_auto_compaction); - RUN_TEST(test_reftable_stack_compaction_concurrent); - RUN_TEST(test_reftable_stack_compaction_concurrent_clean); - 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_compaction_concurrent(), "compaction with concurrent stack"); + TEST(t_reftable_stack_compaction_concurrent_clean(), "compaction with unclean stack shutdown"); + 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 Tue Aug 6 14:13:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13754958 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54CC918D659 for ; Tue, 6 Aug 2024 14:20:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722954053; cv=none; b=KXNmxD5MGmuFW+xE9Vip27Rprjzi7zIKI9UDEasBxzBjXBYqKcy3e8xcLZpuGL70jfzz1koNjZ1ZoaQZmHvrZdQFn9TpUxzX4MBGMV8fVhq9J0A0ERrEOLpcy3dBGBeoc29WQsrR3kENrWimZeodNx2HhFVYpZiZ9JLcY8vcYhQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722954053; c=relaxed/simple; bh=F5t5BXczl9RG3iElJ4AUo2xgQuwpnDXo41JVrdoX1r0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MKiueGcTUJseTA1QEF2Uf8kDtQ87h44lvlrlmeJLshSqgFSxxEsDOl/mnXTWRnm4ceweXmagq/gzLS/kdHbHFbcrEa1NFcK9dfFiLTHM6NzGjYU1wqOYeF/6iKqaTy0Z1IiI9ZqgTTGEh8rWWt0grcdG7DAkLM2pnd2JkC0iqmc= 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=GmwC/MLj; arc=none smtp.client-ip=209.85.210.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GmwC/MLj" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-70d19d768c2so480553b3a.3 for ; Tue, 06 Aug 2024 07:20:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722954050; x=1723558850; 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=4kWfABUEeGuz8pA0bE/5S3/sJ/eOIZlZnG5puvJ46rM=; b=GmwC/MLj/wLvjRqUV7ZrXys9ABxV4Ez7DAmMIp9saCZer2BJkDFz5Hx0YviwjVKgs/ 0sgQgGXsPaQObd6gwqwJYWsiQtbtps61t9J9Zlo3SxCIVSKzyFJ2ONOYUU9vAmscdiLT 5eb/Z2dDSnCacvYcGiJd9n7rl/31jOspWvxcjJK5C32Gw087VC44Z5YLWz0CCc/bfbno 9CtdyCzZrWyTtg1hzTBAcHl/X8+rT9Tl7IdGC55Z3jEjuL0P8Dc1QDO7BMflcdmbbUpQ eWuUAWzYf/NVOPC/kwr6b29z3Jv1PH87W1LlSoN5OjQ+QZ3RRzbomIG8UbfOeuGKLsLE DqAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722954050; x=1723558850; 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=4kWfABUEeGuz8pA0bE/5S3/sJ/eOIZlZnG5puvJ46rM=; b=cJIpRVMzHHwimkzqcpu2vVGePLQRQ2lpoxS1DG3WYDN/g5Cgh4LIV48Tf6pMkcJUTm eeTHZrWdHqS6M3ti4Z9bljeG1LXL/OBiPUUt5UjPKfU9DBtkaUBCWyWeBACUrkKk8/rr HwpAcJw5zcfQez/5ctMiN+JWfL4n2xRMcE/8Uyq1fXVVYtSwCm2wcwl78oJ087mdtoc+ xqOAEfrHAwCKqZA3n00BCl8G7QIiVxKtPkRNso0jx4wEHVnEXoVQqOXFdOq90ep3Dg0p 0Fc0Fx2w/wze3+OgrI7ZpfM3K2X3WCqaLV6A097joSIYJXLsXScmRjLp5/8nB5J/q6Hn Sb7w== X-Gm-Message-State: AOJu0YxeoZxY8bVLZuv9l0fbrLM1ZT9ixv1yta+zEf2dRXmpj3jr8FmB s1nM0IOOifGDifks7C2Wk4LQgKp7WJ03lEoKVNZfSj0PClS/Zwm9GHf3ZYAbxUlfyA== X-Google-Smtp-Source: AGHT+IG/1Lg4aO34zbv82NgtFlnro/meRFcfJUKSPhYNhabDfkyHULvMpEmDbbnnhd7KFY/y/qYn3A== X-Received: by 2002:a05:6a00:1744:b0:70d:2693:d208 with SMTP id d2e1a72fcca58-7106cfd19a6mr15796187b3a.15.1722954050106; Tue, 06 Aug 2024 07:20:50 -0700 (PDT) Received: from Ubuntu.. ([27.59.87.1]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7106ec416aasm7040563b3a.70.2024.08.06.07.20.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 07:20:49 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 2/6] t: harmonize t-reftable-stack.c with coding guidelines Date: Tue, 6 Aug 2024 19:43:38 +0530 Message-ID: <20240806142020.4615-3-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240806142020.4615-1-chandrapratap3519@gmail.com> References: <20240806142020.4615-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 | 128 +++++++++++++++----------------- 1 file changed, 61 insertions(+), 67 deletions(-) diff --git a/t/unit-tests/t-reftable-stack.c b/t/unit-tests/t-reftable-stack.c index c578659017..e033feb8ee 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); } @@ -135,12 +133,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); @@ -212,16 +210,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); @@ -242,7 +240,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); @@ -252,7 +250,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); @@ -276,7 +274,8 @@ 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 i, n = 20; + int err; err = reftable_new_stack(&st, dir, &opts); check(!err); @@ -289,7 +288,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; /* @@ -302,7 +301,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); @@ -395,10 +394,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); @@ -414,7 +413,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); } @@ -424,8 +423,7 @@ static void t_reftable_stack_lock_failure(void) static void t_reftable_stack_add(void) { - int i = 0; - int err = 0; + int err; struct reftable_write_options opts = { .exact_log_message = 1, .default_permissions = 0660, @@ -433,18 +431,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 N = ARRAY_SIZE(refs), i; 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; @@ -458,7 +456,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); } @@ -467,7 +465,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); } @@ -475,7 +473,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); @@ -485,7 +483,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, @@ -524,7 +522,7 @@ static void t_reftable_stack_add(void) static void t_reftable_stack_log_normalize(void) { - int err = 0; + int err; struct reftable_write_options opts = { 0, }; @@ -553,11 +551,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); @@ -566,7 +564,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); @@ -580,16 +578,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 N = ARRAY_SIZE(refs), i; + struct reftable_ref_record dest = { 0 }; + struct reftable_log_record log_dest = { 0 }; err = reftable_new_stack(&st, dir, &opts); check(!err); @@ -615,7 +612,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); } @@ -624,7 +621,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); } @@ -673,12 +670,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. */ @@ -721,21 +718,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 N = ARRAY_SIZE(logs) - 1, i; 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; @@ -750,7 +746,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); } @@ -778,9 +774,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); } @@ -802,7 +797,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); @@ -829,8 +824,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 N = 100, i; err = reftable_new_stack(&st, dir, &opts); check(!err); @@ -843,9 +838,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); @@ -866,7 +861,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); @@ -886,10 +882,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); /* @@ -913,8 +909,8 @@ static void t_reftable_stack_compaction_concurrent(void) struct reftable_write_options opts = { 0 }; struct reftable_stack *st1 = NULL, *st2 = NULL; char *dir = get_tmp_dir(__LINE__); - int err, i; - int N = 3; + int err; + size_t N = 3, i; err = reftable_new_stack(&st1, dir, &opts); check(!err); @@ -927,9 +923,9 @@ static void t_reftable_stack_compaction_concurrent(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(st1, &write_test_ref, &ref); + err = reftable_stack_add(st1, write_test_ref, &ref); check(!err); } @@ -949,10 +945,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); } @@ -962,8 +956,8 @@ static void t_reftable_stack_compaction_concurrent_clean(void) struct reftable_write_options opts = { 0 }; struct reftable_stack *st1 = NULL, *st2 = NULL, *st3 = NULL; char *dir = get_tmp_dir(__LINE__); - int err, i; - int N = 3; + int err; + size_t N = 3, i; err = reftable_new_stack(&st1, dir, &opts); check(!err); @@ -976,9 +970,9 @@ static void t_reftable_stack_compaction_concurrent_clean(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(st1, &write_test_ref, &ref); + err = reftable_stack_add(st1, write_test_ref, &ref); check(!err); } From patchwork Tue Aug 6 14:13:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13754959 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A00418D65E for ; Tue, 6 Aug 2024 14:20:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722954055; cv=none; b=ttL4woFU0STkwy2Q+qcCx7ogb8ZH8d+kogZ539dfCVwJPZLHV/nPVgU18wFcRkgNurPJhSMVFqxGGDWaWF75HC5/9dpgGFxvMekneIgyekiF3mpuLjdLUSggAWB85JIY6P6YI49kw1B2qQXhn7nvd5s6gEJPZzjBk0jJj3r1Q0Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722954055; c=relaxed/simple; bh=I4iRpr7Ee0PwkRVUIv6jV0TGrV2PqU3fMM+GahybNHY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KTCuwXIEflijET88lX2daT6QgpzTmawiSNzsmmegvy4y3yFh22kJrteL7/YsbRsTjraQ7cjHw2/1kNT8FFfXyDOGe78PVkUbEKniGhUk7VtlH6IvW2zIVZ2FZVPej+Kk+JsA2QpdEy7QN8x8nVuFpFm0LPGdSeEWRvpB9g1pDAE= 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=Re/FOjFm; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Re/FOjFm" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-710887a8083so518041b3a.0 for ; Tue, 06 Aug 2024 07:20:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722954053; x=1723558853; 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=WIIUt6LGsM+7z2VDXO+aBgICFG/pOO5LVlbndntxECA=; b=Re/FOjFmFZJHVQ2hl2XWaPrckK85fi0hxyxfpRKj5SF6aWwzcaUTuCJcxwAHMrjFAN PhCyyv3pkpT1YKAjJEZpphQFZZ/+Ln9L58kwaMARxESbd1v2FoY62vnzgvFv3K5LnL2K FtcAXRAKlvWiFMNjGKWPB2kBgdrwyse5XEVFzvTT9DdzhMdfFx1OA2Cw4QuhVIgUG0Vp 7V9aqxqzzjDkUq8D03s3jDBHcGFo7o6UuC4nNDLDjCvzr8XWFApS+Ncq+Xg51tipR+ej URYzDZS08e9s+Cz1zdbQr2TOTHiOiQuMzGrHw4URRBJpPUWwrCWZYagKdH8q29acdIed 3ABg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722954053; x=1723558853; 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=WIIUt6LGsM+7z2VDXO+aBgICFG/pOO5LVlbndntxECA=; b=mglVbFrJrvZfZ9VKyLnPIs55iCI4rFl/5xz80WUa1ONv5NIKscJXsydVuDY1SCQzPP gnbilKbgKHL7ogWoEIYGIPI1B+4ocKn2aOg+xHkqUJdWb3YDV765SaLeB271vVTUVw1K h9tBXwYQH98iJfWEDqssyUZyDX/kEXwcfZsOJEdigybm6M4XHixkFRZ2kKb/rtC3pYIy JRxiAV9ja7VBP3BD7fVXghT5jXV++eW8kVJR6815a0ZZ7EiwmcYbuk7bCZq6J5PrE+mY 3T5rmGvzV9B4Vn31JollgO0Bg/mnmfamriB/PceRebZ1zjIjoYilju4vJZLNH2/RR/Ul cHmg== X-Gm-Message-State: AOJu0YyQ7s6VHmABZrDmBiH1Q9P3JQ6/3r0gi6qlYMBAX0p7mfJ3vFva HUuDUWSB/JzNTL05IQ8/mo2W2IvpQzcqbspdo+FrY+C4rDiSTBnWgl56jcHxYcrrdg== X-Google-Smtp-Source: AGHT+IFkQ1ivGA7iey9Fly5XnFuWsK5Ht5O622zdWneMfvWGNDuXLHyumBPPZ1nyIofDFOfEF0vGHg== X-Received: by 2002:a05:6a00:148c:b0:70d:3438:9689 with SMTP id d2e1a72fcca58-7106cf94dc1mr13520440b3a.5.1722954052855; Tue, 06 Aug 2024 07:20:52 -0700 (PDT) Received: from Ubuntu.. ([27.59.87.1]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7106ec416aasm7040563b3a.70.2024.08.06.07.20.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 07:20:52 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 3/6] t-reftable-stack: use Git's tempfile API instead of mkstemp() Date: Tue, 6 Aug 2024 19:43:39 +0530 Message-ID: <20240806142020.4615-4-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240806142020.4615-1-chandrapratap3519@gmail.com> References: <20240806142020.4615-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 e033feb8ee..14909b127e 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 Tue Aug 6 14:13:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13754960 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 08FA118D65E for ; Tue, 6 Aug 2024 14:20:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722954058; cv=none; b=XvCP2GHd0FxAUVnNGcS1KzGGEUgP9cNwvS2mbZGKv4FKGfnH98sFDP5GWMk/AwR6C/30F30dc0Yp+a82TKiMqawMUpZqFrXmAmI1cmRx5FpWlOT+EZc3ZyxpMfG7ZgFkf4sMwqbglrweTwPKx8NCARMZCU2nKwsSYykvAFf2dFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722954058; c=relaxed/simple; bh=AIcfdS0pRXjOVTTSZqcYF+VA9gRPqYdOWqcmxSNPIAw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SF8CxppiocYeUxVQ4bTMrSe1dzi4zhW+hbKpUwNDjbMa5AhX7yYO243FdPEfMG7zP73ONhUqcmedA4unWr9YYisWHA34f9Dq7c1sI66zTMetdB+PriINFCax0MMU1l8/xYeGgcCYUHG52ayYPtU84uSpfGbnD15WqOg3DzukI+g= 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=N7yC8RIQ; arc=none smtp.client-ip=209.85.210.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N7yC8RIQ" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-70d399da0b5so547359b3a.3 for ; Tue, 06 Aug 2024 07:20:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722954056; x=1723558856; 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=ZCFZpgV+5bGVbTzJf54eaZtTsW9DJYX8HyhNCTSMIlc=; b=N7yC8RIQ1hfFNdw8g0BGJETwwEOxyRoUDYEngVAkvrsmpXE+1OT1ORSBC2jqfy7xOV PLZPPsFZRMeiru34ZMLVqy/NzKIb+JLlep5kpsXoGFw/PD+YtH8AvJOvzw6vjNHKUWuh qCtc0/yrPkHF6SfuqhbW3g5App51VFB7JOCCKzerBB37NMzWil0Hsh9Mg0k7ppjSuMHM IxakEQI0jAoQx7AiKk4SFZyaluvZBiMsLNOUQbhNguS8mcvU4ZTFxIoMYRq0DlT4M/bS Jb8xWBWOc3W2ny4pBpZV2uzeMU1ZU44ZqV/ClXiTk7EtFcj2mwjv6gCLJKUGftmzi0/D Eqdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722954056; x=1723558856; 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=ZCFZpgV+5bGVbTzJf54eaZtTsW9DJYX8HyhNCTSMIlc=; b=bIexRdM/yKMFm1fB9DwSvovhVbveuGeXmlHQwKDXRhgtC4rhH0wV3gkqmpzAkJnYM7 5nLD1IhmBuyJygszjLsQwcaudLM2VWDMkG8mgR1bL61tuorLkIAPhcnO0/ekga8z9Veu VthIzW8jOGc4B8rslx6awRJKzbD1ghMTYDveLfJ4FceKDFtCeScIEmN6p2ON51u1OR+L ELUN6XomQqihlTtqseMEArCfs73RkwfzXTkusJFPIRbBTQAmt96qWBeexMgLEc8q+mpY uR9IgbofBfT3UrI68nzZnSE9QzWtcZ7E1p9b/4YNkIrNkN0aC6BIKebG4nCZwzy28jYp 1zuQ== X-Gm-Message-State: AOJu0Ywu5jeLVsCAC0UKyTZJp+pp1YuZfBmw7+CKbNhf49UwjsJZyid9 BHCrM3vGfa7HAkpigBWVPDcbqK7iadQipnZDbG7LPqXWvRQJAqMnLnTQwdY9vRVweQ== X-Google-Smtp-Source: AGHT+IE3CspApNe6NDizG2Sd8A4N0D+bXIZafgJp/bbVTF4YDdBG/eNwhNMs/ImggAEE7LIrW3ljbA== X-Received: by 2002:a05:6a00:1950:b0:70d:87e0:9e5 with SMTP id d2e1a72fcca58-7106cf9f90cmr17417100b3a.9.1722954055679; Tue, 06 Aug 2024 07:20:55 -0700 (PDT) Received: from Ubuntu.. ([27.59.87.1]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7106ec416aasm7040563b3a.70.2024.08.06.07.20.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 07:20:55 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 4/6] t-reftable-stack: use reftable_ref_record_equal() to compare ref records Date: Tue, 6 Aug 2024 19:43:40 +0530 Message-ID: <20240806142020.4615-5-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240806142020.4615-1-chandrapratap3519@gmail.com> References: <20240806142020.4615-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 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/t/unit-tests/t-reftable-stack.c b/t/unit-tests/t-reftable-stack.c index 14909b127e..0c15e654e8 100644 --- a/t/unit-tests/t-reftable-stack.c +++ b/t/unit-tests/t-reftable-stack.c @@ -145,7 +145,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"); @@ -262,8 +262,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 Tue Aug 6 14:13: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: 13754961 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.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 D269618D648 for ; Tue, 6 Aug 2024 14:20:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722954061; cv=none; b=Stig30NYHba6OBYJ8eohgUp2JP5mYDM2Ao+SHqA/PZytY9oVSXZ7SE/W/nep8kFHfUPCf/V92ITICXX9Q8nbRKLu4q+gXnS9lvLWBV7LnsVplzuVBNcygRC5X5yZB6TVMGjDh7KTiVPf4B9FVVwH6LBARtXMH8eO7y+Ci8ZTxZI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722954061; c=relaxed/simple; bh=ybJ2xtykgebCTatZBuEeLCEpAvoHdTasXIwdbz/Wwqg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IgsoG29/01sVFBQpdjshhtrbt5Y/sWg8Fo+0nB6LqDpsOR5i/YZHPQWUopriTdadGDte5ucjLVaChSCAii3IHON4sZugrifSiIMpLjhGL51/pWJizPb4ywYxVueGVD6q91iR6WEt8Baby+EKbCYNVZHPLPs9wu9Zd9M8oWA8pyY= 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=RzPPckuM; arc=none smtp.client-ip=209.85.210.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="RzPPckuM" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-710887a8083so518116b3a.0 for ; Tue, 06 Aug 2024 07:20:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722954059; x=1723558859; 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=z8w6SZ0MvriHWod+NEqxC9OqroeN7udMheOXVRQCekQ=; b=RzPPckuMlUZvfEjG8zcxt0JC9LVph8/nLbX9jkTEM4tWFHECol0tdfvCCXIbAdjNCB Ywt9BRxZQDeRzMWF1yHBHX3yN64oXSY/uvOz2ELQSUE8FTYBZNegG6QgR1fMIapqufXx ObeQOGNzmnLrjMIwY/Pf9O8ZR7tHmKDqUvzM/Di0+uet0wNcSDXAtbcwY+JNS4i4dWjZ E1lutRSOSognGPvE6EC+7aLyOU67z+d6A/LtKXTLLder+KNI7OXeiTH7JOf276Ai6b4C dYuj8EgPRw8SfaZU1NLae6KrAbcDLLLaK/woRJUdqxoXbalgTH8Jn056xSDeySUvc674 trmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722954059; x=1723558859; 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=z8w6SZ0MvriHWod+NEqxC9OqroeN7udMheOXVRQCekQ=; b=Xdu7nEVKOkNWEU0DsQuQrQiTAR8vnFoPmFtkUMZp14T0YR1SWvDnnAFoPDcrqQ+vAo O6756LDO7HuPRaPqKEDgwJDXPy3j/anX6LQkxZPshEY+K5PMuxHqlQEJ1mSZ5QqScBab UPUQC636P4xllU1ibpKzqDxjHYzZ20ZC5thJRRTRjcRi8M6gG711eVsuSTrzo3ZEwG7K 9KCRccanA55snviw2ZHBgxNDH2PzpmP2Jsdx8yflMPq/HReK9r1Lsjh+9p/i72OXg6p+ 0PN8v3Dhy+PwtJ6a9ozuGGtMpy0dUWyaduPMP//fVGX57K2D5vANEC3uf4qA0owR6KPA eS2g== X-Gm-Message-State: AOJu0YxthaonuYRawzxqvHaOauIsEG2CBK6cJm69WiHNR6LKVwTlj1Mn eCokmWzwNhc6OLTtl6WwQaumpiY1TWvfM9HC3/+byyBICyXGm7HiQprPWTEF2tdWqg== X-Google-Smtp-Source: AGHT+IEzh6mFe8c3isVFW/qxaQ9Vd9KJ5PXW+xScRPMa7afMMxXeyJOKHD8Jq8f5JgW3NGmiDhr7BA== X-Received: by 2002:a05:6a20:439e:b0:1c0:7ec3:c7ae with SMTP id adf61e73a8af0-1c699628d27mr14719527637.47.1722954058635; Tue, 06 Aug 2024 07:20:58 -0700 (PDT) Received: from Ubuntu.. ([27.59.87.1]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7106ec416aasm7040563b3a.70.2024.08.06.07.20.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 07:20:58 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 5/6] t-reftable-stack: add test for non-default compaction factor Date: Tue, 6 Aug 2024 19:43:41 +0530 Message-ID: <20240806142020.4615-6-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240806142020.4615-1-chandrapratap3519@gmail.com> References: <20240806142020.4615-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 0c15e654e8..5228872450 100644 --- a/t/unit-tests/t-reftable-stack.c +++ b/t/unit-tests/t-reftable-stack.c @@ -808,12 +808,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; } @@ -846,11 +846,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); @@ -1009,6 +1041,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_compaction_concurrent(), "compaction with concurrent stack"); TEST(t_reftable_stack_compaction_concurrent_clean(), "compaction with unclean stack shutdown"); From patchwork Tue Aug 6 14:13: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: 13754962 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 8E53E1D47BC for ; Tue, 6 Aug 2024 14:21:02 +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=1722954064; cv=none; b=Gbdng/Ho83JdpKq5p/egcCfiLzAgDbzPGcgclMlPIn6BpjU7w1+nQZAscRX47mOIzhc6mNfZMmQUgSSj8NWvKx3VeJEPjfIP7H86xQSTPBTdN5BnMRYIhnOU2nXJQnPzkHFPGViWuldGsnmWdhXTMCTjCvY8kJ8moGkoe5K4XPE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722954064; c=relaxed/simple; bh=5+ASgjHrFWdQT21/Bj9gxlkYg1pbAgcJ3E5wvYjVaM8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ukbaNeVDQ7U35Prb6ig3SnfuGRf+PH3KdKmpnIjw+tTkupk413Ux1E3O7OqeviS/6Y86gAylSqYfH+f3NCQiCPIPC5TP5KgZt2DwlViwsx/wY3paEvRNbyXnkiKYBaendLUaFfZtDVJhel/C35QUYF23cQWHRg7hjCZE8ukmm78= 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=bwE+wO5F; 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="bwE+wO5F" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-70d162eef54so505142b3a.3 for ; Tue, 06 Aug 2024 07:21:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722954062; x=1723558862; 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=JaCVkVcsNkbzUv4nc9PD9hvNW+AWvk32ThdoHlCYhck=; b=bwE+wO5FilldUHwwhbHQ+IR5or3Tob8UwHQTvQBF5qYU/PfM+ZzaTCvDeifzFW07eC GMtooIC+/tObMi+XkLG/ZGaRARt0uzeL92iWVvSTxstvuCOKRyI0pQqEyFXB5qZFspE2 BB3Aq9gdkP+IJoJkxR/b7ynxM7Uqq2Y4duGCKtIXHpVRO1jsctRXpvZXCW/xZlnnFgyP lcKZl7bRbpjYWGyTzCjn73Zq49XNo5d6Q3rdle9k/CB0ZFOwRv8tVKWoZrQEsXwAjK48 ix9R9YV7yJG3apa74uRPQ0hw1df7wupy3eR/jbEJbhYRS4JK+geOLhfubn1bTwfeahjj Nb8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722954062; x=1723558862; 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=JaCVkVcsNkbzUv4nc9PD9hvNW+AWvk32ThdoHlCYhck=; b=UNQ4bJJ2TMgImbDt3t1sfnfIXPWyY+qO9bee5+nrpHd9jiPUu+pnHwlxjWPYkIklmG c4bnsyU5Q5n406n1XX032n/hdPAQQhSzw4pKR/P9gv0Lg207PKGIgxs864Q6LpQiV01d OjmhjTATv8lmr5x4jKX/ws+brPIznCNJ9L54nLrjE3Wb6e3LQaRn9ETxUUmQ5bJsY3KI KG/UshbB6FDpt9I3Zpbv9SXafTSOE1+WTtznhB2pbxoZQIBXOd1K0oL1yT155uBcet3v fEEeJNx7XkigXFB7KzAZB/tUcKF/eHzIP51YPA3N3QgQePLYmOimBuxF/F0d05FJMGU9 NwmA== X-Gm-Message-State: AOJu0Yzs2IBb2j/ZNSunx4ky7vYdZ+6FauD+yk56JaXeoiTHiTTXMota 3a+h6evIiC+ED7nAGLrtK6/wKTf/4H+DitdoQwQBGyIHAVZUL+Qb1MD8qgSnP7w4MA== X-Google-Smtp-Source: AGHT+IHPETgAAojXJ/94pptY56TrG8tiN3YgIN+yJIACj3CBJ0C+YFhhOH8nuNJzg2key0tnuRwAWg== X-Received: by 2002:a05:6a20:6a24:b0:1c4:b62f:feb2 with SMTP id adf61e73a8af0-1c699559ce2mr16467916637.18.1722954061445; Tue, 06 Aug 2024 07:21:01 -0700 (PDT) Received: from Ubuntu.. ([27.59.87.1]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7106ec416aasm7040563b3a.70.2024.08.06.07.20.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 07:21:00 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 6/6] t-reftable-stack: add test for stack iterators Date: Tue, 6 Aug 2024 19:43:42 +0530 Message-ID: <20240806142020.4615-7-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240806142020.4615-1-chandrapratap3519@gmail.com> References: <20240806142020.4615-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 | 82 +++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/t/unit-tests/t-reftable-stack.c b/t/unit-tests/t-reftable-stack.c index 5228872450..1ec8e4afc0 100644 --- a/t/unit-tests/t-reftable-stack.c +++ b/t/unit-tests/t-reftable-stack.c @@ -521,6 +521,87 @@ 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++) { + char buf[20]; + xsnprintf(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; + set_test_hash(refs[i].value.val1, i); + + logs[i].refname = xstrdup(buf); + 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; @@ -1046,6 +1127,7 @@ int cmd_main(int argc, const char *argv[]) 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_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");