mirror of
https://github.com/Smaug123/WoofWare.PawPrint
synced 2025-10-11 16:48:41 +00:00
Add native call implementations (#18)
This commit is contained in:
@@ -21,11 +21,13 @@ module TestBasicLock =
|
||||
let dotnetRuntimes =
|
||||
DotnetRuntime.SelectForDll assy.Location |> ImmutableArray.CreateRange
|
||||
|
||||
let impls = NativeImpls.Mock ()
|
||||
|
||||
use peImage = new MemoryStream (image)
|
||||
|
||||
try
|
||||
let terminalState, terminatingThread =
|
||||
Program.run loggerFactory (Some "BasicLock.cs") peImage dotnetRuntimes []
|
||||
Program.run loggerFactory (Some "BasicLock.cs") peImage dotnetRuntimes impls []
|
||||
|
||||
let exitCode =
|
||||
match terminalState.ThreadState.[terminatingThread].MethodState.EvaluationStack.Values with
|
||||
|
@@ -6,6 +6,7 @@ open FsUnitTyped
|
||||
open NUnit.Framework
|
||||
open WoofWare.DotnetRuntimeLocator
|
||||
open WoofWare.PawPrint
|
||||
open WoofWare.PawPrint.ExternImplementations
|
||||
open WoofWare.PawPrint.Test
|
||||
|
||||
[<TestFixture>]
|
||||
@@ -17,14 +18,17 @@ module TestCases =
|
||||
{
|
||||
FileName = "BasicException.cs"
|
||||
ExpectedReturnCode = 10
|
||||
NativeImpls = NativeImpls.Mock ()
|
||||
}
|
||||
{
|
||||
FileName = "BasicLock.cs"
|
||||
ExpectedReturnCode = 10
|
||||
NativeImpls = NativeImpls.Mock ()
|
||||
}
|
||||
{
|
||||
FileName = "WriteLine.cs"
|
||||
ExpectedReturnCode = 1
|
||||
NativeImpls = NativeImpls.Mock ()
|
||||
}
|
||||
]
|
||||
|
||||
@@ -33,10 +37,34 @@ module TestCases =
|
||||
{
|
||||
FileName = "NoOp.cs"
|
||||
ExpectedReturnCode = 1
|
||||
NativeImpls = NativeImpls.Mock ()
|
||||
}
|
||||
{
|
||||
FileName = "TriangleNumber.cs"
|
||||
ExpectedReturnCode = 10
|
||||
NativeImpls = NativeImpls.Mock ()
|
||||
}
|
||||
{
|
||||
FileName = "InstaQuit.cs"
|
||||
ExpectedReturnCode = 1
|
||||
NativeImpls =
|
||||
let mock = NativeImpls.Mock ()
|
||||
|
||||
{ mock with
|
||||
System_Env =
|
||||
{ System_EnvironmentMock.Empty with
|
||||
GetProcessorCount =
|
||||
fun thread state ->
|
||||
let state =
|
||||
state |> IlMachineState.pushToEvalStack' (EvalStackValue.Int32 1) thread
|
||||
|
||||
(state, WhatWeDid.Executed) |> ExecutionResult.Stepped
|
||||
_Exit =
|
||||
fun thread state ->
|
||||
let state = state |> IlMachineState.loadArgument thread 0
|
||||
ExecutionResult.Terminated (state, thread)
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@@ -53,7 +81,7 @@ module TestCases =
|
||||
|
||||
try
|
||||
let terminalState, terminatingThread =
|
||||
Program.run loggerFactory (Some case.FileName) peImage dotnetRuntimes []
|
||||
Program.run loggerFactory (Some case.FileName) peImage dotnetRuntimes case.NativeImpls []
|
||||
|
||||
let exitCode =
|
||||
match terminalState.ThreadState.[terminatingThread].MethodState.EvaluationStack.Values with
|
||||
@@ -81,11 +109,13 @@ module TestCases =
|
||||
let dotnetRuntimes =
|
||||
DotnetRuntime.SelectForDll assy.Location |> ImmutableArray.CreateRange
|
||||
|
||||
let impls = NativeImpls.Mock ()
|
||||
|
||||
use peImage = new MemoryStream (image)
|
||||
|
||||
try
|
||||
let terminalState, terminatingThread =
|
||||
Program.run loggerFactory (Some case.FileName) peImage dotnetRuntimes []
|
||||
Program.run loggerFactory (Some case.FileName) peImage dotnetRuntimes impls []
|
||||
|
||||
let exitCode =
|
||||
match terminalState.ThreadState.[terminatingThread].MethodState.EvaluationStack.Values with
|
||||
|
@@ -1,6 +1,7 @@
|
||||
namespace WoofWare.PawPrint.Test
|
||||
|
||||
open WoofWare.PawPrint
|
||||
open WoofWare.PawPrint.ExternImplementations
|
||||
|
||||
/// Result of executing (some steps of) the program under PawPrint.
|
||||
type RunResult =
|
||||
@@ -16,8 +17,22 @@ type RunResult =
|
||||
FinalState : IlMachineState
|
||||
}
|
||||
|
||||
type NativeImpls =
|
||||
{
|
||||
System_Env : ISystem_Environment
|
||||
}
|
||||
|
||||
interface ISystem_Environment_Env with
|
||||
member this.System_Environment = this.System_Env
|
||||
|
||||
static member Mock () =
|
||||
{
|
||||
System_Env = System_EnvironmentMock.Empty
|
||||
}
|
||||
|
||||
type TestCase =
|
||||
{
|
||||
FileName : string
|
||||
ExpectedReturnCode : int
|
||||
NativeImpls : NativeImpls
|
||||
}
|
||||
|
@@ -22,11 +22,13 @@ module TestHelloWorld =
|
||||
let dotnetRuntimes =
|
||||
DotnetRuntime.SelectForDll assy.Location |> ImmutableArray.CreateRange
|
||||
|
||||
let impls = NativeImpls.Mock ()
|
||||
|
||||
try
|
||||
use peImage = new MemoryStream (image)
|
||||
|
||||
let terminalState, terminatingThread =
|
||||
Program.run loggerFactory (Some "HelloWorld.cs") peImage dotnetRuntimes []
|
||||
Program.run loggerFactory (Some "HelloWorld.cs") peImage dotnetRuntimes impls []
|
||||
|
||||
let exitCode =
|
||||
match terminalState.ThreadState.[terminatingThread].MethodState.EvaluationStack.Values with
|
||||
|
@@ -22,6 +22,7 @@
|
||||
<EmbeddedResource Include="sources\BasicException.cs" />
|
||||
<EmbeddedResource Include="sources\TriangleNumber.cs" />
|
||||
<EmbeddedResource Include="sources\WriteLine.cs" />
|
||||
<EmbeddedResource Include="sources\InstaQuit.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
13
WoofWare.PawPrint.Test/sources/InstaQuit.cs
Normal file
13
WoofWare.PawPrint.Test/sources/InstaQuit.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace HelloWorldApp
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static int Main(string[] args)
|
||||
{
|
||||
Environment.Exit(1);
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user