Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

[WIP] Enable CoreFX tests on CoreRT #5287

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Framework/Framework-uapaot.depproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<FileToInclude Include="System.Reflection.Primitives" />
<FileToInclude Include="System.Runtime.InteropServices" />
<FileToInclude Include="System.Text.RegularExpressions" />
<FileToInclude Include="System.Private.Xml" />
<FileToInclude Include="System.Private.Xml.Linq" />

<FileToInclude Include="System.Private.Reflection.Metadata.Ecma335" />
</ItemGroup>
Expand Down
49 changes: 49 additions & 0 deletions tests/CoreFX/build-and-run-test.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
:: Test build and execution wrapper for CoreFX tests
::
:: This wrapper is called for each of CoreFX's tests by runtest.cmd
::
:: %1 contains test folder
:: %2 contains test exe name
::
@echo OFF
setlocal ENABLEDELAYEDEXPANSION

set TestFolder=%1

::
:: We're only interested in referencing the xunit runner - the test dlls will be imported by the test wrapper project
::
set TestExecutable=xunit.console.netcore
set TestFileName=%2


:: Copy the artefacts we need to compile and run the xunit exe
copy /Y "%~dp0\runtest\CoreFXTestHarness\*" "%TestFolder%" >nul

:: Create log dir if it doesn't exist
if not exist %XunitLogDir% md %XunitLogDir%

if not exist %TestFolder%\%TestExecutable%.exe (
:: Not a test we support yet, exit silently
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests not run by Helix (e.g. AssemblyResolve). Technically, this shouldn't ever happen, but in case the test format changes, this degrades more gracefully.
Ideally, the need for this will be completely eliminated once we add a CoreRT parallel to the uap-aot target for CoreFX.

exit /b 0
)

:: Workaround until we have a better reflection engine
:: Add name of currently executing test to rd.xml
powershell -Command "(Get-Content %TestFolder%\default.rd.xml).replace('*Application*', '%TestFileName%') | Set-Content %TestFolder%\default.rd.xml"

if "%CoreRT_BuildArch%" == "x64" (
call "%VS140COMNTOOLS%\..\..\VC\bin\amd64\vcvars64.bat" >nul
)

echo Build %TestFileName%

call "%CoreRT_CliDir%\dotnet.exe" publish %TestFolder%\Test.csproj /ConsoleLoggerParameters:ForceNoAlign "/p:IlcPath=%CoreRT_ToolchainDir%" "/p:DebugSymbols=false" "/p:Configuration=%CoreRT_BuildType%" "/p:FrameworkLibPath=%~dp0..\..\bin\%CoreRT_BuildOS%.%CoreRT_BuildArch%.%CoreRT_BuildType%\lib" "/p:FrameworkObjPath=%~dp0..\..\bin\obj\%CoreRT_BuildOS%.%CoreRT_BuildArch%.%CoreRT_BuildType%\Framework" /p:DisableFrameworkLibGeneration=true /p:TestRootDir=%~dp0 /p:ExecutableName=%TestExecutable% /nologo
if errorlevel 1 (
echo Building %TestFileName% failed
exit /b 1
)

echo Executing %TestFileName%

call %TestFolder%\native\%TestExecutable% %TestFolder%\%TestFileName%.dll -xml %XunitLogDir%\%TestFileName%.xml
82 changes: 82 additions & 0 deletions tests/CoreFX/corerun
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env bash

# This is the Unix equivalent of build-and-run-test.cmd
# It is invoked by each test's bash script. The reason it's called corerun is that
# the unix CoreCLR tests don't have a custom runner override environment variable.
# See issue https://github.com/dotnet/coreclr/issues/9007
# The CoreFX alternative is named corerun to keep parity with CoreCLR's testing infrastructure

#!/usr/bin/env bash

# This is the Unix equivalent of build-and-run-test.cmd
# It is invoked by each test's bash script. The reason it's called corerun is that
# the unix CoreCLR tests don't have a custom runner override environment variable.
# See issue https://github.com/dotnet/coreclr/issues/9007

export TestExecutable=$1
export TestFileName=${TestExecutable%.*}

source "$CoreRT_TestRoot/coredump_handling.sh"

if [[ $CoreRT_EnableCoreDumps == 1 ]]; then
set_up_core_dump_generation
fi

cp -ar $CoreRT_TestRoot/CoreCLR/. .

# Workaround until we have a better reflection engine
# Add name of currently executing test to rd.xml

$__dotnetclipath/dotnet publish


__msbuild_dir=${CoreRT_TestRoot}/../Tools
echo ${__msbuild_dir}/msbuild.sh /m /p:IlcPath=${CoreRT_ToolchainDir} /p:Configuration=${CoreRT_BuildType} Test.csproj
${__msbuild_dir}/msbuild.sh /m /p:IlcPath=${CoreRT_ToolchainDir} /p:Configuration=${CoreRT_BuildType} Test.csproj

if [[ $CoreRT_EnableCoreDumps == 1 ]]; then
# Handle any core files generated when running the test IL through the toolchain.
inspect_and_delete_core_files $CoreRT_ToolchainDir/corerun "$CoreRT_ToolchainDir"
fi

# Remove the test executable from the arg list so it isn't passed to test execution
shift

testExtRepo=$( dirname ${CoreRT_TestRoot} )/tests_downloaded/CoreCLR/
nativeArtifactRepo=${testExtRepo}native/
dirSuffix=$(dirname ${PWD#$testExtRepo})/
nativeDir=${nativeArtifactRepo}tests/src/${dirSuffix}

# In OSX we copy the native component to the directory where the exectuable resides.
# However, in Linux dlopen doesn't seem to look for current directory to resolve the dynamic library.
# So instead we point LD_LIBRARY_PATH to the directory where the native component is.
if [ -e ${nativeDir} ]; then
if [ "${CoreRT_BuildOS}" == "OSX" ]; then
echo "Copying native component from :"${nativeDir}
cp ${nativeDir}*.dylib native/ 2>/dev/null
fi
if [ "${CoreRT_BuildOS}" == "Linux" ]; then
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${nativeDir}
export LD_LIBRARY_PATH
fi
fi

if [[ ! -f native/${TestFileName} ]]; then
echo "ERROR: Native binary not found. Unable to run test."
exit -1
fi

pushd native/
./${TestFileName} "$@"
testScriptExitCode=$?
popd

if [[ $CoreRT_EnableCoreDumps == 1 ]]; then
# Handle any core files generated when running the test.
inspect_and_delete_core_files native/$TestFileName "$CoreRT_ToolchainDir"
fi

# Clean up test binary artifacts to save space
rm -r native 2>/dev/null

exit $testScriptExitCode
13 changes: 13 additions & 0 deletions tests/CoreFX/dependencies.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\dependencies.props" />

<!-- Package version dependencies in test helper projects. -->
<PropertyGroup>
<SystemCommandLineVersion>0.1.0-e160909-1</SystemCommandLineVersion>
<NewtonsoftJsonVersion>10.0.1</NewtonsoftJsonVersion>
<XunitPackageVersion>2.2.0-beta2-build3300</XunitPackageVersion>
<XunitAbstractionsVersion>2.0.1-rc2</XunitAbstractionsVersion>
<XunitNetcoreExtensionsVersion>1.0.1-prerelease-02104-02</XunitNetcoreExtensionsVersion>
</PropertyGroup>
</Project>
64 changes: 64 additions & 0 deletions tests/CoreFX/runtest/CoreFXTestHarness/Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<Project DefaultTargets="LinkNative">
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />

<Import Project="$(TestRootDir)\dependencies.props" />

<!-- Override Default MSBuild properties-->
<PropertyGroup>
<TargetName>$(ExecutableName)</TargetName>
<TargetExt>.exe</TargetExt>
<OutputType>Exe</OutputType>
</PropertyGroup>

<PropertyGroup>
<!-- TODO - need a general way to specify version without relying on the test directory structure being intact, i.e. import dependencies from \tests\ -->
<ToolsDir>$(FrameworkLibPath)\..\tools\</ToolsDir>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only place where ToolsDir is used seems unused?

<TargetFramework>netcoreapp2.0</TargetFramework>
<!-- Don't warn if some dependencies were rolled forward -->
<NoWarn>$(NoWarn);NU1603</NoWarn>
</PropertyGroup>

<ItemGroup>
<RdXmlFile Include="default.rd.xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="xunit.abstractions">
<Version>$(XunitAbstractionsVersion)</Version>
</PackageReference>
<PackageReference Include="xunit.assert">
<Version>$(XunitPackageVersion)</Version>
</PackageReference>
<PackageReference Include="xunit.extensibility.core">
<Version>$(XunitPackageVersion)</Version>
</PackageReference>
<PackageReference Include="xunit.core">
<Version>$(XunitPackageVersion)</Version>
</PackageReference>
<PackageReference Include="xunit.runner.utility">
<Version>$(XunitPackageVersion)</Version>
</PackageReference>
<PackageReference Include="xunit.extensibility.execution">
<Version>$(XunitPackageVersion)</Version>
</PackageReference>
<PackageReference Include="microsoft.xunit.netcore.extensions">
<Version>$(XunitNetcoreExtensionsVersion)</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<!-- Some tests consist of multiple assemblies - make sure ILC sees them -->
<IlcCompileInput Include="$(MSBuildProjectDirectory)\*.dll" />
</ItemGroup>
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

<!-- Set OutputPath after the SDK targets have been imported-->
<PropertyGroup>
<OutputPath>$(MSBuildProjectDirectory)\</OutputPath>
<IntermediateOutputPath>$(MSBuildProjectDirectory)\</IntermediateOutputPath>
</PropertyGroup>

<!-- Import CoreRT build targets -->
<Import Project="$(IlcPath)\build\Microsoft.NETCore.Native.targets" />

<!-- Since tests are already compiled, override Compile target to prevent CSC running -->
<Target Name="Compile" />
</Project>
41 changes: 41 additions & 0 deletions tests/CoreFX/runtest/CoreFXTestHarness/default.rd.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Directives
xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Application>
<Assembly Name="*Application*" Dynamic="Required All" />
<Assembly Name="xunit.abstractions" Dynamic="Required All" />
<Assembly Name="System.Private.CoreLib">
<Type Name="System.Runtime.CompilerServices.CompilationRelaxationsAttribute" Dynamic="Required All" />
<Type Name="System.Runtime.CompilerServices.RuntimeCompatibilityAttribute" Dynamic="Required All" />
<Type Name="System.Runtime.CompilerServices.ExtensionAttribute" Dynamic="Required All" />
<Type Name="System.Runtime.CompilerServices.IntrinsicAttribute" Dynamic="Required All" />
<Type Name="System.Diagnostics.DebuggableAttribute" Dynamic="Required All" />
<Type Name="System.Reflection.AssemblyInformationalVersionAttribute" Dynamic="Required All" />
<Type Name="System.Reflection.AssemblyTitleAttribute" Dynamic="Required All" />
<Type Name="System.Reflection.AssemblyFileVersionAttribute" Dynamic="Required All" />
<Type Name="System.Reflection.AssemblyDescriptionAttribute" Dynamic="Required All" />
<Type Name="System.Reflection.AssemblyCompanyAttribute" Dynamic="Required All" />
<Type Name="System.Reflection.AssemblyCopyrightAttribute" Dynamic="Required All" />
<Type Name="System.Reflection.AssemblyProductAttribute" Dynamic="Required All" />
<Type Name="System.Reflection.AssemblyDefaultAliasAttribute" Dynamic="Required All" />
<Type Name="System.Reflection.AssemblyMetadataAttribute" Dynamic="Required All" />
<Type Name="System.AttributeUsageAttribute" Dynamic="Required All" />
<Type Name="System.AttributeUsageAttribute[]" Dynamic="Required All" />
<Type Name="System.Runtime.InteropServices.ComVisibleAttribute" Dynamic="Required All" />
<Type Name="System.CLSCompliantAttribute" Dynamic="Required All" />
</Assembly>
<Assembly Name="mscorlib">
<Type Name="System.IO.File" Dynamic="Required All"/>
<Type Name="System.Threading.ExecutionContext" Dynamic="Required All"/>
<Type Name="System.Threading.ContextCallback" Dynamic="Required All"/>
</Assembly>
<Assembly Name="xunit.core" Dynamic="Required All" />
<Assembly Name="xunit.runner.utility.dotnet" Dynamic="Required All" />
<Assembly Name="xunit.execution.dotnet" Dynamic="Required All" />
<Assembly Name="xunit.abstractions" Dynamic="Required All" />
<Assembly Name="xunit.core" Dynamic="Required All">
<Type Name="Xunit.Sdk.BeforeAfterTestAttribute[]" Dynamic="Required All" />
</Assembly>
<Assembly Name="Xunit.NetCore.Extensions" Dynamic="Required All" />
<Assembly Name="System.Linq.Expressions" Dynamic="Required All" />
</Application>
</Directives>
33 changes: 33 additions & 0 deletions tests/CoreFX/runtest/dir.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<!-- Don't import the project's parent dir.props - all other projects in the CoreRT repo are set up for the old project format -->

<!--
$(OS) is set to Unix/Windows_NT. This comes from an environment variable on Windows and MSBuild on Unix.
-->
<PropertyGroup>
<OsEnvironment Condition="'$(OsEnvironment)'==''">$(OS)</OsEnvironment>
</PropertyGroup>

<!-- Common repo directories -->
<PropertyGroup>
<CopyNuGetImplementations Condition="'$(CopyNuGetImplementations)'==''">false</CopyNuGetImplementations>
<ProjectDir>$(MSBuildThisFileDirectory)\</ProjectDir>
<SourceDir>$(ProjectDir)src\</SourceDir>
<PackagesDir>$(ProjectDir)..\..\..\packages\</PackagesDir>
<ToolsDir Condition="'$(ToolsDir)'==''">$(ProjectDir)..\Tools\</ToolsDir>
<DotnetCliPath Condition="'$(DotnetCliPath)'==''">$(ToolsDir)dotnetcli/</DotnetCliPath>
<SkipImportILTargets>true</SkipImportILTargets>
</PropertyGroup>

<!-- Provides properties for dependency versions and configures dependency verification/auto-upgrade. -->
<Import Project="$(MSBuildThisFileDirectory)\..\dependencies.props" />

<!-- list of nuget package sources passed to dnu -->
<ItemGroup>
<!-- Need to escape double forward slash (%2F) or MSBuild will normalize to one slash on Unix. -->
<DotnetSourceList Include="https:%2F%2Fdotnet.myget.org/F/dotnet-core/api/v3/index.json" />
<DotnetSourceList Include="https:%2F%2Fapi.nuget.org/v3/index.json" />
</ItemGroup>

</Project>
Loading