2 # ################################################################
3 # Copyright (c) Meta Platforms, Inc. and affiliates.
6 # This source code is licensed under both the BSD-style license (found in the
7 # LICENSE file in the root directory of this source tree) and the GPLv2 (found
8 # in the COPYING file in the root directory of this source tree).
9 # You may select, at your option, one of the above-listed licenses.
10 # ################################################################
11 # datagen : Synthetic and parametrable data generator, for tests
12 # fullbench : Precisely measure speed for each zstd inner functions
13 # fullbench32: Same as fullbench, but forced to compile in 32-bits mode
14 # fuzzer : Test tool, to check zstd integrity on target platform
15 # fuzzer32: Same as fuzzer, but forced to compile in 32-bits mode
16 # paramgrill : parameter tester for zstd
17 # test-zstd-speed.py : script for testing zstd speed difference between commits
18 # versionsTest : compatibility test between zstd versions stored on Github (v0.1+)
19 # zstreamtest : Fuzzer test tool for zstd streaming API
20 # zstreamtest32: Same as zstreamtest, but forced to compile in 32-bits mode
21 # ##########################################################################
23 ZSTD_LEGACY_SUPPORT ?= 5
24 export ZSTD_LEGACY_SUPPORT
27 export DEBUGLEVEL # transmit value to sub-makefiles
29 LIBZSTD_MK_DIR := ../lib
30 include $(LIBZSTD_MK_DIR)/libzstd.mk
34 TESTARTEFACT := versionsTest
36 DEBUGFLAGS += -g -Wno-c++-compat
37 CPPFLAGS += -I$(LIB_SRCDIR) -I$(LIB_SRCDIR)/common -I$(LIB_SRCDIR)/compress -I$(LIB_SRCDIR)/legacy \
38 -I$(LIB_SRCDIR)/dictBuilder -I$(LIB_SRCDIR)/deprecated -I$(PRGDIR) \
39 -DZSTD_WINDOW_OVERFLOW_CORRECT_FREQUENTLY=1
41 ZSTDCOMMON_FILES := $(sort $(ZSTD_COMMON_FILES))
42 ZSTDCOMP_FILES := $(sort $(ZSTD_COMPRESS_FILES))
43 ZSTDDECOMP_FILES := $(sort $(ZSTD_DECOMPRESS_FILES))
44 ZSTDLEGACY_FILES := $(sort $(wildcard $(LIB_SRCDIR)/legacy/*.c))
45 ZSTD_FILES := $(ZSTDDECOMP_FILES) $(ZSTDCOMMON_FILES) $(ZSTDCOMP_FILES) $(ZSTDLEGACY_FILES)
46 ZDICT_FILES := $(sort $(ZSTD_DICTBUILDER_FILES))
48 ZSTD_F1 := $(sort $(wildcard $(ZSTD_FILES)))
49 ZSTD_OBJ1 := $(subst $(LIB_SRCDIR)/common/,zstdm_,$(ZSTD_F1))
50 ZSTD_OBJ2 := $(subst $(LIB_SRCDIR)/compress/,zstdc_,$(ZSTD_OBJ1))
51 ZSTD_OBJ3 := $(subst $(LIB_SRCDIR)/decompress/,zstdd_,$(ZSTD_OBJ2))
52 ZSTD_OBJ4 := $(subst $(LIB_SRCDIR)/legacy/,zstdl_,$(ZSTD_OBJ3))
53 ZSTD_OBJ5 := $(ZSTD_OBJ4:.c=.o)
54 ZSTD_OBJECTS := $(ZSTD_OBJ5:.S=.o)
56 ZSTDMT_OBJ1 := $(subst $(LIB_SRCDIR)/common/,zstdmt_m_,$(ZSTD_F1))
57 ZSTDMT_OBJ2 := $(subst $(LIB_SRCDIR)/compress/,zstdmt_c_,$(ZSTDMT_OBJ1))
58 ZSTDMT_OBJ3 := $(subst $(LIB_SRCDIR)/decompress/,zstdmt_d_,$(ZSTDMT_OBJ2))
59 ZSTDMT_OBJ4 := $(subst $(LIB_SRCDIR)/legacy/,zstdmt_l_,$(ZSTDMT_OBJ3))
60 ZSTDMT_OBJ5 := $(ZSTDMT_OBJ4:.c=.o)
61 ZSTDMT_OBJECTS := $(ZSTDMT_OBJ5:.S=.o)
63 # Define *.exe as extension for Windows systems
64 ifneq (,$(filter Windows%,$(OS)))
66 MULTITHREAD_CPP = -DZSTD_MULTITHREAD
70 MULTITHREAD_CPP = -DZSTD_MULTITHREAD
71 MULTITHREAD_LD = -pthread
73 MULTITHREAD = $(MULTITHREAD_CPP) $(MULTITHREAD_LD)
76 ZSTREAM_TESTTIME ?= -T90s
78 ZSTDRTTEST = --test-large-data
79 DECODECORPUS_TESTTIME ?= -T30
85 all: fullbench fuzzer zstreamtest paramgrill datagen decodecorpus roundTripCrash poolTests
88 all32: fullbench32 fuzzer32 zstreamtest32
91 allnothread: MULTITHREAD_CPP=
92 allnothread: MULTITHREAD_LD=
93 allnothread: fullbench fuzzer paramgrill datagen decodecorpus
95 # note : broken : requires symbols unavailable from dynamic library
97 dll: fuzzer-dll zstreamtest-dll
99 .PHONY: zstd zstd32 zstd-nolegacy # only external makefile knows how to build or update them
100 zstd zstd32 zstd-nolegacy zstd-dll:
101 $(MAKE) -C $(PRGDIR) $@ MOREFLAGS+="$(DEBUGFLAGS)"
105 $(MAKE) -C $(LIB_SRCDIR) libzstd MOREFLAGS+="$(DEBUGFLAGS)"
108 %-dll : LDFLAGS += -L$(LIB_BINDIR) -lzstd
110 $(LIB_BINDIR)/libzstd.a :
111 $(MAKE) -C $(LIB_SRCDIR) libzstd.a
113 zstdm_%.o : $(LIB_SRCDIR)/common/%.c
114 $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
116 zstdc_%.o : $(LIB_SRCDIR)/compress/%.c
117 $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
119 zstdd_%.o : $(LIB_SRCDIR)/decompress/%.c
120 $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
122 zstdd_%.o : $(LIB_SRCDIR)/decompress/%.S
123 $(CC) -c $(CPPFLAGS) $(ASFLAGS) $< -o $@
125 zstdl_%.o : $(LIB_SRCDIR)/legacy/%.c
126 $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
128 zstdmt%.o : CPPFLAGS += $(MULTITHREAD_CPP)
130 zstdmt_m_%.o : $(LIB_SRCDIR)/common/%.c
131 $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
133 zstdmt_c_%.o : $(LIB_SRCDIR)/compress/%.c
134 $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
136 zstdmt_d_%.o : $(LIB_SRCDIR)/decompress/%.c
137 $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
139 zstdmt_d_%.o : $(LIB_SRCDIR)/decompress/%.S
140 $(CC) -c $(CPPFLAGS) $(ASFLAGS) $< -o $@
142 zstdmt_l_%.o : $(LIB_SRCDIR)/legacy/%.c
143 $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
145 FULLBENCHS := fullbench fullbench32
146 CLEAN += $(FULLBENCHS)
147 fullbench32: CPPFLAGS += -m32
148 $(FULLBENCHS) : CPPFLAGS += $(MULTITHREAD_CPP) -Wno-deprecated-declarations
149 $(FULLBENCHS) : LDFLAGS += $(MULTITHREAD_LD)
150 $(FULLBENCHS) : DEBUGFLAGS = -DNDEBUG # turn off assert() for speed measurements
151 $(FULLBENCHS) : $(ZSTD_FILES)
152 $(FULLBENCHS) : $(PRGDIR)/datagen.c $(PRGDIR)/util.c $(PRGDIR)/timefn.c $(PRGDIR)/benchfn.c fullbench.c
153 $(LINK.c) $^ -o $@$(EXT)
155 CLEAN += fullbench-lib
156 fullbench-lib : CPPFLAGS += -DXXH_NAMESPACE=ZSTD_
157 fullbench-lib : $(PRGDIR)/datagen.c $(PRGDIR)/util.c $(PRGDIR)/timefn.c $(PRGDIR)/benchfn.c $(LIB_SRCDIR)/libzstd.a fullbench.c
158 $(LINK.c) $^ -o $@$(EXT)
160 # note : broken : requires symbols unavailable from dynamic library
161 fullbench-dll: $(PRGDIR)/datagen.c $(PRGDIR)/util.c $(PRGDIR)/benchfn.c $(PRGDIR)/timefn.c fullbench.c
162 # $(CC) $(FLAGS) $(filter %.c,$^) -o $@$(EXT) -DZSTD_DLL_IMPORT=1 $(LIB_SRCDIR)/dll/libzstd.dll
163 $(LINK.c) $^ $(LDLIBS) -o $@$(EXT)
165 CLEAN += fuzzer fuzzer32
166 fuzzer : CPPFLAGS += $(MULTITHREAD_CPP) -Wno-deprecated-declarations
167 fuzzer : LDFLAGS += $(MULTITHREAD_LD)
168 fuzzer : $(ZSTDMT_OBJECTS)
169 fuzzer fuzzer32 : $(ZDICT_FILES) $(PRGDIR)/util.c $(PRGDIR)/timefn.c $(PRGDIR)/datagen.c fuzzer.c
171 fuzzer32 : CFLAGS += -m32 $(MULTITHREAD)
172 fuzzer32 : $(ZSTD_FILES)
173 $(LINK.c) $^ -o $@$(EXT)
175 # note : broken : requires symbols unavailable from dynamic library
176 fuzzer-dll : $(LIB_SRCDIR)/common/xxhash.c $(PRGDIR)/util.c $(PRGDIR)/timefn.c $(PRGDIR)/datagen.c fuzzer.c
177 $(CC) $(CPPFLAGS) $(CFLAGS) $(filter %.c,$^) $(LDFLAGS) -o $@$(EXT)
179 CLEAN += zstreamtest zstreamtest32
180 ZSTREAM_LOCAL_FILES := $(PRGDIR)/datagen.c $(PRGDIR)/util.c $(PRGDIR)/timefn.c seqgen.c zstreamtest.c external_matchfinder.c
181 ZSTREAM_PROPER_FILES := $(ZDICT_FILES) $(ZSTREAM_LOCAL_FILES)
182 ZSTREAMFILES := $(ZSTD_FILES) $(ZSTREAM_PROPER_FILES)
183 zstreamtest32 : CFLAGS += -m32
184 zstreamtest zstreamtest32 : CPPFLAGS += $(MULTITHREAD_CPP)
185 zstreamtest zstreamtest32 : LDFLAGS += $(MULTITHREAD_LD)
186 zstreamtest : $(ZSTDMT_OBJECTS) $(ZSTREAM_PROPER_FILES)
187 zstreamtest32 : $(ZSTREAMFILES)
188 zstreamtest zstreamtest32 :
189 $(LINK.c) $^ -o $@$(EXT)
191 CLEAN += zstreamtest_asan
192 zstreamtest_asan : CFLAGS += -fsanitize=address
193 zstreamtest_asan : $(ZSTREAMFILES)
194 $(LINK.c) $(MULTITHREAD) $^ -o $@$(EXT)
196 CLEAN += zstreamtest_tsan
197 zstreamtest_tsan : CFLAGS += -fsanitize=thread
198 zstreamtest_tsan : $(ZSTREAMFILES)
199 $(LINK.c) $(MULTITHREAD) $^ -o $@$(EXT)
201 CLEAN += zstreamtest_ubsan
202 zstreamtest_ubsan : CFLAGS += -fsanitize=undefined
203 zstreamtest_ubsan : $(ZSTREAMFILES)
204 $(LINK.c) $(MULTITHREAD) $^ -o $@$(EXT)
206 # note : broken : requires symbols unavailable from dynamic library
207 zstreamtest-dll : $(LIB_SRCDIR)/common/xxhash.c # xxh symbols not exposed from dll
208 zstreamtest-dll : $(ZSTREAM_LOCAL_FILES)
209 $(CC) $(CPPFLAGS) $(CFLAGS) $(filter %.c,$^) $(LDFLAGS) -o $@$(EXT)
212 paramgrill : DEBUGFLAGS = # turn off debug for speed measurements
213 paramgrill : LDLIBS += -lm
214 paramgrill : $(ZSTD_FILES) $(PRGDIR)/util.c $(PRGDIR)/timefn.c $(PRGDIR)/benchfn.c $(PRGDIR)/benchzstd.c $(PRGDIR)/datagen.c $(PRGDIR)/lorem.c paramgrill.c
217 datagen : $(PRGDIR)/datagen.c $(PRGDIR)/lorem.c loremOut.c datagencli.c
218 $(LINK.c) $^ -o $@$(EXT)
220 CLEAN += roundTripCrash
221 roundTripCrash: CFLAGS += $(MULTITHREAD)
222 roundTripCrash : $(ZSTD_OBJECTS) roundTripCrash.c
225 longmatch : $(ZSTD_OBJECTS) longmatch.c
228 bigdict: CFLAGS += $(MULTITHREAD)
229 bigdict: $(ZSTDMT_OBJECTS) $(PRGDIR)/datagen.c bigdict.c
231 CLEAN += invalidDictionaries
232 invalidDictionaries : $(ZSTD_OBJECTS) invalidDictionaries.c
235 legacy : CPPFLAGS += -UZSTD_LEGACY_SUPPORT -DZSTD_LEGACY_SUPPORT=4
236 legacy : $(ZSTD_FILES) legacy.c
238 CLEAN += decodecorpus
239 decodecorpus : LDLIBS += -lm
240 decodecorpus : $(filter-out zstdc_zstd_compress.o, $(ZSTD_OBJECTS)) $(ZDICT_FILES) $(PRGDIR)/util.c $(PRGDIR)/timefn.c decodecorpus.c
243 poolTests : $(PRGDIR)/util.c $(PRGDIR)/timefn.c poolTests.c $(LIB_SRCDIR)/common/pool.c $(LIB_SRCDIR)/common/threading.c $(LIB_SRCDIR)/common/zstd_common.c $(LIB_SRCDIR)/common/error_private.c
244 $(LINK.c) $(MULTITHREAD) $^ -o $@$(EXT)
248 $(PYTHON) test-zstd-versions.py
250 .PHONY: automated_benchmarking
251 automated_benchmarking: clean
252 $(PYTHON) automated_benchmarking.py
254 # make checkTag : check that release tag corresponds to release version
256 checkTag.o : $(LIB_SRCDIR)/zstd.h
260 $(MAKE) -C $(LIB_SRCDIR) clean
261 $(MAKE) -C $(PRGDIR) clean
262 $(MAKE) -C fuzz clean
263 $(RM) -R $(TESTARTEFACT)
264 $(RM) -r tmp* # some test directories are named tmp*
265 $(RM) $(CLEAN) core *.o *.tmp result* *.gcda dictionary *.zst \
266 $(PRGDIR)/zstd$(EXT) $(PRGDIR)/zstd32$(EXT) \
267 fullbench-dll$(EXT) fuzzer-dll$(EXT) zstreamtest-dll$(EXT)
268 @echo Cleaning completed
271 #----------------------------------------------------------------------------------
272 # valgrind tests validated only for some posix platforms
273 #----------------------------------------------------------------------------------
274 UNAME := $(shell uname)
275 ifneq (,$(filter $(UNAME),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS AIX CYGWIN_NT))
278 .PHONY: test-valgrind
279 test-valgrind: VALGRIND = valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1
280 test-valgrind: zstd datagen fuzzer fullbench
281 @echo "\n ---- valgrind tests : memory analyzer ----"
282 $(VALGRIND) ./datagen -g50M > $(VOID)
283 $(VALGRIND) $(PRGDIR)/zstd ; if [ $$? -eq 0 ] ; then echo "zstd without argument should have failed"; false; fi
284 ./datagen -g80 | $(VALGRIND) $(PRGDIR)/zstd - -c > $(VOID)
285 ./datagen -g16KB | $(VALGRIND) $(PRGDIR)/zstd -vf - -c > $(VOID)
286 ./datagen -g2930KB | $(VALGRIND) $(PRGDIR)/zstd -5 -vf - -o tmp
287 $(VALGRIND) $(PRGDIR)/zstd -vdf tmp -c > $(VOID)
288 ./datagen -g64MB | $(VALGRIND) $(PRGDIR)/zstd -vf - -c > $(VOID)
290 $(VALGRIND) ./fuzzer -T1mn -t1
291 $(VALGRIND) ./fullbench -i1
295 ifneq (,$(filter MINGW% MSYS%,$(UNAME)))
300 #-----------------------------------------------------------------------------
301 # make tests validated only for below targets
302 #-----------------------------------------------------------------------------
303 ifneq (,$(filter $(HOST_OS),MSYS POSIX))
306 ifneq (,$(filter $(UNAME),SunOS))
312 @$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs
315 shortest: ZSTDRTTEST= # remove long tests
322 fuzztest: test-fuzzer test-zstream test-decodecorpus
325 test: test-zstd test-cli-tests test-fullbench test-fuzzer test-zstream test-invalidDictionaries test-legacy test-decodecorpus
331 test32: test-zstd32 test-fullbench32 test-fuzzer32 test-zstream32
334 test-all: test test32 test-decodecorpus-cli
336 .PHONY: test-zstd test-zstd32 test-zstd-nolegacy
337 test-zstd: ZSTD = $(PRGDIR)/zstd
340 .PHONY: test-zstd-dll
341 test-zstd-dll: ZSTD = $(PRGDIR)/zstd
342 test-zstd-dll: zstd-dll
344 test-zstd32: ZSTD = $(PRGDIR)/zstd32
347 test-zstd-nolegacy: ZSTD = $(PRGDIR)/zstd-nolegacy
348 test-zstd-nolegacy: zstd-nolegacy
350 test-zstd test-zstd32 test-zstd-nolegacy test-zstd-dll: datagen
352 EXE_PREFIX="$(QEMU_SYS)" ZSTD_BIN="$(ZSTD)" DATAGEN_BIN=./datagen ./playTests.sh $(ZSTDRTTEST)
354 .PHONY: test-cli-tests
355 test-cli-tests: ZSTD = $(PRGDIR)/zstd
356 test-cli-tests: zstd datagen
358 ./cli-tests/run.py --exec-prefix="$(QEMU_SYS)" --zstd="$(ZSTD)" --datagen=./datagen
360 .PHONY: test-fullbench
361 test-fullbench: fullbench datagen
362 $(QEMU_SYS) ./fullbench -i1
363 $(QEMU_SYS) ./fullbench -i1 -P0
365 .PHONY: test-fullbench32
366 test-fullbench32: fullbench32 datagen
367 $(QEMU_SYS) ./fullbench32 -i1
368 $(QEMU_SYS) ./fullbench32 -i1 -P0
372 $(QEMU_SYS) ./fuzzer -v $(FUZZERTEST) $(FUZZER_FLAGS)
374 # Note : this test presumes `fuzzer` will be built
375 .PHONY: test-fuzzer-stackmode
376 test-fuzzer-stackmode: MOREFLAGS += -DZSTD_HEAPMODE=0
377 test-fuzzer-stackmode: test-fuzzer
379 .PHONY: test-fuzzer32
380 test-fuzzer32: fuzzer32
381 $(QEMU_SYS) ./fuzzer32 -v $(FUZZERTEST) $(FUZZER_FLAGS)
384 test-zstream: zstreamtest
385 $(QEMU_SYS) ./zstreamtest -v $(ZSTREAM_TESTTIME) $(FUZZER_FLAGS)
386 $(QEMU_SYS) ./zstreamtest --newapi -t1 $(ZSTREAM_TESTTIME) $(FUZZER_FLAGS)
388 test-zstream32: zstreamtest32
389 $(QEMU_SYS) ./zstreamtest32 -v $(ZSTREAM_TESTTIME) $(FUZZER_FLAGS)
391 test-longmatch: longmatch
392 $(QEMU_SYS) ./longmatch
394 test-bigdict: bigdict
395 $(QEMU_SYS) ./bigdict
397 test-invalidDictionaries: invalidDictionaries
398 $(QEMU_SYS) ./invalidDictionaries
403 test-decodecorpus: decodecorpus
404 $(QEMU_SYS) ./decodecorpus -t $(DECODECORPUS_TESTTIME)
406 test-decodecorpus-cli: decodecorpus
407 @echo "\n ---- decodecorpus basic cli tests ----"
409 ./decodecorpus -n5 -otestdir -ptestdir
411 $(ZSTD) -d z000000.zst -o tmp0 && \
412 $(ZSTD) -d z000001.zst -o tmp1 && \
413 $(ZSTD) -d z000002.zst -o tmp2 && \
414 $(ZSTD) -d z000003.zst -o tmp3 && \
415 $(ZSTD) -d z000004.zst -o tmp4 && \
416 diff z000000 tmp0 && \
417 diff z000001 tmp1 && \
418 diff z000002 tmp2 && \
419 diff z000003 tmp3 && \
420 diff z000004 tmp4 && \
423 @echo "\n ---- decodecorpus dictionary cli tests ----"
424 ./decodecorpus -n5 -otestdir -ptestdir --use-dict=1MB
426 $(ZSTD) -d z000000.zst -D dictionary -o tmp0 && \
427 $(ZSTD) -d z000001.zst -D dictionary -o tmp1 && \
428 $(ZSTD) -d z000002.zst -D dictionary -o tmp2 && \
429 $(ZSTD) -d z000003.zst -D dictionary -o tmp3 && \
430 $(ZSTD) -d z000004.zst -D dictionary -o tmp4 && \
431 diff z000000 tmp0 && \
432 diff z000001 tmp1 && \
433 diff z000002 tmp2 && \
434 diff z000003 tmp3 && \
435 diff z000004 tmp4 && \
440 $(QEMU_SYS) ./poolTests
442 test-lz4: ZSTD = LD_LIBRARY_PATH=/usr/local/lib $(PRGDIR)/zstd
443 test-lz4: ZSTD_LZ4 = LD_LIBRARY_PATH=/usr/local/lib ./lz4
444 test-lz4: ZSTD_UNLZ4 = LD_LIBRARY_PATH=/usr/local/lib ./unlz4
445 test-lz4: zstd decodecorpus datagen
446 [ -f lz4 ] || ln -s $(PRGDIR)/zstd lz4
447 [ -f unlz4 ] || ln -s $(PRGDIR)/zstd unlz4
458 $(ZSTD) --format=lz4 < tmp | \
461 $(ZSTD_LZ4) < tmp | \
465 $(ZSTD) --format=lz4 < tmp | \
473 ./datagen -g384KB | $(ZSTD) --format=lz4 | $(ZSTD) -d > /dev/null