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
25
26DEBUGLEVEL ?= 1
27DEBUGFLAGS  = -g -DDEBUGLEVEL=$(DEBUGLEVEL)
28CPPFLAGS   += -I$(ZSTDDIR) -I$(ZSTDDIR)/common -I$(ZSTDDIR)/compress \
29              -I$(ZSTDDIR)/dictBuilder -I$(ZSTDDIR)/deprecated -I$(PRGDIR)
30ifeq ($(OS),Windows_NT)   # MinGW assumed
31CPPFLAGS   += -D__USE_MINGW_ANSI_STDIO   # compatibility with %zu formatting
32endif
33CFLAGS     ?= -O3
34CFLAGS     += -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow                 \
35              -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
36              -Wstrict-prototypes -Wundef                                     \
37              -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings      \
38              -Wredundant-decls -Wmissing-prototypes
39CFLAGS     += $(DEBUGFLAGS) $(MOREFLAGS)
40FLAGS       = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
41
42
43ZSTDCOMMON_FILES := $(ZSTDDIR)/common/*.c
44ZSTDCOMP_FILES   := $(ZSTDDIR)/compress/*.c
45ZSTDDECOMP_FILES := $(ZSTDDIR)/decompress/*.c
46ZSTD_FILES  := $(ZSTDDECOMP_FILES) $(ZSTDCOMMON_FILES) $(ZSTDCOMP_FILES)
47ZBUFF_FILES := $(ZSTDDIR)/deprecated/*.c
48ZDICT_FILES := $(ZSTDDIR)/dictBuilder/*.c
49
50ZSTD_F1 := $(wildcard $(ZSTD_FILES))
51ZSTD_OBJ1 := $(subst $(ZSTDDIR)/common/,zstdm_,$(ZSTD_F1))
52ZSTD_OBJ2 := $(subst $(ZSTDDIR)/compress/,zstdc_,$(ZSTD_OBJ1))
53ZSTD_OBJ3 := $(subst $(ZSTDDIR)/decompress/,zstdd_,$(ZSTD_OBJ2))
54ZSTD_OBJECTS := $(ZSTD_OBJ3:.c=.o)
55
56ZSTDMT_OBJ1 := $(subst $(ZSTDDIR)/common/,zstdmt_m_,$(ZSTD_F1))
57ZSTDMT_OBJ2 := $(subst $(ZSTDDIR)/compress/,zstdmt_c_,$(ZSTDMT_OBJ1))
58ZSTDMT_OBJ3 := $(subst $(ZSTDDIR)/decompress/,zstdmt_d_,$(ZSTDMT_OBJ2))
59ZSTDMT_OBJECTS := $(ZSTDMT_OBJ3:.c=.o)
60
61# Define *.exe as extension for Windows systems
62ifneq (,$(filter Windows%,$(OS)))
63EXT =.exe
64MULTITHREAD_CPP = -DZSTD_MULTITHREAD
65MULTITHREAD_LD  =
66else
67EXT =
68MULTITHREAD_CPP = -DZSTD_MULTITHREAD
69MULTITHREAD_LD  = -pthread
70endif
71MULTITHREAD = $(MULTITHREAD_CPP) $(MULTITHREAD_LD)
72
73VOID = /dev/null
74ZSTREAM_TESTTIME ?= -T90s
75FUZZERTEST ?= -T200s
76ZSTDRTTEST = --test-large-data
77DECODECORPUS_TESTTIME ?= -T30
78
79.PHONY: default all all32 allnothread dll clean test test32 test-all versionsTest
80
81default: fullbench
82	@echo $(ZSTDMT_OBJECTS)
83
84all: fullbench fuzzer zstreamtest paramgrill datagen decodecorpus roundTripCrash \
85     fullbench-lib poolTests
86
87all32: fullbench32 fuzzer32 zstreamtest32
88
89allnothread: MULTITHREAD_CPP=
90allnothread: MULTITHREAD_LD=
91allnothread: fullbench fuzzer paramgrill datagen decodecorpus
92
93dll: fuzzer-dll zstreamtest-dll
94
95PHONY: zstd zstd32 zstd-nolegacy  # must be phony, only external makefile knows how to build them, or if they need an update
96zstd zstd32 zstd-nolegacy:
97	$(MAKE) -C $(PRGDIR) $@ MOREFLAGS+="$(DEBUGFLAGS)"
98
99gzstd:
100	$(MAKE) -C $(PRGDIR) zstd HAVE_ZLIB=1 MOREFLAGS+="$(DEBUGFLAGS)"
101
102.PHONY: zstd-dll
103zstd-dll :
104	$(MAKE) -C $(ZSTDDIR) libzstd
105
106.PHONY: zstd-staticLib
107zstd-staticLib :
108	$(MAKE) -C $(ZSTDDIR) libzstd.a
109
110zstdm_%.o : $(ZSTDDIR)/common/%.c
111	$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
112
113zstdc_%.o : $(ZSTDDIR)/compress/%.c
114	$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
115
116zstdd_%.o : $(ZSTDDIR)/decompress/%.c
117	$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
118
119zstdmt%.o : CPPFLAGS += $(MULTITHREAD_CPP)
120
121zstdmt_m_%.o : $(ZSTDDIR)/common/%.c
122	$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
123
124zstdmt_c_%.o : $(ZSTDDIR)/compress/%.c
125	$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
126
127zstdmt_d_%.o : $(ZSTDDIR)/decompress/%.c
128	$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
129
130fullbench32: CPPFLAGS += -m32
131fullbench fullbench32 : CPPFLAGS += $(MULTITHREAD_CPP)
132fullbench fullbench32 : LDFLAGS += $(MULTITHREAD_LD)
133fullbench fullbench32 : DEBUGFLAGS = -DNDEBUG  # turn off assert() for speed measurements
134fullbench fullbench32 : $(ZSTD_FILES)
135fullbench fullbench32 : $(PRGDIR)/datagen.c $(PRGDIR)/util.c $(PRGDIR)/timefn.c $(PRGDIR)/benchfn.c fullbench.c
136	$(CC) $(FLAGS) $^ -o $@$(EXT)
137
138fullbench-lib : CPPFLAGS += -DXXH_NAMESPACE=ZSTD_
139fullbench-lib : zstd-staticLib
140fullbench-lib : $(PRGDIR)/datagen.c $(PRGDIR)/util.c $(PRGDIR)/timefn.c $(PRGDIR)/benchfn.c fullbench.c
141	$(CC) $(FLAGS) $(filter %.c,$^) -o $@$(EXT) $(ZSTDDIR)/libzstd.a
142
143# note : broken : requires unavailable symbols
144fullbench-dll : zstd-dll
145fullbench-dll : LDFLAGS+= -L$(ZSTDDIR) -lzstd
146fullbench-dll: $(PRGDIR)/datagen.c $(PRGDIR)/util.c $(PRGDIR)/benchfn.c $(PRGDIR)/timefn.c fullbench.c
147#	$(CC) $(FLAGS) $(filter %.c,$^) -o $@$(EXT) -DZSTD_DLL_IMPORT=1 $(ZSTDDIR)/dll/libzstd.dll
148	$(CC) $(FLAGS) $(filter %.c,$^) -o $@$(EXT)
149
150fuzzer  : CPPFLAGS += $(MULTITHREAD_CPP)
151fuzzer  : LDFLAGS += $(MULTITHREAD_LD)
152fuzzer32: CFLAGS += -m32
153fuzzer  : $(ZSTDMT_OBJECTS)
154fuzzer32: $(ZSTD_FILES)
155fuzzer fuzzer32 : $(ZDICT_FILES) $(PRGDIR)/util.c $(PRGDIR)/timefn.c $(PRGDIR)/datagen.c fuzzer.c
156	$(CC) $(FLAGS) $^ -o $@$(EXT)
157
158fuzzer-dll : zstd-dll
159fuzzer-dll : LDFLAGS+= -L$(ZSTDDIR) -lzstd
160fuzzer-dll : $(ZSTDDIR)/common/xxhash.c $(PRGDIR)/util.c $(PRGDIR)/timefn.c $(PRGDIR)/datagen.c fuzzer.c
161	$(CC) $(CPPFLAGS) $(CFLAGS) $(filter %.c,$^) $(LDFLAGS) -o $@$(EXT)
162
163zbufftest : CPPFLAGS += -I$(ZSTDDIR)/deprecated
164zbufftest : CFLAGS += -Wno-deprecated-declarations   # required to silence deprecation warnings
165zbufftest : $(ZSTD_OBJECTS) $(ZBUFF_FILES) $(PRGDIR)/util.c $(PRGDIR)/timefn.c $(PRGDIR)/datagen.c zbufftest.c
166	$(CC) $(FLAGS) $^ -o $@$(EXT)
167
168zbufftest32 : CPPFLAGS += -I$(ZSTDDIR)/deprecated
169zbufftest32 : CFLAGS += -Wno-deprecated-declarations -m32
170zbufftest32 : $(ZSTD_FILES) $(ZBUFF_FILES) $(PRGDIR)/util.c $(PRGDIR)/timefn.c $(PRGDIR)/datagen.c zbufftest.c
171	$(CC) $(FLAGS) $^ -o $@$(EXT)
172
173zbufftest-dll : zstd-dll
174zbufftest-dll : CPPFLAGS += -I$(ZSTDDIR)/deprecated
175zbufftest-dll : CFLAGS += -Wno-deprecated-declarations   # required to silence deprecation warnings
176zbufftest-dll : LDFLAGS+= -L$(ZSTDDIR) -lzstd
177zbufftest-dll : $(ZSTDDIR)/common/xxhash.c $(PRGDIR)/util.c $(PRGDIR)/timefn.c $(PRGDIR)/datagen.c zbufftest.c
178	$(CC) $(CPPFLAGS) $(CFLAGS) $(filter %.c,$^) $(LDFLAGS) -o $@$(EXT)
179
180ZSTREAM_LOCAL_FILES := $(PRGDIR)/datagen.c $(PRGDIR)/util.c $(PRGDIR)/timefn.c seqgen.c zstreamtest.c
181ZSTREAM_PROPER_FILES := $(ZDICT_FILES) $(ZSTREAM_LOCAL_FILES)
182ZSTREAMFILES := $(ZSTD_FILES) $(ZSTREAM_PROPER_FILES)
183zstreamtest32 : CFLAGS += -m32
184zstreamtest zstreamtest32 : CPPFLAGS += $(MULTITHREAD_CPP)
185zstreamtest zstreamtest32 : LDFLAGS += $(MULTITHREAD_LD)
186zstreamtest : $(ZSTDMT_OBJECTS) $(ZSTREAM_PROPER_FILES)
187zstreamtest32 : $(ZSTREAMFILES)
188zstreamtest zstreamtest32 :
189	$(CC) $(FLAGS) $^ -o $@$(EXT)
190
191zstreamtest_asan : CFLAGS += -fsanitize=address
192zstreamtest_asan : $(ZSTREAMFILES)
193	$(CC) $(FLAGS) $(MULTITHREAD) $^ -o $@$(EXT)
194
195zstreamtest_tsan : CFLAGS += -fsanitize=thread
196zstreamtest_tsan : $(ZSTREAMFILES)
197	$(CC) $(FLAGS) $(MULTITHREAD) $^ -o $@$(EXT)
198
199zstreamtest-dll : zstd-dll
200zstreamtest-dll : LDFLAGS+= -L$(ZSTDDIR) -lzstd
201zstreamtest-dll : $(ZSTDDIR)/common/xxhash.c  # xxh symbols not exposed from dll
202zstreamtest-dll : $(ZSTREAM_LOCAL_FILES)
203	$(CC) $(CPPFLAGS) $(CFLAGS) $(filter %.c,$^) $(LDFLAGS) -o $@$(EXT)
204
205paramgrill : DEBUGFLAGS =  # turn off assert() by default for speed measurements
206paramgrill : $(ZSTD_FILES) $(PRGDIR)/util.c $(PRGDIR)/timefn.c $(PRGDIR)/benchfn.c $(PRGDIR)/benchzstd.c $(PRGDIR)/datagen.c paramgrill.c
207	$(CC) $(FLAGS) $^ -lm -o $@$(EXT)
208
209datagen : $(PRGDIR)/datagen.c datagencli.c
210	$(CC) $(FLAGS) $^ -o $@$(EXT)
211
212roundTripCrash : $(ZSTD_OBJECTS) roundTripCrash.c
213	$(CC) $(FLAGS) $(MULTITHREAD) $^ -o $@$(EXT)
214
215longmatch  : $(ZSTD_OBJECTS) longmatch.c
216	$(CC) $(FLAGS) $^ -o $@$(EXT)
217
218bigdict: $(ZSTDMT_OBJECTS) $(PRGDIR)/datagen.c bigdict.c
219	$(CC) $(FLAGS) $(MULTITHREAD) $^ -o $@$(EXT)
220
221invalidDictionaries : $(ZSTD_OBJECTS) invalidDictionaries.c
222	$(CC) $(FLAGS) $^ -o $@$(EXT)
223
224legacy : CPPFLAGS += -I$(ZSTDDIR)/legacy -DZSTD_LEGACY_SUPPORT=4
225legacy : $(ZSTD_FILES) $(wildcard $(ZSTDDIR)/legacy/*.c) legacy.c
226	$(CC) $(FLAGS) $^ -o $@$(EXT)
227
228decodecorpus : $(filter-out zstdc_zstd_compress.o, $(ZSTD_OBJECTS)) $(ZDICT_FILES) $(PRGDIR)/util.c $(PRGDIR)/timefn.c decodecorpus.c
229	$(CC) $(FLAGS) $^ -o $@$(EXT) -lm
230
231symbols  : symbols.c zstd-dll
232ifneq (,$(filter Windows%,$(OS)))
233	cp $(ZSTDDIR)/dll/libzstd.dll .
234	$(CC) $(FLAGS) $< -o $@$(EXT) -DZSTD_DLL_IMPORT=1 libzstd.dll
235else
236	$(CC) $(FLAGS) $< -o $@$(EXT) -Wl,-rpath=$(ZSTDDIR) $(ZSTDDIR)/libzstd.so   # broken on Mac
237endif
238
239poolTests : $(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
240	$(CC) $(FLAGS) $(MULTITHREAD) $^ -o $@$(EXT)
241
242.PHONY: versionsTest
243versionsTest: clean
244	$(PYTHON) test-zstd-versions.py
245
246checkTag: checkTag.c $(ZSTDDIR)/zstd.h
247	$(CC) $(FLAGS) $< -o $@$(EXT)
248
249clean:
250	$(MAKE) -C $(ZSTDDIR) clean
251	$(MAKE) -C $(PRGDIR) clean
252	@$(RM) -fR $(TESTARTEFACT)
253	@$(RM) -f core *.o tmp* *.tmp result* *.gcda dictionary *.zst \
254        $(PRGDIR)/zstd$(EXT) $(PRGDIR)/zstd32$(EXT) \
255        fullbench$(EXT) fullbench32$(EXT) \
256        fullbench-lib$(EXT) fullbench-dll$(EXT) \
257        fuzzer$(EXT) fuzzer32$(EXT) zbufftest$(EXT) zbufftest32$(EXT) \
258        fuzzer-dll$(EXT) zstreamtest-dll$(EXT) zbufftest-dll$(EXT) \
259        zstreamtest$(EXT) zstreamtest32$(EXT) \
260        datagen$(EXT) paramgrill$(EXT) roundTripCrash$(EXT) longmatch$(EXT) \
261        symbols$(EXT) invalidDictionaries$(EXT) legacy$(EXT) poolTests$(EXT) \
262        decodecorpus$(EXT) checkTag$(EXT) bigdict$(EXT)
263	@echo Cleaning completed
264
265
266#----------------------------------------------------------------------------------
267#make valgrindTest is validated only for Linux, macOS, BSD, Hurd and Solaris targets
268#----------------------------------------------------------------------------------
269ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS))
270HOST_OS = POSIX
271
272valgrindTest: VALGRIND = valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1
273valgrindTest: zstd datagen fuzzer fullbench
274	@echo "\n ---- valgrind tests : memory analyzer ----"
275	$(VALGRIND) ./datagen -g50M > $(VOID)
276	$(VALGRIND) $(PRGDIR)/zstd ; if [ $$? -eq 0 ] ; then echo "zstd without argument should have failed"; false; fi
277	./datagen -g80 | $(VALGRIND) $(PRGDIR)/zstd - -c > $(VOID)
278	./datagen -g16KB | $(VALGRIND) $(PRGDIR)/zstd -vf - -c > $(VOID)
279	./datagen -g2930KB | $(VALGRIND) $(PRGDIR)/zstd -5 -vf - -o tmp
280	$(VALGRIND) $(PRGDIR)/zstd -vdf tmp -c > $(VOID)
281	./datagen -g64MB | $(VALGRIND) $(PRGDIR)/zstd -vf - -c > $(VOID)
282	@rm tmp
283	$(VALGRIND) ./fuzzer -T1mn -t1
284	$(VALGRIND) ./fullbench -i1
285
286endif
287
288
289ifneq (,$(filter MSYS%,$(shell uname)))
290HOST_OS = MSYS
291endif
292
293
294#-----------------------------------------------------------------------------
295# make tests validated only for below targets
296#-----------------------------------------------------------------------------
297ifneq (,$(filter $(HOST_OS),MSYS POSIX))
298
299DIFF:=diff
300ifneq (,$(filter $(shell uname),SunOS))
301DIFF:=gdiff
302endif
303
304.PHONY: list
305list:
306	@$(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
307
308.PHONY: shortest
309shortest: ZSTDRTTEST=
310shortest: test-zstd
311
312.PHONY: fuzztest
313fuzztest: test-fuzzer test-zstream test-decodecorpus
314
315.PHONY: test
316test: test-zstd test-fullbench test-fuzzer test-zstream test-invalidDictionaries test-legacy test-decodecorpus
317ifeq ($(QEMU_SYS),)
318test: test-pool
319endif
320
321test32: test-zstd32 test-fullbench32 test-fuzzer32 test-zstream32
322
323test-all: test test32 valgrindTest test-decodecorpus-cli
324
325
326.PHONY: test-zstd test-zstd32 test-zstd-nolegacy test-zstdgrep
327test-zstd: ZSTD = $(PRGDIR)/zstd
328test-zstd: zstd
329
330test-zstd32: ZSTD = $(PRGDIR)/zstd32
331test-zstd32: zstd32
332
333test-zstd-nolegacy: ZSTD = $(PRGDIR)/zstd-nolegacy
334test-zstd-nolegacy: zstd-nolegacy
335
336test-zstd test-zstd32 test-zstd-nolegacy: datagen
337	file $(ZSTD)
338	ZSTD="$(QEMU_SYS) $(ZSTD)" ./playTests.sh $(ZSTDRTTEST)
339
340
341test-gzstd: gzstd
342	$(PRGDIR)/zstd -f README.md test-zstd-speed.py
343	gzip -f README.md test-zstd-speed.py
344	cat README.md.zst test-zstd-speed.py.gz >zstd_gz.zst
345	cat README.md.gz test-zstd-speed.py.zst >gz_zstd.gz
346	$(PRGDIR)/zstd -df README.md.gz -o README2.md
347	$(PRGDIR)/zstd -df README.md.gz test-zstd-speed.py.gz
348	$(PRGDIR)/zstd -df zstd_gz.zst gz_zstd.gz
349	$(DIFF) -q zstd_gz gz_zstd
350	echo Hello World ZSTD | $(PRGDIR)/zstd -c - >hello.zst
351	echo Hello World GZIP | gzip -c - >hello.gz
352	echo Hello World TEXT >hello.txt
353	cat hello.zst hello.gz hello.txt >hello_zst_gz_txt.gz
354	$(PRGDIR)/zstd -dcf hello.*
355	$(PRGDIR)/zstd -dcf - <hello_zst_gz_txt.gz
356	$(RM) *.gz *.zst README2.md gz_zstd zstd_gz hello.txt
357
358test-zstdgrep: gzstd
359	-[ -f /tmp/zstdcat ] || ln -s $(PWD)/$(PRGDIR)/zstd /tmp/zstdcat
360	echo a | $(PRGDIR)/zstd | env ZCAT=/tmp/zstdcat $(PRGDIR)/zstdgrep a
361	echo a | $(PRGDIR)/zstd | env ZCAT=/tmp/zstdcat $(PRGDIR)/zstdgrep b && return 1 || return 0
362	-echo 'hello world' > test.txt && $(PRGDIR)/zstd test.txt
363	env ZCAT=/tmp/zstdcat $(PRGDIR)/zstdgrep hello test.txt.zst
364	env ZCAT=/tmp/zstdcat $(PRGDIR)/zstdgrep weird test.txt.zst && return 1 || return 0
365	-echo 'hello' > pattern.txt
366	env ZCAT=/tmp/zstdcat $(PRGDIR)/zstdgrep -f pattern.txt test.txt.zst
367	$(RM) test.txt test.txt.zst pattern.txt
368
369test-fullbench: fullbench datagen
370	$(QEMU_SYS) ./fullbench -i1
371	$(QEMU_SYS) ./fullbench -i1 -P0
372
373test-fullbench32: fullbench32 datagen
374	$(QEMU_SYS) ./fullbench32 -i1
375	$(QEMU_SYS) ./fullbench32 -i1 -P0
376
377test-fuzzer: fuzzer
378	$(QEMU_SYS) ./fuzzer -v $(FUZZERTEST) $(FUZZER_FLAGS)
379
380test-fuzzer-stackmode: MOREFLAGS += -DZSTD_HEAPMODE=0
381test-fuzzer-stackmode: test-fuzzer
382
383test-fuzzer32: fuzzer32
384	$(QEMU_SYS) ./fuzzer32 -v $(FUZZERTEST) $(FUZZER_FLAGS)
385
386test-zbuff: zbufftest
387	$(QEMU_SYS) ./zbufftest $(ZSTREAM_TESTTIME)
388
389test-zbuff32: zbufftest32
390	$(QEMU_SYS) ./zbufftest32 $(ZSTREAM_TESTTIME)
391
392test-zstream: zstreamtest
393	$(QEMU_SYS) ./zstreamtest -v $(ZSTREAM_TESTTIME) $(FUZZER_FLAGS)
394	$(QEMU_SYS) ./zstreamtest --mt -t1 $(ZSTREAM_TESTTIME) $(FUZZER_FLAGS)
395	$(QEMU_SYS) ./zstreamtest --newapi -t1 $(ZSTREAM_TESTTIME) $(FUZZER_FLAGS)
396
397test-zstream32: zstreamtest32
398	$(QEMU_SYS) ./zstreamtest32 $(ZSTREAM_TESTTIME) $(FUZZER_FLAGS)
399
400test-longmatch: longmatch
401	$(QEMU_SYS) ./longmatch
402
403test-bigdict: bigdict
404	$(QEMU_SYS) ./bigdict
405
406test-invalidDictionaries: invalidDictionaries
407	$(QEMU_SYS) ./invalidDictionaries
408
409test-symbols: symbols
410	$(QEMU_SYS) ./symbols
411
412test-legacy: legacy
413	$(QEMU_SYS) ./legacy
414
415test-decodecorpus: decodecorpus
416	$(QEMU_SYS) ./decodecorpus -t $(DECODECORPUS_TESTTIME)
417
418test-decodecorpus-cli: decodecorpus
419	@echo "\n ---- decodecorpus basic cli tests ----"
420	@mkdir testdir
421	./decodecorpus -n5 -otestdir -ptestdir
422	@cd testdir && \
423	$(ZSTD) -d z000000.zst -o tmp0 && \
424	$(ZSTD) -d z000001.zst -o tmp1 && \
425	$(ZSTD) -d z000002.zst -o tmp2 && \
426	$(ZSTD) -d z000003.zst -o tmp3 && \
427	$(ZSTD) -d z000004.zst -o tmp4 && \
428	diff z000000 tmp0 && \
429	diff z000001 tmp1 && \
430	diff z000002 tmp2 && \
431	diff z000003 tmp3 && \
432	diff z000004 tmp4 && \
433	rm ./* && \
434	cd ..
435	@echo "\n ---- decodecorpus dictionary cli tests ----"
436	./decodecorpus -n5 -otestdir -ptestdir --use-dict=1MB
437	@cd testdir && \
438	$(ZSTD) -d z000000.zst -D dictionary -o tmp0 && \
439	$(ZSTD) -d z000001.zst -D dictionary -o tmp1 && \
440	$(ZSTD) -d z000002.zst -D dictionary -o tmp2 && \
441	$(ZSTD) -d z000003.zst -D dictionary -o tmp3 && \
442	$(ZSTD) -d z000004.zst -D dictionary -o tmp4 && \
443	diff z000000 tmp0 && \
444	diff z000001 tmp1 && \
445	diff z000002 tmp2 && \
446	diff z000003 tmp3 && \
447	diff z000004 tmp4 && \
448	cd ..
449	@rm -rf testdir
450
451test-pool: poolTests
452	$(QEMU_SYS) ./poolTests
453
454test-lz4: ZSTD = LD_LIBRARY_PATH=/usr/local/lib $(PRGDIR)/zstd
455test-lz4: ZSTD_LZ4 = LD_LIBRARY_PATH=/usr/local/lib ./lz4
456test-lz4: ZSTD_UNLZ4 = LD_LIBRARY_PATH=/usr/local/lib ./unlz4
457test-lz4: zstd decodecorpus datagen
458	[ -f lz4 ] || ln -s $(PRGDIR)/zstd lz4
459	[ -f unlz4 ] || ln -s $(PRGDIR)/zstd unlz4
460
461	./decodecorpus -ptmp
462	# lz4 -> zstd
463	lz4 < tmp | \
464	$(ZSTD) -d | \
465	cmp - tmp
466	lz4 < tmp | \
467	$(ZSTD_UNLZ4) | \
468	cmp - tmp
469	# zstd -> lz4
470	$(ZSTD) --format=lz4 < tmp | \
471	lz4 -d | \
472	cmp - tmp
473	$(ZSTD_LZ4) < tmp | \
474	lz4 -d | \
475	cmp - tmp
476	# zstd -> zstd
477	$(ZSTD) --format=lz4 < tmp | \
478	$(ZSTD) -d | \
479	cmp - tmp
480	# zstd -> zstd
481	$(ZSTD) < tmp | \
482	$(ZSTD) -d | \
483	cmp - tmp
484
485	./datagen -g384KB | $(ZSTD) --format=lz4 | $(ZSTD) -d > /dev/null
486
487	rm tmp lz4 unlz4
488
489endif
490