From 8027941b705e219fd202b7c01d5a4a311670cbee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Sat, 7 Apr 2018 21:13:42 +0200 Subject: Add initial implementatio of caches --- qtmips_machine/tests/testcache.cpp | 61 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 qtmips_machine/tests/testcache.cpp (limited to 'qtmips_machine/tests/testcache.cpp') diff --git a/qtmips_machine/tests/testcache.cpp b/qtmips_machine/tests/testcache.cpp new file mode 100644 index 0000000..02e734e --- /dev/null +++ b/qtmips_machine/tests/testcache.cpp @@ -0,0 +1,61 @@ +#include "tst_machine.h" +#include "cache.h" + +using namespace machine; + +void MachineTests::cache_data() { + QTest::addColumn("cache_c"); + QTest::addColumn("hit"); + QTest::addColumn("miss"); + + MachineConfigCache cache_c; + cache_c.set_write_policy(MachineConfigCache::WP_TROUGH); + cache_c.set_enabled(true); + cache_c.set_sets(8); + cache_c.set_blocks(1); + cache_c.set_associativity(1); + QTest::newRow("Directly mapped") << cache_c \ + << (unsigned)3 \ + << (unsigned)7; + cache_c.set_sets(1); + cache_c.set_blocks(8); + QTest::newRow("Wide") << cache_c \ + << (unsigned)5 \ + << (unsigned)5; + cache_c.set_sets(4); + cache_c.set_blocks(4); + QTest::newRow("Square") << cache_c \ + << (unsigned)4 \ + << (unsigned)6; +} + +void MachineTests::cache() { + QFETCH(MachineConfigCache, cache_c); + QFETCH(unsigned, hit); + QFETCH(unsigned, miss); + + Memory m; + Cache cch(&m, &cache_c); + + // Test reads // + m.write_word(0x200, 0x24); + m.write_word(0x204, 0x66); + m.write_word(0x21c, 0x12); + m.write_word(0x300, 0x32); + for (int i = 0; i < 2; i++) { + QCOMPARE(cch.read_word(0x200), (std::uint32_t)0x24); + QCOMPARE(cch.read_word(0x204), (std::uint32_t)0x66); + QCOMPARE(cch.read_word(0x21c), (std::uint32_t)0x12); + QCOMPARE(cch.read_word(0x300), (std::uint32_t)0x32); + } + + // Test writes // + cch.write_word(0x700, 0x24); + QCOMPARE(m.read_word(0x700), (std::uint32_t)0x24); + cch.write_word(0x700, 0x23); + QCOMPARE(m.read_word(0x700), (std::uint32_t)0x23); + + // Verify counts + QCOMPARE(cch.hit(), hit); + QCOMPARE(cch.miss(), miss); +} -- cgit v1.2.3