Skip to content

Commit

Permalink
Make CoreFx.Private.TestUtilites RID-agnostic (dotnet#36207)
Browse files Browse the repository at this point in the history
* Make CoreFx.Private.TestUtilites RID-agnostic

* Add version checks for other distros

dotnet@4f0d107
Porting fix over into PlatformDetection.

* Build test lib in advance for VS support

* Disable pretest in AllConfigurations
  • Loading branch information
ViktorHofer authored Jun 29, 2019
1 parent 0decf07 commit d3d144f
Show file tree
Hide file tree
Showing 67 changed files with 641 additions and 1,940 deletions.
11 changes: 1 addition & 10 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<UseSharedCompilation>true</UseSharedCompilation>

<ToolSetCommonDirectory>$(MSBuildThisFileDirectory)artifacts\toolset\Common\</ToolSetCommonDirectory>
<IsSourceProject Condition="'$(MSBuildProjectName)' != 'CoreFx.Private.TestUtilities'">$([System.Text.RegularExpressions.Regex]::IsMatch($(MSBuildProjectDirectory), 'src%24'))</IsSourceProject>
<IsSourceProject>$([System.Text.RegularExpressions.Regex]::IsMatch($(MSBuildProjectDirectory), 'src%24'))</IsSourceProject>
</PropertyGroup>

<!-- Define vNext UAP Moniker -->
Expand Down Expand Up @@ -295,9 +295,7 @@
<RuntimePath Condition="'$(RuntimePath)' == ''">$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'runtime', '$(BuildConfiguration)'))</RuntimePath>
<RefRootPath>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'ref'))</RefRootPath>
<BuildConfigurationRefPath>$([MSBuild]::NormalizeDirectory('$(RefRootPath)', '$(_bc_TargetGroup)'))</BuildConfigurationRefPath>
<BuildConfigurationRefPath Condition="$(_bc_TargetGroup.EndsWith('aot'))">$([MSBuild]::NormalizeDirectory('$(RefRootPath)', '$(_bc_TargetGroup.TrimEnd('aot'))'))</BuildConfigurationRefPath>
<RefPath>$([MSBuild]::NormalizeDirectory('$(RefRootPath)', '$(TargetGroup)'))</RefPath>
<RefPath Condition="$(TargetGroup.EndsWith('aot'))">$([MSBuild]::NormalizeDirectory('$(RefRootPath)', '$(TargetGroup.TrimEnd('aot'))'))</RefPath>
<NetStandardRefPath>$([MSBuild]::NormalizeDirectory('$(RefRootPath)', 'netstandard'))</NetStandardRefPath>
<NetStandard21RefPath>$([MSBuild]::NormalizeDirectory('$(RefRootPath)', 'netstandard2.1'))</NetStandard21RefPath>
<NetFxRefPath>$([MSBuild]::NormalizeDirectory('$(RefRootPath)', 'netfx'))</NetFxRefPath>
Expand Down Expand Up @@ -343,13 +341,6 @@
<UAPTestSharedFrameworkPath>$(TestHostRootPath)UAPLayout</UAPTestSharedFrameworkPath>
</PropertyGroup>

<!--
Remove test-only dependencies during source-build: disable project that brings in XUnit.Runtime
dependencies through 'ReferenceFromRuntime' property.
-->
<ItemGroup Condition="'$(DotNetBuildFromSource)' == 'true' and '$(BuildTests)' != 'true'">
<ProjectExclusions Include="$(SourceDir)CoreFx.Private.TestUtilities/**/*.csproj" />
</ItemGroup>
<!-- AOT only asset that we currently don't support. -->
<ItemGroup>
<ProjectExclusions Include="$(SourceDir)System.Private.Reflection.Metadata.Ecma335/**/*.csproj" />
Expand Down
3 changes: 0 additions & 3 deletions build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@

<ItemGroup Condition="'$(DotNetBuildFromSource)' != 'true'">
<_RestoreProjects Include="$(SourceDir)tests.proj" Build="false" />
<!-- Remove when ref and src project restore is enabled. -->
<_RestoreProjects Include="$(SourceDir)CoreFx.Private.TestUtilities\ref\CoreFx.Private.TestUtilities.csproj" Build="false" />
<_RestoreProjects Include="$(SourceDir)CoreFx.Private.TestUtilities\src\CoreFx.Private.TestUtilities.csproj" Build="false" />
</ItemGroup>

<MSBuild Projects="@(_RestoreProjects)" Targets="Restore" Properties="$(ProjectProperties)" />
Expand Down
3 changes: 2 additions & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
<TraceEventPackageVersion>2.0.5</TraceEventPackageVersion>
<MicrosoftDotNetUapTestToolsPackageVersion>1.0.31</MicrosoftDotNetUapTestToolsPackageVersion>
<NewtonsoftJsonPackageVersion>12.0.1</NewtonsoftJsonPackageVersion>
<MicrosoftExtensionsDependencyModelPackageVersion>3.0.0-preview5-27626-15</MicrosoftExtensionsDependencyModelPackageVersion>
<MicrosoftExtensionsDependencyModelPackageVersion>3.0.0-preview6-27804-01</MicrosoftExtensionsDependencyModelPackageVersion>
<MicrosoftDotNetPlatformAbstractionsPackageVersion>3.0.0-preview6-27804-01</MicrosoftDotNetPlatformAbstractionsPackageVersion>
<!-- Test data -->
<SystemIOCompressionTestDataPackageVersion>1.0.13</SystemIOCompressionTestDataPackageVersion>
<SystemIOPackagingTestDataPackageVersion>1.0.4</SystemIOPackagingTestDataPackageVersion>
Expand Down
7 changes: 0 additions & 7 deletions pkg/Microsoft.Private.PackageBaseline/packageIndex.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
"net45": "4.0.0.0"
}
},
"CoreFx.Private.TestUtilities": {
"InboxOn": {},
"AssemblyVersionInPackageVersion": {
"1.0.0.0": "4.5.0",
"1.0.1.0": "4.6.0"
}
},
"CustomMarshalers": {
"InboxOn": {
"net45": "4.0.0.0"
Expand Down
5 changes: 0 additions & 5 deletions pkg/descriptions.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
[
{
"Name": "CoreFx.Private.TestUtilities",
"Description": "Private package, which provides testing utility classes. The package is meant to be used when running CoreFX tests on a runtime.",
"CommonTypes": []
},
{
"Name": "RuntimePackage",
"Description": "Internal implementation package not meant for direct consumption. Please do not reference directly.",
Expand Down
1 change: 0 additions & 1 deletion pkg/test/testPackages.proj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

<ItemGroup>
<TestPackages Condition="'$(TestPackages)' != ''" Include="$(TestPackages)" />
<ExcludePackages Include="CoreFx.Private.TestUtilities" />
<ExcludePackages Include="$(ExcludePackages)" />

<PackageReports Condition="'@(TestPackages)' == ''" Include="$(PackageReportDir)*.json" Exclude="@(ExcludePackages->'$(PackageReportDir)%(Identity).json')"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<BuildConfigurations>
netcoreapp;
netstandard;
netfx;
uap;
</BuildConfigurations>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<ProjectGuid>{EBDB0247-CA43-4226-B7A1-8FEF21061D09}</ProjectGuid>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>$(NoWarn);CS1573</NoWarn>
<!--
This assembly is referenced from rid agnostic configurations therefore we can't make it RID specific
and instead use runtime checks.
-->
<Configurations>netcoreapp-Debug;netcoreapp-Release;netstandard-Debug;netstandard-Release</Configurations>
</PropertyGroup>

<ItemGroup>
<Compile Include="System\AdminHelpers.cs" />
<Compile Include="System\AssertExtensions.cs" />
<Compile Include="System\RetryHelper.cs" />
<Compile Include="System\Buffers\BoundedMemory.cs" />
<Compile Include="System\Buffers\BoundedMemory.Creation.cs" />
<Compile Include="System\Buffers\BoundedMemory.Unix.cs" />
<Compile Include="System\Buffers\BoundedMemory.Windows.cs" />
<Compile Include="System\Buffers\PoisonPagePlacement.cs" />
<Compile Include="System\IO\FileCleanupTestBase.cs" />
<Compile Include="System\TestEnvironment.cs" />
<!-- We don't compile per but and instead use runtime platform checks. -->
<Compile Include="System\PlatformDetection.cs" />
<Compile Include="System\PlatformDetection.Unix.cs" />
<Compile Include="System\PlatformDetection.Windows.cs" />
<!--
Interop.Library is not designed to support runtime checks therefore we are picking the Windows
variant from the Common folder and adding the missing members manually.
-->
<Compile Include="Interop\Interop.Libraries.cs" />
</ItemGroup>
<!-- Windows imports -->
<ItemGroup>
<Compile Include="$(CommonPath)\CoreLib\Interop\Windows\Kernel32\Interop.GetCurrentProcess_IntPtr.cs">
<Link>Common\Interop\Windows\Kernel32\Interop.GetCurrentProcess_IntPtr.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\NtDll\Interop.RTL_OSVERSIONINFOEX.cs">
<Link>Common\Interop\Windows\NtDll\Interop.RTL_OSVERSIONINFOEX.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\NtDll\Interop.RtlGetVersion.cs">
<Link>Common\Interop\Windows\NtDll\Interop.RtlGetVersion.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\Advapi32\Interop.OpenProcessToken_SafeAccessTokenHandle.cs">
<Link>Common\Interop\Windows\Advapi32\Interop.OpenProcessToken_SafeAccessTokenHandle.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\Interop.Libraries.cs">
<Link>Common\Interop\Windows\Interop.Libraries.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\CoreLib\Interop\Windows\Kernel32\Interop.CloseHandle.cs">
<Link>Common\CoreLib\Interop\Windows\Kernel32\Interop.CloseHandle.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\Advapi32\Interop.TOKEN_INFORMATION_CLASS.cs">
<Link>Common\Interop\Windows\Advapi32\Interop.TOKEN_INFORMATION_CLASS.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\Advapi32\Interop.GetTokenInformation_void.cs">
<Link>Common\Interop\Windows\Advapi32\Interop.GetTokenInformation_void.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\Advapi32\Interop.TOKEN_ELEVATION.cs">
<Link>Common\Interop\Windows\Advapi32\Interop.TOKEN_ELEVATION.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\CoreLib\Interop\Windows\Interop.BOOL.cs">
<Link>Common\CoreLib\Interop\Windows\Interop.BOOL.cs</Link>
</Compile>
</ItemGroup>
<!-- Unix imports -->
<ItemGroup>
<Compile Include="$(CommonPath)\Interop\Unix\System.Security.Cryptography.Native\Interop.OpenSslVersion.cs">
<Link>Common\Interop\Unix\System.Security.Cryptography.Native\Interop.OpenSslVersion.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\CoreLib\Interop\Unix\System.Native\Interop.GetEUid.cs">
<Link>Common\Interop\Unix\Interop.GetEUid.cs</Link>
</Compile>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.DotNet.XUnitExtensions" Version="$(MicrosoftDotNetXUnitExtensionsPackageVersion)" />
<PackageReference Include="xunit.core" Version="$(XUnitPackageVersion)" ExcludeAssets="build" />
<PackageReference Include="xunit.assert" Version="$(XUnitPackageVersion)" />
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="$(MicrosoftDotNetPlatformAbstractionsPackageVersion)" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

internal static partial class Interop
{
internal static partial class Libraries
{
// Shims
public const string CryptoNative = "System.Security.Cryptography.Native.OpenSsl";
public const string SystemNative = "System.Native";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,44 @@
// See the LICENSE file in the project root for more information.

using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Security.Principal;
using Microsoft.Win32.SafeHandles;
using Xunit;

namespace System
{
public static partial class AdminHelpers
public static class AdminHelpers
{
/// <summary>
/// Returns true if the current process is elevated (in Windows).
/// Runs the given command as sudo (for Unix).
/// </summary>
/// <param name="commandLine">The command line to run as sudo</param>
/// <returns> Returns the process exit code (0 typically means it is successful)</returns>
public static int RunAsSudo(string commandLine)
{
ProcessStartInfo startInfo = new ProcessStartInfo()
{
FileName = "sudo",
Arguments = commandLine
};

using (Process process = Process.Start(startInfo))
{
Assert.True(process.WaitForExit(30000));
return process.ExitCode;
}
}

public unsafe static bool IsProcessElevated()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
uint userId = Interop.Sys.GetEUid();
return(userId == 0);
}

IntPtr processHandle = Interop.Kernel32.GetCurrentProcess();
SafeAccessTokenHandle token;
if (!Interop.Advapi32.OpenProcessToken(processHandle, TokenAccessLevels.Read, out token))
Expand All @@ -39,6 +64,5 @@ public unsafe static bool IsProcessElevated()
return elevation.TokenIsElevated != Interop.BOOL.FALSE;
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,17 @@ private static void FillRandom(Span<byte> buffer)
buffer[i] = (byte)random.Next();
}
}

private static BoundedMemory<T> AllocateWithoutDataPopulation<T>(int elementCount, PoisonPagePlacement placement) where T : unmanaged
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return AllocateWithoutDataPopulationWindows<T>(elementCount, placement);
}
else
{
return AllocateWithoutDataPopulationUnix<T>(elementCount, placement);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ namespace System.Buffers
{
public static partial class BoundedMemory
{
private static UnixImplementation<T> AllocateWithoutDataPopulation<T>(int elementCount, PoisonPagePlacement placement) where T : unmanaged
private static UnixImplementation<T> AllocateWithoutDataPopulationUnix<T>(int elementCount, PoisonPagePlacement placement) where T : unmanaged
{
// On non-Windows platforms, we don't yet have support for changing the permissions of individual pages.

return new UnixImplementation<T>(elementCount);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static unsafe partial class BoundedMemory
{
private static readonly int SystemPageSize = Environment.SystemPageSize;

private static WindowsImplementation<T> AllocateWithoutDataPopulation<T>(int elementCount, PoisonPagePlacement placement) where T : unmanaged
private static WindowsImplementation<T> AllocateWithoutDataPopulationWindows<T>(int elementCount, PoisonPagePlacement placement) where T : unmanaged
{
long cb, totalBytesToAllocate;
checked
Expand Down
Loading

0 comments on commit d3d144f

Please sign in to comment.