-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mjit] Add tests for MiniCompiler (mono#19)
* [mjit] Store opt differently for MiniCompiler * [mjit] Add tests for MiniCompiler
- Loading branch information
Showing
9 changed files
with
158 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 10 additions & 2 deletions
12
mcs/class/Mono.Compiler/Mono.Compiler/InstalledRuntimeCode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
namespace Mono.Compiler { | ||
public class InstalledRuntimeCode { | ||
|
||
using System; | ||
|
||
namespace Mono.Compiler | ||
{ | ||
public struct InstalledRuntimeCode | ||
{ | ||
#pragma warning disable 169 | ||
IntPtr handle; /* This is the actual pointer to the domain-allocated InstalledRuntimeCode */ | ||
#pragma warning restore 169 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
ICompilerInterfaceTest.cs | ||
MiniCompilerTest.cs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System; | ||
using NUnit.Framework; | ||
using Mono.Compiler; | ||
|
||
namespace MonoTests.Mono.Compiler | ||
{ | ||
[TestFixture] | ||
public class MiniCompilerTests | ||
{ | ||
IRuntimeInformation runtimeInfo = null; | ||
ICompiler compiler = null; | ||
|
||
[TestFixtureSetUp] | ||
public void Init () { | ||
runtimeInfo = new RuntimeInformation (); | ||
compiler = new MiniCompiler (); | ||
} | ||
|
||
public static void EmptyMethod () { | ||
return; | ||
} | ||
|
||
public static int AddMethod (int a, int b) { | ||
return a + b; | ||
} | ||
|
||
public static int AddMethod3 (int a, int b, int c) { | ||
return a + b + c; | ||
} | ||
|
||
[Test] | ||
public unsafe void TestEmptyMethod () | ||
{ | ||
MethodInfo methodInfo = new MethodInfo(this.GetType().GetMethod("EmptyMethod").MethodHandle); | ||
|
||
CompilationResult result = compiler.CompileMethod (runtimeInfo, methodInfo, CompilationFlags.None, out NativeCodeHandle nativeCode); | ||
Assert.AreEqual(result, CompilationResult.Ok); | ||
Assert.AreNotEqual((IntPtr)nativeCode.Blob, IntPtr.Zero); | ||
// AssertHelper.Greater(nativeCode.Length, 0); | ||
|
||
InstalledRuntimeCode irc = runtimeInfo.InstallCompilationResult (result, methodInfo, nativeCode); | ||
runtimeInfo.ExecuteInstalledMethod (irc); | ||
} | ||
|
||
[Test] | ||
public unsafe void TestAddMethod () | ||
{ | ||
MethodInfo methodInfo = new MethodInfo(this.GetType().GetMethod("AddMethod").MethodHandle); | ||
|
||
CompilationResult result = compiler.CompileMethod (runtimeInfo, methodInfo, CompilationFlags.None, out NativeCodeHandle nativeCode); | ||
Assert.AreEqual(result, CompilationResult.Ok); | ||
Assert.AreNotEqual((IntPtr)nativeCode.Blob, IntPtr.Zero); | ||
// AssertHelper.Greater(nativeCode.Length, 0); | ||
|
||
InstalledRuntimeCode irc = runtimeInfo.InstallCompilationResult (result, methodInfo, nativeCode); | ||
int addition = (int) runtimeInfo.ExecuteInstalledMethod (irc, 1, 2); | ||
Assert.AreEqual (addition, 3); | ||
} | ||
|
||
[Test] | ||
public unsafe void TestAddMethod3 () | ||
{ | ||
MethodInfo methodInfo = new MethodInfo(this.GetType().GetMethod("AddMethod3").MethodHandle); | ||
|
||
CompilationResult result = compiler.CompileMethod (runtimeInfo, methodInfo, CompilationFlags.None, out NativeCodeHandle nativeCode); | ||
Assert.AreEqual(result, CompilationResult.Ok); | ||
Assert.AreNotEqual((IntPtr)nativeCode.Blob, IntPtr.Zero); | ||
// AssertHelper.Greater(nativeCode.Length, 0); | ||
|
||
InstalledRuntimeCode irc = runtimeInfo.InstallCompilationResult (result, methodInfo, nativeCode); | ||
int addition = (int) runtimeInfo.ExecuteInstalledMethod (irc, 1, 2, 3); | ||
Assert.AreEqual (addition, 6); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters