Lines Matching full:state
51 typedef void (*round_trip_t)(state_t* state);
60 state_t state; in state_create() local
62 state.seed = seed; in state_create()
64 state.data.buf = (char const*)data; in state_create()
65 state.data.size = size; in state_create()
66 state.data.pos = 0; in state_create()
69 state.compressed = cursor_create(1024 + 2 * LZ4_compressBound(size)); in state_create()
70 state.roundTrip = cursor_create(size); in state_create()
72 state.cstream = LZ4_createStream(); in state_create()
73 FUZZ_ASSERT(state.cstream); in state_create()
74 state.cstreamHC = LZ4_createStreamHC(); in state_create()
75 FUZZ_ASSERT(state.cstream); in state_create()
76 state.dstream = LZ4_createStreamDecode(); in state_create()
77 FUZZ_ASSERT(state.dstream); in state_create()
79 return state; in state_create()
82 void state_free(state_t state) in state_free() argument
84 cursor_free(state.compressed); in state_free()
85 cursor_free(state.roundTrip); in state_free()
86 LZ4_freeStream(state.cstream); in state_free()
87 LZ4_freeStreamHC(state.cstreamHC); in state_free()
88 LZ4_freeStreamDecode(state.dstream); in state_free()
91 static void state_reset(state_t* state, uint32_t seed) in state_reset() argument
93 state->level = FUZZ_rand32(&seed, LZ4HC_CLEVEL_MIN, LZ4HC_CLEVEL_MAX); in state_reset()
94 LZ4_resetStream_fast(state->cstream); in state_reset()
95 LZ4_resetStreamHC_fast(state->cstreamHC, state->level); in state_reset()
96 LZ4_setStreamDecode(state->dstream, NULL, 0); in state_reset()
97 state->data.pos = 0; in state_reset()
98 state->compressed.pos = 0; in state_reset()
99 state->roundTrip.pos = 0; in state_reset()
100 state->seed = seed; in state_reset()
103 static void state_decompress(state_t* state, char const* src, int srcSize) in state_decompress() argument
105 char* dst = state->roundTrip.buf + state->roundTrip.pos; in state_decompress()
106 int const dstCapacity = state->roundTrip.size - state->roundTrip.pos; in state_decompress()
107 int const dSize = LZ4_decompress_safe_continue(state->dstream, src, dst, in state_decompress()
110 state->roundTrip.pos += dSize; in state_decompress()
113 static void state_checkRoundTrip(state_t const* state) in state_checkRoundTrip() argument
115 char const* data = state->data.buf; in state_checkRoundTrip()
116 size_t const size = state->data.size; in state_checkRoundTrip()
117 FUZZ_ASSERT_MSG(size == state->roundTrip.pos, "Incorrect size!"); in state_checkRoundTrip()
118 FUZZ_ASSERT_MSG(!memcmp(data, state->roundTrip.buf, size), "Corruption!"); in state_checkRoundTrip()
125 static size_t state_trimDict(state_t* state) in state_trimDict() argument
128 uint32_t maxDictSize = MIN(70 * 1024, state->data.size); in state_trimDict()
129 size_t const dictSize = FUZZ_rand32(&state->seed, 0, maxDictSize); in state_trimDict()
131 FUZZ_ASSERT(state->data.pos == 0); in state_trimDict()
132 FUZZ_ASSERT(state->roundTrip.pos == 0); in state_trimDict()
133 memcpy(state->roundTrip.buf, state->data.buf, dictSize); in state_trimDict()
134 state->data.pos += dictSize; in state_trimDict()
135 state->roundTrip.pos += dictSize; in state_trimDict()
139 static void state_prefixRoundTrip(state_t* state) in state_prefixRoundTrip() argument
141 while (state->data.pos != state->data.size) { in state_prefixRoundTrip()
142 char const* src = state->data.buf + state->data.pos; in state_prefixRoundTrip()
143 char* dst = state->compressed.buf + state->compressed.pos; in state_prefixRoundTrip()
144 int const srcRemaining = state->data.size - state->data.pos; in state_prefixRoundTrip()
145 int const srcSize = FUZZ_rand32(&state->seed, 0, srcRemaining); in state_prefixRoundTrip()
146 int const dstCapacity = state->compressed.size - state->compressed.pos; in state_prefixRoundTrip()
147 int const cSize = LZ4_compress_fast_continue(state->cstream, src, dst, in state_prefixRoundTrip()
150 state->data.pos += srcSize; in state_prefixRoundTrip()
151 state->compressed.pos += cSize; in state_prefixRoundTrip()
152 state_decompress(state, dst, cSize); in state_prefixRoundTrip()
156 static void state_extDictRoundTrip(state_t* state) in state_extDictRoundTrip() argument
159 cursor_t data2 = cursor_create(state->data.size); in state_extDictRoundTrip()
160 memcpy(data2.buf, state->data.buf, state->data.size); in state_extDictRoundTrip()
161 while (state->data.pos != state->data.size) { in state_extDictRoundTrip()
162 char const* data = (i++ & 1) ? state->data.buf : data2.buf; in state_extDictRoundTrip()
163 char const* src = data + state->data.pos; in state_extDictRoundTrip()
164 char* dst = state->compressed.buf + state->compressed.pos; in state_extDictRoundTrip()
165 int const srcRemaining = state->data.size - state->data.pos; in state_extDictRoundTrip()
166 int const srcSize = FUZZ_rand32(&state->seed, 0, srcRemaining); in state_extDictRoundTrip()
167 int const dstCapacity = state->compressed.size - state->compressed.pos; in state_extDictRoundTrip()
168 int const cSize = LZ4_compress_fast_continue(state->cstream, src, dst, in state_extDictRoundTrip()
171 state->data.pos += srcSize; in state_extDictRoundTrip()
172 state->compressed.pos += cSize; in state_extDictRoundTrip()
173 state_decompress(state, dst, cSize); in state_extDictRoundTrip()
178 static void state_randomRoundTrip(state_t* state, round_trip_t rt0, in state_randomRoundTrip() argument
181 if (FUZZ_rand32(&state->seed, 0, 1)) { in state_randomRoundTrip()
182 rt0(state); in state_randomRoundTrip()
184 rt1(state); in state_randomRoundTrip()
188 static void state_loadDictRoundTrip(state_t* state) in state_loadDictRoundTrip() argument
190 char const* dict = state->data.buf; in state_loadDictRoundTrip()
191 size_t const dictSize = state_trimDict(state); in state_loadDictRoundTrip()
192 LZ4_loadDict(state->cstream, dict, dictSize); in state_loadDictRoundTrip()
193 LZ4_setStreamDecode(state->dstream, dict, dictSize); in state_loadDictRoundTrip()
194 state_randomRoundTrip(state, state_prefixRoundTrip, state_extDictRoundTrip); in state_loadDictRoundTrip()
197 static void state_attachDictRoundTrip(state_t* state) in state_attachDictRoundTrip() argument
199 char const* dict = state->data.buf; in state_attachDictRoundTrip()
200 size_t const dictSize = state_trimDict(state); in state_attachDictRoundTrip()
203 LZ4_attach_dictionary(state->cstream, dictStream); in state_attachDictRoundTrip()
204 LZ4_setStreamDecode(state->dstream, dict, dictSize); in state_attachDictRoundTrip()
205 state_randomRoundTrip(state, state_prefixRoundTrip, state_extDictRoundTrip); in state_attachDictRoundTrip()
209 static void state_prefixHCRoundTrip(state_t* state) in state_prefixHCRoundTrip() argument
211 while (state->data.pos != state->data.size) { in state_prefixHCRoundTrip()
212 char const* src = state->data.buf + state->data.pos; in state_prefixHCRoundTrip()
213 char* dst = state->compressed.buf + state->compressed.pos; in state_prefixHCRoundTrip()
214 int const srcRemaining = state->data.size - state->data.pos; in state_prefixHCRoundTrip()
215 int const srcSize = FUZZ_rand32(&state->seed, 0, srcRemaining); in state_prefixHCRoundTrip()
216 int const dstCapacity = state->compressed.size - state->compressed.pos; in state_prefixHCRoundTrip()
217 int const cSize = LZ4_compress_HC_continue(state->cstreamHC, src, dst, in state_prefixHCRoundTrip()
220 state->data.pos += srcSize; in state_prefixHCRoundTrip()
221 state->compressed.pos += cSize; in state_prefixHCRoundTrip()
222 state_decompress(state, dst, cSize); in state_prefixHCRoundTrip()
226 static void state_extDictHCRoundTrip(state_t* state) in state_extDictHCRoundTrip() argument
229 cursor_t data2 = cursor_create(state->data.size); in state_extDictHCRoundTrip()
231 memcpy(data2.buf, state->data.buf, state->data.size); in state_extDictHCRoundTrip()
232 while (state->data.pos != state->data.size) { in state_extDictHCRoundTrip()
233 char const* data = (i++ & 1) ? state->data.buf : data2.buf; in state_extDictHCRoundTrip()
234 char const* src = data + state->data.pos; in state_extDictHCRoundTrip()
235 char* dst = state->compressed.buf + state->compressed.pos; in state_extDictHCRoundTrip()
236 int const srcRemaining = state->data.size - state->data.pos; in state_extDictHCRoundTrip()
237 int const srcSize = FUZZ_rand32(&state->seed, 0, srcRemaining); in state_extDictHCRoundTrip()
238 int const dstCapacity = state->compressed.size - state->compressed.pos; in state_extDictHCRoundTrip()
239 int const cSize = LZ4_compress_HC_continue(state->cstreamHC, src, dst, in state_extDictHCRoundTrip()
243 state->data.pos += srcSize; in state_extDictHCRoundTrip()
244 state->compressed.pos += cSize; in state_extDictHCRoundTrip()
245 state_decompress(state, dst, cSize); in state_extDictHCRoundTrip()
250 static void state_loadDictHCRoundTrip(state_t* state) in state_loadDictHCRoundTrip() argument
252 char const* dict = state->data.buf; in state_loadDictHCRoundTrip()
253 size_t const dictSize = state_trimDict(state); in state_loadDictHCRoundTrip()
254 LZ4_loadDictHC(state->cstreamHC, dict, dictSize); in state_loadDictHCRoundTrip()
255 LZ4_setStreamDecode(state->dstream, dict, dictSize); in state_loadDictHCRoundTrip()
256 state_randomRoundTrip(state, state_prefixHCRoundTrip, in state_loadDictHCRoundTrip()
260 static void state_attachDictHCRoundTrip(state_t* state) in state_attachDictHCRoundTrip() argument
262 char const* dict = state->data.buf; in state_attachDictHCRoundTrip()
263 size_t const dictSize = state_trimDict(state); in state_attachDictHCRoundTrip()
265 LZ4_setCompressionLevel(dictStream, state->level); in state_attachDictHCRoundTrip()
267 LZ4_attach_HC_dictionary(state->cstreamHC, dictStream); in state_attachDictHCRoundTrip()
268 LZ4_setStreamDecode(state->dstream, dict, dictSize); in state_attachDictHCRoundTrip()
269 state_randomRoundTrip(state, state_prefixHCRoundTrip, in state_attachDictHCRoundTrip()
288 state_t state = state_create((char const*)data, size, seed); in LLVMFuzzerTestOneInput() local
294 state_reset(&state, seed); in LLVMFuzzerTestOneInput()
295 roundTrips[i](&state); in LLVMFuzzerTestOneInput()
296 state_checkRoundTrip(&state); in LLVMFuzzerTestOneInput()
299 state_free(state); in LLVMFuzzerTestOneInput()