forked from nodemcu/nodemcu-firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix bugs for spiffs from pellepl/spiffs
- Loading branch information
Showing
15 changed files
with
3,301 additions
and
8 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
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,7 @@ | ||
#include "testrunner.h" | ||
#include <stdlib.h> | ||
|
||
int main(int argc, char **args) { | ||
run_tests(argc, args); | ||
exit(EXIT_SUCCESS); | ||
} |
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,36 @@ | ||
/* | ||
* params_test.h | ||
* | ||
* Created on: May 26, 2013 | ||
* Author: petera | ||
*/ | ||
|
||
#ifndef PARAMS_TEST_H_ | ||
#define PARAMS_TEST_H_ | ||
|
||
// total emulated spi flash size | ||
#define PHYS_FLASH_SIZE (16*1024*1024) | ||
// spiffs file system size | ||
#define SPIFFS_FLASH_SIZE (2*1024*1024) | ||
// spiffs file system offset in emulated spi flash | ||
#define SPIFFS_PHYS_ADDR (4*1024*1024) | ||
|
||
#define SECTOR_SIZE 65536 | ||
#define LOG_BLOCK (SECTOR_SIZE*2) | ||
#define LOG_PAGE (SECTOR_SIZE/256) | ||
|
||
#define FD_BUF_SIZE 64*6 | ||
#define CACHE_BUF_SIZE (LOG_PAGE + 32)*8 | ||
|
||
#define ASSERT(c, m) real_assert((c),(m), __FILE__, __LINE__); | ||
|
||
typedef signed int s32_t; | ||
typedef unsigned int u32_t; | ||
typedef signed short s16_t; | ||
typedef unsigned short u16_t; | ||
typedef signed char s8_t; | ||
typedef unsigned char u8_t; | ||
|
||
void real_assert(int c, const char *n, const char *file, int l); | ||
|
||
#endif /* PARAMS_TEST_H_ */ |
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,160 @@ | ||
/* | ||
* test_bugreports.c | ||
* | ||
* Created on: Mar 8, 2015 | ||
* Author: petera | ||
*/ | ||
|
||
|
||
|
||
#include "testrunner.h" | ||
#include "test_spiffs.h" | ||
#include "spiffs_nucleus.h" | ||
#include "spiffs.h" | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
#include <dirent.h> | ||
#include <unistd.h> | ||
|
||
|
||
SUITE(bug_tests) | ||
void setup() { | ||
_setup_test_only(); | ||
} | ||
void teardown() { | ||
_teardown(); | ||
} | ||
|
||
TEST(nodemcu_full_fs_1) { | ||
fs_reset_specific(0, 4096*20, 4096, 4096, 256); | ||
|
||
int res; | ||
spiffs_file fd; | ||
|
||
printf(" fill up system by writing one byte a lot\n"); | ||
fd = SPIFFS_open(FS, "test1.txt", SPIFFS_RDWR | SPIFFS_CREAT | SPIFFS_TRUNC, 0); | ||
TEST_CHECK(fd > 0); | ||
int i; | ||
spiffs_stat s; | ||
res = SPIFFS_OK; | ||
for (i = 0; i < 100*1000; i++) { | ||
u8_t buf = 'x'; | ||
res = SPIFFS_write(FS, fd, &buf, 1); | ||
} | ||
|
||
int errno = SPIFFS_errno(FS); | ||
int res2 = SPIFFS_fstat(FS, fd, &s); | ||
TEST_CHECK(res2 == SPIFFS_OK); | ||
printf(" >>> file %s size: %i\n", s.name, s.size); | ||
|
||
TEST_CHECK(errno == SPIFFS_ERR_FULL); | ||
SPIFFS_close(FS, fd); | ||
|
||
printf(" remove big file\n"); | ||
res = SPIFFS_remove(FS, "test1.txt"); | ||
|
||
printf("res:%i errno:%i\n",res, SPIFFS_errno(FS)); | ||
|
||
TEST_CHECK(res == SPIFFS_OK); | ||
res2 = SPIFFS_fstat(FS, fd, &s); | ||
TEST_CHECK(res2 == -1); | ||
TEST_CHECK(SPIFFS_errno(FS) == SPIFFS_ERR_FILE_CLOSED); | ||
res2 = SPIFFS_stat(FS, "test1.txt", &s); | ||
TEST_CHECK(res2 == -1); | ||
TEST_CHECK(SPIFFS_errno(FS) == SPIFFS_ERR_NOT_FOUND); | ||
|
||
printf(" create small file\n"); | ||
fd = SPIFFS_open(FS, "test2.txt", SPIFFS_RDWR | SPIFFS_CREAT | SPIFFS_TRUNC, 0); | ||
TEST_CHECK(fd > 0); | ||
res = SPIFFS_OK; | ||
for (i = 0; res >= 0 && i < 1000; i++) { | ||
u8_t buf = 'x'; | ||
res = SPIFFS_write(FS, fd, &buf, 1); | ||
} | ||
TEST_CHECK(res >= SPIFFS_OK); | ||
|
||
res2 = SPIFFS_fstat(FS, fd, &s); | ||
TEST_CHECK(res2 == SPIFFS_OK); | ||
printf(" >>> file %s size: %i\n", s.name, s.size); | ||
|
||
TEST_CHECK(s.size == 1000); | ||
SPIFFS_close(FS, fd); | ||
|
||
return TEST_RES_OK; | ||
|
||
} TEST_END(nodemcu_full_fs_1) | ||
|
||
TEST(nodemcu_full_fs_2) { | ||
fs_reset_specific(0, 4096*22, 4096, 4096, 256); | ||
|
||
int res; | ||
spiffs_file fd; | ||
|
||
printf(" fill up system by writing one byte a lot\n"); | ||
fd = SPIFFS_open(FS, "test1.txt", SPIFFS_RDWR | SPIFFS_CREAT | SPIFFS_TRUNC, 0); | ||
TEST_CHECK(fd > 0); | ||
int i; | ||
spiffs_stat s; | ||
res = SPIFFS_OK; | ||
for (i = 0; i < 100*1000; i++) { | ||
u8_t buf = 'x'; | ||
res = SPIFFS_write(FS, fd, &buf, 1); | ||
} | ||
|
||
int errno = SPIFFS_errno(FS); | ||
int res2 = SPIFFS_fstat(FS, fd, &s); | ||
TEST_CHECK(res2 == SPIFFS_OK); | ||
printf(" >>> file %s size: %i\n", s.name, s.size); | ||
|
||
TEST_CHECK(errno == SPIFFS_ERR_FULL); | ||
SPIFFS_close(FS, fd); | ||
|
||
res2 = SPIFFS_stat(FS, "test1.txt", &s); | ||
TEST_CHECK(res2 == SPIFFS_OK); | ||
|
||
SPIFFS_clearerr(FS); | ||
printf(" create small file\n"); | ||
fd = SPIFFS_open(FS, "test2.txt", SPIFFS_RDWR | SPIFFS_CREAT | SPIFFS_TRUNC, 0); | ||
TEST_CHECK(SPIFFS_errno(FS) == SPIFFS_OK); | ||
TEST_CHECK(fd > 0); | ||
|
||
for (i = 0; i < 1000; i++) { | ||
u8_t buf = 'x'; | ||
res = SPIFFS_write(FS, fd, &buf, 1); | ||
} | ||
|
||
TEST_CHECK(SPIFFS_errno(FS) == SPIFFS_ERR_FULL); | ||
res2 = SPIFFS_fstat(FS, fd, &s); | ||
TEST_CHECK(res2 == SPIFFS_OK); | ||
printf(" >>> file %s size: %i\n", s.name, s.size); | ||
TEST_CHECK(s.size == 0); | ||
SPIFFS_clearerr(FS); | ||
|
||
printf(" remove files\n"); | ||
res = SPIFFS_remove(FS, "test1.txt"); | ||
TEST_CHECK(res == SPIFFS_OK); | ||
res = SPIFFS_remove(FS, "test2.txt"); | ||
TEST_CHECK(res == SPIFFS_OK); | ||
|
||
printf(" create medium file\n"); | ||
fd = SPIFFS_open(FS, "test3.txt", SPIFFS_RDWR | SPIFFS_CREAT | SPIFFS_TRUNC, 0); | ||
TEST_CHECK(SPIFFS_errno(FS) == SPIFFS_OK); | ||
TEST_CHECK(fd > 0); | ||
|
||
for (i = 0; i < 20*1000; i++) { | ||
u8_t buf = 'x'; | ||
res = SPIFFS_write(FS, fd, &buf, 1); | ||
} | ||
TEST_CHECK(SPIFFS_errno(FS) == SPIFFS_OK); | ||
|
||
res2 = SPIFFS_fstat(FS, fd, &s); | ||
TEST_CHECK(res2 == SPIFFS_OK); | ||
printf(" >>> file %s size: %i\n", s.name, s.size); | ||
TEST_CHECK(s.size == 20*1000); | ||
|
||
return TEST_RES_OK; | ||
|
||
} TEST_END(nodemcu_full_fs_2) | ||
|
||
SUITE_END(bug_tests) |
Oops, something went wrong.