Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
141272d5
Commit
141272d5
authored
9 years ago
by
Sree Kuchibhotla
Browse files
Options
Downloads
Plain Diff
Merge pull request #4363 from dgquintas/compression_coverage
Increased message_compress.c coverage
parents
5efe9255
0a08791b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/core/compression/message_compress.c
+13
-1
13 additions, 1 deletion
src/core/compression/message_compress.c
test/core/compression/message_compress_test.c
+45
-0
45 additions, 0 deletions
test/core/compression/message_compress_test.c
with
58 additions
and
1 deletion
src/core/compression/message_compress.c
+
13
−
1
View file @
141272d5
...
...
@@ -91,6 +91,14 @@ error:
return
0
;
}
static
void
*
zalloc_gpr
(
void
*
opaque
,
unsigned
int
items
,
unsigned
int
size
)
{
return
gpr_malloc
(
items
*
size
);
}
static
void
zfree_gpr
(
void
*
opaque
,
void
*
address
)
{
gpr_free
(
address
);
}
static
int
zlib_compress
(
gpr_slice_buffer
*
input
,
gpr_slice_buffer
*
output
,
int
gzip
)
{
z_stream
zs
;
...
...
@@ -99,6 +107,8 @@ static int zlib_compress(gpr_slice_buffer* input, gpr_slice_buffer* output,
size_t
count_before
=
output
->
count
;
size_t
length_before
=
output
->
length
;
memset
(
&
zs
,
0
,
sizeof
(
zs
));
zs
.
zalloc
=
zalloc_gpr
;
zs
.
zfree
=
zfree_gpr
;
r
=
deflateInit2
(
&
zs
,
Z_DEFAULT_COMPRESSION
,
Z_DEFLATED
,
15
|
(
gzip
?
16
:
0
),
8
,
Z_DEFAULT_STRATEGY
);
if
(
r
!=
Z_OK
)
{
...
...
@@ -125,6 +135,8 @@ static int zlib_decompress(gpr_slice_buffer* input, gpr_slice_buffer* output,
size_t
count_before
=
output
->
count
;
size_t
length_before
=
output
->
length
;
memset
(
&
zs
,
0
,
sizeof
(
zs
));
zs
.
zalloc
=
zalloc_gpr
;
zs
.
zfree
=
zfree_gpr
;
r
=
inflateInit2
(
&
zs
,
15
|
(
gzip
?
16
:
0
));
if
(
r
!=
Z_OK
)
{
gpr_log
(
GPR_ERROR
,
"inflateInit2 returns %d"
,
r
);
...
...
@@ -150,7 +162,7 @@ static int copy(gpr_slice_buffer* input, gpr_slice_buffer* output) {
return
1
;
}
int
compress_inner
(
grpc_compression_algorithm
algorithm
,
static
int
compress_inner
(
grpc_compression_algorithm
algorithm
,
gpr_slice_buffer
*
input
,
gpr_slice_buffer
*
output
)
{
switch
(
algorithm
)
{
case
GRPC_COMPRESS_NONE
:
...
...
This diff is collapsed.
Click to expand it.
test/core/compression/message_compress_test.c
+
45
−
0
View file @
141272d5
...
...
@@ -168,6 +168,49 @@ static void test_bad_data(void) {
gpr_slice_buffer_destroy
(
&
output
);
}
static
void
test_bad_compression_algorithm
(
void
)
{
gpr_slice_buffer
input
;
gpr_slice_buffer
output
;
int
was_compressed
;
gpr_slice_buffer_init
(
&
input
);
gpr_slice_buffer_init
(
&
output
);
gpr_slice_buffer_add
(
&
input
,
gpr_slice_from_copied_string
(
"Never gonna give you up"
));
was_compressed
=
grpc_msg_compress
(
GRPC_COMPRESS_ALGORITHMS_COUNT
,
&
input
,
&
output
);
GPR_ASSERT
(
0
==
was_compressed
);
was_compressed
=
grpc_msg_compress
(
GRPC_COMPRESS_ALGORITHMS_COUNT
+
123
,
&
input
,
&
output
);
GPR_ASSERT
(
0
==
was_compressed
);
gpr_slice_buffer_destroy
(
&
input
);
gpr_slice_buffer_destroy
(
&
output
);
}
static
void
test_bad_decompression_algorithm
(
void
)
{
gpr_slice_buffer
input
;
gpr_slice_buffer
output
;
int
was_decompressed
;
gpr_slice_buffer_init
(
&
input
);
gpr_slice_buffer_init
(
&
output
);
gpr_slice_buffer_add
(
&
input
,
gpr_slice_from_copied_string
(
"I'm not really compressed but it doesn't matter"
));
was_decompressed
=
grpc_msg_decompress
(
GRPC_COMPRESS_ALGORITHMS_COUNT
,
&
input
,
&
output
);
GPR_ASSERT
(
0
==
was_decompressed
);
was_decompressed
=
grpc_msg_decompress
(
GRPC_COMPRESS_ALGORITHMS_COUNT
+
123
,
&
input
,
&
output
);
GPR_ASSERT
(
0
==
was_decompressed
);
gpr_slice_buffer_destroy
(
&
input
);
gpr_slice_buffer_destroy
(
&
output
);
}
int
main
(
int
argc
,
char
**
argv
)
{
unsigned
i
,
j
,
k
,
m
;
grpc_slice_split_mode
uncompressed_split_modes
[]
=
{
...
...
@@ -192,6 +235,8 @@ int main(int argc, char **argv) {
}
test_bad_data
();
test_bad_compression_algorithm
();
test_bad_decompression_algorithm
();
grpc_shutdown
();
return
0
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment