test_vfs_lwip.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2021 Espressif Systems (Shanghai) CO LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include <unistd.h>
  15. #include <sys/fcntl.h>
  16. #include <sys/param.h>
  17. #include <sys/socket.h>
  18. #include "unity.h"
  19. #include "test_utils.h"
  20. TEST_CASE("fstat() sets st_mode to socket type", "[vfs][lwip]")
  21. {
  22. test_case_uses_tcpip();
  23. int socket_fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  24. struct stat stat = { 0 };
  25. fstat(socket_fd, &stat);
  26. TEST_ASSERT_TRUE(S_ISSOCK(stat.st_mode));
  27. TEST_ASSERT_FALSE(S_ISBLK(stat.st_mode));
  28. TEST_ASSERT_FALSE(S_ISCHR(stat.st_mode));
  29. TEST_ASSERT_FALSE(S_ISDIR(stat.st_mode));
  30. TEST_ASSERT_FALSE(S_ISREG(stat.st_mode));
  31. TEST_ASSERT_FALSE(S_ISLNK(stat.st_mode));
  32. close(socket_fd);
  33. }