Makefile 25 KB

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