From db158de830e4fd4ab20ef5d357e24147c7a9281d Mon Sep 17 00:00:00 2001 From: bd Date: Wed, 5 Mar 2025 14:17:45 -0500 Subject: constructors + method declarations for cache, dram, reponse, storage --- tests/cache.cc | 8 +++++++ tests/dram.cc | 8 +++++++ tests/logger.cc | 72 ++++++++++++++++++++++++++++----------------------------- 3 files changed, 52 insertions(+), 36 deletions(-) create mode 100644 tests/cache.cc create mode 100644 tests/dram.cc (limited to 'tests') diff --git a/tests/cache.cc b/tests/cache.cc new file mode 100644 index 0000000..df5004a --- /dev/null +++ b/tests/cache.cc @@ -0,0 +1,8 @@ +#include "cache.h" +#include + +TEST_CASE("Constructor initialize test 1", "[cache]") +{ + Cache *c = new Cache(1, nullptr, 4); + delete c; +} diff --git a/tests/dram.cc b/tests/dram.cc new file mode 100644 index 0000000..1bde0fd --- /dev/null +++ b/tests/dram.cc @@ -0,0 +1,8 @@ +#include "dram.h" +#include + +TEST_CASE("Constructor initialize test 1", "[dram]") +{ + Dram *d = new Dram(1, 4); + delete d; +} diff --git a/tests/logger.cc b/tests/logger.cc index 18e4fab..e2f72a5 100644 --- a/tests/logger.cc +++ b/tests/logger.cc @@ -4,62 +4,62 @@ #include #include -TEST_CASE("Logger logs higher log level") +TEST_CASE("Logger logs higher log level", "[logger]") { - std::streambuf *coutBuffer = std::cout.rdbuf(); - std::ostringstream oss; - std::cout.rdbuf(oss.rdbuf()); + std::streambuf *coutBuffer = std::cout.rdbuf(); + std::ostringstream oss; + std::cout.rdbuf(oss.rdbuf()); - Logger logger(""); - logger.setLevel(INFO); + Logger logger(""); + logger.setLevel(INFO); - logger.log(ERROR, "foo bar baz qux"); + logger.log(ERROR, "foo bar baz qux"); - std::cout.rdbuf(coutBuffer); + std::cout.rdbuf(coutBuffer); - std::string actual = oss.str(); - std::regex expected( - "\\[\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\] ERROR: " - "foo bar baz qux\\n"); + std::string actual = oss.str(); + std::regex expected( + "\\[\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\] ERROR: " + "foo bar baz qux\\n"); - REQUIRE(std::regex_match(actual, expected)); + REQUIRE(std::regex_match(actual, expected)); } -TEST_CASE("Logger logs equal log level") +TEST_CASE("Logger logs equal log level", "[logger]") { - std::streambuf *coutBuffer = std::cout.rdbuf(); - std::ostringstream oss; - std::cout.rdbuf(oss.rdbuf()); + std::streambuf *coutBuffer = std::cout.rdbuf(); + std::ostringstream oss; + std::cout.rdbuf(oss.rdbuf()); - Logger logger(""); - logger.setLevel(INFO); + Logger logger(""); + logger.setLevel(INFO); - logger.log(INFO, "foo bar baz qux"); + logger.log(INFO, "foo bar baz qux"); - std::cout.rdbuf(coutBuffer); + std::cout.rdbuf(coutBuffer); - std::string actual = oss.str(); - std::regex expected("\\[\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\] INFO: " - "foo bar baz qux\\n"); + std::string actual = oss.str(); + std::regex expected("\\[\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\] INFO: " + "foo bar baz qux\\n"); - REQUIRE(std::regex_match(actual, expected)); + REQUIRE(std::regex_match(actual, expected)); } -TEST_CASE("Logger ignores lower log level") +TEST_CASE("Logger ignores lower log level", "[logger]") { - std::streambuf *coutBuffer = std::cout.rdbuf(); - std::ostringstream oss; - std::cout.rdbuf(oss.rdbuf()); + std::streambuf *coutBuffer = std::cout.rdbuf(); + std::ostringstream oss; + std::cout.rdbuf(oss.rdbuf()); - Logger logger(""); - logger.setLevel(INFO); + Logger logger(""); + logger.setLevel(INFO); - logger.log(DEBUG, "foo bar baz qux"); + logger.log(DEBUG, "foo bar baz qux"); - std::cout.rdbuf(coutBuffer); + std::cout.rdbuf(coutBuffer); - std::string actual = oss.str(); - std::string expected(""); + std::string actual = oss.str(); + std::string expected(""); - REQUIRE(actual == expected); + REQUIRE(actual == expected); } -- cgit v1.2.3 From e296a3a6ab782cb80b7091324b41bb78db6d3906 Mon Sep 17 00:00:00 2001 From: bd Date: Wed, 5 Mar 2025 14:20:15 -0500 Subject: whitespace --- inc/cache.h | 28 +++++++++--------- inc/dram.h | 24 +++++++-------- inc/logger.h | 46 ++++++++++++++-------------- inc/response.h | 12 ++++---- inc/storage.h | 84 ++++++++++++++++++++++++++-------------------------- src/storage/cache.cc | 12 ++++---- src/storage/dram.cc | 10 +++---- tests/cache.cc | 4 +-- tests/dram.cc | 4 +-- tests/logger.cc | 66 ++++++++++++++++++++--------------------- 10 files changed, 145 insertions(+), 145 deletions(-) (limited to 'tests') diff --git a/inc/cache.h b/inc/cache.h index e808727..101cd6e 100644 --- a/inc/cache.h +++ b/inc/cache.h @@ -5,21 +5,21 @@ class Cache : public Storage { public: - /** - * Constructor. - * @param The number of `lines` contained in memory. The total number of - * words is this number multiplied by 4. - * @param The next lowest level in storage. Methods from this object are - * called in case of a cache miss. - * @param The number of clock cycles each access takes. - * @return A new cache object. - */ - Cache(int lines, Storage *lower, int delay); - ~Cache(); + /** + * Constructor. + * @param The number of `lines` contained in memory. The total number of + * words is this number multiplied by 4. + * @param The next lowest level in storage. Methods from this object are + * called in case of a cache miss. + * @param The number of clock cycles each access takes. + * @return A new cache object. + */ + Cache(int lines, Storage *lower, int delay); + ~Cache(); - Response *write(Accessor accessor, signed int data, int address) override; - Response *read(Accessor accessor, int address) override; - int **view(int base, int lines) override; + Response *write(Accessor accessor, signed int data, int address) override; + Response *read(Accessor accessor, int address) override; + int **view(int base, int lines) override; }; #endif /* CACHE_H_INCLUDED */ diff --git a/inc/dram.h b/inc/dram.h index c8782d1..41dd7de 100644 --- a/inc/dram.h +++ b/inc/dram.h @@ -5,19 +5,19 @@ class Dram : public Storage { public: - /** - * Constructor. - * @param The number of `lines` contained in memory. The total number of - * words is this number multiplied by 4. - * @param The number of clock cycles each access takes. - * @return A new memory object. - */ - Dram(int lines, int delay); - ~Dram(); + /** + * Constructor. + * @param The number of `lines` contained in memory. The total number of + * words is this number multiplied by 4. + * @param The number of clock cycles each access takes. + * @return A new memory object. + */ + Dram(int lines, int delay); + ~Dram(); - Response *write(Accessor accessor, signed int data, int address) override; - Response *read(Accessor accessor, int address) override; - int **view(int base, int lines) override; + Response *write(Accessor accessor, signed int data, int address) override; + Response *read(Accessor accessor, int address) override; + int **view(int base, int lines) override; }; #endif /* DRAM_H_INCLUDED */ diff --git a/inc/logger.h b/inc/logger.h index 005e518..7ab3051 100644 --- a/inc/logger.h +++ b/inc/logger.h @@ -9,32 +9,32 @@ enum LogLevel { DEBUG, INFO, WARNING, ERROR, CRITICAL }; class Logger { public: - /** - * Constructor. - * @param The file name to log to. - * @return A new logger object. - */ - Logger(const string &); - ~Logger(); + /** + * Constructor. + * @param The file name to log to. + * @return A new logger object. + */ + Logger(const string &); + ~Logger(); - /** - * Set the log level. - * @param the log level to set to. - */ - void setLevel(LogLevel); - /** - * Log a message at a certain log level. - * @param The level to log this message. If the level is lower than the - * level set by `setLevel`, then the message is not logged. - * @param The message to log. - */ - void log(LogLevel, const string &); + /** + * Set the log level. + * @param the log level to set to. + */ + void setLevel(LogLevel); + /** + * Log a message at a certain log level. + * @param The level to log this message. If the level is lower than the + * level set by `setLevel`, then the message is not logged. + * @param The message to log. + */ + void log(LogLevel, const string &); private: - LogLevel level = INFO; - ofstream logFile; - string levelToString(LogLevel); - int levelToInt(LogLevel); + LogLevel level = INFO; + ofstream logFile; + string levelToString(LogLevel); + int levelToInt(LogLevel); }; #endif /* LOGGER_H_INCLUDED */ diff --git a/inc/response.h b/inc/response.h index d190953..c8141fd 100644 --- a/inc/response.h +++ b/inc/response.h @@ -2,15 +2,15 @@ #define RESPONSE_H enum Status { - OK, - WAIT, - BLOCKED, + OK, + WAIT, + BLOCKED, }; struct Response { - Status status; - int *line; - int val; + Status status; + int *line; + int val; }; #endif /* RESPONSE_H_INCLUDED */ diff --git a/inc/storage.h b/inc/storage.h index bad9d10..1e512e2 100644 --- a/inc/storage.h +++ b/inc/storage.h @@ -5,55 +5,55 @@ #include enum Accessor { - MEMORY, - FETCH, - L1CACHE, + MEMORY, + FETCH, + L1CACHE, }; class Storage { public: - /** - * Write `data` into `address`. - * @param the source making the request. - * @param the data (hexadecimal) to write. - * @param the address to write to. - * @return a status code reflecting the state of the storage level. - */ - virtual Response * - write(Accessor accessor, signed int data, int address) = 0; - /** - * Get the data at `address`. - * @param the source making the request. - * @param the address being accessed. - * @return a status code reflecting the state of the storage level, and the - * data being returned. - */ - virtual Response *read(Accessor accessor, int address) = 0; - /** - * Sidedoor view of `lines` of memory starting at `base`. - * @param The base line to start getting memory from. - * @param The amount of lines to fetch. - * @return A matrix of data values, where each row is a line and each column - * is a word. - */ - virtual int **view(int base, int lines) = 0; + /** + * Write `data` into `address`. + * @param the source making the request. + * @param the data (hexadecimal) to write. + * @param the address to write to. + * @return a status code reflecting the state of the storage level. + */ + virtual Response * + write(Accessor accessor, signed int data, int address) = 0; + /** + * Get the data at `address`. + * @param the source making the request. + * @param the address being accessed. + * @return a status code reflecting the state of the storage level, and the + * data being returned. + */ + virtual Response *read(Accessor accessor, int address) = 0; + /** + * Sidedoor view of `lines` of memory starting at `base`. + * @param The base line to start getting memory from. + * @param The amount of lines to fetch. + * @return A matrix of data values, where each row is a line and each column + * is a word. + */ + virtual int **view(int base, int lines) = 0; protected: - /** - * The data currently stored in this level of storage. - */ - std::vector> *data; - /** - * A pointer to the next lowest level of storage. - * Used in case of cache misses. - */ - Storage *lower; - /** - * The number of clock cycles this level of storage takes to complete - * requests. - */ - int delay; + /** + * The data currently stored in this level of storage. + */ + std::vector> *data; + /** + * A pointer to the next lowest level of storage. + * Used in case of cache misses. + */ + Storage *lower; + /** + * The number of clock cycles this level of storage takes to complete + * requests. + */ + int delay; }; #endif /* STORAGE_H_INCLUDED */ diff --git a/src/storage/cache.cc b/src/storage/cache.cc index efcaa32..34bdc5f 100644 --- a/src/storage/cache.cc +++ b/src/storage/cache.cc @@ -2,18 +2,18 @@ Cache::Cache(int lines, Storage *lower, int delay) { - this->data = new std::vector>; - this->data->resize(lines); - this->lower = lower; - this->delay = delay; - this->lower = nullptr; + this->data = new std::vector>; + this->data->resize(lines); + this->lower = lower; + this->delay = delay; + this->lower = nullptr; } Cache::~Cache() { delete this->data; } Response *Cache::write(Accessor accessor, signed int data, int address) { - return new Response(); + return new Response(); } Response *Cache::read(Accessor accessor, int address) { return nullptr; } diff --git a/src/storage/dram.cc b/src/storage/dram.cc index b3b728d..20858cd 100644 --- a/src/storage/dram.cc +++ b/src/storage/dram.cc @@ -3,17 +3,17 @@ Dram::Dram(int lines, int delay) { - this->data = new std::vector>; - this->data->resize(lines); - this->delay = delay; - this->lower = nullptr; + this->data = new std::vector>; + this->data->resize(lines); + this->delay = delay; + this->lower = nullptr; } Dram::~Dram() { delete this->data; } Response *Dram::write(Accessor accessor, signed int data, int address) { - return new Response(); + return new Response(); } Response *Dram::read(Accessor accessor, int address) { return nullptr; } diff --git a/tests/cache.cc b/tests/cache.cc index df5004a..6580563 100644 --- a/tests/cache.cc +++ b/tests/cache.cc @@ -3,6 +3,6 @@ TEST_CASE("Constructor initialize test 1", "[cache]") { - Cache *c = new Cache(1, nullptr, 4); - delete c; + Cache *c = new Cache(1, nullptr, 4); + delete c; } diff --git a/tests/dram.cc b/tests/dram.cc index 1bde0fd..21182f8 100644 --- a/tests/dram.cc +++ b/tests/dram.cc @@ -3,6 +3,6 @@ TEST_CASE("Constructor initialize test 1", "[dram]") { - Dram *d = new Dram(1, 4); - delete d; + Dram *d = new Dram(1, 4); + delete d; } diff --git a/tests/logger.cc b/tests/logger.cc index e2f72a5..711dd0e 100644 --- a/tests/logger.cc +++ b/tests/logger.cc @@ -6,60 +6,60 @@ TEST_CASE("Logger logs higher log level", "[logger]") { - std::streambuf *coutBuffer = std::cout.rdbuf(); - std::ostringstream oss; - std::cout.rdbuf(oss.rdbuf()); + std::streambuf *coutBuffer = std::cout.rdbuf(); + std::ostringstream oss; + std::cout.rdbuf(oss.rdbuf()); - Logger logger(""); - logger.setLevel(INFO); + Logger logger(""); + logger.setLevel(INFO); - logger.log(ERROR, "foo bar baz qux"); + logger.log(ERROR, "foo bar baz qux"); - std::cout.rdbuf(coutBuffer); + std::cout.rdbuf(coutBuffer); - std::string actual = oss.str(); - std::regex expected( - "\\[\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\] ERROR: " - "foo bar baz qux\\n"); + std::string actual = oss.str(); + std::regex expected( + "\\[\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\] ERROR: " + "foo bar baz qux\\n"); - REQUIRE(std::regex_match(actual, expected)); + REQUIRE(std::regex_match(actual, expected)); } TEST_CASE("Logger logs equal log level", "[logger]") { - std::streambuf *coutBuffer = std::cout.rdbuf(); - std::ostringstream oss; - std::cout.rdbuf(oss.rdbuf()); + std::streambuf *coutBuffer = std::cout.rdbuf(); + std::ostringstream oss; + std::cout.rdbuf(oss.rdbuf()); - Logger logger(""); - logger.setLevel(INFO); + Logger logger(""); + logger.setLevel(INFO); - logger.log(INFO, "foo bar baz qux"); + logger.log(INFO, "foo bar baz qux"); - std::cout.rdbuf(coutBuffer); + std::cout.rdbuf(coutBuffer); - std::string actual = oss.str(); - std::regex expected("\\[\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\] INFO: " - "foo bar baz qux\\n"); + std::string actual = oss.str(); + std::regex expected("\\[\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\] INFO: " + "foo bar baz qux\\n"); - REQUIRE(std::regex_match(actual, expected)); + REQUIRE(std::regex_match(actual, expected)); } TEST_CASE("Logger ignores lower log level", "[logger]") { - std::streambuf *coutBuffer = std::cout.rdbuf(); - std::ostringstream oss; - std::cout.rdbuf(oss.rdbuf()); + std::streambuf *coutBuffer = std::cout.rdbuf(); + std::ostringstream oss; + std::cout.rdbuf(oss.rdbuf()); - Logger logger(""); - logger.setLevel(INFO); + Logger logger(""); + logger.setLevel(INFO); - logger.log(DEBUG, "foo bar baz qux"); + logger.log(DEBUG, "foo bar baz qux"); - std::cout.rdbuf(coutBuffer); + std::cout.rdbuf(coutBuffer); - std::string actual = oss.str(); - std::string expected(""); + std::string actual = oss.str(); + std::string expected(""); - REQUIRE(actual == expected); + REQUIRE(actual == expected); } -- cgit v1.2.3