diff --git a/src/NBench.PerformanceCounters/Metrics/PerformanceCounterBenchmarkSetting.cs b/src/NBench.PerformanceCounters/Metrics/PerformanceCounterBenchmarkSetting.cs index 1550ae23..87c755e8 100644 --- a/src/NBench.PerformanceCounters/Metrics/PerformanceCounterBenchmarkSetting.cs +++ b/src/NBench.PerformanceCounters/Metrics/PerformanceCounterBenchmarkSetting.cs @@ -10,7 +10,7 @@ namespace NBench.PerformanceCounters.Metrics /// /// used to instrument performance counters inside a /// - public sealed class PerformanceCounterBenchmarkSetting : IBenchmarkSetting, IEquatable + public sealed class PerformanceCounterBenchmarkSetting : MarshalByRefObject, IBenchmarkSetting, IEquatable { public PerformanceCounterBenchmarkSetting(PerformanceCounterMetricName performanceCounterMetric, AssertionType assertionType, Assertion assertion) { diff --git a/src/NBench/Collection/MetricsCollectorSelector.cs b/src/NBench/Collection/MetricsCollectorSelector.cs index b082ed75..69284cd1 100644 --- a/src/NBench/Collection/MetricsCollectorSelector.cs +++ b/src/NBench/Collection/MetricsCollectorSelector.cs @@ -1,6 +1,7 @@ // Copyright (c) Petabridge . All rights reserved. -// Licensed under the Apache 2.0 license. See LICENSE file in the project root for full license information. - +// Licensed under the Apache 2.0 license. See LICENSE file in the project root for full license information. + +using System; using System.Collections.Generic; using NBench.Metrics; using NBench.Sdk; @@ -12,7 +13,7 @@ namespace NBench.Collection /// Strategy pattern that's used to determine how to pick the appropriate /// based on platform dependencies and user-preferences. /// - public abstract class MetricsCollectorSelector + public abstract class MetricsCollectorSelector: MarshalByRefObject { protected MetricsCollectorSelector(MetricName name) : this(name, SysInfo.Instance) { diff --git a/src/NBench/Metrics/Counters/CounterBenchmarkSetting.cs b/src/NBench/Metrics/Counters/CounterBenchmarkSetting.cs index 083af040..3587a4cb 100644 --- a/src/NBench/Metrics/Counters/CounterBenchmarkSetting.cs +++ b/src/NBench/Metrics/Counters/CounterBenchmarkSetting.cs @@ -1,6 +1,7 @@ // Copyright (c) Petabridge . All rights reserved. -// Licensed under the Apache 2.0 license. See LICENSE file in the project root for full license information. - +// Licensed under the Apache 2.0 license. See LICENSE file in the project root for full license information. + +using System; using System.Collections.Generic; using System.Diagnostics.Contracts; using NBench.Sdk; @@ -11,7 +12,7 @@ namespace NBench.Metrics.Counters /// Used inside a class to indiciate that a specific /// needs to be recorded and tested against . /// - public sealed class CounterBenchmarkSetting : IBenchmarkSetting + public sealed class CounterBenchmarkSetting : MarshalByRefObject, IBenchmarkSetting { public CounterBenchmarkSetting(string counterName, AssertionType assertionType, Assertion assertion) { diff --git a/src/NBench/Metrics/Counters/CreateCounterBenchmarkSetting.cs b/src/NBench/Metrics/Counters/CreateCounterBenchmarkSetting.cs index ea29593f..6fe2b53d 100644 --- a/src/NBench/Metrics/Counters/CreateCounterBenchmarkSetting.cs +++ b/src/NBench/Metrics/Counters/CreateCounterBenchmarkSetting.cs @@ -1,6 +1,7 @@ // Copyright (c) Petabridge . All rights reserved. -// Licensed under the Apache 2.0 license. See LICENSE file in the project root for full license information. - +// Licensed under the Apache 2.0 license. See LICENSE file in the project root for full license information. + +using System; using NBench.Collection; using NBench.Collection.Counters; using NBench.Sdk; @@ -11,7 +12,7 @@ namespace NBench.Metrics.Counters /// /// Special internal class needed to pass in a to a . /// - internal sealed class CreateCounterBenchmarkSetting : IBenchmarkSetting { + internal sealed class CreateCounterBenchmarkSetting : MarshalByRefObject, IBenchmarkSetting { public CreateCounterBenchmarkSetting(CounterBenchmarkSetting benchmarkSetting, AtomicCounter counter) { BenchmarkSetting = benchmarkSetting; diff --git a/src/NBench/Metrics/GarbageCollection/GcBenchmarkSetting.cs b/src/NBench/Metrics/GarbageCollection/GcBenchmarkSetting.cs index 0497f239..907cc029 100644 --- a/src/NBench/Metrics/GarbageCollection/GcBenchmarkSetting.cs +++ b/src/NBench/Metrics/GarbageCollection/GcBenchmarkSetting.cs @@ -1,6 +1,7 @@ // Copyright (c) Petabridge . All rights reserved. -// Licensed under the Apache 2.0 license. See LICENSE file in the project root for full license information. - +// Licensed under the Apache 2.0 license. See LICENSE file in the project root for full license information. + +using System; using System.Collections.Generic; using NBench.Sdk; @@ -10,7 +11,7 @@ namespace NBench.Metrics.GarbageCollection /// Used inside a class to indiciate that a specific /// for a needs to be recorded and tested against . /// - public sealed class GcBenchmarkSetting : IBenchmarkSetting + public sealed class GcBenchmarkSetting : MarshalByRefObject, IBenchmarkSetting { public GcBenchmarkSetting(GcMetric metric, GcGeneration generation, AssertionType assertionType, Assertion assertion) { diff --git a/src/NBench/Metrics/Memory/MemoryBenchmarkSetting.cs b/src/NBench/Metrics/Memory/MemoryBenchmarkSetting.cs index d3ddcf52..213b26a7 100644 --- a/src/NBench/Metrics/Memory/MemoryBenchmarkSetting.cs +++ b/src/NBench/Metrics/Memory/MemoryBenchmarkSetting.cs @@ -1,6 +1,7 @@ // Copyright (c) Petabridge . All rights reserved. -// Licensed under the Apache 2.0 license. See LICENSE file in the project root for full license information. - +// Licensed under the Apache 2.0 license. See LICENSE file in the project root for full license information. + +using System; using System.Collections.Generic; using NBench.Sdk; @@ -10,7 +11,7 @@ namespace NBench.Metrics.Memory /// Used inside a class to indiciate that a specific /// needs to be recorded and tested against . /// - public sealed class MemoryBenchmarkSetting : IBenchmarkSetting + public sealed class MemoryBenchmarkSetting : MarshalByRefObject, IBenchmarkSetting { public MemoryBenchmarkSetting(MemoryMetric metric, Assertion assertion) { diff --git a/src/NBench/Metrics/MetricName.cs b/src/NBench/Metrics/MetricName.cs index 928b517c..b0644228 100644 --- a/src/NBench/Metrics/MetricName.cs +++ b/src/NBench/Metrics/MetricName.cs @@ -8,7 +8,7 @@ namespace NBench.Metrics /// /// Used to uniquely represent the name of a metric in a manner-agnostic way. /// - public abstract class MetricName : IEquatable + public abstract class MetricName : MarshalByRefObject, IEquatable { public abstract bool Equals(MetricName other); diff --git a/src/NBench/Metrics/Timing/TimingBenchmarkSetting.cs b/src/NBench/Metrics/Timing/TimingBenchmarkSetting.cs index dd4acab7..889f4cae 100644 --- a/src/NBench/Metrics/Timing/TimingBenchmarkSetting.cs +++ b/src/NBench/Metrics/Timing/TimingBenchmarkSetting.cs @@ -1,6 +1,7 @@ // Copyright (c) Petabridge . All rights reserved. -// Licensed under the Apache 2.0 license. See LICENSE file in the project root for full license information. - +// Licensed under the Apache 2.0 license. See LICENSE file in the project root for full license information. + +using System; using NBench.Sdk; namespace NBench.Metrics.Timing @@ -9,7 +10,7 @@ namespace NBench.Metrics.Timing /// implementation for /// and other derived versions. /// - public sealed class TimingBenchmarkSetting : IBenchmarkSetting + public sealed class TimingBenchmarkSetting : MarshalByRefObject, IBenchmarkSetting { public TimingBenchmarkSetting(TimingMetricName metricName, Assertion assertion) { diff --git a/src/NBench/NBench.csproj b/src/NBench/NBench.csproj index bf5bc338..5cfafc40 100644 --- a/src/NBench/NBench.csproj +++ b/src/NBench/NBench.csproj @@ -127,6 +127,7 @@ + diff --git a/src/NBench/Reporting/AggregateMetrics.cs b/src/NBench/Reporting/AggregateMetrics.cs index 45fb4d07..7637a119 100644 --- a/src/NBench/Reporting/AggregateMetrics.cs +++ b/src/NBench/Reporting/AggregateMetrics.cs @@ -1,6 +1,7 @@ // Copyright (c) Petabridge . All rights reserved. -// Licensed under the Apache 2.0 license. See LICENSE file in the project root for full license information. - +// Licensed under the Apache 2.0 license. See LICENSE file in the project root for full license information. + +using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; @@ -12,7 +13,8 @@ namespace NBench.Reporting { /// /// Aggregated metrics accumulated for a single metric across an entire - /// + /// + [Serializable] public struct AggregateMetrics { private static IReadOnlyList GetSafeRuns(MetricName name, string unit) diff --git a/src/NBench/Reporting/BenchmarkFinalResults.cs b/src/NBench/Reporting/BenchmarkFinalResults.cs index cd47530b..ee06c998 100644 --- a/src/NBench/Reporting/BenchmarkFinalResults.cs +++ b/src/NBench/Reporting/BenchmarkFinalResults.cs @@ -1,6 +1,7 @@ // Copyright (c) Petabridge . All rights reserved. -// Licensed under the Apache 2.0 license. See LICENSE file in the project root for full license information. - +// Licensed under the Apache 2.0 license. See LICENSE file in the project root for full license information. + +using System; using System.Collections.Generic; using NBench.Sdk; @@ -8,7 +9,8 @@ namespace NBench.Reporting { /// /// with data provided. - /// + /// + [Serializable] public class BenchmarkFinalResults { public BenchmarkFinalResults(BenchmarkResults data, IReadOnlyList assertionResults) diff --git a/src/NBench/Reporting/BenchmarkResults.cs b/src/NBench/Reporting/BenchmarkResults.cs index 872c2f0d..8ebe4219 100644 --- a/src/NBench/Reporting/BenchmarkResults.cs +++ b/src/NBench/Reporting/BenchmarkResults.cs @@ -12,7 +12,8 @@ namespace NBench.Reporting { /// /// The cumulative results for an entire - /// + /// + [Serializable] public class BenchmarkResults { public BenchmarkResults(string typeName, BenchmarkSettings settings, IReadOnlyList runs) diff --git a/src/NBench/Reporting/BenchmarkRunReport.cs b/src/NBench/Reporting/BenchmarkRunReport.cs index b62ca8db..6e6c709a 100644 --- a/src/NBench/Reporting/BenchmarkRunReport.cs +++ b/src/NBench/Reporting/BenchmarkRunReport.cs @@ -10,7 +10,8 @@ namespace NBench.Reporting { /// /// Compiled statistics for each - /// + /// + [Serializable] public struct BenchmarkRunReport { public BenchmarkRunReport(TimeSpan elapsed, IEnumerable metrics, IReadOnlyList exceptions) diff --git a/src/NBench/Reporting/BenchmarkStat.cs b/src/NBench/Reporting/BenchmarkStat.cs index 381737e0..c501d90c 100644 --- a/src/NBench/Reporting/BenchmarkStat.cs +++ b/src/NBench/Reporting/BenchmarkStat.cs @@ -10,7 +10,8 @@ namespace NBench.Reporting { /// /// Represents aggregate statics for a benchmark across multiple runs - /// + /// + [Serializable] public struct BenchmarkStat { public static readonly double[] SafeValues = {0.0d}; diff --git a/src/NBench/Reporting/CompositeBenchmarkOutput.cs b/src/NBench/Reporting/CompositeBenchmarkOutput.cs index 67df1ff7..c5919f6b 100644 --- a/src/NBench/Reporting/CompositeBenchmarkOutput.cs +++ b/src/NBench/Reporting/CompositeBenchmarkOutput.cs @@ -9,8 +9,8 @@ namespace NBench.Reporting { /// /// Composition of multiple instances being run in parallel. - /// - public class CompositeBenchmarkOutput : IBenchmarkOutput + /// + public class CompositeBenchmarkOutput : MarshalByRefObject, IBenchmarkOutput { private readonly IReadOnlyList _outputs; diff --git a/src/NBench/Reporting/MetricRunReport.cs b/src/NBench/Reporting/MetricRunReport.cs index dd5c8fab..51de73a9 100644 --- a/src/NBench/Reporting/MetricRunReport.cs +++ b/src/NBench/Reporting/MetricRunReport.cs @@ -10,7 +10,8 @@ namespace NBench.Reporting { /// /// All of the compiled values from one for a given - /// + /// + [Serializable] public struct MetricRunReport { public MetricRunReport(MetricName name, string unit, double metricReading, long ticks) diff --git a/src/NBench/Reporting/Targets/ConsoleBenchmarkOutput.cs b/src/NBench/Reporting/Targets/ConsoleBenchmarkOutput.cs index 3a28e490..bc769b2c 100644 --- a/src/NBench/Reporting/Targets/ConsoleBenchmarkOutput.cs +++ b/src/NBench/Reporting/Targets/ConsoleBenchmarkOutput.cs @@ -8,7 +8,7 @@ namespace NBench.Reporting.Targets /// /// Output writer to the console for NBench /// - public class ConsoleBenchmarkOutput : IBenchmarkOutput + public class ConsoleBenchmarkOutput : MarshalByRefObject, IBenchmarkOutput { public void WriteLine(string message) { diff --git a/src/NBench/Reporting/Targets/MarkdownBenchmarkOutput.cs b/src/NBench/Reporting/Targets/MarkdownBenchmarkOutput.cs index bd0b684c..f85fd797 100644 --- a/src/NBench/Reporting/Targets/MarkdownBenchmarkOutput.cs +++ b/src/NBench/Reporting/Targets/MarkdownBenchmarkOutput.cs @@ -18,7 +18,7 @@ namespace NBench.Reporting.Targets /// completed benchmark to a markdown file. Uses /// to generate a file name unique to each test AND the time it was run. /// - public class MarkdownBenchmarkOutput : IBenchmarkOutput + public class MarkdownBenchmarkOutput : MarshalByRefObject, IBenchmarkOutput { public const string MarkdownFileExtension = ".md"; public const int MaxColumnSize = 18; diff --git a/src/NBench/Sdk/AssertionResult.cs b/src/NBench/Sdk/AssertionResult.cs index 126ae8e8..18c243d7 100644 --- a/src/NBench/Sdk/AssertionResult.cs +++ b/src/NBench/Sdk/AssertionResult.cs @@ -7,6 +7,7 @@ namespace NBench.Sdk { + [Serializable] public struct AssertionResult { public AssertionResult(MetricName metricName, string message, bool passed) diff --git a/src/NBench/Sdk/BenchMarkRunner.cs b/src/NBench/Sdk/BenchMarkRunner.cs new file mode 100644 index 00000000..6757232d --- /dev/null +++ b/src/NBench/Sdk/BenchMarkRunner.cs @@ -0,0 +1,40 @@ +using System; +using System.Linq; +using NBench.Reporting; +using NBench.Sdk.Compiler; + +namespace NBench.Sdk +{ + [Serializable] + internal class BenchmarkRunnerResult + { + public bool AllTestsPassed { get; set; } + } + + internal class BenchmarkRunner : MarshalByRefObject + { + private readonly IBenchmarkOutput _output; + + public BenchmarkRunner(IBenchmarkOutput output) + { + _output = output; + } + + public BenchmarkRunnerResult Run(string testFile, string benchmarkName) + { + var discovery = new ReflectionDiscovery(_output); + + var assembly = AssemblyRuntimeLoader.LoadAssembly(testFile); + var benchmarks = discovery.FindBenchmarks(assembly); + + var benchmark = benchmarks.FirstOrDefault(b => b.BenchmarkName == benchmarkName); + benchmark.Run(); + benchmark.Finish(); + + return new BenchmarkRunnerResult + { + AllTestsPassed = benchmark.AllAssertsPassed, + }; + } + } +} \ No newline at end of file diff --git a/src/NBench/Sdk/BenchmarkSettings.cs b/src/NBench/Sdk/BenchmarkSettings.cs index 4a156f58..cfd59fc1 100644 --- a/src/NBench/Sdk/BenchmarkSettings.cs +++ b/src/NBench/Sdk/BenchmarkSettings.cs @@ -15,7 +15,8 @@ namespace NBench.Sdk { /// /// Settings for how a particular should be run and executed. - /// + /// + [Serializable] public class BenchmarkSettings { internal class BenchmarkEqualityComparer : IEqualityComparer diff --git a/src/NBench/Sdk/TestRunner.cs b/src/NBench/Sdk/TestRunner.cs index fd06798f..447108cf 100644 --- a/src/NBench/Sdk/TestRunner.cs +++ b/src/NBench/Sdk/TestRunner.cs @@ -65,19 +65,8 @@ public static TestRunner CreateRunner(AppDomain domain, TestPackage package) /// Creates a new AppDomain and executes the tests. public static TestRunnerResult Run(TestPackage package) { - Contract.Requires(package != null); - // create the test app domain - var testDomain = DomainManager.CreateDomain(package); - - try - { - var runner = TestRunner.CreateRunner(testDomain, package); - return runner.Execute(); - } - finally - { - DomainManager.UnloadDomain(testDomain); - } + var runner = new TestRunner(package); + return runner.Execute(); } /// @@ -152,12 +141,22 @@ public TestRunnerResult Execute() // verify if the benchmark should be included/excluded from the list of benchmarks to be run if (_package.ShouldRunBenchmark(benchmark.BenchmarkName)) { + var testDomain = DomainManager.CreateDomain(_package); + var benchmarkRunnerType = typeof(BenchmarkRunner); + var benchMarkRunner = testDomain.CreateInstanceAndUnwrap(benchmarkRunnerType.Assembly.FullName, benchmarkRunnerType.FullName, false, 0, null, new object[] { output }, null, null) as BenchmarkRunner; + output.WriteLine($"------------ STARTING {benchmark.BenchmarkName} ---------- "); - benchmark.Run(); - benchmark.Finish(); + try + { + var benchMarkResult = benchMarkRunner.Run(testFile, benchmark.BenchmarkName); + // if one assert fails, all fail + result.AllTestsPassed = result.AllTestsPassed && benchMarkResult.AllTestsPassed; + } + finally + { + DomainManager.UnloadDomain(testDomain); + } - // if one assert fails, all fail - result.AllTestsPassed = result.AllTestsPassed && benchmark.AllAssertsPassed; output.WriteLine($"------------ FINISHED {benchmark.BenchmarkName} ---------- "); result.ExecutedTestsCount = result.ExecutedTestsCount + 1; } diff --git a/src/NBench/Tracing/NoOpBenchmarkTrace.cs b/src/NBench/Tracing/NoOpBenchmarkTrace.cs index 9d67c3f5..7412d0d8 100644 --- a/src/NBench/Tracing/NoOpBenchmarkTrace.cs +++ b/src/NBench/Tracing/NoOpBenchmarkTrace.cs @@ -5,7 +5,7 @@ namespace NBench.Tracing /// /// Default no-op implementation of . Does nothing. /// - internal sealed class NoOpBenchmarkTrace : IBenchmarkTrace + internal sealed class NoOpBenchmarkTrace : MarshalByRefObject, IBenchmarkTrace { public static readonly NoOpBenchmarkTrace Instance = new NoOpBenchmarkTrace();