summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Collet <cyan@fb.com>2019-06-29 03:55:47 (GMT)
committerYann Collet <cyan@fb.com>2019-06-29 03:55:47 (GMT)
commit3b917ef6e6e9b18b15f18b6d691c4ea5033cfe41 (patch)
treebc30112c08395acebe06a422b37a2c87955e2900
parent567b4e098baad783870bf6514a984c4b021d5056 (diff)
downloadlz4-3b917ef6e6e9b18b15f18b6d691c4ea5033cfe41.zip
lz4-3b917ef6e6e9b18b15f18b6d691c4ea5033cfe41.tar.gz
lz4-3b917ef6e6e9b18b15f18b6d691c4ea5033cfe41.tar.bz2
travisCI: added ASAN fuzzer tests
and fixed minor formatting warnings
-rw-r--r--.travis.yml6
-rw-r--r--examples/HCStreaming_ringBuffer.c9
-rw-r--r--tests/fullbench.c16
-rw-r--r--tests/fuzzer.c6
4 files changed, 24 insertions, 13 deletions
diff --git a/.travis.yml b/.travis.yml
index ee643e5..b88d907 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -27,6 +27,12 @@ matrix:
script:
- make -C tests test-frametest test-fuzzer
+ - name: ASAN tests with fuzzer and frametest
+ install:
+ - sudo sysctl -w vm.mmap_min_addr=4096
+ script:
+ - CC=clang MOREFLAGS=-fsanitize=address make -C tests test-frametest test-fuzzer
+
- name: (Precise) g++ and clang CMake test
dist: precise
script:
diff --git a/examples/HCStreaming_ringBuffer.c b/examples/HCStreaming_ringBuffer.c
index a878577..bc8391e 100644
--- a/examples/HCStreaming_ringBuffer.c
+++ b/examples/HCStreaming_ringBuffer.c
@@ -26,6 +26,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
enum {
MESSAGE_MAX_BYTES = 1024,
@@ -39,7 +40,8 @@ size_t write_int32(FILE* fp, int32_t i) {
}
size_t write_bin(FILE* fp, const void* array, int arrayBytes) {
- return fwrite(array, 1, arrayBytes, fp);
+ assert(arrayBytes >= 0);
+ return fwrite(array, 1, (size_t)arrayBytes, fp);
}
size_t read_int32(FILE* fp, int32_t* i) {
@@ -47,7 +49,8 @@ size_t read_int32(FILE* fp, int32_t* i) {
}
size_t read_bin(FILE* fp, void* array, int arrayBytes) {
- return fread(array, 1, arrayBytes, fp);
+ assert(arrayBytes >= 0);
+ return fread(array, 1, (size_t)arrayBytes, fp);
}
@@ -174,7 +177,7 @@ int main(int argc, const char** argv)
return 0;
}
- if (!strcmp(argv[1], "-p")) pause = 1, fileID = 2;
+ if (!strcmp(argv[1], "-p")) { pause = 1; fileID = 2; }
snprintf(inpFilename, 256, "%s", argv[fileID]);
snprintf(lz4Filename, 256, "%s.lz4s-%d", argv[fileID], 9);
diff --git a/tests/fullbench.c b/tests/fullbench.c
index 4609f13..7d74d3f 100644
--- a/tests/fullbench.c
+++ b/tests/fullbench.c
@@ -541,9 +541,10 @@ int fullSpeedBench(const char** fileNamesTable, int nbFiles)
if (initFunction!=NULL) initFunction();
for (chunkNb=0; chunkNb<nbChunks; chunkNb++) {
chunkP[chunkNb].compressedSize = compressionFunction(chunkP[chunkNb].origBuffer, chunkP[chunkNb].compressedBuffer, chunkP[chunkNb].origSize);
- if (chunkP[chunkNb].compressedSize==0)
- DISPLAY("ERROR ! %s() = 0 !! \n", compressorName), exit(1);
- }
+ if (chunkP[chunkNb].compressedSize==0) {
+ DISPLAY("ERROR ! %s() = 0 !! \n", compressorName);
+ exit(1);
+ } }
nb_loops++;
}
clockTime = BMK_GetClockSpan(clockTime);
@@ -551,7 +552,7 @@ int fullSpeedBench(const char** fileNamesTable, int nbFiles)
nb_loops += !nb_loops; /* avoid division by zero */
averageTime = ((double)clockTime) / nb_loops / CLOCKS_PER_SEC;
if (averageTime < bestTime) bestTime = averageTime;
- cSize=0; for (chunkNb=0; chunkNb<nbChunks; chunkNb++) cSize += chunkP[chunkNb].compressedSize;
+ cSize=0; for (chunkNb=0; chunkNb<nbChunks; chunkNb++) cSize += (size_t)chunkP[chunkNb].compressedSize;
ratio = (double)cSize/(double)benchedSize*100.;
PROGRESS("%2i-%-34.34s :%10i ->%9i (%5.2f%%),%7.1f MB/s\r", loopNb, compressorName, (int)benchedSize, (int)cSize, ratio, (double)benchedSize / bestTime / 1000000);
}
@@ -586,9 +587,10 @@ int fullSpeedBench(const char** fileNamesTable, int nbFiles)
}
for (chunkNb=0; chunkNb<nbChunks; chunkNb++) {
chunkP[chunkNb].compressedSize = LZ4_compress_default(chunkP[chunkNb].origBuffer, chunkP[chunkNb].compressedBuffer, chunkP[chunkNb].origSize, maxCompressedChunkSize);
- if (chunkP[chunkNb].compressedSize==0)
- DISPLAY("ERROR ! %s() = 0 !! \n", "LZ4_compress"), exit(1);
- }
+ if (chunkP[chunkNb].compressedSize==0) {
+ DISPLAY("ERROR ! %s() = 0 !! \n", "LZ4_compress");
+ exit(1);
+ } }
/* Decompression Algorithms */
for (dAlgNb=0; (dAlgNb <= NB_DECOMPRESSION_ALGORITHMS) && g_decompressionTest; dAlgNb++) {
diff --git a/tests/fuzzer.c b/tests/fuzzer.c
index 368b28b..7b6e929 100644
--- a/tests/fuzzer.c
+++ b/tests/fuzzer.c
@@ -126,7 +126,7 @@ static U32 FUZ_highbit32(U32 v32)
{
unsigned nbBits = 0;
if (v32==0) return 0;
- while (v32) v32 >>= 1, nbBits++;
+ while (v32) { v32 >>= 1; nbBits++; }
return nbBits;
}
@@ -766,8 +766,8 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c
if (blockSize > missingBytes) {
decodedBuffer[blockSize-missingBytes] = 0;
ret = LZ4_decompress_safe_usingDict(compressedBuffer, decodedBuffer, blockContinueCompressedSize, blockSize-missingBytes, dict, dictSize);
- FUZ_CHECKTEST(ret>=0, "LZ4_decompress_safe_usingDict should have failed : output buffer too small (-%u byte)", missingBytes);
- FUZ_CHECKTEST(decodedBuffer[blockSize-missingBytes], "LZ4_decompress_safe_usingDict overrun specified output buffer size (-%u byte) (blockSize=%i)", missingBytes, blockSize);
+ FUZ_CHECKTEST(ret>=0, "LZ4_decompress_safe_usingDict should have failed : output buffer too small (-%i byte)", missingBytes);
+ FUZ_CHECKTEST(decodedBuffer[blockSize-missingBytes], "LZ4_decompress_safe_usingDict overrun specified output buffer size (-%i byte) (blockSize=%i)", missingBytes, blockSize);
} }
/* Compress using external dictionary stream */