Skip to content

Commit

Permalink
Merge pull request #207 from gigi81/fix-outputlogger
Browse files Browse the repository at this point in the history
Fixed tests not using OutputLogger
  • Loading branch information
AndreyAkinshin committed Jun 12, 2016
2 parents 600cdd1 + 7d05011 commit ae5eab0
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 12 deletions.
11 changes: 10 additions & 1 deletion BenchmarkDotNet.IntegrationTests/MemoryDiagnoserTests.cs
Expand Up @@ -5,6 +5,7 @@
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
using Xunit;
using Xunit.Abstractions;

namespace BenchmarkDotNet.IntegrationTests
{
Expand Down Expand Up @@ -46,6 +47,13 @@ public int ListObjectEnumerator()
// this class is not compiled for CORE because it is using Diagnosers that currently do not support Core
public class MemoryDiagnoserTests
{
private readonly ITestOutputHelper output;

public MemoryDiagnoserTests(ITestOutputHelper outputHelper)
{
output = outputHelper;
}

[Fact]
public void Test()
{
Expand All @@ -59,7 +67,8 @@ public void Test()
.With(Job.Dry.With(Runtime.Core).With(Jit.Host).With(Mode.Throughput).WithWarmupCount(1).WithTargetCount(1))
.With(DefaultConfig.Instance.GetLoggers().ToArray())
.With(DefaultConfig.Instance.GetColumns().ToArray())
.With(memoryDiagnoser));
.With(memoryDiagnoser)
.With(new OutputLogger(output)));

var gcCollectionColumns = memoryDiagnoser.GetColumns.OfType<Diagnostics.Windows.MemoryDiagnoser.GCCollectionColumn>().ToArray();
var listStructEnumeratorBenchmarks = benchmarks.Where(benchmark => benchmark.ShortInfo.Contains("ListStructEnumerator"));
Expand Down
11 changes: 10 additions & 1 deletion BenchmarkDotNet.IntegrationTests/MultipleRuntimesTest.cs
Expand Up @@ -6,11 +6,19 @@
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Toolchains;
using Xunit;
using Xunit.Abstractions;

namespace BenchmarkDotNet.IntegrationTests
{
public class MultipleRuntimesTest
{
private readonly ITestOutputHelper output;

public MultipleRuntimesTest(ITestOutputHelper outputHelper)
{
output = outputHelper;
}

[Fact]
public void SingleBenchmarkCanBeExecutedForMultpleRuntimes()
{
Expand All @@ -19,7 +27,8 @@ public void SingleBenchmarkCanBeExecutedForMultpleRuntimes()
ManualConfig.CreateEmpty()
.With(Job.Dry.With(Runtime.Dnx))
.With(Job.Dry.With(Runtime.Core))
.With(Job.Dry.With(Runtime.Clr).With(Framework.V46)));
.With(Job.Dry.With(Runtime.Clr).With(Framework.V46))
.With(new OutputLogger(output)));

Assert.True(summary.Reports
.All(report => report.ExecuteResults
Expand Down
3 changes: 3 additions & 0 deletions BenchmarkDotNet.IntegrationTests/OutputLogger.cs
Expand Up @@ -10,6 +10,9 @@ public class OutputLogger : AccumulationLogger

public OutputLogger(ITestOutputHelper testOutputHelper)
{
if (testOutputHelper == null)
throw new ArgumentNullException(nameof(testOutputHelper));

this.testOutputHelper = testOutputHelper;
}

Expand Down
17 changes: 14 additions & 3 deletions BenchmarkDotNet.IntegrationTests/PerformanceUnitTest.cs
Expand Up @@ -8,16 +8,23 @@
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;
using Xunit;
using Xunit.Abstractions;

namespace BenchmarkDotNet.IntegrationTests
{
[Config(typeof(SingleRunFastConfig))]
public class PerformanceUnitTest
public class PerformanceUnitTestRunner
{
private readonly ITestOutputHelper output;

public PerformanceUnitTestRunner(ITestOutputHelper outputHelper)
{
output = outputHelper;
}

[Fact]
public void Test()
{
var logger = new AccumulationLogger();
var logger = new OutputLogger(output);
var config = DefaultConfig.Instance.With(logger);
var summary = BenchmarkRunner.Run<PerformanceUnitTest>(config);

Expand All @@ -44,7 +51,11 @@ public void Test()
foreach (var fastRun in fastBenchmarkReport.GetResultRuns())
Assert.InRange(fastRun.GetAverageNanoseconds() / 1000.0 / 1000.0, low: 14, high: 17);
}
}

[Config(typeof(SingleRunFastConfig))]
public class PerformanceUnitTest
{
[Benchmark]
public void FastBenchmark()
{
Expand Down
15 changes: 12 additions & 3 deletions BenchmarkDotNet.IntegrationTests/ProcessorArchitectureTest.cs
Expand Up @@ -5,10 +5,10 @@
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Jobs;
using Xunit;
using Xunit.Abstractions;

namespace BenchmarkDotNet.IntegrationTests
{
[Config(typeof(PlatformConfig))]
public class ProcessorArchitectureTest
{
private class PlatformConfig : ManualConfig
Expand All @@ -25,6 +25,13 @@ public PlatformConfig(Platform platform)
const string HostPlatformOkCaption = "// HostPlatformOkCaption";
const string BenchmarkNotFound = "// There are no benchmarks found";

private readonly ITestOutputHelper output;

public ProcessorArchitectureTest(ITestOutputHelper outputHelper)
{
output = outputHelper;
}

[Fact]
public void SpecifiedProccesorArchitectureMustBeRespected()
{
Expand All @@ -38,9 +45,11 @@ public void SpecifiedProccesorArchitectureMustBeRespected()

private void Verify(Platform platform, Type benchmark, string failureText)
{
var logger = new AccumulationLogger();
var logger = new OutputLogger(output);
// make sure we get an output in the TestRunner log
var config = new PlatformConfig(platform).With(logger).With(ConsoleLogger.Default);
var config = new PlatformConfig(platform)
.With(logger)
.With(ConsoleLogger.Default);

BenchmarkTestExecutor.CanExecute(benchmark, config);
var testLog = logger.GetLog();
Expand Down
21 changes: 17 additions & 4 deletions BenchmarkDotNet.IntegrationTests/ValidatorsTest.cs
Expand Up @@ -6,6 +6,7 @@
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Loggers;
using Xunit;
using Xunit.Abstractions;

namespace BenchmarkDotNet.IntegrationTests
{
Expand All @@ -23,26 +24,35 @@ public class ValidatorsTest
PlainExporter.Default,
};

private readonly ITestOutputHelper output;

public ValidatorsTest(ITestOutputHelper outputHelper)
{
output = outputHelper;
}

[Fact]
public void BenchmarkRunnerShouldNotFailOnCriticalValidationErrors()
{
BenchmarkRunner
.Run<ValidatorsTest>(
.Run<Nothing>(
ManualConfig
.CreateEmpty()
.With(new FailingValidator())
.With(ConsoleLogger.Default) // so we get an output in the TestRunner log
.With(new OutputLogger(output))
.With(AllKnownExportersThatSupportExportToLog));
}

[Fact]
public void LoggersShouldNotFailOnCriticalValidationErrors()
{
var summary = BenchmarkRunner
.Run<ValidatorsTest>(
.Run<Nothing>(
ManualConfig
.CreateEmpty()
.With(ConsoleLogger.Default) // so we get an output in the TestRunner log
.With(new OutputLogger(output))
.With(new FailingValidator()));

foreach (var exporter in AllKnownExportersThatSupportExportToLog)
Expand All @@ -61,7 +71,10 @@ public IEnumerable<ValidationError> Validate(IList<Benchmark> benchmarks)
}
}

[Benchmark]
public void Nothing() { }
public class Nothing
{
[Benchmark]
public void DoNothing() { }
}
}
}

0 comments on commit ae5eab0

Please sign in to comment.