Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
8606f33b
Commit
8606f33b
authored
Jan 30, 2014
by
Russell Belfer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expand zstream tests and fix off-by-one error
parent
d9b04d78
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
18 deletions
+64
-18
src/zstream.c
+2
-1
tests/core/zstream.c
+62
-17
No files found.
src/zstream.c
View file @
8606f33b
...
...
@@ -98,6 +98,7 @@ int git_zstream_get_output(void *out, size_t *out_len, git_zstream *zstream)
/* compress next chunk */
zstream
->
zerr
=
deflate
(
&
zstream
->
z
,
zflush
);
if
(
zstream
->
zerr
==
Z_STREAM_ERROR
)
return
zstream_seterr
(
zstream
);
...
...
@@ -133,7 +134,7 @@ int git_zstream_deflatebuf(git_buf *out, const void *in, size_t in_len)
while
(
!
git_zstream_done
(
&
zs
))
{
size_t
step
=
git_zstream_suggest_output_len
(
&
zs
),
written
;
if
((
error
=
git_buf_grow
(
out
,
out
->
asize
+
step
))
<
0
)
if
((
error
=
git_buf_grow
(
out
,
out
->
asize
+
step
+
1
))
<
0
)
goto
done
;
written
=
out
->
asize
-
out
->
size
;
...
...
tests/core/zstream.c
View file @
8606f33b
...
...
@@ -68,31 +68,76 @@ void test_core_zstream__buffer(void)
#define BIG_STRING_PART "Big Data IS Big - Long Data IS Long - We need a buffer larger than 1024 x 1024 to make sure we trigger chunked compression - Big Big Data IS Bigger than Big - Long Long Data IS Longer than Long"
void
test_core_zstream__big_data
(
void
)
static
void
compress_input_various_ways
(
git_buf
*
input
)
{
git_buf
in
=
GIT_BUF_INIT
;
git_buf
out
=
GIT_BUF_INIT
;
size_t
scan
;
git_buf
out1
=
GIT_BUF_INIT
,
out2
=
GIT_BUF_INIT
;
size_t
i
,
fixed_size
=
max
(
input
->
size
/
2
,
256
);
char
*
fixed
=
git__malloc
(
fixed_size
);
cl_assert
(
fixed
);
/* make a big string that's easy to compress */
while
(
in
.
size
<
1024
*
1024
)
cl_git_pass
(
git_buf_put
(
&
in
,
BIG_STRING_PART
,
strlen
(
BIG_STRING_PART
)));
/* compress with deflatebuf */
cl_git_pass
(
git_zstream_deflatebuf
(
&
out
,
in
.
ptr
,
in
.
size
));
assert_zlib_equal
(
in
.
ptr
,
in
.
size
,
out
.
ptr
,
out
.
size
);
cl_git_pass
(
git_zstream_deflatebuf
(
&
out
1
,
input
->
ptr
,
input
->
size
));
assert_zlib_equal
(
in
put
->
ptr
,
input
->
size
,
out1
.
ptr
,
out1
.
size
);
git_buf_free
(
&
out
);
/* compress with various fixed size buffer (accumulating the output) */
/* make a big string that's hard to compress */
for
(
i
=
0
;
i
<
3
;
++
i
)
{
git_zstream
zs
=
GIT_ZSTREAM_INIT
;
size_t
use_fixed_size
;
srand
(
0xabad1dea
);
for
(
scan
=
0
;
scan
<
in
.
size
;
++
scan
)
in
.
ptr
[
scan
]
=
(
char
)
rand
();
switch
(
i
)
{
case
0
:
use_fixed_size
=
256
;
break
;
case
1
:
use_fixed_size
=
fixed_size
/
2
;
break
;
case
2
:
use_fixed_size
=
fixed_size
;
break
;
}
cl_assert
(
use_fixed_size
<=
fixed_size
);
cl_git_pass
(
git_zstream_deflatebuf
(
&
out
,
in
.
ptr
,
in
.
size
));
assert_zlib_equal
(
in
.
ptr
,
in
.
size
,
out
.
ptr
,
out
.
size
);
cl_git_pass
(
git_zstream_init
(
&
zs
));
cl_git_pass
(
git_zstream_set_input
(
&
zs
,
input
->
ptr
,
input
->
size
)
);
git_buf_free
(
&
out
);
while
(
!
git_zstream_done
(
&
zs
))
{
size_t
written
=
use_fixed_size
;
cl_git_pass
(
git_zstream_get_output
(
fixed
,
&
written
,
&
zs
));
cl_git_pass
(
git_buf_put
(
&
out2
,
fixed
,
written
));
}
git_zstream_free
(
&
zs
);
assert_zlib_equal
(
input
->
ptr
,
input
->
size
,
out2
.
ptr
,
out2
.
size
);
/* did both approaches give the same data? */
cl_assert_equal_sz
(
out1
.
size
,
out2
.
size
);
cl_assert
(
!
memcmp
(
out1
.
ptr
,
out2
.
ptr
,
out1
.
size
));
git_buf_free
(
&
out2
);
}
git_buf_free
(
&
out1
);
git__free
(
fixed
);
}
void
test_core_zstream__big_data
(
void
)
{
git_buf
in
=
GIT_BUF_INIT
;
size_t
scan
,
target
;
for
(
target
=
1024
;
target
<=
1024
*
1024
*
4
;
target
*=
8
)
{
/* make a big string that's easy to compress */
git_buf_clear
(
&
in
);
while
(
in
.
size
<
target
)
cl_git_pass
(
git_buf_put
(
&
in
,
BIG_STRING_PART
,
strlen
(
BIG_STRING_PART
)));
compress_input_various_ways
(
&
in
);
/* make a big string that's hard to compress */
srand
(
0xabad1dea
);
for
(
scan
=
0
;
scan
<
in
.
size
;
++
scan
)
in
.
ptr
[
scan
]
=
(
char
)
rand
();
compress_input_various_ways
(
&
in
);
}
git_buf_free
(
&
in
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment