Skip to content

Commit a81a43d

Browse files
committed
refactor fuzzing jobs
1 parent a6fbf10 commit a81a43d

18 files changed

+59
-38
lines changed

.github/workflows/run_fuzzer.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,9 @@ jobs:
6363
cxxstd: 17
6464
targets: libs/json/fuzzing//run
6565
- name: Pack the corpus
66-
working-directory: boost-root/libs/json/fuzzing/
66+
working-directory: boost-root/libs/json/fuzzing/cmin
6767
run: |
68-
tar cf - cmin > corpus.tar.tmp && mv corpus.tar.tmp "${GITHUB_WORKSPACE}"/head/fuzzing
69-
- name: Save the corpus as a github artifact
70-
uses: actions/upload-artifact@v4
71-
if: success()
72-
with:
73-
name: corpus
74-
path: head/fuzzing/corpus.tar
68+
tar cf - * > "$GITHUB_WORKSPACE"/head/fuzzing/corpus.tar
7569
- name: Archive any crashes as an artifact
7670
uses: actions/upload-artifact@v4
7771
if: always()

fuzzing/Jamfile

Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,31 @@ import testing ;
3939
] ;
4040

4141
local corpus.tar = [ glob-ex . : corpus.tar ] ;
42+
local test-corpus ;
4243
if $(corpus.tar)
4344
{
4445
# if an old corpus exists, use it
45-
# get it with curl -O --location -J https://bintray.com/pauldreik/boost.json/download_file?file_path=corpus%2Fcorpus.tar
4646
make old-corpus
4747
: $(corpus.tar)
4848
: @untar-corpus
4949
: <location>oldcorpus
5050
;
51+
explicit old-corpus ;
5152
}
5253
else
5354
{
54-
alias old-corpus ;
55+
test-corpus = [ glob-tree-ex ../test : *.json ] ;
5556
}
56-
explicit old-corpus ;
57-
58-
59-
local initial-corpus = [ glob-tree-ex ../test : *.json ] ;
6057

58+
local old-runs = [ SORT [ glob-tree-ex old_crashes : * ] ] ;
59+
make old_crashes : : @mkdir : <location>. ;
60+
explicit old_crashes ;
6161

6262
local variants = basic_parser parse parser direct_parse ;
6363
for local variant in basic_parser parse parser direct_parse
6464
{
6565
local $(variant)-runs ;
6666
local fuzzer = fuzzer_$(variant) ;
67-
lib $(fuzzer) : fuzz_$(variant).cpp /boost/json//boost_json ;
6867
exe $(fuzzer)
6968
: fuzz_$(variant).cpp /boost/json//json_sources
7069
: requirements
@@ -73,44 +72,44 @@ for local variant in basic_parser parse parser direct_parse
7372
;
7473

7574
# make sure the old crashes pass without problems
76-
local old-runs = [ glob-tree-ex old_crashes/$(variant) : * ] ;
7775
if $(old-runs)
7876
{
7977
run $(fuzzer)
8078
: target-name $(variant)-run-crashes
81-
: input-files [ SORT $(old-runs) ]
79+
: input-files $(old-runs)
8280
;
81+
explicit $(variant)-run-crashes ;
8382
$(variant)-runs += $(variant)-run-crashes ;
8483
}
8584

86-
make oldcorpus/$(variant)
87-
: old-corpus
88-
: common.MkDir
89-
: <location>.
90-
;
91-
explicit oldcorpus/$(variant) ;
92-
93-
# make an initial corpus from the test data already in the repo
94-
local seed-corpus ;
95-
for file in $(initial-corpus)
85+
local old-corpus-deps ;
86+
if $(corpus.tar)
9687
{
97-
local copied = $(variant)/$(file:D=) ;
98-
make $(copied) : $(file) : common.copy : <location>seedcorpus ;
99-
explicit $(copied) ;
100-
seed-corpus += $(copied) ;
88+
old-corpus-deps = old-corpus ;
10189
}
102-
make seedcorpus/$(variant)
103-
: $(seed-corpus)
104-
: common.MkDir
90+
else
91+
{
92+
# make an initial corpus from the test data already in the repo
93+
for file in $(test-corpus)
94+
{
95+
local copied = $(variant)/$(file:D=) ;
96+
make $(copied) : $(file) : common.copy : <location>oldcorpus ;
97+
explicit $(copied) ;
98+
old-corpus-deps += $(copied) ;
99+
}
100+
}
101+
make oldcorpus/$(variant)
102+
: $(old-corpus-deps)
103+
: @mkdir
105104
: <location>.
106105
;
107-
explicit seedcorpus/$(variant) ;
106+
explicit oldcorpus/$(variant) ;
108107

109108
# run the fuzzer for a short while
110109
make out/$(variant)
111110
: $(fuzzer)
112111
oldcorpus/$(variant)
113-
seedcorpus/$(variant)
112+
old_crashes
114113
: @run-fuzzer
115114
: <location>.
116115
<flags>$(.MAXTIME)
@@ -122,8 +121,9 @@ for local variant in basic_parser parse parser direct_parse
122121
# minimize the corpus
123122
make cmin/$(variant)
124123
: $(fuzzer)
125-
oldcorpus/$(variant)
126124
out/$(variant)
125+
oldcorpus/$(variant)
126+
old_crashes
127127
: @run-fuzzer
128128
: <location>.
129129
<flags>-merge=1
@@ -139,6 +139,13 @@ alias run : $(variants)-run ;
139139
explicit run $(variants)-run ;
140140

141141

142+
rule mkdir ( target : source * : props * )
143+
{
144+
local dir = [ path.make [ on $(target) return $(LOCATE) ] ] ;
145+
dir = [ path.join $(dir) $(target:G=) ] ;
146+
common.MkDir $(dir) ;
147+
}
148+
142149
rule fuzzer-props ( props * )
143150
{
144151
local toolset = [ property.select toolset : $(props) ] ;
@@ -169,16 +176,36 @@ rule run-fuzzer ( target : sources * : props * )
169176
local flags = [ property.select flags : $(props) ] ;
170177
FLAGS on $(target) = $(flags:G=) ;
171178

179+
LOG on $(target) = [ path.native [ path.join $(target) _log ] ] ;
180+
172181
local dir = [ path.make [ on $(target) return $(LOCATE) ] ] ;
173182
dir = $(dir)/$(target:G=) ;
174183
common.MkDir $(dir) ;
175184
DEPENDS $(target) : $(dir) ;
185+
186+
LOG on $(target) = [ path.native [ path.join $(dir) _log ] ] ;
176187
}
177188

189+
.SET_STATUS = [ modules.peek testing : .SET_STATUS ] ;
190+
.STATUS = [ modules.peek testing : .STATUS ] ;
191+
.RUN_OUTPUT_NL = [ modules.peek testing : .RUN_OUTPUT_NL ] ;
192+
.STATUS_NOT_0 = [ modules.peek testing : .STATUS_NOT_0 ] ;
193+
.CATENATE = [ modules.peek testing : .CATENATE ] ;
194+
.ENDIF = [ modules.peek testing : .ENDIF ] ;
195+
.NULL_OUT = [ modules.peek common : NULL_OUT ] ;
196+
.RM = [ common.rm-command ] ;
178197
actions run-fuzzer
179198
{
180199
$(.UBSAN_OPTIONS)
181-
$(>[1]) $(<) $(>[2]) $(>[3]) $(FLAGS)
200+
$(>[1]) $(<) $(>[2-]) $(FLAGS) > "$(LOG)" 2>&1
201+
$(.SET_STATUS)
202+
if $(.STATUS_NOT_0)
203+
echo ====== BEGIN OUTPUT ======
204+
$(.CATENATE) "$(LOG)"
205+
echo ====== END OUTPUT ======
206+
$(RM) $(LOG) $(.NULL_OUT)
207+
exit 1
208+
$(.ENDIF)
182209
}
183210

184211
.TOUCH_FILE = [ common.file-touch-command ] ;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)