• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# ##########################################################################
2# LZ4 programs - Makefile
3# Copyright (C) Yann Collet 2011-2020
4#
5# GPL v2 License
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License along
18# with this program; if not, write to the Free Software Foundation, Inc.,
19# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20#
21# You can contact the author at :
22#  - LZ4 homepage : http://www.lz4.org
23#  - LZ4 source repository : https://github.com/lz4/lz4
24# ##########################################################################
25# fuzzer  : Test tool, to check lz4 integrity on target platform
26# frametest  : Test tool, to check lz4frame integrity on target platform
27# fullbench  : Precisely measure speed for each LZ4 function variant
28# datagen : generates synthetic data samples for tests & benchmarks
29# ##########################################################################
30
31LZ4DIR  := ../lib
32PRGDIR  := ../programs
33TESTDIR := versionsTest
34PYTHON  ?= python3
35
36DEBUGLEVEL?= 1
37DEBUGFLAGS = -g -DLZ4_DEBUG=$(DEBUGLEVEL)
38CFLAGS  ?= -O3 # can select custom optimization flags. Example : CFLAGS=-O2 make
39CFLAGS  += -Wall -Wextra -Wundef -Wcast-qual -Wcast-align -Wshadow \
40           -Wswitch-enum -Wdeclaration-after-statement -Wstrict-prototypes \
41           -Wpointer-arith -Wstrict-aliasing=1
42CFLAGS  += $(DEBUGFLAGS) $(MOREFLAGS)
43CPPFLAGS+= -I$(LZ4DIR) -I$(PRGDIR) -DXXH_NAMESPACE=LZ4_
44FLAGS    = $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
45
46include ../Makefile.inc
47
48LZ4 := $(PRGDIR)/lz4$(EXT)
49
50
51# Default test parameters
52TEST_FILES   := COPYING
53FUZZER_TIME  := -T90s
54NB_LOOPS     ?= -i1
55
56.PHONY: default
57default: all
58
59all: fullbench fuzzer frametest roundTripTest datagen checkFrame decompress-partial
60
61all32: CFLAGS+=-m32
62all32: all
63
64lz4:
65	$(MAKE) -C $(PRGDIR) $@ CFLAGS="$(CFLAGS)"
66
67lib liblz4.pc:
68	$(MAKE) -C $(LZ4DIR) $@ CFLAGS="$(CFLAGS)"
69
70lz4c unlz4 lz4cat: lz4
71	$(LN_SF) $(LZ4) $(PRGDIR)/$@
72
73lz4c32:   # create a 32-bits version for 32/64 interop tests
74	$(MAKE) -C $(PRGDIR) $@ CFLAGS="-m32 $(CFLAGS)"
75
76%.o : $(LZ4DIR)/%.c $(LZ4DIR)/%.h
77	$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
78
79fullbench : DEBUGLEVEL=0
80fullbench : lz4.o lz4hc.o lz4frame.o xxhash.o fullbench.c
81	$(CC) $(FLAGS) $^ -o $@$(EXT)
82
83$(LZ4DIR)/liblz4.a:
84	$(MAKE) -C $(LZ4DIR) liblz4.a
85
86fullbench-lib: fullbench.c $(LZ4DIR)/liblz4.a
87	$(CC) $(FLAGS) $^ -o $@$(EXT)
88
89fullbench-dll: fullbench.c $(LZ4DIR)/xxhash.c
90	$(MAKE) -C $(LZ4DIR) liblz4
91	$(CC) $(FLAGS) $^ -o $@$(EXT) -DLZ4_DLL_IMPORT=1 $(LZ4DIR)/dll/$(LIBLZ4).dll
92
93# test LZ4_USER_MEMORY_FUNCTIONS
94fullbench-wmalloc: CPPFLAGS += -DLZ4_USER_MEMORY_FUNCTIONS
95fullbench-wmalloc: fullbench
96
97fuzzer  : lz4.o lz4hc.o xxhash.o fuzzer.c
98	$(CC) $(FLAGS) $^ -o $@$(EXT)
99
100frametest: lz4frame.o lz4.o lz4hc.o xxhash.o frametest.c
101	$(CC) $(FLAGS) $^ -o $@$(EXT)
102
103roundTripTest : lz4.o lz4hc.o xxhash.o roundTripTest.c
104	$(CC) $(FLAGS) $^ -o $@$(EXT)
105
106datagen : $(PRGDIR)/datagen.c datagencli.c
107	$(CC) $(FLAGS) -I$(PRGDIR) $^ -o $@$(EXT)
108
109checkFrame : lz4frame.o lz4.o lz4hc.o xxhash.o checkFrame.c
110	$(CC) $(FLAGS) $^ -o $@$(EXT)
111
112decompress-partial: lz4.o decompress-partial.c
113	$(CC) $(FLAGS) $^ -o $@$(EXT)
114
115decompress-partial-usingDict: lz4.o decompress-partial-usingDict.c
116	$(CC) $(FLAGS) $^ -o $@$(EXT)
117
118freestanding: freestanding.c
119	$(CC) -ffreestanding -nostdlib $^ -o $@$(EXT)
120
121.PHONY: clean
122clean:
123	@$(MAKE) -C $(LZ4DIR) $@ > $(VOID)
124	@$(MAKE) -C $(PRGDIR) $@ > $(VOID)
125	@$(RM) -rf core *.o *.test tmp* \
126        fullbench-dll$(EXT) fullbench-lib$(EXT) \
127        fullbench$(EXT) fullbench32$(EXT) \
128        fuzzer$(EXT) fuzzer32$(EXT) \
129        frametest$(EXT) frametest32$(EXT) \
130        fasttest$(EXT) roundTripTest$(EXT) \
131        datagen$(EXT) checkTag$(EXT) \
132        frameTest$(EXT) decompress-partial$(EXT) \
133        abiTest$(EXT) freestanding$(EXT) \
134        lz4_all.c
135	@$(RM) -rf $(TESTDIR)
136	@echo Cleaning completed
137
138.PHONY: versionsTest
139versionsTest:
140	$(PYTHON) test-lz4-versions.py
141
142.PHONY: listTest
143listTest: lz4
144	QEMU_SYS=$(QEMU_SYS) $(PYTHON) test-lz4-list.py
145
146abiTest: LDLIBS += -llz4
147
148.PHONY: abiTests
149abiTests:
150	$(PYTHON) test-lz4-abi.py
151
152checkTag: checkTag.c $(LZ4DIR)/lz4.h
153	$(CC) $(FLAGS) $< -o $@$(EXT)
154
155#-----------------------------------------------------------------------------
156# validated only for Linux, OSX, BSD, Hurd and Solaris targets
157#-----------------------------------------------------------------------------
158ifeq ($(POSIX_ENV),Yes)
159
160MD5:=md5sum
161ifneq (,$(filter $(shell $(UNAME)), Darwin ))
162MD5:=md5 -r
163endif
164
165# note : we should probably settle on a single compare utility
166CMP:=cmp
167GREP:=grep
168DIFF:=diff
169ifneq (,$(filter $(shell $(UNAME)),SunOS))
170DIFF:=gdiff
171endif
172
173CAT:=cat
174DD:=dd
175DATAGEN:=./datagen
176
177.PHONY: list
178list:
179	@$(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
180
181.PHONY: check
182check: test-lz4-essentials
183
184.PHONY: test
185test: test-lz4 test-lz4c test-frametest test-fullbench test-fuzzer test-amalgamation listTest test-decompress-partial
186
187.PHONY: test32
188test32: CFLAGS+=-m32
189test32: test
190
191.PHONY: test-amalgamation
192test-amalgamation: lz4_all.o
193
194lz4_all.c: $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c $(LZ4DIR)/lz4frame.c
195	$(CAT) $^ > $@
196
197.PHONY: test-install
198test-install: lz4 lib liblz4.pc
199	lz4_root=.. ./test_install.sh
200
201.PHONY: test-compile-with-lz4-memory-usage
202test-compile-with-lz4-memory-usage:
203	$(MAKE) clean; CFLAGS=-O0 CPPFLAGS=-D'LZ4_MEMORY_USAGE=LZ4_MEMORY_USAGE_MIN' $(MAKE) all
204	$(MAKE) clean; CFLAGS=-O0 CPPFLAGS=-D'LZ4_MEMORY_USAGE=LZ4_MEMORY_USAGE_MAX' $(MAKE) all
205
206.PHONY: test-lz4-sparse
207# Rules regarding Temporary test files :
208# Each test must use its own unique set of names during execution.
209# Each temporary test file must begin by an FPREFIX.
210# Each FPREFIX must be unique for each test.
211# All FPREFIX must start with `tmp`, for `make clean`
212# All tests must clean their temporary test files on successful completion,
213# and only their test files : do not employ sweeping statements such `rm tmp*` or `rm *.lz4`
214test-lz4-sparse: FPREFIX = tmp-tls
215test-lz4-sparse: lz4 datagen
216	@echo "\n ---- test sparse file support ----"
217	$(DATAGEN) -g5M  -P100 > $(FPREFIX)dg5M
218	$(LZ4) -B4D $(FPREFIX)dg5M -c | $(LZ4) -dv --sparse > $(FPREFIX)cB4
219	$(DIFF) -s $(FPREFIX)dg5M $(FPREFIX)cB4
220	$(LZ4) -B5D $(FPREFIX)dg5M -c | $(LZ4) -dv --sparse > $(FPREFIX)cB5
221	$(DIFF) -s $(FPREFIX)dg5M $(FPREFIX)cB5
222	$(LZ4) -B6D $(FPREFIX)dg5M -c | $(LZ4) -dv --sparse > $(FPREFIX)cB6
223	$(DIFF) -s $(FPREFIX)dg5M $(FPREFIX)cB6
224	$(LZ4) -B7D $(FPREFIX)dg5M -c | $(LZ4) -dv --sparse > $(FPREFIX)cB7
225	$(DIFF) -s $(FPREFIX)dg5M $(FPREFIX)cB7
226	$(LZ4) $(FPREFIX)dg5M -c | $(LZ4) -dv --no-sparse > $(FPREFIX)nosparse
227	$(DIFF) -s $(FPREFIX)dg5M $(FPREFIX)nosparse
228	ls -ls $(FPREFIX)*
229	$(DATAGEN) -s1 -g1200007 -P100 | $(LZ4) | $(LZ4) -dv --sparse > $(FPREFIX)odd   # Odd size file (to generate non-full last block)
230	$(DATAGEN) -s1 -g1200007 -P100 | $(DIFF) -s - $(FPREFIX)odd
231	ls -ls $(FPREFIX)odd
232	@$(RM) $(FPREFIX)*
233	@echo "\n Compatibility with Console :"
234	echo "Hello World 1 !" | $(LZ4) | $(LZ4) -d -c
235	echo "Hello World 2 !" | $(LZ4) | $(LZ4) -d | $(CAT)
236	echo "Hello World 3 !" | $(LZ4) --no-frame-crc | $(LZ4) -d -c
237	@echo "\n Compatibility with Append :"
238	$(DATAGEN) -P100 -g1M > $(FPREFIX)dg1M
239	$(CAT) $(FPREFIX)dg1M $(FPREFIX)dg1M > $(FPREFIX)2M
240	$(LZ4) -B5 -v $(FPREFIX)dg1M $(FPREFIX)c
241	$(LZ4) -d -v $(FPREFIX)c $(FPREFIX)r
242	$(LZ4) -d -v $(FPREFIX)c -c >> $(FPREFIX)r
243	ls -ls $(FPREFIX)*
244	$(DIFF) $(FPREFIX)2M $(FPREFIX)r
245	@$(RM) $(FPREFIX)*
246
247test-lz4-contentSize: FPREFIX = tmp-lzc
248test-lz4-contentSize: lz4 datagen
249	@echo "\n ---- test original size support ----"
250	$(DATAGEN) -g15M > $(FPREFIX)
251	$(LZ4) -v $(FPREFIX) -c | $(LZ4) -t
252	$(LZ4) -v --content-size $(FPREFIX) -c | $(LZ4) -d > $(FPREFIX)-dup
253	$(DIFF) $(FPREFIX) $(FPREFIX)-dup
254	$(LZ4) -f $(FPREFIX) -c > $(FPREFIX).lz4 # compressed with content size
255	$(LZ4) --content-size $(FPREFIX) -c > $(FPREFIX)-wcz.lz4
256	! $(DIFF) $(FPREFIX).lz4 $(FPREFIX)-wcz.lz4  # must differ, due to content size
257	$(LZ4) --content-size < $(FPREFIX) > $(FPREFIX)-wcz2.lz4 # can determine content size because stdin is just a file
258	$(DIFF) $(FPREFIX)-wcz.lz4 $(FPREFIX)-wcz2.lz4  # both must contain content size
259	$(CAT) $(FPREFIX) | $(LZ4) > $(FPREFIX)-ncz.lz4
260	$(DIFF) $(FPREFIX).lz4 $(FPREFIX)-ncz.lz4  # both don't have content size
261	$(CAT) $(FPREFIX) | $(LZ4) --content-size > $(FPREFIX)-ncz2.lz4 # can't determine content size
262	$(DIFF) $(FPREFIX).lz4 $(FPREFIX)-ncz2.lz4  # both don't have content size
263	@$(RM) $(FPREFIX)*
264
265test-lz4-frame-concatenation: FPREFIX = tmp-lfc
266test-lz4-frame-concatenation: lz4 datagen
267	@echo "\n ---- test frame concatenation ----"
268	@echo -n > $(FPREFIX)-empty
269	@echo hi > $(FPREFIX)-nonempty
270	$(CAT) $(FPREFIX)-nonempty $(FPREFIX)-empty $(FPREFIX)-nonempty > $(FPREFIX)-src
271	$(LZ4) -zq $(FPREFIX)-empty -c > $(FPREFIX)-empty.lz4
272	$(LZ4) -zq $(FPREFIX)-nonempty -c > $(FPREFIX)-nonempty.lz4
273	$(CAT) $(FPREFIX)-nonempty.lz4 $(FPREFIX)-empty.lz4 $(FPREFIX)-nonempty.lz4 > $(FPREFIX)-concat.lz4
274	$(LZ4) -d $(FPREFIX)-concat.lz4 -c > $(FPREFIX)-result
275	$(CMP) $(FPREFIX)-src $(FPREFIX)-result
276	@$(RM) $(FPREFIX)*
277	@echo frame concatenation test completed
278
279test-lz4-multiple: FPREFIX = tmp-tml
280test-lz4-multiple: lz4 datagen
281	@echo "\n ---- test multiple files ----"
282	@$(DATAGEN) -s1        > $(FPREFIX)1 2> $(VOID)
283	@$(DATAGEN) -s2 -g100K > $(FPREFIX)2 2> $(VOID)
284	@$(DATAGEN) -s3 -g200K > $(FPREFIX)3 2> $(VOID)
285	# compress multiple files : one .lz4 per source file
286	$(LZ4) -f -m $(FPREFIX)*
287	test -f $(FPREFIX)1.lz4
288	test -f $(FPREFIX)2.lz4
289	test -f $(FPREFIX)3.lz4
290	# decompress multiple files : one output file per .lz4
291	mv $(FPREFIX)1 $(FPREFIX)1-orig
292	mv $(FPREFIX)2 $(FPREFIX)2-orig
293	mv $(FPREFIX)3 $(FPREFIX)3-orig
294	$(LZ4) -d -f -m $(FPREFIX)*.lz4
295	$(CMP) $(FPREFIX)1 $(FPREFIX)1-orig   # must be identical
296	$(CMP) $(FPREFIX)2 $(FPREFIX)2-orig
297	$(CMP) $(FPREFIX)3 $(FPREFIX)3-orig
298	# compress multiple files into stdout
299	$(CAT) $(FPREFIX)1.lz4 $(FPREFIX)2.lz4 $(FPREFIX)3.lz4 > $(FPREFIX)-concat1
300	$(RM) $(FPREFIX)*.lz4
301	$(LZ4) -m $(FPREFIX)1 $(FPREFIX)2 $(FPREFIX)3 -c > $(FPREFIX)-concat2
302	test ! -f $(FPREFIX)1.lz4  # must not create .lz4 artefact
303	$(CMP) $(FPREFIX)-concat1 $(FPREFIX)-concat2  # must be equivalent
304	# decompress multiple files into stdout
305	$(RM) $(FPREFIX)-concat1 $(FPREFIX)-concat2
306	$(LZ4) -f -m $(FPREFIX)1 $(FPREFIX)2 $(FPREFIX)3   # generate .lz4 to decompress
307	$(CAT) $(FPREFIX)1 $(FPREFIX)2 $(FPREFIX)3 > $(FPREFIX)-concat1   # create concatenated reference
308	$(RM) $(FPREFIX)1 $(FPREFIX)2 $(FPREFIX)3
309	$(LZ4) -d -m $(FPREFIX)1.lz4 $(FPREFIX)2.lz4 $(FPREFIX)3.lz4 -c > $(FPREFIX)-concat2
310	test ! -f $(FPREFIX)1  # must not create file artefact
311	$(CMP) $(FPREFIX)-concat1 $(FPREFIX)-concat2  # must be equivalent
312	# compress multiple files, one of which is absent (must fail)
313	! $(LZ4) -f -m $(FPREFIX)-concat1 notHere $(FPREFIX)-concat2  # must fail : notHere not present
314	# test lz4-compressed file
315	$(LZ4) -tm $(FPREFIX)-concat1.lz4
316	$(LZ4) -tm $(FPREFIX)-concat1.lz4 $(FPREFIX)-concat2.lz4
317	# test multiple lz4 files, one of which is absent (must fail)
318	! $(LZ4) -tm $(FPREFIX)-concat1.lz4 notHere.lz4 $(FPREFIX)-concat2.lz4
319	@$(RM) $(FPREFIX)*
320
321test-lz4-multiple-legacy: FPREFIX = tmp-lml
322test-lz4-multiple-legacy: lz4 datagen
323	@echo "\n ---- test multiple files (Legacy format) ----"
324	@$(DATAGEN) -s1        > $(FPREFIX)1 2> $(VOID)
325	@$(DATAGEN) -s2 -g100K > $(FPREFIX)2 2> $(VOID)
326	@$(DATAGEN) -s3 -g200K > $(FPREFIX)3 2> $(VOID)
327	# compress multiple files using legacy format: one .lz4 per source file
328	$(LZ4) -f -l -m $(FPREFIX)*
329	test -f $(FPREFIX)1.lz4
330	test -f $(FPREFIX)2.lz4
331	test -f $(FPREFIX)3.lz4
332	# decompress multiple files compressed using legacy format: one output file per .lz4
333	mv $(FPREFIX)1 $(FPREFIX)1-orig
334	mv $(FPREFIX)2 $(FPREFIX)2-orig
335	mv $(FPREFIX)3 $(FPREFIX)3-orig
336	$(LZ4) -d -f -m $(FPREFIX)*.lz4
337	$(LZ4) -l -d -f -m $(FPREFIX)*.lz4 # -l mustn't impact -d option
338	$(CMP) $(FPREFIX)1 $(FPREFIX)1-orig   # must be identical
339	$(CMP) $(FPREFIX)2 $(FPREFIX)2-orig
340	$(CMP) $(FPREFIX)3 $(FPREFIX)3-orig
341	# compress multiple files into stdout using legacy format
342	$(CAT) $(FPREFIX)1.lz4 $(FPREFIX)2.lz4 $(FPREFIX)3.lz4 > $(FPREFIX)-concat1
343	$(RM) $(FPREFIX)*.lz4
344	$(LZ4) -l -m $(FPREFIX)1 $(FPREFIX)2 $(FPREFIX)3 -c > $(FPREFIX)-concat2
345	test ! -f $(FPREFIX)1.lz4  # must not create .lz4 artefact
346	$(CMP) $(FPREFIX)-concat1 $(FPREFIX)-concat2  # must be equivalent
347	# # # decompress multiple files into stdout using legacy format
348	$(RM) $(FPREFIX)-concat1 $(FPREFIX)-concat2
349	$(LZ4) -l -f -m $(FPREFIX)1 $(FPREFIX)2 $(FPREFIX)3   # generate .lz4 to decompress
350	$(CAT) $(FPREFIX)1 $(FPREFIX)2 $(FPREFIX)3 > $(FPREFIX)-concat1   # create concatenated reference
351	$(RM) $(FPREFIX)1 $(FPREFIX)2 $(FPREFIX)3
352	$(LZ4) -d -m $(FPREFIX)1.lz4 $(FPREFIX)2.lz4 $(FPREFIX)3.lz4 -c > $(FPREFIX)-concat2
353	$(LZ4) -d -l -m $(FPREFIX)1.lz4 $(FPREFIX)2.lz4 $(FPREFIX)3.lz4 -c > $(FPREFIX)-concat2 # -l mustn't impact option -d
354	test ! -f $(FPREFIX)1  # must not create file artefact
355	$(CMP) $(FPREFIX)-concat1 $(FPREFIX)-concat2  # must be equivalent
356	# # # compress multiple files, one of which is absent (must fail)
357	! $(LZ4) -f -l -m $(FPREFIX)-concat1 notHere-legacy $(FPREFIX)-concat2  # must fail : notHere-legacy not present
358	@$(RM) $(FPREFIX)*
359
360SKIPFILE = goldenSamples/skip.bin
361test-lz4-skippable: FPREFIX = tmp-lsk
362test-lz4-skippable: lz4 datagen
363	@echo "\n ---- test lz4 with skippable frames ----"
364	$(LZ4) -dc $(SKIPFILE)
365	$(LZ4) -dc < $(SKIPFILE)
366	cat $(SKIPFILE) | $(LZ4) -dc
367	echo "Hello from Valid Frame!\n" | $(LZ4) -c > $(FPREFIX).lz4
368	cat $(SKIPFILE) $(FPREFIX).lz4 $(SKIPFILE) | $(LZ4) -dc
369	$(RM) $(FPREFIX)*
370
371test-lz4-basic: FPREFIX = tmp-tlb
372test-lz4-basic: lz4 datagen unlz4 lz4cat
373	@echo "\n ---- test lz4 basic compression/decompression ----"
374	$(DATAGEN) -g0       | $(LZ4) -v     | $(LZ4) -t
375	$(DATAGEN) -g16KB    | $(LZ4) -9     | $(LZ4) -t
376	$(DATAGEN) -g20KB > $(FPREFIX)-dg20k
377	$(LZ4) < $(FPREFIX)-dg20k | $(LZ4) -d > $(FPREFIX)-dec
378	$(DIFF) -q $(FPREFIX)-dg20k $(FPREFIX)-dec
379	$(LZ4) --no-frame-crc < $(FPREFIX)-dg20k | $(LZ4) -d > $(FPREFIX)-dec
380	$(DIFF) -q $(FPREFIX)-dg20k $(FPREFIX)-dec
381	$(DATAGEN)           | $(LZ4) -BI    | $(LZ4) -t
382	$(DATAGEN)           | $(LZ4) --no-crc | $(LZ4) -t
383	$(DATAGEN) -g6M -P99 | $(LZ4) -9BD   | $(LZ4) -t
384	$(DATAGEN) -g17M     | $(LZ4) -9v    | $(LZ4) -qt
385	$(DATAGEN) -g33M     | $(LZ4) --no-frame-crc | $(LZ4) -t
386	$(DATAGEN) -g256MB   | $(LZ4) -vqB4D | $(LZ4) -t --no-crc
387	@echo "hello world" > $(FPREFIX)-hw
388	$(LZ4) --rm -f $(FPREFIX)-hw $(FPREFIX)-hw.lz4
389	test ! -f $(FPREFIX)-hw                      # must fail (--rm)
390	test   -f $(FPREFIX)-hw.lz4
391	$(PRGDIR)/lz4cat $(FPREFIX)-hw.lz4 | $(GREP) "hello world"
392	$(PRGDIR)/unlz4 --rm $(FPREFIX)-hw.lz4 $(FPREFIX)-hw
393	test   -f $(FPREFIX)-hw
394	test ! -f $(FPREFIX)-hw.lz4                  # must fail (--rm)
395	test ! -f $(FPREFIX)-hw.lz4.lz4              # must fail (unlz4)
396	$(PRGDIR)/lz4cat $(FPREFIX)-hw               # pass-through mode
397	test   -f $(FPREFIX)-hw
398	test ! -f $(FPREFIX)-hw.lz4                  # must fail (lz4cat)
399	$(LZ4) $(FPREFIX)-hw $(FPREFIX)-hw.lz4          # creates $(FPREFIX)-hw.lz4
400	$(PRGDIR)/lz4cat < $(FPREFIX)-hw.lz4 > $(FPREFIX)3  # checks lz4cat works with stdin (#285)
401	$(DIFF) -q $(FPREFIX)-hw $(FPREFIX)3
402	$(PRGDIR)/lz4cat < $(FPREFIX)-hw > $(FPREFIX)2      # checks lz4cat works in pass-through mode
403	$(DIFF) -q $(FPREFIX)-hw $(FPREFIX)2
404	cp $(FPREFIX)-hw ./-d
405	$(LZ4) --rm -- -d -d.lz4               # compresses ./d into ./-d.lz4
406	test   -f ./-d.lz4
407	test ! -f ./-d
408	mv ./-d.lz4 ./-z
409	$(LZ4) -d --rm -- -z $(FPREFIX)4          # uncompresses ./-z into $(FPREFIX)4
410	test ! -f ./-z
411	$(DIFF) -q $(FPREFIX)-hw $(FPREFIX)4
412	! $(LZ4) $(FPREFIX)2 $(FPREFIX)3 $(FPREFIX)4    # must fail: refuse to handle 3+ file names
413	$(LZ4) -f $(FPREFIX)-hw                   # create $(FPREFIX)-hw.lz4, for next tests
414	$(LZ4) --list $(FPREFIX)-hw.lz4           # test --list on valid single-frame file
415	$(LZ4) --list < $(FPREFIX)-hw.lz4         # test --list from stdin (file only)
416	$(CAT) $(FPREFIX)-hw >> $(FPREFIX)-hw.lz4
417	! $(LZ4) -f $(FPREFIX)-hw.lz4             # uncompress valid frame followed by invalid data (must fail now)
418	$(LZ4) -BX $(FPREFIX)-hw -c -q | $(LZ4) -tv  # test block checksum
419	# $(DATAGEN) -g20KB generates the same file every single time
420	# cannot save output of $(DATAGEN) -g20KB as input file to lz4 because the following shell commands are run before $(DATAGEN) -g20KB
421	test "$(shell $(DATAGEN) -g20KB | $(LZ4) -c --fast | wc -c)" -lt "$(shell $(DATAGEN) -g20KB | $(LZ4) -c --fast=9 | wc -c)" # -1 vs -9
422	test "$(shell $(DATAGEN) -g20KB | $(LZ4) -c -1 | wc -c)" -lt "$(shell $(DATAGEN) -g20KB| $(LZ4) -c --fast=1 | wc -c)" # 1 vs -1
423	test "$(shell $(DATAGEN) -g20KB | $(LZ4) -c --fast=1 | wc -c)" -eq "$(shell $(DATAGEN) -g20KB| $(LZ4) -c --fast| wc -c)" # checks default fast compression is -1
424	! $(LZ4) -c --fast=0 $(FPREFIX)-dg20K # lz4 should fail when fast=0
425	! $(LZ4) -c --fast=-1 $(FPREFIX)-dg20K # lz4 should fail when fast=-1
426	# High --fast values can result in out-of-bound dereferences #876
427	$(DATAGEN) -g1M | $(LZ4) -c --fast=999999999 > /dev/null
428	# Test for #596
429	@echo "TEST" > $(FPREFIX)-test
430	$(LZ4) -m $(FPREFIX)-test
431	$(LZ4) $(FPREFIX)-test.lz4 $(FPREFIX)-test2
432	$(DIFF) -q $(FPREFIX)-test $(FPREFIX)-test2
433	@$(RM) $(FPREFIX)*
434
435
436test-lz4-dict: FPREFIX = tmp-dict
437test-lz4-dict: lz4 datagen
438	@echo "\n ---- test lz4 compression/decompression with dictionary ----"
439	$(DATAGEN) -g16KB > $(FPREFIX)
440	$(DATAGEN) -g32KB > $(FPREFIX)-sample-32k
441	< $(FPREFIX)-sample-32k $(LZ4) -D $(FPREFIX) | $(LZ4) -dD $(FPREFIX) | diff - $(FPREFIX)-sample-32k
442	$(DATAGEN) -g128MB > $(FPREFIX)-sample-128m
443	< $(FPREFIX)-sample-128m $(LZ4) -D $(FPREFIX) | $(LZ4) -dD $(FPREFIX) | diff - $(FPREFIX)-sample-128m
444	touch $(FPREFIX)-sample-0
445	< $(FPREFIX)-sample-0 $(LZ4) -D $(FPREFIX) | $(LZ4) -dD $(FPREFIX) | diff - $(FPREFIX)-sample-0
446
447	< $(FPREFIX)-sample-32k $(LZ4) -D $(FPREFIX)-sample-0 | $(LZ4) -dD $(FPREFIX)-sample-0 | diff - $(FPREFIX)-sample-32k
448	< $(FPREFIX)-sample-0 $(LZ4) -D $(FPREFIX)-sample-0 | $(LZ4) -dD $(FPREFIX)-sample-0 | diff - $(FPREFIX)-sample-0
449
450	@echo "\n ---- test lz4 dictionary loading ----"
451	$(DATAGEN) -g128KB > $(FPREFIX)-data-128KB
452	set -e; \
453	for l in 0 1 4 128 32767 32768 32769 65535 65536 65537 98303 98304 98305 131071 131072 131073; do \
454		$(DATAGEN) -g$$l > $(FPREFIX)-$$l; \
455		$(DD) if=$(FPREFIX)-$$l of=$(FPREFIX)-$$l-tail bs=1 count=65536 skip=$$((l > 65536 ? l - 65536 : 0)); \
456		< $(FPREFIX)-$$l      $(LZ4) -D stdin $(FPREFIX)-data-128KB -c | $(LZ4) -dD $(FPREFIX)-$$l-tail | $(DIFF) - $(FPREFIX)-data-128KB; \
457		< $(FPREFIX)-$$l-tail $(LZ4) -D stdin $(FPREFIX)-data-128KB -c | $(LZ4) -dD $(FPREFIX)-$$l      | $(DIFF) - $(FPREFIX)-data-128KB; \
458	done
459	@$(RM) $(FPREFIX)*
460
461test-lz4hc-hugefile: lz4 datagen
462	@echo "\n ---- test HC compression/decompression of huge files ----"
463	$(DATAGEN) -g4200MB | $(LZ4) -v3BD | $(LZ4) -qt
464
465test-lz4-fast-hugefile: FPREFIX = tmp-lfh
466test-lz4-fast-hugefile: lz4 datagen
467	@echo "\n ---- test huge files compression/decompression ----"
468	$(DATAGEN) -g6GB    | $(LZ4) -vB5D | $(LZ4) -qt
469	# test large file size [2-4] GB
470	@$(DATAGEN) -g3G -P100 | $(LZ4) -vv | $(LZ4) --decompress --force --sparse - $(FPREFIX)1
471	@ls -ls $(FPREFIX)1
472	@$(DATAGEN) -g3G -P100 | $(LZ4) --quiet --content-size | $(LZ4) --verbose --decompress --force --sparse - $(FPREFIX)2
473	@ls -ls $(FPREFIX)2
474	$(DIFF) -s $(FPREFIX)1 $(FPREFIX)2
475	@$(RM) $(FPREFIX)*
476
477test-lz4-hugefile: test-lz4-fast-hugefile test-lz4hc-hugefile
478
479test-lz4-testmode: FPREFIX = tmp-ltm
480test-lz4-testmode: lz4 datagen
481	@echo "\n ---- bench mode ----"
482	$(LZ4) -bi0
483	$(DATAGEN) > $(FPREFIX)
484	$(LZ4) -f $(FPREFIX) -c > $(FPREFIX).lz4
485	$(LZ4) -bdi0 $(FPREFIX).lz4 # test benchmark decode-only mode
486	$(LZ4) -bdi0 --no-crc $(FPREFIX).lz4 # test benchmark decode-only mode
487	@echo "\n ---- test mode ----"
488	! $(DATAGEN) | $(LZ4) -t
489	! $(DATAGEN) | $(LZ4) -tf
490	@echo "\n ---- pass-through mode ----"
491	@echo "Why hello there " > $(FPREFIX)2.lz4
492	! $(LZ4) -f $(FPREFIX)2.lz4 > $(VOID)
493	! $(DATAGEN) | $(LZ4) -dc  > $(VOID)
494	! $(DATAGEN) | $(LZ4) -df > $(VOID)
495	$(DATAGEN) | $(LZ4) -dcf > $(VOID)
496	@echo "Hello World !" > $(FPREFIX)1
497	$(LZ4) -dcf $(FPREFIX)1
498	@echo "from underground..." > $(FPREFIX)2
499	$(LZ4) -dcfm $(FPREFIX)1 $(FPREFIX)2
500	@echo "\n ---- non-existing source (must fail cleanly) ----"
501	! $(LZ4)     file-does-not-exist
502	! $(LZ4) -f  file-does-not-exist
503	! $(LZ4) -t  file-does-not-exist
504	! $(LZ4) -fm file1-dne file2-dne
505	@$(RM) $(FPREFIX)*
506
507test-lz4-opt-parser: lz4 datagen
508	@echo "\n ---- test opt-parser ----"
509	$(DATAGEN) -g16KB      | $(LZ4) -12      | $(LZ4) -t
510	$(DATAGEN) -P10        | $(LZ4) -12B4    | $(LZ4) -t
511	$(DATAGEN) -g256K      | $(LZ4) -12B4D   | $(LZ4) -t
512	$(DATAGEN) -g512K -P25 | $(LZ4) -12BD    | $(LZ4) -t
513	$(DATAGEN) -g1M        | $(LZ4) -12B5    | $(LZ4) -t
514	$(DATAGEN) -g1M -s2    | $(LZ4) -12B4D   | $(LZ4) -t
515	$(DATAGEN) -g2M -P99   | $(LZ4) -11B4D   | $(LZ4) -t
516	$(DATAGEN) -g4M        | $(LZ4) -11vq    | $(LZ4) -qt
517	$(DATAGEN) -g8M        | $(LZ4) -11B4    | $(LZ4) -t
518	$(DATAGEN) -g16M -P90  | $(LZ4) -11B5    | $(LZ4) -t
519	$(DATAGEN) -g32M -P10  | $(LZ4) -11B5D   | $(LZ4) -t
520
521test-lz4-essentials : lz4 datagen test-lz4-basic test-lz4-multiple test-lz4-multiple-legacy \
522                      test-lz4-frame-concatenation test-lz4-testmode \
523                      test-lz4-contentSize test-lz4-dict
524
525test-lz4: lz4 datagen test-lz4-essentials test-lz4-opt-parser \
526          test-lz4-sparse test-lz4-hugefile test-lz4-dict \
527          test-lz4-skippable
528
529test-lz4c: LZ4C = $(LZ4)c
530test-lz4c: lz4c datagen
531	@echo "\n ---- test lz4c variant ----"
532	$(DATAGEN) -g256MB | $(LZ4C) -l -v | $(LZ4C) -t
533
534test-lz4c32: CFLAGS+=-m32
535test-lz4c32: test-lz4
536
537test-interop-32-64: lz4 lz4c32 datagen
538	@echo "\n ---- test interoperability 32-bits -vs- 64 bits ----"
539	$(DATAGEN) -g16KB  | $(LZ4)c32 -9     | $(LZ4)    -t
540	$(DATAGEN) -P10    | $(LZ4)    -9B4   | $(LZ4)c32 -t
541	$(DATAGEN)         | $(LZ4)c32        | $(LZ4)    -t
542	$(DATAGEN) -g1M    | $(LZ4)    -3B5   | $(LZ4)c32 -t
543	$(DATAGEN) -g256MB | $(LZ4)c32 -vqB4D | $(LZ4)    -qt
544	$(DATAGEN) -g1G -P90 | $(LZ4)         | $(LZ4)c32 -t
545	$(DATAGEN) -g6GB   | $(LZ4)c32 -vq9BD | $(LZ4)    -qt
546
547test-lz4c32-basic: lz4c32 datagen
548	@echo "\n ---- test lz4c32 32-bits version ----"
549	$(DATAGEN) -g16KB  | $(LZ4)c32 -9     | $(LZ4)c32 -t
550	$(DATAGEN)         | $(LZ4)c32        | $(LZ4)c32 -t
551	$(DATAGEN) -g256MB | $(LZ4)c32 -vqB4D | $(LZ4)c32 -qt
552	$(DATAGEN) -g6GB   | $(LZ4)c32 -vqB5D | $(LZ4)c32 -qt
553
554test-platform:
555	@echo "\n ---- test lz4 $(QEMU_SYS) platform ----"
556	$(QEMU_SYS) $(DATAGEN) -g16KB  | $(QEMU_SYS) $(LZ4) -9     | $(QEMU_SYS) $(LZ4) -t
557	$(QEMU_SYS) $(DATAGEN)         | $(QEMU_SYS) $(LZ4)        | $(QEMU_SYS) $(LZ4) -t
558	$(QEMU_SYS) $(DATAGEN) -g256MB | $(QEMU_SYS) $(LZ4) -vqB4D | $(QEMU_SYS) $(LZ4) -qt
559ifneq ($(QEMU_SYS),qemu-arm-static)
560	$(QEMU_SYS) $(DATAGEN) -g3GB   | $(QEMU_SYS) $(LZ4) -vqB5D | $(QEMU_SYS) $(LZ4) -qt
561endif
562
563test-fullbench: fullbench
564	./fullbench --no-prompt $(NB_LOOPS) $(TEST_FILES)
565
566test-fullbench32: CFLAGS += -m32
567test-fullbench32: test-fullbench
568
569test-fuzzer: fuzzer
570	./fuzzer $(FUZZER_TIME)
571
572test-fuzzer32: CFLAGS += -m32
573test-fuzzer32: test-fuzzer
574
575test-frametest: frametest
576	./frametest -v $(FUZZER_TIME)
577
578test-frametest32: CFLAGS += -m32
579test-frametest32: test-frametest
580
581VALGRIND = valgrind --leak-check=yes --error-exitcode=1
582test-mem: FPREFIX = tmp-tvm
583test-mem: lz4 datagen fuzzer frametest fullbench
584	@echo "\n ---- valgrind tests : memory analyzer ----"
585	$(VALGRIND) $(DATAGEN) -g50M > $(VOID)
586	$(DATAGEN) -g16KB > $(FPREFIX)dg16K
587	$(VALGRIND) $(LZ4) -9 -BD -f $(FPREFIX)dg16K $(VOID)
588	$(DATAGEN) -g16KB -s2 > $(FPREFIX)dg16K2
589	$(DATAGEN) -g16KB -s3 > $(FPREFIX)dg16K3
590	$(VALGRIND) $(LZ4) --force --multiple $(FPREFIX)dg16K $(FPREFIX)dg16K2 $(FPREFIX)dg16K3
591	$(DATAGEN) -g7MB > $(FPREFIX)dg7M
592	$(VALGRIND) $(LZ4) -9 -B5D -f $(FPREFIX)dg7M $(FPREFIX)dg16K2
593	$(VALGRIND) $(LZ4) -t $(FPREFIX)dg16K2
594	$(VALGRIND) $(LZ4) -bi1 $(FPREFIX)dg7M
595	$(VALGRIND) ./fullbench -i1 $(FPREFIX)dg7M $(FPREFIX)dg16K2
596	$(VALGRIND) $(LZ4) -B4D -f -vq $(FPREFIX)dg7M $(VOID)
597	$(VALGRIND) $(LZ4) --list -m $(FPREFIX)*.lz4
598	$(VALGRIND) $(LZ4) --list -m -v $(FPREFIX)*.lz4
599	$(RM) $(FPREFIX)*
600	$(VALGRIND) ./fuzzer -i64 -t1
601	$(VALGRIND) ./frametest -i256
602
603test-mem32: lz4c32 datagen
604# unfortunately, valgrind doesn't seem to work with non-native binary...
605
606test-decompress-partial : decompress-partial decompress-partial-usingDict
607	@echo "\n ---- test decompress-partial ----"
608	./decompress-partial$(EXT)
609	@echo "\n ---- test decompress-partial-usingDict ----"
610	./decompress-partial-usingDict$(EXT)
611
612test-freestanding: freestanding
613	@echo "\n ---- test freestanding ----"
614	./freestanding$(EXT)
615	-strace ./freestanding$(EXT)
616	-ltrace ./freestanding$(EXT)
617
618endif
619