forked from xpol/lua-rapidjson
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
62 lines (60 loc) · 1.46 KB
/
Copy pathMakefile
File metadata and controls
62 lines (60 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
.PHONY: fuzz
LUA ?= lua
DURATION ?= 3600
INTERVAL ?= 5
WORKERS ?= 1
SEED ?= $(shell date +%s)
SORT_KEYS ?= 1
SAMPLE_INTERVAL ?= 0
SAMPLE_LIMIT ?=
fuzz:
@set -u; \
tmpdir=$$(mktemp -d "$${TMPDIR:-/tmp}/lua-rapidjson-fuzz.XXXXXX"); \
pids=""; \
cleanup() { rm -rf "$$tmpdir"; }; \
stop_workers() { for pid in $$pids; do kill "$$pid" 2>/dev/null || true; done; cleanup; }; \
trap cleanup EXIT; \
trap stop_workers INT TERM; \
worker=1; \
while [ "$$worker" -le "$(WORKERS)" ]; do \
seed=$$(( $(SEED) + $$worker - 1 )); \
( \
DURATION="$(DURATION)" \
INTERVAL="$(INTERVAL)" \
WORKERS="$(WORKERS)" \
WORKER_ID="$$worker" \
SEED="$$seed" \
SORT_KEYS="$(SORT_KEYS)" \
SAMPLE_INTERVAL="$(SAMPLE_INTERVAL)" \
SAMPLE_LIMIT="$(SAMPLE_LIMIT)" \
"$(LUA)" tools/fuzz_encode.lua; \
rc=$$?; \
if [ "$$rc" -ne 0 ]; then \
echo "$$rc" > "$$tmpdir/fail.$$worker"; \
fi; \
echo "$$rc" > "$$tmpdir/done.$$worker"; \
) & \
pids="$$pids $$!"; \
worker=$$(( $$worker + 1 )); \
done; \
status=0; \
while :; do \
if ls "$$tmpdir"/fail.* >/dev/null 2>&1; then \
status=1; \
for pid in $$pids; do \
kill "$$pid" 2>/dev/null || true; \
done; \
break; \
fi; \
done_count=$$(ls "$$tmpdir"/done.* 2>/dev/null | wc -l | tr -d ' '); \
if [ "$$done_count" -ge "$(WORKERS)" ]; then \
break; \
fi; \
sleep 1; \
done; \
for pid in $$pids; do \
if ! wait "$$pid" 2>/dev/null; then \
status=1; \
fi; \
done; \
exit "$$status"