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 2021-10-11 10:20:18 +01:00
parent 760f5d5aec
commit 4be61a9d54
3 changed files with 56 additions and 29 deletions

View File

@ -1,7 +1,7 @@
#include "stdafx.h"
#include "TestRunner.h"
#include <iostream>
#include <sstream>
#include <Disassembly.h>
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();
lowerPOWER();
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;
}

View File

@ -1,5 +1,9 @@
#pragma once
#include <cstdint>
#include <string>
#include <vector>
#include <Bus.h>
#include <Ram.h>
#include <mos6502.h>
@ -11,11 +15,13 @@ private:
EightBit::Ram m_ram = 0x10000;
EightBit::MOS6502 m_cpu = { *this };
const test_t& m_test;
std::vector<std::string> 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();
};

View File

@ -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();
}
std::cout << "\n";
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;
}
}
}
}
}