git/reftable/test_framework.h
John Cai 1df18a1c9a reftable: honor core.fsync
While the reffiles backend honors configured fsync settings, the
reftable backend does not. Address this by fsyncing reftable files using
the write-or-die api's fsync_component() in two places: when we
add additional entries into the table, and when we close the reftable
writer.

This commits adds a flush function pointer as a new member of
reftable_writer because we are not sure that the first argument to the
*write function pointer always contains a file descriptor. In the case of
strbuf_add_void, the first argument is a buffer. This way, we can pass
in a corresponding flush function that knows how to flush depending on
which writer is being used.

This patch does not contain tests as they will need to wait for another
patch to start to exercise the reftable backend. At that point, the
tests will be added to observe that fsyncs are happening when the
reftable is in use.

Signed-off-by: John Cai <johncai86@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-01-23 13:45:27 -08:00

62 lines
2.4 KiB
C

/*
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