From 4be61a9d5461e6c564403f1d734efd9746b1819d Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Mon, 11 Oct 2021 10:20:18 +0100 Subject: [PATCH] Separate concerns a little between low level classes and high level classes in terms of report generation. Signed-off-by: Adrian Conlon --- M6502/HarteTest_6502/TestRunner.cpp | 54 +++++++++++++++++------------ M6502/HarteTest_6502/TestRunner.h | 11 ++++-- M6502/HarteTest_6502/tests.cpp | 20 ++++++++--- 3 files changed, 56 insertions(+), 29 deletions(-) diff --git a/M6502/HarteTest_6502/TestRunner.cpp b/M6502/HarteTest_6502/TestRunner.cpp index 8c78cf1..92883ee 100644 --- a/M6502/HarteTest_6502/TestRunner.cpp +++ b/M6502/HarteTest_6502/TestRunner.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" #include "TestRunner.h" -#include +#include #include 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) { - std::cout - << "** Failure: " << what + std::ostringstream os; + os + << what << ": expected: " << EightBit::Disassembly::dump_WordValue(expected) - << ", actual: " << EightBit::Disassembly::dump_WordValue(actual) - << "\n"; + << ", actual: " << EightBit::Disassembly::dump_WordValue(actual); + m_messages.push_back(os.str()); } void TestRunner::raise(std::string what, uint8_t expected, uint8_t actual) { - std::cout - << "** Failure: " << what + std::ostringstream os; + os + << what << ": expected: " << EightBit::Disassembly::dump_ByteValue(expected) << "(" << EightBit::Disassembly::dump_Flags(expected) << ")" << ", actual: " << EightBit::Disassembly::dump_ByteValue(actual) - << "(" << EightBit::Disassembly::dump_Flags(actual) << ")" - << "\n"; + << "(" << EightBit::Disassembly::dump_Flags(actual) << ")"; + m_messages.push_back(os.str()); } void TestRunner::raise(std::string what, test_t::action expected, test_t::action actual) { - std::cout - << "** Failure: " << what + std::ostringstream os; + os + << what << ": expected: " << test_t::to_string(expected) - << ", actual: " << test_t::to_string(actual) - << "\n"; + << ", actual: " << test_t::to_string(actual); + m_messages.push_back(os.str()); } void TestRunner::initialiseState() { @@ -87,16 +90,15 @@ void TestRunner::initialiseState() { m_actualEvents.clear(); } -void TestRunner::verifyState() { +bool TestRunner::checkState() { const auto& finished = test().final_state(); const auto& expected_events = test().cycles(); const auto& actual_events = m_actualEvents; - if (expected_events.size() != actual_events.size()) { - //std::cout << "** event count mismatch" << "\n"; - return; - } + m_event_count_mismatch = expected_events.size() != actual_events.size(); + if (m_event_count_mismatch) + return false; for (int i = 0; i < expected_events.size(); ++i) { const auto& expected = expected_events[i]; @@ -124,15 +126,23 @@ void TestRunner::verifyState() { ram_problem = true; } - const auto good = pc_good && s_good && a_good && x_good && y_good && p_good && !ram_problem; - std::cout << (good ? "+" : "-"); + return pc_good && s_good && a_good && x_good && y_good && p_good && !ram_problem; } -void TestRunner::run() { +bool TestRunner::check() { initialise(); raisePOWER(); initialiseState(); 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(); + return valid; } diff --git a/M6502/HarteTest_6502/TestRunner.h b/M6502/HarteTest_6502/TestRunner.h index 31c85d1..a102388 100644 --- a/M6502/HarteTest_6502/TestRunner.h +++ b/M6502/HarteTest_6502/TestRunner.h @@ -1,5 +1,9 @@ #pragma once +#include +#include +#include + #include #include #include @@ -11,11 +15,13 @@ private: EightBit::Ram m_ram = 0x10000; EightBit::MOS6502 m_cpu = { *this }; const test_t& m_test; + std::vector m_messages; test_t::events_t m_actualEvents; + bool m_event_count_mismatch = false; void initialiseState(); - void verifyState(); + bool checkState(); void raise(std::string what, uint16_t expected, uint16_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& CPU() noexcept { return m_cpu; } constexpr const auto& test() const noexcept { return m_test; } + constexpr const auto& messages() const noexcept { return m_messages; } - void run(); + bool check(); }; diff --git a/M6502/HarteTest_6502/tests.cpp b/M6502/HarteTest_6502/tests.cpp index 6ea5809..7de0e6a 100644 --- a/M6502/HarteTest_6502/tests.cpp +++ b/M6502/HarteTest_6502/tests.cpp @@ -7,26 +7,36 @@ #include "test_t.h" #include "opcode_test_suite_t.h" - int main() { + std::filesystem::path location = "C:\\github\\spectrum\\libraries\\EightBit\\modules\\ProcessorTests\\6502\\v1"; for (const auto& entry : std::filesystem::directory_iterator{ location }) { 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.load(); const auto& opcode_test_array = opcode.get_array(); + + bool opcode_bad = false; for (const auto& opcode_test_element : opcode_test_array) { const auto opcode_test = test_t(opcode_test_element); 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"; } } \ No newline at end of file