Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Improve test:
* skip on aot platforms
* add current thread test for coreclr
  • Loading branch information
John Salem committed Jul 7, 2021
commit a7aa30a5ae94b445b6b8b67fdfc6a3c0bf927081
52 changes: 49 additions & 3 deletions src/libraries/System.Runtime/tests/System/Runtime/JitInfoTests.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,67 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.DotNet.XUnitExtensions;
using System.Threading;
using Xunit;

namespace System.Runtime.Tests
{
// NOTE: DependentHandle is already heavily tested indirectly through ConditionalWeakTable<,>.
// This class contains some specific tests for APIs that are only relevant when used directly.
public class JitInfoTests
{
// TODO(josalem): disable test on iOS/Android/browser
private const TestPlatforms AotPlatforms = TestPlatforms.Browser | TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.Android;

[Fact]
[SkipOnPlatform(AotPlatforms, "JitInfo metrics will be 0 in AOT scenarios.")]
public void JitInfoIsPopulated()
{
Func<string> theFunc = () => "JIT compile this!";
Assert.True(theFunc().Equals("JIT compile this!"));
Assert.True(System.Runtime.JitInfo.GetCompilationTime() > TimeSpan.Zero);
Assert.True(System.Runtime.JitInfo.GetCompiledILBytes() > 0);
Assert.True(System.Runtime.JitInfo.GetCompiledMethodCount() > 0);
}

[Fact]
[SkipOnMono("Mono does not track thread specific JIT information")]
public void JitInfoCurrentThreadIsPopulated()
{
TimeSpan t1_compilationTime = TimeSpan.Zero;
long t1_compiledILBytes = 0;
long t1_compiledMethodCount = 0;

TimeSpan t2_compilationTime = TimeSpan.Zero;
long t2_compiledILBytes = 0;
long t2_compiledMethodCount = 0;

var t1 = new Thread(() => {
Func<string> theFunc = () => "JIT compile this!";
Assert.True(theFunc().Equals("JIT compile this!"));
t1_compilationTime = System.Runtime.JitInfo.GetCompilationTime(currentThread: true);
t1_compiledILBytes = System.Runtime.JitInfo.GetCompiledILBytes(currentThread: true);
t1_compiledMethodCount = System.Runtime.JitInfo.GetCompiledMethodCount(currentThread: true);
});

var t2 = new Thread(() => {
Func<string> theFunc2 = () => "Also JIT compile this!";
Assert.True(theFunc2().Equals("Also JIT compile this!"));
t2_compilationTime = System.Runtime.JitInfo.GetCompilationTime(currentThread: true);
t2_compiledILBytes = System.Runtime.JitInfo.GetCompiledILBytes(currentThread: true);
t2_compiledMethodCount = System.Runtime.JitInfo.GetCompiledMethodCount(currentThread: true);
});

t1.Start();
t2.Start();
t1.Join();
t2.Join();

Assert.True(t1_compilationTime > TimeSpan.Zero);
Assert.True(t1_compiledILBytes > 0);
Assert.True(t1_compiledMethodCount > 0);

Assert.True(t2_compilationTime > TimeSpan.Zero);
Assert.True(t2_compiledILBytes > 0);
Assert.True(t2_compiledMethodCount > 0);
}
}
}