From 9cf92379d5fcf0076c25dae0935daab446c992cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Wed, 30 Aug 2017 21:37:53 +0200 Subject: Initial commit Adding work done so far. --- qtmips_machine/tests/testmemory.cpp | 61 +++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 qtmips_machine/tests/testmemory.cpp (limited to 'qtmips_machine/tests/testmemory.cpp') diff --git a/qtmips_machine/tests/testmemory.cpp b/qtmips_machine/tests/testmemory.cpp new file mode 100644 index 0000000..991e1f1 --- /dev/null +++ b/qtmips_machine/tests/testmemory.cpp @@ -0,0 +1,61 @@ +#include "tst_machine.h" +#include "memory.h" + +void MachineTests::memory_data() { + QTest::addColumn("address"); + + QTest::newRow("memory begin") << (std::uint32_t)0x00; + QTest::newRow("memory end") << (std::uint32_t)0xFFFFFFFC; + QTest::newRow("memory midle start") << (std::uint32_t)0xFFFF00; + QTest::newRow("memory midle end") << (std::uint32_t)0xFFFFFF; +} + +void MachineTests::memory() { + Memory m; + + QFETCH(std::uint32_t, address); + + // Uninitialize memory should read as zero + QCOMPARE(m.read_byte(address), (std::uint8_t)0); + QCOMPARE(m.read_hword(address), (std::uint16_t)0); + QCOMPARE(m.read_word(address), (std::uint32_t)0); + // Just a byte + m.write_byte(address, 0x42); + QCOMPARE(m.read_byte(address), (std::uint8_t)0x42); + // Half word + m.write_hword(address, 0x4243); + QCOMPARE(m.read_hword(address), (std::uint16_t)0x4243); + // Word + m.write_word(address, 0x42434445); + QCOMPARE(m.read_word(address), (std::uint32_t)0x42434445); +} + +void MachineTests::memory_section_data() { + QTest::addColumn("address"); + + QTest::newRow("memory begin") << (std::uint32_t)0x00; + QTest::newRow("memory end") << (std::uint32_t)0xFFFFFFFF; + QTest::newRow("memory midle start") << (std::uint32_t)0xFFFF00; + QTest::newRow("memory midle end") << (std::uint32_t)0xFFFFFF; +} + +void MachineTests::memory_section() { + Memory m; + + QFETCH(std::uint32_t, address); + + // First section shouldn't exists + QCOMPARE(m.get_section(address, false), (MemorySection*)nullptr); + // Create section + MemorySection *s = m.get_section(address, true); + QVERIFY(s != nullptr); + + // Write some data to memory + m.write_byte(address, 0x42); + // Read it trough section (mask bits outside of the memory section) + QCOMPARE(s->read_byte(address & ((1 << MEMORY_SECTION_BITS) - 1)), (std::uint8_t)0x42); + // Write some other data trough section + s->write_byte(address & ((1 << MEMORY_SECTION_BITS) - 1), 0x66); + // Read trough memory + QCOMPARE(m.read_byte(address), (std::uint8_t)0x66); +} -- cgit v1.2.3