mirror of
https://github.com/pellepl/spiffs.git
synced 2026-08-27 20:30:06 +00:00
Test framework update and some added tests
This commit is contained in:
+124
-9
@@ -27,7 +27,7 @@ void teardown() {
|
||||
}
|
||||
|
||||
TEST(nodemcu_full_fs_1) {
|
||||
fs_reset_specific(0, 4096*20, 4096, 4096, 256);
|
||||
fs_reset_specific(0, 0, 4096*20, 4096, 4096, 256);
|
||||
|
||||
int res;
|
||||
spiffs_file fd;
|
||||
@@ -86,7 +86,7 @@ TEST(nodemcu_full_fs_1) {
|
||||
} TEST_END(nodemcu_full_fs_1)
|
||||
|
||||
TEST(nodemcu_full_fs_2) {
|
||||
fs_reset_specific(0, 4096*22, 4096, 4096, 256);
|
||||
fs_reset_specific(0, 0, 4096*22, 4096, 4096, 256);
|
||||
|
||||
int res;
|
||||
spiffs_file fd;
|
||||
@@ -166,13 +166,13 @@ TEST(nodemcu_full_fs_2) {
|
||||
|
||||
TEST(magic_test) {
|
||||
// one obj lu page, not full
|
||||
fs_reset_specific(0, 4096*16, 4096, 4096*1, 128);
|
||||
fs_reset_specific(0, 0, 4096*16, 4096, 4096*1, 128);
|
||||
TEST_CHECK(SPIFFS_CHECK_MAGIC_POSSIBLE(FS));
|
||||
// one obj lu page, full
|
||||
fs_reset_specific(0, 4096*16, 4096, 4096*2, 128);
|
||||
fs_reset_specific(0, 0, 4096*16, 4096, 4096*2, 128);
|
||||
TEST_CHECK(!SPIFFS_CHECK_MAGIC_POSSIBLE(FS));
|
||||
// two obj lu pages, not full
|
||||
fs_reset_specific(0, 4096*16, 4096, 4096*4, 128);
|
||||
fs_reset_specific(0, 0, 4096*16, 4096, 4096*4, 128);
|
||||
TEST_CHECK(SPIFFS_CHECK_MAGIC_POSSIBLE(FS));
|
||||
|
||||
return TEST_RES_OK;
|
||||
@@ -180,7 +180,7 @@ TEST(magic_test) {
|
||||
} TEST_END(magic_test)
|
||||
|
||||
TEST(nodemcu_309) {
|
||||
fs_reset_specific(0, 4096*20, 4096, 4096, 256);
|
||||
fs_reset_specific(0, 0, 4096*20, 4096, 4096, 256);
|
||||
|
||||
int res;
|
||||
spiffs_file fd;
|
||||
@@ -194,10 +194,14 @@ TEST(nodemcu_309) {
|
||||
int i;
|
||||
spiffs_stat s;
|
||||
res = SPIFFS_OK;
|
||||
u8_t err = 0;
|
||||
for (i = 1; i <= 1280; i++) {
|
||||
char *buf = "0123456789ABCDE";
|
||||
char *buf = "0123456789ABCDE\n";
|
||||
res = SPIFFS_write(FS, fd, buf, strlen(buf));
|
||||
if (res < 0) printf("err @ %i,%i\n", i, j);
|
||||
if (!err && res < 0) {
|
||||
printf("err @ %i,%i\n", i, j);
|
||||
err = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,7 +213,7 @@ TEST(nodemcu_309) {
|
||||
|
||||
SPIFFS_info(FS, &total, &used);
|
||||
printf("total:%i\nused:%i\nremain:%i\nerrno:%i\n", total, used, total-used, errno);
|
||||
TEST_CHECK(total-used < 10000);
|
||||
TEST_CHECK(total-used < 11000);
|
||||
|
||||
spiffs_DIR d;
|
||||
struct spiffs_dirent e;
|
||||
@@ -228,4 +232,115 @@ TEST(nodemcu_309) {
|
||||
|
||||
} TEST_END(nodemcu_309)
|
||||
|
||||
|
||||
|
||||
TEST(robert) {
|
||||
// create a clean file system starting at address 0, 2 megabytes big,
|
||||
// sector size 65536, block size 65536, page size 256
|
||||
fs_reset_specific(0, 0, 1024*1024*2, 65536, 65536, 256);
|
||||
|
||||
int res;
|
||||
spiffs_file fd;
|
||||
int j;
|
||||
|
||||
// create three files
|
||||
for (j = 1; j <= 3; j++) {
|
||||
char fname[32];
|
||||
|
||||
sprintf(fname, "test%i.txt", j);
|
||||
fd = SPIFFS_open(FS, fname, SPIFFS_RDWR | SPIFFS_CREAT | SPIFFS_TRUNC, 0);
|
||||
TEST_CHECK(fd > 0);
|
||||
int i;
|
||||
res = SPIFFS_OK;
|
||||
for (i = 0; i <= 999; i++) {
|
||||
char *buf = "0123456789ABCDEF";
|
||||
res = SPIFFS_write(FS, fd, buf, 16);
|
||||
}
|
||||
SPIFFS_close(FS, fd);
|
||||
|
||||
spiffs_stat s;
|
||||
TEST_CHECK(SPIFFS_stat(FS, fname, &s) == SPIFFS_OK);
|
||||
printf("file %s stat size %i\n", s.name, s.size);
|
||||
}
|
||||
int errno = SPIFFS_errno(FS);
|
||||
TEST_CHECK(errno == SPIFFS_OK);
|
||||
|
||||
// unmount
|
||||
SPIFFS_unmount(FS);
|
||||
|
||||
// remount
|
||||
res = fs_mount_specific(0, 1024*1024*2, 65536, 65536, 256);
|
||||
TEST_CHECK(res== SPIFFS_OK);
|
||||
|
||||
|
||||
spiffs_DIR d;
|
||||
struct spiffs_dirent e;
|
||||
struct spiffs_dirent *pe = &e;
|
||||
|
||||
SPIFFS_opendir(FS, "/", &d);
|
||||
while ((pe = SPIFFS_readdir(&d, pe))) {
|
||||
printf("%s [%04x] size:%i\n", pe->name, pe->obj_id, pe->size);
|
||||
}
|
||||
SPIFFS_closedir(&d);
|
||||
|
||||
return TEST_RES_OK;
|
||||
|
||||
} TEST_END(robert)
|
||||
|
||||
|
||||
TEST(spiffs_12) {
|
||||
fs_reset_specific(0x4024c000, 0x4024c000 + 0, 192*1024, 4096, 4096*2, 256);
|
||||
|
||||
int res;
|
||||
spiffs_file fd;
|
||||
int j = 1;
|
||||
|
||||
while (1) {
|
||||
char fname[32];
|
||||
sprintf(fname, "file%i.txt", j);
|
||||
fd = SPIFFS_open(FS, fname, SPIFFS_RDWR | SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_DIRECT, 0);
|
||||
if (fd <=0) break;
|
||||
|
||||
int i;
|
||||
res = SPIFFS_OK;
|
||||
for (i = 1; i <= 100; i++) {
|
||||
char *buf = "0123456789ABCDE\n";
|
||||
res = SPIFFS_write(FS, fd, buf, strlen(buf));
|
||||
if (res < 0) break;
|
||||
}
|
||||
SPIFFS_close(FS, fd);
|
||||
j++;
|
||||
}
|
||||
|
||||
int errno = SPIFFS_errno(FS);
|
||||
TEST_CHECK(errno == SPIFFS_ERR_FULL);
|
||||
|
||||
u32_t total;
|
||||
u32_t used;
|
||||
|
||||
SPIFFS_info(FS, &total, &used);
|
||||
printf("total:%i (%iK)\nused:%i (%iK)\nremain:%i (%iK)\nerrno:%i\n", total, total/1024, used, used/1024, total-used, (total-used)/1024, errno);
|
||||
|
||||
spiffs_DIR d;
|
||||
struct spiffs_dirent e;
|
||||
struct spiffs_dirent *pe = &e;
|
||||
|
||||
SPIFFS_opendir(FS, "/", &d);
|
||||
while ((pe = SPIFFS_readdir(&d, pe))) {
|
||||
printf("%s [%04x] size:%i\n", pe->name, pe->obj_id, pe->size);
|
||||
}
|
||||
SPIFFS_closedir(&d);
|
||||
|
||||
//SPIFFS_vis(FS);
|
||||
|
||||
//dump_page(FS, 0);
|
||||
//dump_page(FS, 1);
|
||||
|
||||
return TEST_RES_OK;
|
||||
|
||||
} TEST_END(spiffs_12)
|
||||
|
||||
|
||||
|
||||
|
||||
SUITE_END(bug_tests)
|
||||
|
||||
@@ -592,7 +592,6 @@ TEST(simultaneous_write_append) {
|
||||
}
|
||||
TEST_END(simultaneous_write_append)
|
||||
|
||||
|
||||
TEST(file_uniqueness)
|
||||
{
|
||||
int res;
|
||||
|
||||
+26
-18
@@ -24,7 +24,10 @@
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define AREA(x) area[(x) - addr_offset]
|
||||
|
||||
static unsigned char area[PHYS_FLASH_SIZE];
|
||||
static u32_t addr_offset = 0;
|
||||
|
||||
static int erases[PHYS_FLASH_SIZE/SECTOR_SIZE];
|
||||
static char _path[256];
|
||||
@@ -88,7 +91,7 @@ static s32_t _read(u32_t addr, u32_t size, u8_t *dst) {
|
||||
printf("FATAL read addr too high %08x + %08x > %08x\n", addr, size, SPIFFS_PHYS_ADDR + SPIFFS_FLASH_SIZE);
|
||||
exit(0);
|
||||
}
|
||||
memcpy(dst, &area[addr], size);
|
||||
memcpy(dst, &AREA(addr), size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -117,14 +120,14 @@ static s32_t _write(u32_t addr, u32_t size, u8_t *src) {
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
if (((addr + i) & (__fs.cfg.log_page_size-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);
|
||||
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;
|
||||
dump_page(&__fs, pix);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
area[addr + i] &= src[i];
|
||||
AREA(addr + i) &= src[i];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -139,7 +142,7 @@ static s32_t _erase(u32_t addr, u32_t size) {
|
||||
return -1;
|
||||
}
|
||||
erases[(addr-__fs.cfg.phys_addr)/__fs.cfg.phys_erase_block]++;
|
||||
memset(&area[addr], 0xff, size);
|
||||
memset(&AREA(addr), 0xff, size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -165,7 +168,7 @@ void hexdump(u32_t addr, u32_t len) {
|
||||
if (a-32+j < addr)
|
||||
printf(" ");
|
||||
else {
|
||||
printf("%c", (area[a-32+j] < 32 || area[a-32+j] >= 0x7f) ? '.' : area[a-32+j]);
|
||||
printf("%c", (AREA(a-32+j) < 32 || AREA(a-32+j) >= 0x7f) ? '.' : AREA(a-32+j));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -174,7 +177,7 @@ void hexdump(u32_t addr, u32_t len) {
|
||||
if (a < addr) {
|
||||
printf(" ");
|
||||
} else {
|
||||
printf("%02x", area[a]);
|
||||
printf("%02x", AREA(a));
|
||||
}
|
||||
}
|
||||
int j;
|
||||
@@ -183,7 +186,7 @@ void hexdump(u32_t addr, u32_t len) {
|
||||
if (a-32+j < addr)
|
||||
printf(" ");
|
||||
else {
|
||||
printf("%c", (area[a-32+j] < 32 || area[a-32+j] >= 0x7f) ? '.' : area[a-32+j]);
|
||||
printf("%c", (AREA(a-32+j) < 32 || AREA(a-32+j) >= 0x7f) ? '.' : AREA(a-32+j));
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
@@ -198,9 +201,9 @@ void dump_page(spiffs *fs, spiffs_page_ix p) {
|
||||
} else {
|
||||
u32_t obj_id_addr = SPIFFS_BLOCK_TO_PADDR(fs, SPIFFS_BLOCK_FOR_PAGE(fs , p)) +
|
||||
SPIFFS_OBJ_LOOKUP_ENTRY_FOR_PAGE(fs, p) * sizeof(spiffs_obj_id);
|
||||
spiffs_obj_id obj_id = *((spiffs_obj_id *)&area[obj_id_addr]);
|
||||
spiffs_obj_id obj_id = *((spiffs_obj_id *)&AREA(obj_id_addr));
|
||||
// data page
|
||||
spiffs_page_header *ph = (spiffs_page_header *)&area[addr];
|
||||
spiffs_page_header *ph = (spiffs_page_header *)&AREA(addr);
|
||||
printf("DATA %04x:%04x ", obj_id, ph->span_ix);
|
||||
printf("%s", ((ph->flags & SPIFFS_PH_FLAG_FINAL) == 0) ? "FIN " : "fin ");
|
||||
printf("%s", ((ph->flags & SPIFFS_PH_FLAG_DELET) == 0) ? "DEL " : "del ");
|
||||
@@ -212,7 +215,7 @@ void dump_page(spiffs *fs, spiffs_page_ix p) {
|
||||
printf("OBJ_IX");
|
||||
if (ph->span_ix == 0) {
|
||||
printf("_HDR ");
|
||||
spiffs_page_object_ix_header *oix_hdr = (spiffs_page_object_ix_header *)&area[addr];
|
||||
spiffs_page_object_ix_header *oix_hdr = (spiffs_page_object_ix_header *)&AREA(addr);
|
||||
printf("'%s' %i bytes type:%02x", oix_hdr->name, oix_hdr->size, oix_hdr->type);
|
||||
}
|
||||
} else {
|
||||
@@ -228,14 +231,14 @@ void dump_page(spiffs *fs, spiffs_page_ix p) {
|
||||
void area_write(u32_t addr, u8_t *buf, u32_t size) {
|
||||
int i;
|
||||
for (i = 0; i < size; i++) {
|
||||
area[addr + i] = *buf++;
|
||||
AREA(addr + i) = *buf++;
|
||||
}
|
||||
}
|
||||
|
||||
void area_read(u32_t addr, u8_t *buf, u32_t size) {
|
||||
int i;
|
||||
for (i = 0; i < size; i++) {
|
||||
*buf++ = area[addr + i];
|
||||
*buf++ = AREA(addr + i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,6 +316,10 @@ static void spiffs_check_cb_f(spiffs_check_type type, spiffs_check_report report
|
||||
}
|
||||
}
|
||||
|
||||
void fs_set_addr_offset(u32_t offset) {
|
||||
addr_offset = offset;
|
||||
}
|
||||
|
||||
s32_t fs_mount_specific(u32_t phys_addr, u32_t phys_size,
|
||||
u32_t phys_sector_size,
|
||||
u32_t log_block_size, u32_t log_page_size) {
|
||||
@@ -329,11 +336,12 @@ s32_t fs_mount_specific(u32_t phys_addr, u32_t phys_size,
|
||||
return SPIFFS_mount(&__fs, &c, _work, _fds, sizeof(_fds), _cache, sizeof(_cache), spiffs_check_cb_f);
|
||||
}
|
||||
|
||||
void fs_reset_specific(u32_t phys_addr, u32_t phys_size,
|
||||
void fs_reset_specific(u32_t addr_offset, u32_t phys_addr, u32_t phys_size,
|
||||
u32_t phys_sector_size,
|
||||
u32_t log_block_size, u32_t log_page_size) {
|
||||
fs_set_addr_offset(addr_offset);
|
||||
memset(area, 0xcc, sizeof(area));
|
||||
memset(&area[phys_addr], 0xff, phys_size);
|
||||
memset(&AREA(phys_addr), 0xff, phys_size);
|
||||
memset(&__fs, 0, sizeof(__fs));
|
||||
|
||||
memset(erases,0,sizeof(erases));
|
||||
@@ -361,7 +369,7 @@ void fs_reset_specific(u32_t phys_addr, u32_t phys_size,
|
||||
}
|
||||
|
||||
void fs_reset() {
|
||||
fs_reset_specific(SPIFFS_PHYS_ADDR, SPIFFS_FLASH_SIZE, SECTOR_SIZE, LOG_BLOCK, LOG_PAGE);
|
||||
fs_reset_specific(0, SPIFFS_PHYS_ADDR, SPIFFS_FLASH_SIZE, SECTOR_SIZE, LOG_BLOCK, LOG_PAGE);
|
||||
}
|
||||
|
||||
void set_flash_ops_log(int enable) {
|
||||
@@ -609,8 +617,8 @@ void _teardown() {
|
||||
SPIFFS_check(FS);
|
||||
clear_test_path();
|
||||
|
||||
//hexdump_mem(&area[SPIFFS_PHYS_ADDR - 16], 32);
|
||||
//hexdump_mem(&area[SPIFFS_PHYS_ADDR + SPIFFS_FLASH_SIZE - 16], 32);
|
||||
//hexdump_mem(&AREA(SPIFFS_PHYS_ADDR - 16), 32);
|
||||
//hexdump_mem(&AREA(SPIFFS_PHYS_ADDR + SPIFFS_FLASH_SIZE - 16), 32);
|
||||
}
|
||||
|
||||
u32_t tfile_get_size(tfile_size s) {
|
||||
|
||||
@@ -57,12 +57,13 @@ typedef struct {
|
||||
|
||||
|
||||
void fs_reset();
|
||||
void fs_reset_specific(u32_t phys_addr, u32_t phys_size,
|
||||
void fs_reset_specific(u32_t addr_offset, u32_t phys_addr, u32_t phys_size,
|
||||
u32_t phys_sector_size,
|
||||
u32_t log_block_size, u32_t log_page_size);
|
||||
s32_t fs_mount_specific(u32_t phys_addr, u32_t phys_size,
|
||||
u32_t phys_sector_size,
|
||||
u32_t log_block_size, u32_t log_page_size);
|
||||
void fs_set_addr_offset(u32_t offset);
|
||||
int read_and_verify(char *name);
|
||||
int read_and_verify_fd(spiffs_file fd, char *name);
|
||||
void dump_page(spiffs *fs, spiffs_page_ix p);
|
||||
|
||||
Reference in New Issue
Block a user