@@ -39,32 +39,31 @@ import testing ;
3939] ;
4040
4141local corpus.tar = [ glob-ex . : corpus.tar ] ;
42+ local test-corpus ;
4243if $(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}
5253else
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
6262local variants = basic_parser parse parser direct_parse ;
6363for 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 ;
139139explicit 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+
142149rule 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 ] ;
178197actions 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 ] ;
0 commit comments