1 /*
2  * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <stdio.h>
8 #include <string.h>
9 #include <fcntl.h>
10 #include <errno.h>
11 #include "esp_vfs.h"
12 #include "unity.h"
13 
open_errno_test_open(const char * path,int flags,int mode)14 static int open_errno_test_open(const char * path, int flags, int mode)
15 {
16     errno = EIO;
17     return -1;
18 }
19 
20 TEST_CASE("esp_vfs_open sets correct errno", "[vfs]")
21 {
22     esp_vfs_t desc = {
23         .open = open_errno_test_open
24     };
25     TEST_ESP_OK(esp_vfs_register("/test", &desc, NULL));
26 
27     int fd = open("/test/path", 0, 0);
28     int e = errno;
29     TEST_ASSERT_EQUAL(-1, fd);
30     TEST_ASSERT_EQUAL(EIO, e);
31 
32     fd = open("/nonexistent/path", 0, 0);
33     e = errno;
34     TEST_ASSERT_EQUAL(-1, fd);
35     TEST_ASSERT_EQUAL(ENOENT, e);
36 
37     TEST_ESP_OK(esp_vfs_unregister("/test"));
38 }
39