2016-04-21 00:53:38 +00:00
|
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
2016-04-22 19:23:26 +00:00
|
|
|
|
using Microsoft.DotNet.TestFramework;
|
2016-04-21 00:53:38 +00:00
|
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using Xunit;
|
|
|
|
|
using Xunit.Abstractions;
|
|
|
|
|
using FluentAssertions;
|
2016-08-09 18:05:00 +00:00
|
|
|
|
using Microsoft.DotNet.PlatformAbstractions;
|
2016-04-21 00:53:38 +00:00
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Tests
|
|
|
|
|
{
|
|
|
|
|
public class GivenThatIWantToManageMulticoreJIT : TestBase
|
|
|
|
|
{
|
|
|
|
|
ITestOutputHelper _output;
|
2016-04-22 19:23:26 +00:00
|
|
|
|
private const string OptimizationProfileFileName = "dotnet";
|
2016-04-21 00:53:38 +00:00
|
|
|
|
|
|
|
|
|
public GivenThatIWantToManageMulticoreJIT(ITestOutputHelper output)
|
|
|
|
|
{
|
|
|
|
|
_output = output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2016-12-13 22:15:35 +00:00
|
|
|
|
public void WhenInvokedThenDotnetWritesOptimizationDataToTheProfileRoot()
|
2016-04-21 00:53:38 +00:00
|
|
|
|
{
|
2017-02-15 23:35:03 +00:00
|
|
|
|
var testDirectory = TestAssets.CreateTestDirectory();
|
2016-04-22 19:23:26 +00:00
|
|
|
|
var testStartTime = GetTruncatedDateTime();
|
|
|
|
|
|
2016-04-21 00:53:38 +00:00
|
|
|
|
new TestCommand("dotnet")
|
2017-02-15 23:35:03 +00:00
|
|
|
|
.WithUserProfileRoot(testDirectory.FullName)
|
2016-04-22 19:23:26 +00:00
|
|
|
|
.ExecuteWithCapturedOutput("--help");
|
|
|
|
|
|
2017-02-15 23:35:03 +00:00
|
|
|
|
var optimizationProfileFilePath = GetOptimizationProfileFilePath(testDirectory.FullName);
|
2016-04-21 00:53:38 +00:00
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
new FileInfo(optimizationProfileFilePath)
|
|
|
|
|
.Should().Exist("Because dotnet CLI creates it after each run")
|
|
|
|
|
.And.HaveLastWriteTimeUtc()
|
|
|
|
|
.Which.Should().BeOnOrAfter(testStartTime, "Because dotnet CLI was executed after that time");
|
2016-04-21 00:53:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-22 19:23:26 +00:00
|
|
|
|
[Fact]
|
2016-12-13 22:15:35 +00:00
|
|
|
|
public void WhenInvokedWithMulticoreJitDisabledThenDotnetDoesNotWriteOptimizationDataToTheProfileRoot()
|
2016-04-21 00:53:38 +00:00
|
|
|
|
{
|
2017-02-15 23:35:03 +00:00
|
|
|
|
var testDirectory = TestAssets.CreateTestDirectory();
|
2016-04-22 19:23:26 +00:00
|
|
|
|
var testStartTime = GetTruncatedDateTime();
|
|
|
|
|
|
|
|
|
|
new TestCommand("dotnet")
|
2017-02-15 23:35:03 +00:00
|
|
|
|
.WithUserProfileRoot(testDirectory.FullName)
|
2016-04-22 19:23:26 +00:00
|
|
|
|
.WithEnvironmentVariable("DOTNET_DISABLE_MULTICOREJIT", "1")
|
|
|
|
|
.ExecuteWithCapturedOutput("--help");
|
|
|
|
|
|
2017-02-15 23:35:03 +00:00
|
|
|
|
var optimizationProfileFilePath = GetOptimizationProfileFilePath(testDirectory.FullName);
|
2016-04-22 19:23:26 +00:00
|
|
|
|
|
|
|
|
|
File.Exists(optimizationProfileFilePath)
|
|
|
|
|
.Should().BeFalse("Because multicore JIT is disabled");
|
2016-04-21 00:53:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-22 19:23:26 +00:00
|
|
|
|
[Fact]
|
2016-12-13 22:15:35 +00:00
|
|
|
|
public void WhenTheProfileRootIsUndefinedThenDotnetDoesNotCrash()
|
2016-04-21 00:53:38 +00:00
|
|
|
|
{
|
2017-02-15 23:35:03 +00:00
|
|
|
|
var testDirectory = TestAssets.CreateTestDirectory();
|
2016-04-22 19:23:26 +00:00
|
|
|
|
var testStartTime = GetTruncatedDateTime();
|
|
|
|
|
|
2017-02-15 23:35:03 +00:00
|
|
|
|
var optimizationProfileFilePath = GetOptimizationProfileFilePath(testDirectory.FullName);
|
2016-04-22 19:23:26 +00:00
|
|
|
|
|
|
|
|
|
new TestCommand("dotnet")
|
|
|
|
|
.WithUserProfileRoot("")
|
|
|
|
|
.ExecuteWithCapturedOutput("--help")
|
|
|
|
|
.Should().Pass();
|
2016-04-21 00:53:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-22 19:23:26 +00:00
|
|
|
|
[Fact]
|
2016-12-13 22:15:35 +00:00
|
|
|
|
public void WhenCliRepoBuildsThenDotnetWritesOptimizationDataToTheDefaultProfileRoot()
|
2016-04-21 00:53:38 +00:00
|
|
|
|
{
|
2016-04-22 19:23:26 +00:00
|
|
|
|
var optimizationProfileFilePath = GetOptimizationProfileFilePath();
|
|
|
|
|
|
|
|
|
|
File.Exists(optimizationProfileFilePath)
|
|
|
|
|
.Should().BeTrue("Because the dotnet building dotnet writes to the default root");
|
2016-04-21 00:53:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-22 19:23:26 +00:00
|
|
|
|
private static string GetOptimizationProfileFilePath(string userHomePath = null)
|
2016-04-21 00:53:38 +00:00
|
|
|
|
{
|
2016-04-22 19:23:26 +00:00
|
|
|
|
return Path.Combine(
|
|
|
|
|
GetUserProfileRoot(userHomePath),
|
|
|
|
|
GetOptimizationRootPath(GetDotnetVersion()),
|
|
|
|
|
OptimizationProfileFileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetUserProfileRoot(string overrideUserProfileRoot = null)
|
|
|
|
|
{
|
|
|
|
|
if (overrideUserProfileRoot != null)
|
|
|
|
|
{
|
|
|
|
|
return overrideUserProfileRoot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
|
|
|
|
|
? Environment.GetEnvironmentVariable("LocalAppData")
|
|
|
|
|
: Environment.GetEnvironmentVariable("HOME");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetOptimizationRootPath(string version)
|
|
|
|
|
{
|
2017-01-26 03:19:44 +00:00
|
|
|
|
var rid = PlatformAbstractions.RuntimeEnvironment.GetRuntimeIdentifier();
|
2016-04-22 19:23:26 +00:00
|
|
|
|
|
|
|
|
|
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
|
2016-05-26 03:41:10 +00:00
|
|
|
|
? $@"Microsoft\dotnet\optimizationdata\{version}\{rid}"
|
|
|
|
|
: $@".dotnet/optimizationdata/{version}/{rid}";
|
2016-04-21 00:53:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetDotnetVersion()
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
return new TestCommand("dotnet")
|
|
|
|
|
.ExecuteWithCapturedOutput("--version" )
|
2016-04-21 00:53:38 +00:00
|
|
|
|
.StdOut
|
|
|
|
|
.Trim();
|
|
|
|
|
}
|
2016-04-22 19:23:26 +00:00
|
|
|
|
|
|
|
|
|
private static DateTime GetTruncatedDateTime()
|
|
|
|
|
{
|
|
|
|
|
var dt = DateTime.UtcNow;
|
|
|
|
|
|
|
|
|
|
return new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second, 0, dt.Kind);
|
|
|
|
|
}
|
2016-04-21 00:53:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|