@@ -30,15 +30,15 @@ typedef struct {
30
30
size_t compSize ;
31
31
} test_data_t ;
32
32
33
- test_data_t create_test_data (void ) {
33
+ static test_data_t create_test_data (void ) {
34
34
test_data_t data ;
35
35
data .dataSize = 128 * 1024 ;
36
- data .data = malloc (data .dataSize );
36
+ data .data = ( char * ) malloc (data .dataSize );
37
37
CONTROL (data .data != NULL );
38
- data .data2 = malloc (data .dataSize );
38
+ data .data2 = ( char * ) malloc (data .dataSize );
39
39
CONTROL (data .data2 != NULL );
40
40
data .compSize = zstd_compress_bound (data .dataSize );
41
- data .comp = malloc (data .compSize );
41
+ data .comp = ( char * ) malloc (data .compSize );
42
42
CONTROL (data .comp != NULL );
43
43
memset (data .data , 0 , data .dataSize );
44
44
return data ;
@@ -54,26 +54,27 @@ static void free_test_data(test_data_t const *data) {
54
54
#define MAX (a , b ) ((a) > (b) ? (a) : (b))
55
55
56
56
static void test_btrfs (test_data_t const * data ) {
57
- fprintf (stderr , "testing btrfs use cases... " );
58
57
size_t const size = MIN (data -> dataSize , 128 * 1024 );
58
+ fprintf (stderr , "testing btrfs use cases... " );
59
59
for (int level = -1 ; level < 16 ; ++ level ) {
60
60
zstd_parameters params = zstd_get_params (level , size );
61
- CONTROL (params .cParams .windowLog <= 17 );
62
61
size_t const workspaceSize =
63
62
MAX (zstd_cstream_workspace_bound (& params .cParams ),
64
63
zstd_dstream_workspace_bound (size ));
65
64
void * workspace = malloc (workspaceSize );
66
- CONTROL (workspace != NULL );
67
65
68
66
char const * ip = data -> data ;
69
67
char const * iend = ip + size ;
70
68
char * op = data -> comp ;
71
69
char * oend = op + data -> compSize ;
70
+
71
+ CONTROL (params .cParams .windowLog <= 17 );
72
+ CONTROL (workspace != NULL );
72
73
{
73
74
zstd_cstream * cctx = zstd_init_cstream (& params , size , workspace , workspaceSize );
74
- CONTROL (cctx != NULL );
75
75
zstd_out_buffer out = {NULL , 0 , 0 };
76
76
zstd_in_buffer in = {NULL , 0 , 0 };
77
+ CONTROL (cctx != NULL );
77
78
for (;;) {
78
79
if (in .pos == in .size ) {
79
80
in .src = ip ;
@@ -108,9 +109,9 @@ static void test_btrfs(test_data_t const *data) {
108
109
oend = op + size ;
109
110
{
110
111
zstd_dstream * dctx = zstd_init_dstream (1ULL << params .cParams .windowLog , workspace , workspaceSize );
111
- CONTROL (dctx != NULL );
112
112
zstd_out_buffer out = {NULL , 0 , 0 };
113
113
zstd_in_buffer in = {NULL , 0 , 0 };
114
+ CONTROL (dctx != NULL );
114
115
for (;;) {
115
116
if (in .pos == in .size ) {
116
117
in .src = ip ;
@@ -125,30 +126,31 @@ static void test_btrfs(test_data_t const *data) {
125
126
out .pos = 0 ;
126
127
op += out .size ;
127
128
}
128
-
129
- size_t const ret = zstd_decompress_stream (dctx , & out , & in );
130
- CONTROL (!zstd_is_error (ret ));
131
- if (ret == 0 ) {
132
- break ;
129
+ {
130
+ size_t const ret = zstd_decompress_stream (dctx , & out , & in );
131
+ CONTROL (!zstd_is_error (ret ));
132
+ if (ret == 0 ) {
133
+ break ;
134
+ }
133
135
}
134
136
}
135
137
}
136
- CONTROL (op - data -> data2 == data -> dataSize );
138
+ CONTROL (( size_t )( op - data -> data2 ) == data -> dataSize );
137
139
CONTROL (!memcmp (data -> data , data -> data2 , data -> dataSize ));
138
140
free (workspace );
139
141
}
140
142
fprintf (stderr , "Ok\n" );
141
143
}
142
144
143
145
static void test_decompress_unzstd (test_data_t const * data ) {
144
- fprintf (stderr , "Testing decompress unzstd... " );
145
146
size_t cSize ;
147
+ fprintf (stderr , "Testing decompress unzstd... " );
146
148
{
147
149
zstd_parameters params = zstd_get_params (19 , 0 );
148
150
size_t const wkspSize = zstd_cctx_workspace_bound (& params .cParams );
149
151
void * wksp = malloc (wkspSize );
150
- CONTROL (wksp != NULL );
151
152
zstd_cctx * cctx = zstd_init_cctx (wksp , wkspSize );
153
+ CONTROL (wksp != NULL );
152
154
CONTROL (cctx != NULL );
153
155
cSize = zstd_compress_cctx (cctx , data -> comp , data -> compSize , data -> data , data -> dataSize , & params );
154
156
CONTROL (!zstd_is_error (cSize ));
@@ -157,19 +159,21 @@ static void test_decompress_unzstd(test_data_t const *data) {
157
159
{
158
160
size_t const wkspSize = zstd_dctx_workspace_bound ();
159
161
void * wksp = malloc (wkspSize );
160
- CONTROL (wksp != NULL );
161
162
zstd_dctx * dctx = zstd_init_dctx (wksp , wkspSize );
163
+ CONTROL (wksp != NULL );
162
164
CONTROL (dctx != NULL );
163
- size_t const dSize = zstd_decompress_dctx (dctx , data -> data2 , data -> dataSize , data -> comp , cSize );
164
- CONTROL (!zstd_is_error (dSize ));
165
- CONTROL (dSize == data -> dataSize );
165
+ {
166
+ size_t const dSize = zstd_decompress_dctx (dctx , data -> data2 , data -> dataSize , data -> comp , cSize );
167
+ CONTROL (!zstd_is_error (dSize ));
168
+ CONTROL (dSize == data -> dataSize );
169
+ }
166
170
CONTROL (!memcmp (data -> data , data -> data2 , data -> dataSize ));
167
171
free (wksp );
168
172
}
169
173
fprintf (stderr , "Ok\n" );
170
174
}
171
175
172
- static void test_f2fs () {
176
+ static void test_f2fs (void ) {
173
177
fprintf (stderr , "testing f2fs uses... " );
174
178
CONTROL (zstd_min_clevel () < 0 );
175
179
CONTROL (zstd_max_clevel () == 22 );
@@ -182,22 +186,24 @@ static void __attribute__((noinline)) use(void *x) {
182
186
asm volatile ("" : "+r" (x ));
183
187
}
184
188
185
- static void __attribute__((noinline )) set_stack () {
189
+ static void __attribute__((noinline )) set_stack (void ) {
186
190
187
191
char stack [8192 ];
188
192
g_stack = stack ;
189
193
memset (g_stack , 0x33 , 8192 );
190
194
use (g_stack );
191
195
}
192
196
193
- static void __attribute__((noinline )) check_stack () {
197
+ static void __attribute__((noinline )) check_stack (void ) {
194
198
size_t cleanStack = 0 ;
195
199
while (cleanStack < 8192 && g_stack [cleanStack ] == 0x33 ) {
196
200
++ cleanStack ;
197
201
}
198
- size_t const stackSize = 8192 - cleanStack ;
199
- fprintf (stderr , "Maximum stack size: %zu\n" , stackSize );
200
- CONTROL (stackSize <= 2048 + 512 );
202
+ {
203
+ size_t const stackSize = 8192 - cleanStack ;
204
+ fprintf (stderr , "Maximum stack size: %zu\n" , stackSize );
205
+ CONTROL (stackSize <= 2048 + 512 );
206
+ }
201
207
}
202
208
203
209
static void test_stack_usage (test_data_t const * data ) {
0 commit comments