@@ -47,13 +47,19 @@ internal static Summary[] Run(BenchmarkRunInfo[] benchmarkRunInfos)
4747 {
4848 var compositeLogger = CreateCompositeLogger ( benchmarkRunInfos , streamLogger ) ;
4949
50- var supportedBenchmarks = GetSupportedBenchmarks ( benchmarkRunInfos , compositeLogger , resolver ) ;
51- if ( ! supportedBenchmarks . Any ( benchmarks => benchmarks . BenchmarksCases . Any ( ) ) )
52- return new [ ] { Summary . NothingToRun ( title , resultsFolderPath , logFilePath ) } ;
50+ compositeLogger . WriteLineInfo ( "// Validating benchmarks:" ) ;
51+
52+ var ( supportedBenchmarks , validationErrors ) = GetSupportedBenchmarks ( benchmarkRunInfos , compositeLogger , resolver ) ;
53+
54+ validationErrors . AddRange ( Validate ( supportedBenchmarks ) ) ;
55+
56+ PrintValidationErrors ( compositeLogger , validationErrors ) ;
5357
54- var validationErrors = Validate ( supportedBenchmarks , compositeLogger ) ;
5558 if ( validationErrors . Any ( validationError => validationError . IsCritical ) )
56- return new [ ] { Summary . ValidationFailed ( title , resultsFolderPath , logFilePath , validationErrors ) } ;
59+ return new [ ] { Summary . ValidationFailed ( title , resultsFolderPath , logFilePath , validationErrors . ToImmutableArray ( ) ) } ;
60+
61+ if ( ! supportedBenchmarks . Any ( benchmarks => benchmarks . BenchmarksCases . Any ( ) ) )
62+ return new [ ] { Summary . ValidationFailed ( title , resultsFolderPath , logFilePath ) } ;
5763
5864 int totalBenchmarkCount = supportedBenchmarks . Sum ( benchmarkInfo => benchmarkInfo . BenchmarksCases . Length ) ;
5965 int benchmarksToRunCount = totalBenchmarkCount ;
@@ -145,7 +151,7 @@ private static Summary Run(BenchmarkRunInfo benchmarkRunInfo,
145151 var cultureInfo = config . CultureInfo ?? DefaultCultureInfo . Instance ;
146152 var reports = new List < BenchmarkReport > ( ) ;
147153 string title = GetTitle ( new [ ] { benchmarkRunInfo } ) ;
148- var consoleTitle = RuntimeInformation . IsWindows ( ) ? Console . Title : string . Empty ;
154+ var consoleTitle = RuntimeInformation . IsWindows ( ) ? Console . Title : string . Empty ;
149155
150156 logger . WriteLineInfo ( $ "// Found { benchmarks . Length } benchmarks:") ;
151157 foreach ( var benchmark in benchmarks )
@@ -236,7 +242,7 @@ private static Summary Run(BenchmarkRunInfo benchmarkRunInfo,
236242 logFilePath ,
237243 runEnd . GetTimeSpan ( ) - runStart . GetTimeSpan ( ) ,
238244 cultureInfo ,
239- Validate ( new [ ] { benchmarkRunInfo } , NullLogger . Instance ) , // validate them once again, but don't print the output
245+ Validate ( benchmarkRunInfo ) , // validate them once again, but don't print the output
240246 config . GetColumnHidingRules ( ) . ToImmutableArray ( ) ) ;
241247 }
242248
@@ -306,10 +312,8 @@ private static void PrintSummary(ILogger logger, ImmutableConfig config, Summary
306312 logger . WriteLineHeader ( "// ***** BenchmarkRunner: End *****" ) ;
307313 }
308314
309- private static ImmutableArray < ValidationError > Validate ( BenchmarkRunInfo [ ] benchmarks , ILogger logger )
315+ private static ImmutableArray < ValidationError > Validate ( params BenchmarkRunInfo [ ] benchmarks )
310316 {
311- logger . WriteLineInfo ( "// Validating benchmarks:" ) ;
312-
313317 var validationErrors = new List < ValidationError > ( ) ;
314318
315319 if ( benchmarks . Any ( b => b . Config . Options . IsSet ( ConfigOptions . JoinSummary ) ) )
@@ -326,9 +330,6 @@ private static ImmutableArray<ValidationError> Validate(BenchmarkRunInfo[] bench
326330 foreach ( var benchmarkRunInfo in benchmarks )
327331 validationErrors . AddRange ( benchmarkRunInfo . Config . GetCompositeValidator ( ) . Validate ( new ValidationParameters ( benchmarkRunInfo . BenchmarksCases , benchmarkRunInfo . Config ) ) ) ;
328332
329- foreach ( var validationError in validationErrors . Distinct ( ) )
330- logger . WriteLineError ( validationError . Message ) ;
331-
332333 return validationErrors . ToImmutableArray ( ) ;
333334 }
334335
@@ -531,14 +532,25 @@ private static ExecuteResult RunExecute(ILogger logger, BenchmarkCase benchmarkC
531532 private static void LogTotalTime ( ILogger logger , TimeSpan time , int executedBenchmarksCount , string message = "Total time" )
532533 => logger . WriteLineStatistic ( $ "{ message } : { time . ToFormattedTotalTime ( DefaultCultureInfo . Instance ) } , executed benchmarks: { executedBenchmarksCount } ") ;
533534
534- private static BenchmarkRunInfo [ ] GetSupportedBenchmarks ( BenchmarkRunInfo [ ] benchmarkRunInfos , ILogger logger , IResolver resolver )
535- => benchmarkRunInfos . Select ( info => new BenchmarkRunInfo (
536- info . BenchmarksCases . Where ( benchmark => benchmark . GetToolchain ( ) . IsSupported ( benchmark , logger , resolver ) ) . ToArray ( ) ,
535+ private static ( BenchmarkRunInfo [ ] , List < ValidationError > ) GetSupportedBenchmarks ( BenchmarkRunInfo [ ] benchmarkRunInfos , ILogger logger , IResolver resolver )
536+ {
537+ List < ValidationError > validationErrors = new ( ) ;
538+
539+ var benchmarksRunInfo = benchmarkRunInfos . Select ( info => new BenchmarkRunInfo (
540+ info . BenchmarksCases . Where ( benchmark =>
541+ {
542+ var errors = benchmark . GetToolchain ( ) . Validate ( benchmark , resolver ) . ToArray ( ) ;
543+ validationErrors . AddRange ( errors ) ;
544+ return ! errors . Any ( ) ;
545+ } ) . ToArray ( ) ,
537546 info . Type ,
538547 info . Config ) )
539548 . Where ( infos => infos . BenchmarksCases . Any ( ) )
540549 . ToArray ( ) ;
541550
551+ return ( benchmarkRunInfos , validationErrors ) ;
552+ }
553+
542554 private static string GetRootArtifactsFolderPath ( BenchmarkRunInfo [ ] benchmarkRunInfos )
543555 {
544556 var defaultPath = DefaultConfig . Instance . ArtifactsPath ;
@@ -652,5 +664,19 @@ private static TimeSpan GetEstimatedFinishTime(in StartedClock runsChronometer,
652664 TimeSpan fromNow = TimeSpan . FromSeconds ( avgSecondsPerBenchmark * benchmarksToRunCount ) ;
653665 return fromNow ;
654666 }
667+
668+ private static void PrintValidationErrors ( ILogger logger , IEnumerable < ValidationError > validationErrors )
669+ {
670+ foreach ( var validationError in validationErrors . Distinct ( ) )
671+ {
672+ if ( validationError . BenchmarkCase != null )
673+ {
674+ logger . WriteLineInfo ( $ "// Benchmark { validationError . BenchmarkCase . DisplayInfo } ") ;
675+ }
676+
677+ logger . WriteLineError ( $ "// * { validationError . Message } ") ;
678+ logger . WriteLine ( ) ;
679+ }
680+ }
655681 }
656- }
682+ }
0 commit comments