Files
esp-idf/components/vfs/test_apps/main/test_vfs_open.c
2025-12-16 17:48:55 +08:00

40 lines
886 B
C

/*
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include <string.h>
#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)
{
errno = EIO;
return -1;
}
TEST_CASE("esp_vfs_open sets correct errno", "[vfs]")
{
const esp_vfs_fs_ops_t desc = {
.open = open_errno_test_open
};
TEST_ESP_OK(esp_vfs_register_fs("/test", &desc, ESP_VFS_FLAG_DEFAULT, NULL));
int fd = open("/test/path", 0, 0);
int e = errno;
TEST_ASSERT_EQUAL(-1, fd);
TEST_ASSERT_EQUAL(EIO, e);
fd = open("/nonexistent/path", 0, 0);
e = errno;
TEST_ASSERT_EQUAL(-1, fd);
TEST_ASSERT_EQUAL(ENOENT, e);
TEST_ESP_OK(esp_vfs_unregister("/test"));
}