@@ -11,18 +11,23 @@ fn add_empty_result_error_explanation(error_details: &str) -> String {
1111}
1212
1313/// Validates that walltime results exist and contain at least one benchmark.
14- pub fn validate_walltime_results ( profile_folder : & Path ) -> Result < ( ) > {
14+ /// When `allow_empty` is true, empty benchmark results are allowed.
15+ pub fn validate_walltime_results ( profile_folder : & Path , allow_empty : bool ) -> Result < ( ) > {
1516 let results_dir = profile_folder. join ( "results" ) ;
1617
1718 if !results_dir. exists ( ) {
19+ if allow_empty {
20+ warn ! ( "No walltime results found in profile folder: {results_dir:?}." ) ;
21+ return Ok ( ( ) ) ;
22+ }
1823 bail ! ( add_empty_result_error_explanation( & format!(
1924 "No walltime results found in profile folder: {results_dir:?}."
2025 ) ) ) ;
2126 }
2227
2328 debug ! ( "Validating walltime results in {results_dir:?}" ) ;
2429
25- let mut found_valid_results = false ;
30+ let mut found_benchmark_results = false ;
2631
2732 for entry in std:: fs:: read_dir ( & results_dir) ? {
2833 let entry = entry?;
@@ -41,19 +46,26 @@ pub fn validate_walltime_results(profile_folder: &Path) -> Result<()> {
4146 . with_context ( || format ! ( "Failed to parse walltime results from: {path:?}" ) ) ?;
4247
4348 if results. benchmarks . is_empty ( ) {
44- bail ! ( add_empty_result_error_explanation( & format!(
45- "No benchmarks found in walltime results file: {path:?}."
46- ) ) ) ;
49+ if !allow_empty {
50+ bail ! ( add_empty_result_error_explanation( & format!(
51+ "No benchmarks found in walltime results file: {path:?}."
52+ ) ) ) ;
53+ }
54+ debug ! ( "No benchmarks found in {path:?} (allowed)" ) ;
4755 }
4856
49- found_valid_results = true ;
57+ found_benchmark_results = true ;
5058 debug ! (
5159 "Found {} benchmark(s) in {path:?}" ,
5260 results. benchmarks. len( )
5361 ) ;
5462 }
5563
56- if !found_valid_results {
64+ if !found_benchmark_results {
65+ if allow_empty {
66+ warn ! ( "No JSON result files found in: {results_dir:?}." ) ;
67+ return Ok ( ( ) ) ;
68+ }
5769 bail ! ( add_empty_result_error_explanation( & format!(
5870 "No JSON result files found in: {results_dir:?}."
5971 ) ) ) ;
@@ -174,7 +186,7 @@ mod tests {
174186 let profile = TestProfileFolder :: new ( ) ;
175187 profile. write_json_file ( "results.json" , & valid_walltime_results_json ( 1 ) ) ;
176188
177- let result = validate_walltime_results ( profile. path ( ) ) ;
189+ let result = validate_walltime_results ( profile. path ( ) , false ) ;
178190 assert ! ( result. is_ok( ) ) ;
179191 }
180192
@@ -184,7 +196,7 @@ mod tests {
184196 profile. write_json_file ( "results1.json" , & valid_walltime_results_json ( 2 ) ) ;
185197 profile. write_json_file ( "results2.json" , & valid_walltime_results_json ( 3 ) ) ;
186198
187- let result = validate_walltime_results ( profile. path ( ) ) ;
199+ let result = validate_walltime_results ( profile. path ( ) , false ) ;
188200 assert ! ( result. is_ok( ) ) ;
189201 }
190202
@@ -195,7 +207,7 @@ mod tests {
195207 profile. write_text_file ( "readme.txt" , "This is a text file" ) ;
196208 profile. write_text_file ( "data.csv" , "col1,col2" ) ;
197209
198- let result = validate_walltime_results ( profile. path ( ) ) ;
210+ let result = validate_walltime_results ( profile. path ( ) , false ) ;
199211 assert ! ( result. is_ok( ) ) ;
200212 }
201213
@@ -206,7 +218,7 @@ mod tests {
206218 let profile = TestProfileFolder :: new ( ) ;
207219 // Don't create results directory
208220
209- let result = validate_walltime_results ( profile. path ( ) ) ;
221+ let result = validate_walltime_results ( profile. path ( ) , false ) ;
210222 assert ! ( result. is_err( ) ) ;
211223 let error = result. unwrap_err ( ) . to_string ( ) ;
212224 assert ! ( error. contains( "No walltime results found in profile folder" ) ) ;
@@ -217,7 +229,7 @@ mod tests {
217229 let profile = TestProfileFolder :: new ( ) ;
218230 profile. create_results_dir ( ) ;
219231
220- let result = validate_walltime_results ( profile. path ( ) ) ;
232+ let result = validate_walltime_results ( profile. path ( ) , false ) ;
221233 assert ! ( result. is_err( ) ) ;
222234 let error = result. unwrap_err ( ) . to_string ( ) ;
223235 assert ! ( error. contains( "No JSON result files found in" ) ) ;
@@ -229,7 +241,7 @@ mod tests {
229241 profile. write_text_file ( "readme.txt" , "some text" ) ;
230242 profile. write_text_file ( "data.csv" , "col1,col2" ) ;
231243
232- let result = validate_walltime_results ( profile. path ( ) ) ;
244+ let result = validate_walltime_results ( profile. path ( ) , false ) ;
233245 assert ! ( result. is_err( ) ) ;
234246 let error = result. unwrap_err ( ) . to_string ( ) ;
235247 assert ! ( error. contains( "No JSON result files found in" ) ) ;
@@ -240,7 +252,7 @@ mod tests {
240252 let profile = TestProfileFolder :: new ( ) ;
241253 profile. write_json_file ( "results.json" , & empty_benchmarks_json ( ) ) ;
242254
243- let result = validate_walltime_results ( profile. path ( ) ) ;
255+ let result = validate_walltime_results ( profile. path ( ) , false ) ;
244256 assert ! ( result. is_err( ) ) ;
245257 let error = result. unwrap_err ( ) . to_string ( ) ;
246258 assert ! ( error. contains( "No benchmarks found in walltime results file" ) ) ;
@@ -251,7 +263,7 @@ mod tests {
251263 let profile = TestProfileFolder :: new ( ) ;
252264 profile. write_json_file ( "results.json" , "{ invalid json }" ) ;
253265
254- let result = validate_walltime_results ( profile. path ( ) ) ;
266+ let result = validate_walltime_results ( profile. path ( ) , false ) ;
255267 assert ! ( result. is_err( ) ) ;
256268 let error = result. unwrap_err ( ) . to_string ( ) ;
257269 assert ! ( error. contains( "Failed to parse walltime results from" ) ) ;
@@ -263,9 +275,38 @@ mod tests {
263275 profile. write_json_file ( "results1.json" , & valid_walltime_results_json ( 2 ) ) ;
264276 profile. write_json_file ( "results2.json" , & empty_benchmarks_json ( ) ) ;
265277
266- let result = validate_walltime_results ( profile. path ( ) ) ;
278+ let result = validate_walltime_results ( profile. path ( ) , false ) ;
267279 assert ! ( result. is_err( ) ) ;
268280 let error = result. unwrap_err ( ) . to_string ( ) ;
269281 assert ! ( error. contains( "No benchmarks found in walltime results file" ) ) ;
270282 }
283+
284+ // Allow empty cases
285+
286+ #[ test]
287+ fn test_allow_empty_with_empty_benchmarks ( ) {
288+ let profile = TestProfileFolder :: new ( ) ;
289+ profile. write_json_file ( "results.json" , & empty_benchmarks_json ( ) ) ;
290+
291+ let result = validate_walltime_results ( profile. path ( ) , true ) ;
292+ assert ! ( result. is_ok( ) ) ;
293+ }
294+
295+ #[ test]
296+ fn test_allow_empty_with_missing_results_directory ( ) {
297+ let profile = TestProfileFolder :: new ( ) ;
298+ // Don't create results directory
299+
300+ let result = validate_walltime_results ( profile. path ( ) , true ) ;
301+ assert ! ( result. is_ok( ) ) ;
302+ }
303+
304+ #[ test]
305+ fn test_allow_empty_with_no_json_files ( ) {
306+ let profile = TestProfileFolder :: new ( ) ;
307+ profile. create_results_dir ( ) ;
308+
309+ let result = validate_walltime_results ( profile. path ( ) , true ) ;
310+ assert ! ( result. is_ok( ) ) ;
311+ }
271312}
0 commit comments