Run() public méthode

public Run ( string assemblyPath ) : int
assemblyPath string
Résultat int
        /// <summary>
        /// Run the xUnit tests tagged with the [<see cref="BenchmarkAttribute"/>] attribute.
        /// </summary>
        /// <param name="assemblyFileName">Path to the assembly that contains the xUnit performance tests.</param>
        public void RunBenchmarks(string assemblyFileName)
        {
            if (string.IsNullOrEmpty(assemblyFileName))
            {
                throw new ArgumentNullException(nameof(assemblyFileName));
            }
            if (!File.Exists(assemblyFileName))
            {
                throw new FileNotFoundException(assemblyFileName);
            }

            void xUnitAction(string assemblyPath)
            {
                var errCode = XunitRunner.Run(assemblyPath, _typeNames);

                if (errCode != 0)
                {
                    throw new Exception($"{errCode} benchmark(s) failed to execute.");
                }
            }

            var xUnitPerformanceSessionData = new XUnitPerformanceSessionData
            {
                AssemblyFileName           = assemblyFileName,
                CollectOutputFilesCallback = LogFileSaved,
                OutputDirectory            = OutputDirectory,
                RunId = Configuration.RunId
            };

            var xUnitPerformanceMetricData = XunitBenchmark.GetMetadata(
                assemblyFileName,
                _metricCollectionFactory.GetMetrics(),
                _collectDefaultXUnitMetrics);

            if (IsWindowsPlatform && _requireEtw)
            {
                void winRunner()
                {
                    xUnitAction(assemblyFileName);
                }

                ETWProfiler.Record(
                    xUnitPerformanceSessionData,
                    xUnitPerformanceMetricData,
                    winRunner);
            }
            else
            {
                xUnitAction(assemblyFileName);
                ProcessResults(xUnitPerformanceSessionData, xUnitPerformanceMetricData);
            }
        }
        public void RunBenchmarks(string assemblyPath)
        {
            if (string.IsNullOrEmpty(assemblyPath))
            {
                throw new ArgumentNullException(nameof(assemblyPath));
            }

            if(!File.Exists(assemblyPath))
            {
                throw new FileNotFoundException(assemblyPath);
            }

            // Invoke xunit to run benchmarks in the specified assembly.
            XunitRunner runner = new XunitRunner();
            runner.Run(assemblyPath);
        }
Exemple #3
0
        public XunitPerformanceHarness(string[] args)
        {
            _args        = args;
            _disposed    = false;
            _outputFiles = new List <string>();

            var options = XunitPerformanceHarnessOptions.Parse(args);

            // Set the run id.
            _outputDirectory = options.OutputDirectory;
            _typeNames       = new List <string>(options.TypeNames);
            _runner          = (assemblyPath) =>
            {
                XunitRunner.Run(assemblyPath, _typeNames);
            };

            Configuration.RunId = options.RunId;
            // Set the file log path.
            // TODO: Conditionally set this based on whether we want a csv file written.
            Configuration.FileLogPath = Configuration.RunId + ".csv";
        }
        public void RunBenchmarks(string assemblyFileName)
        {
            Validate(assemblyFileName);

            Action <string> xUnitAction = (assemblyPath) => { XunitRunner.Run(assemblyPath, _typeNames); };
            var             xUnitPerformanceSessionData = new XUnitPerformanceSessionData {
                AssemblyFileName           = assemblyFileName,
                CollectOutputFilesCallback = (fileName) => {
                    // FIXME: This will need safe guards when the client calls RunBenchmarks in different threads.
                    _outputFiles.Add(fileName);
                    WriteInfoLine($"File saved to: \"{fileName}\"");
                },
                OutputDirectory = OutputDirectory,
                RunId           = Configuration.RunId
            };

            var metrics = _metricCollectionFactory.GetMetrics(assemblyFileName);
            var xUnitPerformanceMetricData = XunitBenchmark.GetMetadata(
                assemblyFileName,
                metrics,
                _collectDefaultXUnitMetrics);

            if (IsWindowsPlatform && _requireEtw)
            {
                Action winRunner = () => { xUnitAction(assemblyFileName); };
                ETWProfiler.Record(
                    xUnitPerformanceSessionData,
                    xUnitPerformanceMetricData,
                    winRunner);
            }
            else
            {
                xUnitAction.Invoke(assemblyFileName);
                ProcessResults(xUnitPerformanceSessionData, xUnitPerformanceMetricData);
            }
        }