Skip to content
Merged
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
22 changes: 16 additions & 6 deletions src/tests/managed/Compilation/Compilation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,34 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using Xunit;

class Program
public class Program
{
static int Main()
[Fact]
public static int TestEntryPoint()
{
Console.WriteLine("Starting the test");
string codeFile = @"HelloWorld.cs";

var sourceTree = new List<SyntaxTree>(){SyntaxFactory.ParseSyntaxTree(File.ReadAllText(codeFile))};
var sourceTree = new List<SyntaxTree>()
{
SyntaxFactory.ParseSyntaxTree(File.ReadAllText(codeFile))
};

string mscorlibFile = Path.Combine(Environment.GetEnvironmentVariable("CORE_ROOT"),
"System.Private.CoreLib.dll");

string mscorlibFile = Path.Combine(Environment.GetEnvironmentVariable("CORE_ROOT"), "System.Private.CoreLib.dll");
Console.WriteLine("Using reference to: {0}", mscorlibFile);
var reference = new List<MetadataReference>(){ MetadataReference.CreateFromFile(mscorlibFile)};
var reference = new List<MetadataReference>()
{
MetadataReference.CreateFromFile(mscorlibFile)
};

var compilation = CSharpCompilation.Create("helloworld", sourceTree, reference);

Console.WriteLine("Test compiled");
var result = compilation.Emit(new FileStream("helloworld.exe", FileMode.Create));

if (!result.Success)
{
return -1;
Expand Down
2 changes: 1 addition & 1 deletion src/tests/managed/Compilation/Compilation.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<GCStressIncompatible>true</GCStressIncompatible>
<!-- Test unsupported outside of windows -->
<CLRTestTargetUnsupported Condition="'$(TargetsWindows)' != 'true'">true</CLRTestTargetUnsupported>
Expand Down
11 changes: 11 additions & 0 deletions src/tests/managed/Managed.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<MergedWrapperProjectReference Include="*/**/*.??proj" />
</ItemGroup>

<PropertyGroup>
<BuildAsStandalone>false</BuildAsStandalone>
</PropertyGroup>

<Import Project="$(TestSourceDir)MergedTestRunner.targets" />
</Project>
6 changes: 4 additions & 2 deletions src/tests/nativeaot/CustomMain/CustomMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Xunit;

class Program
public class Program
{
// Each of the module initializer, class constructor, and IncrementExitCode
// should be executed exactly once, causing this to each 100 by program exit.
Expand All @@ -32,7 +33,8 @@ static void IncrementExitCode(int amount)

int ExitCode;

static int Main(string[] args)
[Fact]
public static int TestEntryPoint()
{
Console.WriteLine("hello from managed main");
return s_exitCode;
Expand Down
2 changes: 1 addition & 1 deletion src/tests/nativeaot/CustomMain/CustomMain.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<CustomNativeMain>true</CustomNativeMain>
<StaticLibraryPrefix Condition="'$(TargetOS)' != 'windows'">lib</StaticLibraryPrefix>
<RequiresProcessIsolation>true</RequiresProcessIsolation>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Xunit;

namespace GenerateUnmanagedEntryPoints
{
unsafe class Program
public unsafe class Program
{
[UnmanagedCallersOnly(EntryPoint = "MainAssemblyMethod")]
static void MainAssemblyMethod() => Console.WriteLine($"Hello from {nameof(MainAssemblyMethod)}");

static int Main()
[Fact]
public static int TestEntryPoint()
{
IntPtr methodAddress = IntPtr.Zero;
IntPtr programHandle = IntPtr.Zero;
Expand Down Expand Up @@ -52,4 +54,4 @@ static int Main()
return 100;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<IlcExportUnmanagedEntrypoints>true</IlcExportUnmanagedEntrypoints>
<!--
For some reason, this particular test hits some case in AddressSanitizer where it fails to intercept methods correctly, causing failures.
Expand Down
23 changes: 23 additions & 0 deletions src/tests/nativeaot/NativeAot.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<MergedWrapperProjectReference Include="*/**/*.??proj" />

<!-- Due to the nature of the MultiModule tests, it is unfeasible to convert
them to the Merged Wrapper system.
The main idea of these ones is that we pre-NativeAOT the whole framework,
then NativeAOT each assembly separately, and then link them all together
at the end using the native linker.
So, when we try using the Merged Wrapper system, nothing ends up producing
the code for xunit.assert, as its assembly is not in the actual framework.
-->
<MergedWrapperProjectReference Remove="SmokeTests/MultiModule/*.csproj" />
Comment on lines +5 to +15
Copy link
Member

Choose a reason for hiding this comment

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

If we mark the MultiModule tests as "RequiresProcessIsolation", then we shouldn't be getting warnings here. My guess is that I never hooked up the MSBuild logic for the "out of process" tests to exclude them as inputs to ILC. If you want to fix in this this PR, you can. Otherwise, can you file a follow-up issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can confirm that adding <RequiresProcessIsolation> removes the warnings from this test. So, just to confirm, the follow-up issue is to write the necessary logic to exclude out-of-process tests from being inputs to ILC. Is this accurate?

Copy link
Member

Choose a reason for hiding this comment

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

Yep!

</ItemGroup>

<PropertyGroup>
<BuildAsStandalone>false</BuildAsStandalone>
</PropertyGroup>

<Import Project="$(TestSourceDir)MergedTestRunner.targets" />
</Project>
6 changes: 4 additions & 2 deletions src/tests/nativeaot/SmokeTests/ComWrappers/ComWrappers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using Xunit;

namespace ComWrappersTests
{
internal class Program
public class Program
{
static ComWrappers GlobalComWrappers;

[DynamicDependency(DynamicallyAccessedMemberTypes.PublicMethods, typeof(IComInterface))]
public static int Main()
[Fact]
public static int TestEntryPoint()
{
TestComInteropNullPointers();
TestComInteropRegistrationRequired();
Expand Down
7 changes: 3 additions & 4 deletions src/tests/nativeaot/SmokeTests/ComWrappers/ComWrappers.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<CLRTestTargetUnsupported Condition="'$(TargetsWindows)' != 'true'">true</CLRTestTargetUnsupported>

<!-- Shouldn't need this: https://github.com/dotnet/linker/issues/2618 -->
<NoWarn>$(NoWarn);IL2050</NoWarn>

<!-- Registers a global 'ComWrappers' instance for marshalling. -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
Copy link
Member

Choose a reason for hiding this comment

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

For tests that are legitimately marked as RequiresProcessIsolation due to something in the test, we should add comments explaining why so when we come around and clean up some of them in the future, we know which ones need to stay.

Suggested change
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<!-- Registers a global ComWrappers instance for marshalling -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>

</PropertyGroup>

<ItemGroup>
<Compile Include="ComWrappers.cs" />
</ItemGroup>
Expand Down
57 changes: 36 additions & 21 deletions src/tests/nativeaot/SmokeTests/Determinism/Determinism.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,45 @@

using System;
using System.IO;
using Xunit;

using var baseline = File.OpenRead("baseline.object");
using var compare = File.OpenRead("compare.object");
public class Program
{
[Fact]
public static int TestEntryPoint()
{
var baseline = File.OpenRead("baseline.object");
var compare = File.OpenRead("compare.object");

Console.WriteLine($"Baseline size: {baseline.Length}");
Console.WriteLine($"Compare size: {compare.Length}");
Console.WriteLine($"Baseline size: {baseline.Length}");
Console.WriteLine($"Compare size: {compare.Length}");

if (baseline.Length != compare.Length)
throw new Exception("Different sizes");
if (baseline.Length != compare.Length)
{
Console.WriteLine("Test Fail: Baseline and Compare have different sizes.");
return 101;
}

long length = baseline.Length;
for (int i = 0; i < length; i++)
{
if (baseline.ReadByte() != compare.ReadByte())
throw new Exception($"Different at byte {i}");
}
long length = baseline.Length;
for (int i = 0; i < length; i++)
{
if (baseline.ReadByte() != compare.ReadByte())
{
Console.WriteLine($"Test Fail: Baseline and Compare were different"
+ " at byte {i}.");
return 101;
}
}

// We're not interested in running this, we just want some junk to compile
if (Environment.GetEnvironmentVariable("Never") == "Ever")
{
Delegates.Run();
Devirtualization.Run();
Generics.Run();
Interfaces.Run();
}
// We're not interested in running this, we just want some junk to compile
if (Environment.GetEnvironmentVariable("Never") == "Ever")
{
Delegates.Run();
Devirtualization.Run();
Generics.Run();
Interfaces.Run();
}

return 100;
return 100;
}
}
5 changes: 3 additions & 2 deletions src/tests/nativeaot/SmokeTests/Determinism/Determinism.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<CLRTestPriority>0</CLRTestPriority>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RequiresProcessIsolation>true</RequiresProcessIsolation>

<!-- test tries to read files from disk, bundling them into the app isn't easily possible right now -->
<CLRTestTargetUnsupported Condition="'$(TargetsAppleMobile)' == 'true'">true</CLRTestTargetUnsupported>
</PropertyGroup>

<ItemGroup>
<Compile Include="Determinism.cs" />
<Compile Include="../UnitTests/Delegates.cs" />
<Compile Include="../UnitTests/Devirtualization.cs" />
<Compile Include="../UnitTests/Generics.cs" />
<Compile Include="../UnitTests/Interfaces.cs" />

</ItemGroup>

<Target Name="IlcCompileSingleThreaded"
Expand Down
2 changes: 1 addition & 1 deletion src/tests/nativeaot/SmokeTests/DwarfDump/DwarfDump.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<CLRTestPriority>0</CLRTestPriority>
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<!-- Currently only tracking DWARF info on Linux -->
<CLRTestTargetUnsupported Condition="'$(TargetOS)' != 'linux'">true</CLRTestTargetUnsupported>
<!-- We don't have SuperFileCheck binaries for llvm-dwarfdump on ARM platform -->
Expand Down
4 changes: 3 additions & 1 deletion src/tests/nativeaot/SmokeTests/DwarfDump/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using Xunit;

public class Program
{
public static int Main(string[] args)
[Fact]
public static int TestEntryPoint()
{
var llvmDwarfDumpPath = Path.Combine(
Environment.GetEnvironmentVariable("CORE_ROOT"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<CLRTestPriority>0</CLRTestPriority>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RequiresProcessIsolation>true</RequiresProcessIsolation>

<!-- There's just too many of these warnings -->
<SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings>
Expand Down
Loading