Browse Source

Added another couple of commands....

pull/100/head
philip 8 years ago
parent
commit
492371c218
  1. 8
      afltests/a
  2. 36
      src/test/test_bugreports.c
  3. 41
      src/test/test_spiffs.c
  4. 2
      src/test/test_spiffs.h

8
afltests/a

@ -1,12 +1,12 @@
b55 b55
O4W4R4C4 O4W4R4C4D4
b45 b45
d5rh d5rh
O4W4R4f4C4 O4W4R4f4C4
baa baaU
d5rh d5rh
OaWaRafaCa OaWaRafaCa
d5rh cd5rh
OaWaRafaCa OaWaRafaCa
O4S4W4R4C4 O4S4W4R4C4
d5rh d5rh

36
src/test/test_bugreports.c

@ -638,6 +638,7 @@ static int run_fuzz_test(FILE *f) {
buff[i] = i * 19; buff[i] = i * 19;
} }
while ((c = fgetc(f)) >= 0) { while ((c = fgetc(f)) >= 0) {
int add; int add;
char rbuff[2048]; char rbuff[2048];
@ -700,6 +701,12 @@ static int run_fuzz_test(FILE *f) {
} }
break; break;
case 'D':
if (fd[fdn] >= 0) {
SPIFFS_fremove(FS, fd[fdn]);
}
break;
case 'd': case 'd':
SPIFFS_remove(FS, filename[arg & 7]); SPIFFS_remove(FS, filename[arg & 7]);
break; break;
@ -707,6 +714,30 @@ static int run_fuzz_test(FILE *f) {
case 'r': case 'r':
SPIFFS_rename(FS, filename[arg & 7], filename[(arg >> 3) & 7]); SPIFFS_rename(FS, filename[arg & 7], filename[(arg >> 3) & 7]);
break; break;
case 'U':
ungetc(arg, f);
for (i = 0; i < 4; i++) {
fd[i] = -1;
}
{
char *tmpfile = strdup("/tmp/fsdump.XXXXXX");
close(mkstemp(tmpfile));
fs_store_dump(tmpfile);
fs_mount_dump(tmpfile, 0, 0, blocks * block_size, erase_size, block_size, page_size);
unlink(tmpfile);
free(tmpfile);
}
break;
case 'c':
SPIFFS_check(FS);
ungetc(arg, f);
break;
default:
ungetc(arg, f);
break;
} }
} }
@ -730,7 +761,10 @@ TEST(fuzzer_found_2) {
} TEST_END } TEST_END
TEST(afl_test) { TEST(afl_test) {
return run_fuzz_test(stdin); u32_t old_val = set_abort_on_error(1);
int rc = run_fuzz_test(stdin);
set_abort_on_error(old_val);
return rc;
} TEST_END } TEST_END
TEST(small_free_space) { TEST(small_free_space) {

41
src/test/test_spiffs.c

@ -27,12 +27,14 @@
#define AREA(x) _area[(x) - addr_offset] #define AREA(x) _area[(x) - addr_offset]
#define ERREXIT(i) abort() #define ERREXIT() if (abort_on_error) abort()
static u32_t _area_sz; static u32_t _area_sz;
static unsigned char *_area = NULL; static unsigned char *_area = NULL;
static u32_t addr_offset = 0; static u32_t addr_offset = 0;
static u32_t abort_on_error = 0;
static int *_erases; static int *_erases;
static char _path[256]; static char _path[256];
static u32_t bytes_rd = 0; static u32_t bytes_rd = 0;
@ -112,6 +114,14 @@ static int mkpath(const char *path, mode_t mode) {
} }
// end take // end take
//
u32_t set_abort_on_error(u32_t val) {
u32_t old_val = abort_on_error;
abort_on_error = val;
return old_val;
}
char *make_test_fname(const char *name) { char *make_test_fname(const char *name) {
sprintf(_path, "%s/%s", TEST_PATH, name); sprintf(_path, "%s/%s", TEST_PATH, name);
@ -155,11 +165,13 @@ static s32_t _read(spiffs *fs, u32_t addr, u32_t size, u8_t *dst) {
} }
if (addr < __fs.cfg.phys_addr) { if (addr < __fs.cfg.phys_addr) {
printf("FATAL read addr too low %08x < %08x\n", addr, __fs.cfg.phys_addr); printf("FATAL read addr too low %08x < %08x\n", addr, __fs.cfg.phys_addr);
ERREXIT(0); ERREXIT();
exit(0);
} }
if (addr + size > __fs.cfg.phys_addr + __fs.cfg.phys_size) { if (addr + size > __fs.cfg.phys_addr + __fs.cfg.phys_size) {
printf("FATAL read addr too high %08x + %08x > %08x\n", addr, size, __fs.cfg.phys_addr + __fs.cfg.phys_size); printf("FATAL read addr too high %08x + %08x > %08x\n", addr, size, __fs.cfg.phys_addr + __fs.cfg.phys_size);
ERREXIT(0); ERREXIT();
exit(0);
} }
memcpy(dst, &AREA(addr), size); memcpy(dst, &AREA(addr), size);
return 0; return 0;
@ -181,11 +193,13 @@ static s32_t _write(spiffs *fs, u32_t addr, u32_t size, u8_t *src) {
if (addr < __fs.cfg.phys_addr) { if (addr < __fs.cfg.phys_addr) {
printf("FATAL write addr too low %08x < %08x\n", addr, __fs.cfg.phys_addr); printf("FATAL write addr too low %08x < %08x\n", addr, __fs.cfg.phys_addr);
ERREXIT(0); ERREXIT();
exit(0);
} }
if (addr + size > __fs.cfg.phys_addr + __fs.cfg.phys_size) { if (addr + size > __fs.cfg.phys_addr + __fs.cfg.phys_size) {
printf("FATAL write addr too high %08x + %08x > %08x\n", addr, size, __fs.cfg.phys_addr + __fs.cfg.phys_size); printf("FATAL write addr too high %08x + %08x > %08x\n", addr, size, __fs.cfg.phys_addr + __fs.cfg.phys_size);
ERREXIT(0); ERREXIT();
exit(0);
} }
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
@ -194,7 +208,7 @@ static s32_t _write(spiffs *fs, u32_t addr, u32_t size, u8_t *src) {
printf("trying to write %02x to %02x at addr %08x\n", src[i], AREA(addr + i), addr+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; spiffs_page_ix pix = (addr + i) / LOG_PAGE;
dump_page(&__fs, pix); dump_page(&__fs, pix);
ERREXIT(0); ERREXIT();
return -1; return -1;
} }
} }
@ -205,12 +219,12 @@ static s32_t _write(spiffs *fs, u32_t addr, u32_t size, u8_t *src) {
static s32_t _erase(spiffs *fs, u32_t addr, u32_t size) { static s32_t _erase(spiffs *fs, u32_t addr, u32_t size) {
if (addr & (__fs.cfg.phys_erase_block-1)) { if (addr & (__fs.cfg.phys_erase_block-1)) {
printf("trying to erase at addr %08x, out of boundary\n", addr); printf("trying to erase at addr %08x, out of boundary\n", addr);
ERREXIT(0); ERREXIT();
return -1; return -1;
} }
if (size & (__fs.cfg.phys_erase_block-1)) { if (size & (__fs.cfg.phys_erase_block-1)) {
printf("trying to erase at with size %08x, out of boundary\n", size); printf("trying to erase at with size %08x, out of boundary\n", size);
ERREXIT(0); ERREXIT();
return -1; return -1;
} }
_erases[(addr-__fs.cfg.phys_addr)/__fs.cfg.phys_erase_block]++; _erases[(addr-__fs.cfg.phys_addr)/__fs.cfg.phys_erase_block]++;
@ -404,7 +418,8 @@ void fs_set_addr_offset(u32_t offset) {
void test_lock(spiffs *fs) { void test_lock(spiffs *fs) {
if (_fs_locks != 0) { if (_fs_locks != 0) {
printf("FATAL: reentrant locks. Abort.\n"); printf("FATAL: reentrant locks. Abort.\n");
ERREXIT(-1); ERREXIT();
exit(-1);
} }
_fs_locks++; _fs_locks++;
} }
@ -412,7 +427,8 @@ void test_lock(spiffs *fs) {
void test_unlock(spiffs *fs) { void test_unlock(spiffs *fs) {
if (_fs_locks != 1) { if (_fs_locks != 1) {
printf("FATAL: unlocking unlocked. Abort.\n"); printf("FATAL: unlocking unlocked. Abort.\n");
ERREXIT(-1); ERREXIT();
exit(-1);
} }
_fs_locks--; _fs_locks--;
} }
@ -891,7 +907,7 @@ void _teardown() {
SPIFFS_check(FS); SPIFFS_check(FS);
printf(" fs consistency check output end\n"); printf(" fs consistency check output end\n");
if (check_cb_count) { if (check_cb_count) {
//abort(); ERREXIT();
} }
} }
clear_test_path(); clear_test_path();
@ -899,7 +915,8 @@ void _teardown() {
printf(" locks : %i\n", _fs_locks); printf(" locks : %i\n", _fs_locks);
if (_fs_locks != 0) { if (_fs_locks != 0) {
printf("FATAL: lock asymmetry. Abort.\n"); printf("FATAL: lock asymmetry. Abort.\n");
ERREXIT(-1); ERREXIT();
exit(-1);
} }
} }

2
src/test/test_spiffs.h

@ -55,6 +55,8 @@ typedef struct {
char name[32]; char name[32];
} tfile; } tfile;
u32_t set_abort_on_error(u32_t val);
void fs_reset(); void fs_reset();
void fs_reset_specific(u32_t addr_offset, 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 phys_sector_size,

Loading…
Cancel
Save