feat(storage/vfs): Remove old API usage

This commit is contained in:
Tomáš Rohlínek
2025-12-17 14:00:22 +01:00
parent 44d224c041
commit 1bf8b030e3
21 changed files with 154 additions and 123 deletions
+12 -16
View File
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -60,13 +60,12 @@ TEST_CASE("FDs from different VFSs don't collide", "[vfs]")
.fd = 1,
};
esp_vfs_t desc = {
.flags = ESP_VFS_FLAG_CONTEXT_PTR,
esp_vfs_fs_ops_t desc = {
.open_p = collision_test_vfs_open,
.close_p = collision_test_vfs_close,
};
TEST_ESP_OK( esp_vfs_register(VFS_PREF1, &desc, &param) );
TEST_ESP_OK( esp_vfs_register(VFS_PREF2, &desc, &param) );
TEST_ESP_OK( esp_vfs_register_fs(VFS_PREF1, &desc, ESP_VFS_FLAG_CONTEXT_PTR, &param) );
TEST_ESP_OK( esp_vfs_register_fs(VFS_PREF2, &desc, ESP_VFS_FLAG_CONTEXT_PTR, &param) );
const int fd1 = open(VFS_PREF1 FILE1, 0, 0);
const int fd2 = open(VFS_PREF2 FILE1, 0, 0);
@@ -155,13 +154,12 @@ static void concurrent_task(void *param)
TEST_CASE("VFS can handle concurrent open/close requests", "[vfs]")
{
esp_vfs_t desc = {
.flags = ESP_VFS_FLAG_DEFAULT,
esp_vfs_fs_ops_t desc = {
.open = concurrent_test_vfs_open,
.close = concurrent_test_vfs_close,
};
TEST_ESP_OK( esp_vfs_register(VFS_PREF1, &desc, NULL) );
TEST_ESP_OK( esp_vfs_register_fs(VFS_PREF1, &desc, ESP_VFS_FLAG_DEFAULT, NULL) );
concurrent_test_task_param_t param1 = { .path = VFS_PREF1 FILE1, .done = xSemaphoreCreateBinary() };
concurrent_test_task_param_t param2 = { .path = VFS_PREF1 FILE1, .done = xSemaphoreCreateBinary() };
@@ -233,14 +231,13 @@ static int time_test_vfs_write(int fd, const void *data, size_t size)
TEST_CASE("Open & write & close through VFS passes performance test", "[vfs]")
{
esp_vfs_t desc = {
.flags = ESP_VFS_FLAG_DEFAULT,
esp_vfs_fs_ops_t desc = {
.open = time_test_vfs_open,
.close = time_test_vfs_close,
.write = time_test_vfs_write,
};
TEST_ESP_OK( esp_vfs_register(VFS_PREF1, &desc, NULL) );
TEST_ESP_OK( esp_vfs_register_fs(VFS_PREF1, &desc, ESP_VFS_FLAG_DEFAULT, NULL) );
ccomp_timer_start();
const int iter_count = 5000;
@@ -278,17 +275,16 @@ static int vfs_overlap_test_close(int fd)
TEST_CASE("esp_vfs_register_fd_range checks for overlap", "[vfs]")
{
esp_vfs_t vfs1 = {
esp_vfs_fs_ops_t vfs1 = {
.open = vfs_overlap_test_open,
.close = vfs_overlap_test_close
};
TEST_ESP_OK(esp_vfs_register("/test", &vfs1, NULL));
TEST_ESP_OK(esp_vfs_register_fs("/test", &vfs1, ESP_VFS_FLAG_DEFAULT, NULL));
int fd = open("/test/1", 0, 0);
TEST_ASSERT_NOT_EQUAL(-1, fd);
esp_vfs_t vfs2 = { };
esp_err_t err = esp_vfs_register_fd_range(&vfs2, NULL, fd, fd + 1);
esp_vfs_fs_ops_t vfs2 = { };
esp_err_t err = esp_vfs_register_fd_range(&vfs2, ESP_VFS_FLAG_DEFAULT, NULL, fd, fd + 1);
close(fd);
TEST_ESP_OK(esp_vfs_unregister("/test"));
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -9,6 +9,7 @@
#include <fcntl.h>
#include <errno.h>
#include "esp_vfs.h"
#include "esp_vfs_ops.h"
#include "unity.h"
static int open_errno_test_open(const char * path, int flags, int mode)
@@ -19,10 +20,10 @@ static int open_errno_test_open(const char * path, int flags, int mode)
TEST_CASE("esp_vfs_open sets correct errno", "[vfs]")
{
esp_vfs_t desc = {
const esp_vfs_fs_ops_t desc = {
.open = open_errno_test_open
};
TEST_ESP_OK(esp_vfs_register("/test", &desc, NULL));
TEST_ESP_OK(esp_vfs_register_fs("/test", &desc, ESP_VFS_FLAG_DEFAULT, NULL));
int fd = open("/test/path", 0, 0);
int e = errno;
+23 -26
View File
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -12,6 +12,7 @@
#include <sys/fcntl.h>
#include <dirent.h>
#include "esp_vfs.h"
#include "esp_vfs_ops.h"
#include "unity.h"
#include "esp_log.h"
@@ -68,13 +69,16 @@ static int dummy_closedir(void* ctx, DIR* pdir)
/* Initializer for this dummy VFS implementation
*/
#define DUMMY_VFS() { \
.flags = ESP_VFS_FLAG_CONTEXT_PTR, \
.open_p = dummy_open, \
.close_p = dummy_close, \
.opendir_p = dummy_opendir, \
.closedir_p = dummy_closedir \
}
static const esp_vfs_dir_ops_t s_dummy_vfs_dir = {
.opendir_p = dummy_opendir,
.closedir_p = dummy_closedir,
};
static const esp_vfs_fs_ops_t s_dummy_vfs = {
.open_p = dummy_open,
.close_p = dummy_close,
.dir = &s_dummy_vfs_dir,
};
/* Helper functions to test VFS behavior
*/
@@ -136,15 +140,13 @@ TEST_CASE("vfs parses paths correctly", "[vfs]")
.match_path = "",
.called = false
};
esp_vfs_t desc_foo = DUMMY_VFS();
TEST_ESP_OK( esp_vfs_register("/foo", &desc_foo, &inst_foo) );
TEST_ESP_OK( esp_vfs_register_fs("/foo", &s_dummy_vfs, ESP_VFS_FLAG_CONTEXT_PTR, &inst_foo) );
dummy_vfs_t inst_foo1 = {
.match_path = "",
.called = false
};
esp_vfs_t desc_foo1 = DUMMY_VFS();
TEST_ESP_OK( esp_vfs_register("/foo1", &desc_foo1, &inst_foo1) );
TEST_ESP_OK( esp_vfs_register_fs("/foo1", &s_dummy_vfs, ESP_VFS_FLAG_CONTEXT_PTR, &inst_foo1) );
inst_foo.match_path = "/file";
test_opened(&inst_foo, "/foo/file");
@@ -171,15 +173,13 @@ TEST_CASE("vfs parses paths correctly", "[vfs]")
.match_path = "",
.called = false
};
esp_vfs_t desc_foobar = DUMMY_VFS();
TEST_ESP_OK( esp_vfs_register("/foo/bar", &desc_foobar, &inst_foobar) );
TEST_ESP_OK( esp_vfs_register_fs("/foo/bar", &s_dummy_vfs, ESP_VFS_FLAG_CONTEXT_PTR, &inst_foobar) );
dummy_vfs_t inst_toplevel = {
.match_path = "",
.called = false
};
esp_vfs_t desc_toplevel = DUMMY_VFS();
TEST_ESP_OK( esp_vfs_register("", &desc_toplevel, &inst_toplevel) );
TEST_ESP_OK( esp_vfs_register_fs("", &s_dummy_vfs, ESP_VFS_FLAG_CONTEXT_PTR, &inst_toplevel) );
inst_foo.match_path = "/bar/file";
inst_foobar.match_path = "/file";
@@ -204,15 +204,13 @@ TEST_CASE("vfs unregisters correct nested mount point", "[vfs]")
.match_path = "/file",
.called = false
};
esp_vfs_t desc_foobar = DUMMY_VFS();
TEST_ESP_OK( esp_vfs_register("/foo/bar", &desc_foobar, &inst_foobar) );
TEST_ESP_OK( esp_vfs_register_fs("/foo/bar", &s_dummy_vfs, ESP_VFS_FLAG_CONTEXT_PTR, &inst_foobar) );
dummy_vfs_t inst_foo = {
.match_path = "/bar/file",
.called = false
};
esp_vfs_t desc_foo = DUMMY_VFS();
TEST_ESP_OK( esp_vfs_register("/foo", &desc_foo, &inst_foo) );
TEST_ESP_OK( esp_vfs_register_fs("/foo", &s_dummy_vfs, ESP_VFS_FLAG_CONTEXT_PTR, &inst_foo) );
/* basic operation */
test_opened(&inst_foobar, "/foo/bar/file");
@@ -228,8 +226,8 @@ TEST_CASE("vfs unregisters correct nested mount point", "[vfs]")
/* repeat the above, with the reverse order of registration */
TEST_ESP_OK( esp_vfs_unregister("/foo/bar") );
TEST_ESP_OK( esp_vfs_register("/foo", &desc_foo, &inst_foo) );
TEST_ESP_OK( esp_vfs_register("/foo/bar", &desc_foobar, &inst_foobar) );
TEST_ESP_OK( esp_vfs_register_fs("/foo", &s_dummy_vfs, ESP_VFS_FLAG_CONTEXT_PTR, &inst_foo) );
TEST_ESP_OK( esp_vfs_register_fs("/foo/bar", &s_dummy_vfs, ESP_VFS_FLAG_CONTEXT_PTR, &inst_foobar) );
test_opened(&inst_foobar, "/foo/bar/file");
test_not_called(&inst_foo, "/foo/bar/file");
TEST_ESP_OK( esp_vfs_unregister("/foo") );
@@ -242,13 +240,12 @@ TEST_CASE("vfs unregisters correct nested mount point", "[vfs]")
void test_vfs_register(const char* prefix, bool expect_success, int line)
{
dummy_vfs_t inst;
esp_vfs_t desc = DUMMY_VFS();
esp_err_t err = esp_vfs_register(prefix, &desc, &inst);
esp_err_t err = esp_vfs_register_fs(prefix, &s_dummy_vfs, ESP_VFS_FLAG_CONTEXT_PTR, &inst);
if (expect_success) {
UNITY_TEST_ASSERT_EQUAL_INT(ESP_OK, err, line, "esp_vfs_register should succeed");
UNITY_TEST_ASSERT_EQUAL_INT(ESP_OK, err, line, "esp_vfs_register_fs should succeed");
} else {
UNITY_TEST_ASSERT_EQUAL_INT(ESP_ERR_INVALID_ARG,
err, line, "esp_vfs_register should fail");
err, line, "esp_vfs_register_fs should fail");
}
if (err == ESP_OK) {
TEST_ESP_OK( esp_vfs_unregister(prefix) );