1# ########################################################################## 2# LZ4 programs - Makefile 3# Copyright (C) Yann Collet 2011-2016 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 31DESTDIR ?= 32PREFIX ?= /usr/local 33BINDIR := $(PREFIX)/bin 34MANDIR := $(PREFIX)/share/man/man1 35LIBDIR := ../lib 36PRGDIR := ../programs 37VOID := /dev/null 38TESTDIR := versionsTest 39PYTHON ?= python3 40 41CFLAGS ?= -O3 # can select custom optimization flags. For example : CFLAGS=-O2 make 42CFLAGS += -g -Wall -Wextra -Wundef -Wcast-qual -Wcast-align -Wshadow -Wswitch-enum \ 43 -Wdeclaration-after-statement -Wstrict-prototypes \ 44 -Wpointer-arith -Wstrict-aliasing=1 45CFLAGS += $(MOREFLAGS) 46CPPFLAGS:= -I$(LIBDIR) -I$(PRGDIR) -DXXH_NAMESPACE=LZ4_ 47FLAGS = $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) 48 49 50# Define *.exe as extension for Windows systems 51ifneq (,$(filter Windows%,$(OS))) 52EXT =.exe 53else 54EXT = 55endif 56LZ4 := $(PRGDIR)/lz4$(EXT) 57 58 59# Default test parameters 60TEST_FILES := COPYING 61FUZZER_TIME := -T3mn 62NB_LOOPS ?= -i1 63 64 65default: all 66 67all: fullbench fuzzer frametest datagen fasttest 68 69all32: CFLAGS+=-m32 70all32: all 71 72lz4: 73 $(MAKE) -C $(PRGDIR) clean $@ CFLAGS="$(CFLAGS)" 74 75lz4c: 76 $(MAKE) -C $(PRGDIR) clean $@ CFLAGS="$(CFLAGS)" 77 78lz4c32: # create a 32-bits version for 32/64 interop tests 79 $(MAKE) -C $(PRGDIR) clean $@ CFLAGS="-m32 $(CFLAGS)" 80 cp $(LZ4) $(LZ4)c32 81 82fullbench : $(LIBDIR)/lz4.o $(LIBDIR)/lz4hc.o $(LIBDIR)/lz4frame.o $(LIBDIR)/xxhash.o fullbench.c 83 $(CC) $(FLAGS) $^ -o $@$(EXT) 84 85fullbench-lib: fullbench.c $(LIBDIR)/xxhash.c 86 $(MAKE) -C $(LIBDIR) liblz4.a 87 $(CC) $(FLAGS) $^ -o $@$(EXT) $(LIBDIR)/liblz4.a 88 89fullbench-dll: fullbench.c $(LIBDIR)/xxhash.c 90 $(MAKE) -C $(LIBDIR) liblz4 91 $(CC) $(FLAGS) $^ -o $@$(EXT) -DLZ4_DLL_IMPORT=1 $(LIBDIR)/dll/liblz4.dll 92 93fuzzer : $(LIBDIR)/lz4.o $(LIBDIR)/lz4hc.o $(LIBDIR)/xxhash.o fuzzer.c 94 $(CC) $(FLAGS) $^ -o $@$(EXT) 95 96frametest: $(LIBDIR)/lz4frame.o $(LIBDIR)/lz4.o $(LIBDIR)/lz4hc.o $(LIBDIR)/xxhash.o frametest.c 97 $(CC) $(FLAGS) $^ -o $@$(EXT) 98 99fasttest: $(LIBDIR)/lz4.o fasttest.c 100 $(CC) $(FLAGS) $^ -o $@$(EXT) 101 102datagen : $(PRGDIR)/datagen.c datagencli.c 103 $(CC) $(FLAGS) -I$(PRGDIR) $^ -o $@$(EXT) 104 105clean: 106 @$(MAKE) -C $(LIBDIR) $@ > $(VOID) 107 @$(MAKE) -C $(PRGDIR) $@ > $(VOID) 108 @$(RM) core *.o *.test tmp* \ 109 fullbench-dll$(EXT) fullbench-lib$(EXT) \ 110 fullbench$(EXT) fullbench32$(EXT) \ 111 fuzzer$(EXT) fuzzer32$(EXT) \ 112 frametest$(EXT) frametest32$(EXT) \ 113 fasttest$(EXT) datagen$(EXT) 114 @rm -fR $(TESTDIR) 115 @echo Cleaning completed 116 117.PHONY: versionsTest 118versionsTest: 119 $(PYTHON) test-lz4-versions.py 120 121 122#------------------------------------------------------------------------ 123#make test is validated only for Linux, OSX, kFreeBSD, FreeBSD, Hurd and 124#Solaris targets 125ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS)) 126 127MD5:=md5sum 128ifneq (,$(filter $(shell uname), Darwin )) 129MD5:=md5 -r 130endif 131 132DIFF:=diff 133ifneq (,$(filter $(shell uname),SunOS)) 134DIFF:=gdiff 135endif 136 137 138test: test-lz4 test-lz4c test-fasttest test-frametest test-fullbench test-fuzzer 139 140test32: CFLAGS+=-m32 141test32: test 142 143test-lz4-sparse: lz4 datagen 144 @echo "\n ---- test sparse file support ----" 145 ./datagen -g5M -P100 > tmpSrc 146 $(LZ4) -B4D tmpSrc | $(LZ4) -dv --sparse > tmpB4 147 $(DIFF) -s tmpSrc tmpB4 148 $(LZ4) -B5D tmpSrc | $(LZ4) -dv --sparse > tmpB5 149 $(DIFF) -s tmpSrc tmpB5 150 $(LZ4) -B6D tmpSrc | $(LZ4) -dv --sparse > tmpB6 151 $(DIFF) -s tmpSrc tmpB6 152 $(LZ4) -B7D tmpSrc | $(LZ4) -dv --sparse > tmpB7 153 $(DIFF) -s tmpSrc tmpB7 154 $(LZ4) tmpSrc | $(LZ4) -dv --no-sparse > tmpNoSparse 155 $(DIFF) -s tmpSrc tmpNoSparse 156 ls -ls tmp* 157 ./datagen -s1 -g1200007 -P100 | $(LZ4) | $(LZ4) -dv --sparse > tmpOdd # Odd size file (to generate non-full last block) 158 ./datagen -s1 -g1200007 -P100 | $(DIFF) -s - tmpOdd 159 ls -ls tmpOdd 160 @$(RM) tmp* 161 @echo "\n Compatibility with Console :" 162 echo "Hello World 1 !" | $(LZ4) | $(LZ4) -d -c 163 echo "Hello World 2 !" | $(LZ4) | $(LZ4) -d | cat 164 echo "Hello World 3 !" | $(LZ4) --no-frame-crc | $(LZ4) -d -c 165 @echo "\n Compatibility with Append :" 166 ./datagen -P100 -g1M > tmp1M 167 cat tmp1M tmp1M > tmp2M 168 $(LZ4) -B5 -v tmp1M tmpC 169 $(LZ4) -d -v tmpC tmpR 170 $(LZ4) -d -v tmpC >> tmpR 171 ls -ls tmp* 172 $(DIFF) tmp2M tmpR 173 @$(RM) tmp* 174 175test-lz4-contentSize: lz4 datagen 176 @echo "\n ---- test original size support ----" 177 ./datagen -g15M > tmp 178 $(LZ4) -v tmp | $(LZ4) -t 179 $(LZ4) -v --content-size tmp | $(LZ4) -d > tmp2 180 $(DIFF) -s tmp tmp2 181 # test large size [2-4] GB 182 @./datagen -g3G -P100 | $(LZ4) -vv | $(LZ4) --decompress --force --sparse - tmp 183 @ls -ls tmp 184 @./datagen -g3G -P100 | $(LZ4) --quiet --content-size | $(LZ4) --verbose --decompress --force --sparse - tmp2 185 @ls -ls tmp2 186 $(DIFF) -s tmp tmp2 187 @$(RM) tmp* 188 189test-lz4-frame-concatenation: lz4 datagen 190 @echo "\n ---- test frame concatenation ----" 191 @echo -n > empty.test 192 @echo hi > nonempty.test 193 cat nonempty.test empty.test nonempty.test > orig.test 194 @$(LZ4) -zq empty.test > empty.lz4.test 195 @$(LZ4) -zq nonempty.test > nonempty.lz4.test 196 cat nonempty.lz4.test empty.lz4.test nonempty.lz4.test > concat.lz4.test 197 $(LZ4) -d concat.lz4.test > result.test 198 sdiff orig.test result.test 199 @$(RM) *.test 200 @echo frame concatenation test completed 201 202test-lz4-multiple: lz4 datagen 203 @echo "\n ---- test multiple files ----" 204 @./datagen -s1 > tmp1 2> $(VOID) 205 @./datagen -s2 -g100K > tmp2 2> $(VOID) 206 @./datagen -s3 -g1M > tmp3 2> $(VOID) 207 $(LZ4) -f -m tmp* 208 ls -ls tmp* 209 @$(RM) tmp1 tmp2 tmp3 210 $(LZ4) -df -m *.lz4 211 ls -ls tmp* 212 $(LZ4) -f -m tmp1 notHere tmp2; echo $$? 213 @$(RM) tmp* 214 215unlz4: 216 @$(MAKE) -C $(PRGDIR) $@ CFLAGS="$(CFLAGS)" 217 218lz4cat: 219 @$(MAKE) -C $(PRGDIR) $@ CFLAGS="$(CFLAGS)" 220 221test-lz4-basic: lz4 datagen unlz4 lz4cat 222 @echo "\n ---- test lz4 basic compression/decompression ----" 223 ./datagen -g0 | $(LZ4) -v | $(LZ4) -t 224 ./datagen -g16KB | $(LZ4) -9 | $(LZ4) -t 225 ./datagen -g20KB > tmpSrc 226 $(LZ4) < tmpSrc | $(LZ4) -d > tmpRes 227 $(DIFF) -q tmpSrc tmpRes 228 $(LZ4) --no-frame-crc < tmpSrc | $(LZ4) -d > tmpRes 229 $(DIFF) -q tmpSrc tmpRes 230 ./datagen | $(LZ4) | $(LZ4) -t 231 ./datagen -g6M -P99 | $(LZ4) -9BD | $(LZ4) -t 232 ./datagen -g17M | $(LZ4) -9v | $(LZ4) -qt 233 ./datagen -g33M | $(LZ4) --no-frame-crc | $(LZ4) -t 234 ./datagen -g256MB | $(LZ4) -vqB4D | $(LZ4) -t 235 @echo "hello world" > tmp 236 $(LZ4) --rm -f tmp 237 ls -ls tmp && false || true # must fail (--rm) 238 ls -ls tmp.lz4 239 $(PRGDIR)/lz4cat tmp.lz4 # must display hello world 240 ls -ls tmp.lz4 241 $(PRGDIR)/unlz4 --rm tmp.lz4 242 ls -ls tmp 243 ls -ls tmp.lz4 && false || true # must fail (--rm) 244 ls -ls tmp.lz4.lz4 && false || true # must fail (unlz4) 245 $(PRGDIR)/lz4cat tmp # pass-through mode 246 ls -ls tmp 247 ls -ls tmp.lz4 && false || true # must fail (lz4cat) 248 $(LZ4) tmp # creates tmp.lz4 249 $(PRGDIR)/lz4cat < tmp.lz4 > tmp3 # checks lz4cat works with stdin (#285) 250 $(DIFF) -q tmp tmp3 251 $(PRGDIR)/lz4cat < tmp > tmp2 # checks lz4cat works with stdin (#285) 252 $(DIFF) -q tmp tmp2 253 @$(RM) tmp* 254 255test-lz4-hugefile: lz4 datagen 256 @echo "\n ---- test huge files compression/decompression ----" 257 ./datagen -g6GB | $(LZ4) -vB5D | $(LZ4) -qt 258 ./datagen -g6GB | $(LZ4) -v5BD | $(LZ4) -qt 259 @$(RM) tmp* 260 261test-lz4-testmode: lz4 datagen 262 @echo "\n ---- bench mode ----" 263 $(LZ4) -bi1 264 @echo "\n ---- test mode ----" 265 ./datagen | $(LZ4) -t && false || true 266 ./datagen | $(LZ4) -tf && false || true 267 @echo "\n ---- pass-through mode ----" 268 ./datagen | $(LZ4) -d > $(VOID) && false || true 269 ./datagen | $(LZ4) -df > $(VOID) 270 @echo "Hello World !" > tmp1 271 $(LZ4) -dcf tmp1 272 @echo "from underground..." > tmp2 273 $(LZ4) -dcfm tmp1 tmp2 274 @echo "\n ---- test cli ----" 275 $(LZ4) file-does-not-exist && false || true 276 $(LZ4) -f file-does-not-exist && false || true 277 $(LZ4) -fm file1-dne file2-dne && false || true 278 $(LZ4) -fm file1-dne file2-dne && false || true 279 280test-lz4-opt-parser: lz4 datagen 281 @echo "\n ---- test opt-parser ----" 282 ./datagen -g16KB | $(LZ4) -12 | $(LZ4) -t 283 ./datagen -P10 | $(LZ4) -12B4 | $(LZ4) -t 284 ./datagen -g256K | $(LZ4) -12B4D | $(LZ4) -t 285 ./datagen -g512K -P25 | $(LZ4) -12BD | $(LZ4) -t 286 ./datagen -g1M | $(LZ4) -12B5 | $(LZ4) -t 287 ./datagen -g2M -P99 | $(LZ4) -11B4D | $(LZ4) -t 288 ./datagen -g4M | $(LZ4) -11vq | $(LZ4) -qt 289 ./datagen -g8M | $(LZ4) -11B4 | $(LZ4) -t 290 ./datagen -g16M -P90 | $(LZ4) -11B5 | $(LZ4) -t 291 ./datagen -g32M -P10 | $(LZ4) -11B5D | $(LZ4) -t 292 293test-lz4: lz4 datagen test-lz4-opt-parser test-lz4-basic test-lz4-multiple test-lz4-sparse \ 294 test-lz4-frame-concatenation test-lz4-testmode test-lz4-contentSize \ 295 test-lz4-hugefile 296 297test-lz4c: lz4c datagen 298 @echo "\n ---- test lz4c version ----" 299 ./datagen -g256MB | $(LZ4)c -l -v | $(LZ4)c -t 300 301test-lz4c32: CFLAGS+=-m32 302test-lz4c32: test-lz4 303 304test-interop-32-64: lz4 lz4c32 datagen 305 @echo "\n ---- test interoperability 32-bits -vs- 64 bits ----" 306 ./datagen -g16KB | $(LZ4)c32 -9 | $(LZ4) -t 307 ./datagen -P10 | $(LZ4) -9B4 | $(LZ4)c32 -t 308 ./datagen | $(LZ4)c32 | $(LZ4) -t 309 ./datagen -g1M | $(LZ4) -3B5 | $(LZ4)c32 -t 310 ./datagen -g256MB | $(LZ4)c32 -vqB4D | $(LZ4) -qt 311 ./datagen -g1G -P90 | $(LZ4) | $(LZ4)c32 -t 312 ./datagen -g6GB | $(LZ4)c32 -vq9BD | $(LZ4) -qt 313 314test-lz4c32-basic: lz4c32 datagen 315 @echo "\n ---- test lz4c32 32-bits version ----" 316 ./datagen -g16KB | $(LZ4)c32 -9 | $(LZ4)c32 -t 317 ./datagen | $(LZ4)c32 | $(LZ4)c32 -t 318 ./datagen -g256MB | $(LZ4)c32 -vqB4D | $(LZ4)c32 -qt 319 ./datagen -g6GB | $(LZ4)c32 -vqB5D | $(LZ4)c32 -qt 320 321test-platform: 322 @echo "\n ---- test lz4 $(QEMU_SYS) platform ----" 323 $(QEMU_SYS) ./datagen -g16KB | $(QEMU_SYS) $(LZ4) -9 | $(QEMU_SYS) $(LZ4) -t 324 $(QEMU_SYS) ./datagen | $(QEMU_SYS) $(LZ4) | $(QEMU_SYS) $(LZ4) -t 325 $(QEMU_SYS) ./datagen -g256MB | $(QEMU_SYS) $(LZ4) -vqB4D | $(QEMU_SYS) $(LZ4) -qt 326ifneq ($(QEMU_SYS),qemu-arm-static) 327 $(QEMU_SYS) ./datagen -g3GB | $(QEMU_SYS) $(LZ4) -vqB5D | $(QEMU_SYS) $(LZ4) -qt 328endif 329 330test-fullbench: fullbench 331 ./fullbench --no-prompt $(NB_LOOPS) $(TEST_FILES) 332 333test-fullbench32: CFLAGS += -m32 334test-fullbench32: test-fullbench 335 336test-fuzzer: fuzzer 337 ./fuzzer $(FUZZER_TIME) 338 339test-fuzzer32: CFLAGS += -m32 340test-fuzzer32: test-fuzzer 341 342test-frametest: frametest 343 ./frametest $(FUZZER_TIME) 344 345test-frametest32: CFLAGS += -m32 346test-frametest32: test-frametest 347 348test-fasttest: fasttest 349 ./fasttest 350 351test-mem: lz4 datagen fuzzer frametest fullbench 352 @echo "\n ---- valgrind tests : memory analyzer ----" 353 valgrind --leak-check=yes --error-exitcode=1 ./datagen -g50M > $(VOID) 354 ./datagen -g16KB > tmp 355 valgrind --leak-check=yes --error-exitcode=1 $(LZ4) -9 -BD -f tmp $(VOID) 356 ./datagen -g16KB -s2 > tmp2 357 ./datagen -g16KB -s3 > tmp3 358 valgrind --leak-check=yes --error-exitcode=1 $(LZ4) --force --multiple tmp tmp2 tmp3 359 ./datagen -g16MB > tmp 360 valgrind --leak-check=yes --error-exitcode=1 $(LZ4) -9 -B5D -f tmp tmp2 361 valgrind --leak-check=yes --error-exitcode=1 $(LZ4) -t tmp2 362 valgrind --leak-check=yes --error-exitcode=1 $(LZ4) -bi1 tmp 363 valgrind --leak-check=yes --error-exitcode=1 ./fullbench -i1 tmp tmp2 364 ./datagen -g256MB > tmp 365 valgrind --leak-check=yes --error-exitcode=1 $(LZ4) -B4D -f -vq tmp $(VOID) 366 $(RM) tmp* 367 valgrind --leak-check=yes --error-exitcode=1 ./fuzzer -i64 -t1 368 valgrind --leak-check=yes --error-exitcode=1 ./frametest -i256 369 370test-mem32: lz4c32 datagen 371# unfortunately, valgrind doesn't seem to work with non-native binary... 372 373endif 374