kernfs_test.c 816 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // SPDX-License-Identifier: GPL-2.0
  2. #define _GNU_SOURCE
  3. #define __SANE_USERSPACE_TYPES__
  4. #include <fcntl.h>
  5. #include <stdio.h>
  6. #include <sys/stat.h>
  7. #include <sys/xattr.h>
  8. #include "kselftest_harness.h"
  9. #include "wrappers.h"
  10. TEST(kernfs_listxattr)
  11. {
  12. int fd;
  13. /* Read-only file that can never have any extended attributes set. */
  14. fd = open("/sys/kernel/warn_count", O_RDONLY | O_CLOEXEC);
  15. ASSERT_GE(fd, 0);
  16. ASSERT_EQ(flistxattr(fd, NULL, 0), 0);
  17. EXPECT_EQ(close(fd), 0);
  18. }
  19. TEST(kernfs_getxattr)
  20. {
  21. int fd;
  22. char buf[1];
  23. /* Read-only file that can never have any extended attributes set. */
  24. fd = open("/sys/kernel/warn_count", O_RDONLY | O_CLOEXEC);
  25. ASSERT_GE(fd, 0);
  26. ASSERT_LT(fgetxattr(fd, "user.foo", buf, sizeof(buf)), 0);
  27. ASSERT_EQ(errno, ENODATA);
  28. EXPECT_EQ(close(fd), 0);
  29. }
  30. TEST_HARNESS_MAIN