1# ################################################################ 2# Copyright (c) 2015-present, Yann Collet, Facebook, Inc. 3# All rights reserved. 4# 5# This source code is licensed under both the BSD-style license (found in the 6# LICENSE file in the root directory of this source tree) and the GPLv2 (found 7# in the COPYING file in the root directory of this source tree). 8# ################################################################ 9# datagen : Synthetic and parametrable data generator, for tests 10# fullbench : Precisely measure speed for each zstd inner functions 11# fullbench32: Same as fullbench, but forced to compile in 32-bits mode 12# fuzzer : Test tool, to check zstd integrity on target platform 13# fuzzer32: Same as fuzzer, but forced to compile in 32-bits mode 14# paramgrill : parameter tester for zstd 15# test-zstd-speed.py : script for testing zstd speed difference between commits 16# versionsTest : compatibility test between zstd versions stored on Github (v0.1+) 17# zstreamtest : Fuzzer test tool for zstd streaming API 18# zstreamtest32: Same as zstreamtest, but forced to compile in 32-bits mode 19# ########################################################################## 20 21ZSTDDIR = ../lib 22PRGDIR = ../programs 23PYTHON ?= python3 24TESTARTEFACT := versionsTest namespaceTest 25 26DEBUGLEVEL ?= 1 27DEBUGFLAGS = -g -DZSTD_DEBUG=$(DEBUGLEVEL) 28CPPFLAGS += -I$(ZSTDDIR) -I$(ZSTDDIR)/common -I$(ZSTDDIR)/compress \ 29 -I$(ZSTDDIR)/dictBuilder -I$(ZSTDDIR)/deprecated -I$(PRGDIR) 30CFLAGS ?= -O3 31CFLAGS += -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \ 32 -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \ 33 -Wstrict-prototypes -Wundef -Wformat-security \ 34 -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \ 35 -Wredundant-decls 36CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS) 37FLAGS = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) 38 39 40ZSTDCOMMON_FILES := $(ZSTDDIR)/common/*.c 41ZSTDCOMP_FILES := $(ZSTDDIR)/compress/*.c 42ZSTDDECOMP_FILES := $(ZSTDDIR)/decompress/*.c 43ZSTD_FILES := $(ZSTDDECOMP_FILES) $(ZSTDCOMMON_FILES) $(ZSTDCOMP_FILES) 44ZBUFF_FILES := $(ZSTDDIR)/deprecated/*.c 45ZDICT_FILES := $(ZSTDDIR)/dictBuilder/*.c 46 47 48# Define *.exe as extension for Windows systems 49ifneq (,$(filter Windows%,$(OS))) 50EXT =.exe 51MULTITHREAD_CPP = -DZSTD_MULTITHREAD 52MULTITHREAD_LD = 53else 54EXT = 55MULTITHREAD_CPP = -DZSTD_MULTITHREAD 56MULTITHREAD_LD = -pthread 57endif 58MULTITHREAD = $(MULTITHREAD_CPP) $(MULTITHREAD_LD) 59 60VOID = /dev/null 61ZSTREAM_TESTTIME ?= -T90s 62FUZZERTEST ?= -T200s 63ZSTDRTTEST = --test-large-data 64DECODECORPUS_TESTTIME ?= -T30 65 66.PHONY: default all all32 allnothread dll clean test test32 test-all namespaceTest versionsTest 67 68default: fullbench 69 70all: fullbench fuzzer zstreamtest paramgrill datagen decodecorpus 71 72all32: fullbench32 fuzzer32 zstreamtest32 73 74allnothread: fullbench fuzzer paramgrill datagen decodecorpus 75 76dll: fuzzer-dll zstreamtest-dll 77 78zstd: 79 $(MAKE) -C $(PRGDIR) $@ MOREFLAGS+="$(DEBUGFLAGS)" 80 81zstd32: 82 $(MAKE) -C $(PRGDIR) $@ MOREFLAGS+="$(DEBUGFLAGS)" 83 84zstd-nolegacy: 85 $(MAKE) -C $(PRGDIR) $@ MOREFLAGS+="$(DEBUGFLAGS)" 86 87gzstd: 88 $(MAKE) -C $(PRGDIR) zstd HAVE_ZLIB=1 MOREFLAGS="$(DEBUGFLAGS)" 89 90fullbench32: CPPFLAGS += -m32 91fullbench fullbench32 : CPPFLAGS += $(MULTITHREAD_CPP) 92fullbench fullbench32 : LDFLAGS += $(MULTITHREAD_LD) 93fullbench fullbench32 : DEBUGFLAGS = # turn off assert() for speed measurements 94fullbench fullbench32 : $(ZSTD_FILES) $(PRGDIR)/datagen.c fullbench.c 95 $(CC) $(FLAGS) $^ -o $@$(EXT) 96 97fullbench-lib: $(PRGDIR)/datagen.c fullbench.c 98 $(MAKE) -C $(ZSTDDIR) libzstd.a 99 $(CC) $(FLAGS) $^ -o $@$(EXT) $(ZSTDDIR)/libzstd.a 100 101fullbench-dll: $(PRGDIR)/datagen.c fullbench.c 102 $(MAKE) -C $(ZSTDDIR) libzstd 103 $(CC) $(FLAGS) $^ -o $@$(EXT) -DZSTD_DLL_IMPORT=1 $(ZSTDDIR)/dll/libzstd.dll 104 105fuzzer : CPPFLAGS += $(MULTITHREAD_CPP) 106fuzzer : LDFLAGS += $(MULTITHREAD_LD) 107fuzzer32: CFLAGS += -m32 108fuzzer fuzzer32 : $(ZSTD_FILES) $(ZDICT_FILES) $(PRGDIR)/datagen.c fuzzer.c 109 $(CC) $(FLAGS) $^ -o $@$(EXT) 110 111fuzzer-dll : LDFLAGS+= -L$(ZSTDDIR) -lzstd 112fuzzer-dll : $(ZSTDDIR)/common/xxhash.c $(PRGDIR)/datagen.c fuzzer.c 113 $(MAKE) -C $(ZSTDDIR) libzstd 114 $(CC) $(CPPFLAGS) $(CFLAGS) $^ $(LDFLAGS) -o $@$(EXT) 115 116zbufftest : CPPFLAGS += -I$(ZSTDDIR)/deprecated 117zbufftest : CFLAGS += -Wno-deprecated-declarations # required to silence deprecation warnings 118zbufftest : $(ZSTD_FILES) $(ZBUFF_FILES) $(PRGDIR)/datagen.c zbufftest.c 119 $(CC) $(FLAGS) $^ -o $@$(EXT) 120 121zbufftest32 : CPPFLAGS += -I$(ZSTDDIR)/deprecated 122zbufftest32 : CFLAGS += -Wno-deprecated-declarations -m32 123zbufftest32 : $(ZSTD_FILES) $(ZBUFF_FILES) $(PRGDIR)/datagen.c zbufftest.c 124 $(CC) $(FLAGS) $^ -o $@$(EXT) 125 126zbufftest-dll : CPPFLAGS += -I$(ZSTDDIR)/deprecated 127zbufftest-dll : CFLAGS += -Wno-deprecated-declarations # required to silence deprecation warnings 128zbufftest-dll : LDFLAGS+= -L$(ZSTDDIR) -lzstd 129zbufftest-dll : $(ZSTDDIR)/common/xxhash.c $(PRGDIR)/datagen.c zbufftest.c 130 $(MAKE) -C $(ZSTDDIR) libzstd 131 $(CC) $(CPPFLAGS) $(CFLAGS) $^ $(LDFLAGS) -o $@$(EXT) 132 133ZSTREAMFILES := $(ZSTD_FILES) $(ZDICT_FILES) $(PRGDIR)/datagen.c seqgen.c zstreamtest.c 134zstreamtest32 : CFLAGS += -m32 135zstreamtest zstreamtest32 : CPPFLAGS += $(MULTITHREAD_CPP) 136zstreamtest zstreamtest32 : LDFLAGS += $(MULTITHREAD_LD) 137zstreamtest zstreamtest32 : $(ZSTREAMFILES) 138 $(CC) $(FLAGS) $^ -o $@$(EXT) 139 140zstreamtest_asan : CFLAGS += -fsanitize=address 141zstreamtest_asan : $(ZSTREAMFILES) 142 $(CC) $(FLAGS) $(MULTITHREAD) $^ -o $@$(EXT) 143 144zstreamtest_tsan : CFLAGS += -fsanitize=thread 145zstreamtest_tsan : $(ZSTREAMFILES) 146 $(CC) $(FLAGS) $(MULTITHREAD) $^ -o $@$(EXT) 147 148zstreamtest-dll : LDFLAGS+= -L$(ZSTDDIR) -lzstd 149zstreamtest-dll : $(ZSTDDIR)/common/xxhash.c $(PRGDIR)/datagen.c zstreamtest.c 150 $(MAKE) -C $(ZSTDDIR) libzstd 151 $(CC) $(CPPFLAGS) $(CFLAGS) $^ $(LDFLAGS) -o $@$(EXT) 152 153paramgrill : DEBUGFLAGS = 154paramgrill : $(ZSTD_FILES) $(PRGDIR)/datagen.c paramgrill.c 155 $(CC) $(FLAGS) $^ -lm -o $@$(EXT) 156 157datagen : $(PRGDIR)/datagen.c datagencli.c 158 $(CC) $(FLAGS) $^ -o $@$(EXT) 159 160roundTripCrash : $(ZSTD_FILES) roundTripCrash.c 161 $(CC) $(FLAGS) $(MULTITHREAD) $^ -o $@$(EXT) 162 163longmatch : $(ZSTD_FILES) longmatch.c 164 $(CC) $(FLAGS) $^ -o $@$(EXT) 165 166invalidDictionaries : $(ZSTD_FILES) invalidDictionaries.c 167 $(CC) $(FLAGS) $^ -o $@$(EXT) 168 169legacy : CFLAGS+= -DZSTD_LEGACY_SUPPORT=4 170legacy : CPPFLAGS+= -I$(ZSTDDIR)/legacy 171legacy : $(ZSTD_FILES) $(wildcard $(ZSTDDIR)/legacy/*.c) legacy.c 172 $(CC) $(FLAGS) $^ -o $@$(EXT) 173 174decodecorpus : $(filter-out $(ZSTDDIR)/compress/zstd_compress.c, $(wildcard $(ZSTD_FILES))) $(ZDICT_FILES) decodecorpus.c 175 $(CC) $(FLAGS) $^ -o $@$(EXT) -lm 176 177symbols : symbols.c 178 $(MAKE) -C $(ZSTDDIR) libzstd 179ifneq (,$(filter Windows%,$(OS))) 180 cp $(ZSTDDIR)/dll/libzstd.dll . 181 $(CC) $(FLAGS) $^ -o $@$(EXT) -DZSTD_DLL_IMPORT=1 libzstd.dll 182else 183 $(CC) $(FLAGS) $^ -o $@$(EXT) -Wl,-rpath=$(ZSTDDIR) $(ZSTDDIR)/libzstd.so 184endif 185 186poolTests : poolTests.c $(ZSTDDIR)/common/pool.c $(ZSTDDIR)/common/threading.c $(ZSTDDIR)/common/zstd_common.c $(ZSTDDIR)/common/error_private.c 187 $(CC) $(FLAGS) $(MULTITHREAD) $^ -o $@$(EXT) 188 189namespaceTest: 190 if $(CC) namespaceTest.c ../lib/common/xxhash.c -o $@ ; then echo compilation should fail; exit 1 ; fi 191 $(RM) $@ 192 193versionsTest: clean 194 $(PYTHON) test-zstd-versions.py 195 196clean: 197 $(MAKE) -C $(ZSTDDIR) clean 198 @$(RM) -fR $(TESTARTEFACT) 199 @$(RM) -f core *.o tmp* result* *.gcda dictionary *.zst \ 200 $(PRGDIR)/zstd$(EXT) $(PRGDIR)/zstd32$(EXT) \ 201 fullbench$(EXT) fullbench32$(EXT) \ 202 fullbench-lib$(EXT) fullbench-dll$(EXT) \ 203 fuzzer$(EXT) fuzzer32$(EXT) zbufftest$(EXT) zbufftest32$(EXT) \ 204 fuzzer-dll$(EXT) zstreamtest-dll$(EXT) zbufftest-dll$(EXT)\ 205 zstreamtest$(EXT) zstreamtest32$(EXT) \ 206 datagen$(EXT) paramgrill$(EXT) roundTripCrash$(EXT) longmatch$(EXT) \ 207 symbols$(EXT) invalidDictionaries$(EXT) legacy$(EXT) poolTests$(EXT) \ 208 decodecorpus$(EXT) 209 @echo Cleaning completed 210 211 212#---------------------------------------------------------------------------------- 213#make valgrindTest is validated only for Linux, OSX, BSD, Hurd and Solaris targets 214#---------------------------------------------------------------------------------- 215ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS)) 216HOST_OS = POSIX 217 218valgrindTest: VALGRIND = valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 219valgrindTest: zstd datagen fuzzer fullbench 220 @echo "\n ---- valgrind tests : memory analyzer ----" 221 $(VALGRIND) ./datagen -g50M > $(VOID) 222 $(VALGRIND) $(PRGDIR)/zstd ; if [ $$? -eq 0 ] ; then echo "zstd without argument should have failed"; false; fi 223 ./datagen -g80 | $(VALGRIND) $(PRGDIR)/zstd - -c > $(VOID) 224 ./datagen -g16KB | $(VALGRIND) $(PRGDIR)/zstd -vf - -c > $(VOID) 225 ./datagen -g2930KB | $(VALGRIND) $(PRGDIR)/zstd -5 -vf - -o tmp 226 $(VALGRIND) $(PRGDIR)/zstd -vdf tmp -c > $(VOID) 227 ./datagen -g64MB | $(VALGRIND) $(PRGDIR)/zstd -vf - -c > $(VOID) 228 @rm tmp 229 $(VALGRIND) ./fuzzer -T1mn -t1 230 $(VALGRIND) ./fullbench -i1 231 232endif 233 234 235ifneq (,$(filter MSYS%,$(shell uname))) 236HOST_OS = MSYS 237endif 238 239 240#----------------------------------------------------------------------------- 241# make tests validated only for below targets 242#----------------------------------------------------------------------------- 243ifneq (,$(filter $(HOST_OS),MSYS POSIX)) 244 245DIFF:=diff 246ifneq (,$(filter $(shell uname),SunOS)) 247DIFF:=gdiff 248endif 249 250zstd-playTests: datagen 251 file $(ZSTD) 252 ZSTD="$(QEMU_SYS) $(ZSTD)" ./playTests.sh $(ZSTDRTTEST) 253 254shortest: ZSTDRTTEST= 255shortest: test-zstd 256 257fuzztest: test-fuzzer test-zstream test-decodecorpus 258 259test: test-zstd test-fullbench test-fuzzer test-zstream test-invalidDictionaries test-legacy test-decodecorpus 260ifeq ($(QEMU_SYS),) 261test: test-pool 262endif 263 264test32: test-zstd32 test-fullbench32 test-fuzzer32 test-zstream32 265 266test-all: test test32 valgrindTest test-decodecorpus-cli 267 268test-zstd: ZSTD = $(PRGDIR)/zstd 269test-zstd: zstd zstd-playTests 270 271test-zstd32: ZSTD = $(PRGDIR)/zstd32 272test-zstd32: zstd32 zstd-playTests 273 274test-zstd-nolegacy: ZSTD = $(PRGDIR)/zstd-nolegacy 275test-zstd-nolegacy: zstd-nolegacy zstd-playTests 276 277test-gzstd: gzstd 278 $(PRGDIR)/zstd -f README.md test-zstd-speed.py 279 gzip -f README.md test-zstd-speed.py 280 cat README.md.zst test-zstd-speed.py.gz >zstd_gz.zst 281 cat README.md.gz test-zstd-speed.py.zst >gz_zstd.gz 282 $(PRGDIR)/zstd -df README.md.gz -o README2.md 283 $(PRGDIR)/zstd -df README.md.gz test-zstd-speed.py.gz 284 $(PRGDIR)/zstd -df zstd_gz.zst gz_zstd.gz 285 $(DIFF) -q zstd_gz gz_zstd 286 echo Hello World ZSTD | $(PRGDIR)/zstd -c - >hello.zst 287 echo Hello World GZIP | gzip -c - >hello.gz 288 echo Hello World TEXT >hello.txt 289 cat hello.zst hello.gz hello.txt >hello_zst_gz_txt.gz 290 $(PRGDIR)/zstd -dcf hello.* 291 $(PRGDIR)/zstd -dcf - <hello_zst_gz_txt.gz 292 $(RM) *.gz *.zst README2.md gz_zstd zstd_gz hello.txt 293 294test-fullbench: fullbench datagen 295 $(QEMU_SYS) ./fullbench -i1 296 $(QEMU_SYS) ./fullbench -i1 -P0 297 298test-fullbench32: fullbench32 datagen 299 $(QEMU_SYS) ./fullbench32 -i1 300 $(QEMU_SYS) ./fullbench32 -i1 -P0 301 302test-fuzzer: fuzzer 303 $(QEMU_SYS) ./fuzzer -v $(FUZZERTEST) $(FUZZER_FLAGS) 304 305test-fuzzer32: fuzzer32 306 $(QEMU_SYS) ./fuzzer32 -v $(FUZZERTEST) $(FUZZER_FLAGS) 307 308test-zbuff: zbufftest 309 $(QEMU_SYS) ./zbufftest $(ZSTREAM_TESTTIME) 310 311test-zbuff32: zbufftest32 312 $(QEMU_SYS) ./zbufftest32 $(ZSTREAM_TESTTIME) 313 314test-zstream: zstreamtest 315 $(QEMU_SYS) ./zstreamtest -v $(ZSTREAM_TESTTIME) $(FUZZER_FLAGS) 316 $(QEMU_SYS) ./zstreamtest --mt -t1 $(ZSTREAM_TESTTIME) $(FUZZER_FLAGS) 317 $(QEMU_SYS) ./zstreamtest --newapi -t1 $(ZSTREAM_TESTTIME) $(FUZZER_FLAGS) 318 $(QEMU_SYS) ./zstreamtest --opaqueapi -t1 $(ZSTREAM_TESTTIME) $(FUZZER_FLAGS) 319 320test-zstream32: zstreamtest32 321 $(QEMU_SYS) ./zstreamtest32 $(ZSTREAM_TESTTIME) $(FUZZER_FLAGS) 322 323test-longmatch: longmatch 324 $(QEMU_SYS) ./longmatch 325 326test-invalidDictionaries: invalidDictionaries 327 $(QEMU_SYS) ./invalidDictionaries 328 329test-symbols: symbols 330 $(QEMU_SYS) ./symbols 331 332test-legacy: legacy 333 $(QEMU_SYS) ./legacy 334 335test-decodecorpus: decodecorpus 336 $(QEMU_SYS) ./decodecorpus -t $(DECODECORPUS_TESTTIME) 337 338test-decodecorpus-cli: decodecorpus 339 @echo "\n ---- decodecorpus basic cli tests ----" 340 @mkdir testdir 341 ./decodecorpus -n5 -otestdir -ptestdir 342 @cd testdir && \ 343 $(ZSTD) -d z000000.zst -o tmp0 && \ 344 $(ZSTD) -d z000001.zst -o tmp1 && \ 345 $(ZSTD) -d z000002.zst -o tmp2 && \ 346 $(ZSTD) -d z000003.zst -o tmp3 && \ 347 $(ZSTD) -d z000004.zst -o tmp4 && \ 348 diff z000000 tmp0 && \ 349 diff z000001 tmp1 && \ 350 diff z000002 tmp2 && \ 351 diff z000003 tmp3 && \ 352 diff z000004 tmp4 && \ 353 rm ./* && \ 354 cd .. 355 @echo "\n ---- decodecorpus dictionary cli tests ----" 356 ./decodecorpus -n5 -otestdir -ptestdir --use-dict=1MB 357 @cd testdir && \ 358 $(ZSTD) -d z000000.zst -D dictionary -o tmp0 && \ 359 $(ZSTD) -d z000001.zst -D dictionary -o tmp1 && \ 360 $(ZSTD) -d z000002.zst -D dictionary -o tmp2 && \ 361 $(ZSTD) -d z000003.zst -D dictionary -o tmp3 && \ 362 $(ZSTD) -d z000004.zst -D dictionary -o tmp4 && \ 363 diff z000000 tmp0 && \ 364 diff z000001 tmp1 && \ 365 diff z000002 tmp2 && \ 366 diff z000003 tmp3 && \ 367 diff z000004 tmp4 && \ 368 cd .. 369 @rm -rf testdir 370 371test-pool: poolTests 372 $(QEMU_SYS) ./poolTests 373 374test-lz4: ZSTD = LD_LIBRARY_PATH=/usr/local/lib $(PRGDIR)/zstd 375test-lz4: ZSTD_LZ4 = LD_LIBRARY_PATH=/usr/local/lib ./lz4 376test-lz4: ZSTD_UNLZ4 = LD_LIBRARY_PATH=/usr/local/lib ./unlz4 377test-lz4: zstd decodecorpus datagen 378 [ -f lz4 ] || ln -s $(PRGDIR)/zstd lz4 379 [ -f unlz4 ] || ln -s $(PRGDIR)/zstd unlz4 380 381 ./decodecorpus -ptmp 382 # lz4 -> zstd 383 lz4 < tmp | \ 384 $(ZSTD) -d | \ 385 cmp - tmp 386 lz4 < tmp | \ 387 $(ZSTD_UNLZ4) | \ 388 cmp - tmp 389 # zstd -> lz4 390 $(ZSTD) --format=lz4 < tmp | \ 391 lz4 -d | \ 392 cmp - tmp 393 $(ZSTD_LZ4) < tmp | \ 394 lz4 -d | \ 395 cmp - tmp 396 # zstd -> zstd 397 $(ZSTD) --format=lz4 < tmp | \ 398 $(ZSTD) -d | \ 399 cmp - tmp 400 # zstd -> zstd 401 $(ZSTD) < tmp | \ 402 $(ZSTD) -d | \ 403 cmp - tmp 404 405 ./datagen -g384KB | $(ZSTD) --format=lz4 | $(ZSTD) -d > /dev/null 406 407 rm tmp lz4 unlz4 408 409endif 410