Skip to content

Commit dacc329

Browse files
committed
odb: test loose reading/writing large objects
Introduce a test for very large objects in the ODB. Write a large object (5 GB) and ensure that the write succeeds and provides us the expected object ID. Introduce a test that writes that file and ensures that we can subsequently read it.
1 parent 86219f4 commit dacc329

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

tests/odb/largefiles.c

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#include "clar_libgit2.h"
2+
#include "git2/odb_backend.h"
3+
4+
static git_repository *repo;
5+
static git_odb *odb;
6+
7+
void test_odb_largefiles__initialize(void)
8+
{
9+
repo = cl_git_sandbox_init("testrepo.git");
10+
cl_git_pass(git_repository_odb(&odb, repo));
11+
}
12+
13+
void test_odb_largefiles__cleanup(void)
14+
{
15+
git_odb_free(odb);
16+
cl_git_sandbox_cleanup();
17+
}
18+
19+
static void writefile(git_oid *oid)
20+
{
21+
static git_odb_stream *stream;
22+
git_buf buf = GIT_BUF_INIT;
23+
size_t i;
24+
25+
for (i = 0; i < 3041; i++)
26+
cl_git_pass(git_buf_puts(&buf, "Hello, world.\n"));
27+
28+
cl_git_pass(git_odb_open_wstream(&stream, odb, 5368709122, GIT_OBJ_BLOB));
29+
for (i = 0; i < 126103; i++)
30+
cl_git_pass(git_odb_stream_write(stream, buf.ptr, buf.size));
31+
32+
cl_git_pass(git_odb_stream_finalize_write(oid, stream));
33+
34+
git_odb_stream_free(stream);
35+
git_buf_free(&buf);
36+
}
37+
38+
void test_odb_largefiles__write_from_memory(void)
39+
{
40+
git_oid expected, oid;
41+
git_buf buf = GIT_BUF_INIT;
42+
size_t i;
43+
44+
#ifndef GIT_ARCH_64
45+
cl_skip();
46+
#endif
47+
48+
if (!cl_is_env_set("GITTEST_INVASIVE_FS_SIZE"))
49+
cl_skip();
50+
51+
if (!cl_is_env_set("GITTEST_INVASIVE_MEMORY"))
52+
cl_skip();
53+
54+
for (i = 0; i < (3041*126103); i++)
55+
cl_git_pass(git_buf_puts(&buf, "Hello, world.\n"));
56+
57+
git_oid_fromstr(&expected, "3fb56989cca483b21ba7cb0a6edb229d10e1c26c");
58+
cl_git_pass(git_odb_write(&oid, odb, buf.ptr, buf.size, GIT_OBJ_BLOB));
59+
60+
cl_assert_equal_oid(&expected, &oid);
61+
}
62+
63+
void test_odb_largefiles__streamwrite(void)
64+
{
65+
git_oid expected, oid;
66+
67+
if (!cl_is_env_set("GITTEST_INVASIVE_FS_SIZE"))
68+
cl_skip();
69+
70+
git_oid_fromstr(&expected, "3fb56989cca483b21ba7cb0a6edb229d10e1c26c");
71+
writefile(&oid);
72+
73+
cl_assert_equal_oid(&expected, &oid);
74+
}
75+
76+
void test_odb_largefiles__read_into_memory(void)
77+
{
78+
git_oid oid;
79+
git_odb_object *obj;
80+
81+
#ifndef GIT_ARCH_64
82+
cl_skip();
83+
#endif
84+
85+
if (!cl_is_env_set("GITTEST_INVASIVE_FS_SIZE"))
86+
cl_skip();
87+
88+
if (!cl_is_env_set("GITTEST_INVASIVE_MEMORY"))
89+
cl_skip();
90+
91+
writefile(&oid);
92+
cl_git_pass(git_odb_read(&obj, odb, &oid));
93+
94+
git_odb_object_free(obj);
95+
}

0 commit comments

Comments
 (0)