]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/zstd/tests/Makefile
Merge ^/head r317808 through r317970.
[FreeBSD/FreeBSD.git] / contrib / zstd / tests / Makefile
1 # ##########################################################################
2 # Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3 # All rights reserved.
4 #
5 # This Makefile is validated for Linux, macOS, *BSD, Hurd, Solaris, MSYS2 targets
6 #
7 # This source code is licensed under the BSD-style license found in the
8 # LICENSE file in the root directory of this source tree. An additional grant
9 # of patent rights can be found in the PATENTS file in the same directory.
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 # ##########################################################################
22
23 ZSTDDIR = ../lib
24 PRGDIR  = ../programs
25 PYTHON ?= python3
26 TESTARTEFACT := versionsTest namespaceTest
27
28
29 DEBUGFLAGS=-g -DZSTD_DEBUG=1
30 CPPFLAGS+= -I$(ZSTDDIR) -I$(ZSTDDIR)/common -I$(ZSTDDIR)/compress \
31            -I$(ZSTDDIR)/dictBuilder -I$(ZSTDDIR)/deprecated -I$(PRGDIR) \
32            $(DEBUGFLAG)
33 CFLAGS  ?= -O3
34 CFLAGS  += -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
35            -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
36            -Wstrict-prototypes -Wundef -Wformat-security
37 CFLAGS  += $(MOREFLAGS)
38 FLAGS    = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
39
40
41 ZSTDCOMMON_FILES := $(ZSTDDIR)/common/*.c
42 ZSTDCOMP_FILES   := $(ZSTDDIR)/compress/*.c
43 ZSTDDECOMP_FILES := $(ZSTDDIR)/decompress/*.c
44 ZSTD_FILES  := $(ZSTDDECOMP_FILES) $(ZSTDCOMMON_FILES) $(ZSTDCOMP_FILES)
45 ZBUFF_FILES := $(ZSTDDIR)/deprecated/*.c
46 ZDICT_FILES := $(ZSTDDIR)/dictBuilder/*.c
47
48 ZSTD_OBJ  := $(patsubst %.c,%.o, $(wildcard $(ZSTD_FILES)) )
49 ZBUFF_OBJ := $(patsubst %.c,%.o, $(wildcard $(ZBUFF_FILES)) )
50 ZDICT_OBJ := $(patsubst %.c,%.o, $(wildcard $(ZDICT_FILES)) )
51
52
53 # Define *.exe as extension for Windows systems
54 ifneq (,$(filter Windows%,$(OS)))
55 EXT =.exe
56 MULTITHREAD_CPP = -DZSTD_MULTITHREAD
57 MULTITHREAD_LD  =
58 else
59 EXT =
60 MULTITHREAD_CPP = -DZSTD_MULTITHREAD
61 MULTITHREAD_LD  = -pthread
62 endif
63 MULTITHREAD = $(MULTITHREAD_CPP) $(MULTITHREAD_LD)
64
65 VOID = /dev/null
66 ZSTREAM_TESTTIME ?= -T2mn
67 FUZZERTEST ?= -T5mn
68 ZSTDRTTEST = --test-large-data
69 DECODECORPUS_TESTTIME ?= -T30
70
71 .PHONY: default all all32 allnothread dll clean test test32 test-all namespaceTest versionsTest
72
73 default: fullbench
74
75 all: fullbench fuzzer zstreamtest paramgrill datagen zbufftest decodecorpus
76
77 all32: fullbench32 fuzzer32 zstreamtest32 zbufftest32
78
79 allnothread: fullbench fuzzer paramgrill datagen zbufftest decodecorpus
80
81 dll: fuzzer-dll zstreamtest-dll zbufftest-dll
82
83 zstd:
84         $(MAKE) -C $(PRGDIR) $@
85
86 zstd32:
87         $(MAKE) -C $(PRGDIR) $@
88
89 zstd-nolegacy:
90         $(MAKE) -C $(PRGDIR) $@
91
92 gzstd:
93         $(MAKE) -C $(PRGDIR) $@
94
95 fullbench  : $(ZSTD_FILES) $(PRGDIR)/datagen.c fullbench.c
96         $(CC)      $(FLAGS) $^ -o $@$(EXT)
97
98 fullbench32 : $(ZSTD_FILES) $(PRGDIR)/datagen.c fullbench.c
99         $(CC)  -m32  $(FLAGS) $^ -o $@$(EXT)
100
101 fullbench-lib: $(PRGDIR)/datagen.c fullbench.c
102         $(MAKE) -C $(ZSTDDIR) libzstd.a
103         $(CC) $(FLAGS) $^ -o $@$(EXT) $(ZSTDDIR)/libzstd.a
104
105 fullbench-dll: $(PRGDIR)/datagen.c fullbench.c
106         $(MAKE) -C $(ZSTDDIR) libzstd
107         $(CC) $(FLAGS) $^ -o $@$(EXT) -DZSTD_DLL_IMPORT=1 $(ZSTDDIR)/dll/libzstd.dll
108
109 fuzzer   : $(ZSTD_FILES) $(ZDICT_FILES) $(PRGDIR)/datagen.c fuzzer.c
110         $(CC)      $(FLAGS) $^ -o $@$(EXT)
111
112 fuzzer32 : $(ZSTD_FILES) $(ZDICT_FILES) $(PRGDIR)/datagen.c fuzzer.c
113         $(CC) -m32 $(FLAGS) $^ -o $@$(EXT)
114
115 fuzzer-dll : LDFLAGS+= -L$(ZSTDDIR) -lzstd
116 fuzzer-dll : $(ZSTDDIR)/common/xxhash.c $(PRGDIR)/datagen.c fuzzer.c
117         $(MAKE) -C $(ZSTDDIR) libzstd
118         $(CC) $(CPPFLAGS) $(CFLAGS) $^ $(LDFLAGS) -o $@$(EXT)
119
120 zbufftest : CPPFLAGS += -I$(ZSTDDIR)/deprecated
121 zbufftest : CFLAGS += -Wno-deprecated-declarations   # required to silence deprecation warnings
122 zbufftest : $(ZSTD_FILES) $(ZBUFF_FILES) $(PRGDIR)/datagen.c zbufftest.c
123         $(CC) $(FLAGS) $^ -o $@$(EXT)
124
125 zbufftest32 : CPPFLAGS += -I$(ZSTDDIR)/deprecated
126 zbufftest32 : CFLAGS += -Wno-deprecated-declarations -m32
127 zbufftest32 : $(ZSTD_FILES) $(ZBUFF_FILES) $(PRGDIR)/datagen.c zbufftest.c
128         $(CC) $(FLAGS) $^ -o $@$(EXT)
129
130 zbufftest-dll : CPPFLAGS += -I$(ZSTDDIR)/deprecated
131 zbufftest-dll : CFLAGS += -Wno-deprecated-declarations   # required to silence deprecation warnings
132 zbufftest-dll : LDFLAGS+= -L$(ZSTDDIR) -lzstd
133 zbufftest-dll : $(ZSTDDIR)/common/xxhash.c $(PRGDIR)/datagen.c zbufftest.c
134         $(MAKE) -C $(ZSTDDIR) libzstd
135         $(CC) $(CPPFLAGS) $(CFLAGS) $^ $(LDFLAGS) -o $@$(EXT)
136
137 ZSTREAMFILES := $(ZSTD_FILES) $(ZDICT_FILES) $(PRGDIR)/datagen.c zstreamtest.c
138 zstreamtest : CPPFLAGS += $(MULTITHREAD_CPP)
139 zstreamtest : LDFLAGS += $(MULTITHREAD_LD)
140 zstreamtest : $(ZSTREAMFILES)
141         $(CC) $(FLAGS) $^ -o $@$(EXT)
142
143 zstreamtest32 : CFLAGS += -m32
144 zstreamtest32 : $(ZSTREAMFILES)
145         $(CC) $(FLAGS) $(MULTITHREAD) $^ -o $@$(EXT)
146
147 zstreamtest_asan : CFLAGS += -fsanitize=address
148 zstreamtest_asan : $(ZSTREAMFILES)
149         $(CC) $(FLAGS) $(MULTITHREAD) $^ -o $@$(EXT)
150
151 zstreamtest_tsan : CFLAGS += -fsanitize=thread
152 zstreamtest_tsan : $(ZSTREAMFILES)
153         $(CC) $(FLAGS) $(MULTITHREAD) $^ -o $@$(EXT)
154
155 zstreamtest-dll : LDFLAGS+= -L$(ZSTDDIR) -lzstd
156 zstreamtest-dll : $(ZSTDDIR)/common/xxhash.c $(PRGDIR)/datagen.c zstreamtest.c
157         $(MAKE) -C $(ZSTDDIR) libzstd
158         $(CC) $(CPPFLAGS) $(CFLAGS) $^ $(LDFLAGS) -o $@$(EXT)
159
160 paramgrill : DEBUGFLAG =
161 paramgrill : $(ZSTD_FILES) $(PRGDIR)/datagen.c paramgrill.c
162         $(CC)      $(FLAGS) $^ -lm -o $@$(EXT)
163
164 datagen : $(PRGDIR)/datagen.c datagencli.c
165         $(CC)      $(FLAGS) $^ -o $@$(EXT)
166
167 roundTripCrash : $(ZSTD_FILES) roundTripCrash.c
168         $(CC)      $(FLAGS) $^ -o $@$(EXT)
169
170 longmatch  : $(ZSTD_FILES) longmatch.c
171         $(CC)      $(FLAGS) $^ -o $@$(EXT)
172
173 invalidDictionaries  : $(ZSTD_FILES) invalidDictionaries.c
174         $(CC)      $(FLAGS) $^ -o $@$(EXT)
175
176 legacy : CFLAGS+= -DZSTD_LEGACY_SUPPORT=4
177 legacy : CPPFLAGS+= -I$(ZSTDDIR)/legacy
178 legacy : $(ZSTD_FILES) $(wildcard $(ZSTDDIR)/legacy/*.c) legacy.c
179         $(CC)      $(FLAGS) $^ -o $@$(EXT)
180
181 decodecorpus    : $(filter-out $(ZSTDDIR)/compress/zstd_compress.c, $(wildcard $(ZSTD_FILES))) decodecorpus.c
182         $(CC)      $(FLAGS) $^ -o $@$(EXT) -lm
183
184 symbols  : symbols.c
185         $(MAKE) -C $(ZSTDDIR) libzstd
186 ifneq (,$(filter Windows%,$(OS)))
187         cp $(ZSTDDIR)/dll/libzstd.dll .
188         $(CC) $(FLAGS) $^ -o $@$(EXT) -DZSTD_DLL_IMPORT=1 libzstd.dll
189 else
190         $(CC) $(FLAGS) $^ -o $@$(EXT) -Wl,-rpath=$(ZSTDDIR) $(ZSTDDIR)/libzstd.so
191 endif
192
193 pool  : pool.c $(ZSTDDIR)/common/pool.c $(ZSTDDIR)/common/threading.c
194         $(CC)    $(FLAGS) $(MULTITHREAD) $^ -o $@$(EXT)
195
196 namespaceTest:
197         if $(CC) namespaceTest.c ../lib/common/xxhash.c -o $@ ; then echo compilation should fail; exit 1 ; fi
198         $(RM) $@
199
200 versionsTest: clean
201         $(PYTHON) test-zstd-versions.py
202
203 clean:
204         $(MAKE) -C $(ZSTDDIR) clean
205         @$(RM) -fR $(TESTARTEFACT)
206         @$(RM) -f core *.o tmp* result* *.gcda dictionary *.zst \
207         $(PRGDIR)/zstd$(EXT) $(PRGDIR)/zstd32$(EXT) \
208         fullbench$(EXT) fullbench32$(EXT) \
209         fullbench-lib$(EXT) fullbench-dll$(EXT) \
210         fuzzer$(EXT) fuzzer32$(EXT) zbufftest$(EXT) zbufftest32$(EXT) \
211         fuzzer-dll$(EXT) zstreamtest-dll$(EXT) zbufftest-dll$(EXT)\
212         zstreamtest$(EXT) zstreamtest32$(EXT) \
213         datagen$(EXT) paramgrill$(EXT) roundTripCrash$(EXT) longmatch$(EXT) \
214         symbols$(EXT) invalidDictionaries$(EXT) legacy$(EXT) pool$(EXT) \
215         decodecorpus$(EXT)
216         @echo Cleaning completed
217
218
219 #----------------------------------------------------------------------------------
220 #make valgrindTest is validated only for Linux, OSX, BSD, Hurd and Solaris targets
221 #----------------------------------------------------------------------------------
222 ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS))
223 HOST_OS = POSIX
224
225 valgrindTest: VALGRIND = valgrind --leak-check=full --error-exitcode=1
226 valgrindTest: zstd datagen fuzzer fullbench
227         @echo "\n ---- valgrind tests : memory analyzer ----"
228         $(VALGRIND) ./datagen -g50M > $(VOID)
229         $(VALGRIND) $(PRGDIR)/zstd ; if [ $$? -eq 0 ] ; then echo "zstd without argument should have failed"; false; fi
230         ./datagen -g80 | $(VALGRIND) $(PRGDIR)/zstd - -c > $(VOID)
231         ./datagen -g16KB | $(VALGRIND) $(PRGDIR)/zstd -vf - -c > $(VOID)
232         ./datagen -g2930KB | $(VALGRIND) $(PRGDIR)/zstd -5 -vf - -o tmp
233         $(VALGRIND) $(PRGDIR)/zstd -vdf tmp -c > $(VOID)
234         ./datagen -g64MB | $(VALGRIND) $(PRGDIR)/zstd -vf - -c > $(VOID)
235         @rm tmp
236         $(VALGRIND) ./fuzzer -T1mn -t1
237         $(VALGRIND) ./fullbench -i1
238
239 endif
240
241
242 ifneq (,$(filter MSYS%,$(shell uname)))
243 HOST_OS = MSYS
244 endif
245
246
247 #-----------------------------------------------------------------------------
248 #make tests validated only for MSYS, Linux, OSX, BSD, Hurd and Solaris targets
249 #-----------------------------------------------------------------------------
250 ifneq (,$(filter $(HOST_OS),MSYS POSIX))
251
252 DIFF:=diff
253 ifneq (,$(filter $(shell uname),SunOS))
254 DIFF:=gdiff
255 endif
256
257 zstd-playTests: datagen
258         file $(ZSTD)
259         ZSTD="$(QEMU_SYS) $(ZSTD)" ./playTests.sh $(ZSTDRTTEST)
260
261 shortest: ZSTDRTTEST=
262 shortest: test-zstd
263
264 fuzztest: test-fuzzer test-zstream test-decodecorpus
265
266 test: test-zstd test-fullbench test-fuzzer test-zstream test-invalidDictionaries test-legacy test-decodecorpus
267 ifeq ($(QEMU_SYS),)
268 test: test-pool
269 endif
270
271 test32: test-zstd32 test-fullbench32 test-fuzzer32 test-zstream32
272
273 test-all: test test32 valgrindTest
274
275 test-zstd: ZSTD = $(PRGDIR)/zstd
276 test-zstd: zstd zstd-playTests
277
278 test-zstd32: ZSTD = $(PRGDIR)/zstd32
279 test-zstd32: zstd32 zstd-playTests
280
281 test-zstd-nolegacy: ZSTD = $(PRGDIR)/zstd
282 test-zstd-nolegacy: zstd-nolegacy zstd-playTests
283
284 test-gzstd: gzstd
285         $(PRGDIR)/zstd README.md test-zstd-speed.py
286         gzip README.md test-zstd-speed.py
287         cat README.md.zst test-zstd-speed.py.gz >zstd_gz.zst
288         cat README.md.gz test-zstd-speed.py.zst >gz_zstd.gz
289         $(PRGDIR)/zstd -d README.md.gz -o README2.md
290         $(PRGDIR)/zstd -d README.md.gz test-zstd-speed.py.gz
291         $(PRGDIR)/zstd -d zstd_gz.zst gz_zstd.gz
292         $(DIFF) -q zstd_gz gz_zstd
293         echo Hello World ZSTD | $(PRGDIR)/zstd -c - >hello.zst
294         echo Hello World GZIP | gzip -c - >hello.gz
295         echo Hello World TEXT >hello.txt
296         cat hello.zst hello.gz hello.txt >hello_zst_gz_txt.gz
297         $(PRGDIR)/zstd -dcf hello.*
298         $(PRGDIR)/zstd -dcf - <hello_zst_gz_txt.gz
299
300 test-fullbench: fullbench datagen
301         $(QEMU_SYS) ./fullbench -i1
302         $(QEMU_SYS) ./fullbench -i1 -P0
303
304 test-fullbench32: fullbench32 datagen
305         $(QEMU_SYS) ./fullbench32 -i1
306         $(QEMU_SYS) ./fullbench32 -i1 -P0
307
308 test-fuzzer: fuzzer
309         $(QEMU_SYS) ./fuzzer $(FUZZERTEST) $(FUZZER_FLAGS)
310
311 test-fuzzer32: fuzzer32
312         $(QEMU_SYS) ./fuzzer32 $(FUZZERTEST) $(FUZZER_FLAGS)
313
314 test-zbuff: zbufftest
315         $(QEMU_SYS) ./zbufftest $(ZSTREAM_TESTTIME)
316
317 test-zbuff32: zbufftest32
318         $(QEMU_SYS) ./zbufftest32 $(ZSTREAM_TESTTIME)
319
320 test-zstream: zstreamtest
321         $(QEMU_SYS) ./zstreamtest $(ZSTREAM_TESTTIME) $(FUZZER_FLAGS)
322
323 test-zstream32: zstreamtest32
324         $(QEMU_SYS) ./zstreamtest32 $(ZSTREAM_TESTTIME) $(FUZZER_FLAGS)
325
326 test-longmatch: longmatch
327         $(QEMU_SYS) ./longmatch
328
329 test-invalidDictionaries: invalidDictionaries
330         $(QEMU_SYS) ./invalidDictionaries
331
332 test-symbols: symbols
333         $(QEMU_SYS) ./symbols
334
335 test-legacy: legacy
336         $(QEMU_SYS) ./legacy
337
338 test-decodecorpus: decodecorpus
339         $(QEMU_SYS) ./decodecorpus -t $(DECODECORPUS_TESTTIME)
340
341 test-pool: pool
342         $(QEMU_SYS) ./pool
343
344 endif