diff options
-rw-r--r-- | .github/workflows/ci.yml | 10 | ||||
-rw-r--r-- | Makefile | 39 | ||||
-rw-r--r-- | tests/decompress-partial-usingDict.c | 37 |
3 files changed, 74 insertions, 12 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 616926e..0e6d69c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -207,6 +207,16 @@ jobs: run: make V=1 -C tests test-fuzzer32 + lz4-standard-makefile-variables: + name: LZ4 Makefile - support for standard variables + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 # https://github.com/actions/checkout + + - name: make standard_variables + run: make V=1 standard_variables + + lz4-versions: name: LZ4 versions test runs-on: ubuntu-latest @@ -233,6 +233,43 @@ c_standards_c99: clean .PHONY: c_standards_c11 c_standards_c11: clean - $(MAKE) clean; CFLAGS="-std=c11 -Werror" $(MAKE) all + $(MAKE) clean; CFLAGS="-std=c11 -Werror" $(MAKE) all + +# The following test ensures that standard Makefile variables set through environment +# are correctly transmitted at compilation stage. +# This test is meant to detect issues like https://github.com/lz4/lz4/issues/958 +.PHONY: standard_variables +standard_variables: clean + @echo ================= + @echo Check support of Makefile Standard variables through environment + @echo note : this test requires V=1 to work properly + @echo ================= + CC="cc -DCC_TEST" \ + CFLAGS=-DCFLAGS_TEST \ + CPPFLAGS=-DCPPFLAGS_TEST \ + LDFLAGS=-DLDFLAGS_TEST \ + LDLIBS=-DLDLIBS_TEST \ + $(MAKE) V=1 > tmpsv + # Note: just checking the presence of custom flags + # would not detect situations where custom flags are + # supported in some part of the Makefile, and missed in others. + # So the test checks if they are present the _right nb of times_. + # However, checking static quantities makes this test brittle, + # because quantities (7, 2 and 1) can still evolve in future, + # for example when source directories or Makefile evolve. + if [ $$(grep CC_TEST tmpsv | wc -l) -ne 7 ]; then \ + echo "CC environment variable missed" && False; fi + if [ $$(grep CFLAGS_TEST tmpsv | wc -l) -ne 7 ]; then \ + echo "CFLAGS environment variable missed" && False; fi + if [ $$(grep CPPFLAGS_TEST tmpsv | wc -l) -ne 7 ]; then \ + echo "CPPFLAGS environment variable missed" && False; fi + if [ $$(grep LDFLAGS_TEST tmpsv | wc -l) -ne 2 ]; then \ + echo "LDFLAGS environment variable missed" && False; fi + if [ $$(grep LDLIBS_TEST tmpsv | wc -l) -ne 1 ]; then \ + echo "LDLIBS environment variable missed" && False; fi + @echo ================= + @echo all custom variables detected + @echo ================= + $(RM) tmpsv endif # MSYS POSIX diff --git a/tests/decompress-partial-usingDict.c b/tests/decompress-partial-usingDict.c index cfcb971..8b85106 100644 --- a/tests/decompress-partial-usingDict.c +++ b/tests/decompress-partial-usingDict.c @@ -1,6 +1,7 @@ -#include "stdio.h" -#include "string.h" -#include "stdlib.h" +#include <stdlib.h> +#include <string.h> +#include <stdio.h> +#include <assert.h> #include "lz4.h" const char source[] = @@ -33,27 +34,35 @@ int main(void) size_t const smallSize = 1024; size_t const largeSize = 64 * 1024 - 1; char cmpBuffer[BUFFER_SIZE]; - char buffer[BUFFER_SIZE + largeSize]; + char* const buffer = (char*)malloc(BUFFER_SIZE + largeSize); char* outBuffer = buffer + largeSize; char* const dict = (char*)malloc(largeSize); char* const largeDict = dict; char* const smallDict = dict + largeSize - smallSize; - int cmpSize; int i; + int cmpSize; + + printf("starting test decompress-partial-usingDict : \n"); + assert(buffer != NULL); + assert(dict != NULL); cmpSize = LZ4_compress_default(source, cmpBuffer, srcLen, BUFFER_SIZE); for (i = cmpSize; i < cmpSize + 10; ++i) { int result = LZ4_decompress_safe_partial_usingDict(cmpBuffer, outBuffer, i, srcLen, BUFFER_SIZE, NULL, 0); - if ((result < 0) || (result != srcLen) || memcmp(source, outBuffer, srcLen)) { + if ( (result < 0) + || (result != srcLen) + || memcmp(source, outBuffer, (size_t)srcLen) ) { printf("test decompress-partial-usingDict with no dict error \n"); return -1; } } - + for (i = cmpSize; i < cmpSize + 10; ++i) { int result = LZ4_decompress_safe_partial_usingDict(cmpBuffer, outBuffer, i, srcLen, BUFFER_SIZE, outBuffer - smallSize, smallSize); - if ((result < 0) || (result != srcLen) || memcmp(source, outBuffer, srcLen)) { + if ( (result < 0) + || (result != srcLen) + || memcmp(source, outBuffer, (size_t)srcLen) ) { printf("test decompress-partial-usingDict with small prefix error \n"); return -1; } @@ -61,7 +70,9 @@ int main(void) for (i = cmpSize; i < cmpSize + 10; ++i) { int result = LZ4_decompress_safe_partial_usingDict(cmpBuffer, outBuffer, i, srcLen, BUFFER_SIZE, buffer, largeSize); - if ((result < 0) || (result != srcLen) || memcmp(source, outBuffer, srcLen)) { + if ( (result < 0) + || (result != srcLen) + || memcmp(source, outBuffer, (size_t)srcLen) ) { printf("test decompress-partial-usingDict with large prefix error \n"); return -1; } @@ -69,7 +80,9 @@ int main(void) for (i = cmpSize; i < cmpSize + 10; ++i) { int result = LZ4_decompress_safe_partial_usingDict(cmpBuffer, outBuffer, i, srcLen, BUFFER_SIZE, smallDict, smallSize); - if ((result < 0) || (result != srcLen) || memcmp(source, outBuffer, srcLen)) { + if ( (result < 0) + || (result != srcLen) + || memcmp(source, outBuffer, (size_t)srcLen) ) { printf("test decompress-partial-usingDict with small external dict error \n"); return -1; } @@ -77,7 +90,9 @@ int main(void) for (i = cmpSize; i < cmpSize + 10; ++i) { int result = LZ4_decompress_safe_partial_usingDict(cmpBuffer, outBuffer, i, srcLen, BUFFER_SIZE, largeDict, largeSize); - if ((result < 0) || (result != srcLen) || memcmp(source, outBuffer, srcLen)) { + if ( (result < 0) + || (result != srcLen) + || memcmp(source, outBuffer, (size_t)srcLen) ) { printf("test decompress-partial-usingDict with large external dict error \n"); return -1; } |