Skip to content

Commit 1592eff

Browse files
saibulususaibulusu
andauthored
dotnet runtime migration to open-source (#722)
* Migrating dotnet cpu runtime from internal. * Very minor documentation change. * adding one example file * upversion --------- Co-authored-by: saibulusu <saibulusu@microsoft.com>
1 parent 4ee151c commit 1592eff

12 files changed

Lines changed: 887 additions & 1 deletion

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.3.1
1+
3.3.2
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
namespace VirtualClient.Actions
5+
{
6+
using System;
7+
using System.Collections.Generic;
8+
using System.IO;
9+
using System.Reflection;
10+
using System.Threading;
11+
using System.Threading.Tasks;
12+
using AutoFixture;
13+
using VirtualClient;
14+
using VirtualClient.Common.Telemetry;
15+
using VirtualClient.Contracts;
16+
using Microsoft.Extensions.DependencyInjection;
17+
using Moq;
18+
using NUnit.Framework;
19+
20+
[TestFixture]
21+
[Category("Unit")]
22+
[Platform(Exclude = "Unix,Linux,MacOsX")]
23+
public class DotNetRuntimeExecutorTests
24+
{
25+
private MockFixture fixture;
26+
private DependencyPath mockPath;
27+
private DependencyPath currentDirectoryPath;
28+
private string rawString;
29+
30+
[SetUp]
31+
public void SetUpTests()
32+
{
33+
this.fixture = new MockFixture();
34+
this.fixture.Setup(PlatformID.Win32NT);
35+
this.mockPath = this.fixture.Create<DependencyPath>();
36+
this.fixture.Parameters = new Dictionary<string, IConvertible>
37+
{
38+
{ "PackageName", "DotNetRuntime" }
39+
};
40+
41+
this.SetupDefaultMockBehavior();
42+
}
43+
44+
[Test]
45+
public async Task DotNetRuntimeExecutorInitializesItsDependenciesAsExpected()
46+
{
47+
using (TestDotNetRuntimeExecutor executor = new TestDotNetRuntimeExecutor(this.fixture))
48+
{
49+
Assert.IsNull(executor.ExecutablePath);
50+
51+
await executor.InitializeAsync(EventContext.None, CancellationToken.None)
52+
.ConfigureAwait(false);
53+
54+
string expectedPath = this.fixture.PlatformSpecifics.Combine(
55+
this.mockPath.Path, "win-x64", "dotnet.bat");
56+
Assert.AreEqual(expectedPath, executor.ExecutablePath);
57+
}
58+
}
59+
60+
[Test]
61+
public void DotNetRuntimeExecutorThrowsOnInitializationWhenTheWorkloadPackageIsNotFound()
62+
{
63+
this.fixture.PackageManager.OnGetPackage().ReturnsAsync(null as DependencyPath);
64+
using (TestDotNetRuntimeExecutor executor = new TestDotNetRuntimeExecutor(this.fixture))
65+
{
66+
DependencyException exception = Assert.ThrowsAsync<DependencyException>(
67+
() => executor.InitializeAsync(EventContext.None, CancellationToken.None));
68+
Assert.AreEqual(ErrorReason.WorkloadDependencyMissing, exception.Reason);
69+
}
70+
}
71+
72+
[Test]
73+
[Ignore("There is some kind of very unusual and difficult to determine anomaly that causes this method to fail to run due to a call to the IProcessProxy.Kill() method downstream.")]
74+
public async Task DotNetRuntimeExecutorExecutesWorkloadAsExpected()
75+
{
76+
using (TestDotNetRuntimeExecutor executor = new TestDotNetRuntimeExecutor(this.fixture))
77+
{
78+
string expectedFilePath = this.fixture.PlatformSpecifics.Combine(this.mockPath.Path, "runtimes", "win-x64", "dotnet.bat");
79+
int executed = 0;
80+
this.fixture.ProcessManager.OnCreateProcess = (file, arguments, workingDirectory) =>
81+
{
82+
executed++;
83+
Assert.AreEqual(expectedFilePath, file);
84+
return this.fixture.Process;
85+
};
86+
87+
await executor.ExecuteAsync(EventContext.None, CancellationToken.None)
88+
.ConfigureAwait(false);
89+
90+
Assert.AreEqual(1, executed);
91+
}
92+
}
93+
94+
[Test]
95+
[Ignore("There is some kind of very unusual and difficult to determine anomaly that causes this method to fail to run due to a call to the IProcessProxy.Kill() method downstream.")]
96+
public void DotNetRuntimeExecutorThrowsWorkloadExceptionWhenTheResultsFileIsNotGenerated()
97+
{
98+
using (TestDotNetRuntimeExecutor executor = new TestDotNetRuntimeExecutor(this.fixture))
99+
{
100+
this.fixture.ProcessManager.OnCreateProcess = (file, arguments, workingDirectory) =>
101+
{
102+
this.fixture.FileSystem.Setup(fe => fe.File.Exists(executor.ResultsFilePath)).Returns(false);
103+
return this.fixture.Process;
104+
};
105+
106+
WorkloadException exception = Assert.ThrowsAsync<WorkloadException>(
107+
() => executor.ExecuteAsync(EventContext.None, CancellationToken.None));
108+
Assert.AreEqual(ErrorReason.WorkloadFailed, exception.Reason);
109+
}
110+
}
111+
112+
private void SetupDefaultMockBehavior()
113+
{
114+
string currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
115+
this.currentDirectoryPath = new DependencyPath("DotNetRuntime", currentDirectory);
116+
string resultsPath = this.fixture.PlatformSpecifics.Combine(this.currentDirectoryPath.Path, "Examples", "DotNetRuntimeResultsExample.txt");
117+
this.rawString = File.ReadAllText(resultsPath);
118+
this.fixture.FileSystem.Setup(fe => fe.File.Exists(It.IsAny<string>())).Returns(true);
119+
this.fixture.FileSystem.Setup(fe => fe.File.Exists(null)).Returns(false);
120+
this.fixture.FileSystem.Setup(fc => fc.File.Copy(It.IsAny<string>(), It.IsAny<string>()));
121+
this.fixture.Directory.Setup(d => d.Exists(It.IsAny<string>()))
122+
.Returns(true);
123+
124+
this.fixture.FileSystem.Setup(rt => rt.File.ReadAllTextAsync(It.IsAny<string>(), It.IsAny<CancellationToken>()))
125+
.ReturnsAsync(this.rawString);
126+
127+
this.fixture.PackageManager.OnGetPackage().ReturnsAsync(this.mockPath);
128+
this.fixture.ProcessManager.OnCreateProcess = (command, arguments, directory) => this.fixture.Process;
129+
}
130+
131+
private class TestDotNetRuntimeExecutor : DotNetRuntimeExecutor
132+
{
133+
public TestDotNetRuntimeExecutor(MockFixture fixture)
134+
: base(fixture.Dependencies, fixture.Parameters)
135+
{
136+
}
137+
138+
public TestDotNetRuntimeExecutor(IServiceCollection dependencies, IDictionary<string, IConvertible> parameters)
139+
: base(dependencies, parameters)
140+
{
141+
}
142+
143+
public new Task InitializeAsync(EventContext telemetryContext, CancellationToken cancellationToken)
144+
{
145+
return base.InitializeAsync(telemetryContext, cancellationToken);
146+
}
147+
148+
public new Task ExecuteAsync(EventContext context, CancellationToken cancellationToken)
149+
{
150+
this.InitializeAsync(context, cancellationToken).GetAwaiter().GetResult();
151+
return base.ExecuteAsync(context, cancellationToken);
152+
}
153+
}
154+
}
155+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Reflection;
6+
using VirtualClient.Contracts;
7+
using NUnit.Framework;
8+
using VirtualClient;
9+
10+
namespace VirtualClient.Actions
11+
{
12+
13+
[TestFixture]
14+
[Category("Unit")]
15+
internal class DotNetRuntimeMetricsParserUnitTests
16+
{
17+
private string rawText;
18+
private DotNetRuntimeMetricsParser testParser;
19+
20+
[SetUp]
21+
public void Setup()
22+
{
23+
string workingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
24+
string outputPath = Path.Combine(workingDirectory, @"Examples", "DotNetRuntimeResultsExample.txt");
25+
this.rawText = File.ReadAllText(outputPath);
26+
this.testParser = new DotNetRuntimeMetricsParser(this.rawText);
27+
}
28+
29+
[Test]
30+
public void DotNetRuntimeParserVerifyThroughputResult()
31+
{
32+
this.testParser.Parse();
33+
this.testParser.ThroughputResult.PrintDataTableFormatted();
34+
Assert.AreEqual(4, this.testParser.ThroughputResult.Columns.Count);
35+
}
36+
37+
[Test]
38+
public void DotNetRuntimeParserVerifyMetrics()
39+
{
40+
IList<Metric> metrics = this.testParser.Parse();
41+
MetricAssert.Exists(metrics, "throughput", 11284.51, "bops");
42+
}
43+
44+
[Test]
45+
public void DotNetRuntimeParserThrowIfInvalidOutputFormat()
46+
{
47+
string workingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
48+
string IncorrectDotNetoutputPath =Path.Combine(workingDirectory, @"Examples", "IncorrectDotNetRuntimeResultsExample.txt");
49+
this.rawText = File.ReadAllText(IncorrectDotNetoutputPath);
50+
this.testParser = new DotNetRuntimeMetricsParser(this.rawText);
51+
SchemaException exception = Assert.Throws<SchemaException>(() => this.testParser.Parse());
52+
StringAssert.Contains("The DotNetRuntime output file has incorrect format for parsing", exception.Message);
53+
}
54+
}
55+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
===============================================================================
2+
TOTALS FOR: COMPANY with 8 warehouses
3+
........ .NET fixed throughput benchmark 1.0 Results (time in seconds) ........
4+
Count Total Min Max Avg Heap Space
5+
New Order: 9142643 4568.99 0.000 ****** 0.000 total 0.0MB
6+
Payment: 6101520 2572.06 0.000 ****** 0.000 used 0.0MB
7+
OrderStatus: 691503 368.25 0.000 39.781 0.001
8+
Delivery: 671169 3068.53 0.000 ****** 0.005
9+
Stock Level: 671171 693.12 0.000 79.547 0.001
10+
Cust Report: 3060386 1945.34 0.000 ****** 0.001
11+
12+
throughput = 11284.51 bops
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This file is IncorrectDotNetRuntime example.

0 commit comments

Comments
 (0)