From db106b171935666a55761abb79a6524777702ba9 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Mon, 11 Oct 2021 11:41:50 +0100 Subject: [PATCH] Performance: speed up message handling in TestRunner. Signed-off-by: Adrian Conlon --- M6502/HarteTest_6502/TestRunner.cpp | 42 +++++++++++++++++++---------- M6502/HarteTest_6502/TestRunner.h | 9 ++++++- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/M6502/HarteTest_6502/TestRunner.cpp b/M6502/HarteTest_6502/TestRunner.cpp index a8291f5..9fb00db 100644 --- a/M6502/HarteTest_6502/TestRunner.cpp +++ b/M6502/HarteTest_6502/TestRunner.cpp @@ -39,35 +39,49 @@ void TestRunner::initialise() { WrittenByte.connect([this](EightBit::EventArgs&) { addActualEvent(test_t::action::write, ADDRESS().word, DATA()); }); + + os() << std::hex << std::uppercase << std::setfill('0'); } void TestRunner::raise(std::string what, uint16_t expected, uint16_t actual) { - std::ostringstream os; - os + os() + << std::setw(4) << what - << ": expected: " << EightBit::Disassembly::dump_WordValue(expected) - << ", actual: " << EightBit::Disassembly::dump_WordValue(actual); - m_messages.push_back(os.str()); + << ": expected: " << (int)expected + << ", actual: " << (int)actual; + m_messages.push_back(os().str()); + os().str(""); } void TestRunner::raise(std::string what, uint8_t expected, uint8_t actual) { - std::ostringstream os; - os + os() + << std::setw(2) << what - << ": expected: " << EightBit::Disassembly::dump_ByteValue(expected) + << ": expected: " << (int)expected << "(" << EightBit::Disassembly::dump_Flags(expected) << ")" - << ", actual: " << EightBit::Disassembly::dump_ByteValue(actual) + << ", actual: " << (int)actual << "(" << EightBit::Disassembly::dump_Flags(actual) << ")"; - m_messages.push_back(os.str()); + m_messages.push_back(os().str()); + os().str(""); } void TestRunner::raise(std::string what, test_t::action expected, test_t::action actual) { - std::ostringstream os; - os + os() << what << ": expected: " << test_t::to_string(expected) << ", actual: " << test_t::to_string(actual); - m_messages.push_back(os.str()); + m_messages.push_back(os().str()); + os().str(""); +} + +bool TestRunner::check(std::string what, uint16_t address, uint8_t expected, uint8_t actual) { + const auto success = actual == expected; + if (!success) { + os() << what << ": " << std::setw(4) << (int)address; + raise(os().str(), expected, actual); + os().str(""); + } + return success; } void TestRunner::initialiseState() { @@ -120,7 +134,7 @@ bool TestRunner::checkState() { bool ram_problem = false; for (const auto& entry : ram) { const auto [address, value] = entry; - const auto ram_good = check("RAM: " + EightBit::Disassembly::dump_WordValue(address), value, RAM().peek(address)); + const auto ram_good = check("RAM", address, value, RAM().peek(address)); if (!ram_good && !ram_problem) ram_problem = true; } diff --git a/M6502/HarteTest_6502/TestRunner.h b/M6502/HarteTest_6502/TestRunner.h index ccb9e48..ff1c8d7 100644 --- a/M6502/HarteTest_6502/TestRunner.h +++ b/M6502/HarteTest_6502/TestRunner.h @@ -15,6 +15,8 @@ private: EightBit::Ram m_ram = 0x10000; EightBit::MOS6502 m_cpu = { *this }; const test_t& m_test; + + std::ostringstream m_os; std::vector m_messages; test_t::events_t m_actualEvents; @@ -28,15 +30,20 @@ private: void raise(std::string what, test_t::action expected, test_t::action actual); template - [[nodiscard]] bool check(std::string what, T expected, T actual) { + bool check(std::string what, T expected, T actual) { const auto success = actual == expected; if (!success) raise(what, expected, actual); return success; } + bool check(std::string what, uint16_t address, uint8_t expected, uint8_t actual); + + void addActualEvent(test_t::action action, uint16_t address, uint8_t value); + [[nodiscard]] auto& os() { return m_os; } + protected: virtual EightBit::MemoryMapping mapping(uint16_t address) noexcept final;