From 45405d5624c534d99601b08887f129ae45a2ef3d Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Mon, 25 Oct 2021 18:40:21 +0100 Subject: [PATCH] Improve overall test speed by reusing test runners. Signed-off-by: Adrian Conlon --- M6502/HarteTest_6502/TestRunner.cpp | 15 +++++++++++---- M6502/HarteTest_6502/TestRunner.h | 6 +++--- M6502/HarteTest_6502/element_t.cpp | 2 ++ M6502/HarteTest_6502/element_t.h | 5 ++++- M6502/HarteTest_6502/test_t.cpp | 2 ++ M6502/HarteTest_6502/test_t.h | 1 + M6502/HarteTest_6502/tests.cpp | 6 ++++-- 7 files changed, 27 insertions(+), 10 deletions(-) diff --git a/M6502/HarteTest_6502/TestRunner.cpp b/M6502/HarteTest_6502/TestRunner.cpp index e3c89cf..465e0a5 100644 --- a/M6502/HarteTest_6502/TestRunner.cpp +++ b/M6502/HarteTest_6502/TestRunner.cpp @@ -4,8 +4,7 @@ std::set TestRunner::m_undocumented_opcodes; bool TestRunner::m_undocumented_opcodes_initialised = false; -TestRunner::TestRunner(const test_t test) -: m_test(test) {} +TestRunner::TestRunner() {} EightBit::MemoryMapping TestRunner::mapping(const uint16_t address) noexcept { return { RAM(), 0x0000, 0xffff, EightBit::MemoryMapping::AccessLevel::ReadWrite }; @@ -191,8 +190,16 @@ void TestRunner::disassemble(uint16_t address) { pushCurrentMessage(); } -void TestRunner::check() { - initialise(); +void TestRunner::check(const test_t updated) { + + m_test = updated; + + m_messages.clear(); + m_actualCycles.clear(); + m_cycles = 0; + m_valid = true; + m_undocumented = false; + raisePOWER(); initialiseState(); const auto pc = CPU().PC().word; diff --git a/M6502/HarteTest_6502/TestRunner.h b/M6502/HarteTest_6502/TestRunner.h index a8b0190..2de325b 100644 --- a/M6502/HarteTest_6502/TestRunner.h +++ b/M6502/HarteTest_6502/TestRunner.h @@ -25,7 +25,7 @@ private: EightBit::Symbols m_symbols; EightBit::Disassembly m_disassembler = { *this, m_cpu, m_symbols }; - const test_t m_test; + test_t m_test; std::ostringstream m_os; std::vector m_messages; @@ -92,7 +92,7 @@ protected: virtual EightBit::MemoryMapping mapping(uint16_t address) noexcept final; public: - TestRunner(test_t test); + TestRunner(); virtual void raisePOWER() final; virtual void lowerPOWER() final; @@ -112,5 +112,5 @@ public: [[nodiscard]] constexpr auto undocumented() const noexcept { return m_undocumented; } [[nodiscard]] constexpr auto documented() const noexcept { return !undocumented(); } - void check(); + void check(test_t updated); }; diff --git a/M6502/HarteTest_6502/element_t.cpp b/M6502/HarteTest_6502/element_t.cpp index 6ba0583..395a460 100644 --- a/M6502/HarteTest_6502/element_t.cpp +++ b/M6502/HarteTest_6502/element_t.cpp @@ -1,5 +1,7 @@ #include "stdafx.h" #include "element_t.h" +element_t::element_t() noexcept {} + element_t::element_t(const simdjson::dom::element input) noexcept : m_raw(input) {} diff --git a/M6502/HarteTest_6502/element_t.h b/M6502/HarteTest_6502/element_t.h index d1b7f3c..7053df8 100644 --- a/M6502/HarteTest_6502/element_t.h +++ b/M6502/HarteTest_6502/element_t.h @@ -6,9 +6,10 @@ class element_t { private: - const simdjson::dom::element m_raw; + simdjson::dom::element m_raw; protected: + element_t() noexcept; element_t(simdjson::dom::element input) noexcept; [[nodiscard]] auto raw() const noexcept { return m_raw; } @@ -17,4 +18,6 @@ protected: [[nodiscard]] auto operator[](std::string key) const noexcept { return at(key); } [[nodiscard]] auto array_at(std::string key) const noexcept { return at(key).get_array(); } [[nodiscard]] auto integer_at(std::string key) const noexcept { return at(key).get_int64(); } + + }; diff --git a/M6502/HarteTest_6502/test_t.cpp b/M6502/HarteTest_6502/test_t.cpp index 49d97c1..3f196dd 100644 --- a/M6502/HarteTest_6502/test_t.cpp +++ b/M6502/HarteTest_6502/test_t.cpp @@ -1,5 +1,7 @@ #include "stdafx.h" #include "test_t.h" +test_t::test_t() noexcept {} + test_t::test_t(const simdjson::dom::element input) noexcept : element_t(input) {} diff --git a/M6502/HarteTest_6502/test_t.h b/M6502/HarteTest_6502/test_t.h index d9ab705..32e271b 100644 --- a/M6502/HarteTest_6502/test_t.h +++ b/M6502/HarteTest_6502/test_t.h @@ -8,6 +8,7 @@ class test_t final : public element_t { public: + test_t() noexcept; test_t(simdjson::dom::element input) noexcept; [[nodiscard]] auto name() const noexcept { return at("name"); } diff --git a/M6502/HarteTest_6502/tests.cpp b/M6502/HarteTest_6502/tests.cpp index a6bdc08..f02101c 100644 --- a/M6502/HarteTest_6502/tests.cpp +++ b/M6502/HarteTest_6502/tests.cpp @@ -18,6 +18,9 @@ int main() { int unimplemented_opcode_count = 0; int invalid_opcode_count = 0; + TestRunner runner; + runner.initialise(); + for (const auto& entry : std::filesystem::directory_iterator{ location }) { const auto path = entry.path(); @@ -29,8 +32,7 @@ int main() { for (const auto opcode_test_element : opcode) { const auto opcode_test = test_t(opcode_test_element); - TestRunner runner(opcode_test); - runner.check(); + runner.check(opcode_test); if (runner.invalid()) { ++invalid_opcode_count;