Skip to content

Commit

Permalink
Speed-up the AOT tests in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
aaubry committed Jan 28, 2021
1 parent 32454ea commit 8b6905d
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ YamlDotNet/Properties/AssemblyInfo.Generated.cs
/YamlDotNet/Properties/AssemblyInfo.cs
BenchmarkDotNet.Artifacts

/YamlDotNet.AotTest/exitcode.txt
30 changes: 11 additions & 19 deletions YamlDotNet.AotTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ class Program
static int Main(string[] args)
{
Console.WriteLine();
Console.WriteLine("---------------------------------------------------------------------------------");
Console.WriteLine("\x1b[37m---------------------------------------------------------------------------------");
Console.WriteLine();

Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(" Running AOT tests...");
Console.WriteLine("\x1b[97m Running AOT tests...");
Console.WriteLine();

TryDeserialize<MyDictionary>("DictionaryNodeDeserializer", "myDictionary: { winners: 3 }");
Expand All @@ -25,13 +24,11 @@ static int Main(string[] args)
TrySerialize("TraverseGenericDictionary", new GenericTestDictionary<long, long> { { 1, 2 } });

Console.WriteLine();
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(" {0} test succeeded, {1} tests failed", succeededTestCount, failedTestCount);
Console.WriteLine(" \x1b[93m{0}\x1b[97m test succeeded, \x1b[93m{1}\x1b[97m tests failed", succeededTestCount, failedTestCount);

Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine();
Console.WriteLine("---------------------------------------------------------------------------------");
Console.WriteLine();
Console.WriteLine("\x1b[37m---------------------------------------------------------------------------------");
Console.WriteLine("\x1b[0m");

return failedTestCount;
}
Expand Down Expand Up @@ -59,16 +56,13 @@ private static void TryDeserialize<T>(string testName, string yaml)

private static void PerformTest(string testName, Action act)
{
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write(" ");
Console.Write("\x1b[37m ");
Console.Write(testName.PadRight(70));

try
{
act();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("[success]");
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("\x1b[92m[success]\x1b[37m");
++succeededTestCount;
}
catch (Exception ex)
Expand All @@ -80,19 +74,17 @@ private static void PerformTest(string testName, Action act)
if (current is ExecutionEngineException)
#pragma warning restore CS0618 // Type or member is obsolete
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("[failure]");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write(" ");
Console.WriteLine("\x1b[91m[failure]");
Console.Write("\x1b[93m ");
Console.WriteLine(current.Message);
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write("\x1b[37m");
++failedTestCount;
return;
}

current = current.InnerException;
}
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("\x1b[91m");
throw;
}
}
Expand Down
20 changes: 4 additions & 16 deletions YamlDotNet.AotTest/run.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
#!/bin/sh

apt-get update
apt-get install --no-install-recommends -y mono-runtime

mono --aot=full /usr/lib/mono/4.5/mscorlib.dll
mono --aot=full /usr/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll
mono --aot=full /usr/lib/mono/gac/System.Xml/4.0.0.0__b77a5c561934e089/System.Xml.dll
mono --aot=full /usr/lib/mono/gac/Mono.Security/4.0.0.0__0738eb9f132ed756/Mono.Security.dll
mono --aot=full /usr/lib/mono/gac/System.Configuration/4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
mono --aot=full /usr/lib/mono/gac/System.Security/4.0.0.0__b03f5f7f11d50a3a/System.Security.dll
mono --aot=full /usr/lib/mono/gac/System.Core/4.0.0.0__b77a5c561934e089/System.Core.dll
mono --aot=full /usr/lib/mono/gac/System.Numerics/4.0.0.0__b77a5c561934e089/System.Numerics.dll

mono --aot=full YamlDotNet.AotTest/bin/Release/net45/YamlDotNet.dll
mono --aot=full YamlDotNet.AotTest/bin/Release/net45/YamlDotNet.AotTest.exe

mono --full-aot YamlDotNet.AotTest/bin/Release/net45/YamlDotNet.AotTest.exe
mono --aot=full ./bin/Release/net45/YamlDotNet.dll && \
mono --aot=full ./bin/Release/net45/YamlDotNet.AotTest.exe && \
mono --full-aot ./bin/Release/net45/YamlDotNet.AotTest.exe

echo $? > exitcode.txt
10 changes: 10 additions & 0 deletions tools/aot/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM mono:6.12-slim

RUN mono --aot=full /usr/lib/mono/4.5/mscorlib.dll && \
mono --aot=full /usr/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll && \
mono --aot=full /usr/lib/mono/gac/System.Xml/4.0.0.0__b77a5c561934e089/System.Xml.dll && \
mono --aot=full /usr/lib/mono/gac/Mono.Security/4.0.0.0__0738eb9f132ed756/Mono.Security.dll && \
mono --aot=full /usr/lib/mono/gac/System.Configuration/4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll && \
mono --aot=full /usr/lib/mono/gac/System.Security/4.0.0.0__b03f5f7f11d50a3a/System.Security.dll && \
mono --aot=full /usr/lib/mono/gac/System.Core/4.0.0.0__b77a5c561934e089/System.Core.dll && \
mono --aot=full /usr/lib/mono/gac/System.Numerics/4.0.0.0__b77a5c561934e089/System.Numerics.dll
2 changes: 2 additions & 0 deletions tools/aot/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

docker build . -t "aaubry/mono-aot"
19 changes: 17 additions & 2 deletions tools/build/BuildDefinition.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Bullseye;
using SimpleExec;
using System;
using System.Collections.Generic;
using System.Globalization;
Expand Down Expand Up @@ -105,9 +106,23 @@ public static SuccessfulUnitTests UnitTest(Options options, SuccessfulBuild _)
return default;
}

public static SuccessfulAotTests AotTest(SuccessfulBuild _)
public static SuccessfulAotTests AotTest(Options options, SuccessfulBuild _)
{
Run("wsl", $"--user root YamlDotNet.AotTest/run.sh", BasePath);
var testsDir = Path.Combine(BasePath, "YamlDotNet.AotTest");

try
{
Run("docker", $"run --rm -v {testsDir}:/build -w /build aaubry/mono-aot bash ./run.sh");
}
catch (NonZeroExitCodeException ex) when (options.Host == Host.Appveyor && ex.ExitCode == -1)
{
// Appveyor fails with exit code -1 for some reason...
var realExitCode = int.Parse(File.ReadAllLines(Path.Combine(testsDir, "exitcode.txt")).First(), CultureInfo.InvariantCulture);
if (realExitCode != 0)
{
throw new NonZeroExitCodeException(realExitCode);
}
}

return default;
}
Expand Down

0 comments on commit 8b6905d

Please sign in to comment.