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