~mmach/netext73/lz4

« back to all changes in this revision

Viewing changes to .pc/0002-Change-optimize-to-O2.patch/tests/Makefile

  • Committer: mmach
  • Date: 2022-11-09 18:52:10 UTC
  • Revision ID: netbit73@gmail.com-20221109185210-w358idlhh0phq688
1.9.4

Show diffs side-by-side

added added

removed removed

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