-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c933cc
commit c359114
Showing
12 changed files
with
1,356 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
// --------------------------------------------------------------------------- | ||
// USB EPROM/Flash Programmer | ||
// | ||
// Copyright (2024) Robson Martins | ||
// | ||
// This work is licensed under a Creative Commons Attribution-NonCommercial- | ||
// ShareAlike 4.0 International License. | ||
// --------------------------------------------------------------------------- | ||
/** | ||
* @ingroup UnitTests | ||
* @file test/backend/chip_test.cpp | ||
* @brief Implementation of Unit Test for Device (Chip) Classes. | ||
* | ||
* @author Robson Martins (https://www.robsonmartins.com) | ||
*/ | ||
// --------------------------------------------------------------------------- | ||
|
||
#include <QByteArray> | ||
#include <QObject> | ||
#include <cmath> | ||
|
||
#include "chip_test.hpp" | ||
|
||
#include "emulator/emulator.hpp" | ||
#include "emulator/sram.hpp" | ||
#include "emulator/eprom.hpp" | ||
|
||
#include "../../backend/devices/parallel/sram.hpp" | ||
#include "../../backend/devices/parallel/eprom.hpp" | ||
|
||
// --------------------------------------------------------------------------- | ||
|
||
/* GTest macro to print to console */ | ||
#define GTEST_COUT std::cerr << "[ ] ChipTest current: " | ||
|
||
// --------------------------------------------------------------------------- | ||
// private functions | ||
|
||
/* Run the chip tests. | ||
@param emuChip Pointer to Chip Emulator object. | ||
@param device Pointer to Device object to test. | ||
@param size Size of the device, in bytes. | ||
*/ | ||
void runChipTests(BaseChip *emuChip, Device *device, uint32_t size); | ||
|
||
// --------------------------------------------------------------------------- | ||
|
||
TEST_F(ChipTest, sram_test) { | ||
ChipSRAM *emuChip = new ChipSRAM(); | ||
Emulator::setChip(emuChip); | ||
SRAM *device = new SRAM(); | ||
runChipTests(emuChip, device, 2048); | ||
runChipTests(emuChip, device, 8192); | ||
delete device; | ||
delete emuChip; | ||
} | ||
|
||
TEST_F(ChipTest, eprom27_test) { | ||
ChipEPROM *emuChip = new ChipEPROM(); | ||
Emulator::setChip(emuChip); | ||
M27xxx *device = new M27xxx(); | ||
runChipTests(emuChip, device, 2048); | ||
runChipTests(emuChip, device, 8192); | ||
delete emuChip; | ||
delete device; | ||
} | ||
|
||
TEST_F(ChipTest, eprom27C_test) { | ||
ChipEPROM *emuChip = new ChipEPROM(); | ||
Emulator::setChip(emuChip); | ||
M27Cxxx *device = new M27Cxxx(); | ||
runChipTests(emuChip, device, 2048); | ||
runChipTests(emuChip, device, 8192); | ||
delete emuChip; | ||
delete device; | ||
} | ||
|
||
TEST_F(ChipTest, eprom27C16Bit_test) { | ||
ChipEPROM *emuChip = new ChipEPROM(); | ||
Emulator::setChip(emuChip); | ||
M27C16Bit *device = new M27C16Bit(); | ||
runChipTests(emuChip, device, 2048); | ||
runChipTests(emuChip, device, 8192); | ||
delete emuChip; | ||
delete device; | ||
} | ||
|
||
TEST_F(ChipTest, epromW27E_test) { | ||
ChipEPROM *emuChip = new ChipEPROM(); | ||
Emulator::setChip(emuChip); | ||
W27Exxx *device = new W27Exxx(); | ||
runChipTests(emuChip, device, 2048); | ||
runChipTests(emuChip, device, 8192); | ||
delete emuChip; | ||
delete device; | ||
} | ||
|
||
// --------------------------------------------------------------------------- | ||
|
||
void runChipTests(BaseChip *emuChip, Device *device, uint32_t size) { | ||
QByteArray buffer; | ||
device->setPort("COM1"); | ||
emuChip->setSize(size); | ||
device->setSize(size); | ||
Emulator::randomizeBuffer(buffer, size); | ||
|
||
TDeviceCapabilities cap = device->getInfo().capability; | ||
|
||
if (cap.hasBlankCheck) { | ||
GTEST_COUT << "Blank Check" << std::endl; | ||
EXPECT_EQ(device->blankCheck(), true); | ||
} | ||
if (cap.hasProgram) { | ||
GTEST_COUT << "Program" << std::endl; | ||
EXPECT_EQ(device->program(buffer), true); | ||
if (cap.hasVerify) { | ||
GTEST_COUT << "Verify" << std::endl; | ||
EXPECT_EQ(device->verify(buffer), true); | ||
} | ||
} | ||
if (cap.hasProgram && cap.hasVerify) { | ||
GTEST_COUT << "Program and Verify" << std::endl; | ||
EXPECT_EQ(device->program(buffer, true), true); | ||
} | ||
if (cap.hasProgram && cap.hasBlankCheck) { | ||
GTEST_COUT << "Blank Check" << std::endl; | ||
EXPECT_EQ(device->blankCheck(), false); | ||
} | ||
if (cap.hasProgram && cap.hasVerify) { | ||
buffer[buffer.size() - 1] = ~buffer[buffer.size() - 1]; | ||
GTEST_COUT << "Verify" << std::endl; | ||
EXPECT_EQ(device->verify(buffer), false); | ||
} | ||
if (cap.hasErase) { | ||
GTEST_COUT << "Erase" << std::endl; | ||
EXPECT_EQ(device->erase(), true); | ||
if (cap.hasBlankCheck) { | ||
GTEST_COUT << "Blank Check" << std::endl; | ||
EXPECT_EQ(device->blankCheck(), true); | ||
} | ||
if (cap.hasVerify) { | ||
buffer[buffer.size() - 1] = ~buffer[buffer.size() - 1]; | ||
GTEST_COUT << "Verify" << std::endl; | ||
EXPECT_EQ(device->verify(buffer), false); | ||
} | ||
if (cap.hasProgram) { | ||
GTEST_COUT << "Program" << std::endl; | ||
EXPECT_EQ(device->program(buffer), true); | ||
} | ||
if (cap.hasBlankCheck) { | ||
GTEST_COUT << "Erase and Blank Check" << std::endl; | ||
EXPECT_EQ(device->erase(true), true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// --------------------------------------------------------------------------- | ||
// USB EPROM/Flash Programmer | ||
// | ||
// Copyright (2024) Robson Martins | ||
// | ||
// This work is licensed under a Creative Commons Attribution-NonCommercial- | ||
// ShareAlike 4.0 International License. | ||
// --------------------------------------------------------------------------- | ||
/** | ||
* @ingroup UnitTests | ||
* @file test/backend/chip_test.hpp | ||
* @brief Header of Unit Test for Device (Chip) Classes. | ||
* | ||
* @author Robson Martins (https://www.robsonmartins.com) | ||
*/ | ||
// --------------------------------------------------------------------------- | ||
|
||
#ifndef TEST_BACKEND_CHIP_TEST_HPP_ | ||
#define TEST_BACKEND_CHIP_TEST_HPP_ | ||
|
||
#include <gtest/gtest.h> | ||
|
||
// --------------------------------------------------------------------------- | ||
|
||
/** | ||
* @ingroup UnitTests | ||
* @brief Test class for Device (Chip) Classes. | ||
* @details The purpose of this class is to test the Device (Chip) Classes. | ||
* @nosubgrouping | ||
*/ | ||
class ChipTest : public testing::Test { | ||
protected: | ||
/** @brief Constructor. */ | ||
ChipTest() {} | ||
/** @brief Destructor. */ | ||
~ChipTest() override {} | ||
/** @brief Sets Up the test. */ | ||
void SetUp() override {} | ||
/** @brief Teardown of the test. */ | ||
void TearDown() override {} | ||
}; | ||
|
||
#endif // TEST_BACKEND_CHIP_TEST_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
// --------------------------------------------------------------------------- | ||
// USB EPROM/Flash Programmer | ||
// | ||
// Copyright (2024) Robson Martins | ||
// | ||
// This work is licensed under a Creative Commons Attribution-NonCommercial- | ||
// ShareAlike 4.0 International License. | ||
// --------------------------------------------------------------------------- | ||
/** | ||
* @ingroup UnitTests | ||
* @file test/emulator/chip.cpp | ||
* @brief Implementation of Chip Emulation Base Classes. | ||
* | ||
* @author Robson Martins (https://www.robsonmartins.com) | ||
*/ | ||
// --------------------------------------------------------------------------- | ||
|
||
#include <QRandomGenerator> | ||
#include "chip.hpp" | ||
|
||
// --------------------------------------------------------------------------- | ||
|
||
BaseChip::BaseChip() | ||
: f_vdd(false), f_vpp(false), f_addr_bus(0), f_data_bus(0) {} | ||
|
||
BaseChip::BaseChip(const BaseChip& src) | ||
: f_vdd(src.f_vdd), | ||
f_vpp(src.f_vpp), | ||
f_addr_bus(src.f_addr_bus), | ||
f_data_bus(src.f_data_bus) { | ||
f_memory_area = src.f_memory_area; | ||
} | ||
|
||
BaseChip& BaseChip::operator=(const BaseChip& src) { | ||
f_vdd = src.f_vdd; | ||
f_vpp = src.f_vpp; | ||
f_addr_bus = src.f_addr_bus; | ||
f_data_bus = src.f_data_bus; | ||
f_memory_area = src.f_memory_area; | ||
return *this; | ||
} | ||
|
||
BaseChip::~BaseChip() {} | ||
|
||
void BaseChip::setSize(uint32_t size) { | ||
if (size == f_memory_area.size()) return; | ||
/* sets the chip size */ | ||
f_memory_area.resize(size); | ||
} | ||
|
||
void BaseChip::setVDD(bool state) { | ||
if (state == f_vdd) return; | ||
f_vdd = state; | ||
emuChip(); | ||
} | ||
|
||
void BaseChip::setVPP(bool state) { | ||
if (state == f_vpp) return; | ||
f_vpp = state; | ||
emuChip(); | ||
} | ||
|
||
void BaseChip::randomizeData(void) { | ||
/* fills memory area with random data */ | ||
for (int i = 0; i < f_memory_area.size(); ++i) { | ||
f_memory_area[i] = | ||
static_cast<uint16_t>(QRandomGenerator::global()->generate()); | ||
} | ||
} | ||
|
||
void BaseChip::fillData(uint16_t data) { | ||
/* fills memory area with specified data */ | ||
std::fill(f_memory_area.begin(), f_memory_area.end(), data); | ||
} | ||
|
||
void BaseChip::read(void) { | ||
/* checks the params */ | ||
if (f_addr_bus >= f_memory_area.size()) { | ||
f_data_bus = 0xFFFF; | ||
return; | ||
} | ||
static uint32_t last_addr = f_addr_bus; | ||
uint16_t data = f_memory_area[f_addr_bus]; | ||
if (f_data_bus == data && f_addr_bus == last_addr) return; | ||
/* returns the data from memory area */ | ||
f_data_bus = data; | ||
/* update last_addr */ | ||
last_addr = f_addr_bus; | ||
} | ||
|
||
void BaseChip::write(void) { | ||
/* checks the params */ | ||
if (f_addr_bus >= f_memory_area.size()) return; | ||
/* writes the data to memory area */ | ||
f_memory_area[f_addr_bus] = f_data_bus; | ||
} | ||
|
||
// --------------------------------------------------------------------------- | ||
|
||
BaseParChip::BaseParChip() | ||
: BaseChip(), f_oe(false), f_ce(false), f_we(false) {} | ||
|
||
BaseParChip::~BaseParChip() {} | ||
|
||
void BaseParChip::setOE(bool state) { | ||
if (state == f_oe) return; | ||
f_oe = state; | ||
emuChip(); | ||
} | ||
|
||
void BaseParChip::setCE(bool state) { | ||
if (state == f_ce) return; | ||
f_ce = state; | ||
emuChip(); | ||
} | ||
|
||
void BaseParChip::setWE(bool state) { | ||
if (state == f_we) return; | ||
f_we = state; | ||
emuChip(); | ||
} | ||
|
||
void BaseParChip::setAddrBus(uint32_t addr) { | ||
/* calculates the valid address (into memory area) */ | ||
uint32_t addr_new = (addr & (f_memory_area.size() - 1)); | ||
if (f_addr_bus == addr_new) return; | ||
/* set addr bus */ | ||
f_addr_bus = addr_new; | ||
} | ||
|
||
void BaseParChip::setDataBus(uint16_t data) { | ||
if (f_data_bus == data) return; | ||
/* changes the data bus */ | ||
f_data_bus = data; | ||
/* writes data */ | ||
emuChip(); | ||
} | ||
|
||
uint16_t BaseParChip::getDataBus(void) { | ||
/* reads data */ | ||
emuChip(); | ||
/* returns the data bus */ | ||
return f_data_bus; | ||
} |
Oops, something went wrong.