Skip to content

Commit c0b4673

Browse files
committed
streamline make clean list maintenance
When creating a new `Makefile` target to build, it's also necessary to update the `clean` target, which purpose is to remove built targets when they are present. This process is simple, but it's also easy to forget : since there is a large distance between the position in the `Makefile` where the new built target is added, and the place where the list of files to `clean` is defined. Moreover, the list of files becomes pretty long over time, hence it's difficult to visually ensure that all built targets are present there, or that no old target (no longer produced) is no longer in the list This PR tries to improve this process by adding a CLEAN variable. Now, when a new built target is added to the `Makefile`, it should preceded by : ``` CLEAN += newTarget newTarget: <TAB> ...recipe... ``` This new requirement is somewhat similar to `.PHONY: newTarget` for non-built targets. This new method offers the advantage of locality : there is no separate place in the file to maintain a list of files to clean. This makes maintenance of `make clean` easier.
1 parent 155d6a5 commit c0b4673

File tree

5 files changed

+49
-30
lines changed

5 files changed

+49
-30
lines changed

.github/workflows/dev-long-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ jobs:
157157
run: |
158158
sudo apt-get -qqq update
159159
make valgrindinstall
160-
make -C tests valgrindTest
160+
make -C tests test-valgrind
161161
make clean
162162
make -C tests test-fuzzer-stackmode
163163

.github/workflows/dev-short-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ jobs:
127127
sudo apt-get -qqq update
128128
make valgrindinstall
129129
make -C zlibWrapper test
130-
make -C zlibWrapper valgrindTest
130+
make -C zlibWrapper test-valgrind
131131
132132
lz4-threadpool-libs:
133133
runs-on: ubuntu-latest

TESTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ They consist of the following tests:
2222
- `tests/playTests.sh --test-large-data`
2323
- Fuzzer tests: `tests/fuzzer.c`, `tests/zstreamtest.c`, and `tests/decodecorpus.c`
2424
- `tests/zstreamtest.c` under Tsan (streaming mode, including multithreaded mode)
25-
- Valgrind Test (`make -C tests valgrindTest`) (testing CLI and fuzzer under valgrind)
25+
- Valgrind Test (`make -C tests test-valgrind`) (testing CLI and fuzzer under `valgrind`)
2626
- Fuzzer tests (see above) on ARM, AArch64, PowerPC, and PowerPC64
2727

2828
Long Tests

tests/Makefile

+42-24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
# ################################################################
2+
# ################################################################
33
# Copyright (c) Yann Collet, Facebook, Inc.
44
# All rights reserved.
55
#
@@ -37,7 +37,7 @@ TESTARTEFACT := versionsTest
3737
DEBUGFLAGS += -g -Wno-c++-compat
3838
CPPFLAGS += -I$(ZSTDDIR) -I$(ZSTDDIR)/common -I$(ZSTDDIR)/compress \
3939
-I$(ZSTDDIR)/dictBuilder -I$(ZSTDDIR)/deprecated -I$(PRGDIR) \
40-
-DZSTD_WINDOW_OVERFLOW_CORRECT_FREQUENTLY=1
40+
-DZSTD_WINDOW_OVERFLOW_CORRECT_FREQUENTLY=1
4141

4242
ZSTDCOMMON_FILES := $(sort $(ZSTD_COMMON_FILES))
4343
ZSTDCOMP_FILES := $(sort $(ZSTD_COMPRESS_FILES))
@@ -134,14 +134,17 @@ zstdmt_d_%.o : $(ZSTDDIR)/decompress/%.c
134134
zstdmt_d_%.o : $(ZSTDDIR)/decompress/%.S
135135
$(CC) -c $(CPPFLAGS) $(ASFLAGS) $< -o $@
136136

137+
FULLBENCHS := fullbench fullbench32
138+
CLEAN += $(FULLBENCHS)
137139
fullbench32: CPPFLAGS += -m32
138-
fullbench fullbench32 : CPPFLAGS += $(MULTITHREAD_CPP) -Wno-deprecated-declarations
139-
fullbench fullbench32 : LDFLAGS += $(MULTITHREAD_LD)
140-
fullbench fullbench32 : DEBUGFLAGS = -DNDEBUG # turn off assert() for speed measurements
141-
fullbench fullbench32 : $(ZSTD_FILES)
142-
fullbench fullbench32 : $(PRGDIR)/datagen.c $(PRGDIR)/util.c $(PRGDIR)/timefn.c $(PRGDIR)/benchfn.c fullbench.c
140+
$(FULLBENCHS) : CPPFLAGS += $(MULTITHREAD_CPP) -Wno-deprecated-declarations
141+
$(FULLBENCHS) : LDFLAGS += $(MULTITHREAD_LD)
142+
$(FULLBENCHS) : DEBUGFLAGS = -DNDEBUG # turn off assert() for speed measurements
143+
$(FULLBENCHS) : $(ZSTD_FILES)
144+
$(FULLBENCHS) : $(PRGDIR)/datagen.c $(PRGDIR)/util.c $(PRGDIR)/timefn.c $(PRGDIR)/benchfn.c fullbench.c
143145
$(LINK.c) $^ -o $@$(EXT)
144146

147+
CLEAN += fullbench-lib
145148
fullbench-lib : CPPFLAGS += -DXXH_NAMESPACE=ZSTD_
146149
fullbench-lib : $(PRGDIR)/datagen.c $(PRGDIR)/util.c $(PRGDIR)/timefn.c $(PRGDIR)/benchfn.c $(ZSTDDIR)/libzstd.a fullbench.c
147150
$(LINK.c) $^ -o $@$(EXT)
@@ -151,6 +154,7 @@ fullbench-dll: $(PRGDIR)/datagen.c $(PRGDIR)/util.c $(PRGDIR)/benchfn.c $(PRGDIR
151154
# $(CC) $(FLAGS) $(filter %.c,$^) -o $@$(EXT) -DZSTD_DLL_IMPORT=1 $(ZSTDDIR)/dll/libzstd.dll
152155
$(LINK.c) $^ $(LDLIBS) -o $@$(EXT)
153156

157+
CLEAN += fuzzer fuzzer32
154158
fuzzer : CPPFLAGS += $(MULTITHREAD_CPP) -Wno-deprecated-declarations
155159
fuzzer : LDFLAGS += $(MULTITHREAD_LD)
156160
fuzzer : $(ZSTDMT_OBJECTS)
@@ -164,6 +168,7 @@ fuzzer32 : $(ZSTD_FILES)
164168
fuzzer-dll : $(ZSTDDIR)/common/xxhash.c $(PRGDIR)/util.c $(PRGDIR)/timefn.c $(PRGDIR)/datagen.c fuzzer.c
165169
$(CC) $(CPPFLAGS) $(CFLAGS) $(filter %.c,$^) $(LDFLAGS) -o $@$(EXT)
166170

171+
CLEAN += zstreamtest zstreamtest32
167172
ZSTREAM_LOCAL_FILES := $(PRGDIR)/datagen.c $(PRGDIR)/util.c $(PRGDIR)/timefn.c seqgen.c zstreamtest.c
168173
ZSTREAM_PROPER_FILES := $(ZDICT_FILES) $(ZSTREAM_LOCAL_FILES)
169174
ZSTREAMFILES := $(ZSTD_FILES) $(ZSTREAM_PROPER_FILES)
@@ -175,10 +180,12 @@ zstreamtest32 : $(ZSTREAMFILES)
175180
zstreamtest zstreamtest32 :
176181
$(LINK.c) $^ -o $@$(EXT)
177182

183+
CLEAN += zstreamtest_asan
178184
zstreamtest_asan : CFLAGS += -fsanitize=address
179185
zstreamtest_asan : $(ZSTREAMFILES)
180186
$(LINK.c) $(MULTITHREAD) $^ -o $@$(EXT)
181187

188+
CLEAN += zstreamtest_tsan
182189
zstreamtest_tsan : CFLAGS += -fsanitize=thread
183190
zstreamtest_tsan : $(ZSTREAMFILES)
184191
$(LINK.c) $(MULTITHREAD) $^ -o $@$(EXT)
@@ -188,29 +195,38 @@ zstreamtest-dll : $(ZSTDDIR)/common/xxhash.c # xxh symbols not exposed from dll
188195
zstreamtest-dll : $(ZSTREAM_LOCAL_FILES)
189196
$(CC) $(CPPFLAGS) $(CFLAGS) $(filter %.c,$^) $(LDFLAGS) -o $@$(EXT)
190197

198+
CLEAN += paramgrill
191199
paramgrill : DEBUGFLAGS = # turn off debug for speed measurements
192200
paramgrill : LDLIBS += -lm
193201
paramgrill : $(ZSTD_FILES) $(PRGDIR)/util.c $(PRGDIR)/timefn.c $(PRGDIR)/benchfn.c $(PRGDIR)/benchzstd.c $(PRGDIR)/datagen.c paramgrill.c
194202

203+
CLEAN += datagen
195204
datagen : $(PRGDIR)/datagen.c datagencli.c
196205
$(LINK.c) $^ -o $@$(EXT)
197206

207+
CLEAN += roundTripCrash
198208
roundTripCrash: CFLAGS += $(MULTITHREAD)
199209
roundTripCrash : $(ZSTD_OBJECTS) roundTripCrash.c
200210

211+
CLEAN += longmatch
201212
longmatch : $(ZSTD_OBJECTS) longmatch.c
202213

214+
CLEAN += bigdict
203215
bigdict: CFLAGS += $(MULTITHREAD)
204216
bigdict: $(ZSTDMT_OBJECTS) $(PRGDIR)/datagen.c bigdict.c
205217

218+
CLEAN += invalidDictionaries
206219
invalidDictionaries : $(ZSTD_OBJECTS) invalidDictionaries.c
207220

221+
CLEAN += legacy
208222
legacy : CPPFLAGS += -I$(ZSTDDIR)/legacy -UZSTD_LEGACY_SUPPORT -DZSTD_LEGACY_SUPPORT=4
209223
legacy : $(ZSTD_FILES) $(sort $(wildcard $(ZSTDDIR)/legacy/*.c)) legacy.c
210224

225+
CLEAN += decodecorpus
211226
decodecorpus : LDLIBS += -lm
212227
decodecorpus : $(filter-out zstdc_zstd_compress.o, $(ZSTD_OBJECTS)) $(ZDICT_FILES) $(PRGDIR)/util.c $(PRGDIR)/timefn.c decodecorpus.c
213228

229+
CLEAN += poolTests
214230
poolTests : $(PRGDIR)/util.c $(PRGDIR)/timefn.c poolTests.c $(ZSTDDIR)/common/pool.c $(ZSTDDIR)/common/threading.c $(ZSTDDIR)/common/zstd_common.c $(ZSTDDIR)/common/error_private.c
215231
$(LINK.c) $(MULTITHREAD) $^ -o $@$(EXT)
216232

@@ -222,7 +238,8 @@ versionsTest: clean
222238
automated_benchmarking: clean
223239
$(PYTHON) automated_benchmarking.py
224240

225-
# make checkTag
241+
# make checkTag : check that release tag corresponds to release version
242+
CLEAN += checkTag
226243
checkTag.o : $(ZSTDDIR)/zstd.h
227244

228245
.PHONY: clean
@@ -231,28 +248,22 @@ clean:
231248
$(MAKE) -C $(PRGDIR) clean
232249
$(RM) -fR $(TESTARTEFACT)
233250
$(RM) -rf tmp* # some test directories are named tmp*
234-
$(RM) core *.o *.tmp result* *.gcda dictionary *.zst \
251+
$(RM) $(CLEAN) core *.o *.tmp result* *.gcda dictionary *.zst \
235252
$(PRGDIR)/zstd$(EXT) $(PRGDIR)/zstd32$(EXT) \
236-
fullbench$(EXT) fullbench32$(EXT) \
237-
fullbench-lib$(EXT) fullbench-dll$(EXT) \
238-
fuzzer$(EXT) fuzzer32$(EXT) \
239-
fuzzer-dll$(EXT) zstreamtest-dll$(EXT) \
240-
zstreamtest$(EXT) zstreamtest32$(EXT) \
241-
datagen$(EXT) paramgrill$(EXT) roundTripCrash$(EXT) longmatch$(EXT) \
242-
symbols$(EXT) invalidDictionaries$(EXT) legacy$(EXT) poolTests$(EXT) \
243-
decodecorpus$(EXT) checkTag$(EXT) bigdict$(EXT)
253+
fullbench-dll$(EXT) fuzzer-dll$(EXT) zstreamtest-dll$(EXT)
244254
@echo Cleaning completed
245255

246256

247257
#----------------------------------------------------------------------------------
248-
# valgrind tests are validated only for some posix platforms
258+
# valgrind tests validated only for some posix platforms
249259
#----------------------------------------------------------------------------------
250260
UNAME := $(shell uname)
251261
ifneq (,$(filter $(UNAME),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS AIX))
252262
HOST_OS = POSIX
253263

254-
valgrindTest: VALGRIND = valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1
255-
valgrindTest: zstd datagen fuzzer fullbench
264+
.PHONY: test-valgrind
265+
test-valgrind: VALGRIND = valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1
266+
test-valgrind: zstd datagen fuzzer fullbench
256267
@echo "\n ---- valgrind tests : memory analyzer ----"
257268
$(VALGRIND) ./datagen -g50M > $(VOID)
258269
$(VALGRIND) $(PRGDIR)/zstd ; if [ $$? -eq 0 ] ; then echo "zstd without argument should have failed"; false; fi
@@ -261,7 +272,7 @@ valgrindTest: zstd datagen fuzzer fullbench
261272
./datagen -g2930KB | $(VALGRIND) $(PRGDIR)/zstd -5 -vf - -o tmp
262273
$(VALGRIND) $(PRGDIR)/zstd -vdf tmp -c > $(VOID)
263274
./datagen -g64MB | $(VALGRIND) $(PRGDIR)/zstd -vf - -c > $(VOID)
264-
@rm tmp
275+
$(RM) tmp
265276
$(VALGRIND) ./fuzzer -T1mn -t1
266277
$(VALGRIND) ./fullbench -i1
267278

@@ -306,9 +317,9 @@ endif
306317
test32: test-zstd32 test-fullbench32 test-fuzzer32 test-zstream32
307318

308319
.PHONY: test-all
309-
test-all: test test32 valgrindTest test-decodecorpus-cli
320+
test-all: test test32 test-decodecorpus-cli
310321

311-
.PHONY: test-zstd test-zstd32 test-zstd-nolegacy test-zstdgrep
322+
.PHONY: test-zstd test-zstd32 test-zstd-nolegacy
312323
test-zstd: ZSTD = $(PRGDIR)/zstd
313324
test-zstd: zstd
314325

@@ -322,29 +333,36 @@ test-zstd test-zstd32 test-zstd-nolegacy: datagen
322333
file $(ZSTD)
323334
EXE_PREFIX="$(QEMU_SYS)" ZSTD_BIN="$(ZSTD)" DATAGEN_BIN=./datagen ./playTests.sh $(ZSTDRTTEST)
324335

336+
.PHONY: test-cli-tests
325337
test-cli-tests: ZSTD = $(PRGDIR)/zstd
326338
test-cli-tests: zstd datagen
327339
file $(ZSTD)
328340
./cli-tests/run.py --exec-prefix="$(QEMU_SYS)" --zstd="$(ZSTD)" --datagen=./datagen
329341

330-
342+
.PHONY: test-fullbench
331343
test-fullbench: fullbench datagen
332344
$(QEMU_SYS) ./fullbench -i1
333345
$(QEMU_SYS) ./fullbench -i1 -P0
334346

347+
.PHONY: test-fullbench32
335348
test-fullbench32: fullbench32 datagen
336349
$(QEMU_SYS) ./fullbench32 -i1
337350
$(QEMU_SYS) ./fullbench32 -i1 -P0
338351

352+
.PHONY: test-fuzzer
339353
test-fuzzer: fuzzer
340354
$(QEMU_SYS) ./fuzzer -v $(FUZZERTEST) $(FUZZER_FLAGS)
341355

356+
# Note : this test presumes `fuzzer` will be built
357+
.PHONY: test-fuzzer-stackmode
342358
test-fuzzer-stackmode: MOREFLAGS += -DZSTD_HEAPMODE=0
343359
test-fuzzer-stackmode: test-fuzzer
344360

361+
.PHONY: test-fuzzer32
345362
test-fuzzer32: fuzzer32
346363
$(QEMU_SYS) ./fuzzer32 -v $(FUZZERTEST) $(FUZZER_FLAGS)
347364

365+
.PHONY: test-zstream
348366
test-zstream: zstreamtest
349367
$(QEMU_SYS) ./zstreamtest -v $(ZSTREAM_TESTTIME) $(FUZZER_FLAGS)
350368
$(QEMU_SYS) ./zstreamtest --newapi -t1 $(ZSTREAM_TESTTIME) $(FUZZER_FLAGS)

zlibWrapper/Makefile

+4-3
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ test: example fitblk example_zstd fitblk_zstd zwrapbench minigzip minigzip_zstd
6666
./zwrapbench -qi1b3B1K $(TEST_FILE)
6767
./zwrapbench -rqi1b1e3 ../lib
6868

69-
#valgrindTest: ZSTDLIBRARY = $(ZSTDLIBDIR)/libzstd.so
70-
valgrindTest: VALGRIND = LD_LIBRARY_PATH=$(ZSTDLIBDIR) valgrind --track-origins=yes --leak-check=full --error-exitcode=1
71-
valgrindTest: clean example fitblk example_zstd fitblk_zstd zwrapbench
69+
.PHONY: test-valgrind
70+
#test-valgrind: ZSTDLIBRARY = $(ZSTDLIBDIR)/libzstd.so
71+
test-valgrind: VALGRIND = LD_LIBRARY_PATH=$(ZSTDLIBDIR) valgrind --track-origins=yes --leak-check=full --error-exitcode=1
72+
test-valgrind: clean example fitblk example_zstd fitblk_zstd zwrapbench
7273
@echo "\n ---- valgrind tests ----"
7374
$(VALGRIND) ./example
7475
$(VALGRIND) ./example_zstd

0 commit comments

Comments
 (0)