mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
vfs: add test for errno value after 'open'
This commit is contained in:
parent
931dd74da6
commit
23b0cdad8a
38
components/vfs/test/test_vfs_open.c
Normal file
38
components/vfs/test/test_vfs_open.c
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022 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 "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]")
|
||||
{
|
||||
esp_vfs_t desc = {
|
||||
.open = open_errno_test_open
|
||||
};
|
||||
TEST_ESP_OK(esp_vfs_register("/test", &desc, 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"));
|
||||
}
|
Loading…
Reference in New Issue
Block a user