Skip to content

Commit

Permalink
Refactoring of kernel tester. Take out generic part of the runner, so…
Browse files Browse the repository at this point in the history
… other targets (vmware, hyper-v in the future, etc) can also be tested.
  • Loading branch information
mterwoord committed Jul 17, 2015
1 parent 65fc684 commit 3f86e04
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 123 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ indent_size = 2
trim_trailing_whitespace = true

[*.cs]
indent_size = 2
indent_size = 4

[*.csproj]
indent_size = 2
7 changes: 7 additions & 0 deletions Tests/Cosmos.TestRunner.Core/Cosmos.TestRunner.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@
<Compile Include="Engine.Run.cs">
<DependentUpon>Engine.cs</DependentUpon>
</Compile>
<Compile Include="Engine.Running.cs">
<DependentUpon>Engine.cs</DependentUpon>
</Compile>
<Compile Include="Engine.VMware.cs">
<DependentUpon>Engine.cs</DependentUpon>
</Compile>
<Compile Include="Enums.cs" />
<Compile Include="MultiplexingOutputHandler.cs" />
<Compile Include="OutputHandlerBase.cs" />
<Compile Include="OutputHandlerConsole.cs" />
Expand Down
4 changes: 2 additions & 2 deletions Tests/Cosmos.TestRunner.Core/DefaultEngineConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public static void Apply(Engine engine)
}

engine.AddKernel(typeof(Cosmos.Compiler.Tests.SimpleWriteLine.Kernel.Kernel).Assembly.Location);
engine.AddKernel(typeof(SimpleStructsAndArraysTest.Kernel).Assembly.Location);
engine.AddKernel(typeof(VGACompilerCrash.Kernel).Assembly.Location);
//engine.AddKernel(typeof(SimpleStructsAndArraysTest.Kernel).Assembly.Location);
//engine.AddKernel(typeof(VGACompilerCrash.Kernel).Assembly.Location);

// known bugs, therefor disabled for now:
}
Expand Down
121 changes: 3 additions & 118 deletions Tests/Cosmos.TestRunner.Core/Engine.Bochs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace Cosmos.TestRunner.Core
{
partial class Engine
{
private const int AllowedSecondsInKernel = 30;

private void RunIsoInBochs(string iso)
{
var xBochsConfig = Path.Combine(mBaseWorkingDirectory, "Kernel.bochsrc");
Expand All @@ -21,50 +19,8 @@ private void RunIsoInBochs(string iso)
xParams.Add("ISOFile", iso);
xParams.Add(BuildProperties.VisualStudioDebugPortString, "Pipe: Cosmos\\Serial");

var xDebugConnector = new DebugConnectorPipeServer("Cosmos\\Serial");

xDebugConnector.CmdChannel = ChannelPacketReceived;
xDebugConnector.CmdStarted = () =>
{
OutputHandler.LogMessage("DC: Started");
xDebugConnector.SendCmd(Vs2Ds.BatchEnd);
};
xDebugConnector.Error = e =>
{
OutputHandler.LogMessage("DC Error: " + e.ToString());
OutputHandler.SetKernelTestResult(false, "DC Error");
mKernelResultSet = true;
mBochsRunning = false;
};
xDebugConnector.CmdText += s =>
{
if (s == "SYS_TestKernel_Completed")
{
KernelTestCompleted();
return;
}
else if (s == "SYS_TestKernel_Failed")
{
KernelTestFailed();
return;
}
else if (s == "SYS_TestKernel_AssertionSucceeded")
{
KernelAssertionSucceeded();
return;
}
OutputHandler.LogMessage("Text from kernel: " + s);
};
xDebugConnector.CmdMessageBox = s =>
{
//OutputHandler.LogMessage("MessageBox from kernel: " + s)
};
xDebugConnector.CmdTrace = t =>
{
};
xDebugConnector.CmdBreak = t =>
{
};
var xDebugConnector = new DebugConnectorPipeServer(DebugConnectorPipeServer.DefaultCosmosPipeName);
InitializeDebugConnector(xDebugConnector);

var xBochs = new Bochs(xParams, false, new FileInfo(xBochsConfig));
xBochs.OnShutDown = (a, b) =>
Expand All @@ -75,82 +31,11 @@ private void RunIsoInBochs(string iso)
xBochs.LogOutput = s => OutputHandler.LogDebugMessage(s);

mBochsRunning = true;
xBochs.Start();
try
{
var xStartTime = DateTime.Now;
mKernelResultSet = false;
Interlocked.Exchange(ref mSucceededAssertions, 0);

while (mBochsRunning)
{
Thread.Sleep(50);

if (Math.Abs(DateTime.Now.Subtract(xStartTime).TotalSeconds) > AllowedSecondsInKernel)
{
OutputHandler.SetKernelTestResult(false, "Timeout exceeded");
mKernelResultSet = true;
break;
}
}
if (!mKernelResultSet)
{
OutputHandler.SetKernelTestResult(true, null);
}
OutputHandler.SetKernelSucceededAssertionsCount(mSucceededAssertions);
}
finally
{
xBochs.Stop();
xDebugConnector.Dispose();
Thread.Sleep(50);
}
HandleRunning(xDebugConnector, xBochs);
}

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

private void ChannelPacketReceived(byte arg1, byte arg2, byte[] arg3)
{
OutputHandler.LogMessage(String.Format("ChannelPacketReceived, Channel = {0}, Command = {1}", arg1, arg2));
if (arg1 == 129)
{
// for now, skip
return;
}
if (arg1 == TestController.TestChannel)
{
switch (arg2)
{
case (byte)TestChannelCommandEnum.TestCompleted:
KernelTestCompleted();
break;
case (byte)TestChannelCommandEnum.TestFailed:
KernelTestFailed();
break;
case (byte)TestChannelCommandEnum.AssertionSucceeded:
KernelAssertionSucceeded();
break;
}
}
}

private void KernelAssertionSucceeded()
{
Interlocked.Increment(ref mSucceededAssertions);
}

private void KernelTestFailed()
{
OutputHandler.SetKernelTestResult(false, "Test failed");
mKernelResultSet = true;
mBochsRunning = false;
}

private void KernelTestCompleted()
{
mBochsRunning = false;
}
}
}
14 changes: 13 additions & 1 deletion Tests/Cosmos.TestRunner.Core/Engine.Run.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace Cosmos.TestRunner.Core
{
partial class Engine
{
private const int AllowedSecondsInKernel = 30;

private void ExecuteKernel(string assemblyFileName, RunConfiguration configuration)
{
OutputHandler.ExecuteKernelStart(assemblyFileName);
Expand All @@ -34,7 +36,17 @@ private void ExecuteKernel(string assemblyFileName, RunConfiguration configurati
}

RunTask("MakeISO", () => MakeIso(xObjectFile, xIsoFile));
RunTask("RunISOInBochs", () => RunIsoInBochs(xIsoFile));
switch (configuration.RunTarget)
{
case RunTargetEnum.Bochs:
RunTask("RunISO", () => RunIsoInBochs(xIsoFile));
break;
//case RunTargetEnum.VMware:
// RunTask("RunISO", () => RunIsoInVMware(xIsoFile));
// break;
default:
throw new ArgumentOutOfRangeException("RunTarget " + configuration.RunTarget + " not implemented!");
}
}
catch (Exception e)
{
Expand Down
151 changes: 151 additions & 0 deletions Tests/Cosmos.TestRunner.Core/Engine.Running.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
using System;
using System.Threading;
using Cosmos.Debug.Common;
using Cosmos.Debug.VSDebugEngine.Host;

namespace Cosmos.TestRunner.Core
{
partial class Engine
{
// this file contains code handling situations when a kernel is running
// most of this is debug stub related

private void InitializeDebugConnector(DebugConnector debugConnector)
{
if (debugConnector == null)
{
throw new ArgumentNullException("debugConnector");
}

debugConnector.CmdChannel = ChannelPacketReceived;
debugConnector.CmdStarted = () =>
{
OutputHandler.LogMessage("DC: Started");
debugConnector.SendCmd(Vs2Ds.BatchEnd);
};
debugConnector.Error = e =>
{
OutputHandler.LogMessage("DC Error: " + e.ToString());
OutputHandler.SetKernelTestResult(false, "DC Error");
mKernelResultSet = true;
mBochsRunning = false;
};
debugConnector.CmdText += s =>
{
if (s == "SYS_TestKernel_Completed")
{
KernelTestCompleted();
return;
}
else if (s == "SYS_TestKernel_Failed")
{
KernelTestFailed();
return;
}
else if (s == "SYS_TestKernel_AssertionSucceeded")
{
KernelAssertionSucceeded();
return;
}
OutputHandler.LogMessage("Text from kernel: " + s);
};
debugConnector.CmdMessageBox = s =>
{
//OutputHandler.LogMessage("MessageBox from kernel: " + s)
};
debugConnector.CmdTrace = t =>
{
};
debugConnector.CmdBreak = t =>
{
};
}

private void HandleRunning(DebugConnector debugConnector, Base host)
{
if (debugConnector == null)
{
throw new ArgumentNullException("debugConnector");
}
if (host == null)
{
throw new ArgumentNullException("host");
}
host.Start();
try
{
var xStartTime = DateTime.Now;
mKernelResultSet = false;
Interlocked.Exchange(ref mSucceededAssertions, 0);

while (mBochsRunning)
{
Thread.Sleep(50);

if (Math.Abs(DateTime.Now.Subtract(xStartTime).TotalSeconds) > AllowedSecondsInKernel)
{
OutputHandler.SetKernelTestResult(false, "Timeout exceeded");
mKernelResultSet = true;
break;
}
}
if (!mKernelResultSet)
{
OutputHandler.SetKernelTestResult(true, null);
}
OutputHandler.SetKernelSucceededAssertionsCount(mSucceededAssertions);
}
finally
{
host.Stop();
debugConnector.Dispose();
Thread.Sleep(50);
}
}

private volatile bool mKernelResultSet;
private int mSucceededAssertions;

private void ChannelPacketReceived(byte arg1, byte arg2, byte[] arg3)
{
OutputHandler.LogMessage(String.Format("ChannelPacketReceived, Channel = {0}, Command = {1}", arg1, arg2));
if (arg1 == 129)
{
// for now, skip
return;
}
if (arg1 == TestController.TestChannel)
{
switch (arg2)
{
case (byte)TestChannelCommandEnum.TestCompleted:
KernelTestCompleted();
break;
case (byte)TestChannelCommandEnum.TestFailed:
KernelTestFailed();
break;
case (byte)TestChannelCommandEnum.AssertionSucceeded:
KernelAssertionSucceeded();
break;
}
}
}

private void KernelAssertionSucceeded()
{
Interlocked.Increment(ref mSucceededAssertions);
}

private void KernelTestFailed()
{
OutputHandler.SetKernelTestResult(false, "Test failed");
mKernelResultSet = true;
mBochsRunning = false;
}

private void KernelTestCompleted()
{
mBochsRunning = false;
}
}
}
14 changes: 14 additions & 0 deletions Tests/Cosmos.TestRunner.Core/Engine.VMware.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Specialized;
using System.IO;
using System.Threading;
using Cosmos.Build.Common;
using Cosmos.Debug.Common;
using Cosmos.Debug.VSDebugEngine.Host;

namespace Cosmos.TestRunner.Core
{
partial class Engine
{
}
}
8 changes: 8 additions & 0 deletions Tests/Cosmos.TestRunner.Core/Enums.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Cosmos.TestRunner.Core
{
public enum RunTargetEnum
{
Bochs,
VMware
}
}
6 changes: 6 additions & 0 deletions Tests/Cosmos.TestRunner.Core/RunConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@ public bool IsELF
get;
set;
}

public RunTargetEnum RunTarget
{
get;
set;
}
}
}
Loading

0 comments on commit 3f86e04

Please sign in to comment.