Yann Collet | 4ded9e5 | 2016-08-30 10:04:33 -0700 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * This source code is licensed under the BSD-style license found in the |
| 6 | * LICENSE file in the root directory of this source tree. An additional grant |
| 7 | * of patent rights can be found in the PATENTS file in the same directory. |
| 8 | */ |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 9 | |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 10 | |
| 11 | /*-************************************ |
| 12 | * Compiler specific |
| 13 | **************************************/ |
| 14 | #ifdef _MSC_VER /* Visual Studio */ |
| 15 | # define _CRT_SECURE_NO_WARNINGS /* fgets */ |
| 16 | # pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */ |
| 17 | # pragma warning(disable : 4146) /* disable: C4146: minus unsigned expression */ |
| 18 | #endif |
| 19 | |
| 20 | |
| 21 | /*-************************************ |
| 22 | * Includes |
| 23 | **************************************/ |
| 24 | #include <stdlib.h> /* free */ |
| 25 | #include <stdio.h> /* fgets, sscanf */ |
Yann Collet | ef9999f | 2016-09-01 16:44:48 -0700 | [diff] [blame] | 26 | #include <time.h> /* clock_t, clock() */ |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 27 | #include <string.h> /* strcmp */ |
| 28 | #include "mem.h" |
Yann Collet | 33fce03 | 2017-01-16 19:46:22 -0800 | [diff] [blame] | 29 | #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_maxCLevel, ZSTD_customMem, ZSTD_getDictID_fromFrame */ |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 30 | #include "zstd.h" /* ZSTD_compressBound */ |
Yann Collet | e795c8a | 2016-12-13 16:39:36 +0100 | [diff] [blame] | 31 | #include "zstd_errors.h" /* ZSTD_error_srcSize_wrong */ |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 32 | #include "zstdmt_compress.h" |
Yann Collet | 33fce03 | 2017-01-16 19:46:22 -0800 | [diff] [blame] | 33 | #include "zdict.h" /* ZDICT_trainFromBuffer */ |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 34 | #include "datagen.h" /* RDG_genBuffer */ |
Yann Collet | ef9999f | 2016-09-01 16:44:48 -0700 | [diff] [blame] | 35 | #define XXH_STATIC_LINKING_ONLY /* XXH64_state_t */ |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 36 | #include "xxhash.h" /* XXH64_* */ |
| 37 | |
| 38 | |
| 39 | /*-************************************ |
| 40 | * Constants |
| 41 | **************************************/ |
| 42 | #define KB *(1U<<10) |
| 43 | #define MB *(1U<<20) |
| 44 | #define GB *(1U<<30) |
| 45 | |
| 46 | static const U32 nbTestsDefault = 10000; |
| 47 | #define COMPRESSIBLE_NOISE_LENGTH (10 MB) |
| 48 | #define FUZ_COMPRESSIBILITY_DEFAULT 50 |
Yann Collet | 33fce03 | 2017-01-16 19:46:22 -0800 | [diff] [blame] | 49 | static const U32 prime32 = 2654435761U; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 50 | |
| 51 | |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 52 | /*-************************************ |
| 53 | * Display Macros |
| 54 | **************************************/ |
| 55 | #define DISPLAY(...) fprintf(stderr, __VA_ARGS__) |
Yann Collet | 0be6fd3 | 2017-05-08 16:08:01 -0700 | [diff] [blame] | 56 | #define DISPLAYLEVEL(l, ...) if (g_displayLevel>=l) { \ |
| 57 | DISPLAY(__VA_ARGS__); \ |
| 58 | if (g_displayLevel>=4) fflush(stderr); } |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 59 | static U32 g_displayLevel = 2; |
| 60 | |
| 61 | #define DISPLAYUPDATE(l, ...) if (g_displayLevel>=l) { \ |
Yann Collet | ef9999f | 2016-09-01 16:44:48 -0700 | [diff] [blame] | 62 | if ((FUZ_GetClockSpan(g_displayClock) > g_refreshRate) || (g_displayLevel>=4)) \ |
| 63 | { g_displayClock = clock(); DISPLAY(__VA_ARGS__); \ |
Yann Collet | 0be6fd3 | 2017-05-08 16:08:01 -0700 | [diff] [blame] | 64 | if (g_displayLevel>=4) fflush(stderr); } } |
Yann Collet | b3060f7 | 2016-09-09 16:44:16 +0200 | [diff] [blame] | 65 | static const clock_t g_refreshRate = CLOCKS_PER_SEC / 6; |
Yann Collet | ef9999f | 2016-09-01 16:44:48 -0700 | [diff] [blame] | 66 | static clock_t g_displayClock = 0; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 67 | |
Yann Collet | ef9999f | 2016-09-01 16:44:48 -0700 | [diff] [blame] | 68 | static clock_t g_clockTime = 0; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 69 | |
| 70 | |
| 71 | /*-******************************************************* |
| 72 | * Fuzzer functions |
| 73 | *********************************************************/ |
| 74 | #define MAX(a,b) ((a)>(b)?(a):(b)) |
| 75 | |
Yann Collet | ef9999f | 2016-09-01 16:44:48 -0700 | [diff] [blame] | 76 | static clock_t FUZ_GetClockSpan(clock_t clockStart) |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 77 | { |
Yann Collet | ef9999f | 2016-09-01 16:44:48 -0700 | [diff] [blame] | 78 | return clock() - clockStart; /* works even when overflow. Max span ~ 30 mn */ |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | /*! FUZ_rand() : |
| 82 | @return : a 27 bits random value, from a 32-bits `seed`. |
| 83 | `seed` is also modified */ |
Yann Collet | 9516234 | 2016-10-25 16:19:52 -0700 | [diff] [blame] | 84 | #define FUZ_rotl32(x,r) ((x << r) | (x >> (32 - r))) |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 85 | unsigned int FUZ_rand(unsigned int* seedPtr) |
| 86 | { |
Yann Collet | 33fce03 | 2017-01-16 19:46:22 -0800 | [diff] [blame] | 87 | static const U32 prime2 = 2246822519U; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 88 | U32 rand32 = *seedPtr; |
Yann Collet | 33fce03 | 2017-01-16 19:46:22 -0800 | [diff] [blame] | 89 | rand32 *= prime32; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 90 | rand32 += prime2; |
| 91 | rand32 = FUZ_rotl32(rand32, 13); |
| 92 | *seedPtr = rand32; |
| 93 | return rand32 >> 5; |
| 94 | } |
| 95 | |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 96 | static void* allocFunction(void* opaque, size_t size) |
| 97 | { |
| 98 | void* address = malloc(size); |
| 99 | (void)opaque; |
| 100 | return address; |
| 101 | } |
| 102 | |
| 103 | static void freeFunction(void* opaque, void* address) |
| 104 | { |
| 105 | (void)opaque; |
| 106 | free(address); |
| 107 | } |
| 108 | |
Yann Collet | cb32763 | 2016-08-23 00:30:31 +0200 | [diff] [blame] | 109 | |
| 110 | /*====================================================== |
| 111 | * Basic Unit tests |
| 112 | ======================================================*/ |
| 113 | |
Yann Collet | 33fce03 | 2017-01-16 19:46:22 -0800 | [diff] [blame] | 114 | typedef struct { |
| 115 | void* start; |
| 116 | size_t size; |
| 117 | size_t filled; |
| 118 | } buffer_t; |
| 119 | |
| 120 | static const buffer_t g_nullBuffer = { NULL, 0 , 0 }; |
| 121 | |
| 122 | static buffer_t FUZ_createDictionary(const void* src, size_t srcSize, size_t blockSize, size_t requestedDictSize) |
| 123 | { |
| 124 | buffer_t dict = { NULL, 0, 0 }; |
| 125 | size_t const nbBlocks = (srcSize + (blockSize-1)) / blockSize; |
| 126 | size_t* const blockSizes = (size_t*) malloc(nbBlocks * sizeof(size_t)); |
| 127 | if (!blockSizes) return dict; |
| 128 | dict.start = malloc(requestedDictSize); |
| 129 | if (!dict.start) { free(blockSizes); return dict; } |
| 130 | { size_t nb; |
| 131 | for (nb=0; nb<nbBlocks-1; nb++) blockSizes[nb] = blockSize; |
| 132 | blockSizes[nbBlocks-1] = srcSize - (blockSize * (nbBlocks-1)); |
| 133 | } |
| 134 | { size_t const dictSize = ZDICT_trainFromBuffer(dict.start, requestedDictSize, src, blockSizes, (unsigned)nbBlocks); |
| 135 | free(blockSizes); |
Yann Collet | 2c5514c | 2017-04-18 22:52:41 -0700 | [diff] [blame] | 136 | if (ZDICT_isError(dictSize)) { free(dict.start); return g_nullBuffer; } |
Yann Collet | 33fce03 | 2017-01-16 19:46:22 -0800 | [diff] [blame] | 137 | dict.size = requestedDictSize; |
| 138 | dict.filled = dictSize; |
| 139 | return dict; /* how to return dictSize ? */ |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | static void FUZ_freeDictionary(buffer_t dict) |
| 144 | { |
| 145 | free(dict.start); |
| 146 | } |
| 147 | |
| 148 | |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 149 | static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem customMem) |
| 150 | { |
Yann Collet | b3060f7 | 2016-09-09 16:44:16 +0200 | [diff] [blame] | 151 | size_t const CNBufferSize = COMPRESSIBLE_NOISE_LENGTH; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 152 | void* CNBuffer = malloc(CNBufferSize); |
| 153 | size_t const skippableFrameSize = 11; |
| 154 | size_t const compressedBufferSize = (8 + skippableFrameSize) + ZSTD_compressBound(COMPRESSIBLE_NOISE_LENGTH); |
| 155 | void* compressedBuffer = malloc(compressedBufferSize); |
| 156 | size_t const decodedBufferSize = CNBufferSize; |
| 157 | void* decodedBuffer = malloc(decodedBufferSize); |
| 158 | size_t cSize; |
Yann Collet | b3060f7 | 2016-09-09 16:44:16 +0200 | [diff] [blame] | 159 | int testResult = 0; |
Yann Collet | 0be6fd3 | 2017-05-08 16:08:01 -0700 | [diff] [blame] | 160 | U32 testNb = 1; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 161 | ZSTD_CStream* zc = ZSTD_createCStream_advanced(customMem); |
| 162 | ZSTD_DStream* zd = ZSTD_createDStream_advanced(customMem); |
Yann Collet | 9ffbeea | 2016-12-02 18:37:38 -0800 | [diff] [blame] | 163 | ZSTD_inBuffer inBuff, inBuff2; |
Yann Collet | 53e17fb | 2016-08-17 01:39:22 +0200 | [diff] [blame] | 164 | ZSTD_outBuffer outBuff; |
Yann Collet | 33fce03 | 2017-01-16 19:46:22 -0800 | [diff] [blame] | 165 | buffer_t dictionary = g_nullBuffer; |
Yann Collet | 30ab64e | 2017-05-10 11:30:19 -0700 | [diff] [blame] | 166 | size_t const dictSize = 128 KB; |
Yann Collet | 33fce03 | 2017-01-16 19:46:22 -0800 | [diff] [blame] | 167 | unsigned dictID = 0; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 168 | |
| 169 | /* Create compressible test buffer */ |
| 170 | if (!CNBuffer || !compressedBuffer || !decodedBuffer || !zc || !zd) { |
Yann Collet | 33fce03 | 2017-01-16 19:46:22 -0800 | [diff] [blame] | 171 | DISPLAY("Not enough memory, aborting \n"); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 172 | goto _output_error; |
| 173 | } |
| 174 | RDG_genBuffer(CNBuffer, CNBufferSize, compressibility, 0., seed); |
| 175 | |
Yann Collet | 33fce03 | 2017-01-16 19:46:22 -0800 | [diff] [blame] | 176 | /* Create dictionary */ |
| 177 | MEM_STATIC_ASSERT(COMPRESSIBLE_NOISE_LENGTH >= 4 MB); |
| 178 | dictionary = FUZ_createDictionary(CNBuffer, 4 MB, 4 KB, 40 KB); |
| 179 | if (!dictionary.start) { |
| 180 | DISPLAY("Error creating dictionary, aborting \n"); |
| 181 | goto _output_error; |
| 182 | } |
| 183 | dictID = ZDICT_getDictID(dictionary.start, dictionary.filled); |
| 184 | |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 185 | /* generate skippable frame */ |
| 186 | MEM_writeLE32(compressedBuffer, ZSTD_MAGIC_SKIPPABLE_START); |
| 187 | MEM_writeLE32(((char*)compressedBuffer)+4, (U32)skippableFrameSize); |
| 188 | cSize = skippableFrameSize + 8; |
| 189 | |
| 190 | /* Basic compression test */ |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 191 | DISPLAYLEVEL(3, "test%3i : compress %u bytes : ", testNb++, COMPRESSIBLE_NOISE_LENGTH); |
Yann Collet | 30ab64e | 2017-05-10 11:30:19 -0700 | [diff] [blame] | 192 | ZSTD_initCStream_usingDict(zc, CNBuffer, dictSize, 1); |
Yann Collet | 53e17fb | 2016-08-17 01:39:22 +0200 | [diff] [blame] | 193 | outBuff.dst = (char*)(compressedBuffer)+cSize; |
| 194 | outBuff.size = compressedBufferSize; |
| 195 | outBuff.pos = 0; |
| 196 | inBuff.src = CNBuffer; |
| 197 | inBuff.size = CNBufferSize; |
| 198 | inBuff.pos = 0; |
| 199 | { size_t const r = ZSTD_compressStream(zc, &outBuff, &inBuff); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 200 | if (ZSTD_isError(r)) goto _output_error; } |
Yann Collet | 53e17fb | 2016-08-17 01:39:22 +0200 | [diff] [blame] | 201 | if (inBuff.pos != inBuff.size) goto _output_error; /* entire input should be consumed */ |
| 202 | { size_t const r = ZSTD_endStream(zc, &outBuff); |
Yann Collet | 9a021c1 | 2016-08-26 09:05:06 +0200 | [diff] [blame] | 203 | if (r != 0) goto _output_error; } /* error, or some data not flushed */ |
Yann Collet | 53e17fb | 2016-08-17 01:39:22 +0200 | [diff] [blame] | 204 | cSize += outBuff.pos; |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 205 | DISPLAYLEVEL(3, "OK (%u bytes : %.2f%%)\n", (U32)cSize, (double)cSize/COMPRESSIBLE_NOISE_LENGTH*100); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 206 | |
Yann Collet | 30ab64e | 2017-05-10 11:30:19 -0700 | [diff] [blame] | 207 | /* context size functions */ |
| 208 | DISPLAYLEVEL(3, "test%3i : estimate CStream size : ", testNb++); |
| 209 | { ZSTD_compressionParameters const cParams = ZSTD_getCParams(1, CNBufferSize, dictSize); |
| 210 | size_t const s = ZSTD_estimateCStreamSize(cParams) |
| 211 | + ZSTD_estimateCDictSize(cParams, dictSize); /* uses ZSTD_initCStream_usingDict() */ |
| 212 | if (ZSTD_isError(s)) goto _output_error; |
| 213 | DISPLAYLEVEL(3, "OK (%u bytes) \n", (U32)s); |
| 214 | } |
| 215 | |
| 216 | DISPLAYLEVEL(3, "test%3i : check actual CStream size : ", testNb++); |
Yann Collet | 70e3b31 | 2016-08-23 01:18:06 +0200 | [diff] [blame] | 217 | { size_t const s = ZSTD_sizeof_CStream(zc); |
Yann Collet | cb32763 | 2016-08-23 00:30:31 +0200 | [diff] [blame] | 218 | if (ZSTD_isError(s)) goto _output_error; |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 219 | DISPLAYLEVEL(3, "OK (%u bytes) \n", (U32)s); |
Yann Collet | cb32763 | 2016-08-23 00:30:31 +0200 | [diff] [blame] | 220 | } |
| 221 | |
Yann Collet | 4b987ad | 2017-04-10 17:50:44 -0700 | [diff] [blame] | 222 | /* Attempt bad compression parameters */ |
| 223 | DISPLAYLEVEL(3, "test%3i : use bad compression parameters : ", testNb++); |
| 224 | { size_t r; |
| 225 | ZSTD_parameters params = ZSTD_getParams(1, 0, 0); |
| 226 | params.cParams.searchLength = 2; |
| 227 | r = ZSTD_initCStream_advanced(zc, NULL, 0, params, 0); |
| 228 | if (!ZSTD_isError(r)) goto _output_error; |
| 229 | DISPLAYLEVEL(3, "init error : %s \n", ZSTD_getErrorName(r)); |
| 230 | } |
| 231 | |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 232 | /* skippable frame test */ |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 233 | DISPLAYLEVEL(3, "test%3i : decompress skippable frame : ", testNb++); |
Yann Collet | 30ab64e | 2017-05-10 11:30:19 -0700 | [diff] [blame] | 234 | ZSTD_initDStream_usingDict(zd, CNBuffer, dictSize); |
Yann Collet | 53e17fb | 2016-08-17 01:39:22 +0200 | [diff] [blame] | 235 | inBuff.src = compressedBuffer; |
| 236 | inBuff.size = cSize; |
| 237 | inBuff.pos = 0; |
| 238 | outBuff.dst = decodedBuffer; |
| 239 | outBuff.size = CNBufferSize; |
| 240 | outBuff.pos = 0; |
| 241 | { size_t const r = ZSTD_decompressStream(zd, &outBuff, &inBuff); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 242 | if (r != 0) goto _output_error; } |
Yann Collet | a33ae64 | 2017-02-28 01:15:28 -0800 | [diff] [blame] | 243 | if (outBuff.pos != 0) goto _output_error; /* skippable frame output len is 0 */ |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 244 | DISPLAYLEVEL(3, "OK \n"); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 245 | |
| 246 | /* Basic decompression test */ |
Yann Collet | 9ffbeea | 2016-12-02 18:37:38 -0800 | [diff] [blame] | 247 | inBuff2 = inBuff; |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 248 | DISPLAYLEVEL(3, "test%3i : decompress %u bytes : ", testNb++, COMPRESSIBLE_NOISE_LENGTH); |
Yann Collet | 30ab64e | 2017-05-10 11:30:19 -0700 | [diff] [blame] | 249 | ZSTD_initDStream_usingDict(zd, CNBuffer, dictSize); |
Yann Collet | bb00274 | 2017-01-25 16:25:38 -0800 | [diff] [blame] | 250 | { size_t const r = ZSTD_setDStreamParameter(zd, DStream_p_maxWindowSize, 1000000000); /* large limit */ |
Yann Collet | 17e482e | 2016-08-23 16:58:10 +0200 | [diff] [blame] | 251 | if (ZSTD_isError(r)) goto _output_error; } |
Yann Collet | 9ffbeea | 2016-12-02 18:37:38 -0800 | [diff] [blame] | 252 | { size_t const remaining = ZSTD_decompressStream(zd, &outBuff, &inBuff); |
| 253 | if (remaining != 0) goto _output_error; } /* should reach end of frame == 0; otherwise, some data left, or an error */ |
| 254 | if (outBuff.pos != CNBufferSize) goto _output_error; /* should regenerate the same amount */ |
| 255 | if (inBuff.pos != inBuff.size) goto _output_error; /* should have read the entire frame */ |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 256 | DISPLAYLEVEL(3, "OK \n"); |
Yann Collet | 9ffbeea | 2016-12-02 18:37:38 -0800 | [diff] [blame] | 257 | |
| 258 | /* Re-use without init */ |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 259 | DISPLAYLEVEL(3, "test%3i : decompress again without init (re-use previous settings): ", testNb++); |
Yann Collet | 9ffbeea | 2016-12-02 18:37:38 -0800 | [diff] [blame] | 260 | outBuff.pos = 0; |
| 261 | { size_t const remaining = ZSTD_decompressStream(zd, &outBuff, &inBuff2); |
| 262 | if (remaining != 0) goto _output_error; } /* should reach end of frame == 0; otherwise, some data left, or an error */ |
Yann Collet | 53e17fb | 2016-08-17 01:39:22 +0200 | [diff] [blame] | 263 | if (outBuff.pos != CNBufferSize) goto _output_error; /* should regenerate the same amount */ |
| 264 | if (inBuff.pos != inBuff.size) goto _output_error; /* should have read the entire frame */ |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 265 | DISPLAYLEVEL(3, "OK \n"); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 266 | |
| 267 | /* check regenerated data is byte exact */ |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 268 | DISPLAYLEVEL(3, "test%3i : check decompressed result : ", testNb++); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 269 | { size_t i; |
| 270 | for (i=0; i<CNBufferSize; i++) { |
| 271 | if (((BYTE*)decodedBuffer)[i] != ((BYTE*)CNBuffer)[i]) goto _output_error; |
| 272 | } } |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 273 | DISPLAYLEVEL(3, "OK \n"); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 274 | |
Yann Collet | f16f449 | 2017-05-09 16:18:17 -0700 | [diff] [blame] | 275 | /* context size functions */ |
| 276 | DISPLAYLEVEL(3, "test%3i : estimate DStream size : ", testNb++); |
| 277 | { ZSTD_frameHeader fhi; |
| 278 | const void* cStart = (char*)compressedBuffer + (skippableFrameSize + 8); |
| 279 | size_t const gfhError = ZSTD_getFrameHeader(&fhi, cStart, cSize); |
| 280 | if (gfhError!=0) goto _output_error; |
| 281 | DISPLAYLEVEL(5, " (windowSize : %u) ", fhi.windowSize); |
| 282 | { size_t const s = ZSTD_estimateDStreamSize(fhi) |
Yann Collet | 30ab64e | 2017-05-10 11:30:19 -0700 | [diff] [blame] | 283 | + ZSTD_estimateDDictSize(dictSize); /* uses ZSTD_initDStream_usingDict() */ |
Yann Collet | f16f449 | 2017-05-09 16:18:17 -0700 | [diff] [blame] | 284 | if (ZSTD_isError(s)) goto _output_error; |
| 285 | DISPLAYLEVEL(3, "OK (%u bytes) \n", (U32)s); |
| 286 | } } |
| 287 | |
| 288 | DISPLAYLEVEL(3, "test%3i : check actual DStream size : ", testNb++); |
Yann Collet | 70e3b31 | 2016-08-23 01:18:06 +0200 | [diff] [blame] | 289 | { size_t const s = ZSTD_sizeof_DStream(zd); |
Yann Collet | cb32763 | 2016-08-23 00:30:31 +0200 | [diff] [blame] | 290 | if (ZSTD_isError(s)) goto _output_error; |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 291 | DISPLAYLEVEL(3, "OK (%u bytes) \n", (U32)s); |
Yann Collet | cb32763 | 2016-08-23 00:30:31 +0200 | [diff] [blame] | 292 | } |
| 293 | |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 294 | /* Byte-by-byte decompression test */ |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 295 | DISPLAYLEVEL(3, "test%3i : decompress byte-by-byte : ", testNb++); |
Yann Collet | 3ecbe6a | 2016-09-14 17:26:59 +0200 | [diff] [blame] | 296 | { /* skippable frame */ |
| 297 | size_t r = 1; |
Yann Collet | 30ab64e | 2017-05-10 11:30:19 -0700 | [diff] [blame] | 298 | ZSTD_initDStream_usingDict(zd, CNBuffer, dictSize); |
Yann Collet | 53e17fb | 2016-08-17 01:39:22 +0200 | [diff] [blame] | 299 | inBuff.src = compressedBuffer; |
| 300 | outBuff.dst = decodedBuffer; |
| 301 | inBuff.pos = 0; |
| 302 | outBuff.pos = 0; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 303 | while (r) { /* skippable frame */ |
Yann Collet | 53e17fb | 2016-08-17 01:39:22 +0200 | [diff] [blame] | 304 | inBuff.size = inBuff.pos + 1; |
| 305 | outBuff.size = outBuff.pos + 1; |
| 306 | r = ZSTD_decompressStream(zd, &outBuff, &inBuff); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 307 | if (ZSTD_isError(r)) goto _output_error; |
| 308 | } |
Yann Collet | 3ecbe6a | 2016-09-14 17:26:59 +0200 | [diff] [blame] | 309 | /* normal frame */ |
Yann Collet | 30ab64e | 2017-05-10 11:30:19 -0700 | [diff] [blame] | 310 | ZSTD_initDStream_usingDict(zd, CNBuffer, dictSize); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 311 | r=1; |
Yann Collet | 3ecbe6a | 2016-09-14 17:26:59 +0200 | [diff] [blame] | 312 | while (r) { |
Yann Collet | 53e17fb | 2016-08-17 01:39:22 +0200 | [diff] [blame] | 313 | inBuff.size = inBuff.pos + 1; |
| 314 | outBuff.size = outBuff.pos + 1; |
| 315 | r = ZSTD_decompressStream(zd, &outBuff, &inBuff); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 316 | if (ZSTD_isError(r)) goto _output_error; |
| 317 | } |
| 318 | } |
Yann Collet | 53e17fb | 2016-08-17 01:39:22 +0200 | [diff] [blame] | 319 | if (outBuff.pos != CNBufferSize) goto _output_error; /* should regenerate the same amount */ |
| 320 | if (inBuff.pos != cSize) goto _output_error; /* should have read the entire frame */ |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 321 | DISPLAYLEVEL(3, "OK \n"); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 322 | |
| 323 | /* check regenerated data is byte exact */ |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 324 | DISPLAYLEVEL(3, "test%3i : check decompressed result : ", testNb++); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 325 | { size_t i; |
| 326 | for (i=0; i<CNBufferSize; i++) { |
| 327 | if (((BYTE*)decodedBuffer)[i] != ((BYTE*)CNBuffer)[i]) goto _output_error;; |
| 328 | } } |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 329 | DISPLAYLEVEL(3, "OK \n"); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 330 | |
Yann Collet | e795c8a | 2016-12-13 16:39:36 +0100 | [diff] [blame] | 331 | /* _srcSize compression test */ |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 332 | DISPLAYLEVEL(3, "test%3i : compress_srcSize %u bytes : ", testNb++, COMPRESSIBLE_NOISE_LENGTH); |
Yann Collet | e795c8a | 2016-12-13 16:39:36 +0100 | [diff] [blame] | 333 | ZSTD_initCStream_srcSize(zc, 1, CNBufferSize); |
Yann Collet | d564faa | 2016-12-18 21:39:15 +0100 | [diff] [blame] | 334 | outBuff.dst = (char*)(compressedBuffer); |
Yann Collet | e795c8a | 2016-12-13 16:39:36 +0100 | [diff] [blame] | 335 | outBuff.size = compressedBufferSize; |
| 336 | outBuff.pos = 0; |
| 337 | inBuff.src = CNBuffer; |
| 338 | inBuff.size = CNBufferSize; |
| 339 | inBuff.pos = 0; |
| 340 | { size_t const r = ZSTD_compressStream(zc, &outBuff, &inBuff); |
| 341 | if (ZSTD_isError(r)) goto _output_error; } |
| 342 | if (inBuff.pos != inBuff.size) goto _output_error; /* entire input should be consumed */ |
| 343 | { size_t const r = ZSTD_endStream(zc, &outBuff); |
| 344 | if (r != 0) goto _output_error; } /* error, or some data not flushed */ |
Sean Purcell | 4e70971 | 2017-02-07 13:50:09 -0800 | [diff] [blame] | 345 | { unsigned long long origSize = ZSTD_findDecompressedSize(outBuff.dst, outBuff.pos); |
Yann Collet | d564faa | 2016-12-18 21:39:15 +0100 | [diff] [blame] | 346 | if ((size_t)origSize != CNBufferSize) goto _output_error; } /* exact original size must be present */ |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 347 | DISPLAYLEVEL(3, "OK (%u bytes : %.2f%%)\n", (U32)cSize, (double)cSize/COMPRESSIBLE_NOISE_LENGTH*100); |
Yann Collet | e795c8a | 2016-12-13 16:39:36 +0100 | [diff] [blame] | 348 | |
| 349 | /* wrong _srcSize compression test */ |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 350 | DISPLAYLEVEL(3, "test%3i : wrong srcSize : %u bytes : ", testNb++, COMPRESSIBLE_NOISE_LENGTH-1); |
Yann Collet | e795c8a | 2016-12-13 16:39:36 +0100 | [diff] [blame] | 351 | ZSTD_initCStream_srcSize(zc, 1, CNBufferSize-1); |
Yann Collet | d564faa | 2016-12-18 21:39:15 +0100 | [diff] [blame] | 352 | outBuff.dst = (char*)(compressedBuffer); |
Yann Collet | e795c8a | 2016-12-13 16:39:36 +0100 | [diff] [blame] | 353 | outBuff.size = compressedBufferSize; |
| 354 | outBuff.pos = 0; |
| 355 | inBuff.src = CNBuffer; |
| 356 | inBuff.size = CNBufferSize; |
| 357 | inBuff.pos = 0; |
| 358 | { size_t const r = ZSTD_compressStream(zc, &outBuff, &inBuff); |
| 359 | if (ZSTD_isError(r)) goto _output_error; } |
| 360 | if (inBuff.pos != inBuff.size) goto _output_error; /* entire input should be consumed */ |
| 361 | { size_t const r = ZSTD_endStream(zc, &outBuff); |
| 362 | if (ZSTD_getErrorCode(r) != ZSTD_error_srcSize_wrong) goto _output_error; /* must fail : wrong srcSize */ |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 363 | DISPLAYLEVEL(3, "OK (error detected : %s) \n", ZSTD_getErrorName(r)); } |
Yann Collet | e795c8a | 2016-12-13 16:39:36 +0100 | [diff] [blame] | 364 | |
Yann Collet | 12083a4 | 2016-09-06 15:01:51 +0200 | [diff] [blame] | 365 | /* Complex context re-use scenario */ |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 366 | DISPLAYLEVEL(3, "test%3i : context re-use : ", testNb++); |
Yann Collet | 12083a4 | 2016-09-06 15:01:51 +0200 | [diff] [blame] | 367 | ZSTD_freeCStream(zc); |
| 368 | zc = ZSTD_createCStream_advanced(customMem); |
| 369 | if (zc==NULL) goto _output_error; /* memory allocation issue */ |
| 370 | /* use 1 */ |
| 371 | { size_t const inSize = 513; |
Yann Collet | 0be6fd3 | 2017-05-08 16:08:01 -0700 | [diff] [blame] | 372 | DISPLAYLEVEL(5, "use1 "); |
Yann Collet | 12083a4 | 2016-09-06 15:01:51 +0200 | [diff] [blame] | 373 | ZSTD_initCStream_advanced(zc, NULL, 0, ZSTD_getParams(19, inSize, 0), inSize); /* needs btopt + search3 to trigger hashLog3 */ |
| 374 | inBuff.src = CNBuffer; |
| 375 | inBuff.size = inSize; |
| 376 | inBuff.pos = 0; |
| 377 | outBuff.dst = (char*)(compressedBuffer)+cSize; |
| 378 | outBuff.size = ZSTD_compressBound(inSize); |
| 379 | outBuff.pos = 0; |
Yann Collet | 0be6fd3 | 2017-05-08 16:08:01 -0700 | [diff] [blame] | 380 | DISPLAYLEVEL(5, "compress1 "); |
Yann Collet | 12083a4 | 2016-09-06 15:01:51 +0200 | [diff] [blame] | 381 | { size_t const r = ZSTD_compressStream(zc, &outBuff, &inBuff); |
| 382 | if (ZSTD_isError(r)) goto _output_error; } |
| 383 | if (inBuff.pos != inBuff.size) goto _output_error; /* entire input should be consumed */ |
Yann Collet | 0be6fd3 | 2017-05-08 16:08:01 -0700 | [diff] [blame] | 384 | DISPLAYLEVEL(5, "end1 "); |
Yann Collet | 12083a4 | 2016-09-06 15:01:51 +0200 | [diff] [blame] | 385 | { size_t const r = ZSTD_endStream(zc, &outBuff); |
| 386 | if (r != 0) goto _output_error; } /* error, or some data not flushed */ |
| 387 | } |
| 388 | /* use 2 */ |
| 389 | { size_t const inSize = 1025; /* will not continue, because tables auto-adjust and are therefore different size */ |
Yann Collet | 0be6fd3 | 2017-05-08 16:08:01 -0700 | [diff] [blame] | 390 | DISPLAYLEVEL(5, "use2 "); |
Yann Collet | 12083a4 | 2016-09-06 15:01:51 +0200 | [diff] [blame] | 391 | ZSTD_initCStream_advanced(zc, NULL, 0, ZSTD_getParams(19, inSize, 0), inSize); /* needs btopt + search3 to trigger hashLog3 */ |
| 392 | inBuff.src = CNBuffer; |
| 393 | inBuff.size = inSize; |
| 394 | inBuff.pos = 0; |
| 395 | outBuff.dst = (char*)(compressedBuffer)+cSize; |
| 396 | outBuff.size = ZSTD_compressBound(inSize); |
| 397 | outBuff.pos = 0; |
Yann Collet | 0be6fd3 | 2017-05-08 16:08:01 -0700 | [diff] [blame] | 398 | DISPLAYLEVEL(5, "compress2 "); |
Yann Collet | 12083a4 | 2016-09-06 15:01:51 +0200 | [diff] [blame] | 399 | { size_t const r = ZSTD_compressStream(zc, &outBuff, &inBuff); |
| 400 | if (ZSTD_isError(r)) goto _output_error; } |
| 401 | if (inBuff.pos != inBuff.size) goto _output_error; /* entire input should be consumed */ |
Yann Collet | 0be6fd3 | 2017-05-08 16:08:01 -0700 | [diff] [blame] | 402 | DISPLAYLEVEL(5, "end2 "); |
Yann Collet | 12083a4 | 2016-09-06 15:01:51 +0200 | [diff] [blame] | 403 | { size_t const r = ZSTD_endStream(zc, &outBuff); |
| 404 | if (r != 0) goto _output_error; } /* error, or some data not flushed */ |
| 405 | } |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 406 | DISPLAYLEVEL(3, "OK \n"); |
Yann Collet | 12083a4 | 2016-09-06 15:01:51 +0200 | [diff] [blame] | 407 | |
Yann Collet | 9516234 | 2016-10-25 16:19:52 -0700 | [diff] [blame] | 408 | /* CDict scenario */ |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 409 | DISPLAYLEVEL(3, "test%3i : digested dictionary : ", testNb++); |
Yann Collet | 33fce03 | 2017-01-16 19:46:22 -0800 | [diff] [blame] | 410 | { ZSTD_CDict* const cdict = ZSTD_createCDict(dictionary.start, dictionary.filled, 1); |
Yann Collet | 9516234 | 2016-10-25 16:19:52 -0700 | [diff] [blame] | 411 | size_t const initError = ZSTD_initCStream_usingCDict(zc, cdict); |
| 412 | if (ZSTD_isError(initError)) goto _output_error; |
| 413 | cSize = 0; |
| 414 | outBuff.dst = compressedBuffer; |
| 415 | outBuff.size = compressedBufferSize; |
| 416 | outBuff.pos = 0; |
| 417 | inBuff.src = CNBuffer; |
| 418 | inBuff.size = CNBufferSize; |
| 419 | inBuff.pos = 0; |
| 420 | { size_t const r = ZSTD_compressStream(zc, &outBuff, &inBuff); |
| 421 | if (ZSTD_isError(r)) goto _output_error; } |
| 422 | if (inBuff.pos != inBuff.size) goto _output_error; /* entire input should be consumed */ |
| 423 | { size_t const r = ZSTD_endStream(zc, &outBuff); |
| 424 | if (r != 0) goto _output_error; } /* error, or some data not flushed */ |
| 425 | cSize = outBuff.pos; |
| 426 | ZSTD_freeCDict(cdict); |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 427 | DISPLAYLEVEL(3, "OK (%u bytes : %.2f%%)\n", (U32)cSize, (double)cSize/CNBufferSize*100); |
Yann Collet | 9516234 | 2016-10-25 16:19:52 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 430 | DISPLAYLEVEL(3, "test%3i : check CStream size : ", testNb++); |
Yann Collet | 12083a4 | 2016-09-06 15:01:51 +0200 | [diff] [blame] | 431 | { size_t const s = ZSTD_sizeof_CStream(zc); |
| 432 | if (ZSTD_isError(s)) goto _output_error; |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 433 | DISPLAYLEVEL(3, "OK (%u bytes) \n", (U32)s); |
Yann Collet | 12083a4 | 2016-09-06 15:01:51 +0200 | [diff] [blame] | 434 | } |
| 435 | |
Yann Collet | 33fce03 | 2017-01-16 19:46:22 -0800 | [diff] [blame] | 436 | DISPLAYLEVEL(4, "test%3i : check Dictionary ID : ", testNb++); |
| 437 | { unsigned const dID = ZSTD_getDictID_fromFrame(compressedBuffer, cSize); |
| 438 | if (dID != dictID) goto _output_error; |
| 439 | DISPLAYLEVEL(4, "OK (%u) \n", dID); |
| 440 | } |
| 441 | |
Yann Collet | 335ad5d | 2016-10-25 17:47:02 -0700 | [diff] [blame] | 442 | /* DDict scenario */ |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 443 | DISPLAYLEVEL(3, "test%3i : decompress %u bytes with digested dictionary : ", testNb++, (U32)CNBufferSize); |
Yann Collet | 33fce03 | 2017-01-16 19:46:22 -0800 | [diff] [blame] | 444 | { ZSTD_DDict* const ddict = ZSTD_createDDict(dictionary.start, dictionary.filled); |
Yann Collet | 335ad5d | 2016-10-25 17:47:02 -0700 | [diff] [blame] | 445 | size_t const initError = ZSTD_initDStream_usingDDict(zd, ddict); |
| 446 | if (ZSTD_isError(initError)) goto _output_error; |
| 447 | inBuff.src = compressedBuffer; |
| 448 | inBuff.size = cSize; |
| 449 | inBuff.pos = 0; |
| 450 | outBuff.dst = decodedBuffer; |
| 451 | outBuff.size = CNBufferSize; |
| 452 | outBuff.pos = 0; |
| 453 | { size_t const r = ZSTD_decompressStream(zd, &outBuff, &inBuff); |
| 454 | if (r != 0) goto _output_error; } /* should reach end of frame == 0; otherwise, some data left, or an error */ |
| 455 | if (outBuff.pos != CNBufferSize) goto _output_error; /* should regenerate the same amount */ |
| 456 | if (inBuff.pos != inBuff.size) goto _output_error; /* should have read the entire frame */ |
| 457 | ZSTD_freeDDict(ddict); |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 458 | DISPLAYLEVEL(3, "OK \n"); |
Yann Collet | 335ad5d | 2016-10-25 17:47:02 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Yann Collet | 12083a4 | 2016-09-06 15:01:51 +0200 | [diff] [blame] | 461 | /* test ZSTD_setDStreamParameter() resilience */ |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 462 | DISPLAYLEVEL(3, "test%3i : wrong parameter for ZSTD_setDStreamParameter(): ", testNb++); |
Yann Collet | 17e482e | 2016-08-23 16:58:10 +0200 | [diff] [blame] | 463 | { size_t const r = ZSTD_setDStreamParameter(zd, (ZSTD_DStreamParameter_e)999, 1); /* large limit */ |
| 464 | if (!ZSTD_isError(r)) goto _output_error; } |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 465 | DISPLAYLEVEL(3, "OK \n"); |
Yann Collet | 17e482e | 2016-08-23 16:58:10 +0200 | [diff] [blame] | 466 | |
| 467 | /* Memory restriction */ |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 468 | DISPLAYLEVEL(3, "test%3i : maxWindowSize < frame requirement : ", testNb++); |
Yann Collet | 30ab64e | 2017-05-10 11:30:19 -0700 | [diff] [blame] | 469 | ZSTD_initDStream_usingDict(zd, CNBuffer, dictSize); |
Yann Collet | bb00274 | 2017-01-25 16:25:38 -0800 | [diff] [blame] | 470 | { size_t const r = ZSTD_setDStreamParameter(zd, DStream_p_maxWindowSize, 1000); /* too small limit */ |
Yann Collet | 17e482e | 2016-08-23 16:58:10 +0200 | [diff] [blame] | 471 | if (ZSTD_isError(r)) goto _output_error; } |
| 472 | inBuff.src = compressedBuffer; |
| 473 | inBuff.size = cSize; |
| 474 | inBuff.pos = 0; |
| 475 | outBuff.dst = decodedBuffer; |
| 476 | outBuff.size = CNBufferSize; |
| 477 | outBuff.pos = 0; |
| 478 | { size_t const r = ZSTD_decompressStream(zd, &outBuff, &inBuff); |
| 479 | if (!ZSTD_isError(r)) goto _output_error; /* must fail : frame requires > 100 bytes */ |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 480 | DISPLAYLEVEL(3, "OK (%s)\n", ZSTD_getErrorName(r)); } |
Yann Collet | 17e482e | 2016-08-23 16:58:10 +0200 | [diff] [blame] | 481 | |
Yann Collet | 7d283cd | 2017-04-27 14:48:34 -0700 | [diff] [blame] | 482 | DISPLAYLEVEL(3, "test%3i : ZSTD_initCStream_usingCDict_advanced with masked dictID : ", testNb++); |
| 483 | { ZSTD_compressionParameters const cParams = ZSTD_getCParams(1, CNBufferSize, dictionary.filled); |
| 484 | ZSTD_frameParameters const fParams = { 1 /* contentSize */, 1 /* checksum */, 1 /* noDictID */}; |
Yann Collet | a92cbb7 | 2017-04-27 15:08:56 -0700 | [diff] [blame] | 485 | ZSTD_CDict* const cdict = ZSTD_createCDict_advanced(dictionary.start, dictionary.filled, 1 /* byReference */, cParams, customMem); |
Yann Collet | 7d283cd | 2017-04-27 14:48:34 -0700 | [diff] [blame] | 486 | size_t const initError = ZSTD_initCStream_usingCDict_advanced(zc, cdict, CNBufferSize, fParams); |
| 487 | if (ZSTD_isError(initError)) goto _output_error; |
Nick Terrell | 62ecad3 | 2017-04-03 20:56:39 -0700 | [diff] [blame] | 488 | cSize = 0; |
| 489 | outBuff.dst = compressedBuffer; |
| 490 | outBuff.size = compressedBufferSize; |
| 491 | outBuff.pos = 0; |
| 492 | inBuff.src = CNBuffer; |
| 493 | inBuff.size = CNBufferSize; |
| 494 | inBuff.pos = 0; |
| 495 | { size_t const r = ZSTD_compressStream(zc, &outBuff, &inBuff); |
| 496 | if (ZSTD_isError(r)) goto _output_error; } |
| 497 | if (inBuff.pos != inBuff.size) goto _output_error; /* entire input should be consumed */ |
| 498 | { size_t const r = ZSTD_endStream(zc, &outBuff); |
| 499 | if (r != 0) goto _output_error; } /* error, or some data not flushed */ |
| 500 | cSize = outBuff.pos; |
| 501 | ZSTD_freeCDict(cdict); |
| 502 | DISPLAYLEVEL(3, "OK (%u bytes : %.2f%%)\n", (U32)cSize, (double)cSize/CNBufferSize*100); |
Yann Collet | 4ee6b15 | 2017-04-11 11:59:44 -0700 | [diff] [blame] | 503 | } |
Nick Terrell | 62ecad3 | 2017-04-03 20:56:39 -0700 | [diff] [blame] | 504 | |
Yann Collet | a92cbb7 | 2017-04-27 15:08:56 -0700 | [diff] [blame] | 505 | DISPLAYLEVEL(3, "test%3i : try retrieving dictID from frame : ", testNb++); |
| 506 | { U32 const did = ZSTD_getDictID_fromFrame(compressedBuffer, cSize); |
| 507 | if (did != 0) goto _output_error; |
| 508 | } |
| 509 | DISPLAYLEVEL(3, "OK (not detected) \n"); |
| 510 | |
Yann Collet | 4ee6b15 | 2017-04-11 11:59:44 -0700 | [diff] [blame] | 511 | DISPLAYLEVEL(3, "test%3i : decompress without dictionary : ", testNb++); |
| 512 | { size_t const r = ZSTD_decompress(decodedBuffer, CNBufferSize, compressedBuffer, cSize); |
| 513 | if (!ZSTD_isError(r)) goto _output_error; /* must fail : dictionary not used */ |
| 514 | DISPLAYLEVEL(3, "OK (%s)\n", ZSTD_getErrorName(r)); |
Nick Terrell | 62ecad3 | 2017-04-03 20:56:39 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Yann Collet | 0bb381d | 2017-04-18 15:08:52 -0700 | [diff] [blame] | 517 | /* Empty srcSize */ |
| 518 | DISPLAYLEVEL(3, "test%3i : ZSTD_initCStream_advanced with pledgedSrcSize=0 and dict : ", testNb++); |
| 519 | { ZSTD_parameters params = ZSTD_getParams(5, 0, 0); |
| 520 | params.fParams.contentSizeFlag = 1; |
| 521 | ZSTD_initCStream_advanced(zc, dictionary.start, dictionary.filled, params, 0); |
| 522 | } /* cstream advanced shall write content size = 0 */ |
| 523 | inBuff.src = CNBuffer; |
| 524 | inBuff.size = 0; |
| 525 | inBuff.pos = 0; |
| 526 | outBuff.dst = compressedBuffer; |
| 527 | outBuff.size = compressedBufferSize; |
| 528 | outBuff.pos = 0; |
| 529 | if (ZSTD_isError(ZSTD_compressStream(zc, &outBuff, &inBuff))) goto _output_error; |
| 530 | if (ZSTD_endStream(zc, &outBuff) != 0) goto _output_error; |
| 531 | cSize = outBuff.pos; |
| 532 | if (ZSTD_findDecompressedSize(compressedBuffer, cSize) != 0) goto _output_error; |
| 533 | DISPLAYLEVEL(3, "OK \n"); |
| 534 | |
Sean Purcell | 2db7249 | 2017-02-09 10:50:43 -0800 | [diff] [blame] | 535 | DISPLAYLEVEL(3, "test%3i : pledgedSrcSize == 0 behaves properly : ", testNb++); |
| 536 | { ZSTD_parameters params = ZSTD_getParams(5, 0, 0); |
| 537 | params.fParams.contentSizeFlag = 1; |
Yann Collet | 4ee6b15 | 2017-04-11 11:59:44 -0700 | [diff] [blame] | 538 | ZSTD_initCStream_advanced(zc, NULL, 0, params, 0); |
| 539 | } /* cstream advanced shall write content size = 0 */ |
Sean Purcell | 2db7249 | 2017-02-09 10:50:43 -0800 | [diff] [blame] | 540 | inBuff.src = CNBuffer; |
| 541 | inBuff.size = 0; |
| 542 | inBuff.pos = 0; |
| 543 | outBuff.dst = compressedBuffer; |
| 544 | outBuff.size = compressedBufferSize; |
| 545 | outBuff.pos = 0; |
| 546 | if (ZSTD_isError(ZSTD_compressStream(zc, &outBuff, &inBuff))) goto _output_error; |
| 547 | if (ZSTD_endStream(zc, &outBuff) != 0) goto _output_error; |
| 548 | cSize = outBuff.pos; |
| 549 | if (ZSTD_findDecompressedSize(compressedBuffer, cSize) != 0) goto _output_error; |
| 550 | |
| 551 | ZSTD_resetCStream(zc, 0); /* resetCStream should treat 0 as unknown */ |
| 552 | inBuff.src = CNBuffer; |
| 553 | inBuff.size = 0; |
| 554 | inBuff.pos = 0; |
| 555 | outBuff.dst = compressedBuffer; |
| 556 | outBuff.size = compressedBufferSize; |
| 557 | outBuff.pos = 0; |
| 558 | if (ZSTD_isError(ZSTD_compressStream(zc, &outBuff, &inBuff))) goto _output_error; |
| 559 | if (ZSTD_endStream(zc, &outBuff) != 0) goto _output_error; |
| 560 | cSize = outBuff.pos; |
| 561 | if (ZSTD_findDecompressedSize(compressedBuffer, cSize) != ZSTD_CONTENTSIZE_UNKNOWN) goto _output_error; |
| 562 | DISPLAYLEVEL(3, "OK \n"); |
Yann Collet | 17e482e | 2016-08-23 16:58:10 +0200 | [diff] [blame] | 563 | |
Sean Purcell | 887eaa9 | 2017-02-15 16:43:45 -0800 | [diff] [blame] | 564 | /* Overlen overwriting window data bug */ |
| 565 | DISPLAYLEVEL(3, "test%3i : wildcopy doesn't overwrite potential match data : ", testNb++); |
Sean Purcell | 0ed3901 | 2017-02-16 13:29:47 -0800 | [diff] [blame] | 566 | { /* This test has a window size of 1024 bytes and consists of 3 blocks: |
| 567 | 1. 'a' repeated 517 times |
| 568 | 2. 'b' repeated 516 times |
| 569 | 3. a compressed block with no literals and 3 sequence commands: |
| 570 | litlength = 0, offset = 24, match length = 24 |
| 571 | litlength = 0, offset = 24, match length = 3 (this one creates an overlength write of length 2*WILDCOPY_OVERLENGTH - 3) |
| 572 | litlength = 0, offset = 1021, match length = 3 (this one will try to read from overwritten data if the buffer is too small) */ |
| 573 | |
| 574 | const char* testCase = |
| 575 | "\x28\xB5\x2F\xFD\x04\x00\x4C\x00\x00\x10\x61\x61\x01\x00\x00\x2A" |
| 576 | "\x80\x05\x44\x00\x00\x08\x62\x01\x00\x00\x2A\x20\x04\x5D\x00\x00" |
| 577 | "\x00\x03\x40\x00\x00\x64\x60\x27\xB0\xE0\x0C\x67\x62\xCE\xE0"; |
Sean Purcell | 887eaa9 | 2017-02-15 16:43:45 -0800 | [diff] [blame] | 578 | ZSTD_DStream* zds = ZSTD_createDStream(); |
| 579 | |
| 580 | ZSTD_initDStream(zds); |
| 581 | inBuff.src = testCase; |
Sean Purcell | 0ed3901 | 2017-02-16 13:29:47 -0800 | [diff] [blame] | 582 | inBuff.size = 47; |
Sean Purcell | 887eaa9 | 2017-02-15 16:43:45 -0800 | [diff] [blame] | 583 | inBuff.pos = 0; |
| 584 | outBuff.dst = decodedBuffer; |
| 585 | outBuff.size = CNBufferSize; |
| 586 | outBuff.pos = 0; |
| 587 | |
| 588 | while (inBuff.pos < inBuff.size) { |
| 589 | size_t const r = ZSTD_decompressStream(zds, &outBuff, &inBuff); |
| 590 | /* Bug will cause checksum to fail */ |
| 591 | if (ZSTD_isError(r)) goto _output_error; |
| 592 | } |
Przemyslaw Skibinski | 684858e | 2017-02-21 18:17:24 +0100 | [diff] [blame] | 593 | |
| 594 | ZSTD_freeDStream(zds); |
Sean Purcell | 887eaa9 | 2017-02-15 16:43:45 -0800 | [diff] [blame] | 595 | } |
| 596 | DISPLAYLEVEL(3, "OK \n"); |
| 597 | |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 598 | _end: |
Yann Collet | 33fce03 | 2017-01-16 19:46:22 -0800 | [diff] [blame] | 599 | FUZ_freeDictionary(dictionary); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 600 | ZSTD_freeCStream(zc); |
| 601 | ZSTD_freeDStream(zd); |
| 602 | free(CNBuffer); |
| 603 | free(compressedBuffer); |
| 604 | free(decodedBuffer); |
| 605 | return testResult; |
| 606 | |
| 607 | _output_error: |
| 608 | testResult = 1; |
| 609 | DISPLAY("Error detected in Unit tests ! \n"); |
| 610 | goto _end; |
| 611 | } |
| 612 | |
| 613 | |
Yann Collet | 3ecbe6a | 2016-09-14 17:26:59 +0200 | [diff] [blame] | 614 | /* ====== Fuzzer tests ====== */ |
| 615 | |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 616 | static size_t findDiff(const void* buf1, const void* buf2, size_t max) |
| 617 | { |
| 618 | const BYTE* b1 = (const BYTE*)buf1; |
| 619 | const BYTE* b2 = (const BYTE*)buf2; |
| 620 | size_t u; |
| 621 | for (u=0; u<max; u++) { |
| 622 | if (b1[u] != b2[u]) break; |
| 623 | } |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 624 | DISPLAY("Error at position %u / %u \n", (U32)u, (U32)max); |
Yann Collet | bb00274 | 2017-01-25 16:25:38 -0800 | [diff] [blame] | 625 | DISPLAY(" %02X %02X %02X :%02X: %02X %02X %02X %02X %02X \n", |
| 626 | b1[u-3], b1[u-2], b1[u-1], b1[u-0], b1[u+1], b1[u+2], b1[u+3], b1[u+4], b1[u+5]); |
| 627 | DISPLAY(" %02X %02X %02X :%02X: %02X %02X %02X %02X %02X \n", |
| 628 | b2[u-3], b2[u-2], b2[u-1], b2[u-0], b2[u+1], b2[u+2], b2[u+3], b2[u+4], b2[u+5]); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 629 | return u; |
| 630 | } |
| 631 | |
| 632 | static size_t FUZ_rLogLength(U32* seed, U32 logLength) |
| 633 | { |
| 634 | size_t const lengthMask = ((size_t)1 << logLength) - 1; |
| 635 | return (lengthMask+1) + (FUZ_rand(seed) & lengthMask); |
| 636 | } |
| 637 | |
| 638 | static size_t FUZ_randomLength(U32* seed, U32 maxLog) |
| 639 | { |
| 640 | U32 const logLength = FUZ_rand(seed) % maxLog; |
| 641 | return FUZ_rLogLength(seed, logLength); |
| 642 | } |
| 643 | |
| 644 | #define MIN(a,b) ( (a) < (b) ? (a) : (b) ) |
| 645 | |
| 646 | #define CHECK(cond, ...) if (cond) { DISPLAY("Error => "); DISPLAY(__VA_ARGS__); \ |
| 647 | DISPLAY(" (seed %u, test nb %u) \n", seed, testNb); goto _output_error; } |
| 648 | |
Sean Purcell | 7ebf2de | 2017-03-20 11:25:00 -0700 | [diff] [blame] | 649 | static int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibility, int bigTests) |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 650 | { |
| 651 | static const U32 maxSrcLog = 24; |
| 652 | static const U32 maxSampleLog = 19; |
Yann Collet | 58d5dfe | 2016-09-25 01:34:03 +0200 | [diff] [blame] | 653 | size_t const srcBufferSize = (size_t)1<<maxSrcLog; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 654 | BYTE* cNoiseBuffer[5]; |
Yann Collet | 58d5dfe | 2016-09-25 01:34:03 +0200 | [diff] [blame] | 655 | size_t const copyBufferSize= srcBufferSize + (1<<maxSampleLog); |
| 656 | BYTE* const copyBuffer = (BYTE*)malloc (copyBufferSize); |
| 657 | size_t const cBufferSize = ZSTD_compressBound(srcBufferSize); |
| 658 | BYTE* const cBuffer = (BYTE*)malloc (cBufferSize); |
| 659 | size_t const dstBufferSize = srcBufferSize; |
| 660 | BYTE* const dstBuffer = (BYTE*)malloc (dstBufferSize); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 661 | U32 result = 0; |
| 662 | U32 testNb = 0; |
| 663 | U32 coreSeed = seed; |
Yann Collet | 58d5dfe | 2016-09-25 01:34:03 +0200 | [diff] [blame] | 664 | ZSTD_CStream* zc = ZSTD_createCStream(); /* will be reset sometimes */ |
| 665 | ZSTD_DStream* zd = ZSTD_createDStream(); /* will be reset sometimes */ |
| 666 | ZSTD_DStream* const zd_noise = ZSTD_createDStream(); |
| 667 | clock_t const startClock = clock(); |
| 668 | const BYTE* dict=NULL; /* can keep same dict on 2 consecutive tests */ |
Yann Collet | cf409a7 | 2016-09-26 16:41:05 +0200 | [diff] [blame] | 669 | size_t dictSize = 0; |
| 670 | U32 oldTestLog = 0; |
Sean Purcell | 7ebf2de | 2017-03-20 11:25:00 -0700 | [diff] [blame] | 671 | int const cLevelLimiter = bigTests ? 3 : 2; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 672 | |
| 673 | /* allocations */ |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 674 | cNoiseBuffer[0] = (BYTE*)malloc (srcBufferSize); |
| 675 | cNoiseBuffer[1] = (BYTE*)malloc (srcBufferSize); |
| 676 | cNoiseBuffer[2] = (BYTE*)malloc (srcBufferSize); |
| 677 | cNoiseBuffer[3] = (BYTE*)malloc (srcBufferSize); |
| 678 | cNoiseBuffer[4] = (BYTE*)malloc (srcBufferSize); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 679 | CHECK (!cNoiseBuffer[0] || !cNoiseBuffer[1] || !cNoiseBuffer[2] || !cNoiseBuffer[3] || !cNoiseBuffer[4] || |
Yann Collet | 58d5dfe | 2016-09-25 01:34:03 +0200 | [diff] [blame] | 680 | !copyBuffer || !dstBuffer || !cBuffer || !zc || !zd || !zd_noise , |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 681 | "Not enough memory, fuzzer tests cancelled"); |
| 682 | |
| 683 | /* Create initial samples */ |
| 684 | RDG_genBuffer(cNoiseBuffer[0], srcBufferSize, 0.00, 0., coreSeed); /* pure noise */ |
| 685 | RDG_genBuffer(cNoiseBuffer[1], srcBufferSize, 0.05, 0., coreSeed); /* barely compressible */ |
| 686 | RDG_genBuffer(cNoiseBuffer[2], srcBufferSize, compressibility, 0., coreSeed); |
| 687 | RDG_genBuffer(cNoiseBuffer[3], srcBufferSize, 0.95, 0., coreSeed); /* highly compressible */ |
| 688 | RDG_genBuffer(cNoiseBuffer[4], srcBufferSize, 1.00, 0., coreSeed); /* sparse content */ |
| 689 | memset(copyBuffer, 0x65, copyBufferSize); /* make copyBuffer considered initialized */ |
Yann Collet | 58d5dfe | 2016-09-25 01:34:03 +0200 | [diff] [blame] | 690 | ZSTD_initDStream_usingDict(zd, NULL, 0); /* ensure at least one init */ |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 691 | |
| 692 | /* catch up testNb */ |
| 693 | for (testNb=1; testNb < startTest; testNb++) |
| 694 | FUZ_rand(&coreSeed); |
| 695 | |
| 696 | /* test loop */ |
Yann Collet | ef9999f | 2016-09-01 16:44:48 -0700 | [diff] [blame] | 697 | for ( ; (testNb <= nbTests) || (FUZ_GetClockSpan(startClock) < g_clockTime) ; testNb++ ) { |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 698 | U32 lseed; |
| 699 | const BYTE* srcBuffer; |
Yann Collet | 58d5dfe | 2016-09-25 01:34:03 +0200 | [diff] [blame] | 700 | size_t totalTestSize, totalGenSize, cSize; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 701 | XXH64_state_t xxhState; |
| 702 | U64 crcOrig; |
Yann Collet | 58d5dfe | 2016-09-25 01:34:03 +0200 | [diff] [blame] | 703 | U32 resetAllowed = 1; |
Yann Collet | cf409a7 | 2016-09-26 16:41:05 +0200 | [diff] [blame] | 704 | size_t maxTestSize; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 705 | |
| 706 | /* init */ |
Yann Collet | 4c0b44f | 2016-11-01 11:13:22 -0700 | [diff] [blame] | 707 | if (nbTests >= testNb) { DISPLAYUPDATE(2, "\r%6u/%6u ", testNb, nbTests); } |
| 708 | else { DISPLAYUPDATE(2, "\r%6u ", testNb); } |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 709 | FUZ_rand(&coreSeed); |
Yann Collet | 33fce03 | 2017-01-16 19:46:22 -0800 | [diff] [blame] | 710 | lseed = coreSeed ^ prime32; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 711 | |
Yann Collet | 3ecbe6a | 2016-09-14 17:26:59 +0200 | [diff] [blame] | 712 | /* states full reset (deliberately not synchronized) */ |
| 713 | /* some issues can only happen when reusing states */ |
Yann Collet | 58d5dfe | 2016-09-25 01:34:03 +0200 | [diff] [blame] | 714 | if ((FUZ_rand(&lseed) & 0xFF) == 131) { ZSTD_freeCStream(zc); zc = ZSTD_createCStream(); resetAllowed=0; } |
| 715 | if ((FUZ_rand(&lseed) & 0xFF) == 132) { ZSTD_freeDStream(zd); zd = ZSTD_createDStream(); ZSTD_initDStream_usingDict(zd, NULL, 0); /* ensure at least one init */ } |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 716 | |
| 717 | /* srcBuffer selection [0-4] */ |
| 718 | { U32 buffNb = FUZ_rand(&lseed) & 0x7F; |
| 719 | if (buffNb & 7) buffNb=2; /* most common : compressible (P) */ |
| 720 | else { |
| 721 | buffNb >>= 3; |
| 722 | if (buffNb & 7) { |
| 723 | const U32 tnb[2] = { 1, 3 }; /* barely/highly compressible */ |
| 724 | buffNb = tnb[buffNb >> 3]; |
| 725 | } else { |
| 726 | const U32 tnb[2] = { 0, 4 }; /* not compressible / sparse */ |
| 727 | buffNb = tnb[buffNb >> 3]; |
| 728 | } } |
| 729 | srcBuffer = cNoiseBuffer[buffNb]; |
| 730 | } |
| 731 | |
| 732 | /* compression init */ |
Yann Collet | cf409a7 | 2016-09-26 16:41:05 +0200 | [diff] [blame] | 733 | if ((FUZ_rand(&lseed)&1) /* at beginning, to keep same nb of rand */ |
| 734 | && oldTestLog /* at least one test happened */ && resetAllowed) { |
| 735 | maxTestSize = FUZ_randomLength(&lseed, oldTestLog+2); |
Yann Collet | ce80098 | 2017-04-05 16:34:09 -0700 | [diff] [blame] | 736 | if (maxTestSize >= srcBufferSize) |
| 737 | maxTestSize = srcBufferSize-1; |
Yann Collet | cf409a7 | 2016-09-26 16:41:05 +0200 | [diff] [blame] | 738 | { U64 const pledgedSrcSize = (FUZ_rand(&lseed) & 3) ? 0 : maxTestSize; |
| 739 | size_t const resetError = ZSTD_resetCStream(zc, pledgedSrcSize); |
| 740 | CHECK(ZSTD_isError(resetError), "ZSTD_resetCStream error : %s", ZSTD_getErrorName(resetError)); |
| 741 | } |
Yann Collet | 58d5dfe | 2016-09-25 01:34:03 +0200 | [diff] [blame] | 742 | } else { |
| 743 | U32 const testLog = FUZ_rand(&lseed) % maxSrcLog; |
Sean Purcell | f5e5051 | 2017-03-15 15:04:54 -0700 | [diff] [blame] | 744 | U32 const dictLog = FUZ_rand(&lseed) % maxSrcLog; |
Yann Collet | ce80098 | 2017-04-05 16:34:09 -0700 | [diff] [blame] | 745 | U32 const cLevel = ( FUZ_rand(&lseed) % |
Sean Purcell | 7ebf2de | 2017-03-20 11:25:00 -0700 | [diff] [blame] | 746 | (ZSTD_maxCLevel() - |
Yann Collet | ce80098 | 2017-04-05 16:34:09 -0700 | [diff] [blame] | 747 | (MAX(testLog, dictLog) / cLevelLimiter))) |
| 748 | + 1; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 749 | maxTestSize = FUZ_rLogLength(&lseed, testLog); |
Yann Collet | cf409a7 | 2016-09-26 16:41:05 +0200 | [diff] [blame] | 750 | oldTestLog = testLog; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 751 | /* random dictionary selection */ |
Yann Collet | ce80098 | 2017-04-05 16:34:09 -0700 | [diff] [blame] | 752 | dictSize = ((FUZ_rand(&lseed)&1)==1) ? FUZ_rLogLength(&lseed, dictLog) : 0; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 753 | { size_t const dictStart = FUZ_rand(&lseed) % (srcBufferSize - dictSize); |
| 754 | dict = srcBuffer + dictStart; |
| 755 | } |
Yann Collet | cf409a7 | 2016-09-26 16:41:05 +0200 | [diff] [blame] | 756 | { U64 const pledgedSrcSize = (FUZ_rand(&lseed) & 3) ? 0 : maxTestSize; |
| 757 | ZSTD_parameters params = ZSTD_getParams(cLevel, pledgedSrcSize, dictSize); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 758 | params.fParams.checksumFlag = FUZ_rand(&lseed) & 1; |
| 759 | params.fParams.noDictIDFlag = FUZ_rand(&lseed) & 1; |
Yann Collet | cf409a7 | 2016-09-26 16:41:05 +0200 | [diff] [blame] | 760 | { size_t const initError = ZSTD_initCStream_advanced(zc, dict, dictSize, params, pledgedSrcSize); |
Yann Collet | b3060f7 | 2016-09-09 16:44:16 +0200 | [diff] [blame] | 761 | CHECK (ZSTD_isError(initError),"ZSTD_initCStream_advanced error : %s", ZSTD_getErrorName(initError)); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 762 | } } } |
| 763 | |
| 764 | /* multi-segments compression test */ |
| 765 | XXH64_reset(&xxhState, 0); |
Yann Collet | 2f26394 | 2016-09-26 14:06:08 +0200 | [diff] [blame] | 766 | { ZSTD_outBuffer outBuff = { cBuffer, cBufferSize, 0 } ; |
Yann Collet | 58d5dfe | 2016-09-25 01:34:03 +0200 | [diff] [blame] | 767 | U32 n; |
Yann Collet | 2f26394 | 2016-09-26 14:06:08 +0200 | [diff] [blame] | 768 | for (n=0, cSize=0, totalTestSize=0 ; totalTestSize < maxTestSize ; n++) { |
Yann Collet | e795c8a | 2016-12-13 16:39:36 +0100 | [diff] [blame] | 769 | /* compress random chunks into randomly sized dst buffers */ |
Yann Collet | 2f26394 | 2016-09-26 14:06:08 +0200 | [diff] [blame] | 770 | { size_t const randomSrcSize = FUZ_randomLength(&lseed, maxSampleLog); |
| 771 | size_t const srcSize = MIN (maxTestSize-totalTestSize, randomSrcSize); |
| 772 | size_t const srcStart = FUZ_rand(&lseed) % (srcBufferSize - srcSize); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 773 | size_t const randomDstSize = FUZ_randomLength(&lseed, maxSampleLog); |
| 774 | size_t const dstBuffSize = MIN(cBufferSize - cSize, randomDstSize); |
Yann Collet | 2f26394 | 2016-09-26 14:06:08 +0200 | [diff] [blame] | 775 | ZSTD_inBuffer inBuff = { srcBuffer+srcStart, srcSize, 0 }; |
Yann Collet | 53e17fb | 2016-08-17 01:39:22 +0200 | [diff] [blame] | 776 | outBuff.size = outBuff.pos + dstBuffSize; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 777 | |
Yann Collet | 53e17fb | 2016-08-17 01:39:22 +0200 | [diff] [blame] | 778 | { size_t const compressionError = ZSTD_compressStream(zc, &outBuff, &inBuff); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 779 | CHECK (ZSTD_isError(compressionError), "compression error : %s", ZSTD_getErrorName(compressionError)); } |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 780 | |
Yann Collet | 53e17fb | 2016-08-17 01:39:22 +0200 | [diff] [blame] | 781 | XXH64_update(&xxhState, srcBuffer+srcStart, inBuff.pos); |
| 782 | memcpy(copyBuffer+totalTestSize, srcBuffer+srcStart, inBuff.pos); |
| 783 | totalTestSize += inBuff.pos; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | /* random flush operation, to mess around */ |
| 787 | if ((FUZ_rand(&lseed) & 15) == 0) { |
| 788 | size_t const randomDstSize = FUZ_randomLength(&lseed, maxSampleLog); |
Yann Collet | 53e17fb | 2016-08-17 01:39:22 +0200 | [diff] [blame] | 789 | size_t const adjustedDstSize = MIN(cBufferSize - cSize, randomDstSize); |
| 790 | outBuff.size = outBuff.pos + adjustedDstSize; |
| 791 | { size_t const flushError = ZSTD_flushStream(zc, &outBuff); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 792 | CHECK (ZSTD_isError(flushError), "flush error : %s", ZSTD_getErrorName(flushError)); |
| 793 | } } } |
| 794 | |
| 795 | /* final frame epilogue */ |
| 796 | { size_t remainingToFlush = (size_t)(-1); |
| 797 | while (remainingToFlush) { |
| 798 | size_t const randomDstSize = FUZ_randomLength(&lseed, maxSampleLog); |
| 799 | size_t const adjustedDstSize = MIN(cBufferSize - cSize, randomDstSize); |
| 800 | U32 const enoughDstSize = (adjustedDstSize >= remainingToFlush); |
Yann Collet | 53e17fb | 2016-08-17 01:39:22 +0200 | [diff] [blame] | 801 | outBuff.size = outBuff.pos + adjustedDstSize; |
| 802 | remainingToFlush = ZSTD_endStream(zc, &outBuff); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 803 | CHECK (ZSTD_isError(remainingToFlush), "flush error : %s", ZSTD_getErrorName(remainingToFlush)); |
Yann Collet | 0be6fd3 | 2017-05-08 16:08:01 -0700 | [diff] [blame] | 804 | CHECK (enoughDstSize && remainingToFlush, |
| 805 | "ZSTD_endStream() not fully flushed (%u remaining), but enough space available (%u)", |
| 806 | (U32)remainingToFlush, (U32)adjustedDstSize); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 807 | } } |
| 808 | crcOrig = XXH64_digest(&xxhState); |
Yann Collet | 53e17fb | 2016-08-17 01:39:22 +0200 | [diff] [blame] | 809 | cSize = outBuff.pos; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | /* multi - fragments decompression test */ |
Yann Collet | 58d5dfe | 2016-09-25 01:34:03 +0200 | [diff] [blame] | 813 | if (!dictSize /* don't reset if dictionary : could be different */ && (FUZ_rand(&lseed) & 1)) { |
Yann Collet | 9516234 | 2016-10-25 16:19:52 -0700 | [diff] [blame] | 814 | CHECK (ZSTD_isError(ZSTD_resetDStream(zd)), "ZSTD_resetDStream failed"); |
Yann Collet | 9ffbeea | 2016-12-02 18:37:38 -0800 | [diff] [blame] | 815 | } else { |
Yann Collet | 58d5dfe | 2016-09-25 01:34:03 +0200 | [diff] [blame] | 816 | ZSTD_initDStream_usingDict(zd, dict, dictSize); |
Yann Collet | 9ffbeea | 2016-12-02 18:37:38 -0800 | [diff] [blame] | 817 | } |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 818 | { size_t decompressionResult = 1; |
Yann Collet | 53e17fb | 2016-08-17 01:39:22 +0200 | [diff] [blame] | 819 | ZSTD_inBuffer inBuff = { cBuffer, cSize, 0 }; |
| 820 | ZSTD_outBuffer outBuff= { dstBuffer, dstBufferSize, 0 }; |
| 821 | for (totalGenSize = 0 ; decompressionResult ; ) { |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 822 | size_t const readCSrcSize = FUZ_randomLength(&lseed, maxSampleLog); |
| 823 | size_t const randomDstSize = FUZ_randomLength(&lseed, maxSampleLog); |
| 824 | size_t const dstBuffSize = MIN(dstBufferSize - totalGenSize, randomDstSize); |
Yann Collet | 53e17fb | 2016-08-17 01:39:22 +0200 | [diff] [blame] | 825 | inBuff.size = inBuff.pos + readCSrcSize; |
| 826 | outBuff.size = inBuff.pos + dstBuffSize; |
| 827 | decompressionResult = ZSTD_decompressStream(zd, &outBuff, &inBuff); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 828 | CHECK (ZSTD_isError(decompressionResult), "decompression error : %s", ZSTD_getErrorName(decompressionResult)); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 829 | } |
| 830 | CHECK (decompressionResult != 0, "frame not fully decoded"); |
Yann Collet | 53e17fb | 2016-08-17 01:39:22 +0200 | [diff] [blame] | 831 | CHECK (outBuff.pos != totalTestSize, "decompressed data : wrong size") |
| 832 | CHECK (inBuff.pos != cSize, "compressed data should be fully read") |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 833 | { U64 const crcDest = XXH64(dstBuffer, totalTestSize, 0); |
| 834 | if (crcDest!=crcOrig) findDiff(copyBuffer, dstBuffer, totalTestSize); |
| 835 | CHECK (crcDest!=crcOrig, "decompressed data corrupted"); |
| 836 | } } |
| 837 | |
| 838 | /*===== noisy/erroneous src decompression test =====*/ |
| 839 | |
| 840 | /* add some noise */ |
| 841 | { U32 const nbNoiseChunks = (FUZ_rand(&lseed) & 7) + 2; |
| 842 | U32 nn; for (nn=0; nn<nbNoiseChunks; nn++) { |
| 843 | size_t const randomNoiseSize = FUZ_randomLength(&lseed, maxSampleLog); |
| 844 | size_t const noiseSize = MIN((cSize/3) , randomNoiseSize); |
| 845 | size_t const noiseStart = FUZ_rand(&lseed) % (srcBufferSize - noiseSize); |
| 846 | size_t const cStart = FUZ_rand(&lseed) % (cSize - noiseSize); |
| 847 | memcpy(cBuffer+cStart, srcBuffer+noiseStart, noiseSize); |
| 848 | } } |
| 849 | |
| 850 | /* try decompression on noisy data */ |
Yann Collet | 58d5dfe | 2016-09-25 01:34:03 +0200 | [diff] [blame] | 851 | ZSTD_initDStream(zd_noise); /* note : no dictionary */ |
Yann Collet | 53e17fb | 2016-08-17 01:39:22 +0200 | [diff] [blame] | 852 | { ZSTD_inBuffer inBuff = { cBuffer, cSize, 0 }; |
| 853 | ZSTD_outBuffer outBuff= { dstBuffer, dstBufferSize, 0 }; |
| 854 | while (outBuff.pos < dstBufferSize) { |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 855 | size_t const randomCSrcSize = FUZ_randomLength(&lseed, maxSampleLog); |
| 856 | size_t const randomDstSize = FUZ_randomLength(&lseed, maxSampleLog); |
Yann Collet | 53e17fb | 2016-08-17 01:39:22 +0200 | [diff] [blame] | 857 | size_t const adjustedDstSize = MIN(dstBufferSize - outBuff.pos, randomDstSize); |
Yann Collet | 64bf8ff | 2017-01-27 17:25:07 -0800 | [diff] [blame] | 858 | size_t const adjustedCSrcSize = MIN(cSize - inBuff.pos, randomCSrcSize); |
Yann Collet | 53e17fb | 2016-08-17 01:39:22 +0200 | [diff] [blame] | 859 | outBuff.size = outBuff.pos + adjustedDstSize; |
Yann Collet | 64bf8ff | 2017-01-27 17:25:07 -0800 | [diff] [blame] | 860 | inBuff.size = inBuff.pos + adjustedCSrcSize; |
Yann Collet | 53e17fb | 2016-08-17 01:39:22 +0200 | [diff] [blame] | 861 | { size_t const decompressError = ZSTD_decompressStream(zd, &outBuff, &inBuff); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 862 | if (ZSTD_isError(decompressError)) break; /* error correctly detected */ |
Yann Collet | 64bf8ff | 2017-01-27 17:25:07 -0800 | [diff] [blame] | 863 | /* No forward progress possible */ |
| 864 | if (outBuff.pos < outBuff.size && inBuff.pos == cSize) break; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 865 | } } } } |
| 866 | DISPLAY("\r%u fuzzer tests completed \n", testNb); |
| 867 | |
| 868 | _cleanup: |
| 869 | ZSTD_freeCStream(zc); |
| 870 | ZSTD_freeDStream(zd); |
Yann Collet | 58d5dfe | 2016-09-25 01:34:03 +0200 | [diff] [blame] | 871 | ZSTD_freeDStream(zd_noise); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 872 | free(cNoiseBuffer[0]); |
| 873 | free(cNoiseBuffer[1]); |
| 874 | free(cNoiseBuffer[2]); |
| 875 | free(cNoiseBuffer[3]); |
| 876 | free(cNoiseBuffer[4]); |
| 877 | free(copyBuffer); |
| 878 | free(cBuffer); |
| 879 | free(dstBuffer); |
| 880 | return result; |
| 881 | |
| 882 | _output_error: |
| 883 | result = 1; |
| 884 | goto _cleanup; |
| 885 | } |
| 886 | |
| 887 | |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 888 | /* Multi-threading version of fuzzer Tests */ |
Sean Purcell | 7ebf2de | 2017-03-20 11:25:00 -0700 | [diff] [blame] | 889 | static int fuzzerTests_MT(U32 seed, U32 nbTests, unsigned startTest, double compressibility, int bigTests) |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 890 | { |
| 891 | static const U32 maxSrcLog = 24; |
| 892 | static const U32 maxSampleLog = 19; |
| 893 | size_t const srcBufferSize = (size_t)1<<maxSrcLog; |
| 894 | BYTE* cNoiseBuffer[5]; |
| 895 | size_t const copyBufferSize= srcBufferSize + (1<<maxSampleLog); |
| 896 | BYTE* const copyBuffer = (BYTE*)malloc (copyBufferSize); |
| 897 | size_t const cBufferSize = ZSTD_compressBound(srcBufferSize); |
| 898 | BYTE* const cBuffer = (BYTE*)malloc (cBufferSize); |
| 899 | size_t const dstBufferSize = srcBufferSize; |
| 900 | BYTE* const dstBuffer = (BYTE*)malloc (dstBufferSize); |
| 901 | U32 result = 0; |
| 902 | U32 testNb = 0; |
| 903 | U32 coreSeed = seed; |
| 904 | ZSTDMT_CCtx* zc = ZSTDMT_createCCtx(2); /* will be reset sometimes */ |
| 905 | ZSTD_DStream* zd = ZSTD_createDStream(); /* will be reset sometimes */ |
| 906 | ZSTD_DStream* const zd_noise = ZSTD_createDStream(); |
| 907 | clock_t const startClock = clock(); |
| 908 | const BYTE* dict=NULL; /* can keep same dict on 2 consecutive tests */ |
| 909 | size_t dictSize = 0; |
| 910 | U32 oldTestLog = 0; |
Sean Purcell | 7ebf2de | 2017-03-20 11:25:00 -0700 | [diff] [blame] | 911 | int const cLevelLimiter = bigTests ? 3 : 2; |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 912 | |
| 913 | /* allocations */ |
| 914 | cNoiseBuffer[0] = (BYTE*)malloc (srcBufferSize); |
| 915 | cNoiseBuffer[1] = (BYTE*)malloc (srcBufferSize); |
| 916 | cNoiseBuffer[2] = (BYTE*)malloc (srcBufferSize); |
| 917 | cNoiseBuffer[3] = (BYTE*)malloc (srcBufferSize); |
| 918 | cNoiseBuffer[4] = (BYTE*)malloc (srcBufferSize); |
| 919 | CHECK (!cNoiseBuffer[0] || !cNoiseBuffer[1] || !cNoiseBuffer[2] || !cNoiseBuffer[3] || !cNoiseBuffer[4] || |
| 920 | !copyBuffer || !dstBuffer || !cBuffer || !zc || !zd || !zd_noise , |
| 921 | "Not enough memory, fuzzer tests cancelled"); |
| 922 | |
| 923 | /* Create initial samples */ |
| 924 | RDG_genBuffer(cNoiseBuffer[0], srcBufferSize, 0.00, 0., coreSeed); /* pure noise */ |
| 925 | RDG_genBuffer(cNoiseBuffer[1], srcBufferSize, 0.05, 0., coreSeed); /* barely compressible */ |
| 926 | RDG_genBuffer(cNoiseBuffer[2], srcBufferSize, compressibility, 0., coreSeed); |
| 927 | RDG_genBuffer(cNoiseBuffer[3], srcBufferSize, 0.95, 0., coreSeed); /* highly compressible */ |
| 928 | RDG_genBuffer(cNoiseBuffer[4], srcBufferSize, 1.00, 0., coreSeed); /* sparse content */ |
| 929 | memset(copyBuffer, 0x65, copyBufferSize); /* make copyBuffer considered initialized */ |
| 930 | ZSTD_initDStream_usingDict(zd, NULL, 0); /* ensure at least one init */ |
| 931 | |
| 932 | /* catch up testNb */ |
| 933 | for (testNb=1; testNb < startTest; testNb++) |
| 934 | FUZ_rand(&coreSeed); |
| 935 | |
| 936 | /* test loop */ |
| 937 | for ( ; (testNb <= nbTests) || (FUZ_GetClockSpan(startClock) < g_clockTime) ; testNb++ ) { |
| 938 | U32 lseed; |
| 939 | const BYTE* srcBuffer; |
| 940 | size_t totalTestSize, totalGenSize, cSize; |
| 941 | XXH64_state_t xxhState; |
| 942 | U64 crcOrig; |
| 943 | U32 resetAllowed = 1; |
| 944 | size_t maxTestSize; |
| 945 | |
| 946 | /* init */ |
| 947 | if (nbTests >= testNb) { DISPLAYUPDATE(2, "\r%6u/%6u ", testNb, nbTests); } |
| 948 | else { DISPLAYUPDATE(2, "\r%6u ", testNb); } |
| 949 | FUZ_rand(&coreSeed); |
Yann Collet | d7e3cb5 | 2017-01-20 16:44:50 -0800 | [diff] [blame] | 950 | lseed = coreSeed ^ prime32; |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 951 | |
| 952 | /* states full reset (deliberately not synchronized) */ |
| 953 | /* some issues can only happen when reusing states */ |
| 954 | if ((FUZ_rand(&lseed) & 0xFF) == 131) { |
| 955 | U32 const nbThreads = (FUZ_rand(&lseed) % 6) + 1; |
Yann Collet | 30c7698 | 2017-03-31 18:27:03 -0700 | [diff] [blame] | 956 | DISPLAYLEVEL(5, "Creating new context with %u threads \n", nbThreads); |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 957 | ZSTDMT_freeCCtx(zc); |
| 958 | zc = ZSTDMT_createCCtx(nbThreads); |
| 959 | resetAllowed=0; |
| 960 | } |
| 961 | if ((FUZ_rand(&lseed) & 0xFF) == 132) { |
| 962 | ZSTD_freeDStream(zd); |
| 963 | zd = ZSTD_createDStream(); |
| 964 | ZSTD_initDStream_usingDict(zd, NULL, 0); /* ensure at least one init */ |
| 965 | } |
| 966 | |
| 967 | /* srcBuffer selection [0-4] */ |
| 968 | { U32 buffNb = FUZ_rand(&lseed) & 0x7F; |
| 969 | if (buffNb & 7) buffNb=2; /* most common : compressible (P) */ |
| 970 | else { |
| 971 | buffNb >>= 3; |
| 972 | if (buffNb & 7) { |
| 973 | const U32 tnb[2] = { 1, 3 }; /* barely/highly compressible */ |
| 974 | buffNb = tnb[buffNb >> 3]; |
| 975 | } else { |
| 976 | const U32 tnb[2] = { 0, 4 }; /* not compressible / sparse */ |
| 977 | buffNb = tnb[buffNb >> 3]; |
| 978 | } } |
| 979 | srcBuffer = cNoiseBuffer[buffNb]; |
| 980 | } |
| 981 | |
| 982 | /* compression init */ |
| 983 | if ((FUZ_rand(&lseed)&1) /* at beginning, to keep same nb of rand */ |
| 984 | && oldTestLog /* at least one test happened */ && resetAllowed) { |
| 985 | maxTestSize = FUZ_randomLength(&lseed, oldTestLog+2); |
| 986 | if (maxTestSize >= srcBufferSize) maxTestSize = srcBufferSize-1; |
| 987 | { int const compressionLevel = (FUZ_rand(&lseed) % 5) + 1; |
| 988 | size_t const resetError = ZSTDMT_initCStream(zc, compressionLevel); |
Yann Collet | 19d670b | 2017-01-19 15:32:07 -0800 | [diff] [blame] | 989 | CHECK(ZSTD_isError(resetError), "ZSTDMT_initCStream error : %s", ZSTD_getErrorName(resetError)); |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 990 | } |
| 991 | } else { |
| 992 | U32 const testLog = FUZ_rand(&lseed) % maxSrcLog; |
Sean Purcell | f5e5051 | 2017-03-15 15:04:54 -0700 | [diff] [blame] | 993 | U32 const dictLog = FUZ_rand(&lseed) % maxSrcLog; |
Sean Purcell | 7ebf2de | 2017-03-20 11:25:00 -0700 | [diff] [blame] | 994 | U32 const cLevel = (FUZ_rand(&lseed) % |
| 995 | (ZSTD_maxCLevel() - |
| 996 | (MAX(testLog, dictLog) / cLevelLimiter))) + |
| 997 | 1; |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 998 | maxTestSize = FUZ_rLogLength(&lseed, testLog); |
| 999 | oldTestLog = testLog; |
| 1000 | /* random dictionary selection */ |
Sean Purcell | f5e5051 | 2017-03-15 15:04:54 -0700 | [diff] [blame] | 1001 | dictSize = ((FUZ_rand(&lseed)&63)==1) ? FUZ_rLogLength(&lseed, dictLog) : 0; |
Yann Collet | 19d670b | 2017-01-19 15:32:07 -0800 | [diff] [blame] | 1002 | { size_t const dictStart = FUZ_rand(&lseed) % (srcBufferSize - dictSize); |
| 1003 | dict = srcBuffer + dictStart; |
| 1004 | } |
| 1005 | { U64 const pledgedSrcSize = (FUZ_rand(&lseed) & 3) ? 0 : maxTestSize; |
| 1006 | ZSTD_parameters params = ZSTD_getParams(cLevel, pledgedSrcSize, dictSize); |
Yann Collet | ce80098 | 2017-04-05 16:34:09 -0700 | [diff] [blame] | 1007 | DISPLAYLEVEL(5, "Init with windowLog = %u and pledgedSrcSize = %u \n", |
| 1008 | params.cParams.windowLog, (U32)pledgedSrcSize); |
Yann Collet | 19d670b | 2017-01-19 15:32:07 -0800 | [diff] [blame] | 1009 | params.fParams.checksumFlag = FUZ_rand(&lseed) & 1; |
| 1010 | params.fParams.noDictIDFlag = FUZ_rand(&lseed) & 1; |
Yann Collet | ce80098 | 2017-04-05 16:34:09 -0700 | [diff] [blame] | 1011 | params.fParams.contentSizeFlag = pledgedSrcSize>0; |
Yann Collet | 2c5514c | 2017-04-18 22:52:41 -0700 | [diff] [blame] | 1012 | DISPLAYLEVEL(5, "checksumFlag : %u \n", params.fParams.checksumFlag); |
Yann Collet | cd23dd2 | 2017-01-30 12:46:35 -0800 | [diff] [blame] | 1013 | { size_t const initError = ZSTDMT_initCStream_advanced(zc, dict, dictSize, params, pledgedSrcSize); |
| 1014 | CHECK (ZSTD_isError(initError),"ZSTDMT_initCStream_advanced error : %s", ZSTD_getErrorName(initError)); } |
| 1015 | ZSTDMT_setMTCtxParameter(zc, ZSTDMT_p_overlapSectionLog, FUZ_rand(&lseed) % 12); |
Yann Collet | 92c98a5 | 2017-01-30 12:50:31 -0800 | [diff] [blame] | 1016 | ZSTDMT_setMTCtxParameter(zc, ZSTDMT_p_sectionSize, FUZ_rand(&lseed) % (2*maxTestSize+1)); |
Yann Collet | cd23dd2 | 2017-01-30 12:46:35 -0800 | [diff] [blame] | 1017 | } } |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 1018 | |
| 1019 | /* multi-segments compression test */ |
| 1020 | XXH64_reset(&xxhState, 0); |
| 1021 | { ZSTD_outBuffer outBuff = { cBuffer, cBufferSize, 0 } ; |
| 1022 | U32 n; |
| 1023 | for (n=0, cSize=0, totalTestSize=0 ; totalTestSize < maxTestSize ; n++) { |
| 1024 | /* compress random chunks into randomly sized dst buffers */ |
| 1025 | { size_t const randomSrcSize = FUZ_randomLength(&lseed, maxSampleLog); |
| 1026 | size_t const srcSize = MIN (maxTestSize-totalTestSize, randomSrcSize); |
| 1027 | size_t const srcStart = FUZ_rand(&lseed) % (srcBufferSize - srcSize); |
| 1028 | size_t const randomDstSize = FUZ_randomLength(&lseed, maxSampleLog); |
| 1029 | size_t const dstBuffSize = MIN(cBufferSize - cSize, randomDstSize); |
| 1030 | ZSTD_inBuffer inBuff = { srcBuffer+srcStart, srcSize, 0 }; |
| 1031 | outBuff.size = outBuff.pos + dstBuffSize; |
| 1032 | |
| 1033 | DISPLAYLEVEL(5, "Sending %u bytes to compress \n", (U32)srcSize); |
| 1034 | { size_t const compressionError = ZSTDMT_compressStream(zc, &outBuff, &inBuff); |
| 1035 | CHECK (ZSTD_isError(compressionError), "compression error : %s", ZSTD_getErrorName(compressionError)); } |
Yann Collet | 19d670b | 2017-01-19 15:32:07 -0800 | [diff] [blame] | 1036 | DISPLAYLEVEL(5, "%u bytes read by ZSTDMT_compressStream \n", (U32)inBuff.pos); |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 1037 | |
| 1038 | XXH64_update(&xxhState, srcBuffer+srcStart, inBuff.pos); |
| 1039 | memcpy(copyBuffer+totalTestSize, srcBuffer+srcStart, inBuff.pos); |
| 1040 | totalTestSize += inBuff.pos; |
| 1041 | } |
| 1042 | |
| 1043 | /* random flush operation, to mess around */ |
| 1044 | if ((FUZ_rand(&lseed) & 15) == 0) { |
| 1045 | size_t const randomDstSize = FUZ_randomLength(&lseed, maxSampleLog); |
| 1046 | size_t const adjustedDstSize = MIN(cBufferSize - cSize, randomDstSize); |
| 1047 | outBuff.size = outBuff.pos + adjustedDstSize; |
| 1048 | DISPLAYLEVEL(5, "Flushing into dst buffer of size %u \n", (U32)adjustedDstSize); |
| 1049 | { size_t const flushError = ZSTDMT_flushStream(zc, &outBuff); |
Yann Collet | 30c7698 | 2017-03-31 18:27:03 -0700 | [diff] [blame] | 1050 | CHECK (ZSTD_isError(flushError), "ZSTDMT_flushStream error : %s", ZSTD_getErrorName(flushError)); |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 1051 | } } } |
| 1052 | |
| 1053 | /* final frame epilogue */ |
| 1054 | { size_t remainingToFlush = (size_t)(-1); |
| 1055 | while (remainingToFlush) { |
| 1056 | size_t const randomDstSize = FUZ_randomLength(&lseed, maxSampleLog); |
| 1057 | size_t const adjustedDstSize = MIN(cBufferSize - cSize, randomDstSize); |
| 1058 | outBuff.size = outBuff.pos + adjustedDstSize; |
| 1059 | DISPLAYLEVEL(5, "Ending into dst buffer of size %u \n", (U32)adjustedDstSize); |
| 1060 | remainingToFlush = ZSTDMT_endStream(zc, &outBuff); |
Yann Collet | 30c7698 | 2017-03-31 18:27:03 -0700 | [diff] [blame] | 1061 | CHECK (ZSTD_isError(remainingToFlush), "ZSTDMT_endStream error : %s", ZSTD_getErrorName(remainingToFlush)); |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 1062 | DISPLAYLEVEL(5, "endStream : remainingToFlush : %u \n", (U32)remainingToFlush); |
| 1063 | } } |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 1064 | crcOrig = XXH64_digest(&xxhState); |
| 1065 | cSize = outBuff.pos; |
Yann Collet | 2c5514c | 2017-04-18 22:52:41 -0700 | [diff] [blame] | 1066 | DISPLAYLEVEL(5, "Frame completed : %u bytes \n", (U32)cSize); |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | /* multi - fragments decompression test */ |
| 1070 | if (!dictSize /* don't reset if dictionary : could be different */ && (FUZ_rand(&lseed) & 1)) { |
| 1071 | CHECK (ZSTD_isError(ZSTD_resetDStream(zd)), "ZSTD_resetDStream failed"); |
| 1072 | } else { |
| 1073 | ZSTD_initDStream_usingDict(zd, dict, dictSize); |
| 1074 | } |
| 1075 | { size_t decompressionResult = 1; |
| 1076 | ZSTD_inBuffer inBuff = { cBuffer, cSize, 0 }; |
| 1077 | ZSTD_outBuffer outBuff= { dstBuffer, dstBufferSize, 0 }; |
| 1078 | for (totalGenSize = 0 ; decompressionResult ; ) { |
| 1079 | size_t const readCSrcSize = FUZ_randomLength(&lseed, maxSampleLog); |
| 1080 | size_t const randomDstSize = FUZ_randomLength(&lseed, maxSampleLog); |
| 1081 | size_t const dstBuffSize = MIN(dstBufferSize - totalGenSize, randomDstSize); |
| 1082 | inBuff.size = inBuff.pos + readCSrcSize; |
| 1083 | outBuff.size = inBuff.pos + dstBuffSize; |
Yann Collet | ce80098 | 2017-04-05 16:34:09 -0700 | [diff] [blame] | 1084 | DISPLAYLEVEL(5, "ZSTD_decompressStream input %u bytes \n", (U32)readCSrcSize); |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 1085 | decompressionResult = ZSTD_decompressStream(zd, &outBuff, &inBuff); |
| 1086 | CHECK (ZSTD_isError(decompressionResult), "decompression error : %s", ZSTD_getErrorName(decompressionResult)); |
Yann Collet | 2c5514c | 2017-04-18 22:52:41 -0700 | [diff] [blame] | 1087 | DISPLAYLEVEL(5, "inBuff.pos = %u \n", (U32)readCSrcSize); |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 1088 | } |
Yann Collet | bb00274 | 2017-01-25 16:25:38 -0800 | [diff] [blame] | 1089 | CHECK (outBuff.pos != totalTestSize, "decompressed data : wrong size (%u != %u)", (U32)outBuff.pos, (U32)totalTestSize); |
| 1090 | CHECK (inBuff.pos != cSize, "compressed data should be fully read (%u != %u)", (U32)inBuff.pos, (U32)cSize); |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 1091 | { U64 const crcDest = XXH64(dstBuffer, totalTestSize, 0); |
| 1092 | if (crcDest!=crcOrig) findDiff(copyBuffer, dstBuffer, totalTestSize); |
| 1093 | CHECK (crcDest!=crcOrig, "decompressed data corrupted"); |
| 1094 | } } |
| 1095 | |
| 1096 | /*===== noisy/erroneous src decompression test =====*/ |
| 1097 | |
| 1098 | /* add some noise */ |
| 1099 | { U32 const nbNoiseChunks = (FUZ_rand(&lseed) & 7) + 2; |
| 1100 | U32 nn; for (nn=0; nn<nbNoiseChunks; nn++) { |
| 1101 | size_t const randomNoiseSize = FUZ_randomLength(&lseed, maxSampleLog); |
| 1102 | size_t const noiseSize = MIN((cSize/3) , randomNoiseSize); |
| 1103 | size_t const noiseStart = FUZ_rand(&lseed) % (srcBufferSize - noiseSize); |
| 1104 | size_t const cStart = FUZ_rand(&lseed) % (cSize - noiseSize); |
| 1105 | memcpy(cBuffer+cStart, srcBuffer+noiseStart, noiseSize); |
| 1106 | } } |
| 1107 | |
| 1108 | /* try decompression on noisy data */ |
| 1109 | ZSTD_initDStream(zd_noise); /* note : no dictionary */ |
| 1110 | { ZSTD_inBuffer inBuff = { cBuffer, cSize, 0 }; |
| 1111 | ZSTD_outBuffer outBuff= { dstBuffer, dstBufferSize, 0 }; |
| 1112 | while (outBuff.pos < dstBufferSize) { |
| 1113 | size_t const randomCSrcSize = FUZ_randomLength(&lseed, maxSampleLog); |
| 1114 | size_t const randomDstSize = FUZ_randomLength(&lseed, maxSampleLog); |
| 1115 | size_t const adjustedDstSize = MIN(dstBufferSize - outBuff.pos, randomDstSize); |
Nick Terrell | d98bf49 | 2017-01-27 15:42:36 -0800 | [diff] [blame] | 1116 | size_t const adjustedCSrcSize = MIN(cSize - inBuff.pos, randomCSrcSize); |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 1117 | outBuff.size = outBuff.pos + adjustedDstSize; |
Nick Terrell | d98bf49 | 2017-01-27 15:42:36 -0800 | [diff] [blame] | 1118 | inBuff.size = inBuff.pos + adjustedCSrcSize; |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 1119 | { size_t const decompressError = ZSTD_decompressStream(zd, &outBuff, &inBuff); |
| 1120 | if (ZSTD_isError(decompressError)) break; /* error correctly detected */ |
Nick Terrell | d98bf49 | 2017-01-27 15:42:36 -0800 | [diff] [blame] | 1121 | /* No forward progress possible */ |
| 1122 | if (outBuff.pos < outBuff.size && inBuff.pos == cSize) break; |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 1123 | } } } } |
| 1124 | DISPLAY("\r%u fuzzer tests completed \n", testNb); |
| 1125 | |
| 1126 | _cleanup: |
| 1127 | ZSTDMT_freeCCtx(zc); |
| 1128 | ZSTD_freeDStream(zd); |
| 1129 | ZSTD_freeDStream(zd_noise); |
| 1130 | free(cNoiseBuffer[0]); |
| 1131 | free(cNoiseBuffer[1]); |
| 1132 | free(cNoiseBuffer[2]); |
| 1133 | free(cNoiseBuffer[3]); |
| 1134 | free(cNoiseBuffer[4]); |
| 1135 | free(copyBuffer); |
| 1136 | free(cBuffer); |
| 1137 | free(dstBuffer); |
| 1138 | return result; |
| 1139 | |
| 1140 | _output_error: |
| 1141 | result = 1; |
| 1142 | goto _cleanup; |
| 1143 | } |
| 1144 | |
| 1145 | |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 1146 | /*-******************************************************* |
| 1147 | * Command line |
| 1148 | *********************************************************/ |
| 1149 | int FUZ_usage(const char* programName) |
| 1150 | { |
| 1151 | DISPLAY( "Usage :\n"); |
| 1152 | DISPLAY( " %s [args]\n", programName); |
| 1153 | DISPLAY( "\n"); |
| 1154 | DISPLAY( "Arguments :\n"); |
| 1155 | DISPLAY( " -i# : Nb of tests (default:%u) \n", nbTestsDefault); |
| 1156 | DISPLAY( " -s# : Select seed (default:prompt user)\n"); |
| 1157 | DISPLAY( " -t# : Select starting test number (default:0)\n"); |
| 1158 | DISPLAY( " -P# : Select compressibility in %% (default:%i%%)\n", FUZ_COMPRESSIBILITY_DEFAULT); |
| 1159 | DISPLAY( " -v : verbose\n"); |
| 1160 | DISPLAY( " -p : pause at the end\n"); |
| 1161 | DISPLAY( " -h : display help and exit\n"); |
| 1162 | return 0; |
| 1163 | } |
| 1164 | |
| 1165 | |
| 1166 | int main(int argc, const char** argv) |
| 1167 | { |
| 1168 | U32 seed=0; |
| 1169 | int seedset=0; |
| 1170 | int argNb; |
| 1171 | int nbTests = nbTestsDefault; |
| 1172 | int testNb = 0; |
| 1173 | int proba = FUZ_COMPRESSIBILITY_DEFAULT; |
| 1174 | int result=0; |
Yann Collet | 19d670b | 2017-01-19 15:32:07 -0800 | [diff] [blame] | 1175 | int mainPause = 0; |
| 1176 | int mtOnly = 0; |
Sean Purcell | 7ebf2de | 2017-03-20 11:25:00 -0700 | [diff] [blame] | 1177 | int bigTests = 1; |
Yann Collet | 19d670b | 2017-01-19 15:32:07 -0800 | [diff] [blame] | 1178 | const char* const programName = argv[0]; |
Yann Collet | 8dafb1a | 2017-01-25 17:01:13 -0800 | [diff] [blame] | 1179 | ZSTD_customMem const customMem = { allocFunction, freeFunction, NULL }; |
| 1180 | ZSTD_customMem const customNULL = { NULL, NULL, NULL }; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 1181 | |
| 1182 | /* Check command line */ |
| 1183 | for(argNb=1; argNb<argc; argNb++) { |
| 1184 | const char* argument = argv[argNb]; |
| 1185 | if(!argument) continue; /* Protection if argument empty */ |
| 1186 | |
| 1187 | /* Parsing commands. Aggregated commands are allowed */ |
| 1188 | if (argument[0]=='-') { |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 1189 | |
Yann Collet | 19d670b | 2017-01-19 15:32:07 -0800 | [diff] [blame] | 1190 | if (!strcmp(argument, "--mt")) { mtOnly=1; continue; } |
Sean Purcell | 7ebf2de | 2017-03-20 11:25:00 -0700 | [diff] [blame] | 1191 | if (!strcmp(argument, "--no-big-tests")) { bigTests=0; continue; } |
Yann Collet | 19d670b | 2017-01-19 15:32:07 -0800 | [diff] [blame] | 1192 | |
| 1193 | argument++; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 1194 | while (*argument!=0) { |
| 1195 | switch(*argument) |
| 1196 | { |
| 1197 | case 'h': |
| 1198 | return FUZ_usage(programName); |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 1199 | |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 1200 | case 'v': |
| 1201 | argument++; |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 1202 | g_displayLevel++; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 1203 | break; |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 1204 | |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 1205 | case 'q': |
| 1206 | argument++; |
| 1207 | g_displayLevel--; |
| 1208 | break; |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 1209 | |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 1210 | case 'p': /* pause at the end */ |
| 1211 | argument++; |
| 1212 | mainPause = 1; |
| 1213 | break; |
| 1214 | |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 1215 | case 'i': /* limit tests by nb of iterations (default) */ |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 1216 | argument++; |
Yann Collet | ef9999f | 2016-09-01 16:44:48 -0700 | [diff] [blame] | 1217 | nbTests=0; g_clockTime=0; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 1218 | while ((*argument>='0') && (*argument<='9')) { |
| 1219 | nbTests *= 10; |
| 1220 | nbTests += *argument - '0'; |
| 1221 | argument++; |
| 1222 | } |
| 1223 | break; |
| 1224 | |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 1225 | case 'T': /* limit tests by time */ |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 1226 | argument++; |
Yann Collet | ef9999f | 2016-09-01 16:44:48 -0700 | [diff] [blame] | 1227 | nbTests=0; g_clockTime=0; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 1228 | while ((*argument>='0') && (*argument<='9')) { |
Yann Collet | ef9999f | 2016-09-01 16:44:48 -0700 | [diff] [blame] | 1229 | g_clockTime *= 10; |
| 1230 | g_clockTime += *argument - '0'; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 1231 | argument++; |
| 1232 | } |
Yann Collet | ef9999f | 2016-09-01 16:44:48 -0700 | [diff] [blame] | 1233 | if (*argument=='m') g_clockTime *=60, argument++; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 1234 | if (*argument=='n') argument++; |
Yann Collet | ef9999f | 2016-09-01 16:44:48 -0700 | [diff] [blame] | 1235 | g_clockTime *= CLOCKS_PER_SEC; |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 1236 | break; |
| 1237 | |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 1238 | case 's': /* manually select seed */ |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 1239 | argument++; |
| 1240 | seed=0; |
| 1241 | seedset=1; |
| 1242 | while ((*argument>='0') && (*argument<='9')) { |
| 1243 | seed *= 10; |
| 1244 | seed += *argument - '0'; |
| 1245 | argument++; |
| 1246 | } |
| 1247 | break; |
| 1248 | |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 1249 | case 't': /* select starting test number */ |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 1250 | argument++; |
| 1251 | testNb=0; |
| 1252 | while ((*argument>='0') && (*argument<='9')) { |
| 1253 | testNb *= 10; |
| 1254 | testNb += *argument - '0'; |
| 1255 | argument++; |
| 1256 | } |
| 1257 | break; |
| 1258 | |
| 1259 | case 'P': /* compressibility % */ |
| 1260 | argument++; |
| 1261 | proba=0; |
| 1262 | while ((*argument>='0') && (*argument<='9')) { |
| 1263 | proba *= 10; |
| 1264 | proba += *argument - '0'; |
| 1265 | argument++; |
| 1266 | } |
| 1267 | if (proba<0) proba=0; |
| 1268 | if (proba>100) proba=100; |
| 1269 | break; |
| 1270 | |
| 1271 | default: |
| 1272 | return FUZ_usage(programName); |
| 1273 | } |
| 1274 | } } } /* for(argNb=1; argNb<argc; argNb++) */ |
| 1275 | |
| 1276 | /* Get Seed */ |
Yann Collet | bb85581 | 2016-08-25 19:11:11 +0200 | [diff] [blame] | 1277 | DISPLAY("Starting zstream tester (%i-bits, %s)\n", (int)(sizeof(size_t)*8), ZSTD_VERSION_STRING); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 1278 | |
Yann Collet | ef9999f | 2016-09-01 16:44:48 -0700 | [diff] [blame] | 1279 | if (!seedset) { |
| 1280 | time_t const t = time(NULL); |
| 1281 | U32 const h = XXH32(&t, sizeof(t), 1); |
| 1282 | seed = h % 10000; |
| 1283 | } |
| 1284 | |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 1285 | DISPLAY("Seed = %u\n", seed); |
| 1286 | if (proba!=FUZ_COMPRESSIBILITY_DEFAULT) DISPLAY("Compressibility : %i%%\n", proba); |
| 1287 | |
| 1288 | if (nbTests<=0) nbTests=1; |
| 1289 | |
| 1290 | if (testNb==0) { |
| 1291 | result = basicUnitTests(0, ((double)proba) / 100, customNULL); /* constant seed for predictability */ |
| 1292 | if (!result) { |
Yann Collet | 736788f | 2017-01-19 12:12:50 -0800 | [diff] [blame] | 1293 | DISPLAYLEVEL(3, "Unit tests using customMem :\n") |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 1294 | result = basicUnitTests(0, ((double)proba) / 100, customMem); /* use custom memory allocation functions */ |
| 1295 | } } |
| 1296 | |
Sean Purcell | 7ebf2de | 2017-03-20 11:25:00 -0700 | [diff] [blame] | 1297 | if (!result && !mtOnly) result = fuzzerTests(seed, nbTests, testNb, ((double)proba) / 100, bigTests); |
| 1298 | if (!result) result = fuzzerTests_MT(seed, nbTests, testNb, ((double)proba) / 100, bigTests); |
Yann Collet | d7883a2 | 2016-08-12 16:48:02 +0200 | [diff] [blame] | 1299 | |
| 1300 | if (mainPause) { |
| 1301 | int unused; |
| 1302 | DISPLAY("Press Enter \n"); |
| 1303 | unused = getchar(); |
| 1304 | (void)unused; |
| 1305 | } |
| 1306 | return result; |
| 1307 | } |