onnxruntime/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Devices/TestResultProcessor.cs
Brian Martin 6c236fd939 Merged PR 6622174: merge latest onnxruntime into dmldev
there was a merge conflict in onnxruntime/core/providers/dml/OperatorAuthorHelper/Common.h that required manual merging.

Related work items: #36867798
2021-10-30 19:59:33 +00:00

52 lines
No EOL
1.7 KiB
C#

using System;
using System.Collections.Concurrent;
using System.Globalization;
using System.Linq;
using Newtonsoft.Json;
using Xunit.Abstractions;
namespace Microsoft.ML.OnnxRuntime.Tests.Devices
{
public class TestResultProcessor
{
ConcurrentBag<TestResult> _results = new ConcurrentBag<TestResult>();
public ConcurrentBag<TestResult> Results
{
get => _results == null ? (_results = new ConcurrentBag<TestResult>()) : _results;
private set => _results = value;
}
internal void RecordResult(TestResult test)
=> Results.Add(test);
public void RecordResult(ITestResultMessage testResult, ITestCase testCase, TestOutcome outcome)
{
try
{
RecordResult(new TestResult
{
TestId = testCase.UniqueID,
TestName = testCase.DisplayName,
Output = testResult.Output,
TestOutcome = outcome,
Duration = TimeSpan.FromSeconds((double)testResult.ExecutionTime).ToString("c", CultureInfo.InvariantCulture)
});
}
catch (Exception ex)
{
System.Diagnostics.Trace.TraceError(ex.Message);
}
}
public TestResultSummary GetResults()
=> new TestResultSummary(Results.ToList());
public string GetSerializedResults()
{
var resultSummary = GetResults();
var serializedResultSummary = JsonConvert.SerializeObject(resultSummary, Formatting.Indented);
return serializedResultSummary;
}
}
}