test: allow for singleton testing

This commit is contained in:
Peter Andersson
2017-02-27 08:11:27 +01:00
parent 330fae3ff2
commit 1b7a1c9fea
3 changed files with 42 additions and 24 deletions
+10 -10
View File
@@ -30,7 +30,7 @@ TEST(info)
int res = SPIFFS_info(FS, &total, &used);
TEST_CHECK(res == SPIFFS_OK);
TEST_CHECK(used == 0);
TEST_CHECK(total < __fs.cfg.phys_size);
TEST_CHECK(total < SPIFFS_CFG_PHYS_SZ(&__fs));
return TEST_RES_OK;
}
TEST_END
@@ -869,7 +869,7 @@ TEST_END
TEST(write_big_file_chunks_page)
{
int size = ((50*(FS)->cfg.phys_size)/100);
int size = ((50*SPIFFS_CFG_PHYS_SZ(FS))/100);
printf(" filesize %i\n", size);
int res = test_create_and_write_file("bigfile", size, SPIFFS_DATA_PAGE_SIZE(FS));
TEST_CHECK(res >= 0);
@@ -887,7 +887,7 @@ TEST(write_big_files_chunks_page)
int f;
int files = 10;
int res;
int size = ((50*(FS)->cfg.phys_size)/100)/files;
int size = ((50*SPIFFS_CFG_PHYS_SZ(FS))/100)/files;
printf(" filesize %i\n", size);
for (f = 0; f < files; f++) {
sprintf(name, "bigfile%i", f);
@@ -907,7 +907,7 @@ TEST_END
TEST(write_big_file_chunks_index)
{
int size = ((50*(FS)->cfg.phys_size)/100);
int size = ((50*SPIFFS_CFG_PHYS_SZ(FS))/100);
printf(" filesize %i\n", size);
int res = test_create_and_write_file("bigfile", size, SPIFFS_DATA_PAGE_SIZE(FS) * SPIFFS_OBJ_HDR_IX_LEN(FS));
TEST_CHECK(res >= 0);
@@ -925,7 +925,7 @@ TEST(write_big_files_chunks_index)
int f;
int files = 10;
int res;
int size = ((50*(FS)->cfg.phys_size)/100)/files;
int size = ((50*SPIFFS_CFG_PHYS_SZ(FS))/100)/files;
printf(" filesize %i\n", size);
for (f = 0; f < files; f++) {
sprintf(name, "bigfile%i", f);
@@ -963,7 +963,7 @@ TEST(write_big_files_chunks_huge)
int f;
int files = 10;
int res;
int size = ((50*(FS)->cfg.phys_size)/100)/files;
int size = ((50*SPIFFS_CFG_PHYS_SZ(FS))/100)/files;
printf(" filesize %i\n", size);
for (f = 0; f < files; f++) {
sprintf(name, "bigfile%i", f);
@@ -1242,7 +1242,7 @@ TEST_END
TEST(read_chunk_huge)
{
int sz = (2*(FS)->cfg.phys_size)/3;
int sz = (2*SPIFFS_CFG_PHYS_SZ(FS))/3;
TEST_CHECK(create_and_read_back(sz, sz) == 0);
return TEST_RES_OK;
}
@@ -1636,7 +1636,7 @@ TEST(write_small_files_chunks_1)
char name[32];
int f;
int size = 512;
int files = ((20*(FS)->cfg.phys_size)/100)/size;
int files = ((20*SPIFFS_CFG_PHYS_SZ(FS))/100)/size;
int res;
for (f = 0; f < files; f++) {
sprintf(name, "smallfile%i", f);
@@ -1655,7 +1655,7 @@ TEST_END
TEST(write_big_file_chunks_1)
{
int size = ((50*(FS)->cfg.phys_size)/100);
int size = ((50*SPIFFS_CFG_PHYS_SZ(FS))/100);
printf(" filesize %i\n", size);
int res = test_create_and_write_file("bigfile", size, 1);
TEST_CHECK(res >= 0);
@@ -1672,7 +1672,7 @@ TEST(write_big_files_chunks_1)
int f;
int files = 10;
int res;
int size = ((50*(FS)->cfg.phys_size)/100)/files;
int size = ((50*SPIFFS_CFG_PHYS_SZ(FS))/100)/files;
printf(" filesize %i\n", size);
for (f = 0; f < files; f++) {
sprintf(name, "bigfile%i", f);
+31 -13
View File
@@ -139,7 +139,11 @@ void clear_test_path() {
}
}
static s32_t _read(spiffs *fs, u32_t addr, u32_t size, u8_t *dst) {
static s32_t _read(
#if SPIFFS_HAL_CALLBACK_EXTRA
spiffs *fs,
#endif
u32_t addr, u32_t size, u8_t *dst) {
//printf("rd @ addr %08x => %p\n", addr, &AREA(addr));
if (log_flash_ops) {
bytes_rd += size;
@@ -151,11 +155,11 @@ static s32_t _read(spiffs *fs, u32_t addr, u32_t size, u8_t *dst) {
return SPIFFS_ERR_TEST;
}
}
if (addr < __fs.cfg.phys_addr) {
if (addr < SPIFFS_CFG_PHYS_ADDR(&__fs)) {
printf("FATAL read addr too low %08x < %08x\n", addr, SPIFFS_PHYS_ADDR);
exit(0);
}
if (addr + size > __fs.cfg.phys_addr + __fs.cfg.phys_size) {
if (addr + size > SPIFFS_CFG_PHYS_ADDR(&__fs) + SPIFFS_CFG_PHYS_SZ(&__fs)) {
printf("FATAL read addr too high %08x + %08x > %08x\n", addr, size, SPIFFS_PHYS_ADDR + SPIFFS_FLASH_SIZE);
exit(0);
}
@@ -163,7 +167,11 @@ static s32_t _read(spiffs *fs, u32_t addr, u32_t size, u8_t *dst) {
return 0;
}
static s32_t _write(spiffs *fs, u32_t addr, u32_t size, u8_t *src) {
static s32_t _write(
#if SPIFFS_HAL_CALLBACK_EXTRA
spiffs *fs,
#endif
u32_t addr, u32_t size, u8_t *src) {
int i;
//printf("wr %08x %i\n", addr, size);
if (log_flash_ops) {
@@ -177,17 +185,17 @@ static s32_t _write(spiffs *fs, u32_t addr, u32_t size, u8_t *src) {
}
}
if (addr < __fs.cfg.phys_addr) {
if (addr < SPIFFS_CFG_PHYS_ADDR(&__fs)) {
printf("FATAL write addr too low %08x < %08x\n", addr, SPIFFS_PHYS_ADDR);
exit(0);
}
if (addr + size > __fs.cfg.phys_addr + __fs.cfg.phys_size) {
if (addr + size > SPIFFS_CFG_PHYS_ADDR(&__fs) + SPIFFS_CFG_PHYS_SZ(&__fs)) {
printf("FATAL write addr too high %08x + %08x > %08x\n", addr, size, SPIFFS_PHYS_ADDR + SPIFFS_FLASH_SIZE);
exit(0);
}
for (i = 0; i < size; i++) {
if (((addr + i) & (__fs.cfg.log_page_size-1)) != offsetof(spiffs_page_header, flags)) {
if (((addr + i) & (SPIFFS_CFG_LOG_PAGE_SZ(&__fs)-1)) != offsetof(spiffs_page_header, flags)) {
if (check_valid_flash && ((AREA(addr + i) ^ src[i]) & src[i])) {
printf("trying to write %02x to %02x at addr %08x\n", src[i], AREA(addr + i), addr+i);
spiffs_page_ix pix = (addr + i) / LOG_PAGE;
@@ -199,16 +207,20 @@ static s32_t _write(spiffs *fs, u32_t addr, u32_t size, u8_t *src) {
}
return 0;
}
static s32_t _erase(spiffs *fs, u32_t addr, u32_t size) {
if (addr & (__fs.cfg.phys_erase_block-1)) {
static s32_t _erase(
#if SPIFFS_HAL_CALLBACK_EXTRA
spiffs *fs,
#endif
u32_t addr, u32_t size) {
if (addr & (SPIFFS_CFG_PHYS_ERASE_SZ(&__fs)-1)) {
printf("trying to erase at addr %08x, out of boundary\n", addr);
return -1;
}
if (size & (__fs.cfg.phys_erase_block-1)) {
if (size & (SPIFFS_CFG_PHYS_ERASE_SZ(&__fs)-1)) {
printf("trying to erase at with size %08x, out of boundary\n", size);
return -1;
}
_erases[(addr-__fs.cfg.phys_addr)/__fs.cfg.phys_erase_block]++;
_erases[(addr-SPIFFS_CFG_PHYS_ADDR(&__fs))/SPIFFS_CFG_PHYS_ERASE_SZ(&__fs)]++;
memset(&AREA(addr), 0xff, size);
return 0;
}
@@ -291,7 +303,7 @@ void dump_page(spiffs *fs, spiffs_page_ix p) {
}
}
printf("\n");
u32_t len = fs->cfg.log_page_size;
u32_t len = SPIFFS_CFG_LOG_PAGE_SZ(fs);
hexdump(addr, len);
}
@@ -343,7 +355,11 @@ void dump_flash_access_stats() {
// static u32_t old_perc = 999;
static void spiffs_check_cb_f(spiffs *fs, spiffs_check_type type, spiffs_check_report report,
static void spiffs_check_cb_f(
#if SPIFFS_HAL_CALLBACK_EXTRA
spiffs *fs,
#endif
spiffs_check_type type, spiffs_check_report report,
u32_t arg1, u32_t arg2) {
/* if (report == SPIFFS_CHECK_PROGRESS && old_perc != arg1) {
old_perc = arg1;
@@ -417,11 +433,13 @@ s32_t fs_mount_specific(u32_t phys_addr, u32_t phys_size,
c.hal_erase_f = _erase;
c.hal_read_f = _read;
c.hal_write_f = _write;
#if SPIFFS_SINGLETON == 0
c.log_block_size = log_block_size;
c.log_page_size = log_page_size;
c.phys_addr = phys_addr;
c.phys_erase_block = phys_sector_size;
c.phys_size = phys_size;
#endif
#if SPIFFS_FILEHDL_OFFSET
c.fh_ix_offset = TEST_SPIFFS_FILEHDL_OFFSET;
#endif
+1 -1
View File
@@ -18,7 +18,7 @@ extern spiffs __fs;
#define CHECK(r) if (!(r)) return -1;
#define CHECK_RES(r) if (r < 0) return -1;
#define FS_PURE_DATA_PAGES(fs) \
((fs)->cfg.phys_size / (fs)->cfg.log_page_size - (fs)->block_count * SPIFFS_OBJ_LOOKUP_PAGES(fs))
(SPIFFS_CFG_PHYS_SZ(fs) / SPIFFS_CFG_LOG_PAGE_SZ(fs)- (fs)->block_count * SPIFFS_OBJ_LOOKUP_PAGES(fs))
#define FS_PURE_DATA_SIZE(fs) \
FS_PURE_DATA_PAGES(fs) * SPIFFS_DATA_PAGE_SIZE(fs)