public void DuplicateAnalyzersAreExcluded()
        {
            var mutable = ManualConfig.CreateEmpty();

            mutable.AddAnalyser(OutliersAnalyser.Default);
            mutable.AddAnalyser(OutliersAnalyser.Default);

            var final = ImmutableConfigBuilder.Create(mutable);

            Assert.Same(OutliersAnalyser.Default, final.GetAnalysers().Single());
        }
        public void WhenUserDefinesHardwareCountersWeChooseTheRightDiagnoser()
        {
            var mutable = ManualConfig.CreateEmpty();

            mutable.AddHardwareCounters(HardwareCounter.CacheMisses);

            var final = ImmutableConfigBuilder.Create(mutable);

            Assert.Single(final.GetDiagnosers());
            Assert.Single(final.GetDiagnosers().OfType <IHardwareCountersDiagnoser>());
        }
        public void DuplicateDiagnosersAreExcludedBasedOnType()
        {
            var mutable = ManualConfig.CreateEmpty();

            mutable.AddDiagnoser(new DisassemblyDiagnoser(new DisassemblyDiagnoserConfig()));
            mutable.AddDiagnoser(new DisassemblyDiagnoser(new DisassemblyDiagnoserConfig()));

            var final = ImmutableConfigBuilder.Create(mutable);

            Assert.Single(final.GetDiagnosers());
        }
        public void DuplicateLoggersAreExcluded()
        {
            var mutable = ManualConfig.CreateEmpty();

            mutable.AddLogger(ConsoleLogger.Default);
            mutable.AddLogger(ConsoleLogger.Default);

            var final = ImmutableConfigBuilder.Create(mutable);

            Assert.Same(ConsoleLogger.Default, final.GetLoggers().Single());
        }
        public void DuplicateHardwareCountersAreExcluded()
        {
            var mutable = ManualConfig.CreateEmpty();

            mutable.AddHardwareCounters(HardwareCounter.CacheMisses);
            mutable.AddHardwareCounters(HardwareCounter.CacheMisses);

            var final = ImmutableConfigBuilder.Create(mutable);

            Assert.Equal(HardwareCounter.CacheMisses, final.GetHardwareCounters().Single());
        }
        public void DuplicateColumnProvidersAreExcluded()
        {
            var mutable = ManualConfig.CreateEmpty();

            mutable.AddColumnProvider(DefaultColumnProviders.Job);
            mutable.AddColumnProvider(DefaultColumnProviders.Job);

            var final = ImmutableConfigBuilder.Create(mutable);

            Assert.Same(DefaultColumnProviders.Job, final.GetColumnProviders().Single());
        }
        [Fact] // See https://github.com/dotnet/BenchmarkDotNet/issues/172
        public void MissingExporterDependencyIsAddedWhenNeeded()
        {
            var mutable = ManualConfig.CreateEmpty();

            mutable.AddExporter(TestExporter.Default);

            var exporters = ImmutableConfigBuilder.Create(mutable).GetExporters().ToArray();

            Assert.Equal(2, exporters.Length);
            Assert.Equal(new IExporter[] { TestExporterDependency.Default, TestExporter.Default }, exporters);
        }
        public void DuplicateValidatorsAreExcludedBasedOnTreatsWarningsAsErrorsProperty()
        {
            var mutable = ManualConfig.CreateEmpty();

            mutable.AddValidator(JitOptimizationsValidator.DontFailOnError);
            mutable.AddValidator(JitOptimizationsValidator.FailOnError);

            var final = ImmutableConfigBuilder.Create(mutable);

            Assert.Same(JitOptimizationsValidator.FailOnError, final.GetValidators().OfType <JitOptimizationsValidator>().Single());
        }
        public void DuplicateExportersAreExcluded()
        {
            var mutable = ManualConfig.CreateEmpty();

            mutable.Add(MarkdownExporter.GitHub);
            mutable.Add(MarkdownExporter.GitHub);

            var final = ImmutableConfigBuilder.Create(mutable);

            Assert.Same(MarkdownExporter.GitHub, final.GetExporters().Single());
        }
        public void JitOptimizationsValidatorIsMandatoryByDefault()
        {
            var fromEmpty = ImmutableConfigBuilder.Create(ManualConfig.CreateEmpty());

            Assert.Contains(JitOptimizationsValidator.DontFailOnError, fromEmpty.GetValidators());

#if !DEBUG
            // DefaultConfig.Instance doesn't include JitOptimizationsValidator.FailOnError in the DEBUG mode
            var fromDefault = ImmutableConfigBuilder.Create(DefaultConfig.Instance);
            Assert.Contains(JitOptimizationsValidator.FailOnError, fromDefault.GetValidators());
#endif
        }
        public void WhenUserDefinesHardwareCountersAndUsesDisassemblyDiagnoserWeAddInstructionPointerExporter()
        {
            var mutable = ManualConfig.CreateEmpty();

            mutable.Add(HardwareCounter.CacheMisses);
            mutable.Add(DisassemblyDiagnoser.Create(DisassemblyDiagnoserConfig.All));

            var final = ImmutableConfigBuilder.Create(mutable);

            Assert.Single(final.GetDiagnosers().OfType <IHardwareCountersDiagnoser>());
            Assert.Single(final.GetDiagnosers().OfType <IDisassemblyDiagnoser>());
            Assert.Single(final.GetExporters().OfType <InstructionPointerExporter>());
        }
        private static ImmutableConfig GetFullTypeConfig(Type type, IConfig config)
        {
            config = config ?? DefaultConfig.Instance;

            var typeAttributes     = type.GetCustomAttributes(true).OfType <IConfigSource>();
            var assemblyAttributes = type.Assembly.GetCustomAttributes().OfType <IConfigSource>();

            foreach (var configFromAttribute in typeAttributes.Concat(assemblyAttributes))
            {
                config = ManualConfig.Union(config, configFromAttribute.Config);
            }

            return(ImmutableConfigBuilder.Create(config));
        }
        public void JitOptimizationsValidatorIsMandatoryCanBeDisabledOnDemand()
        {
            var disabled = ImmutableConfigBuilder.Create(ManualConfig.CreateEmpty().With(ConfigOptions.DisableOptimizationsValidator));

            Assert.DoesNotContain(JitOptimizationsValidator.FailOnError, disabled.GetValidators());
            Assert.DoesNotContain(JitOptimizationsValidator.DontFailOnError, disabled.GetValidators());

            var enabledThenDisabled = ImmutableConfigBuilder.Create(ManualConfig.CreateEmpty()
                                                                    .With(JitOptimizationsValidator.FailOnError)         // we enable it first (to mimic few configs merge)
                                                                    .With(ConfigOptions.DisableOptimizationsValidator)); // then disable

            Assert.DoesNotContain(JitOptimizationsValidator.FailOnError, enabledThenDisabled.GetValidators());
            Assert.DoesNotContain(JitOptimizationsValidator.DontFailOnError, enabledThenDisabled.GetValidators());
        }
        private static ImmutableConfig GetFullMethodConfig(MethodInfo method, ImmutableConfig typeConfig)
        {
            var methodAttributes = method.GetCustomAttributes(true).OfType <IConfigSource>();

            if (!methodAttributes.Any()) // the most common case
            {
                return(typeConfig);
            }

            var config = ManualConfig.Create(typeConfig);

            foreach (var configFromAttribute in methodAttributes)
            {
                config = ManualConfig.Union(config, configFromAttribute.Config);
            }

            return(ImmutableConfigBuilder.Create(config));
        }
Exemple #15
0
        public void WhenTwoCustomTimeoutsAreProvidedTheLongerOneIsUsed(bool direction)
        {
            var oneSecond  = ManualConfig.CreateEmpty().WithBuildTimeout(TimeSpan.FromSeconds(1));
            var twoSeconds = ManualConfig.CreateEmpty().WithBuildTimeout(TimeSpan.FromSeconds(2));

            if (direction)
            {
                oneSecond.Add(twoSeconds);
            }
            else
            {
                twoSeconds.Add(oneSecond);
            }

            var final = ImmutableConfigBuilder.Create(direction ? oneSecond : twoSeconds);

            Assert.Equal(TimeSpan.FromSeconds(2), final.BuildTimeout);
        }
        private static Summary CreateMockSummary(bool printUnitsInContent, bool printUnitsInHeader, TimeUnit timeUnit, double metricValue)
        {
            var summaryStyle  = new SummaryStyle(TestCultureInfo.Instance, printUnitsInHeader, null, timeUnit, printUnitsInContent);
            var config        = new ManualConfig().WithSummaryStyle(summaryStyle);
            var benchmarkCase = new BenchmarkCase(
                new Descriptor(null, null),
                Job.Dry,
                new ParameterInstances(ImmutableArray <ParameterInstance> .Empty),
                ImmutableConfigBuilder.Create(config));
            var metric          = new Metric(LocalMetricDescriptor.TimeInstance, metricValue);
            var benchmarkReport = new BenchmarkReport(true, benchmarkCase, null, null, null, new List <Metric>()
            {
                metric
            });

            return(new Summary("", new[] { benchmarkReport }.ToImmutableArray(), HostEnvironmentInfo.GetCurrent(),
                               "", "", TimeSpan.Zero, CultureInfo.InvariantCulture, ImmutableArray <ValidationError> .Empty, ImmutableArray <IColumnHidingRule> .Empty));
        }
        public static ImmutableConfig GetFullConfig(Type type, IConfig config)
        {
            config = config ?? DefaultConfig.Instance;
            if (type != null)
            {
                var typeAttributes     = type.GetTypeInfo().GetCustomAttributes(true).OfType <IConfigSource>();
                var assemblyAttributes = type.GetTypeInfo().Assembly.GetCustomAttributes().OfType <IConfigSource>();
                var allAttributes      = typeAttributes.Concat(assemblyAttributes);
                var configs            = allAttributes.Select(attribute => attribute.Config)
                                         .OrderBy(c => c.GetJobs().Count(job => job.Meta.IsMutator)); // configs with mutators must be the ones applied at the end

                foreach (var configFromAttribute in configs)
                {
                    config = ManualConfig.Union(config, configFromAttribute);
                }
            }

            return(ImmutableConfigBuilder.Create(config));
        }
        public void BaseLineValidatorIsMandatory()
        {
            var fromEmpty = ImmutableConfigBuilder.Create(ManualConfig.CreateEmpty());

            Assert.Contains(BaselineValidator.FailOnError, fromEmpty.GetValidators());
        }