mirror of
				https://github.com/MoleskiCoder/EightBitNet.git
				synced 2025-10-30 20:16:03 +00:00 
			
		
		
		
	Shared test harness
This commit is contained in:
		
							
								
								
									
										52
									
								
								EightBit/TestHarness.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								EightBit/TestHarness.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,52 @@ | |||||||
|  | // <copyright file="TestHarness.cs" company="Adrian Conlon"> | ||||||
|  | // Copyright (c) Adrian Conlon. All rights reserved. | ||||||
|  | // </copyright> | ||||||
|  |  | ||||||
|  | namespace EightBit | ||||||
|  | { | ||||||
|  |     using System.Diagnostics; | ||||||
|  |  | ||||||
|  |     public class TestHarness<TBus, TProcessor>(TBus board, TProcessor cpu) where TBus : Bus where TProcessor : Processor | ||||||
|  |     { | ||||||
|  |         private readonly Stopwatch _timer = new(); | ||||||
|  |         private readonly TBus _board = board; | ||||||
|  |         private readonly TProcessor _cpu = cpu; | ||||||
|  |         private long _totalCycles; | ||||||
|  |         private TimeSpan _totalUserProcessorTime; | ||||||
|  |  | ||||||
|  |         public long ElapsedMilliseconds => this._timer.ElapsedMilliseconds; | ||||||
|  |  | ||||||
|  |         public float ElapsedSeconds => this.ElapsedMilliseconds / 1000.0f; | ||||||
|  |  | ||||||
|  |         public float CyclesPerSecond => this._totalCycles / this.ElapsedSeconds; | ||||||
|  |  | ||||||
|  |         public void Run() | ||||||
|  |         { | ||||||
|  |             using var process = Process.GetCurrentProcess(); | ||||||
|  |             { | ||||||
|  |                 this._timer.Start(); | ||||||
|  |                 var startingUsage = process.UserProcessorTime; | ||||||
|  |  | ||||||
|  |                 this._board.Initialize(); | ||||||
|  |                 this._board.RaisePOWER(); | ||||||
|  |  | ||||||
|  |                 while (this._cpu.Powered) | ||||||
|  |                 { | ||||||
|  |                     this._totalCycles += this._cpu.Step(); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 var finishingUsage = process.UserProcessorTime; | ||||||
|  |                 this._timer.Stop(); | ||||||
|  |                 this._totalUserProcessorTime = finishingUsage - startingUsage; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             Console.Out.WriteLine(); | ||||||
|  |  | ||||||
|  |             Console.Out.WriteLine($"Guest cycles = {this._totalCycles:N0}"); | ||||||
|  |             Console.Out.WriteLine($"Seconds = {this.ElapsedSeconds}"); | ||||||
|  |  | ||||||
|  |             Console.Out.WriteLine($"{this.CyclesPerSecond / 1000000} MHz"); | ||||||
|  |             Console.Out.WriteLine($"Processor time = {this._totalUserProcessorTime.TotalSeconds:g}"); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -14,7 +14,8 @@ namespace Intel8080.Test | |||||||
|             configuration.DebugMode = true; |             configuration.DebugMode = true; | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|             var harness = new TestHarness(configuration); |             var board = new Board(configuration); | ||||||
|  |             var harness = new EightBit.TestHarness<Board, Intel8080>(board, board.CPU); | ||||||
|             harness.Run(); |             harness.Run(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -1,34 +0,0 @@ | |||||||
| // <copyright file="TestHarness.cs" company="Adrian Conlon"> |  | ||||||
| // Copyright (c) Adrian Conlon. All rights reserved. |  | ||||||
| // </copyright> |  | ||||||
|  |  | ||||||
| namespace Intel8080.Test |  | ||||||
| { |  | ||||||
|     using System.Diagnostics; |  | ||||||
|  |  | ||||||
|     internal class TestHarness(Configuration configuration) |  | ||||||
|     { |  | ||||||
|         private readonly Stopwatch timer = new(); |  | ||||||
|         private readonly Board board = new(configuration); |  | ||||||
|         private long totalCycles; |  | ||||||
|  |  | ||||||
|         public void Run() |  | ||||||
|         { |  | ||||||
|             this.board.Initialize(); |  | ||||||
|             this.board.RaisePOWER(); |  | ||||||
|  |  | ||||||
|             var cpu = this.board.CPU; |  | ||||||
|  |  | ||||||
|             this.timer.Start(); |  | ||||||
|             while (cpu.Powered) |  | ||||||
|             { |  | ||||||
|                 this.totalCycles += cpu.Step(); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             this.timer.Stop(); |  | ||||||
|  |  | ||||||
|             System.Console.Out.WriteLine($"\n\nGuest cycles = {this.totalCycles}"); |  | ||||||
|             System.Console.Out.WriteLine($"Seconds = {this.timer.ElapsedMilliseconds / 1000.0}"); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -10,7 +10,7 @@ namespace M6502.Test | |||||||
|     { |     { | ||||||
|         public bool DebugMode { get; set; } |         public bool DebugMode { get; set; } | ||||||
|  |  | ||||||
|         public bool Profile { get; set; }; |         public bool Profile { get; set; } | ||||||
|  |  | ||||||
|         // Sudoku |         // Sudoku | ||||||
|         public string Program { get; } = "sudoku.65b"; |         public string Program { get; } = "sudoku.65b"; | ||||||
|   | |||||||
| @@ -13,7 +13,8 @@ namespace M6502.Test | |||||||
| #if DEBUG | #if DEBUG | ||||||
|             configuration.DebugMode = false; |             configuration.DebugMode = false; | ||||||
| #endif | #endif | ||||||
|             var harness = new TestHarness(configuration); |             var board = new Board(configuration); | ||||||
|  |             var harness = new EightBit.TestHarness<Board, M6502.Core>(board, board.CPU); | ||||||
|             harness.Run(); |             harness.Run(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -1,53 +0,0 @@ | |||||||
| // <copyright file="TestHarness.cs" company="Adrian Conlon"> |  | ||||||
| // Copyright (c) Adrian Conlon. All rights reserved. |  | ||||||
| // </copyright> |  | ||||||
|  |  | ||||||
| namespace M6502.Test |  | ||||||
| { |  | ||||||
|     using System; |  | ||||||
|     using System.Diagnostics; |  | ||||||
|  |  | ||||||
|     internal sealed class TestHarness(Configuration configuration) |  | ||||||
|     { |  | ||||||
|         private readonly Stopwatch timer = new(); |  | ||||||
|         private readonly Board board = new(configuration); |  | ||||||
|         private long totalCycles; |  | ||||||
|         private TimeSpan totalUserProcessorTime; |  | ||||||
|  |  | ||||||
|         public long ElapsedMilliseconds => this.timer.ElapsedMilliseconds; |  | ||||||
|  |  | ||||||
|         public float ElapsedSeconds => this.ElapsedMilliseconds / 1000.0f; |  | ||||||
|  |  | ||||||
|         public float CyclesPerSecond => this.totalCycles / this.ElapsedSeconds; |  | ||||||
|  |  | ||||||
|         public void Run() |  | ||||||
|         { |  | ||||||
|             using var process = Process.GetCurrentProcess(); |  | ||||||
|             { |  | ||||||
|                 this.timer.Start(); |  | ||||||
|                 var startingUsage = process.UserProcessorTime; |  | ||||||
|  |  | ||||||
|                 this.board.Initialize(); |  | ||||||
|                 this.board.RaisePOWER(); |  | ||||||
|  |  | ||||||
|                 var cpu = this.board.CPU; |  | ||||||
|                 while (cpu.Powered) |  | ||||||
|                 { |  | ||||||
|                     this.totalCycles += cpu.Step(); |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 var finishingUsage = process.UserProcessorTime; |  | ||||||
|                 this.timer.Stop(); |  | ||||||
|                 this.totalUserProcessorTime = finishingUsage - startingUsage; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             System.Console.Out.WriteLine(); |  | ||||||
|  |  | ||||||
|             System.Console.Out.WriteLine($"Guest cycles = {this.totalCycles:N0}"); |  | ||||||
|             System.Console.Out.WriteLine($"Seconds = {this.ElapsedSeconds}"); |  | ||||||
|  |  | ||||||
|             System.Console.Out.WriteLine($"{this.CyclesPerSecond / 1000000} MHz"); |  | ||||||
|             System.Console.Out.WriteLine($"Processor time = {this.totalUserProcessorTime.TotalSeconds:g}"); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -7,7 +7,7 @@ | |||||||
|     <GenerateDocumentationFile>False</GenerateDocumentationFile> |     <GenerateDocumentationFile>False</GenerateDocumentationFile> | ||||||
|     <SignAssembly>False</SignAssembly> |     <SignAssembly>False</SignAssembly> | ||||||
|     <EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild> |     <EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild> | ||||||
|     <AnalysisLevel>latest</AnalysisLevel> |     <AnalysisLevel>latest-all</AnalysisLevel> | ||||||
|     <OutputType>Exe</OutputType> |     <OutputType>Exe</OutputType> | ||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
|  |  | ||||||
|   | |||||||
| @@ -4,6 +4,8 @@ | |||||||
|  |  | ||||||
| namespace Z80.Test | namespace Z80.Test | ||||||
| { | { | ||||||
|  |     using EightBit; | ||||||
|  |  | ||||||
|     public static class Program |     public static class Program | ||||||
|     { |     { | ||||||
|         public static void Main(string[] args) |         public static void Main(string[] args) | ||||||
| @@ -14,10 +16,9 @@ namespace Z80.Test | |||||||
|             configuration.DebugMode = true; |             configuration.DebugMode = true; | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|             using (var harness = new TestHarness(configuration)) |             var board = new Board(configuration); | ||||||
|             { |             var harness = new TestHarness<Board, Z80>(board, board.CPU); | ||||||
|             harness.Run(); |             harness.Run(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| } |  | ||||||
|   | |||||||
| @@ -1,53 +0,0 @@ | |||||||
| // <copyright file="TestHarness.cs" company="Adrian Conlon"> |  | ||||||
| // Copyright (c) Adrian Conlon. All rights reserved. |  | ||||||
| // </copyright> |  | ||||||
|  |  | ||||||
| namespace Z80.Test |  | ||||||
| { |  | ||||||
|     using System; |  | ||||||
|     using System.Diagnostics; |  | ||||||
|  |  | ||||||
|     internal class TestHarness(Configuration configuration) |  | ||||||
|     { |  | ||||||
|         private readonly Stopwatch timer = new(); |  | ||||||
|         private readonly Board board = new(configuration); |  | ||||||
|         private long totalCycles; |  | ||||||
|         private TimeSpan totalUserProcessorTime; |  | ||||||
|  |  | ||||||
|         public long ElapsedMilliseconds => timer.ElapsedMilliseconds; |  | ||||||
|  |  | ||||||
|         public float ElapsedSeconds => ElapsedMilliseconds / 1000.0f; |  | ||||||
|  |  | ||||||
|         public float CyclesPerSecond => totalCycles / ElapsedSeconds; |  | ||||||
|  |  | ||||||
|         public void Run() |  | ||||||
|         { |  | ||||||
|             using var process = Process.GetCurrentProcess(); |  | ||||||
|             { |  | ||||||
|                 timer.Start(); |  | ||||||
|                 var startingUsage = process.UserProcessorTime; |  | ||||||
|  |  | ||||||
|                 board.Initialize(); |  | ||||||
|                 board.RaisePOWER(); |  | ||||||
|  |  | ||||||
|                 var cpu = board.CPU; |  | ||||||
|                 while (cpu.Powered) |  | ||||||
|                 { |  | ||||||
|                     totalCycles += cpu.Step(); |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 var finishingUsage = process.UserProcessorTime; |  | ||||||
|                 timer.Stop(); |  | ||||||
|                 totalUserProcessorTime = finishingUsage - startingUsage; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             System.Console.Out.WriteLine(); |  | ||||||
|  |  | ||||||
|             System.Console.Out.WriteLine($"Guest cycles = {totalCycles:N0}"); |  | ||||||
|             System.Console.Out.WriteLine($"Seconds = {ElapsedSeconds}"); |  | ||||||
|  |  | ||||||
|             System.Console.Out.WriteLine($"{CyclesPerSecond / 1000000} MHz"); |  | ||||||
|             System.Console.Out.WriteLine($"Processor time = {totalUserProcessorTime.TotalSeconds:g}"); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
		Reference in New Issue
	
	Block a user