xref: /aosp_15_r20/external/lz4/tests/Makefile (revision 27162e4e17433d5aa7cb38e7b6a433a09405fc7f)
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
31LIBDIR  := ../lib
32PRGDIR  := ../programs
33TESTDIR := versionsTest
34PYTHON  ?= python3
35
36DEBUGLEVEL?= 1
37DEBUGFLAGS = -g -DLZ4_DEBUG=$(DEBUGLEVEL)
38USERCFLAGS:= -O3 $(CFLAGS) # appended for higher priority
39WFLAGS    = -Wall -Wextra -Wundef -Wcast-qual -Wcast-align -Wshadow \
40            -Wswitch-enum -Wdeclaration-after-statement -Wstrict-prototypes \
41            -Wpointer-arith -Wstrict-aliasing=1
42CFLAGS    = $(WFLAGS) $(DEBUGFLAGS) $(USERCFLAGS)
43CPPFLAGS += -I$(LIBDIR) -I$(PRGDIR) -DXXH_NAMESPACE=LZ4_
44ALLFLAGS  = $(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
59.PHONY: all
60all: fullbench fuzzer frametest roundTripTest datagen checkFrame decompress-partial
61
62.PHONY: all32
63all32: CFLAGS+=-m32
64all32: all
65
66.PHONY: lz4
67lz4:
68	$(MAKE) -C $(PRGDIR) $@ CFLAGS="$(CFLAGS)"
69
70.PHONY: lib liblz4.pc
71lib liblz4.pc:
72	$(MAKE) -C $(LIBDIR) $@ CFLAGS="$(CFLAGS)"
73
74lz4c unlz4 lz4cat: lz4
75	$(LN_SF) $(LZ4) $(PRGDIR)/$@
76
77.PHONY: lz4c32
78lz4c32:  # create a 32-bits version for 32/64 interop tests
79	$(MAKE) -C $(PRGDIR) $@ CFLAGS="-m32 $(CFLAGS)"
80
81# *.o objects are from library
82%.o : $(LIBDIR)/%.c $(LIBDIR)/%.h
83	$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
84
85CLEAN += fullbench
86fullbench : DEBUGLEVEL=0
87fullbench : CPPFLAGS += -DNDEBUG
88fullbench : lz4.o lz4hc.o lz4frame.o xxhash.o fullbench.c
89	$(CC) $(ALLFLAGS) $^ -o $@$(EXT)
90
91.PHONY: $(LIBDIR)/liblz4.a
92$(LIBDIR)/liblz4.a:
93	$(MAKE) -C $(LIBDIR) liblz4.a
94
95CLEAN += fullbench-lib
96fullbench-lib : DEBUGLEVEL=0
97fullbench-lib : CPPFLAGS += -DNDEBUG
98fullbench-lib: fullbench.c $(LIBDIR)/liblz4.a
99	$(CC) $(ALLFLAGS) $^ -o $@$(EXT)
100
101# Note: Windows only
102ifeq ($(WINBASED),yes)
103CLEAN += fullbench-dll
104fullbench-dll : DEBUGLEVEL=0
105fullbench-dll : CPPFLAGS += -DNDEBUG
106fullbench-dll: fullbench.c $(LIBDIR)/xxhash.c
107	$(MAKE) -C $(LIBDIR) liblz4
108	$(CC) $(ALLFLAGS) $^ -o $@$(EXT) -DLZ4_DLL_IMPORT=1 $(LIBDIR)/dll/$(LIBLZ4).dll
109endif
110
111# test LZ4_USER_MEMORY_FUNCTIONS
112fullbench-wmalloc: CPPFLAGS += -DLZ4_USER_MEMORY_FUNCTIONS
113fullbench-wmalloc: fullbench
114
115CLEAN += fuzzer
116fuzzer  : lz4.o lz4hc.o xxhash.o fuzzer.c
117	$(CC) $(ALLFLAGS) $^ -o $@$(EXT)
118
119CLEAN += frametest
120frametest: lz4frame.o lz4.o lz4hc.o xxhash.o frametest.c
121	$(CC) $(ALLFLAGS) $^ -o $@$(EXT)
122
123CLEAN += roundTripTest
124roundTripTest : lz4.o lz4hc.o xxhash.o roundTripTest.c
125	$(CC) $(ALLFLAGS) $^ -o $@$(EXT)
126
127CLEAN += datagen
128datagen: CPPFLAGS+=-DNDEBUG
129datagen : datagen.c $(PRGDIR)/lorem.c loremOut.c datagencli.c
130	$(CC) $(ALLFLAGS) -I$(PRGDIR) $^ -o $@$(EXT)
131
132CLEAN += checkFrame
133checkFrame : lz4frame.o lz4.o lz4hc.o xxhash.o checkFrame.c
134	$(CC) $(ALLFLAGS) $^ -o $@$(EXT)
135
136CLEAN += decompress-partial
137decompress-partial: lz4.o decompress-partial.c
138	$(CC) $(ALLFLAGS) $^ -o $@$(EXT)
139
140CLEAN += decompress-partial-usingDict
141decompress-partial-usingDict: lz4.o decompress-partial-usingDict.c
142	$(CC) $(ALLFLAGS) $^ -o $@$(EXT)
143
144.PHONY: clean
145clean:
146	@$(MAKE) -C $(LIBDIR) $@ > $(VOID)
147	@$(MAKE) -C $(PRGDIR) $@ > $(VOID)
148	@$(RM) $(CLEAN) core *.o *.test tmp*
149	@$(RM) -r $(TESTDIR)
150	@echo Cleaning completed
151
152.PHONY: versionsTest
153versionsTest:
154	$(PYTHON) test-lz4-versions.py
155
156.PHONY: listTest
157listTest: lz4
158	QEMU_SYS=$(QEMU_SYS) $(PYTHON) test-lz4-list.py
159
160# Note: requires liblz4 installed
161CLEAN += abiTest
162abiTest: LDLIBS += -llz4
163
164.PHONY: abiTests
165abiTests:
166	$(PYTHON) test-lz4-abi.py
167
168CLEAN += checkTag
169checkTag: checkTag.c $(LIBDIR)/lz4.h
170	$(CC) $(ALLFLAGS) $< -o $@$(EXT)
171
172#-----------------------------------------------------------------------------
173# validated only for Linux, OSX, BSD, Hurd and Solaris targets
174#-----------------------------------------------------------------------------
175ifeq ($(POSIX_ENV),Yes)
176
177MD5 ?= $(if $(filter Darwin,$(shell $(UNAME))),md5 -r,md5sum)
178GREP?= grep
179CAT ?= cat
180DATAGEN?=./datagen
181PATH:=../programs:$(shell pwd):$(PATH)
182
183.PHONY: list
184list:
185	$(GREP) '^[^#[:space:]].*:' Makefile | sed 's/:.*//' | sort | uniq
186
187ifneq ($(TARGETSEARCH),NO)
188ALL_TARGETS := $(shell make list TARGETSEARCH=NO)
189endif
190TEST_TARGETS := $(filter test%,$(ALL_TARGETS))
191.PHONY: $(TEST_TARGETS) # all targets starting by `test` are now .PHONY
192
193test_targets:
194	@echo TEST_TARGETS = $(TEST_TARGETS)
195
196.PHONY: check
197check: test-lz4-essentials
198
199test: test-lz4 test-lz4c test-frametest test-fullbench test-fuzzer test-amalgamation listTest test-decompress-partial
200
201test32: CFLAGS+=-m32
202test32: test
203
204test-amalgamation: lz4_all.o
205
206CLEAN += lz4_all.c
207lz4_all.c: $(LIBDIR)/lz4.c $(LIBDIR)/lz4hc.c $(LIBDIR)/lz4frame.c
208	$(CAT) $^ > $@
209
210test-install: lz4 lib liblz4.pc
211	lz4_root=.. ./test_install.sh
212
213test-compile-with-lz4-memory-usage:
214	$(MAKE) clean; CFLAGS=-O0 CPPFLAGS=-D'LZ4_MEMORY_USAGE=LZ4_MEMORY_USAGE_MIN' $(MAKE) all
215	$(MAKE) clean; CFLAGS=-O0 CPPFLAGS=-D'LZ4_MEMORY_USAGE=LZ4_MEMORY_USAGE_MAX' $(MAKE) all
216
217# Rules regarding Temporary test files :
218# Each test must use its own unique set of names during execution.
219# Each temporary test file must begin by an FPREFIX.
220# Each FPREFIX must be unique for each test.
221# All FPREFIX must start with `tmp`, for `make clean`
222# All tests must clean their temporary test files on successful completion,
223# and only their test files : do not employ sweeping statements such `rm tmp*` or `rm *.lz4`
224test-lz4-sparse: lz4 datagen
225	@echo "\n ---- test sparse file support ----"
226	./test-lz4-sparse.sh
227
228test-lz4-contentSize: lz4 datagen
229	@echo "\n ---- test original size support ----"
230	./test-lz4-contentSize.sh
231
232test-lz4-frame-concatenation: lz4 datagen
233	@echo "\n ---- test frame concatenation ----"
234	./test-lz4-frame-concatenation.sh
235
236test-lz4-multiple: lz4 datagen
237	@echo "\n ---- test multiple files ----"
238	./test-lz4-multiple.sh
239
240test-lz4-multiple-legacy: lz4 datagen
241	@echo "\n ---- test multiple files (Legacy format) ----"
242	./test-lz4-multiple-legacy.sh
243
244test-lz4-skippable: lz4
245	@echo "\n ---- test lz4 with skippable frames ----"
246	./test-lz4-skippable.sh
247
248test-lz4-basic: lz4 datagen unlz4 lz4cat
249	@echo "\n ---- test lz4 basic compression/decompression ----"
250	./test-lz4-basic.sh
251
252test-lz4-dict: lz4 datagen
253	@echo "\n ---- test lz4 compression/decompression with dictionary ----"
254	./test-lz4-dict.sh
255
256test-lz4hc-hugefile: lz4 datagen
257	@echo "\n ---- test HC compression/decompression of huge files ----"
258	./test-lz4hc-hugefile.sh
259
260test-lz4-fast-hugefile: lz4 datagen
261	@echo "\n ---- test huge files compression/decompression ----"
262	./test-lz4-fast-hugefile.sh
263
264test-lz4-hugefile: test-lz4-fast-hugefile test-lz4hc-hugefile
265
266test-lz4-testmode: lz4 datagen
267	@echo "\n ---- bench mode ----"
268	./test-lz4-testmode.sh
269
270test-lz4-opt-parser: lz4 datagen
271	@echo "\n ---- test opt-parser ----"
272	./test-lz4-opt-parser.sh
273
274test-lz4-essentials : lz4 datagen test-lz4-basic test-lz4-multiple test-lz4-multiple-legacy \
275                      test-lz4-frame-concatenation test-lz4-testmode \
276                      test-lz4-contentSize test-lz4-dict
277
278test-lz4: lz4 datagen test-lz4-essentials test-lz4-opt-parser \
279          test-lz4-sparse test-lz4-hugefile test-lz4-dict \
280          test-lz4-skippable
281
282test-lz4c: LZ4C = $(LZ4)c
283test-lz4c: lz4c datagen
284	@echo "\n ---- test lz4c variant ----"
285	$(DATAGEN) -g256MB | $(LZ4C) -l -v | $(LZ4C) -t
286
287test-lz4c32: CFLAGS+=-m32
288test-lz4c32: test-lz4
289
290test-interop-32-64: lz4 lz4c32 datagen
291	@echo "\n ---- test interoperability 32-bits -vs- 64 bits ----"
292	$(DATAGEN) -g16KB  | $(LZ4)c32 -9     | $(LZ4)    -t
293	$(DATAGEN) -P10    | $(LZ4)    -9B4   | $(LZ4)c32 -t
294	$(DATAGEN)         | $(LZ4)c32        | $(LZ4)    -t
295	$(DATAGEN) -g1M    | $(LZ4)    -3B5   | $(LZ4)c32 -t
296	$(DATAGEN) -g256MB | $(LZ4)c32 -vqB4D | $(LZ4)    -qt
297	$(DATAGEN) -g1G -P90 | $(LZ4)         | $(LZ4)c32 -t
298	$(DATAGEN) -g6GB   | $(LZ4)c32 -vq9BD | $(LZ4)    -qt
299
300test-lz4c32-basic: lz4c32 datagen
301	@echo "\n ---- test lz4c32 32-bits version ----"
302	$(DATAGEN) -g16KB  | $(LZ4)c32 -9     | $(LZ4)c32 -t
303	$(DATAGEN)         | $(LZ4)c32        | $(LZ4)c32 -t
304	$(DATAGEN) -g256MB | $(LZ4)c32 -vqB4D | $(LZ4)c32 -qt
305	$(DATAGEN) -g6GB   | $(LZ4)c32 -vqB5D | $(LZ4)c32 -qt
306
307test-platform:
308	@echo "\n ---- test lz4 $(QEMU_SYS) platform ----"
309	$(QEMU_SYS) $(DATAGEN) -g16KB  | $(QEMU_SYS) $(LZ4) -9     | $(QEMU_SYS) $(LZ4) -t
310	$(QEMU_SYS) $(DATAGEN)         | $(QEMU_SYS) $(LZ4)        | $(QEMU_SYS) $(LZ4) -t
311	$(QEMU_SYS) $(DATAGEN) -g256MB | $(QEMU_SYS) $(LZ4) -vqB4D | $(QEMU_SYS) $(LZ4) -qt
312ifneq ($(QEMU_SYS),qemu-arm-static)
313	$(QEMU_SYS) $(DATAGEN) -g3GB   | $(QEMU_SYS) $(LZ4) -vqB5D | $(QEMU_SYS) $(LZ4) -qt
314endif
315
316test-fullbench: fullbench
317	./fullbench --no-prompt $(NB_LOOPS) $(TEST_FILES)
318
319test-fullbench32: CFLAGS += -m32
320test-fullbench32: test-fullbench
321
322test-fuzzer: fuzzer
323	./fuzzer $(FUZZER_TIME)
324
325test-fuzzer32: CFLAGS += -m32
326test-fuzzer32: test-fuzzer
327
328test-frametest: frametest
329	./frametest -v $(FUZZER_TIME)
330
331test-frametest32: CFLAGS += -m32
332test-frametest32: test-frametest
333
334VALGRIND = valgrind --leak-check=yes --error-exitcode=1
335test-mem: FPREFIX = tmp-tvm
336test-mem: lz4 datagen fuzzer frametest fullbench
337	@echo "\n ---- valgrind tests : memory analyzer ----"
338	$(VALGRIND) $(DATAGEN) -g50M > $(VOID)
339	$(DATAGEN) -g16KB > $(FPREFIX)dg16K
340	$(VALGRIND) $(LZ4) -9 -BD -f $(FPREFIX)dg16K $(VOID)
341	$(DATAGEN) -g16KB -s2 > $(FPREFIX)dg16K2
342	$(DATAGEN) -g16KB -s3 > $(FPREFIX)dg16K3
343	$(VALGRIND) $(LZ4) --force --multiple $(FPREFIX)dg16K $(FPREFIX)dg16K2 $(FPREFIX)dg16K3
344	$(DATAGEN) -g7MB > $(FPREFIX)dg7M
345	$(VALGRIND) $(LZ4) -9 -B5D -f $(FPREFIX)dg7M $(FPREFIX)dg16K2
346	$(VALGRIND) $(LZ4) -t $(FPREFIX)dg16K2
347	$(VALGRIND) $(LZ4) -bi1 $(FPREFIX)dg7M
348	$(VALGRIND) ./fullbench -i1 $(FPREFIX)dg7M $(FPREFIX)dg16K2
349	$(VALGRIND) $(LZ4) -B4D -f -vq $(FPREFIX)dg7M $(VOID)
350	$(VALGRIND) $(LZ4) --list -m $(FPREFIX)*.lz4
351	$(VALGRIND) $(LZ4) --list -m -v $(FPREFIX)*.lz4
352	$(RM) $(FPREFIX)*
353	$(VALGRIND) ./fuzzer -i64 -t1
354	$(VALGRIND) ./frametest -i256
355
356test-mem32: lz4c32 datagen
357# unfortunately, valgrind doesn't seem to work with non-native binary...
358
359test-decompress-partial : decompress-partial decompress-partial-usingDict
360	@echo "\n ---- test decompress-partial ----"
361	./decompress-partial$(EXT)
362	@echo "\n ---- test decompress-partial-usingDict ----"
363	./decompress-partial-usingDict$(EXT)
364
365
366#-----------------------------------------------------------------------------
367# freestanding test only for Linux x86_64
368#-----------------------------------------------------------------------------
369UNAME_S ?= $(if $(filter Windows_NT,$(OS)),Windows,$(shell uname -s))
370UNAME_P ?= $(if $(filter Windows_NT,$(OS)),Unknown,$(shell uname -p))
371
372FREESTANDING_CFLAGS := -ffreestanding -nostdlib
373
374ifneq ($(UNAME_S), Linux)
375  FREESTANDING_CFLAGS :=
376endif
377
378ifneq ($(UNAME_P), x86_64)
379  FREESTANDING_CFLAGS :=
380endif
381
382CLEAN += freestanding
383freestanding: freestanding.c
384	$(CC) $(FREESTANDING_CFLAGS) $^ -o $@$(EXT)
385
386test-freestanding: freestanding
387	@echo "\n ---- test freestanding ----"
388ifeq ($(FREESTANDING_CFLAGS),)
389	@echo "\n (skip)"
390else
391	./freestanding$(EXT)
392	-strace ./freestanding$(EXT)
393	-ltrace ./freestanding$(EXT)
394endif
395
396
397endif
398