aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-09-16 14:22:53 -0700
committerJunio C Hamano <gitster@pobox.com>2024-09-16 14:22:53 -0700
commitc1f41bbe1a23aabdf9026c735dac58c181487e94 (patch)
tree3fba4e28abc893afed8ba9128665cd84251a4d25
parented155187b429a2a6b6475efe1767053df37ccfe1 (diff)
parent2b14ced370aea017efc32b525fd72a6dd2cc60c5 (diff)
downloadgit-c1f41bbe1a23aabdf9026c735dac58c181487e94.tar.gz
Merge branch 'cp/unit-test-reftable-stack'
Another reftable test migrated to the unit-test framework. * cp/unit-test-reftable-stack: t-reftable-stack: add test for stack iterators t-reftable-stack: add test for non-default compaction factor t-reftable-stack: use reftable_ref_record_equal() to compare ref records t-reftable-stack: use Git's tempfile API instead of mkstemp() t: harmonize t-reftable-stack.c with coding guidelines t: move reftable/stack_test.c to the unit testing framework
-rw-r--r--Makefile12
-rw-r--r--reftable/reftable-tests.h14
-rw-r--r--reftable/test_framework.c27
-rw-r--r--reftable/test_framework.h61
-rw-r--r--t/helper/test-reftable.c8
-rw-r--r--t/helper/test-tool.c3
-rw-r--r--t/helper/test-tool.h1
-rwxr-xr-xt/t0032-reftable-unittest.sh16
-rw-r--r--t/unit-tests/t-reftable-stack.c (renamed from reftable/stack_test.c)665
9 files changed, 392 insertions, 415 deletions
diff --git a/Makefile b/Makefile
index be643ef096..275a5ee3c9 100644
--- a/Makefile
+++ b/Makefile
@@ -911,7 +911,6 @@ TEST_SHELL_PATH = $(SHELL_PATH)
LIB_FILE = libgit.a
XDIFF_LIB = xdiff/lib.a
REFTABLE_LIB = reftable/libreftable.a
-REFTABLE_TEST_LIB = reftable/libreftable_test.a
GENERATED_H += command-list.h
GENERATED_H += config-list.h
@@ -1349,6 +1348,7 @@ UNIT_TEST_PROGRAMS += t-reftable-merged
UNIT_TEST_PROGRAMS += t-reftable-pq
UNIT_TEST_PROGRAMS += t-reftable-readwrite
UNIT_TEST_PROGRAMS += t-reftable-record
+UNIT_TEST_PROGRAMS += t-reftable-stack
UNIT_TEST_PROGRAMS += t-reftable-tree
UNIT_TEST_PROGRAMS += t-strbuf
UNIT_TEST_PROGRAMS += t-strcmp-offset
@@ -2691,9 +2691,6 @@ REFTABLE_OBJS += reftable/stack.o
REFTABLE_OBJS += reftable/tree.o
REFTABLE_OBJS += reftable/writer.o
-REFTABLE_TEST_OBJS += reftable/stack_test.o
-REFTABLE_TEST_OBJS += reftable/test_framework.o
-
TEST_OBJS := $(patsubst %$X,%.o,$(TEST_PROGRAMS)) $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS))
.PHONY: test-objs
@@ -2868,9 +2865,6 @@ $(XDIFF_LIB): $(XDIFF_OBJS)
$(REFTABLE_LIB): $(REFTABLE_OBJS)
$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
-$(REFTABLE_TEST_LIB): $(REFTABLE_TEST_OBJS)
- $(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
-
export DEFAULT_EDITOR DEFAULT_PAGER
Documentation/GIT-EXCLUDED-PROGRAMS: FORCE
@@ -3250,7 +3244,7 @@ perf: all
t/helper/test-tool$X: $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS)) $(UNIT_TEST_DIR)/test-lib.o
-t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS) $(REFTABLE_TEST_LIB)
+t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS)
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(filter %.a,$^) $(LIBS)
check-sha1:: t/helper/test-tool$X
@@ -3711,7 +3705,7 @@ clean: profile-clean coverage-clean cocciclean
$(RM) git.res
$(RM) $(OBJECTS)
$(RM) headless-git.o
- $(RM) $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(REFTABLE_TEST_LIB)
+ $(RM) $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB)
$(RM) $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) $(OTHER_PROGRAMS)
$(RM) $(TEST_PROGRAMS)
$(RM) $(FUZZ_PROGRAMS)
diff --git a/reftable/reftable-tests.h b/reftable/reftable-tests.h
deleted file mode 100644
index 5d725c69c7..0000000000
--- a/reftable/reftable-tests.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
-Copyright 2020 Google LLC
-
-Use of this source code is governed by a BSD-style
-license that can be found in the LICENSE file or at
-https://developers.google.com/open-source/licenses/bsd
-*/
-
-#ifndef REFTABLE_TESTS_H
-#define REFTABLE_TESTS_H
-
-int stack_test_main(int argc, const char **argv);
-
-#endif
diff --git a/reftable/test_framework.c b/reftable/test_framework.c
deleted file mode 100644
index a07fec5d84..0000000000
--- a/reftable/test_framework.c
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
-Copyright 2020 Google LLC
-
-Use of this source code is governed by a BSD-style
-license that can be found in the LICENSE file or at
-https://developers.google.com/open-source/licenses/bsd
-*/
-
-#include "system.h"
-#include "test_framework.h"
-
-
-void set_test_hash(uint8_t *p, int i)
-{
- memset(p, (uint8_t)i, hash_size(GIT_SHA1_FORMAT_ID));
-}
-
-ssize_t strbuf_add_void(void *b, const void *data, size_t sz)
-{
- strbuf_add(b, data, sz);
- return sz;
-}
-
-int noop_flush(void *arg UNUSED)
-{
- return 0;
-}
diff --git a/reftable/test_framework.h b/reftable/test_framework.h
deleted file mode 100644
index 687390f9c2..0000000000
--- a/reftable/test_framework.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
-Copyright 2020 Google LLC
-
-Use of this source code is governed by a BSD-style
-license that can be found in the LICENSE file or at
-https://developers.google.com/open-source/licenses/bsd
-*/
-
-#ifndef TEST_FRAMEWORK_H
-#define TEST_FRAMEWORK_H
-
-#include "system.h"
-#include "reftable-error.h"
-
-#define EXPECT_ERR(c) \
- do { \
- if (c != 0) { \
- fflush(stderr); \
- fflush(stdout); \
- fprintf(stderr, "%s: %d: error == %d (%s), want 0\n", \
- __FILE__, __LINE__, c, reftable_error_str(c)); \
- abort(); \
- } \
- } while (0)
-
-#define EXPECT_STREQ(a, b) \
- do { \
- if (strcmp(a, b)) { \
- fflush(stderr); \
- fflush(stdout); \
- fprintf(stderr, "%s:%d: %s (%s) != %s (%s)\n", __FILE__, \
- __LINE__, #a, a, #b, b); \
- abort(); \
- } \
- } while (0)
-
-#define EXPECT(c) \
- do { \
- if (!(c)) { \
- fflush(stderr); \
- fflush(stdout); \
- fprintf(stderr, "%s: %d: failed assertion %s\n", __FILE__, \
- __LINE__, #c); \
- abort(); \
- } \
- } while (0)
-
-#define RUN_TEST(f) \
- fprintf(stderr, "running %s\n", #f); \
- fflush(stderr); \
- f();
-
-void set_test_hash(uint8_t *p, int i);
-
-/* Like strbuf_add, but suitable for passing to reftable_new_writer
- */
-ssize_t strbuf_add_void(void *b, const void *data, size_t sz);
-
-int noop_flush(void *);
-
-#endif
diff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c
index ce5a94fbd3..29d4e9a755 100644
--- a/t/helper/test-reftable.c
+++ b/t/helper/test-reftable.c
@@ -6,16 +6,8 @@
#include "reftable/reftable-merged.h"
#include "reftable/reftable-reader.h"
#include "reftable/reftable-stack.h"
-#include "reftable/reftable-tests.h"
#include "test-tool.h"
-int cmd__reftable(int argc, const char **argv)
-{
- /* test from simple to complex. */
- stack_test_main(argc, argv);
- return 0;
-}
-
static void print_help(void)
{
printf("usage: dump [-st] arg\n\n"
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 7005b7d0bf..1ebb69a5dc 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -26,6 +26,7 @@ static struct test_cmd cmds[] = {
{ "drop-caches", cmd__drop_caches },
{ "dump-cache-tree", cmd__dump_cache_tree },
{ "dump-fsmonitor", cmd__dump_fsmonitor },
+ { "dump-reftable", cmd__dump_reftable },
{ "dump-split-index", cmd__dump_split_index },
{ "dump-untracked-cache", cmd__dump_untracked_cache },
{ "env-helper", cmd__env_helper },
@@ -60,9 +61,7 @@ static struct test_cmd cmds[] = {
{ "read-graph", cmd__read_graph },
{ "read-midx", cmd__read_midx },
{ "ref-store", cmd__ref_store },
- { "reftable", cmd__reftable },
{ "rot13-filter", cmd__rot13_filter },
- { "dump-reftable", cmd__dump_reftable },
{ "regex", cmd__regex },
{ "repository", cmd__repository },
{ "revision-walking", cmd__revision_walking },
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index b51f79e774..21802ac27d 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -55,7 +55,6 @@ int cmd__read_graph(int argc, const char **argv);
int cmd__read_midx(int argc, const char **argv);
int cmd__ref_store(int argc, const char **argv);
int cmd__rot13_filter(int argc, const char **argv);
-int cmd__reftable(int argc, const char **argv);
int cmd__regex(int argc, const char **argv);
int cmd__repository(int argc, const char **argv);
int cmd__revision_walking(int argc, const char **argv);
diff --git a/t/t0032-reftable-unittest.sh b/t/t0032-reftable-unittest.sh
deleted file mode 100755
index 471cb37ac2..0000000000
--- a/t/t0032-reftable-unittest.sh
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/sh
-#
-# Copyright (c) 2020 Google LLC
-#
-
-test_description='reftable unittests'
-
-TEST_PASSES_SANITIZE_LEAK=true
-. ./test-lib.sh
-
-test_expect_success 'unittests' '
- TMPDIR=$(pwd) && export TMPDIR &&
- test-tool reftable
-'
-
-test_done
diff --git a/reftable/stack_test.c b/t/unit-tests/t-reftable-stack.c
index 89cb2be19f..d62a9c1bed 100644
--- a/reftable/stack_test.c
+++ b/t/unit-tests/t-reftable-stack.c
@@ -6,22 +6,18 @@ license that can be found in the LICENSE file or at
https://developers.google.com/open-source/licenses/bsd
*/
-#include "stack.h"
-
-#include "system.h"
-
-#include "copy.h"
-#include "reftable-reader.h"
-#include "merged.h"
-#include "basics.h"
-#include "record.h"
-#include "test_framework.h"
-#include "reftable-tests.h"
-#include "reader.h"
-
-#include <sys/types.h>
+#include "test-lib.h"
+#include "reftable/merged.h"
+#include "reftable/reader.h"
+#include "reftable/reftable-error.h"
+#include "reftable/stack.h"
#include <dirent.h>
+static void set_test_hash(uint8_t *p, int i)
+{
+ memset(p, (uint8_t)i, hash_size(GIT_SHA1_FORMAT_ID));
+}
+
static void clear_dir(const char *dirname)
{
struct strbuf path = STRBUF_INIT;
@@ -73,34 +69,34 @@ 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);
+ 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;
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]));
- }
+ for (size_t i = 0; names[i]; i++)
+ 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)
@@ -127,12 +123,12 @@ static void write_n_ref_tables(struct reftable_stack *st,
};
strbuf_reset(&buf);
- strbuf_addf(&buf, "refs/heads/branch-%04u", (unsigned) i);
+ strbuf_addf(&buf, "refs/heads/branch-%04"PRIuMAX, (uintmax_t)i);
ref.refname = buf.buf;
set_test_hash(ref.value.val1, i);
err = reftable_stack_add(st, &write_test_ref, &ref);
- EXPECT_ERR(err);
+ check(!err);
}
st->opts.disable_auto_compact = disable_auto_compact;
@@ -152,7 +148,7 @@ static int write_test_log(struct reftable_writer *wr, void *arg)
return reftable_writer_add_log(wr, wla->log);
}
-static void test_reftable_stack_add_one(void)
+static void t_reftable_stack_add_one(void)
{
char *dir = get_tmp_dir(__LINE__);
struct strbuf scratch = STRBUF_INIT;
@@ -168,25 +164,25 @@ static void test_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);
- EXPECT_ERR(err);
+ check(!err);
- err = reftable_stack_add(st, &write_test_ref, &ref);
- EXPECT_ERR(err);
+ err = reftable_stack_add(st, write_test_ref, &ref);
+ 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(reftable_ref_record_equal(&ref, &dest, GIT_SHA1_RAWSZ));
+ check_int(st->readers_len, >, 0);
#ifndef GIT_WINDOWS_NATIVE
strbuf_addstr(&scratch, dir);
strbuf_addstr(&scratch, "/tables.list");
err = stat(scratch.buf, &stat_result);
- EXPECT(!err);
- EXPECT((stat_result.st_mode & 0777) == opts.default_permissions);
+ check(!err);
+ check_int((stat_result.st_mode & 0777), ==, opts.default_permissions);
strbuf_reset(&scratch);
strbuf_addstr(&scratch, dir);
@@ -194,8 +190,8 @@ static void test_reftable_stack_add_one(void)
/* do not try at home; not an external API for reftable. */
strbuf_addstr(&scratch, st->readers[0]->name);
err = stat(scratch.buf, &stat_result);
- EXPECT(!err);
- EXPECT((stat_result.st_mode & 0777) == opts.default_permissions);
+ check(!err);
+ check_int((stat_result.st_mode & 0777), ==, opts.default_permissions);
#else
(void) stat_result;
#endif
@@ -207,7 +203,7 @@ static void test_reftable_stack_add_one(void)
umask(mask);
}
-static void test_reftable_stack_uptodate(void)
+static void t_reftable_stack_uptodate(void)
{
struct reftable_write_options opts = { 0 };
struct reftable_stack *st1 = NULL;
@@ -233,28 +229,28 @@ static void test_reftable_stack_uptodate(void)
by creating two stacks for the same directory.
*/
err = reftable_new_stack(&st1, dir, &opts);
- EXPECT_ERR(err);
+ check(!err);
err = reftable_new_stack(&st2, dir, &opts);
- EXPECT_ERR(err);
+ check(!err);
- err = reftable_stack_add(st1, &write_test_ref, &ref1);
- EXPECT_ERR(err);
+ err = reftable_stack_add(st1, write_test_ref, &ref1);
+ check(!err);
- err = reftable_stack_add(st2, &write_test_ref, &ref2);
- EXPECT(err == REFTABLE_OUTDATED_ERROR);
+ err = reftable_stack_add(st2, write_test_ref, &ref2);
+ 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);
+ err = reftable_stack_add(st2, write_test_ref, &ref2);
+ 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 };
@@ -268,46 +264,47 @@ static void test_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);
- 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);
+ err = reftable_addition_add(add, write_test_ref, &ref);
+ 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(reftable_ref_record_equal(&ref, &dest, GIT_SHA1_RAWSZ));
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};
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);
- EXPECT_ERR(err);
+ 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,
@@ -315,7 +312,7 @@ static void test_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;
/*
@@ -326,13 +323,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);
+ err = reftable_addition_add(add, write_test_ref, &ref);
+ check(!err);
err = reftable_addition_commit(add);
- EXPECT_ERR(err);
+ check(!err);
reftable_addition_destroy(add);
@@ -342,16 +339,16 @@ static void test_reftable_stack_transaction_api_performs_auto_compaction(void)
* all tables in the stack.
*/
if (i != n)
- EXPECT(st->merged->readers_len == i + 1);
+ check_int(st->merged->readers_len, ==, i + 1);
else
- EXPECT(st->merged->readers_len == 1);
+ check_int(st->merged->readers_len, ==, 1);
}
reftable_stack_destroy(st);
clear_dir(dir);
}
-static void test_reftable_stack_auto_compaction_fails_gracefully(void)
+static void t_reftable_stack_auto_compaction_fails_gracefully(void)
{
struct reftable_ref_record ref = {
.refname = (char *) "refs/heads/master",
@@ -359,20 +356,20 @@ static void test_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__);
int err;
err = reftable_new_stack(&st, dir, &opts);
- EXPECT_ERR(err);
+ check(!err);
err = reftable_stack_add(st, write_test_ref, &ref);
- EXPECT_ERR(err);
- EXPECT(st->merged->readers_len == 1);
- EXPECT(st->stats.attempts == 0);
- EXPECT(st->stats.failures == 0);
+ check(!err);
+ check_int(st->merged->readers_len, ==, 1);
+ check_int(st->stats.attempts, ==, 0);
+ check_int(st->stats.failures, ==, 0);
/*
* Lock the newly written table such that it cannot be compacted.
@@ -384,10 +381,10 @@ static void test_reftable_stack_auto_compaction_fails_gracefully(void)
ref.update_index = 2;
err = reftable_stack_add(st, write_test_ref, &ref);
- EXPECT_ERR(err);
- EXPECT(st->merged->readers_len == 2);
- EXPECT(st->stats.attempts == 1);
- EXPECT(st->stats.failures == 1);
+ check(!err);
+ check_int(st->merged->readers_len, ==, 2);
+ check_int(st->stats.attempts, ==, 1);
+ check_int(st->stats.failures, ==, 1);
reftable_stack_destroy(st);
strbuf_release(&table_path);
@@ -399,7 +396,7 @@ static int write_error(struct reftable_writer *wr UNUSED, void *arg)
return *((int *)arg);
}
-static void test_reftable_stack_update_index_check(void)
+static void t_reftable_stack_update_index_check(void)
{
char *dir = get_tmp_dir(__LINE__);
struct reftable_write_options opts = { 0 };
@@ -419,18 +416,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);
+ err = reftable_stack_add(st, write_test_ref, &ref1);
+ check(!err);
- err = reftable_stack_add(st, &write_test_ref, &ref2);
- EXPECT(err == REFTABLE_API_ERROR);
+ err = reftable_stack_add(st, write_test_ref, &ref2);
+ check_int(err, ==, REFTABLE_API_ERROR);
reftable_stack_destroy(st);
clear_dir(dir);
}
-static void test_reftable_stack_lock_failure(void)
+static void t_reftable_stack_lock_failure(void)
{
char *dir = get_tmp_dir(__LINE__);
struct reftable_write_options opts = { 0 };
@@ -438,19 +435,18 @@ 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);
+ err = reftable_stack_add(st, write_error, &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;
struct reftable_write_options opts = {
.exact_log_message = 1,
@@ -459,18 +455,18 @@ static void test_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);
- EXPECT_ERR(err);
+ 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;
@@ -484,8 +480,8 @@ 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);
+ int err = reftable_stack_add(st, write_test_ref, &refs[i]);
+ check(!err);
}
for (i = 0; i < N; i++) {
@@ -493,28 +489,28 @@ static void test_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);
- EXPECT_ERR(err);
+ int err = reftable_stack_add(st, write_test_log, &arg);
+ 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 };
+ struct reftable_ref_record dest = { 0 };
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);
}
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);
- EXPECT_ERR(err);
- EXPECT(reftable_log_record_equal(&dest, logs + i,
+ check(!err);
+ check(reftable_log_record_equal(&dest, logs + i,
GIT_SHA1_RAWSZ));
reftable_log_record_release(&dest);
}
@@ -523,8 +519,8 @@ static void test_reftable_stack_add(void)
strbuf_addstr(&path, dir);
strbuf_addstr(&path, "/tables.list");
err = stat(path.buf, &stat_result);
- EXPECT(!err);
- EXPECT((stat_result.st_mode & 0777) == opts.default_permissions);
+ check(!err);
+ check_int((stat_result.st_mode & 0777), ==, opts.default_permissions);
strbuf_reset(&path);
strbuf_addstr(&path, dir);
@@ -532,8 +528,8 @@ static void test_reftable_stack_add(void)
/* do not try at home; not an external API for reftable. */
strbuf_addstr(&path, st->readers[0]->name);
err = stat(path.buf, &stat_result);
- EXPECT(!err);
- EXPECT((stat_result.st_mode & 0777) == opts.default_permissions);
+ check(!err);
+ check_int((stat_result.st_mode & 0777), ==, opts.default_permissions);
#else
(void) stat_result;
#endif
@@ -548,7 +544,89 @@ static void test_reftable_stack_add(void)
clear_dir(dir);
}
-static void test_reftable_stack_log_normalize(void)
+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;
struct reftable_write_options opts = {
@@ -576,27 +654,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);
+ 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);
- EXPECT_ERR(err);
+ err = reftable_stack_add(st, write_test_log, &arg);
+ 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);
+ err = reftable_stack_add(st, write_test_log, &arg);
+ check(!err);
err = reftable_stack_read_log(st, input.refname, &dest);
- EXPECT_ERR(err);
- EXPECT(0 == strcmp(dest.value.update.message, "two\n"));
+ check(!err);
+ check_str(dest.value.update.message, "two\n");
/* cleanup */
reftable_stack_destroy(st);
@@ -604,21 +682,20 @@ 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__);
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);
- EXPECT_ERR(err);
+ check(!err);
/* even entries add the refs, odd entries delete them. */
for (i = 0; i < N; i++) {
@@ -641,8 +718,8 @@ 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);
+ int err = reftable_stack_add(st, write_test_ref, &refs[i]);
+ check(!err);
}
for (i = 0; i < N; i++) {
@@ -650,26 +727,26 @@ static void test_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);
- EXPECT_ERR(err);
+ int err = reftable_stack_add(st, write_test_log, &arg);
+ check(!err);
}
err = reftable_stack_read_ref(st, "branch", &dest);
- EXPECT(err == 1);
+ check_int(err, ==, 1);
reftable_ref_record_release(&dest);
err = reftable_stack_read_log(st, "branch", &log_dest);
- EXPECT(err == 1);
+ check_int(err, ==, 1);
reftable_log_record_release(&log_dest);
err = reftable_stack_compact_all(st, NULL);
- EXPECT_ERR(err);
+ check(!err);
err = reftable_stack_read_ref(st, "branch", &dest);
- EXPECT(err == 1);
+ check_int(err, ==, 1);
err = reftable_stack_read_log(st, "branch", &log_dest);
- EXPECT(err == 1);
+ check_int(err, ==, 1);
reftable_ref_record_release(&dest);
reftable_log_record_release(&log_dest);
@@ -682,7 +759,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 };
@@ -699,69 +776,68 @@ static void test_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);
- EXPECT_ERR(err);
+ check(!err);
- err = reftable_stack_add(st, &write_test_ref, &ref);
- EXPECT_ERR(err);
+ err = reftable_stack_add(st, write_test_ref, &ref);
+ 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 };
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);
- EXPECT_ERR(err);
+ 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;
@@ -776,37 +852,36 @@ static void test_reflog_expire(void)
.log = &logs[i],
.update_index = reftable_stack_next_update_index(st),
};
- int err = reftable_stack_add(st, &write_test_log, &arg);
- EXPECT_ERR(err);
+ int err = reftable_stack_add(st, write_test_log, &arg);
+ 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);
- 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);
}
@@ -817,7 +892,7 @@ static int write_nothing(struct reftable_writer *wr, void *arg UNUSED)
return 0;
}
-static void test_empty_add(void)
+static void t_empty_add(void)
{
struct reftable_write_options opts = { 0 };
struct reftable_stack *st = NULL;
@@ -826,40 +901,40 @@ 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);
+ err = reftable_stack_add(st, write_nothing, NULL);
+ 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);
}
-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;
}
-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,
};
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);
- EXPECT_ERR(err);
+ check(!err);
for (i = 0; i < N; i++) {
char name[100];
@@ -869,24 +944,56 @@ static void test_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);
- EXPECT_ERR(err);
+ err = reftable_stack_add(st, write_test_ref, &ref);
+ check(!err);
err = reftable_stack_auto_compact(st);
- EXPECT_ERR(err);
- EXPECT(i < 3 || st->merged->readers_len < 2 * fastlog2(i));
+ check(!err);
+ check(i < 2 || st->merged->readers_len < 2 * fastlogN(i, 2));
}
- 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 * fastlogN(N, 2)));
+
+ reftable_stack_destroy(st);
+ clear_dir(dir);
+}
+
+static void t_reftable_stack_auto_compaction_factor(void)
+{
+ struct reftable_write_options opts = {
+ .auto_compaction_factor = 5,
+ };
+ struct reftable_stack *st = NULL;
+ char *dir = get_tmp_dir(__LINE__);
+ int err;
+ size_t N = 100;
+
+ err = reftable_new_stack(&st, dir, &opts);
+ check(!err);
+
+ for (size_t i = 0; i < N; i++) {
+ char name[20];
+ struct reftable_ref_record ref = {
+ .refname = name,
+ .update_index = reftable_stack_next_update_index(st),
+ .value_type = REFTABLE_REF_VAL1,
+ };
+ xsnprintf(name, sizeof(name), "branch%04"PRIuMAX, (uintmax_t)i);
+
+ err = reftable_stack_add(st, &write_test_ref, &ref);
+ check(!err);
+
+ check(i < 5 || st->merged->readers_len < 5 * fastlogN(i, 5));
+ }
reftable_stack_destroy(st);
clear_dir(dir);
}
-static void test_reftable_stack_auto_compaction_with_locked_tables(void)
+static void t_reftable_stack_auto_compaction_with_locked_tables(void)
{
struct reftable_write_options opts = {
.disable_auto_compact = 1,
@@ -897,10 +1004,10 @@ static void test_reftable_stack_auto_compaction_with_locked_tables(void)
int err;
err = reftable_new_stack(&st, dir, &opts);
- EXPECT_ERR(err);
+ check(!err);
write_n_ref_tables(st, 5);
- EXPECT(st->merged->readers_len == 5);
+ check_int(st->merged->readers_len, ==, 5);
/*
* Given that all tables we have written should be roughly the same
@@ -918,25 +1025,26 @@ static void test_reftable_stack_auto_compaction_with_locked_tables(void)
* only compact the newest two tables.
*/
err = reftable_stack_auto_compact(st);
- EXPECT_ERR(err);
- EXPECT(st->stats.failures == 0);
- EXPECT(st->merged->readers_len == 4);
+ check(!err);
+ check_int(st->stats.failures, ==, 0);
+ check_int(st->merged->readers_len, ==, 4);
reftable_stack_destroy(st);
strbuf_release(&buf);
clear_dir(dir);
}
-static void test_reftable_stack_add_performs_auto_compaction(void)
+static void t_reftable_stack_add_performs_auto_compaction(void)
{
struct reftable_write_options opts = { 0 };
struct reftable_stack *st = NULL;
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);
- EXPECT_ERR(err);
+ check(!err);
for (i = 0; i <= n; i++) {
struct reftable_ref_record ref = {
@@ -953,11 +1061,11 @@ static void test_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);
- EXPECT_ERR(err);
+ err = reftable_stack_add(st, write_test_ref, &ref);
+ check(!err);
/*
* The stack length should grow continuously for all runs where
@@ -965,9 +1073,9 @@ static void test_reftable_stack_add_performs_auto_compaction(void)
* all tables in the stack.
*/
if (i != n)
- EXPECT(st->merged->readers_len == i + 1);
+ check_int(st->merged->readers_len, ==, i + 1);
else
- EXPECT(st->merged->readers_len == 1);
+ check_int(st->merged->readers_len, ==, 1);
}
reftable_stack_destroy(st);
@@ -975,7 +1083,7 @@ static void test_reftable_stack_add_performs_auto_compaction(void)
clear_dir(dir);
}
-static void test_reftable_stack_compaction_with_locked_tables(void)
+static void t_reftable_stack_compaction_with_locked_tables(void)
{
struct reftable_write_options opts = {
.disable_auto_compact = 1,
@@ -986,10 +1094,10 @@ static void test_reftable_stack_compaction_with_locked_tables(void)
int err;
err = reftable_new_stack(&st, dir, &opts);
- EXPECT_ERR(err);
+ check(!err);
write_n_ref_tables(st, 3);
- EXPECT(st->merged->readers_len == 3);
+ check_int(st->merged->readers_len, ==, 3);
/* Lock one of the tables that we're about to compact. */
strbuf_reset(&buf);
@@ -1001,16 +1109,16 @@ static void test_reftable_stack_compaction_with_locked_tables(void)
* compact all tables.
*/
err = reftable_stack_compact_all(st, NULL);
- EXPECT(err == REFTABLE_LOCK_ERROR);
- EXPECT(st->stats.failures == 1);
- EXPECT(st->merged->readers_len == 3);
+ check_int(err, ==, REFTABLE_LOCK_ERROR);
+ check_int(st->stats.failures, ==, 1);
+ check_int(st->merged->readers_len, ==, 3);
reftable_stack_destroy(st);
strbuf_release(&buf);
clear_dir(dir);
}
-static void test_reftable_stack_compaction_concurrent(void)
+static void t_reftable_stack_compaction_concurrent(void)
{
struct reftable_write_options opts = { 0 };
struct reftable_stack *st1 = NULL, *st2 = NULL;
@@ -1018,19 +1126,19 @@ static void test_reftable_stack_compaction_concurrent(void)
int err;
err = reftable_new_stack(&st1, dir, &opts);
- EXPECT_ERR(err);
+ check(!err);
write_n_ref_tables(st1, 3);
err = reftable_new_stack(&st2, dir, &opts);
- EXPECT_ERR(err);
+ check(!err);
err = reftable_stack_compact_all(st1, NULL);
- EXPECT_ERR(err);
+ check(!err);
reftable_stack_destroy(st1);
reftable_stack_destroy(st2);
- EXPECT(count_dir_entries(dir) == 2);
+ check_int(count_dir_entries(dir), ==, 2);
clear_dir(dir);
}
@@ -1043,7 +1151,7 @@ static void unclean_stack_close(struct reftable_stack *st)
FREE_AND_NULL(st->readers);
}
-static void test_reftable_stack_compaction_concurrent_clean(void)
+static void t_reftable_stack_compaction_concurrent_clean(void)
{
struct reftable_write_options opts = { 0 };
struct reftable_stack *st1 = NULL, *st2 = NULL, *st3 = NULL;
@@ -1051,24 +1159,24 @@ static void test_reftable_stack_compaction_concurrent_clean(void)
int err;
err = reftable_new_stack(&st1, dir, &opts);
- EXPECT_ERR(err);
+ check(!err);
write_n_ref_tables(st1, 3);
err = reftable_new_stack(&st2, dir, &opts);
- EXPECT_ERR(err);
+ check(!err);
err = reftable_stack_compact_all(st1, NULL);
- EXPECT_ERR(err);
+ check(!err);
unclean_stack_close(st1);
unclean_stack_close(st2);
err = reftable_new_stack(&st3, dir, &opts);
- EXPECT_ERR(err);
+ check(!err);
err = reftable_stack_clean(st3);
- EXPECT_ERR(err);
- EXPECT(count_dir_entries(dir) == 2);
+ check(!err);
+ check_int(count_dir_entries(dir), ==, 2);
reftable_stack_destroy(st1);
reftable_stack_destroy(st2);
@@ -1077,7 +1185,7 @@ static void test_reftable_stack_compaction_concurrent_clean(void)
clear_dir(dir);
}
-static void test_reftable_stack_read_across_reload(void)
+static void t_reftable_stack_read_across_reload(void)
{
struct reftable_write_options opts = { 0 };
struct reftable_stack *st1 = NULL, *st2 = NULL;
@@ -1088,36 +1196,36 @@ static void test_reftable_stack_read_across_reload(void)
/* Create a first stack and set up an iterator for it. */
err = reftable_new_stack(&st1, dir, &opts);
- EXPECT_ERR(err);
+ check(!err);
write_n_ref_tables(st1, 2);
- EXPECT(st1->merged->readers_len == 2);
+ check_int(st1->merged->readers_len, ==, 2);
reftable_stack_init_ref_iterator(st1, &it);
err = reftable_iterator_seek_ref(&it, "");
- EXPECT_ERR(err);
+ check(!err);
/* Set up a second stack for the same directory and compact it. */
err = reftable_new_stack(&st2, dir, &opts);
- EXPECT_ERR(err);
- EXPECT(st2->merged->readers_len == 2);
+ check(!err);
+ check_int(st2->merged->readers_len, ==, 2);
err = reftable_stack_compact_all(st2, NULL);
- EXPECT_ERR(err);
- EXPECT(st2->merged->readers_len == 1);
+ check(!err);
+ check_int(st2->merged->readers_len, ==, 1);
/*
* Verify that we can continue to use the old iterator even after we
* have reloaded its stack.
*/
err = reftable_stack_reload(st1);
- EXPECT_ERR(err);
- EXPECT(st1->merged->readers_len == 1);
+ check(!err);
+ check_int(st1->merged->readers_len, ==, 1);
err = reftable_iterator_next_ref(&it, &rec);
- EXPECT_ERR(err);
- EXPECT(!strcmp(rec.refname, "refs/heads/branch-0000"));
+ check(!err);
+ check_str(rec.refname, "refs/heads/branch-0000");
err = reftable_iterator_next_ref(&it, &rec);
- EXPECT_ERR(err);
- EXPECT(!strcmp(rec.refname, "refs/heads/branch-0001"));
+ check(!err);
+ check_str(rec.refname, "refs/heads/branch-0001");
err = reftable_iterator_next_ref(&it, &rec);
- EXPECT(err > 0);
+ check_int(err, >, 0);
reftable_ref_record_release(&rec);
reftable_iterator_destroy(&it);
@@ -1126,7 +1234,7 @@ static void test_reftable_stack_read_across_reload(void)
clear_dir(dir);
}
-static void test_reftable_stack_reload_with_missing_table(void)
+static void t_reftable_stack_reload_with_missing_table(void)
{
struct reftable_write_options opts = { 0 };
struct reftable_stack *st = NULL;
@@ -1138,12 +1246,12 @@ static void test_reftable_stack_reload_with_missing_table(void)
/* Create a first stack and set up an iterator for it. */
err = reftable_new_stack(&st, dir, &opts);
- EXPECT_ERR(err);
+ check(!err);
write_n_ref_tables(st, 2);
- EXPECT(st->merged->readers_len == 2);
+ check_int(st->merged->readers_len, ==, 2);
reftable_stack_init_ref_iterator(st, &it);
err = reftable_iterator_seek_ref(&it, "");
- EXPECT_ERR(err);
+ check(!err);
/*
* Update the tables.list file with some garbage data, while reusing
@@ -1156,24 +1264,24 @@ static void test_reftable_stack_reload_with_missing_table(void)
strbuf_addf(&table_path, "%s.lock", st->list_file);
write_file_buf(table_path.buf, content.buf, content.len);
err = rename(table_path.buf, st->list_file);
- EXPECT_ERR(err);
+ check(!err);
err = reftable_stack_reload(st);
- EXPECT(err == -4);
- EXPECT(st->merged->readers_len == 2);
+ check_int(err, ==, -4);
+ check_int(st->merged->readers_len, ==, 2);
/*
* Even though the reload has failed, we should be able to continue
* using the iterator.
*/
err = reftable_iterator_next_ref(&it, &rec);
- EXPECT_ERR(err);
- EXPECT(!strcmp(rec.refname, "refs/heads/branch-0000"));
+ check(!err);
+ check_str(rec.refname, "refs/heads/branch-0000");
err = reftable_iterator_next_ref(&it, &rec);
- EXPECT_ERR(err);
- EXPECT(!strcmp(rec.refname, "refs/heads/branch-0001"));
+ check(!err);
+ check_str(rec.refname, "refs/heads/branch-0001");
err = reftable_iterator_next_ref(&it, &rec);
- EXPECT(err > 0);
+ check_int(err, >, 0);
reftable_ref_record_release(&rec);
reftable_iterator_destroy(&it);
@@ -1183,31 +1291,34 @@ static void test_reftable_stack_reload_with_missing_table(void)
clear_dir(dir);
}
-int stack_test_main(int argc UNUSED, const char *argv[] UNUSED)
+int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
{
- RUN_TEST(test_empty_add);
- RUN_TEST(test_read_file);
- RUN_TEST(test_reflog_expire);
- RUN_TEST(test_reftable_stack_add);
- RUN_TEST(test_reftable_stack_add_one);
- RUN_TEST(test_reftable_stack_auto_compaction);
- RUN_TEST(test_reftable_stack_auto_compaction_with_locked_tables);
- RUN_TEST(test_reftable_stack_add_performs_auto_compaction);
- RUN_TEST(test_reftable_stack_compaction_concurrent);
- RUN_TEST(test_reftable_stack_compaction_concurrent_clean);
- RUN_TEST(test_reftable_stack_compaction_with_locked_tables);
- RUN_TEST(test_reftable_stack_hash_id);
- RUN_TEST(test_reftable_stack_lock_failure);
- RUN_TEST(test_reftable_stack_log_normalize);
- RUN_TEST(test_reftable_stack_tombstone);
- RUN_TEST(test_reftable_stack_transaction_api);
- RUN_TEST(test_reftable_stack_transaction_api_performs_auto_compaction);
- RUN_TEST(test_reftable_stack_auto_compaction_fails_gracefully);
- RUN_TEST(test_reftable_stack_update_index_check);
- RUN_TEST(test_reftable_stack_uptodate);
- RUN_TEST(test_reftable_stack_read_across_reload);
- RUN_TEST(test_reftable_stack_reload_with_missing_table);
- RUN_TEST(test_suggest_compaction_segment);
- RUN_TEST(test_suggest_compaction_segment_nothing);
- return 0;
+ TEST(t_empty_add(), "empty addition to stack");
+ TEST(t_read_file(), "read_lines works");
+ TEST(t_reflog_expire(), "expire reflog entries");
+ TEST(t_reftable_stack_add(), "add multiple refs and logs to stack");
+ TEST(t_reftable_stack_add_one(), "add a single ref record to stack");
+ TEST(t_reftable_stack_add_performs_auto_compaction(), "addition to stack triggers auto-compaction");
+ TEST(t_reftable_stack_auto_compaction(), "stack must form geometric sequence after compaction");
+ TEST(t_reftable_stack_auto_compaction_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");
+ TEST(t_reftable_stack_compaction_concurrent_clean(), "compaction with unclean stack shutdown");
+ TEST(t_reftable_stack_compaction_with_locked_tables(), "compaction with locked tables");
+ TEST(t_reftable_stack_hash_id(), "read stack with wrong hash ID");
+ TEST(t_reftable_stack_iterator(), "log and ref iterator for reftable stack");
+ TEST(t_reftable_stack_lock_failure(), "stack addition with lockfile failure");
+ TEST(t_reftable_stack_log_normalize(), "log messages should be normalized");
+ TEST(t_reftable_stack_read_across_reload(), "stack iterators work across reloads");
+ TEST(t_reftable_stack_reload_with_missing_table(), "stack iteration with garbage tables");
+ TEST(t_reftable_stack_tombstone(), "'tombstone' refs in stack");
+ TEST(t_reftable_stack_transaction_api(), "update transaction to stack");
+ TEST(t_reftable_stack_transaction_api_performs_auto_compaction(), "update transaction triggers auto-compaction");
+ TEST(t_reftable_stack_update_index_check(), "update transactions with equal update indices");
+ TEST(t_reftable_stack_uptodate(), "stack must be reloaded before ref update");
+ TEST(t_suggest_compaction_segment(), "suggest_compaction_segment with basic input");
+ TEST(t_suggest_compaction_segment_nothing(), "suggest_compaction_segment with pre-compacted input");
+
+ return test_done();
}