Skip to content

Commit 3e1adee

Browse files
dschoGit for Windows Build Agent
authored and
Git for Windows Build Agent
committed
WIP reftable(unit-tests): do make sure to use custom allocators
Just like the preceding commit, this ensures that the tests run with any custom allocator (such as mimalloc) if Git has been configured to be built with one. This addresses the same symptom, this time in the `t/unit-tests/*.exe` programs: exit code 127 (which really is `STATUS_HEAP_CORRUPTION` clamped to the maximal 7-bit value). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 45a247e commit 3e1adee

10 files changed

+30
-0
lines changed

t/unit-tests/lib-reftable.c

+16
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
#define DISABLE_SIGN_COMPARE_WARNINGS
22

3+
#include "git-compat-util.h"
4+
5+
/*
6+
* Save pointers to the custom allocator, if any: `reftable/basics.h` (included
7+
* by `lib-reftable.h`) will simply #undef these if they had been defined, and
8+
* the information would then be lost.
9+
*/
10+
static void *(*git_malloc)(size_t) = malloc;
11+
static void *(*git_realloc)(void *, size_t) = realloc;
12+
static void (*git_free)(void *) = free;
13+
314
#include "lib-reftable.h"
415
#include "test-lib.h"
516
#include "reftable/constants.h"
617
#include "reftable/writer.h"
718
#include "strbuf.h"
819

20+
void t_reftable__initialize(void)
21+
{
22+
reftable_set_alloc(git_malloc, git_realloc, git_free);
23+
}
24+
925
void t_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id)
1026
{
1127
memset(p, (uint8_t)i, hash_size(id));

t/unit-tests/lib-reftable.h

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "git-compat-util.h"
55
#include "reftable/reftable-writer.h"
66

7+
void t_reftable__initialize(void);
8+
79
struct reftable_buf;
810

911
void t_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id);

t/unit-tests/t-reftable-basics.c

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ license that can be found in the LICENSE file or at
77
*/
88

99
#include "test-lib.h"
10+
#include "lib-reftable.h"
1011
#include "reftable/basics.h"
1112

1213
struct integer_needle_lesseq_args {
@@ -27,6 +28,7 @@ static void *realloc_stub(void *p UNUSED, size_t size UNUSED)
2728

2829
int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
2930
{
31+
t_reftable__initialize();
3032
if_test ("binary search with binsearch works") {
3133
int haystack[] = { 2, 4, 6, 8, 10 };
3234
struct {

t/unit-tests/t-reftable-block.c

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ license that can be found in the LICENSE file or at
77
*/
88

99
#include "test-lib.h"
10+
#include "lib-reftable.h"
1011
#include "reftable/block.h"
1112
#include "reftable/blocksource.h"
1213
#include "reftable/constants.h"
@@ -374,6 +375,7 @@ static void t_index_block_read_write(void)
374375

375376
int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
376377
{
378+
t_reftable__initialize();
377379
TEST(t_index_block_read_write(), "read-write operations on index blocks work");
378380
TEST(t_log_block_read_write(), "read-write operations on log blocks work");
379381
TEST(t_obj_block_read_write(), "read-write operations on obj blocks work");

t/unit-tests/t-reftable-merged.c

+1
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ static void t_default_write_opts(void)
535535

536536
int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
537537
{
538+
t_reftable__initialize();
538539
TEST(t_default_write_opts(), "merged table with default write opts");
539540
TEST(t_merged_logs(), "merged table with multiple log updates for same ref");
540541
TEST(t_merged_refs(), "merged table with multiple updates to same ref");

t/unit-tests/t-reftable-pq.c

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ license that can be found in the LICENSE file or at
77
*/
88

99
#include "test-lib.h"
10+
#include "lib-reftable.h"
1011
#include "reftable/constants.h"
1112
#include "reftable/pq.h"
1213
#include "strbuf.h"
@@ -153,6 +154,7 @@ static void t_merged_iter_pqueue_top(void)
153154

154155
int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
155156
{
157+
t_reftable__initialize();
156158
TEST(t_pq_record(), "pq works with record-based comparison");
157159
TEST(t_pq_index(), "pq works with index-based comparison");
158160
TEST(t_merged_iter_pqueue_top(), "merged_iter_pqueue_top works");

t/unit-tests/t-reftable-reader.c

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ static int t_reader_reseek(void)
9090

9191
int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
9292
{
93+
t_reftable__initialize();
9394
TEST(t_reader_seek_once(), "reader can seek once");
9495
TEST(t_reader_reseek(), "reader can reseek multiple times");
9596
return test_done();

t/unit-tests/t-reftable-readwrite.c

+1
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,7 @@ static void t_corrupt_table(void)
957957

958958
int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
959959
{
960+
t_reftable__initialize();
960961
TEST(t_buffer(), "strbuf works as blocksource");
961962
TEST(t_corrupt_table(), "read-write on corrupted table");
962963
TEST(t_corrupt_table_empty(), "read-write on an empty table");

t/unit-tests/t-reftable-record.c

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#include "test-lib.h"
10+
#include "lib-reftable.h"
1011
#include "reftable/basics.h"
1112
#include "reftable/constants.h"
1213
#include "reftable/record.h"
@@ -567,6 +568,7 @@ static void t_reftable_index_record_roundtrip(void)
567568

568569
int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
569570
{
571+
t_reftable__initialize();
570572
TEST(t_reftable_ref_record_comparison(), "comparison operations work on ref record");
571573
TEST(t_reftable_log_record_comparison(), "comparison operations work on log record");
572574
TEST(t_reftable_index_record_comparison(), "comparison operations work on index record");

t/unit-tests/t-reftable-stack.c

+1
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,7 @@ static void t_reftable_invalid_limit_updates(void)
14181418

14191419
int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
14201420
{
1421+
t_reftable__initialize();
14211422
TEST(t_empty_add(), "empty addition to stack");
14221423
TEST(t_read_file(), "read_lines works");
14231424
TEST(t_reflog_expire(), "expire reflog entries");

0 commit comments

Comments
 (0)