mirror of
https://github.com/git/git.git
synced 2024-09-08 03:50:44 +02:00
Merge branch 'cp/unit-test-reftable-merged' into next
Another reftable test has been ported to use the unit test framework. * cp/unit-test-reftable-merged: t-reftable-merged: add test for REFTABLE_FORMAT_ERROR t-reftable-merged: use reftable_ref_record_equal to compare ref records t-reftable-merged: add tests for reftable_merged_table_max_update_index t-reftable-merged: improve the const-correctness of helper functions t-reftable-merged: improve the test t_merged_single_record() t: harmonize t-reftable-merged.c with coding guidelines t: move reftable/merged_test.c to the unit testing framework
This commit is contained in:
commit
88d2a9ee28
2
Makefile
2
Makefile
@ -1340,6 +1340,7 @@ UNIT_TEST_PROGRAMS += t-oidmap
|
||||
UNIT_TEST_PROGRAMS += t-oidtree
|
||||
UNIT_TEST_PROGRAMS += t-prio-queue
|
||||
UNIT_TEST_PROGRAMS += t-reftable-basics
|
||||
UNIT_TEST_PROGRAMS += t-reftable-merged
|
||||
UNIT_TEST_PROGRAMS += t-reftable-record
|
||||
UNIT_TEST_PROGRAMS += t-strbuf
|
||||
UNIT_TEST_PROGRAMS += t-strcmp-offset
|
||||
@ -2680,7 +2681,6 @@ REFTABLE_OBJS += reftable/writer.o
|
||||
|
||||
REFTABLE_TEST_OBJS += reftable/block_test.o
|
||||
REFTABLE_TEST_OBJS += reftable/dump.o
|
||||
REFTABLE_TEST_OBJS += reftable/merged_test.o
|
||||
REFTABLE_TEST_OBJS += reftable/pq_test.o
|
||||
REFTABLE_TEST_OBJS += reftable/readwrite_test.o
|
||||
REFTABLE_TEST_OBJS += reftable/stack_test.o
|
||||
|
@ -11,7 +11,6 @@ https://developers.google.com/open-source/licenses/bsd
|
||||
|
||||
int basics_test_main(int argc, const char **argv);
|
||||
int block_test_main(int argc, const char **argv);
|
||||
int merged_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);
|
||||
|
@ -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);
|
||||
merged_test_main(argc, argv);
|
||||
stack_test_main(argc, argv);
|
||||
return 0;
|
||||
}
|
||||
|
@ -6,27 +6,33 @@ license that can be found in the LICENSE file or at
|
||||
https://developers.google.com/open-source/licenses/bsd
|
||||
*/
|
||||
|
||||
#include "merged.h"
|
||||
#include "test-lib.h"
|
||||
#include "reftable/blocksource.h"
|
||||
#include "reftable/constants.h"
|
||||
#include "reftable/merged.h"
|
||||
#include "reftable/reader.h"
|
||||
#include "reftable/reftable-error.h"
|
||||
#include "reftable/reftable-generic.h"
|
||||
#include "reftable/reftable-merged.h"
|
||||
#include "reftable/reftable-writer.h"
|
||||
|
||||
#include "system.h"
|
||||
static ssize_t strbuf_add_void(void *b, const void *data, const size_t sz)
|
||||
{
|
||||
strbuf_add(b, data, sz);
|
||||
return sz;
|
||||
}
|
||||
|
||||
#include "basics.h"
|
||||
#include "blocksource.h"
|
||||
#include "constants.h"
|
||||
#include "reader.h"
|
||||
#include "record.h"
|
||||
#include "test_framework.h"
|
||||
#include "reftable-merged.h"
|
||||
#include "reftable-tests.h"
|
||||
#include "reftable-generic.h"
|
||||
#include "reftable-writer.h"
|
||||
static int noop_flush(void *arg)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void write_test_table(struct strbuf *buf,
|
||||
struct reftable_ref_record refs[], int n)
|
||||
struct reftable_ref_record refs[], const size_t n)
|
||||
{
|
||||
uint64_t min = 0xffffffff;
|
||||
uint64_t max = 0;
|
||||
int i = 0;
|
||||
size_t i;
|
||||
int err;
|
||||
|
||||
struct reftable_write_options opts = {
|
||||
@ -35,12 +41,10 @@ static void write_test_table(struct strbuf *buf,
|
||||
struct reftable_writer *w = NULL;
|
||||
for (i = 0; i < n; i++) {
|
||||
uint64_t ui = refs[i].update_index;
|
||||
if (ui > max) {
|
||||
if (ui > max)
|
||||
max = ui;
|
||||
}
|
||||
if (ui < min) {
|
||||
if (ui < min)
|
||||
min = ui;
|
||||
}
|
||||
}
|
||||
|
||||
w = reftable_new_writer(&strbuf_add_void, &noop_flush, buf, &opts);
|
||||
@ -49,21 +53,19 @@ static void write_test_table(struct strbuf *buf,
|
||||
for (i = 0; i < n; i++) {
|
||||
uint64_t before = refs[i].update_index;
|
||||
int n = reftable_writer_add_ref(w, &refs[i]);
|
||||
EXPECT(n == 0);
|
||||
EXPECT(before == refs[i].update_index);
|
||||
check_int(n, ==, 0);
|
||||
check_int(before, ==, refs[i].update_index);
|
||||
}
|
||||
|
||||
err = reftable_writer_close(w);
|
||||
EXPECT_ERR(err);
|
||||
check(!err);
|
||||
|
||||
reftable_writer_free(w);
|
||||
}
|
||||
|
||||
static void write_test_log_table(struct strbuf *buf,
|
||||
struct reftable_log_record logs[], int n,
|
||||
uint64_t update_index)
|
||||
static void write_test_log_table(struct strbuf *buf, struct reftable_log_record logs[],
|
||||
const size_t n, const uint64_t update_index)
|
||||
{
|
||||
int i = 0;
|
||||
int err;
|
||||
|
||||
struct reftable_write_options opts = {
|
||||
@ -74,13 +76,13 @@ static void write_test_log_table(struct strbuf *buf,
|
||||
w = reftable_new_writer(&strbuf_add_void, &noop_flush, buf, &opts);
|
||||
reftable_writer_set_limits(w, update_index, update_index);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
int err = reftable_writer_add_log(w, &logs[i]);
|
||||
EXPECT_ERR(err);
|
||||
check(!err);
|
||||
}
|
||||
|
||||
err = reftable_writer_close(w);
|
||||
EXPECT_ERR(err);
|
||||
check(!err);
|
||||
|
||||
reftable_writer_free(w);
|
||||
}
|
||||
@ -88,8 +90,8 @@ static void write_test_log_table(struct strbuf *buf,
|
||||
static struct reftable_merged_table *
|
||||
merged_table_from_records(struct reftable_ref_record **refs,
|
||||
struct reftable_block_source **source,
|
||||
struct reftable_reader ***readers, int *sizes,
|
||||
struct strbuf *buf, size_t n)
|
||||
struct reftable_reader ***readers, const size_t *sizes,
|
||||
struct strbuf *buf, const size_t n)
|
||||
{
|
||||
struct reftable_merged_table *mt = NULL;
|
||||
struct reftable_table *tabs;
|
||||
@ -105,24 +107,23 @@ merged_table_from_records(struct reftable_ref_record **refs,
|
||||
|
||||
err = reftable_new_reader(&(*readers)[i], &(*source)[i],
|
||||
"name");
|
||||
EXPECT_ERR(err);
|
||||
check(!err);
|
||||
reftable_table_from_reader(&tabs[i], (*readers)[i]);
|
||||
}
|
||||
|
||||
err = reftable_new_merged_table(&mt, tabs, n, GIT_SHA1_FORMAT_ID);
|
||||
EXPECT_ERR(err);
|
||||
check(!err);
|
||||
return mt;
|
||||
}
|
||||
|
||||
static void readers_destroy(struct reftable_reader **readers, size_t n)
|
||||
static void readers_destroy(struct reftable_reader **readers, const size_t n)
|
||||
{
|
||||
int i = 0;
|
||||
for (; i < n; i++)
|
||||
for (size_t i = 0; i < n; i++)
|
||||
reftable_reader_free(readers[i]);
|
||||
reftable_free(readers);
|
||||
}
|
||||
|
||||
static void test_merged_between(void)
|
||||
static void t_merged_single_record(void)
|
||||
{
|
||||
struct reftable_ref_record r1[] = { {
|
||||
.refname = (char *) "b",
|
||||
@ -135,37 +136,40 @@ static void test_merged_between(void)
|
||||
.update_index = 2,
|
||||
.value_type = REFTABLE_REF_DELETION,
|
||||
} };
|
||||
struct reftable_ref_record r3[] = { {
|
||||
.refname = (char *) "c",
|
||||
.update_index = 3,
|
||||
.value_type = REFTABLE_REF_DELETION,
|
||||
} };
|
||||
|
||||
struct reftable_ref_record *refs[] = { r1, r2 };
|
||||
int sizes[] = { 1, 1 };
|
||||
struct strbuf bufs[2] = { STRBUF_INIT, STRBUF_INIT };
|
||||
struct reftable_ref_record *refs[] = { r1, r2, r3 };
|
||||
size_t sizes[] = { ARRAY_SIZE(r1), ARRAY_SIZE(r2), ARRAY_SIZE(r3) };
|
||||
struct strbuf bufs[3] = { STRBUF_INIT, STRBUF_INIT, STRBUF_INIT };
|
||||
struct reftable_block_source *bs = NULL;
|
||||
struct reftable_reader **readers = NULL;
|
||||
struct reftable_merged_table *mt =
|
||||
merged_table_from_records(refs, &bs, &readers, sizes, bufs, 2);
|
||||
int i;
|
||||
struct reftable_ref_record ref = { NULL };
|
||||
struct reftable_iterator it = { NULL };
|
||||
merged_table_from_records(refs, &bs, &readers, sizes, bufs, 3);
|
||||
struct reftable_ref_record ref = { 0 };
|
||||
struct reftable_iterator it = { 0 };
|
||||
int err;
|
||||
|
||||
merged_table_init_iter(mt, &it, BLOCK_TYPE_REF);
|
||||
err = reftable_iterator_seek_ref(&it, "a");
|
||||
EXPECT_ERR(err);
|
||||
check(!err);
|
||||
|
||||
err = reftable_iterator_next_ref(&it, &ref);
|
||||
EXPECT_ERR(err);
|
||||
EXPECT(ref.update_index == 2);
|
||||
check(!err);
|
||||
check(reftable_ref_record_equal(&r2[0], &ref, GIT_SHA1_RAWSZ));
|
||||
reftable_ref_record_release(&ref);
|
||||
reftable_iterator_destroy(&it);
|
||||
readers_destroy(readers, 2);
|
||||
readers_destroy(readers, 3);
|
||||
reftable_merged_table_free(mt);
|
||||
for (i = 0; i < ARRAY_SIZE(bufs); i++) {
|
||||
for (size_t i = 0; i < ARRAY_SIZE(bufs); i++)
|
||||
strbuf_release(&bufs[i]);
|
||||
}
|
||||
reftable_free(bs);
|
||||
}
|
||||
|
||||
static void test_merged(void)
|
||||
static void t_merged_refs(void)
|
||||
{
|
||||
struct reftable_ref_record r1[] = {
|
||||
{
|
||||
@ -215,27 +219,28 @@ static void test_merged(void)
|
||||
};
|
||||
|
||||
struct reftable_ref_record *refs[] = { r1, r2, r3 };
|
||||
int sizes[3] = { 3, 1, 2 };
|
||||
size_t sizes[3] = { ARRAY_SIZE(r1), ARRAY_SIZE(r2), ARRAY_SIZE(r3) };
|
||||
struct strbuf bufs[3] = { STRBUF_INIT, STRBUF_INIT, STRBUF_INIT };
|
||||
struct reftable_block_source *bs = NULL;
|
||||
struct reftable_reader **readers = NULL;
|
||||
struct reftable_merged_table *mt =
|
||||
merged_table_from_records(refs, &bs, &readers, sizes, bufs, 3);
|
||||
struct reftable_iterator it = { NULL };
|
||||
struct reftable_iterator it = { 0 };
|
||||
int err;
|
||||
struct reftable_ref_record *out = NULL;
|
||||
size_t len = 0;
|
||||
size_t cap = 0;
|
||||
int i = 0;
|
||||
size_t i;
|
||||
|
||||
merged_table_init_iter(mt, &it, BLOCK_TYPE_REF);
|
||||
err = reftable_iterator_seek_ref(&it, "a");
|
||||
EXPECT_ERR(err);
|
||||
EXPECT(reftable_merged_table_hash_id(mt) == GIT_SHA1_FORMAT_ID);
|
||||
EXPECT(reftable_merged_table_min_update_index(mt) == 1);
|
||||
check(!err);
|
||||
check_int(reftable_merged_table_hash_id(mt), ==, GIT_SHA1_FORMAT_ID);
|
||||
check_int(reftable_merged_table_min_update_index(mt), ==, 1);
|
||||
check_int(reftable_merged_table_max_update_index(mt), ==, 3);
|
||||
|
||||
while (len < 100) { /* cap loops/recursion. */
|
||||
struct reftable_ref_record ref = { NULL };
|
||||
struct reftable_ref_record ref = { 0 };
|
||||
int err = reftable_iterator_next_ref(&it, &ref);
|
||||
if (err > 0)
|
||||
break;
|
||||
@ -245,19 +250,16 @@ static void test_merged(void)
|
||||
}
|
||||
reftable_iterator_destroy(&it);
|
||||
|
||||
EXPECT(ARRAY_SIZE(want) == len);
|
||||
for (i = 0; i < len; i++) {
|
||||
EXPECT(reftable_ref_record_equal(want[i], &out[i],
|
||||
check_int(ARRAY_SIZE(want), ==, len);
|
||||
for (i = 0; i < len; i++)
|
||||
check(reftable_ref_record_equal(want[i], &out[i],
|
||||
GIT_SHA1_RAWSZ));
|
||||
}
|
||||
for (i = 0; i < len; i++) {
|
||||
for (i = 0; i < len; i++)
|
||||
reftable_ref_record_release(&out[i]);
|
||||
}
|
||||
reftable_free(out);
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
for (i = 0; i < 3; i++)
|
||||
strbuf_release(&bufs[i]);
|
||||
}
|
||||
readers_destroy(readers, 3);
|
||||
reftable_merged_table_free(mt);
|
||||
reftable_free(bs);
|
||||
@ -266,8 +268,8 @@ static void test_merged(void)
|
||||
static struct reftable_merged_table *
|
||||
merged_table_from_log_records(struct reftable_log_record **logs,
|
||||
struct reftable_block_source **source,
|
||||
struct reftable_reader ***readers, int *sizes,
|
||||
struct strbuf *buf, size_t n)
|
||||
struct reftable_reader ***readers, const size_t *sizes,
|
||||
struct strbuf *buf, const size_t n)
|
||||
{
|
||||
struct reftable_merged_table *mt = NULL;
|
||||
struct reftable_table *tabs;
|
||||
@ -283,16 +285,16 @@ merged_table_from_log_records(struct reftable_log_record **logs,
|
||||
|
||||
err = reftable_new_reader(&(*readers)[i], &(*source)[i],
|
||||
"name");
|
||||
EXPECT_ERR(err);
|
||||
check(!err);
|
||||
reftable_table_from_reader(&tabs[i], (*readers)[i]);
|
||||
}
|
||||
|
||||
err = reftable_new_merged_table(&mt, tabs, n, GIT_SHA1_FORMAT_ID);
|
||||
EXPECT_ERR(err);
|
||||
check(!err);
|
||||
return mt;
|
||||
}
|
||||
|
||||
static void test_merged_logs(void)
|
||||
static void t_merged_logs(void)
|
||||
{
|
||||
struct reftable_log_record r1[] = {
|
||||
{
|
||||
@ -347,27 +349,28 @@ static void test_merged_logs(void)
|
||||
};
|
||||
|
||||
struct reftable_log_record *logs[] = { r1, r2, r3 };
|
||||
int sizes[3] = { 2, 1, 1 };
|
||||
size_t sizes[3] = { ARRAY_SIZE(r1), ARRAY_SIZE(r2), ARRAY_SIZE(r3) };
|
||||
struct strbuf bufs[3] = { STRBUF_INIT, STRBUF_INIT, STRBUF_INIT };
|
||||
struct reftable_block_source *bs = NULL;
|
||||
struct reftable_reader **readers = NULL;
|
||||
struct reftable_merged_table *mt = merged_table_from_log_records(
|
||||
logs, &bs, &readers, sizes, bufs, 3);
|
||||
struct reftable_iterator it = { NULL };
|
||||
struct reftable_iterator it = { 0 };
|
||||
int err;
|
||||
struct reftable_log_record *out = NULL;
|
||||
size_t len = 0;
|
||||
size_t cap = 0;
|
||||
int i = 0;
|
||||
size_t i;
|
||||
|
||||
merged_table_init_iter(mt, &it, BLOCK_TYPE_LOG);
|
||||
err = reftable_iterator_seek_log(&it, "a");
|
||||
EXPECT_ERR(err);
|
||||
EXPECT(reftable_merged_table_hash_id(mt) == GIT_SHA1_FORMAT_ID);
|
||||
EXPECT(reftable_merged_table_min_update_index(mt) == 1);
|
||||
check(!err);
|
||||
check_int(reftable_merged_table_hash_id(mt), ==, GIT_SHA1_FORMAT_ID);
|
||||
check_int(reftable_merged_table_min_update_index(mt), ==, 1);
|
||||
check_int(reftable_merged_table_max_update_index(mt), ==, 3);
|
||||
|
||||
while (len < 100) { /* cap loops/recursion. */
|
||||
struct reftable_log_record log = { NULL };
|
||||
struct reftable_log_record log = { 0 };
|
||||
int err = reftable_iterator_next_log(&it, &log);
|
||||
if (err > 0)
|
||||
break;
|
||||
@ -377,35 +380,32 @@ static void test_merged_logs(void)
|
||||
}
|
||||
reftable_iterator_destroy(&it);
|
||||
|
||||
EXPECT(ARRAY_SIZE(want) == len);
|
||||
for (i = 0; i < len; i++) {
|
||||
EXPECT(reftable_log_record_equal(want[i], &out[i],
|
||||
check_int(ARRAY_SIZE(want), ==, len);
|
||||
for (i = 0; i < len; i++)
|
||||
check(reftable_log_record_equal(want[i], &out[i],
|
||||
GIT_SHA1_RAWSZ));
|
||||
}
|
||||
|
||||
merged_table_init_iter(mt, &it, BLOCK_TYPE_LOG);
|
||||
err = reftable_iterator_seek_log_at(&it, "a", 2);
|
||||
EXPECT_ERR(err);
|
||||
check(!err);
|
||||
reftable_log_record_release(&out[0]);
|
||||
err = reftable_iterator_next_log(&it, &out[0]);
|
||||
EXPECT_ERR(err);
|
||||
EXPECT(reftable_log_record_equal(&out[0], &r3[0], GIT_SHA1_RAWSZ));
|
||||
check(!err);
|
||||
check(reftable_log_record_equal(&out[0], &r3[0], GIT_SHA1_RAWSZ));
|
||||
reftable_iterator_destroy(&it);
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
for (i = 0; i < len; i++)
|
||||
reftable_log_record_release(&out[i]);
|
||||
}
|
||||
reftable_free(out);
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
for (i = 0; i < 3; i++)
|
||||
strbuf_release(&bufs[i]);
|
||||
}
|
||||
readers_destroy(readers, 3);
|
||||
reftable_merged_table_free(mt);
|
||||
reftable_free(bs);
|
||||
}
|
||||
|
||||
static void test_default_write_opts(void)
|
||||
static void t_default_write_opts(void)
|
||||
{
|
||||
struct reftable_write_options opts = { 0 };
|
||||
struct strbuf buf = STRBUF_INIT;
|
||||
@ -417,7 +417,7 @@ static void test_default_write_opts(void)
|
||||
.update_index = 1,
|
||||
};
|
||||
int err;
|
||||
struct reftable_block_source source = { NULL };
|
||||
struct reftable_block_source source = { 0 };
|
||||
struct reftable_table *tab = reftable_calloc(1, sizeof(*tab));
|
||||
uint32_t hash_id;
|
||||
struct reftable_reader *rd = NULL;
|
||||
@ -426,36 +426,38 @@ static void test_default_write_opts(void)
|
||||
reftable_writer_set_limits(w, 1, 1);
|
||||
|
||||
err = reftable_writer_add_ref(w, &rec);
|
||||
EXPECT_ERR(err);
|
||||
check(!err);
|
||||
|
||||
err = reftable_writer_close(w);
|
||||
EXPECT_ERR(err);
|
||||
check(!err);
|
||||
reftable_writer_free(w);
|
||||
|
||||
block_source_from_strbuf(&source, &buf);
|
||||
|
||||
err = reftable_new_reader(&rd, &source, "filename");
|
||||
EXPECT_ERR(err);
|
||||
check(!err);
|
||||
|
||||
hash_id = reftable_reader_hash_id(rd);
|
||||
EXPECT(hash_id == GIT_SHA1_FORMAT_ID);
|
||||
check_int(hash_id, ==, GIT_SHA1_FORMAT_ID);
|
||||
|
||||
reftable_table_from_reader(&tab[0], rd);
|
||||
err = reftable_new_merged_table(&merged, tab, 1, GIT_SHA256_FORMAT_ID);
|
||||
check_int(err, ==, REFTABLE_FORMAT_ERROR);
|
||||
err = reftable_new_merged_table(&merged, tab, 1, GIT_SHA1_FORMAT_ID);
|
||||
EXPECT_ERR(err);
|
||||
check(!err);
|
||||
|
||||
reftable_reader_free(rd);
|
||||
reftable_merged_table_free(merged);
|
||||
strbuf_release(&buf);
|
||||
}
|
||||
|
||||
/* XXX test refs_for(oid) */
|
||||
|
||||
int merged_test_main(int argc, const char *argv[])
|
||||
int cmd_main(int argc, const char *argv[])
|
||||
{
|
||||
RUN_TEST(test_merged_logs);
|
||||
RUN_TEST(test_merged_between);
|
||||
RUN_TEST(test_merged);
|
||||
RUN_TEST(test_default_write_opts);
|
||||
return 0;
|
||||
TEST(t_default_write_opts(), "merged table with default write opts");
|
||||
TEST(t_merged_logs(), "merged table with multiple log updates for same ref");
|
||||
TEST(t_merged_refs(), "merged table with multiple updates to same ref");
|
||||
TEST(t_merged_single_record(), "ref ocurring in only one record can be fetched");
|
||||
|
||||
return test_done();
|
||||
}
|
Loading…
Reference in New Issue
Block a user