Improve the Fake GPIO Class and started writing tests for the Write Function of the HAL

This commit is contained in:
Gustavo Henrique Santos Souza de Miranda 2026-06-05 02:03:40 -03:00
parent 4e4e25d005
commit 997fd7fb6e
2 changed files with 43 additions and 18 deletions

View File

@ -7,16 +7,37 @@
#include "GPIO.hpp" #include "GPIO.hpp"
struct FakeGpio { struct FakeGpio {
std::vector<std::string> log; std::vector<std::string> operations;
std::vector<uint8_t> bus_values;
std::vector<uint32_t> delays;
void set_data_bus(uint8_t val) { log.push_back("data " + std::to_string(val)); }
void set_a0(Port port) { log.push_back(port == Port::ADDRESS ? "a0 ADDR" : "a0 DATA"); } void set_data_bus(uint8_t val) {
void set_a1(Bank bank) { log.push_back(bank == Bank::BANK_0 ? "a1 B0" : "a1 B1"); } operations.push_back("data_bus");
void set_cs(State s) { log.push_back(s == State::ACTIVE ? "cs ON" : "cs OFF"); } bus_values.push_back(val);
void set_wr(State s) { log.push_back(s == State::ACTIVE ? "wr ON" : "wr OFF"); } }
void set_ic(State s) { log.push_back(s == State::ACTIVE ? "ic ON" : "ic OFF"); } void set_a0(Port port) {
void set_rd(State s) { log.push_back(s == State::ACTIVE ? "rd ON" : "rd OFF"); } operations.push_back(port == Port::ADDRESS ? "a0 ADDRESS" : "a0 DATA");
void delay_ticks(uint32_t n) { log.push_back("delay " + std::to_string(n)); } }
void set_a1(Bank bank) {
operations.push_back(bank == Bank::BANK_0 ? "a1 BANK_0" : "a1 BANK_1");
}
void set_cs(State s) {
operations.push_back(s == State::ACTIVE ? "cs ACTIVE" : "cs INACTIVE");
}
void set_wr(State s) {
operations.push_back(s == State::ACTIVE ? "wr ACTIVE" : "wr INACTIVE");
}
void set_ic(State s) {
operations.push_back(s == State::ACTIVE ? "ic ACTIVE" : "ic INACTIVE");
}
void set_rd(State s) {
operations.push_back(s == State::ACTIVE ? "rd ACTIVE" : "rd INACTIVE");
}
void delay_ticks(uint32_t n) {
operations.push_back("delay_ticks");
delays.push_back(n);
}
}; };
#endif #endif

View File

@ -2,18 +2,22 @@
#include "YMF262-HAL.hpp" #include "YMF262-HAL.hpp"
#include "FakeGPIO.hpp" #include "FakeGPIO.hpp"
TEST(YMF262Write, FazDoisCiclos) { class YMF262_HALWriteTest : public ::testing::Test {
protected:
FakeGpio fake; FakeGpio fake;
YMF262_HAL<FakeGpio> hal(fake, 14318000, 216000000); YMF262_HAL<FakeGpio> hal{fake, 14318000, 216000000};
// ^ fake e hal criados ANTES de cada teste, prontos pra usar
};
TEST_F(YMF262_HALWriteTest,TestForEmptyRun) {
hal.write(Bank::BANK_0, 0x40, 0x20); hal.write(Bank::BANK_0, 0x40, 0x20);
EXPECT_NE(fake.operations.size(),0);
EXPECT_NE(fake.bus_values.size(), 0);
EXPECT_NE(fake.delays.size(), 0);
// imprime o que foi registrado (pra você VER a coreografia) }
for (const auto& linha : fake.log) {
std::cout << linha << "\n";
}
// verificações básicas: o primeiro ciclo é endereço, o barramento recebeu 0x40 (64) TEST_F(YMF262_HALWriteTest, A0MudaEntreCiclos) {
EXPECT_EQ(fake.log.front(), "a0 ADDR"); // começou em modo endereço hal.write(Bank::BANK_0, 0x40, 0x20);
EXPECT_FALSE(fake.log.empty()); // anotou algo EXPECT_EQ(fake.operations.front(), "a0 ADDRESS");
} }