diff options
Diffstat (limited to 'qtmips_machine/tests')
-rw-r--r-- | qtmips_machine/tests/testcache.cpp | 61 | ||||
-rw-r--r-- | qtmips_machine/tests/tests.pro | 3 | ||||
-rw-r--r-- | qtmips_machine/tests/tst_machine.h | 3 |
3 files changed, 66 insertions, 1 deletions
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<MachineConfigCache>("cache_c"); + QTest::addColumn<unsigned>("hit"); + QTest::addColumn<unsigned>("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); +} diff --git a/qtmips_machine/tests/tests.pro b/qtmips_machine/tests/tests.pro index ffe75b7..751bf8a 100644 --- a/qtmips_machine/tests/tests.pro +++ b/qtmips_machine/tests/tests.pro @@ -21,7 +21,8 @@ SOURCES += tst_machine.cpp \ testprogramloader.cpp \ testinstruction.cpp \ testalu.cpp \ - testcore.cpp + testcore.cpp \ + testcache.cpp HEADERS += tst_machine.h diff --git a/qtmips_machine/tests/tst_machine.h b/qtmips_machine/tests/tst_machine.h index ad3112c..a0e8525 100644 --- a/qtmips_machine/tests/tst_machine.h +++ b/qtmips_machine/tests/tst_machine.h @@ -46,6 +46,9 @@ private Q_SLOTS: void singlecore_mem_data(); void pipecore_mem(); void pipecore_mem_data(); + // Cache + void cache_data(); + void cache(); }; #endif // TST_MACHINE_H |