Separate concerns a little between low level classes and high level classes in terms of report generation.

Signed-off-by: Adrian Conlon <adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon committed 2021-10-11 10:20:18 +01:00
1 parent 760f5d5aec
commit 4be61a9d54
3 files changed
+56 -29

No files matched your search

+32 -22
View File
@@ -1,7 +1,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "TestRunner.h" #include "TestRunner.h"
#include <iostream> #include <sstream>
#include <Disassembly.h> #include <Disassembly.h>
TestRunner::TestRunner(const test_t& test) TestRunner::TestRunner(const test_t& test)
@@ -43,29 +43,32 @@ void TestRunner::initialise() {
} }
void TestRunner::raise(std::string what, uint16_t expected, uint16_t actual) { void TestRunner::raise(std::string what, uint16_t expected, uint16_t actual) {
std::cout std::ostringstream os;
<< "** Failure: " << what os
<< what
<< ": expected: " << EightBit::Disassembly::dump_WordValue(expected) << ": expected: " << EightBit::Disassembly::dump_WordValue(expected)
<< ", actual: " << EightBit::Disassembly::dump_WordValue(actual) << ", actual: " << EightBit::Disassembly::dump_WordValue(actual);
<< "\n"; m_messages.push_back(os.str());
} }
void TestRunner::raise(std::string what, uint8_t expected, uint8_t actual) { void TestRunner::raise(std::string what, uint8_t expected, uint8_t actual) {
std::cout std::ostringstream os;
<< "** Failure: " << what os
<< what
<< ": expected: " << EightBit::Disassembly::dump_ByteValue(expected) << ": expected: " << EightBit::Disassembly::dump_ByteValue(expected)
<< "(" << EightBit::Disassembly::dump_Flags(expected) << ")" << "(" << EightBit::Disassembly::dump_Flags(expected) << ")"
<< ", actual: " << EightBit::Disassembly::dump_ByteValue(actual) << ", actual: " << EightBit::Disassembly::dump_ByteValue(actual)
<< "(" << EightBit::Disassembly::dump_Flags(actual) << ")" << "(" << EightBit::Disassembly::dump_Flags(actual) << ")";
<< "\n"; m_messages.push_back(os.str());
} }
void TestRunner::raise(std::string what, test_t::action expected, test_t::action actual) { void TestRunner::raise(std::string what, test_t::action expected, test_t::action actual) {
std::cout std::ostringstream os;
<< "** Failure: " << what os
<< what
<< ": expected: " << test_t::to_string(expected) << ": expected: " << test_t::to_string(expected)
<< ", actual: " << test_t::to_string(actual) << ", actual: " << test_t::to_string(actual);
<< "\n"; m_messages.push_back(os.str());
} }
void TestRunner::initialiseState() { void TestRunner::initialiseState() {
@@ -87,16 +90,15 @@ void TestRunner::initialiseState() {
m_actualEvents.clear(); m_actualEvents.clear();
} }
void TestRunner::verifyState() { bool TestRunner::checkState() {
const auto& finished = test().final_state(); const auto& finished = test().final_state();
const auto& expected_events = test().cycles(); const auto& expected_events = test().cycles();
const auto& actual_events = m_actualEvents; const auto& actual_events = m_actualEvents;
if (expected_events.size() != actual_events.size()) { m_event_count_mismatch = expected_events.size() != actual_events.size();
//std::cout << "** event count mismatch" << "\n"; if (m_event_count_mismatch)
return; return false;
}
for (int i = 0; i < expected_events.size(); ++i) { for (int i = 0; i < expected_events.size(); ++i) {
const auto& expected = expected_events[i]; const auto& expected = expected_events[i];
@@ -124,15 +126,23 @@ void TestRunner::verifyState() {
ram_problem = true; ram_problem = true;
} }
const auto good = pc_good && s_good && a_good && x_good && y_good && p_good && !ram_problem; return pc_good && s_good && a_good && x_good && y_good && p_good && !ram_problem;
std::cout << (good ? "+" : "-");
} }
void TestRunner::run() { bool TestRunner::check() {
initialise(); initialise();
raisePOWER(); raisePOWER();
initialiseState(); initialiseState();
const int cycles = CPU().step(); const int cycles = CPU().step();
verifyState(); const auto valid = checkState();
if (m_event_count_mismatch) {
std::ostringstream os;
os
<< "Stepped cycles: " << cycles
<< ", expected events: " << test().cycles().size()
<< ", actual events: " << m_actualEvents.size();
m_messages.push_back(os.str());
}
lowerPOWER(); lowerPOWER();
return valid;
} }
+9 -2
View File
@@ -1,5 +1,9 @@
#pragma once #pragma once
#include <cstdint>
#include <string>
#include <vector>
#include <Bus.h> #include <Bus.h>
#include <Ram.h> #include <Ram.h>
#include <mos6502.h> #include <mos6502.h>
@@ -11,11 +15,13 @@ private:
EightBit::Ram m_ram = 0x10000; EightBit::Ram m_ram = 0x10000;
EightBit::MOS6502 m_cpu = { *this }; EightBit::MOS6502 m_cpu = { *this };
const test_t& m_test; const test_t& m_test;
std::vector<std::string> m_messages;
test_t::events_t m_actualEvents; test_t::events_t m_actualEvents;
bool m_event_count_mismatch = false;
void initialiseState(); void initialiseState();
void verifyState(); bool checkState();
void raise(std::string what, uint16_t expected, uint16_t actual); void raise(std::string what, uint16_t expected, uint16_t actual);
void raise(std::string what, uint8_t expected, uint8_t actual); void raise(std::string what, uint8_t expected, uint8_t actual);
@@ -45,6 +51,7 @@ public:
constexpr auto& RAM() noexcept { return m_ram; } constexpr auto& RAM() noexcept { return m_ram; }
constexpr auto& CPU() noexcept { return m_cpu; } constexpr auto& CPU() noexcept { return m_cpu; }
constexpr const auto& test() const noexcept { return m_test; } constexpr const auto& test() const noexcept { return m_test; }
constexpr const auto& messages() const noexcept { return m_messages; }
void run(); bool check();
}; };
+15 -5
View File
@@ -7,26 +7,36 @@
#include "test_t.h" #include "test_t.h"
#include "opcode_test_suite_t.h" #include "opcode_test_suite_t.h"
int main() { int main() {
std::filesystem::path location = "C:\\github\\spectrum\\libraries\\EightBit\\modules\\ProcessorTests\\6502\\v1"; std::filesystem::path location = "C:\\github\\spectrum\\libraries\\EightBit\\modules\\ProcessorTests\\6502\\v1";
for (const auto& entry : std::filesystem::directory_iterator{ location }) { for (const auto& entry : std::filesystem::directory_iterator{ location }) {
const auto path = entry.path(); const auto path = entry.path();
std::cout << "** path: " << path << std::endl;
const auto filename = path.filename();
std::cout << "Processing: " << filename << "\n";
opcode_test_suite_t opcode(path.string()); opcode_test_suite_t opcode(path.string());
opcode.load(); opcode.load();
const auto& opcode_test_array = opcode.get_array(); const auto& opcode_test_array = opcode.get_array();
bool opcode_bad = false;
for (const auto& opcode_test_element : opcode_test_array) { for (const auto& opcode_test_element : opcode_test_array) {
const auto opcode_test = test_t(opcode_test_element); const auto opcode_test = test_t(opcode_test_element);
TestRunner runner(opcode_test); TestRunner runner(opcode_test);
runner.run(); const auto good = runner.check();
if (!good) {
if (!opcode_bad) {
std::cout << "** Failed: " << opcode_test.name() << "\n";
for (const auto& message : runner.messages())
std::cout << "**** " << message << "\n";
opcode_bad = true;
}
}
} }
std::cout << "\n";
} }
} }