worked on FileSystem, started to migrate logging class
This commit is contained in:
26
ext/sd/tests/Helper.h
Normal file
26
ext/sd/tests/Helper.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#define PLATFORM DESKTOP
|
||||
|
||||
#include "../Types.h"
|
||||
|
||||
struct TestDevice {
|
||||
|
||||
uint8_t buf[4096];
|
||||
|
||||
/** read a 512 byte block into dst */
|
||||
bool readSingleBlock(LBA512 addr, uint8_t* dst) {
|
||||
memcpy(dst, buf+addr*512, 512);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool writeSingleBlock(LBA512 addr, uint8_t* src) {
|
||||
memcpy(buf+addr*512, src, 512);
|
||||
return true;
|
||||
}
|
||||
|
||||
void reset(uint8_t val) {
|
||||
for (int i = 0; i < sizeof(buf); ++i) {buf[i] = val;}
|
||||
}
|
||||
|
||||
};
|
||||
78
ext/sd/tests/TestAccessHelper.cpp
Normal file
78
ext/sd/tests/TestAccessHelper.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "Helper.h"
|
||||
|
||||
#include "../AccessHelper.h"
|
||||
|
||||
|
||||
/*
|
||||
TEST (TestAccessHelper, read) {
|
||||
|
||||
// read varying numbers of bytes at arbitrary locations
|
||||
|
||||
TestDevice dev;
|
||||
AccessHelper<TestDevice> ah(dev);
|
||||
for (size_t i = 0; i < sizeof(dev.buf); ++i) {dev.buf[i] = i;}
|
||||
|
||||
uint8_t dst[32];
|
||||
|
||||
for (int bytesToRead = 1; bytesToRead < 1100; bytesToRead+=5) {
|
||||
for (int startAddr = 0; startAddr < 1100; startAddr+=3) {
|
||||
|
||||
const uint32_t read = ah.read(startAddr, bytesToRead, dst);
|
||||
|
||||
// ensure correct response
|
||||
ASSERT_EQ(bytesToRead, read);
|
||||
|
||||
// ensure correct contents
|
||||
for (int j = 0; j < bytesToRead; ++j) {
|
||||
ASSERT_EQ((uint8_t)(startAddr+j), dst[j]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
TEST (TestAccessHelper, write) {
|
||||
|
||||
// write varying numbers of bytes at arbitrary locations
|
||||
|
||||
const uint8_t MAGIC = 0xFF;
|
||||
TestDevice dev;
|
||||
AccessHelper<TestDevice> ah(dev);
|
||||
|
||||
// src data
|
||||
uint8_t src[2048];
|
||||
for (uint32_t i = 0; i < 2048; ++i) {src[i] = i;}
|
||||
|
||||
// try several write sizes and start addresses
|
||||
for (uint32_t bytesToWrite = 255; bytesToWrite < 1100; bytesToWrite+=5) {
|
||||
for (uint32_t startAddr = 0; startAddr < 1100; startAddr+=3) {
|
||||
|
||||
dev.reset(MAGIC);
|
||||
|
||||
const uint32_t written = ah.write(startAddr, bytesToWrite, src);
|
||||
|
||||
// ensure correct response
|
||||
ASSERT_EQ(bytesToWrite, written);
|
||||
|
||||
// check content
|
||||
for (uint32_t i = 0; i < sizeof(dev.buf); ++i) {
|
||||
if (i < startAddr || i >= startAddr + bytesToWrite) {
|
||||
ASSERT_EQ(MAGIC, dev.buf[i]);
|
||||
} else {
|
||||
const uint8_t expected = (i - startAddr);
|
||||
ASSERT_EQ(expected, dev.buf[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user