Skip to content
Open
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
1 change: 0 additions & 1 deletion NuGet.Config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="dotnet7" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json" />
<add key="dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" />
<add key="dotnet-libraries" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-libraries/nuget/v3/index.json" />
<add key="myget-legacy" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/myget-legacy/nuget/v3/index.json" />
Expand Down
5 changes: 4 additions & 1 deletion build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ REM Do as many builds as possible; don't stop on first failure (if any).
set __ExitCode=0

REM Declare the list of projects
set projects=jit-diff jit-dasm jit-analyze jit-tp-analyze jit-format pmi jit-dasm-pmi jit-decisions-analyze performance-explorer instructions-retired-explorer
set projects=Antigen jit-diff jit-dasm jit-analyze jit-tp-analyze jit-format pmi jit-dasm-pmi jit-decisions-analyze performance-explorer instructions-retired-explorer

REM Build each project
for %%p in (%projects%) do (
if %publish%==true (
REM Publish src/pmi project without single-file, so it can be executed with a custom build of the runtime/JIT
if "%%p"=="pmi" (
dotnet publish -c %buildType% -o %appInstallDir% .\src\%%p
) else if "%%p"=="Antigen" (
REM Publish Antigen without single-file; it resolves corelib/Roslyn reference assemblies by path for compilation
dotnet publish -c %buildType% -o %appInstallDir% .\src\%%p
) else (
dotnet publish -c %buildType% -o %appInstallDir% .\src\%%p --self-contained -r:%rid% -p:PublishSingleFile=true
)
Expand Down
4 changes: 3 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ while getopts "hpb:" opt; do
done

# declare the array of projects
declare -a projects=(jit-dasm jit-diff jit-analyze jit-tp-analyze jit-format pmi jit-dasm-pmi jit-decisions-analyze performance-explorer instructions-retired-explorer)
declare -a projects=(Antigen jit-dasm jit-diff jit-analyze jit-tp-analyze jit-format pmi jit-dasm-pmi jit-decisions-analyze performance-explorer instructions-retired-explorer)

# for each project either build or publish
for proj in "${projects[@]}"
Expand All @@ -57,6 +57,8 @@ do
case "$proj" in
# Publish src/pmi project without single-file, so it can be executed with a custom build of the runtime/JIT
pmi) dotnet publish -c "$buildType" -o "$appInstallDir" ./src/"$proj" ;;
# Publish Antigen without single-file; it locates reference assemblies (corelib, Roslyn) by path for Roslyn compilation
Antigen) dotnet publish -c "$buildType" -o "$appInstallDir" ./src/"$proj" ;;
*) dotnet publish -c "$buildType" -o "$appInstallDir" ./src/"$proj" --self-contained -r $rid -p:PublishSingleFile=true ;;
esac
exit_code=$?
Expand Down
2 changes: 1 addition & 1 deletion eng/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
displayName: 'Install .NET Core SDK'
inputs:
packageType: sdk
version: 8.x
version: 10.x
installationPath: $(Agent.ToolsDirectory)/dotnet

- ${{ if eq(parameters.agentOs, 'Windows_NT') }}:
Expand Down
1 change: 0 additions & 1 deletion src/AnalyzeAsm/AnalyzeAsm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

</Project>
38 changes: 14 additions & 24 deletions src/Antigen/Antigen/Antigen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
using System.IO;
using System.Threading.Tasks;
using Antigen.Config;
using CommandLine;
using System.CommandLine;
using System.CommandLine.Parsing;
using Utils;
using System.Linq;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -38,23 +39,27 @@ class Program

static int Main(string[] args)
{
return Parser.Default.ParseArguments<CommandLineOptions>(args).MapResult(Run, err => 1);
var command = new AntigenRootCommand(args).UseVersion();
return command.Parse(args).Invoke();
}

private static int Run(CommandLineOptions opts)
internal static int Run(AntigenRootCommand command)
{
try
{
ParseResult result = command.Result;
PRNG.Initialize(s_runOptions.Seed);
s_runOptions.CoreRun = opts.CoreRunPath;
s_runOptions.OutputDirectory = opts.IssuesFolder;
if (opts.RunDuration > 0)
s_runOptions.CoreRun = result.GetValue(command.CoreRunPath);
s_runOptions.OutputDirectory = result.GetValue(command.IssuesFolder);
int runDuration = result.GetValue(command.RunDuration);
if (runDuration > 0)
{
s_runOptions.RunDuration = opts.RunDuration;
s_runOptions.RunDuration = runDuration;
}
if (opts.NumTestCases > 0)
int numTestCases = result.GetValue(command.NumTestCases);
if (numTestCases > 0)
{
s_runOptions.NumTestCases = opts.NumTestCases;
s_runOptions.NumTestCases = numTestCases;
}

if (s_runOptions.RunDuration != -1)
Expand Down Expand Up @@ -295,19 +300,4 @@ static void RunTest()
}
}
}

public class CommandLineOptions
{
[Option(shortName: 'c', longName: "CoreRun", Required = true, HelpText = "Full path to CoreRun/CoreRun.exe.")]
public string CoreRunPath { get; set; }

[Option(shortName: 'o', longName: "IssuesFolder", Required = true, HelpText = "Full path to folder where issues will be copied.")]
public string IssuesFolder { get; set; }

[Option(shortName: 'n', longName: "NumTestCases", Required = false, HelpText = "Number of test cases to execute. By default, 1000.")]
public int NumTestCases { get; set; }

[Option(shortName: 'd', longName: "RunDuration", Required = false, HelpText = "Duration in minutes to run. By default until NumTestCases, but if Duration is given, will override the NumTestCases.")]
public int RunDuration { get; set; }
}
}
14 changes: 2 additions & 12 deletions src/Antigen/Antigen/Antigen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,20 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>Antigen</RootNamespace>
<UserSecretsId>ab71806a-3bd8-4fb1-b0e2-9450aec41a9f</UserSecretsId>
<EnablePreviewFeatures>True</EnablePreviewFeatures>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.0.0-2.final" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="5.3.0 " />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.8" />
</ItemGroup>

<ItemGroup>
<Compile Remove="*.g.cs" />
</ItemGroup>

<PropertyGroup>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<RestoreAdditionalProjectSources>
https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json
</RestoreAdditionalProjectSources>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ExecutionEngine\ExecutionEngine.csproj" />
<ProjectReference Include="..\Trimmer\Trimmer.csproj" />
Expand Down
37 changes: 37 additions & 0 deletions src/Antigen/Antigen/AntigenRootCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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.

using System.CommandLine;
using System.CommandLine.Parsing;

namespace Antigen
{
internal sealed class AntigenRootCommand : RootCommand
{
public Option<string> CoreRunPath { get; } =
new("--CoreRun", "-c") { Description = "Full path to CoreRun/CoreRun.exe.", Required = true };
public Option<string> IssuesFolder { get; } =
new("--IssuesFolder", "-o") { Description = "Full path to folder where issues will be copied.", Required = true };
public Option<int> NumTestCases { get; } =
new("--NumTestCases", "-n") { Description = "Number of test cases to execute. By default, 1000." };
public Option<int> RunDuration { get; } =
new("--RunDuration", "-d") { Description = "Duration in minutes to run. By default until NumTestCases, but if Duration is given, will override the NumTestCases." };

public ParseResult Result { get; private set; }

public AntigenRootCommand(string[] args) : base("Antigen JIT fuzzer")
{
Options.Add(CoreRunPath);
Options.Add(IssuesFolder);
Options.Add(NumTestCases);
Options.Add(RunDuration);

SetAction(result =>
{
Result = result;
return Program.Run(this);
});
}
}
}
16 changes: 13 additions & 3 deletions src/Antigen/Antigen/Config/RunOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
using System.IO;
using System.Reflection;
using System.Runtime.Intrinsics;
using Newtonsoft.Json;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Antigen.Config
{
Expand All @@ -25,7 +26,7 @@ public class RunOptions
// Percent of time to execute baseline
public double ExecuteBaseline;

[NonSerialized()]
[JsonIgnore]
public string CoreRun = null;

public List<ConfigOptions> Configs;
Expand All @@ -40,7 +41,16 @@ internal static RunOptions Initialize()
string antiGenConfig = Path.Combine(currentDirectory, "Config", "antigen.json");
Debug.Assert(File.Exists(antiGenConfig));

var runOption = JsonConvert.DeserializeObject<RunOptions>(File.ReadAllText(antiGenConfig));
JsonSerializerOptions options = new()
{
IncludeFields = true,
PropertyNameCaseInsensitive = true,
ReadCommentHandling = JsonCommentHandling.Skip,
AllowTrailingCommas = true,
NumberHandling = JsonNumberHandling.AllowReadingFromString,
};

var runOption = JsonSerializer.Deserialize<RunOptions>(File.ReadAllText(antiGenConfig), options);
EnvVarOptions.Initialize(runOption.BaselineEnvVars, runOption.TestEnvVars);

return runOption;
Expand Down
2 changes: 1 addition & 1 deletion src/Antigen/ExecutionEngine/DynamicAssemblyLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public Assembly LoadFromBytes(byte[] assemblyBytes)
return LoadFromStream(new MemoryStream(assemblyBytes));
}

protected override Assembly Load(AssemblyName assemblyName)
protected override Assembly? Load(AssemblyName assemblyName)
{
// Default implementation does nothing.
return null;
Expand Down
5 changes: 0 additions & 5 deletions src/Antigen/ExecutionEngine/ExecutionEngine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\Utilities\RequestResponse.cs" Link="RequestResponse.cs" />
</ItemGroup>
Expand Down
19 changes: 9 additions & 10 deletions src/Antigen/ExecutionEngine/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
using System.Reflection.Metadata;
using System.Runtime.ExceptionServices;
using System.Threading;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Text.Json;

namespace ExecutionEngine
{
Expand Down Expand Up @@ -38,7 +37,7 @@ static async Task Main(string[] args)
{
continue;
}
Request? request = JsonConvert.DeserializeObject<Request>(lines);
Request? request = JsonSerializer.Deserialize<Request>(lines);
if (request == null)
{
continue;
Expand All @@ -61,7 +60,7 @@ static async Task Main(string[] args)
response.IsJitAssert = true;
}

var json = JsonConvert.SerializeObject(response);
var json = JsonSerializer.Serialize(response);
Console.WriteLine(json);
Console.Out.Flush();
Console.WriteLine("Done");
Expand All @@ -86,13 +85,13 @@ private static RunResult Run(byte[] assemblyBytes)
{
int hashCode;
var assembly = s_loader.LoadFromBytes(assemblyBytes);
var methodInfo = assembly.GetType("TestClass").GetMethod("Main");
var methodExec = methodInfo.CreateDelegate<Func<string[], int>>();
var methodInfo = assembly.GetType("TestClass")!.GetMethod("Main");
var methodExec = methodInfo!.CreateDelegate<Func<string[], int>>();

// Adopted from Jakob's Fuzzlyn
int threadID = Environment.CurrentManagedThreadId;
List<Exception> exceptions = null;
void FirstChanceExceptionHandler(object sender, FirstChanceExceptionEventArgs args)
List<Exception>? exceptions = null;
void FirstChanceExceptionHandler(object? sender, FirstChanceExceptionEventArgs args)
{
if (Environment.CurrentManagedThreadId == threadID)
{
Expand All @@ -104,7 +103,7 @@ void FirstChanceExceptionHandler(object sender, FirstChanceExceptionEventArgs ar

try
{
hashCode = methodExec(null);
hashCode = methodExec(null!);
}
catch
{
Expand All @@ -123,7 +122,7 @@ void FirstChanceExceptionHandler(object sender, FirstChanceExceptionEventArgs ar
// }
// We are interested in the JIT assert that was hit, and not the OverflowException
// thrown because value = 1 did not get to run.
Exception ex = exceptions[0];
Exception ex = exceptions![0];

if (ex is TypeInitializationException && ex.InnerException != null)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Antigen/Trimmer/Rewriters/Statements/SyntaxRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public void UpdateId(int newId)

public override SyntaxTrivia VisitTrivia(SyntaxTrivia trivia)
{
if (trivia.Kind() == SyntaxKind.SingleLineCommentTrivia ||
trivia.Kind() == SyntaxKind.MultiLineCommentTrivia)
if (trivia.IsKind(SyntaxKind.SingleLineCommentTrivia) ||
trivia.IsKind(SyntaxKind.MultiLineCommentTrivia))
{
return default(SyntaxTrivia);
}
Expand Down
25 changes: 16 additions & 9 deletions src/Antigen/Trimmer/TestTrimmer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
using Antigen.Trimmer.Rewriters;
using Antigen.Trimmer.Rewriters.Expressions;
using Antigen.Trimmer.Rewriters.Statements;
using CommandLine;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Parsing;
using System.Diagnostics;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -52,11 +53,23 @@ public class TestTrimmer

static int Main(string[] args)
{
return Parser.Default.ParseArguments<CommandLineOptions>(args).MapResult(Run, err => 1);
var command = new TrimmerRootCommand(args).UseVersion();
return command.Parse(args).Invoke();
}

private static int Run(CommandLineOptions opts)
internal static int Run(TrimmerRootCommand command)
{
ParseResult result = command.Result;
CommandLineOptions opts = new()
{
CoreRunPath = result.GetValue(command.CoreRunPath),
ParentPid = result.GetValue(command.ParentPid),
IssuesFolder = result.GetValue(command.IssuesFolder),
ReproFile = result.GetValue(command.ReproFile),
AltJitName = result.GetValue(command.AltJitName),
AltJitMethodName = result.GetValue(command.AltJitMethodName),
};

int.TryParse(opts.ParentPid, out s_parentProcessId);
Task monitorTask = Task.Run(() => MonitorParentProcess());

Expand Down Expand Up @@ -615,22 +628,16 @@ private static void MonitorParentProcess()

public class CommandLineOptions
{
[Option(shortName: 'c', longName: "CoreRun", Required = true, HelpText = "Path to CoreRun/CoreRun.exe.")]
public string CoreRunPath { get; set; }

[Option(shortName: 'p', longName: "ParentPid", Required = false, HelpText = "Antigen process id")]
public string ParentPid { get; set; }

[Option(shortName: 'o', longName: "IssuesFolder", Required = false, HelpText = "Path to folder where trimmed issue will be copied.")]
public string IssuesFolder { get; set; }

[Option(shortName: 'f', longName: "ReproFile", Required = false, HelpText = "Full path of the repro file.")]
public string ReproFile { get; set; }

[Option(shortName: 'j', longName: "AltJitName", Required = false, HelpText = "Name of altjit. By default, current OS/arch.")]
public string AltJitName { get; set; }

[Option(shortName: 'm', longName: "AltJitMethodName", Required = false, HelpText = "Name of method for altjit. By default, current OS/arch.")]
public string AltJitMethodName { get; set; }
}
}
Loading