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
49 changes: 49 additions & 0 deletions mono-no-runtime-async/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Mono does not support runtime async.
// This test is ran against Mono builds to verify no assemblies require runtime async.

using System.Reflection;
using System.Reflection.Metadata;
using System.Reflection.PortableExecutable;

// Find the root of the .NET installation.
// <dotnet-root>/shared/Microsoft.NETCore.App/<version>/System.Private.CoreLib.dll
string corelib = typeof(object).Assembly.Location;
string dotnetRoot = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(corelib)!, "..", "..", ".."));
if (!File.Exists(Path.Combine(dotnetRoot, "dotnet")))
throw new Exception($"Expected to find 'dotnet' in {dotnetRoot}");
Console.WriteLine($"Searching for assemblies in {dotnetRoot}");

var assemblies = Directory.EnumerateFiles(dotnetRoot, "*.dll", SearchOption.AllDirectories);
int failureCount = 0;
foreach (var assembly in assemblies)
{
using var file = File.Open(assembly, FileMode.Open, FileAccess.Read);
using var reader = new PEReader(file);

if (!reader.HasMetadata)
continue;

var metadataReader = reader.GetMetadataReader();

foreach (var methodHandle in metadataReader.MethodDefinitions)
{
var method = metadataReader.GetMethodDefinition(methodHandle);

// Detect the use of runtime async through MethodImplAttributes.Async.
if ((method.ImplAttributes & MethodImplAttributes.Async) != 0)
{
Console.WriteLine($"FAIL: {assembly} has methods with MethodImplAttributes.Async");
failureCount++;
break;
}
}
}

if (failureCount > 0)
{
Console.WriteLine($"FAIL: assemblies use runtime async. Mono does not support runtime async.");
return 1;
}

Console.WriteLine("PASS: no assemblies use runtime async.");
return 0;
10 changes: 10 additions & 0 deletions mono-no-runtime-async/mono-no-runtime-async.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>$(TestTargetFramework)</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
14 changes: 14 additions & 0 deletions mono-no-runtime-async/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "mono-no-runtime-async",
"enabled": true,
"requiresSdk": true,
"version": "11.0",
"versionSpecific": false,
"type": "bash",
"cleanup": true,
"skipWhen": [
"runtime=coreclr"
],
"ignoredRIDs":[
]
}
6 changes: 6 additions & 0 deletions mono-no-runtime-async/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -euo pipefail
IFS=$'\n\t'

dotnet run
Loading