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 # ##########################################################################
25 ZSTD_LEGACY_SUPPORT ?= 0
28 export DEBUGLEVEL # transmit value to sub-makefiles
30 include $(LIBZSTD)/libzstd.mk
35 TESTARTEFACT := versionsTest
37 DEBUGFLAGS += -g -Wno-c++-compat
38 CPPFLAGS += -I$(ZSTDDIR) -I$(ZSTDDIR)/common -I$(ZSTDDIR)/compress \
39 -I$(ZSTDDIR)/dictBuilder -I$(ZSTDDIR)/deprecated -I$(PRGDIR) \
40 -DZSTD_WINDOW_OVERFLOW_CORRECT_FREQUENTLY=1
42 ZSTDCOMMON_FILES := $(sort $(ZSTD_COMMON_FILES))
43 ZSTDCOMP_FILES := $(sort $(ZSTD_COMPRESS_FILES))
44 ZSTDDECOMP_FILES := $(sort $(ZSTD_DECOMPRESS_FILES))
45 ZSTD_FILES := $(ZSTDDECOMP_FILES) $(ZSTDCOMMON_FILES) $(ZSTDCOMP_FILES)
46 ZDICT_FILES := $(sort $(ZSTD_DICTBUILDER_FILES))
48 ZSTD_F1 := $(sort $(wildcard $(ZSTD_FILES)))
49 ZSTD_OBJ1 := $(subst $(ZSTDDIR)/common/,zstdm_,$(ZSTD_F1))
50 ZSTD_OBJ2 := $(subst $(ZSTDDIR)/compress/,zstdc_,$(ZSTD_OBJ1))
51 ZSTD_OBJ3 := $(subst $(ZSTDDIR)/decompress/,zstdd_,$(ZSTD_OBJ2))
52 ZSTD_OBJ4 := $(ZSTD_OBJ3:.c=.o)
53 ZSTD_OBJECTS := $(ZSTD_OBJ4:.S=.o)
55 ZSTDMT_OBJ1 := $(subst $(ZSTDDIR)/common/,zstdmt_m_,$(ZSTD_F1))
56 ZSTDMT_OBJ2 := $(subst $(ZSTDDIR)/compress/,zstdmt_c_,$(ZSTDMT_OBJ1))
57 ZSTDMT_OBJ3 := $(subst $(ZSTDDIR)/decompress/,zstdmt_d_,$(ZSTDMT_OBJ2))
58 ZSTDMT_OBJ4 := $(ZSTDMT_OBJ3:.c=.o)
59 ZSTDMT_OBJECTS := $(ZSTDMT_OBJ4:.S=.o)
61 # Define *.exe as extension for Windows systems
62 ifneq (,$(filter Windows%,$(OS)))
64 MULTITHREAD_CPP = -DZSTD_MULTITHREAD
68 MULTITHREAD_CPP = -DZSTD_MULTITHREAD
69 MULTITHREAD_LD = -pthread
71 MULTITHREAD = $(MULTITHREAD_CPP) $(MULTITHREAD_LD)
74 ZSTREAM_TESTTIME ?= -T90s
76 ZSTDRTTEST = --test-large-data
77 DECODECORPUS_TESTTIME ?= -T30
83 all: fullbench fuzzer zstreamtest paramgrill datagen decodecorpus roundTripCrash poolTests
86 all32: fullbench32 fuzzer32 zstreamtest32
89 allnothread: MULTITHREAD_CPP=
90 allnothread: MULTITHREAD_LD=
91 allnothread: fullbench fuzzer paramgrill datagen decodecorpus
93 # note : broken : requires symbols unavailable from dynamic library
95 dll: fuzzer-dll zstreamtest-dll
97 .PHONY: zstd zstd32 zstd-nolegacy # only external makefile knows how to build or update them
98 zstd zstd32 zstd-nolegacy zstd-dll:
99 $(MAKE) -C $(PRGDIR) $@ MOREFLAGS+="$(DEBUGFLAGS)"
103 $(MAKE) -C $(ZSTDDIR) libzstd MOREFLAGS+="$(DEBUGFLAGS)"
106 %-dll : LDFLAGS += -L$(ZSTDDIR) -lzstd
108 $(ZSTDDIR)/libzstd.a :
109 $(MAKE) -C $(ZSTDDIR) libzstd.a
111 zstdm_%.o : $(ZSTDDIR)/common/%.c
112 $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
114 zstdc_%.o : $(ZSTDDIR)/compress/%.c
115 $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
117 zstdd_%.o : $(ZSTDDIR)/decompress/%.c
118 $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
120 zstdd_%.o : $(ZSTDDIR)/decompress/%.S
121 $(CC) -c $(CPPFLAGS) $(ASFLAGS) $< -o $@
123 zstdmt%.o : CPPFLAGS += $(MULTITHREAD_CPP)
125 zstdmt_m_%.o : $(ZSTDDIR)/common/%.c
126 $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
128 zstdmt_c_%.o : $(ZSTDDIR)/compress/%.c
129 $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
131 zstdmt_d_%.o : $(ZSTDDIR)/decompress/%.c
132 $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
134 zstdmt_d_%.o : $(ZSTDDIR)/decompress/%.S
135 $(CC) -c $(CPPFLAGS) $(ASFLAGS) $< -o $@
137 FULLBENCHS := fullbench fullbench32
138 CLEAN += $(FULLBENCHS)
139 fullbench32: CPPFLAGS += -m32
140 $(FULLBENCHS) : CPPFLAGS += $(MULTITHREAD_CPP) -Wno-deprecated-declarations
141 $(FULLBENCHS) : LDFLAGS += $(MULTITHREAD_LD)
142 $(FULLBENCHS) : DEBUGFLAGS = -DNDEBUG # turn off assert() for speed measurements
143 $(FULLBENCHS) : $(ZSTD_FILES)
144 $(FULLBENCHS) : $(PRGDIR)/datagen.c $(PRGDIR)/util.c $(PRGDIR)/timefn.c $(PRGDIR)/benchfn.c fullbench.c
145 $(LINK.c) $^ -o $@$(EXT)
147 CLEAN += fullbench-lib
148 fullbench-lib : CPPFLAGS += -DXXH_NAMESPACE=ZSTD_
149 fullbench-lib : $(PRGDIR)/datagen.c $(PRGDIR)/util.c $(PRGDIR)/timefn.c $(PRGDIR)/benchfn.c $(ZSTDDIR)/libzstd.a fullbench.c
150 $(LINK.c) $^ -o $@$(EXT)
152 # note : broken : requires symbols unavailable from dynamic library
153 fullbench-dll: $(PRGDIR)/datagen.c $(PRGDIR)/util.c $(PRGDIR)/benchfn.c $(PRGDIR)/timefn.c fullbench.c
154 # $(CC) $(FLAGS) $(filter %.c,$^) -o $@$(EXT) -DZSTD_DLL_IMPORT=1 $(ZSTDDIR)/dll/libzstd.dll
155 $(LINK.c) $^ $(LDLIBS) -o $@$(EXT)
157 CLEAN += fuzzer fuzzer32
158 fuzzer : CPPFLAGS += $(MULTITHREAD_CPP) -Wno-deprecated-declarations
159 fuzzer : LDFLAGS += $(MULTITHREAD_LD)
160 fuzzer : $(ZSTDMT_OBJECTS)
161 fuzzer fuzzer32 : $(ZDICT_FILES) $(PRGDIR)/util.c $(PRGDIR)/timefn.c $(PRGDIR)/datagen.c fuzzer.c
163 fuzzer32 : CFLAGS += -m32 $(MULTITHREAD)
164 fuzzer32 : $(ZSTD_FILES)
165 $(LINK.c) $^ -o $@$(EXT)
167 # note : broken : requires symbols unavailable from dynamic library
168 fuzzer-dll : $(ZSTDDIR)/common/xxhash.c $(PRGDIR)/util.c $(PRGDIR)/timefn.c $(PRGDIR)/datagen.c fuzzer.c
169 $(CC) $(CPPFLAGS) $(CFLAGS) $(filter %.c,$^) $(LDFLAGS) -o $@$(EXT)
171 CLEAN += zstreamtest zstreamtest32
172 ZSTREAM_LOCAL_FILES := $(PRGDIR)/datagen.c $(PRGDIR)/util.c $(PRGDIR)/timefn.c seqgen.c zstreamtest.c external_matchfinder.c
173 ZSTREAM_PROPER_FILES := $(ZDICT_FILES) $(ZSTREAM_LOCAL_FILES)
174 ZSTREAMFILES := $(ZSTD_FILES) $(ZSTREAM_PROPER_FILES)
175 zstreamtest32 : CFLAGS += -m32
176 zstreamtest zstreamtest32 : CPPFLAGS += $(MULTITHREAD_CPP)
177 zstreamtest zstreamtest32 : LDFLAGS += $(MULTITHREAD_LD)
178 zstreamtest : $(ZSTDMT_OBJECTS) $(ZSTREAM_PROPER_FILES)
179 zstreamtest32 : $(ZSTREAMFILES)
180 zstreamtest zstreamtest32 :
181 $(LINK.c) $^ -o $@$(EXT)
183 CLEAN += zstreamtest_asan
184 zstreamtest_asan : CFLAGS += -fsanitize=address
185 zstreamtest_asan : $(ZSTREAMFILES)
186 $(LINK.c) $(MULTITHREAD) $^ -o $@$(EXT)
188 CLEAN += zstreamtest_tsan
189 zstreamtest_tsan : CFLAGS += -fsanitize=thread
190 zstreamtest_tsan : $(ZSTREAMFILES)
191 $(LINK.c) $(MULTITHREAD) $^ -o $@$(EXT)
193 CLEAN += zstreamtest_ubsan
194 zstreamtest_ubsan : CFLAGS += -fsanitize=undefined
195 zstreamtest_ubsan : $(ZSTREAMFILES)
196 $(LINK.c) $(MULTITHREAD) $^ -o $@$(EXT)
198 # note : broken : requires symbols unavailable from dynamic library
199 zstreamtest-dll : $(ZSTDDIR)/common/xxhash.c # xxh symbols not exposed from dll
200 zstreamtest-dll : $(ZSTREAM_LOCAL_FILES)
201 $(CC) $(CPPFLAGS) $(CFLAGS) $(filter %.c,$^) $(LDFLAGS) -o $@$(EXT)
204 paramgrill : DEBUGFLAGS = # turn off debug for speed measurements
205 paramgrill : LDLIBS += -lm
206 paramgrill : $(ZSTD_FILES) $(PRGDIR)/util.c $(PRGDIR)/timefn.c $(PRGDIR)/benchfn.c $(PRGDIR)/benchzstd.c $(PRGDIR)/datagen.c paramgrill.c
209 datagen : $(PRGDIR)/datagen.c datagencli.c
210 $(LINK.c) $^ -o $@$(EXT)
212 CLEAN += roundTripCrash
213 roundTripCrash: CFLAGS += $(MULTITHREAD)
214 roundTripCrash : $(ZSTD_OBJECTS) roundTripCrash.c
217 longmatch : $(ZSTD_OBJECTS) longmatch.c
220 bigdict: CFLAGS += $(MULTITHREAD)
221 bigdict: $(ZSTDMT_OBJECTS) $(PRGDIR)/datagen.c bigdict.c
223 CLEAN += invalidDictionaries
224 invalidDictionaries : $(ZSTD_OBJECTS) invalidDictionaries.c
227 legacy : CPPFLAGS += -I$(ZSTDDIR)/legacy -UZSTD_LEGACY_SUPPORT -DZSTD_LEGACY_SUPPORT=4
228 legacy : $(ZSTD_FILES) $(sort $(wildcard $(ZSTDDIR)/legacy/*.c)) legacy.c
230 CLEAN += decodecorpus
231 decodecorpus : LDLIBS += -lm
232 decodecorpus : $(filter-out zstdc_zstd_compress.o, $(ZSTD_OBJECTS)) $(ZDICT_FILES) $(PRGDIR)/util.c $(PRGDIR)/timefn.c decodecorpus.c
235 poolTests : $(PRGDIR)/util.c $(PRGDIR)/timefn.c poolTests.c $(ZSTDDIR)/common/pool.c $(ZSTDDIR)/common/threading.c $(ZSTDDIR)/common/zstd_common.c $(ZSTDDIR)/common/error_private.c
236 $(LINK.c) $(MULTITHREAD) $^ -o $@$(EXT)
240 $(PYTHON) test-zstd-versions.py
242 .PHONY: automated_benchmarking
243 automated_benchmarking: clean
244 $(PYTHON) automated_benchmarking.py
246 # make checkTag : check that release tag corresponds to release version
248 checkTag.o : $(ZSTDDIR)/zstd.h
252 $(MAKE) -C $(ZSTDDIR) clean
253 $(MAKE) -C $(PRGDIR) clean
254 $(RM) -fR $(TESTARTEFACT)
255 $(RM) -rf tmp* # some test directories are named tmp*
256 $(RM) $(CLEAN) core *.o *.tmp result* *.gcda dictionary *.zst \
257 $(PRGDIR)/zstd$(EXT) $(PRGDIR)/zstd32$(EXT) \
258 fullbench-dll$(EXT) fuzzer-dll$(EXT) zstreamtest-dll$(EXT)
259 @echo Cleaning completed
262 #----------------------------------------------------------------------------------
263 # valgrind tests validated only for some posix platforms
264 #----------------------------------------------------------------------------------
265 UNAME := $(shell uname)
266 ifneq (,$(filter $(UNAME),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS AIX))
269 .PHONY: test-valgrind
270 test-valgrind: VALGRIND = valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1
271 test-valgrind: zstd datagen fuzzer fullbench
272 @echo "\n ---- valgrind tests : memory analyzer ----"
273 $(VALGRIND) ./datagen -g50M > $(VOID)
274 $(VALGRIND) $(PRGDIR)/zstd ; if [ $$? -eq 0 ] ; then echo "zstd without argument should have failed"; false; fi
275 ./datagen -g80 | $(VALGRIND) $(PRGDIR)/zstd - -c > $(VOID)
276 ./datagen -g16KB | $(VALGRIND) $(PRGDIR)/zstd -vf - -c > $(VOID)
277 ./datagen -g2930KB | $(VALGRIND) $(PRGDIR)/zstd -5 -vf - -o tmp
278 $(VALGRIND) $(PRGDIR)/zstd -vdf tmp -c > $(VOID)
279 ./datagen -g64MB | $(VALGRIND) $(PRGDIR)/zstd -vf - -c > $(VOID)
281 $(VALGRIND) ./fuzzer -T1mn -t1
282 $(VALGRIND) ./fullbench -i1
286 ifneq (,$(filter MINGW% MSYS%,$(UNAME)))
291 #-----------------------------------------------------------------------------
292 # make tests validated only for below targets
293 #-----------------------------------------------------------------------------
294 ifneq (,$(filter $(HOST_OS),MSYS POSIX))
297 ifneq (,$(filter $(UNAME),SunOS))
303 @$(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
306 shortest: ZSTDRTTEST= # remove long tests
313 fuzztest: test-fuzzer test-zstream test-decodecorpus
316 test: test-zstd test-fullbench test-fuzzer test-zstream test-invalidDictionaries test-legacy test-decodecorpus test-cli-tests
322 test32: test-zstd32 test-fullbench32 test-fuzzer32 test-zstream32
325 test-all: test test32 test-decodecorpus-cli
327 .PHONY: test-zstd test-zstd32 test-zstd-nolegacy
328 test-zstd: ZSTD = $(PRGDIR)/zstd
331 .PHONY: test-zstd-dll
332 test-zstd-dll: ZSTD = $(PRGDIR)/zstd
333 test-zstd-dll: zstd-dll
335 test-zstd32: ZSTD = $(PRGDIR)/zstd32
338 test-zstd-nolegacy: ZSTD = $(PRGDIR)/zstd-nolegacy
339 test-zstd-nolegacy: zstd-nolegacy
341 test-zstd test-zstd32 test-zstd-nolegacy test-zstd-dll: datagen
343 EXE_PREFIX="$(QEMU_SYS)" ZSTD_BIN="$(ZSTD)" DATAGEN_BIN=./datagen ./playTests.sh $(ZSTDRTTEST)
345 .PHONY: test-cli-tests
346 test-cli-tests: ZSTD = $(PRGDIR)/zstd
347 test-cli-tests: zstd datagen
349 ./cli-tests/run.py --exec-prefix="$(QEMU_SYS)" --zstd="$(ZSTD)" --datagen=./datagen
351 .PHONY: test-fullbench
352 test-fullbench: fullbench datagen
353 $(QEMU_SYS) ./fullbench -i1
354 $(QEMU_SYS) ./fullbench -i1 -P0
356 .PHONY: test-fullbench32
357 test-fullbench32: fullbench32 datagen
358 $(QEMU_SYS) ./fullbench32 -i1
359 $(QEMU_SYS) ./fullbench32 -i1 -P0
363 $(QEMU_SYS) ./fuzzer -v $(FUZZERTEST) $(FUZZER_FLAGS)
365 # Note : this test presumes `fuzzer` will be built
366 .PHONY: test-fuzzer-stackmode
367 test-fuzzer-stackmode: MOREFLAGS += -DZSTD_HEAPMODE=0
368 test-fuzzer-stackmode: test-fuzzer
370 .PHONY: test-fuzzer32
371 test-fuzzer32: fuzzer32
372 $(QEMU_SYS) ./fuzzer32 -v $(FUZZERTEST) $(FUZZER_FLAGS)
375 test-zstream: zstreamtest
376 $(QEMU_SYS) ./zstreamtest -v $(ZSTREAM_TESTTIME) $(FUZZER_FLAGS)
377 $(QEMU_SYS) ./zstreamtest --newapi -t1 $(ZSTREAM_TESTTIME) $(FUZZER_FLAGS)
379 test-zstream32: zstreamtest32
380 $(QEMU_SYS) ./zstreamtest32 -v $(ZSTREAM_TESTTIME) $(FUZZER_FLAGS)
382 test-longmatch: longmatch
383 $(QEMU_SYS) ./longmatch
385 test-bigdict: bigdict
386 $(QEMU_SYS) ./bigdict
388 test-invalidDictionaries: invalidDictionaries
389 $(QEMU_SYS) ./invalidDictionaries
394 test-decodecorpus: decodecorpus
395 $(QEMU_SYS) ./decodecorpus -t $(DECODECORPUS_TESTTIME)
397 test-decodecorpus-cli: decodecorpus
398 @echo "\n ---- decodecorpus basic cli tests ----"
400 ./decodecorpus -n5 -otestdir -ptestdir
402 $(ZSTD) -d z000000.zst -o tmp0 && \
403 $(ZSTD) -d z000001.zst -o tmp1 && \
404 $(ZSTD) -d z000002.zst -o tmp2 && \
405 $(ZSTD) -d z000003.zst -o tmp3 && \
406 $(ZSTD) -d z000004.zst -o tmp4 && \
407 diff z000000 tmp0 && \
408 diff z000001 tmp1 && \
409 diff z000002 tmp2 && \
410 diff z000003 tmp3 && \
411 diff z000004 tmp4 && \
414 @echo "\n ---- decodecorpus dictionary cli tests ----"
415 ./decodecorpus -n5 -otestdir -ptestdir --use-dict=1MB
417 $(ZSTD) -d z000000.zst -D dictionary -o tmp0 && \
418 $(ZSTD) -d z000001.zst -D dictionary -o tmp1 && \
419 $(ZSTD) -d z000002.zst -D dictionary -o tmp2 && \
420 $(ZSTD) -d z000003.zst -D dictionary -o tmp3 && \
421 $(ZSTD) -d z000004.zst -D dictionary -o tmp4 && \
422 diff z000000 tmp0 && \
423 diff z000001 tmp1 && \
424 diff z000002 tmp2 && \
425 diff z000003 tmp3 && \
426 diff z000004 tmp4 && \
431 $(QEMU_SYS) ./poolTests
433 test-lz4: ZSTD = LD_LIBRARY_PATH=/usr/local/lib $(PRGDIR)/zstd
434 test-lz4: ZSTD_LZ4 = LD_LIBRARY_PATH=/usr/local/lib ./lz4
435 test-lz4: ZSTD_UNLZ4 = LD_LIBRARY_PATH=/usr/local/lib ./unlz4
436 test-lz4: zstd decodecorpus datagen
437 [ -f lz4 ] || ln -s $(PRGDIR)/zstd lz4
438 [ -f unlz4 ] || ln -s $(PRGDIR)/zstd unlz4
449 $(ZSTD) --format=lz4 < tmp | \
452 $(ZSTD_LZ4) < tmp | \
456 $(ZSTD) --format=lz4 < tmp | \
464 ./datagen -g384KB | $(ZSTD) --format=lz4 | $(ZSTD) -d > /dev/null