spiffs: add test case for readdir_r with large number of files

Ref. https://esp32.com/viewtopic.php?f=13&t=6486
This commit is contained in:
Ivan Grokhotkov 2018-07-23 15:34:18 +03:00 committed by bot
parent ecc82a3c27
commit f206bc51ff

View File

@ -275,6 +275,63 @@ void test_spiffs_opendir_readdir_rewinddir(const char* dir_prefix)
TEST_ASSERT_EQUAL(0, closedir(dir));
}
void test_spiffs_readdir_many_files(const char* dir_prefix)
{
const int n_files = 40;
const int n_folders = 4;
unsigned char file_count[n_files * n_folders];
memset(file_count, 0, sizeof(file_count)/sizeof(file_count[0]));
char file_name[ESP_VFS_PATH_MAX + CONFIG_SPIFFS_OBJ_NAME_LEN];
/* clean stale files before the test */
DIR* dir = opendir(dir_prefix);
if (dir) {
while (true) {
struct dirent* de = readdir(dir);
if (!de) {
break;
}
snprintf(file_name, sizeof(file_name), "%s/%s", dir_prefix, de->d_name);
unlink(file_name);
}
}
/* create files */
for (int d = 0; d < n_folders; ++d) {
printf("filling directory %d\n", d);
for (int f = 0; f < n_files; ++f) {
snprintf(file_name, sizeof(file_name), "%s/%d/%d.txt", dir_prefix, d, f);
test_spiffs_create_file_with_text(file_name, file_name);
}
}
/* list files */
for (int d = 0; d < n_folders; ++d) {
printf("listing files in directory %d\n", d);
snprintf(file_name, sizeof(file_name), "%s/%d", dir_prefix, d);
dir = opendir(file_name);
TEST_ASSERT_NOT_NULL(dir);
while (true) {
struct dirent* de = readdir(dir);
if (!de) {
break;
}
int file_id;
TEST_ASSERT_EQUAL(1, sscanf(de->d_name, "%d.txt", &file_id));
file_count[file_id + d * n_files]++;
}
closedir(dir);
}
/* check that all created files have been seen */
for (int d = 0; d < n_folders; ++d) {
printf("checking that all files have been found in directory %d\n", d);
for (int f = 0; f < n_files; ++f) {
TEST_ASSERT_EQUAL(1, file_count[f + d * n_files]);
}
}
}
typedef struct {
const char* filename;
@ -499,6 +556,13 @@ TEST_CASE("opendir, readdir, rewinddir, seekdir work as expected", "[spiffs]")
test_teardown();
}
TEST_CASE("readdir with large number of files", "[spiffs][timeout=15]")
{
test_setup();
test_spiffs_readdir_many_files("/spiffs/dir2");
test_teardown();
}
TEST_CASE("multiple tasks can use same volume", "[spiffs]")
{
test_setup();