Files
linux/tools/testing/selftests/filesystems/kernfs_test.c
T
Bala-Vignesh-Reddy e6fbd1759c selftests: complete kselftest include centralization
This follow-up patch completes centralization of kselftest.h and
ksefltest_harness.h includes in remaining seltests files, replacing all
relative paths with a non-relative paths using shared -I include path in
lib.mk

Tested with gcc-13.3 and clang-18.1, and cross-compiled successfully on
riscv, arm64, x86_64 and powerpc arch.

[[email protected]: add selftests include path for kselftest.h]
  Link: https://lkml.kernel.org/r/[email protected]
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Bala-Vignesh-Reddy <[email protected]>
Suggested-by: Andrew Morton <[email protected]>
Link: https://lore.kernel.org/lkml/[email protected]/
Reviewed-by: Wei Yang <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: David S. Miller <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Günther Noack <[email protected]>
Cc: Jakub Kacinski <[email protected]>
Cc: Liam Howlett <[email protected]>
Cc: Lorenzo Stoakes <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Mickael Salaun <[email protected]>
Cc: Ming Lei <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: Shuah Khan <[email protected]>
Cc: Simon Horman <[email protected]>
Cc: Suren Baghdasaryan <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
2025-11-27 14:24:31 -08:00

39 lines
816 B
C

// SPDX-License-Identifier: GPL-2.0
#define _GNU_SOURCE
#define __SANE_USERSPACE_TYPES__
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/xattr.h>
#include "kselftest_harness.h"
#include "wrappers.h"
TEST(kernfs_listxattr)
{
int fd;
/* Read-only file that can never have any extended attributes set. */
fd = open("/sys/kernel/warn_count", O_RDONLY | O_CLOEXEC);
ASSERT_GE(fd, 0);
ASSERT_EQ(flistxattr(fd, NULL, 0), 0);
EXPECT_EQ(close(fd), 0);
}
TEST(kernfs_getxattr)
{
int fd;
char buf[1];
/* Read-only file that can never have any extended attributes set. */
fd = open("/sys/kernel/warn_count", O_RDONLY | O_CLOEXEC);
ASSERT_GE(fd, 0);
ASSERT_LT(fgetxattr(fd, "user.foo", buf, sizeof(buf)), 0);
ASSERT_EQ(errno, ENODATA);
EXPECT_EQ(close(fd), 0);
}
TEST_HARNESS_MAIN