-
Notifications
You must be signed in to change notification settings - Fork 559
/
Copy pathEngine.cs
112 lines (84 loc) · 4.19 KB
/
Engine.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using Cosmos.Build.Common;
namespace Cosmos.TestRunner.Core
{
public partial class Engine
{
private static readonly string WorkingDirectoryBase = Path.Combine(
Path.GetDirectoryName(typeof(Engine).Assembly.Location), "WorkingDirectory");
// configuration: in process eases debugging, but means certain errors (like stack overflow) kill the test runner.
protected bool DebugIL2CPU => mConfiguration.DebugIL2CPU;
protected string KernelPkg => mConfiguration.KernelPkg;
protected TraceAssemblies TraceAssembliesLevel => mConfiguration.TraceAssembliesLevel;
protected bool EnableStackCorruptionChecks => mConfiguration.EnableStackCorruptionChecks;
protected StackCorruptionDetectionLevel StackCorruptionDetectionLevel => mConfiguration.StackCorruptionDetectionLevel;
protected DebugMode DebugMode => mConfiguration.DebugMode;
protected bool RunWithGDB => mConfiguration.RunWithGDB;
protected bool StartBochsDebugGui => mConfiguration.StartBochsDebugGUI;
public IEnumerable<string> KernelsAssembliesToRun => mConfiguration.KernelAssembliesToRun;
private IEngineConfiguration mConfiguration;
private TestResultOutputHandler mTestResultOutputHandler;
public OutputHandlerBasic OutputHandler { get; private set; }
public Engine(IEngineConfiguration aEngineConfiguration)
{
mConfiguration = aEngineConfiguration;
mTestResultOutputHandler = new TestResultOutputHandler();
}
public ITestResult Execute() => Execute(CancellationToken.None);
public ITestResult Execute(CancellationToken cancellationToken)
{
// todo: implement cancellation
if (!RunTargets.Any())
{
throw new InvalidOperationException("No run targets were specified!");
}
var xTestResult = new TestResult();
OutputHandler.ExecutionStart();
foreach (var xConfig in GetRunConfigurations())
{
OutputHandler.RunConfigurationStart(xConfig);
foreach (var xKernelAssembly in KernelsAssembliesToRun)
{
var xKernelName = Path.GetFileNameWithoutExtension(xKernelAssembly);
var xKernelTestResult = new KernelTestResult(xKernelName, xConfig);
var xWorkingDirectory = Path.Combine(WorkingDirectoryBase, xKernelName);
if (Directory.Exists(xWorkingDirectory))
{
Directory.Delete(xWorkingDirectory, true);
}
Directory.CreateDirectory(xWorkingDirectory);
try
{
xKernelTestResult.Result = ExecuteKernel(
xKernelAssembly, xWorkingDirectory, xConfig, xKernelTestResult);
}
catch (Exception e)
{
OutputHandler.UnhandledException(e);
}
xKernelTestResult.TestLog = mTestResultOutputHandler.TestLog;
xTestResult.AddKernelTestResult(xKernelTestResult);
}
OutputHandler.RunConfigurationEnd(xConfig);
}
OutputHandler.ExecutionEnd();
var xPassedTestsCount = xTestResult.KernelTestResults.Count(r => r.Result);
var xFailedTestsCount = xTestResult.KernelTestResults.Count(r => !r.Result);
OutputHandler.LogMessage($"Done executing: {xPassedTestsCount} test(s) passed, {xFailedTestsCount} test(s) failed.");
return xTestResult;
}
public void SetOutputHandler(OutputHandlerBasic outputHandler) =>
OutputHandler = new MultiplexingOutputHandler(outputHandler, mTestResultOutputHandler);
private IEnumerable<RunConfiguration> GetRunConfigurations()
{
foreach (var xTarget in RunTargets)
{
yield return new RunConfiguration(isElf: true, runTarget: xTarget);
}
}
}
}