mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2025-01-22 12:30:44 +00:00
Use a shared test harness.
Signed-off-by: Adrian.Conlon <adrian.conlon@gmail.com>
This commit is contained in:
parent
5a3713fc8a
commit
8927f412d4
@ -1,39 +0,0 @@
|
||||
#include "stdafx.h"
|
||||
#include "Game.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
Game::Game(const Configuration& configuration)
|
||||
: m_configuration(configuration),
|
||||
m_board(configuration) {
|
||||
}
|
||||
|
||||
Game::~Game() {
|
||||
|
||||
auto elapsedTime = m_finishTime - m_startTime;
|
||||
auto seconds = std::chrono::duration_cast<std::chrono::seconds>(elapsedTime).count();
|
||||
|
||||
std::cout << "Cycles = " << m_totalCycles << std::endl;
|
||||
std::cout << "Seconds = " << seconds << std::endl;
|
||||
|
||||
auto cyclesPerSecond = m_totalCycles / seconds;
|
||||
std::cout.imbue(std::locale(""));
|
||||
std::cout << cyclesPerSecond << " cycles/second" << std::endl;
|
||||
}
|
||||
|
||||
void Game::initialise() {
|
||||
m_board.initialise();
|
||||
}
|
||||
|
||||
void Game::runLoop() {
|
||||
|
||||
m_startTime = std::chrono::system_clock::now();
|
||||
m_totalCycles = 0UL;
|
||||
|
||||
auto& cpu = m_board.getCPUMutable();
|
||||
while (!cpu.isHalted()) {
|
||||
m_totalCycles += cpu.step();
|
||||
}
|
||||
|
||||
m_finishTime = std::chrono::system_clock::now();
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Board.h"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
class Configuration;
|
||||
|
||||
class Game {
|
||||
public:
|
||||
Game(const Configuration& configuration);
|
||||
~Game();
|
||||
|
||||
void runLoop();
|
||||
void initialise();
|
||||
|
||||
private:
|
||||
const Configuration& m_configuration;
|
||||
Board m_board;
|
||||
long long m_totalCycles;
|
||||
std::chrono::system_clock::time_point m_startTime;
|
||||
std::chrono::system_clock::time_point m_finishTime;
|
||||
};
|
@ -14,6 +14,3 @@
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include <boost/timer/timer.hpp>
|
||||
#include <boost/chrono.hpp>
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "stdafx.h"
|
||||
#include "Game.h"
|
||||
#include "TestHarness.h"
|
||||
#include "Board.h"
|
||||
#include "Configuration.h"
|
||||
|
||||
int main(int, char*[]) {
|
||||
@ -11,9 +12,9 @@ int main(int, char*[]) {
|
||||
configuration.setProfileMode(true);
|
||||
#endif
|
||||
|
||||
Game game(configuration);
|
||||
game.initialise();
|
||||
game.runLoop();
|
||||
EightBit::TestHarness<Configuration, Board> harness(configuration);
|
||||
harness.initialise();
|
||||
harness.runLoop();
|
||||
|
||||
return 0;
|
||||
}
|
@ -148,13 +148,11 @@
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Board.h" />
|
||||
<ClInclude Include="Configuration.h" />
|
||||
<ClInclude Include="Game.h" />
|
||||
<ClInclude Include="stdafx.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Board.cpp" />
|
||||
<ClCompile Include="Configuration.cpp" />
|
||||
<ClCompile Include="Game.cpp" />
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
|
||||
|
@ -20,9 +20,6 @@
|
||||
<ClInclude Include="Configuration.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Game.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
@ -34,9 +31,6 @@
|
||||
<ClCompile Include="Configuration.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Game.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="test.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
@ -1,44 +0,0 @@
|
||||
#include "stdafx.h"
|
||||
#include "Game.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <boost/timer/timer.hpp>
|
||||
#include <boost/chrono.hpp>
|
||||
|
||||
Game::Game(const Configuration& configuration)
|
||||
: m_configuration(configuration),
|
||||
m_board(configuration) {
|
||||
}
|
||||
|
||||
Game::~Game() {
|
||||
|
||||
auto elapsedTime = m_finishTime - m_startTime;
|
||||
auto seconds = std::chrono::duration_cast<std::chrono::seconds>(elapsedTime).count();
|
||||
|
||||
std::cout << "Cycles = " << m_totalCycles << std::endl;
|
||||
std::cout << "Seconds = " << seconds << std::endl;
|
||||
|
||||
auto cyclesPerSecond = m_totalCycles / seconds;
|
||||
std::cout.imbue(std::locale(""));
|
||||
std::cout << cyclesPerSecond << " cycles/second" << std::endl;
|
||||
}
|
||||
|
||||
void Game::initialise() {
|
||||
m_board.initialise();
|
||||
}
|
||||
|
||||
void Game::runLoop() {
|
||||
|
||||
boost::timer::auto_cpu_timer cpu_timer;
|
||||
|
||||
m_startTime = std::chrono::system_clock::now();
|
||||
m_totalCycles = 0UL;
|
||||
|
||||
auto& cpu = m_board.getCPUMutable();
|
||||
while (!cpu.isHalted()) {
|
||||
m_totalCycles += cpu.step();
|
||||
}
|
||||
|
||||
m_finishTime = std::chrono::system_clock::now();
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Board.h"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
class Configuration;
|
||||
|
||||
class Game {
|
||||
public:
|
||||
Game(const Configuration& configuration);
|
||||
~Game();
|
||||
|
||||
void runLoop();
|
||||
void initialise();
|
||||
|
||||
private:
|
||||
const Configuration& m_configuration;
|
||||
Board m_board;
|
||||
long long m_totalCycles;
|
||||
std::chrono::system_clock::time_point m_startTime;
|
||||
std::chrono::system_clock::time_point m_finishTime;
|
||||
};
|
@ -14,6 +14,3 @@
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include <boost/timer/timer.hpp>
|
||||
#include <boost/chrono.hpp>
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "stdafx.h"
|
||||
#include "Game.h"
|
||||
#include "TestHarness.h"
|
||||
#include "Configuration.h"
|
||||
#include "Board.h"
|
||||
|
||||
int main(int, char*[]) {
|
||||
|
||||
@ -11,9 +12,9 @@ int main(int, char*[]) {
|
||||
configuration.setProfileMode(true);
|
||||
#endif
|
||||
|
||||
Game game(configuration);
|
||||
game.initialise();
|
||||
game.runLoop();
|
||||
EightBit::TestHarness<Configuration, Board> harness(configuration);
|
||||
harness.initialise();
|
||||
harness.runLoop();
|
||||
|
||||
return 0;
|
||||
}
|
@ -146,13 +146,11 @@
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Board.h" />
|
||||
<ClInclude Include="Configuration.h" />
|
||||
<ClInclude Include="Game.h" />
|
||||
<ClInclude Include="stdafx.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Board.cpp" />
|
||||
<ClCompile Include="Configuration.cpp" />
|
||||
<ClCompile Include="Game.cpp" />
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||
|
@ -20,9 +20,6 @@
|
||||
<ClInclude Include="Configuration.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Game.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
@ -34,9 +31,6 @@
|
||||
<ClCompile Include="Configuration.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Game.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="test.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
59
inc/TestHarness.h
Normal file
59
inc/TestHarness.h
Normal file
@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
|
||||
namespace EightBit {
|
||||
template<class ConfigurationT, class BoardT> class TestHarness {
|
||||
public:
|
||||
TestHarness(const ConfigurationT& configuration)
|
||||
: m_configuration(configuration),
|
||||
m_board(configuration) {
|
||||
}
|
||||
|
||||
~TestHarness() {
|
||||
auto elapsedTime = m_finishTime - m_startTime;
|
||||
auto seconds = std::chrono::duration_cast<std::chrono::seconds>(elapsedTime).count();
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << "Cycles = " << m_totalCycles << std::endl;
|
||||
std::cout << "Seconds = " << seconds << std::endl;
|
||||
|
||||
auto cyclesPerSecond = m_totalCycles / seconds;
|
||||
std::cout.imbue(std::locale(""));
|
||||
std::cout << cyclesPerSecond << " cycles/second" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
long long getElapsedSeconds() {
|
||||
return std::chrono::duration_cast<std::chrono::seconds>(elapsedTime).count();
|
||||
}
|
||||
|
||||
long long getCyclesPerSecond() const {
|
||||
|
||||
}
|
||||
|
||||
void runLoop() {
|
||||
m_startTime = std::chrono::system_clock::now();
|
||||
m_totalCycles = 0UL;
|
||||
|
||||
auto& cpu = m_board.getCPUMutable();
|
||||
while (!cpu.isHalted()) {
|
||||
m_totalCycles += cpu.step();
|
||||
}
|
||||
|
||||
m_finishTime = std::chrono::system_clock::now();
|
||||
}
|
||||
|
||||
void initialise() {
|
||||
m_board.initialise();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
const ConfigurationT& m_configuration;
|
||||
BoardT m_board;
|
||||
long long m_totalCycles;
|
||||
std::chrono::system_clock::time_point m_startTime;
|
||||
std::chrono::system_clock::time_point m_finishTime;
|
||||
};
|
||||
}
|
@ -143,6 +143,7 @@
|
||||
<ClInclude Include="..\inc\Memory.h" />
|
||||
<ClInclude Include="..\inc\Processor.h" />
|
||||
<ClInclude Include="..\inc\Signal.h" />
|
||||
<ClInclude Include="..\inc\TestHarness.h" />
|
||||
<ClInclude Include="stdafx.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -29,6 +29,9 @@
|
||||
<ClInclude Include="..\inc\IntelProcessor.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\inc\TestHarness.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
|
Loading…
x
Reference in New Issue
Block a user