test_vfs_open.c 823 B

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