mirror of
https://github.com/facebook/zstd.git
synced 2025-07-30 22:23:13 +03:00
Updated FSE
Added clang and g++ tests
This commit is contained in:
@ -72,7 +72,7 @@
|
||||
|
||||
|
||||
/**************************************
|
||||
* Basic Types
|
||||
* Basic Types
|
||||
**************************************/
|
||||
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
|
||||
# include <stdint.h>
|
||||
@ -471,7 +471,7 @@ static int BMK_syntheticTest(int cLevel, double compressibility)
|
||||
}
|
||||
|
||||
|
||||
int BMK_bench(char** fileNamesTable, unsigned nbFiles, unsigned cLevel)
|
||||
int BMK_benchFiles(char** fileNamesTable, unsigned nbFiles, unsigned cLevel)
|
||||
{
|
||||
double compressibility = (double)g_compressibilityDefault / 100;
|
||||
|
||||
|
@ -24,19 +24,11 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Main function */
|
||||
int BMK_bench(char** fileNamesTable, unsigned nbFiles, unsigned cLevel);
|
||||
int BMK_benchFiles(char** fileNamesTable, unsigned nbFiles, unsigned cLevel);
|
||||
|
||||
/* Set Parameters */
|
||||
void BMK_SetNbIterations(int nbLoops);
|
||||
|
||||
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
@ -75,7 +75,7 @@
|
||||
* Local Functions
|
||||
*********************************************************/
|
||||
#define RDG_rotl32(x,r) ((x << r) | (x >> (32 - r)))
|
||||
static unsigned int RDG_rand(U32* src)
|
||||
static U32 RDG_rand(U32* src)
|
||||
{
|
||||
U32 rand32 = *src;
|
||||
rand32 *= PRIME1;
|
||||
@ -88,20 +88,21 @@ static unsigned int RDG_rand(U32* src)
|
||||
|
||||
#define LTSIZE 8192
|
||||
#define LTMASK (LTSIZE-1)
|
||||
static void* RDG_createLiteralDistrib(double ld)
|
||||
static void* RDG_createLiteralDistrib(const double ld)
|
||||
{
|
||||
BYTE* lt = malloc(LTSIZE);
|
||||
BYTE* lt = (BYTE*)malloc(LTSIZE);
|
||||
U32 i = 0;
|
||||
BYTE character = '0';
|
||||
BYTE firstChar = '(';
|
||||
BYTE lastChar = '}';
|
||||
|
||||
if (ld==0.0)
|
||||
if (ld<=0.02)
|
||||
{
|
||||
character = 0;
|
||||
firstChar = 0;
|
||||
lastChar =255;
|
||||
lastChar = 254;
|
||||
character = firstChar;
|
||||
}
|
||||
if (ld==0.0) lastChar = 255;
|
||||
while (i<LTSIZE)
|
||||
{
|
||||
U32 weight = (U32)((double)(LTSIZE - i) * ld) + 1;
|
||||
@ -117,7 +118,7 @@ static void* RDG_createLiteralDistrib(double ld)
|
||||
|
||||
static char RDG_genChar(U32* seed, const void* ltctx)
|
||||
{
|
||||
const BYTE* lt = ltctx;
|
||||
const BYTE* lt = (const BYTE*)ltctx;
|
||||
U32 id = RDG_rand(seed) & LTMASK;
|
||||
return lt[id];
|
||||
}
|
||||
|
@ -243,8 +243,8 @@ unsigned long long FIO_compressFilename(const char* output_filename, const char*
|
||||
ctx = ZSTD_createCCtx();
|
||||
|
||||
/* Allocate Memory */
|
||||
inBuff = malloc(inBuffSize);
|
||||
outBuff = malloc(outBuffSize);
|
||||
inBuff = (BYTE*)malloc(inBuffSize);
|
||||
outBuff = (BYTE*)malloc(outBuffSize);
|
||||
if (!inBuff || !outBuff) EXM_THROW(21, "Allocation error : not enough memory");
|
||||
inSlot = inBuff;
|
||||
inEnd = inBuff + inBuffSize;
|
||||
@ -265,6 +265,7 @@ unsigned long long FIO_compressFilename(const char* output_filename, const char*
|
||||
/* Fill input Buffer */
|
||||
if (inSlot + blockSize > inEnd) inSlot = inBuff;
|
||||
inSize = fread(inSlot, (size_t)1, blockSize, finput);
|
||||
DISPLAY("Read block of size %u at pos %u \n", (U32)inSize, (U32)(inSlot-inBuff));
|
||||
if (inSize==0) break;
|
||||
filesize += inSize;
|
||||
DISPLAYUPDATE(2, "\rRead : %u MB ", (U32)(filesize>>20));
|
||||
@ -340,9 +341,9 @@ unsigned long long FIO_decompressFilename(const char* output_filename, const cha
|
||||
|
||||
/* Allocate Memory */
|
||||
inBuffSize = blockSize + FIO_blockHeaderSize;
|
||||
inBuff = malloc(inBuffSize);
|
||||
inBuff = (BYTE*)malloc(inBuffSize);
|
||||
outBuffSize = wNbBlocks * blockSize;
|
||||
outBuff = malloc(outBuffSize);
|
||||
outBuff = (BYTE*)malloc(outBuffSize);
|
||||
op = outBuff;
|
||||
oend = outBuff + outBuffSize;
|
||||
if (!inBuff || !outBuff) EXM_THROW(33, "Allocation error : not enough memory");
|
||||
@ -352,6 +353,7 @@ unsigned long long FIO_decompressFilename(const char* output_filename, const cha
|
||||
while (toRead)
|
||||
{
|
||||
size_t readSize, decodedSize;
|
||||
static U32 nbReads = 0;
|
||||
|
||||
/* Fill input buffer */
|
||||
readSize = fread(inBuff, 1, toRead, finput);
|
||||
@ -359,11 +361,15 @@ unsigned long long FIO_decompressFilename(const char* output_filename, const cha
|
||||
EXM_THROW(34, "Read error");
|
||||
|
||||
/* Decode block */
|
||||
if (nbReads==55)
|
||||
DISPLAY("!");
|
||||
decodedSize = ZSTD_decompressContinue(dctx, op, oend-op, inBuff, readSize);
|
||||
DISPLAY("nbReads : %u \n", nbReads++);
|
||||
|
||||
if (decodedSize) /* not a header */
|
||||
{
|
||||
/* Write block */
|
||||
DISPLAY("writing %u bytes from pos %u \n", (U32)decodedSize, (U32)(op-outBuff));
|
||||
sizeCheck = fwrite(op, 1, decodedSize, foutput);
|
||||
if (sizeCheck != decodedSize) EXM_THROW(35, "Write error : unable to write data block to destination file");
|
||||
filesize += decodedSize;
|
||||
|
@ -267,7 +267,7 @@ size_t local_conditionalNull(void* dst, size_t dstSize, void* buff2, const void*
|
||||
{
|
||||
U32 i;
|
||||
size_t total = 0;
|
||||
BYTE* data = buff2;
|
||||
BYTE* data = (BYTE*)buff2;
|
||||
|
||||
(void)dst; (void)dstSize; (void)src;
|
||||
for (i=0; i < srcSize; i++)
|
||||
@ -332,8 +332,8 @@ size_t benchMem(void* src, size_t srcSize, U32 benchNb)
|
||||
|
||||
/* Allocation */
|
||||
dstBuffSize = ZSTD_compressBound(srcSize);
|
||||
dstBuff = malloc(dstBuffSize);
|
||||
buff2 = malloc(dstBuffSize);
|
||||
dstBuff = (BYTE*)malloc(dstBuffSize);
|
||||
buff2 = (BYTE*)malloc(dstBuffSize);
|
||||
if ((!dstBuff) || (!buff2))
|
||||
{
|
||||
DISPLAY("\nError: not enough memory!\n");
|
||||
|
@ -256,6 +256,25 @@ static int basicUnitTests(U32 seed, double compressibility)
|
||||
if (result != (size_t)-ZSTD_ERROR_wrongMagicNumber) goto _output_error;
|
||||
DISPLAYLEVEL(4, "OK \n");
|
||||
|
||||
/* long rle test */
|
||||
{
|
||||
size_t sampleSize = 0;
|
||||
DISPLAYLEVEL(4, "test%3i : Long RLE test : ", testNb++);
|
||||
FUZ_generateSynthetic(CNBuffer, sampleSize, compressibility, &randState);
|
||||
memset((char*)CNBuffer+sampleSize, 'B', 256 KB - 1);
|
||||
sampleSize += 256 KB - 1;
|
||||
FUZ_generateSynthetic((char*)CNBuffer+sampleSize, 96 KB, compressibility, &randState);
|
||||
sampleSize += 96 KB;
|
||||
cSize = ZSTD_compress(compressedBuffer, ZSTD_compressBound(sampleSize), CNBuffer, sampleSize);
|
||||
if (ZSTD_isError(cSize)) goto _output_error;
|
||||
result = ZSTD_decompress(decodedBuffer, sampleSize, compressedBuffer, cSize);
|
||||
if (ZSTD_isError(result)) goto _output_error;
|
||||
if (result!=sampleSize) goto _output_error;
|
||||
DISPLAYLEVEL(4, "OK \n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
_end:
|
||||
free(CNBuffer);
|
||||
free(compressedBuffer);
|
||||
@ -271,8 +290,8 @@ _output_error:
|
||||
|
||||
static size_t findDiff(const void* buf1, const void* buf2, size_t max)
|
||||
{
|
||||
const BYTE* b1 = buf1;
|
||||
const BYTE* b2 = buf2;
|
||||
const BYTE* b1 = (const BYTE*)buf1;
|
||||
const BYTE* b2 = (const BYTE*)buf2;
|
||||
size_t i;
|
||||
for (i=0; i<max; i++)
|
||||
{
|
||||
@ -301,9 +320,9 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
|
||||
(void)startTest; (void)compressibility;
|
||||
|
||||
/* allocation */
|
||||
srcBuffer = malloc (srcBufferSize);
|
||||
dstBuffer = malloc (dstBufferSize);
|
||||
cBuffer = malloc (cBufferSize);
|
||||
srcBuffer = (BYTE*)malloc (srcBufferSize);
|
||||
dstBuffer = (BYTE*)malloc (dstBufferSize);
|
||||
cBuffer = (BYTE*)malloc (cBufferSize);
|
||||
CHECK (!srcBuffer || !dstBuffer || !cBuffer, "Not enough memory, fuzzer tests cancelled");
|
||||
|
||||
/* Create initial sample */
|
||||
|
@ -271,7 +271,7 @@ int main(int argc, char** argv)
|
||||
if (!strcmp(inFileName, stdinmark) && IS_CONSOLE(stdin) ) return badusage(programName);
|
||||
|
||||
/* Check if benchmark is selected */
|
||||
if (bench) { BMK_bench(argv+fileNameStart, nbFiles, 0); goto _end; }
|
||||
if (bench) { BMK_benchFiles(argv+fileNameStart, nbFiles, 0); goto _end; }
|
||||
|
||||
/* No output filename ==> try to select one automatically (when possible) */
|
||||
while (!outFileName)
|
||||
|
Reference in New Issue
Block a user