Home | History | Annotate | Download | only in tests
      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 
     31 DESTDIR ?=
     32 PREFIX  ?= /usr/local
     33 BINDIR  := $(PREFIX)/bin
     34 MANDIR  := $(PREFIX)/share/man/man1
     35 LIBDIR  := ../lib
     36 PRGDIR  := ../programs
     37 VOID    := /dev/null
     38 TESTDIR := versionsTest
     39 PYTHON  ?= python3
     40 
     41 CFLAGS  ?= -O3 # can select custom optimization flags. For example : CFLAGS=-O2 make
     42 CFLAGS  += -g -Wall -Wextra -Wundef -Wcast-qual -Wcast-align -Wshadow -Wswitch-enum \
     43            -Wdeclaration-after-statement -Wstrict-prototypes \
     44            -Wpointer-arith -Wstrict-aliasing=1
     45 CFLAGS  += $(MOREFLAGS)
     46 CPPFLAGS:= -I$(LIBDIR) -I$(PRGDIR) -DXXH_NAMESPACE=LZ4_
     47 FLAGS    = $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
     48 
     49 
     50 # Define *.exe as extension for Windows systems
     51 ifneq (,$(filter Windows%,$(OS)))
     52 EXT =.exe
     53 else
     54 EXT =
     55 endif
     56 LZ4     := $(PRGDIR)/lz4$(EXT)
     57 
     58 
     59 # Default test parameters
     60 TEST_FILES   := COPYING
     61 FUZZER_TIME  := -T3mn
     62 NB_LOOPS     ?= -i1
     63 
     64 
     65 default: all
     66 
     67 all: fullbench fuzzer frametest datagen fasttest
     68 
     69 all32: CFLAGS+=-m32
     70 all32: all
     71 
     72 lz4:
     73 	$(MAKE) -C $(PRGDIR) clean $@ CFLAGS="$(CFLAGS)"
     74 
     75 lz4c:
     76 	$(MAKE) -C $(PRGDIR) clean $@ CFLAGS="$(CFLAGS)"
     77 
     78 lz4c32:   # create a 32-bits version for 32/64 interop tests
     79 	$(MAKE) -C $(PRGDIR) clean $@ CFLAGS="-m32 $(CFLAGS)"
     80 	cp $(LZ4) $(LZ4)c32
     81 
     82 fullbench  : $(LIBDIR)/lz4.o $(LIBDIR)/lz4hc.o $(LIBDIR)/lz4frame.o $(LIBDIR)/xxhash.o fullbench.c
     83 	$(CC) $(FLAGS) $^ -o $@$(EXT)
     84 
     85 fullbench-lib: fullbench.c $(LIBDIR)/xxhash.c
     86 	$(MAKE) -C $(LIBDIR) liblz4.a
     87 	$(CC) $(FLAGS) $^ -o $@$(EXT) $(LIBDIR)/liblz4.a
     88 
     89 fullbench-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 
     93 fuzzer  : $(LIBDIR)/lz4.o $(LIBDIR)/lz4hc.o $(LIBDIR)/xxhash.o fuzzer.c
     94 	$(CC) $(FLAGS) $^ -o $@$(EXT)
     95 
     96 frametest: $(LIBDIR)/lz4frame.o $(LIBDIR)/lz4.o $(LIBDIR)/lz4hc.o $(LIBDIR)/xxhash.o frametest.c
     97 	$(CC) $(FLAGS) $^ -o $@$(EXT)
     98 
     99 fasttest: $(LIBDIR)/lz4.o fasttest.c
    100 	$(CC) $(FLAGS) $^ -o $@$(EXT)
    101 
    102 datagen : $(PRGDIR)/datagen.c datagencli.c
    103 	$(CC) $(FLAGS) -I$(PRGDIR) $^ -o $@$(EXT)
    104 
    105 clean:
    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
    118 versionsTest:
    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
    125 ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS))
    126 
    127 MD5:=md5sum
    128 ifneq (,$(filter $(shell uname), Darwin ))
    129 MD5:=md5 -r
    130 endif
    131 
    132 DIFF:=diff
    133 ifneq (,$(filter $(shell uname),SunOS))
    134 DIFF:=gdiff
    135 endif
    136 
    137 
    138 test: test-lz4 test-lz4c test-fasttest test-frametest test-fullbench test-fuzzer
    139 
    140 test32: CFLAGS+=-m32
    141 test32: test
    142 
    143 test-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 
    175 test-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 
    189 test-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 
    202 test-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 
    215 unlz4:
    216 	@$(MAKE) -C $(PRGDIR) $@ CFLAGS="$(CFLAGS)"
    217 
    218 lz4cat:
    219 	@$(MAKE) -C $(PRGDIR) $@ CFLAGS="$(CFLAGS)"
    220 
    221 test-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 
    255 test-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 
    261 test-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 
    280 test-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 
    293 test-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 
    297 test-lz4c: lz4c datagen
    298 	@echo "\n ---- test lz4c version ----"
    299 	./datagen -g256MB | $(LZ4)c -l -v    | $(LZ4)c   -t
    300 
    301 test-lz4c32: CFLAGS+=-m32
    302 test-lz4c32: test-lz4
    303 
    304 test-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 
    314 test-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 
    321 test-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
    326 ifneq ($(QEMU_SYS),qemu-arm-static)
    327 	$(QEMU_SYS) ./datagen -g3GB   | $(QEMU_SYS) $(LZ4) -vqB5D | $(QEMU_SYS) $(LZ4) -qt
    328 endif
    329 
    330 test-fullbench: fullbench
    331 	./fullbench --no-prompt $(NB_LOOPS) $(TEST_FILES)
    332 
    333 test-fullbench32: CFLAGS += -m32
    334 test-fullbench32: test-fullbench
    335 
    336 test-fuzzer: fuzzer
    337 	./fuzzer $(FUZZER_TIME)
    338 
    339 test-fuzzer32: CFLAGS += -m32
    340 test-fuzzer32: test-fuzzer
    341 
    342 test-frametest: frametest
    343 	./frametest $(FUZZER_TIME)
    344 
    345 test-frametest32: CFLAGS += -m32
    346 test-frametest32: test-frametest
    347 
    348 test-fasttest: fasttest
    349 	./fasttest
    350 
    351 test-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 
    370 test-mem32: lz4c32 datagen
    371 # unfortunately, valgrind doesn't seem to work with non-native binary...
    372 
    373 endif
    374