Skip to content

Commit

Permalink
Running tests works now.
Browse files Browse the repository at this point in the history
  • Loading branch information
mterwoord committed Jun 21, 2015
1 parent a492cd0 commit 1828c66
Show file tree
Hide file tree
Showing 18 changed files with 281 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
<Compile Include="Kernel.cs" />
<Compile Include="AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Cosmos.TestRunner.TestController\Cosmos.TestRunner.TestController.csproj">
<Project>{E6D3B644-C487-472D-A978-C1A82D0C099B}</Project>
<Name>Cosmos.TestRunner.TestController</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\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.
Expand Down
6 changes: 3 additions & 3 deletions Tests/Cosmos.Compiler.Tests.Interfaces/Kernel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using Cosmos.TestRunner;
using Sys = Cosmos.System;

namespace Cosmos.Compiler.Tests.Interfaces.Kernel
Expand Down Expand Up @@ -96,9 +97,8 @@ protected override void Run()
Console.WriteLine("-- T --");
xT.PrintText("Test");

Console.WriteLine("Press a key: ");
Console.ReadKey();
Stop();
TestController.Completed();
TestController.Completed();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
<Compile Include="Kernel.cs" />
<Compile Include="AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Cosmos.TestRunner.TestController\Cosmos.TestRunner.TestController.csproj">
<Project>{E6D3B644-C487-472D-A978-C1A82D0C099B}</Project>
<Name>Cosmos.TestRunner.TestController</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\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.
Expand Down
10 changes: 5 additions & 5 deletions Tests/Cosmos.Compiler.Tests.SimpleWriteLine.Kernel/Kernel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using Cosmos.TestRunner;
using Sys = Cosmos.System;

namespace Cosmos.Compiler.Tests.SimpleWriteLine.Kernel
Expand All @@ -14,10 +15,9 @@ protected override void BeforeRun()

protected override void Run()
{
Console.Write("Input: ");
var input = Console.ReadLine();
Console.Write("Text typed: ");
Console.WriteLine(input);
Console.WriteLine("Started correctly!");
Assert.IsTrue(true, "Dummy assertion, to test the system");
TestController.Completed();
}
}
}
}
6 changes: 3 additions & 3 deletions Tests/Cosmos.Compiler.Tests/DoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void SimpleWriteLineTest()
// these files contain the output to be verified. don't clean them.
var xOutputFile = Path.GetTempFileName();
var xLogFile = Path.GetTempFileName();

var xRunner = new CompilerRunner();

xRunner.References.Add(typeof(Cosmos.Compiler.Tests.SimpleWriteLine.Kernel.Kernel).Assembly.Location);
Expand All @@ -29,7 +29,7 @@ public void SimpleWriteLineTest()
xRunner.AssemblerLogFile = xLogFile;
xRunner.OutputFile = xOutputFile;
xRunner.Execute();

Verify("Output", File.ReadAllText(xOutputFile));
Verify("Logfile", File.ReadAllText(xLogFile));
}
Expand Down Expand Up @@ -57,4 +57,4 @@ public void InterfacesTest()
Verify("Logfile", File.ReadAllText(xLogFile));
}
}
}
}
4 changes: 4 additions & 0 deletions Tests/Cosmos.TestRunner.Core/Cosmos.TestRunner.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@
<Project>{6128DEEB-D30F-4859-B60F-C36D5452F3E9}</Project>
<Name>IL2CPU</Name>
</ProjectReference>
<ProjectReference Include="..\Cosmos.TestRunner.TestController\Cosmos.TestRunner.TestController.csproj">
<Project>{E6D3B644-C487-472D-A978-C1A82D0C099B}</Project>
<Name>Cosmos.TestRunner.TestController</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
39 changes: 34 additions & 5 deletions Tests/Cosmos.TestRunner.Core/Engine.Bochs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ private void RunIsoInBochs(string iso)
try
{
var xStartTime = DateTime.Now;
var xKernelResultSet = false;
mKernelResultSet = false;
Interlocked.Exchange(ref mSucceededAssertions, 0);

Console.WriteLine("Bochs started");
while (mBochsRunning)
Expand All @@ -57,14 +58,15 @@ private void RunIsoInBochs(string iso)
if (Math.Abs(DateTime.Now.Subtract(xStartTime).TotalSeconds) > AllowedSecondsInKernel)
{
OutputHandler.SetKernelTestResult(false, "Timeout exceeded");
xKernelResultSet = true;
mKernelResultSet = true;
break;
}
}
if (!xKernelResultSet)
if (!mKernelResultSet)
{
OutputHandler.SetKernelTestResult(true, null);
}
OutputHandler.SetKernelSucceededAssertionsCount(mSucceededAssertions);
Console.WriteLine("Stopping bochs now");
}
finally
Expand All @@ -75,11 +77,38 @@ private void RunIsoInBochs(string iso)
}
}

private bool mBochsRunning = true;
private volatile bool mBochsRunning = true;
private volatile bool mKernelResultSet;
private int mSucceededAssertions;

private void ChannelPacketReceived(byte arg1, byte arg2, byte[] arg3)
{
Console.WriteLine("ChannelPacket received. Channel = {0}, command = {1}", arg1, arg2);
if (arg1 == 129)
{
// for now, skip
return;
}
if (arg1 != TestController.TestChannel)
{
throw new Exception("Unhandled channel " + arg1);
}

switch (arg2)
{
case (byte)TestChannelCommandEnum.TestCompleted:
mBochsRunning = false;
break;
case (byte)TestChannelCommandEnum.TestFailed:
OutputHandler.SetKernelTestResult(false, "Test failed");
mKernelResultSet = true;
mBochsRunning = false;
break;
case (byte)TestChannelCommandEnum.AssertionSucceeded:
Interlocked.Increment(ref mSucceededAssertions);
break;
default:
throw new NotImplementedException("TestChannel command " + arg2 + " is not implemented!");
}
}
}
}
1 change: 1 addition & 0 deletions Tests/Cosmos.TestRunner.Core/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public void Execute()
private IEnumerable<RunConfiguration> GetRunConfigurations()
{
yield return new RunConfiguration {IsELF = true};
yield return new RunConfiguration {IsELF = false};
}
}
}
2 changes: 2 additions & 0 deletions Tests/Cosmos.TestRunner.Core/OutputHandlerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ public abstract class OutputHandlerBase

public abstract void RunConfigurationStart(RunConfiguration configuration);
public abstract void RunConfigurationEnd(RunConfiguration configuration);

public abstract void SetKernelSucceededAssertionsCount(int succeededAssertions);
}
}
4 changes: 4 additions & 0 deletions Tests/Cosmos.TestRunner.Core/OutputHandlerConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,9 @@ public override void SetKernelTestResult(bool succeeded, string message)
{
Log(string.Format("Success = {0}, Message = '{1}'", succeeded, message));
}

public override void SetKernelSucceededAssertionsCount(int succeededAssertions)
{
}
}
}
22 changes: 20 additions & 2 deletions Tests/Cosmos.TestRunner.Core/OutputHandlerXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public partial class OutputHandlerXml: OutputHandlerBase
private readonly string mFilename;
private XmlDocument mDocument;

private bool mConfigurationSucceeded = false;
private bool mExecutionSucceeded = false;

public OutputHandlerXml(string filename)
{
mFilename = filename;
Expand All @@ -25,6 +28,7 @@ public override void ExecuteKernelStart(string assemblyName)
xItem.Attributes.Append(NewXmlAttribute("AssemblyName", assemblyName));
xParent.AppendChild(xItem);
mCurrentNode.Push(xItem);
mCurrentKernelNode = xItem;
mKernelStopwatch = Stopwatch.StartNew();
}

Expand All @@ -34,6 +38,7 @@ public override void ExecuteKernelEnd(string assemblyName)
{
mKernelStopwatch.Stop();
var xItem = mCurrentNode.Pop();
mCurrentKernelNode = null;
xItem.Attributes.Append(NewXmlAttribute("Duration", mKernelStopwatch.Elapsed.ToString("c")));
}

Expand All @@ -60,6 +65,7 @@ public override void ExecutionStart()
mDocument.DocumentElement.Attributes.Append(NewXmlAttribute("DateTime", DateTime.UtcNow.ToString("O")));
mCurrentNode.Push(mDocument.DocumentElement);
mExecutionStopwatch = Stopwatch.StartNew();
mExecutionSucceeded = true;
}

private Stopwatch mExecutionStopwatch;
Expand All @@ -68,13 +74,15 @@ public override void ExecutionEnd()
{
mExecutionStopwatch.Stop();
mDocument.DocumentElement.Attributes.Append(NewXmlAttribute("Duration", mExecutionStopwatch.Elapsed.ToString("c")));
mDocument.DocumentElement.Attributes.Append(NewXmlAttribute("Succeeded", mExecutionSucceeded.ToString()));
mDocument.Save(mFilename);
mCurrentNode.Pop();
}

private Stack<XmlElement> mCurrentNode = new Stack<XmlElement>();
private Stopwatch mTaskStopwatch;
private Stopwatch mConfigurationStopwatch;
private XmlElement mCurrentKernelNode;

public override void UnhandledException(Exception exception)
{
Expand Down Expand Up @@ -103,7 +111,6 @@ public override void TaskEnd(string taskName)

public override void SetKernelTestResult(bool succeeded, string message)
{
var xItem = mCurrentNode.ElementAt(1);
if (succeeded)
{
LogMessage(message);
Expand All @@ -112,7 +119,14 @@ public override void SetKernelTestResult(bool succeeded, string message)
{
LogError(message);
}
xItem.Attributes.Append(NewXmlAttribute("Succeeded", succeeded.ToString()));
mCurrentKernelNode.Attributes.Append(NewXmlAttribute("Succeeded", succeeded.ToString()));
mConfigurationSucceeded &= succeeded;
mExecutionSucceeded &= succeeded;
}

public override void SetKernelSucceededAssertionsCount(int succeededAssertions)
{
mCurrentKernelNode.Attributes.Append(NewXmlAttribute("SucceededAssertionsCount", succeededAssertions.ToString()));
}

public override void RunConfigurationStart(RunConfiguration configuration)
Expand All @@ -122,6 +136,7 @@ public override void RunConfigurationStart(RunConfiguration configuration)
xItem.Attributes.Append(NewXmlAttribute("IsELF", configuration.IsELF.ToString()));
xParent.AppendChild(xItem);
mCurrentNode.Push(xItem);
mConfigurationSucceeded = true;
mConfigurationStopwatch = Stopwatch.StartNew();
}

Expand All @@ -130,6 +145,9 @@ public override void RunConfigurationEnd(RunConfiguration configuration)
mConfigurationStopwatch.Stop();
var xItem = mCurrentNode.Pop();
xItem.Attributes.Append(NewXmlAttribute("Duration", mKernelStopwatch.Elapsed.ToString("c")));
xItem.Attributes.Append(NewXmlAttribute("Succeeded", mConfigurationSucceeded.ToString()));
}


}
}
24 changes: 24 additions & 0 deletions Tests/Cosmos.TestRunner.TestController/Assert.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;

namespace Cosmos.TestRunner
{
public static class Assert
{
public static void IsTrue(bool condition, string message)
{
if (condition)
{
TestController.Debugger.Send("Assertion succeeded:");
TestController.Debugger.Send(message);
TestController.AssertionSucceeded();
}
else
{
TestController.Debugger.Send("Assertion failed!:");
TestController.Debugger.Send(message);
TestController.Failed();
throw new Exception("Assertion failed!");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E6D3B644-C487-472D-A978-C1A82D0C099B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Cosmos.TestRunner</RootNamespace>
<AssemblyName>Cosmos.TestRunner.TestController</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</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>
<PlatformTarget>x86</PlatformTarget>
</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" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Assert.cs" />
<Compile Include="Enums.cs" />
<Compile Include="TestController.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\source\Cosmos.Debug.Kernel\Cosmos.Debug.Kernel.csproj">
<Project>{61607F1E-58F9-41CF-972F-128384F3E115}</Project>
<Name>Cosmos.Debug.Kernel</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\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>
9 changes: 9 additions & 0 deletions Tests/Cosmos.TestRunner.TestController/Enums.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Cosmos.TestRunner
{
public enum TestChannelCommandEnum
{
TestCompleted = 0,
TestFailed = 1,
AssertionSucceeded = 2,
}
}
Loading

0 comments on commit 1828c66

Please sign in to comment.