Incredibly easy testing framework done. it has a bunch of .net .exe and .asm files.The .exe files are fed to the IL2CPU console app, and the resulting .asm file is compared to the framework's .asm versions. WATCH OUT: please only change the .asm file if the contents are verified to be correct!

This commit is contained in:
mterwoord_cp 2007-09-05 17:14:17 +00:00
parent 81e4fa33ff
commit 2c9532ef21
19 changed files with 388 additions and 5 deletions

View file

@ -0,0 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.20706</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{3A0BAC46-1D4E-4E21-89CA-72903B9FCEB1}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>IL2CPU.Tests</RootNamespace>
<AssemblyName>IL2CPU.Tests</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<None Include="Tests\SimpleMethodCall\SimpleMethodCall.cs" />
<None Include="Tests\SingleMethodWithParam\SingleMethodWithParam.cs" />
<None Include="Tests\SimpleVar\SimpleVar.cs" />
<None Include="Tests\EmptyMethod\TestEmptyMethodApp.cs" />
<None Include="Tests\EmptyMethod\TestEmptyMethodApp.expected.asm">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\IL2CPU\IL2CPU.csproj">
<Project>{B7E87073-CFFB-4972-BA0B-DCF0C3A0C930}</Project>
<Name>IL2CPU</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="Tests\EmptyMethod\TestEmptyMethodApp.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Tests\SimpleVar\SimpleVar.expected.asm">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Include="Tests\SimpleMethodCall\SimpleMethodCall.expected.asm">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Tests\SimpleVar\SimpleVar.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Tests\SingleMethodWithParam\SingleMethodWithParam.expected.asm">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Include="Tests\SimpleMethodCall\SimpleMethodCall.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Tests\SingleMethodWithParam\SingleMethodWithParam.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View file

@ -0,0 +1,10 @@
""
{
"FILE_VERSION" = "9237"
"ENLISTMENT_CHOICE" = "NEVER"
"PROJECT_FILE_RELATIVE_PATH" = ""
"NUMBER_OF_EXCLUDED_FILES" = "0"
"ORIGINAL_PROJECT_FILE_PATH" = ""
"NUMBER_OF_NESTED_PROJECTS" = "0"
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
}

View file

@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.IO;
using System.Text;
namespace IL2CPU.Tests {
class Program {
public const int TestTimeout_Seconds = 10;
public const int TestTimeout_Milliseconds = TestTimeout_Seconds * 1000;
static void Main(string[] args) {
SortedList<string, bool?> xTests = new SortedList<string, bool?>();
Console.WriteLine("IL2CPU Tester. Please be patient while all tests are executed");
Console.WriteLine();
string xBaseDir = Path.GetDirectoryName(typeof(Program).Assembly.Location);
string xBaseTestsDir = Path.Combine(xBaseDir, "Tests");
foreach (string s in Directory.GetFiles(xBaseTestsDir, "*.expected.asm", SearchOption.AllDirectories)) {
if (File.Exists(s.Replace(".expected.asm", ".exe"))) {
xTests.Add(s.Replace(".expected.asm", ".exe"), null);
}
}
Console.WriteLine("Found {0} tests. Executing now:", xTests.Count);
for (int i = 0; i < xTests.Count; i++) {
string xTestExe = xTests.Keys[i];
string xExpectedResultFile = xTestExe.Substring(0, xTestExe.Length - ".exe".Length) + ".expected.asm";
string xActualOutputFile = Path.GetTempFileName();
try {
ProcessStartInfo xStartInfo = new ProcessStartInfo();
xStartInfo.CreateNoWindow = true;
xStartInfo.UseShellExecute = false;
xStartInfo.FileName = Path.Combine(xBaseDir, "IL2CPU.exe");
xStartInfo.Arguments = "\"" + xTestExe + "\" \"" + xActualOutputFile + "\"";
Process xProc = Process.Start(xStartInfo);
if (!xProc.WaitForExit(TestTimeout_Milliseconds)) {
xTests[xTestExe] = null;
Console.Write("E");
}
if (String.Equals(File.ReadAllText(xExpectedResultFile), File.ReadAllText(xActualOutputFile))) {
xTests[xTestExe] = true;
Console.Write(".");
} else {
xTests[xTestExe] = false;
Console.Write("F");
}
} finally {
File.Delete(xActualOutputFile);
}
}
Console.WriteLine();
Console.WriteLine("Test execution done.");
if ((from item in xTests
where item.Value == false
select item.Key).Count() > 0) {
Console.WriteLine("Tests Failed:");
foreach (string s in (from item in xTests
where item.Value == false
select item.Key)) {
Console.WriteLine("\t" + s);
}
}
if ((from item in xTests
where item.Value == null
select item.Key).Count() > 0) {
Console.WriteLine("Tests Timed out:");
foreach (string s in (from item in xTests
where item.Value == null
select item.Key)) {
Console.WriteLine("\t" + s);
}
}
int xPassCount = (from item in xTests
where item.Value == true
select item).Count();
int xFailCount = (from item in xTests
where item.Value == false
select item).Count();
int xTimeoutCount = (from item in xTests
where item.Value == null
select item).Count();
Console.WriteLine("\tTests passed: {0}/{1}", xPassCount, xTests.Count);
Console.WriteLine("\tTests failed: {0}/{1}", xFailCount, xTests.Count);
Console.WriteLine("\tTests timed out: {0}/{1}", xTimeoutCount, xTests.Count);
}
}
}

View file

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("IL2CPU.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("IL2CPU.Tests")]
[assembly: AssemblyCopyright("Copyright © 2007")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("7be32638-7ce5-4584-a737-ccf459665a54")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View file

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace IL2CPU.Tests.Tests {
public class TestEmptyMethodApp {
public static void Main() {
}
}
}

View file

@ -0,0 +1,16 @@
format PE console
entry ___ENTRYPOINT___
section '.code' code readable executable
___ENTRYPOINT___:
jmp System_Void___IL2CPU_Tests_Tests_TestEmptyMethodApp_Main____
System_Void___IL2CPU_Tests_Tests_TestEmptyMethodApp_Main____:
mov ebp,esp
; IL: Nop
nop
; IL: Ret
ret

View file

@ -0,0 +1,12 @@
using System;
public static class Program
{
public static void Main()
{
TheMethod();
}
public static void TheMethod()
{
}
}

View file

@ -0,0 +1,27 @@
format PE console
entry ___ENTRYPOINT___
section '.code' code readable executable
___ENTRYPOINT___:
jmp System_Void___Program_Main____
System_Void___Program_Main____:
mov ebp,esp
; IL: Nop
nop
; IL: Call System.Void Program::TheMethod()
call System_Void___Program_TheMethod____
; IL: Nop
nop
; IL: Ret
ret
System_Void___Program_TheMethod____:
mov ebp,esp
; IL: Nop
nop
; IL: Ret
ret

View file

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace IL2CPU.Tests.Tests {
public class TestEmptyMethodApp {
public static void Main() {
int TempInt = 5;
}
}
}

Binary file not shown.

View file

@ -0,0 +1,23 @@
format PE console
entry ___ENTRYPOINT___
section '.code' code readable executable
___ENTRYPOINT___:
jmp System_Void___IL2CPU_Tests_Tests_TestEmptyMethodApp_Main____
System_Void___IL2CPU_Tests_Tests_TestEmptyMethodApp_Main____:
mov ebp,esp
pushd ebp
; IL: Nop
nop
; IL: Ldc_I4_5
pushd 5
; IL: Stloc_0
pop eax
mov [ebp + 12],eax
; IL: Ret
pop ebp
ret

View file

@ -0,0 +1,14 @@
using System;
public static class Program
{
public static void Main()
{
TheMethod(2);
}
public static void TheMethod(int aParam)
{
}
}

View file

@ -0,0 +1,29 @@
format PE console
entry ___ENTRYPOINT___
section '.code' code readable executable
___ENTRYPOINT___:
jmp System_Void___Program_Main____
System_Void___Program_Main____:
mov ebp,esp
; IL: Nop
nop
; IL: Ldc_I4_2
pushd 2
; IL: Call System.Void Program::TheMethod(System.Int32)
call System_Void___Program_TheMethod___System_Int32___
; IL: Nop
nop
; IL: Ret
ret
System_Void___Program_TheMethod___System_Int32___:
mov ebp,esp
; IL: Nop
nop
; IL: Ret
ret 4

View file

@ -21,9 +21,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorldAssembler", "Hell
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorldMetal", "HelloWorldMetal\HelloWorldMetal.csproj", "{B57BEF6D-48D6-49DD-B4C5-893537E0EBB8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IL2CPU.Tests", "IL2CPU.Tests\IL2CPU.Tests.csproj", "{3A0BAC46-1D4E-4E21-89CA-72903B9FCEB1}"
EndProject
Global
GlobalSection(TeamFoundationVersionControl) = preSolution
SccNumberOfProjects = 11
SccNumberOfProjects = 12
SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
SccTeamFoundationServer = https://tfs04.codeplex.com/
SccLocalPath0 = .
@ -57,6 +59,9 @@ Global
SccProjectUniqueName10 = HelloWorldMetal\\HelloWorldMetal.csproj
SccProjectName10 = HelloWorldMetal
SccLocalPath10 = HelloWorldMetal
SccProjectUniqueName11 = IL2CPU.Tests\\IL2CPU.Tests.csproj
SccProjectName11 = IL2CPU.Tests
SccLocalPath11 = IL2CPU.Tests
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -103,6 +108,10 @@ Global
{B57BEF6D-48D6-49DD-B4C5-893537E0EBB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B57BEF6D-48D6-49DD-B4C5-893537E0EBB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B57BEF6D-48D6-49DD-B4C5-893537E0EBB8}.Release|Any CPU.Build.0 = Release|Any CPU
{3A0BAC46-1D4E-4E21-89CA-72903B9FCEB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3A0BAC46-1D4E-4E21-89CA-72903B9FCEB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3A0BAC46-1D4E-4E21-89CA-72903B9FCEB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3A0BAC46-1D4E-4E21-89CA-72903B9FCEB1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View file

@ -9,14 +9,18 @@ namespace IL2CPU {
public static void Main(string[] args) {
try {
string exeName = "HelloWorldMetal.exe";
if(args.Length ==1 ) {
if (args.Length > 0) {
exeName = args[0];
}
string outputFileName = @"output.asm";
if(args.Length > 1) {
outputFileName = args[1];
}
Engine e = new Engine();
e.DebugLog += delegate(string aMessage) {
Console.WriteLine(aMessage);
};
using (FileStream fs = new FileStream(@"output.asm", FileMode.Create)) {
using (FileStream fs = new FileStream(outputFileName, FileMode.Create)) {
using (StreamWriter br = new StreamWriter(fs)) {
e.Execute(exeName, TargetPlatformEnum.x86, br);
}
@ -26,7 +30,6 @@ namespace IL2CPU {
}
Console.WriteLine("");
Console.WriteLine("Completed");
Console.ReadLine();
}
}
}

View file

@ -31,7 +31,7 @@ namespace Indy.IL2CPU.IL.X86 {
for (int i = 0; i < LocalsCount; i++) {
Assembler.Add(new CPU.Pop("ebp"));
}
Assembler.Add(new CPU.Ret(""));
Assembler.Add(new CPU.Ret(TotalArgsSize == 0 ? "" : TotalArgsSize.ToString()));
}
}
}