diff options
author | bd <bdunahu@operationnull.com> | 2025-03-20 18:04:01 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-03-20 18:04:01 -0400 |
commit | c4bb9576e8d9c3913e515a7f0eb0d0e9965ebc72 (patch) | |
tree | 8ba64ec5c88fb9bc4435c1f42dfc9198aa38df4d | |
parent | c55104f8e99ea6ccb0c66a5e0d3cfc81dbbc19ab (diff) |
Make memory simulator an optional command, experiment with fixtures
-rw-r--r-- | src/main.cc | 43 | ||||
-rw-r--r-- | tests/dram.cc | 150 |
2 files changed, 102 insertions, 91 deletions
diff --git a/src/main.cc b/src/main.cc index 08b38e6..f5eecac 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,6 +1,6 @@ #include "cli.h" -#include "logger.h" #include "definitions.h" +#include "logger.h" #include <getopt.h> #include <iostream> @@ -22,36 +22,39 @@ static std::string banner = " _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ \n" " _/ _/ _/_/_/_/ _/_/_/ _/ _/_/ _/ _/ _/ \n" " _/_/ _/_/ "; -static void print_version_number() { std::cout << banner << version_number << '\n'; } +static void print_version_number() +{ + std::cout << banner << version_number << '\n'; +} static void err() { std::cerr << "Usage:\n\trisc_vector [OPTIONS]\nOptions:\n\t--debug,\t-d: " - "turn on verbose output\n\t--no-python,\t-p: run without " - "GUI\n\t--version,\t-v: print the version information and exit\n" + "turn on verbose output\n\t--memory-only,\t-m: run the memory " + "simulator only, without a GUI.\n\t--version,\t-v: print the " + "version information and exit\n" << std::endl; } -static void parseArguments(int argc, char **argv, bool &python) +static void +parseArguments(int argc, char **argv, bool &memory_only) { struct option long_options[] = { {"debug", no_argument, 0, 'd'}, - {"no-python", no_argument, 0, 'p'}, + {"memory-only", no_argument, 0, 'm'}, {0, 0, 0, 0}}; - python = true; - int opt; - while ((opt = getopt_long(argc, argv, "d:p", long_options, NULL)) != -1) { + while ((opt = getopt_long(argc, argv, "d:m", long_options, NULL)) != -1) { switch (opt) { case 'd': global_log->setLevel(DEBUG); global_log->log(DEBUG, "DEBUG output enabled."); break; - case 'p': - global_log->log(INFO, "Python will NOT be started!"); - python = false; + case 'm': + global_log->log(INFO, "Starting the storage CLI interface..."); + memory_only = true; break; default: err(); @@ -63,20 +66,18 @@ static void parseArguments(int argc, char **argv, bool &python) int main(int argc, char **argv) { print_version_number(); - Cli cli; global_log->log(INFO, "Initializing..."); - bool python = true; - parseArguments(argc, argv, python); + bool memory_only = false; + parseArguments(argc, argv, memory_only); - if (python) { - // fork off python here - ; - global_log->log(INFO, "Python started."); + if (memory_only) { + Cli cli; + cli.run(); } - cli.run(); - + // fork off python here + global_log->log(INFO, "Python started."); global_log->log(INFO, "Cleaning up..."); global_log->log(INFO, "Goodbye!"); return EXIT_SUCCESS; diff --git a/tests/dram.cc b/tests/dram.cc index 72a6d14..1fac82b 100644 --- a/tests/dram.cc +++ b/tests/dram.cc @@ -3,13 +3,21 @@ #include <array> #include <catch2/catch_test_macros.hpp> -TEST_CASE("Construct singleton dram", "[dram]") +class DramFixture { - Dram *d = new Dram(1, 1); - std::array<signed int, LINE_SIZE> expected = {0, 0, 0, 0}; - std::array<signed int, LINE_SIZE> actual = d->view(0, 1)[0]; + public: + DramFixture() { this->d = new Dram(1, this->delay); } + ~DramFixture() { delete this->d; } + int delay = 3; + Dram *d; + std::array<signed int, LINE_SIZE> expected; + std::array<signed int, LINE_SIZE> actual; +}; + +TEST_CASE_METHOD(DramFixture, "Construct singleton dram", "[dram]") +{ + this->actual = this->d->view(0, 1)[0]; REQUIRE(expected == actual); - delete d; } TEST_CASE( @@ -51,12 +59,10 @@ TEST_CASE( actual = d->view(0, 1)[0]; REQUIRE(expected == actual); - d->resolve(); } r = d->write_word(MEM, w, 0x00000000); CHECK(r == OK); - d->resolve(); expected.at(0) = w; actual = d->view(0, 1)[0]; @@ -86,19 +92,12 @@ TEST_CASE( actual = d->view(0, 1)[0]; REQUIRE(expected == actual); - d->resolve(); } r = d->write_word(MEM, w, 0x00000000); REQUIRE(r == OK); - // clock cycle did NOT resolve yet! - // this fetch should not make progress r = d->write_word(FETCH, w, 0x00000001); - CHECK(r == WAIT); - - actual = d->view(0, 1)[0]; - CHECK(r == WAIT); - d->resolve(); + CHECK(r == OK); expected.at(0) = w; actual = d->view(0, 1)[0]; @@ -186,8 +185,7 @@ TEST_CASE( delete d; } -TEST_CASE( - "Construct singleton dram, store line in zero cycles", "[dram]") +TEST_CASE("Construct singleton dram, store line in zero cycles", "[dram]") { Dram *d = new Dram(1, 0); std::array<signed int, LINE_SIZE> expected = {0, 0, 0, 0}; @@ -195,7 +193,7 @@ TEST_CASE( CHECK(expected == actual); signed int w = 0x11223344; - expected = {w, w+1, w+2, w+3}; + expected = {w, w + 1, w + 2, w + 3}; Response r = d->write_line(MEM, expected, 0x00000000); CHECK(r == OK); @@ -206,8 +204,7 @@ TEST_CASE( delete d; } -TEST_CASE( - "Construct singleton dram, store line in three cycles", "[dram]") +TEST_CASE("Construct singleton dram, store line in three cycles", "[dram]") { int delay = 3; Dram *d = new Dram(1, delay); @@ -216,7 +213,7 @@ TEST_CASE( CHECK(expected == actual); signed int w = 0x11223344; - std::array<signed int, LINE_SIZE> written_line = {w, w+1, w+2, w+3}; + std::array<signed int, LINE_SIZE> written_line = {w, w + 1, w + 2, w + 3}; int i; Response r; @@ -252,7 +249,7 @@ TEST_CASE( CHECK(expected == actual); signed int w = 0x11223344; - std::array<signed int, LINE_SIZE> written_line = {w, w+1, w+2, w+3}; + std::array<signed int, LINE_SIZE> written_line = {w, w + 1, w + 2, w + 3}; int i; Response r; @@ -280,7 +277,7 @@ TEST_CASE( actual = d->view(0, 1)[0]; REQUIRE(expected == actual); - written_line = {w+4, w+5, w+6, w+7}; + written_line = {w + 4, w + 5, w + 6, w + 7}; for (i = 0; i < delay; ++i) { r = d->write_line(FETCH, written_line, 0x00000001); @@ -314,7 +311,7 @@ TEST_CASE( CHECK(expected == actual); signed int w = 0x11223344; - std::array<signed int, LINE_SIZE> written_line = {w, w+1, w+2, w+3}; + std::array<signed int, LINE_SIZE> written_line = {w, w + 1, w + 2, w + 3}; int i; Response r; @@ -340,7 +337,7 @@ TEST_CASE( expected = written_line; REQUIRE(expected == actual); - written_line = {w+4, w+5, w+6, w+7}; + written_line = {w + 4, w + 5, w + 6, w + 7}; for (i = 0; i < delay; ++i) { r = d->write_line(FETCH, written_line, 0x00000001); CHECK(r == WAIT); @@ -366,7 +363,10 @@ TEST_CASE( delete d; } -TEST_CASE("Construct singleton dram, write a line to an address in 0 cycles, read in 0 cycles", "[dram]") +TEST_CASE( + "Construct singleton dram, write a line to an address in 0 cycles, read in " + "0 cycles", + "[dram]") { Dram *d = new Dram(1, 0); std::array<signed int, LINE_SIZE> expected = {0, 0, 0, 0}; @@ -374,7 +374,7 @@ TEST_CASE("Construct singleton dram, write a line to an address in 0 cycles, rea CHECK(expected == actual); signed int w = 0x11223311; - expected = {w, w+1, w+2, w+3}; + expected = {w, w + 1, w + 2, w + 3}; int addr = 0x00000000; d->write_line(MEM, expected, addr); @@ -397,7 +397,10 @@ TEST_CASE("Construct singleton dram, write a line to an address in 0 cycles, rea delete d; } -TEST_CASE("Construct singleton dram, write a line to an address in three cycles, read it in three cycles", "[dram]") +TEST_CASE( + "Construct singleton dram, write a line to an address in three cycles, " + "read it in three cycles", + "[dram]") { int delay = 3; Dram *d = new Dram(1, delay); @@ -406,13 +409,13 @@ TEST_CASE("Construct singleton dram, write a line to an address in three cycles, CHECK(expected == actual); signed int w = 0x11223311; - expected = {w, w+1, w+2, w+3}; + expected = {w, w + 1, w + 2, w + 3}; int addr = 0x00000000; - + int i; Response r; - - for(i=0; i<delay; ++i) { + + for (i = 0; i < delay; ++i) { r = d->write_line(MEM, expected, addr); d->resolve(); } @@ -434,7 +437,9 @@ TEST_CASE("Construct singleton dram, write a line to an address in three cycles, } TEST_CASE( - "Construct singleton dram, store line in 3 cycles, read line in 3 cycles with no conflict","[dram]") + "Construct singleton dram, store line in 3 cycles, read line in 3 cycles " + "with no conflict", + "[dram]") { int delay = 3; Dram *d = new Dram(1, delay); @@ -443,12 +448,12 @@ TEST_CASE( CHECK(expected == actual); signed int w = 0x11223311; - expected = {w, w+1, w+2, w+3}; + expected = {w, w + 1, w + 2, w + 3}; int addr = 0x00000000; - + int i; Response r; - for(int j=0; j<delay; ++j) { + for (int j = 0; j < delay; ++j) { r = d->write_line(MEM, expected, addr); d->resolve(); } @@ -465,11 +470,11 @@ TEST_CASE( r = d->read_line(MEM, 0x00000000, actual); REQUIRE(r == OK); r = d->read_line(FETCH, 0x00000003, actual); - CHECK(r == WAIT); + CHECK(r == WAIT); d->resolve(); REQUIRE(expected == actual); - actual = {0,0,0,0}; + actual = {0, 0, 0, 0}; for (i = 0; i < delay; ++i) { r = d->read_line(FETCH, 0x00000000, actual); CHECK(r == WAIT); @@ -483,13 +488,14 @@ TEST_CASE( CHECK(r == WAIT); d->resolve(); REQUIRE(expected == actual); - - delete d; + delete d; } TEST_CASE( - "Construct singleton dram, store line in 3 cycles, read line in 3 cycles with much conflict","[dram]") + "Construct singleton dram, store line in 3 cycles, read line in 3 cycles " + "with much conflict", + "[dram]") { int delay = 3; Dram *d = new Dram(1, delay); @@ -498,19 +504,18 @@ TEST_CASE( CHECK(expected == actual); signed int w = 0x11223311; - expected = {w, w+1, w+2, w+3}; + expected = {w, w + 1, w + 2, w + 3}; int addr = 0x00000000; - + int i; Response r; - for(int j=0; j<delay; ++j) { + for (int j = 0; j < delay; ++j) { r = d->write_line(MEM, expected, addr); d->resolve(); } r = d->write_line(MEM, expected, addr++); d->resolve(); - for (i = 0; i < delay; ++i) { r = d->read_line(MEM, 0x00000000, actual); CHECK(r == WAIT); @@ -524,11 +529,11 @@ TEST_CASE( r = d->read_line(MEM, 0x00000000, actual); REQUIRE(r == OK); r = d->read_line(FETCH, 0x00000003, actual); - CHECK(r == WAIT); + CHECK(r == WAIT); d->resolve(); REQUIRE(expected == actual); - actual = {0,0,0,0}; + actual = {0, 0, 0, 0}; for (i = 0; i < delay; ++i) { r = d->read_line(FETCH, 0x00000000, actual); CHECK(r == WAIT); @@ -545,13 +550,14 @@ TEST_CASE( CHECK(r == WAIT); d->resolve(); REQUIRE(expected == actual); - - delete d; + delete d; } - -TEST_CASE("Construct singleton dram, write a line to an address one element at a time, read it in zero cycles", "[dram]") +TEST_CASE( + "Construct singleton dram, write a line to an address one element at a " + "time, read it in zero cycles", + "[dram]") { Dram *d = new Dram(1, 0); std::array<signed int, LINE_SIZE> expected = {0, 0, 0, 0}; @@ -560,7 +566,7 @@ TEST_CASE("Construct singleton dram, write a line to an address one element at a signed int w = 0x11223311; int addr = 0x00000000; - for(int i=0; i<LINE_SIZE; ++i) { + for (int i = 0; i < LINE_SIZE; ++i) { Response r = d->write_word(MEM, w, addr++); CHECK(r == OK); expected.at(i) = w++; @@ -585,7 +591,10 @@ TEST_CASE("Construct singleton dram, write a line to an address one element at a delete d; } -TEST_CASE("Construct singleton dram, write a line to an address one element at a time in 12 cycles, read it in three cycles", "[dram]") +TEST_CASE( + "Construct singleton dram, write a line to an address one element at a " + "time in 12 cycles, read it in three cycles", + "[dram]") { int delay = 3; Dram *d = new Dram(1, delay); @@ -597,8 +606,8 @@ TEST_CASE("Construct singleton dram, write a line to an address one element at a int addr = 0x00000000; int i; Response r; - for(i=0; i<LINE_SIZE; ++i) { - for(int j=0; j<delay; ++j) { + for (i = 0; i < LINE_SIZE; ++i) { + for (int j = 0; j < delay; ++j) { r = d->write_word(MEM, w, addr); d->resolve(); } @@ -622,7 +631,9 @@ TEST_CASE("Construct singleton dram, write a line to an address one element at a } TEST_CASE( - "Construct singleton dram, store line one element at a time in 12 cycles, read line in 3 cycles with no conflict","[dram]") + "Construct singleton dram, store line one element at a time in 12 cycles, " + "read line in 3 cycles with no conflict", + "[dram]") { int delay = 3; Dram *d = new Dram(1, delay); @@ -634,8 +645,8 @@ TEST_CASE( int addr = 0x00000000; int i; Response r; - for(i=0; i<LINE_SIZE; ++i) { - for(int j=0; j<delay; ++j) { + for (i = 0; i < LINE_SIZE; ++i) { + for (int j = 0; j < delay; ++j) { r = d->write_word(MEM, w, addr); d->resolve(); } @@ -654,11 +665,11 @@ TEST_CASE( r = d->read_line(MEM, 0x00000000, actual); REQUIRE(r == OK); r = d->read_line(FETCH, 0x00000003, actual); - CHECK(r == WAIT); + CHECK(r == WAIT); d->resolve(); REQUIRE(expected == actual); - actual = {0,0,0,0}; + actual = {0, 0, 0, 0}; for (i = 0; i < delay; ++i) { r = d->read_line(FETCH, 0x00000000, actual); CHECK(r == WAIT); @@ -672,13 +683,14 @@ TEST_CASE( CHECK(r == WAIT); d->resolve(); REQUIRE(expected == actual); - - delete d; + delete d; } TEST_CASE( - "Construct singleton dram, store line one element at a time in 12 cycles, read line in 3 cycles with much conflict","[dram]") + "Construct singleton dram, store line one element at a time in 12 cycles, " + "read line in 3 cycles with much conflict", + "[dram]") { int delay = 3; Dram *d = new Dram(1, delay); @@ -690,8 +702,8 @@ TEST_CASE( int addr = 0x00000000; int i; Response r; - for(i=0; i<LINE_SIZE; ++i) { - for(int j=0; j<delay; ++j) { + for (i = 0; i < LINE_SIZE; ++i) { + for (int j = 0; j < delay; ++j) { r = d->write_word(MEM, w, addr); d->resolve(); } @@ -713,11 +725,11 @@ TEST_CASE( r = d->read_line(MEM, 0x00000000, actual); REQUIRE(r == OK); r = d->read_line(FETCH, 0x00000003, actual); - CHECK(r == WAIT); + CHECK(r == WAIT); d->resolve(); REQUIRE(expected == actual); - actual = {0,0,0,0}; + actual = {0, 0, 0, 0}; for (i = 0; i < delay; ++i) { r = d->read_line(FETCH, 0x00000000, actual); CHECK(r == WAIT); @@ -734,12 +746,10 @@ TEST_CASE( CHECK(r == WAIT); d->resolve(); REQUIRE(expected == actual); - - delete d; + delete d; } - TEST_CASE("Sidedoor bypasses delay", "[dram]") { int delay = 3; |