diff options
Diffstat (limited to 'tests/id.cc')
-rw-r--r-- | tests/id.cc | 320 |
1 files changed, 160 insertions, 160 deletions
diff --git a/tests/id.cc b/tests/id.cc index 7d5e05d..77a7cd9 100644 --- a/tests/id.cc +++ b/tests/id.cc @@ -84,18 +84,18 @@ class IDFixture Controller *ct; }; -// TEST_CASE_METHOD(IDFixture, "Parse invalid type", "[id]") -// { -// signed int t; -// InstrDTO *i; +TEST_CASE_METHOD(IDFixture, "Parse invalid type", "[id]") +{ + signed int t; + InstrDTO *i; -// t = this->encode_R_type(0b0, 0b1, 0b10, 0b11, 0b11); -// i = this->decode_bits(t); + t = this->encode_R_type(0b0, 0b1, 0b10, 0b11, 0b11); + i = this->decode_bits(t); -// CHECK(i->get_mnemonic() == NOP); + CHECK(i->get_mnemonic() == NOP); -// delete i; -// } + delete i; +} TEST_CASE_METHOD(IDFixture, "Parse arbitrary r-type # one", "[id]") { @@ -113,164 +113,164 @@ TEST_CASE_METHOD(IDFixture, "Parse arbitrary r-type # one", "[id]") delete i; } -// TEST_CASE_METHOD(IDFixture, "Parse arbitrary r-type # two", "[id]") -// { -// signed int t; -// InstrDTO *i; +TEST_CASE_METHOD(IDFixture, "Parse arbitrary r-type # two", "[id]") +{ + signed int t; + InstrDTO *i; -// t = this->encode_R_type(0b10000, 0b01000, 0b00100, 0b10, 0b0); -// i = this->decode_bits(t); + t = this->encode_R_type(0b10000, 0b01000, 0b00100, 0b10, 0b0); + i = this->decode_bits(t); -// CHECK(i->get_s1() == 0x00000000); // registers are empty -// CHECK(i->get_s2() == 0x00000000); -// CHECK(i->get_s3() == 0x00000000); -// CHECK(i->get_mnemonic() == SUB); + CHECK(i->get_s1() == 0x00000000); // registers are empty + CHECK(i->get_s2() == 0x00000000); + CHECK(i->get_s3() == 0x00000000); + CHECK(i->get_mnemonic() == SUB); -// delete i; -// } + delete i; +} -// TEST_CASE_METHOD(IDFixture, "Parse arbitrary i-type # one", "[id]") -// { -// signed int t; -// InstrDTO *i; +TEST_CASE_METHOD(IDFixture, "Parse arbitrary i-type # one", "[id]") +{ + signed int t; + InstrDTO *i; -// t = this->encode_I_type(0xF, 0b1, 0b10, 0b0111, 0b1); -// i = this->decode_bits(t); + t = this->encode_I_type(0xF, 0b1, 0b10, 0b0111, 0b1); + i = this->decode_bits(t); -// CHECK(i->get_s1() == 0x00000000); // registers are empty -// CHECK(i->get_s2() == 0x00000000); -// CHECK(i->get_s3() == 0xF); -// CHECK(i->get_mnemonic() == SFTLI); + CHECK(i->get_s1() == 0x00000000); // registers are empty + CHECK(i->get_s2() == 0x00000000); + CHECK(i->get_s3() == 0xF); + CHECK(i->get_mnemonic() == SFTLI); -// delete i; -// } + delete i; +} -// TEST_CASE_METHOD(IDFixture, "Parse arbitrary i-type # two", "[id]") -// { -// signed int t; -// InstrDTO *i; +TEST_CASE_METHOD(IDFixture, "Parse arbitrary i-type # two", "[id]") +{ + signed int t; + InstrDTO *i; -// t = this->encode_I_type(0xCC, 0b010, 0b101, 0b1011, 0b1); -// i = this->decode_bits(t); + t = this->encode_I_type(0xCC, 0b010, 0b101, 0b1011, 0b1); + i = this->decode_bits(t); -// CHECK(i->get_s1() == 0x00000000); // registers are empty -// CHECK(i->get_s2() == 0x00000000); -// CHECK(i->get_s3() == 0xCC); -// CHECK(i->get_mnemonic() == STORE); - -// delete i; -// } - -// TEST_CASE_METHOD(IDFixture, "Parse arbitrary j-type # one", "[id]") -// { -// signed int t; -// InstrDTO *i; - -// t = this->encode_J_type(0x3456, 0b10101, 0b0111, 0b10); -// i = this->decode_bits(t); - -// CHECK(i->get_s1() == 0x00000000); // registers are empty -// CHECK(i->get_s2() == 0x3456); -// CHECK(i->get_mnemonic() == BOF); - -// delete i; -// } - -// TEST_CASE_METHOD(IDFixture, "Parse arbitrary j-type # two", "[id]") -// { -// signed int t; -// InstrDTO *i; - -// t = this->encode_J_type(0xBBCCF, 0b10101, 0b0011, 0b10); -// i = this->decode_bits(t); - -// CHECK(i->get_s1() == 0x00000000); // registers are empty -// CHECK(i->get_s2() == 0xBBCCF); -// CHECK(i->get_mnemonic() == JAL); - -// delete i; -// } - -// TEST_CASE_METHOD(IDFixture, "read does not conflict with read", "[id]") -// { -// signed int v; -// Response r; - -// v = 0b1; -// r = this->d->read_guard(v); -// CHECK(v == 0b0); -// REQUIRE(r == OK); - -// v = 0b1; -// this->d->read_guard(v); -// REQUIRE(v == 0b0); -// } - -// TEST_CASE_METHOD(IDFixture, "write does not conflict with write", "[id]") -// { -// signed int v; - -// v = 0b1; -// this->d->write_guard(v); -// REQUIRE(v == 0b0); - -// v = 0b1; -// this->d->write_guard(v); -// REQUIRE(v == 0b0); -// } - -// TEST_CASE_METHOD(IDFixture, "write does not conflict with read", "[id]") -// { -// signed int v; -// Response r; - -// v = 0b1; -// r = this->d->read_guard(v); -// CHECK(v == 0b0); -// REQUIRE(r == OK); - -// v = 0b1; -// this->d->write_guard(v); -// REQUIRE(v == 0b0); -// } - -// TEST_CASE_METHOD(IDFixture, "read does conflict with write", "[id]") -// { -// signed int v; -// Response r; - -// v = 0b1; -// this->d->write_guard(v); -// REQUIRE(v == 0b0); - -// v = 0b1; -// r = this->d->read_guard(v); -// CHECK(v == 0b01); -// REQUIRE(r == STALLED); -// } - -// TEST_CASE_METHOD(IDFixture, "stores indefinite conflicts", "[id]") -// { -// signed int v, ov; -// Response r; - -// v = 0b0; -// ov = v; -// while (v < 0b110) { -// this->d->write_guard(v); -// REQUIRE(v == 0b0); -// v = ++ov; -// } -// this->d->write_guard(v); -// REQUIRE(v == 0b0); - -// v = 0b110; -// r = this->d->read_guard(v); -// CHECK(v == 0b110); -// REQUIRE(r == STALLED); - -// v = 0b0; -// r = this->d->read_guard(v); -// CHECK(v == 0b0); -// REQUIRE(r == STALLED); -// } + CHECK(i->get_s1() == 0x00000000); // registers are empty + CHECK(i->get_s2() == 0x00000000); + CHECK(i->get_s3() == 0xCC); + CHECK(i->get_mnemonic() == STORE); + + delete i; +} + +TEST_CASE_METHOD(IDFixture, "Parse arbitrary j-type # one", "[id]") +{ + signed int t; + InstrDTO *i; + + t = this->encode_J_type(0x3456, 0b10101, 0b0111, 0b10); + i = this->decode_bits(t); + + CHECK(i->get_s1() == 0x00000000); // registers are empty + CHECK(i->get_s2() == 0x3456); + CHECK(i->get_mnemonic() == BOF); + + delete i; +} + +TEST_CASE_METHOD(IDFixture, "Parse arbitrary j-type # two", "[id]") +{ + signed int t; + InstrDTO *i; + + t = this->encode_J_type(0xBBCCF, 0b10101, 0b0011, 0b10); + i = this->decode_bits(t); + + CHECK(i->get_s1() == 0x00000000); // registers are empty + CHECK(i->get_s2() == 0xBBCCF); + CHECK(i->get_mnemonic() == JAL); + + delete i; +} + +TEST_CASE_METHOD(IDFixture, "read does not conflict with read", "[id]") +{ + signed int v; + Response r; + + v = 0b1; + r = this->d->read_guard(v); + CHECK(v == 0b0); + REQUIRE(r == OK); + + v = 0b1; + this->d->read_guard(v); + REQUIRE(v == 0b0); +} + +TEST_CASE_METHOD(IDFixture, "write does not conflict with write", "[id]") +{ + signed int v; + + v = 0b1; + this->d->write_guard(v); + REQUIRE(v == 0b0); + + v = 0b1; + this->d->write_guard(v); + REQUIRE(v == 0b0); +} + +TEST_CASE_METHOD(IDFixture, "write does not conflict with read", "[id]") +{ + signed int v; + Response r; + + v = 0b1; + r = this->d->read_guard(v); + CHECK(v == 0b0); + REQUIRE(r == OK); + + v = 0b1; + this->d->write_guard(v); + REQUIRE(v == 0b0); +} + +TEST_CASE_METHOD(IDFixture, "read does conflict with write", "[id]") +{ + signed int v; + Response r; + + v = 0b1; + this->d->write_guard(v); + REQUIRE(v == 0b0); + + v = 0b1; + r = this->d->read_guard(v); + CHECK(v == 0b01); + REQUIRE(r == STALLED); +} + +TEST_CASE_METHOD(IDFixture, "stores indefinite conflicts", "[id]") +{ + signed int v, ov; + Response r; + + v = 0b0; + ov = v; + while (v < 0b110) { + this->d->write_guard(v); + REQUIRE(v == 0b0); + v = ++ov; + } + this->d->write_guard(v); + REQUIRE(v == 0b0); + + v = 0b110; + r = this->d->read_guard(v); + CHECK(v == 0b110); + REQUIRE(r == STALLED); + + v = 0b0; + r = this->d->read_guard(v); + CHECK(v == 0b0); + REQUIRE(r == STALLED); +} |