tools/testing/selftests/filesystems/xattr/xattr_socket_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/filesystems/xattr/xattr_socket_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/filesystems/xattr/xattr_socket_test.c- Extension
.c- Size
- 11449 bytes
- Lines
- 471
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
errno.hlimits.hstdio.hstdlib.hstring.hsys/socket.hsys/stat.hsys/types.hsys/un.hsys/xattr.hunistd.h../../kselftest_harness.h
Detected Declarations
function filesystemfunction ASSERT_EQ
Annotated Snippet
if (strcmp(ptr, TEST_XATTR_NAME) == 0) {
found = true;
break;
}
}
ASSERT_TRUE(found) {
TH_LOG("xattr %s not found in list", TEST_XATTR_NAME);
}
}
TEST_F(xattr_socket, remove_user_xattr)
{
char buf[256];
ssize_t ret;
ret = setxattr(self->socket_path, TEST_XATTR_NAME,
TEST_XATTR_VALUE, strlen(TEST_XATTR_VALUE), 0);
ASSERT_EQ(ret, 0) {
TH_LOG("setxattr failed: %s", strerror(errno));
}
ret = removexattr(self->socket_path, TEST_XATTR_NAME);
ASSERT_EQ(ret, 0) {
TH_LOG("removexattr failed: %s", strerror(errno));
}
ret = getxattr(self->socket_path, TEST_XATTR_NAME, buf, sizeof(buf));
ASSERT_EQ(ret, -1);
ASSERT_EQ(errno, ENODATA) {
TH_LOG("Expected ENODATA, got %s", strerror(errno));
}
}
/*
* Test that xattrs persist across socket close and reopen.
* The xattr is on the filesystem inode, not the socket fd.
*/
TEST_F(xattr_socket, xattr_persistence)
{
char buf[256];
ssize_t ret;
ret = setxattr(self->socket_path, TEST_XATTR_NAME,
TEST_XATTR_VALUE, strlen(TEST_XATTR_VALUE), 0);
ASSERT_EQ(ret, 0) {
TH_LOG("setxattr failed: %s", strerror(errno));
}
close(self->sockfd);
self->sockfd = -1;
memset(buf, 0, sizeof(buf));
ret = getxattr(self->socket_path, TEST_XATTR_NAME, buf, sizeof(buf));
ASSERT_EQ(ret, (ssize_t)strlen(TEST_XATTR_VALUE)) {
TH_LOG("getxattr after close failed: %s", strerror(errno));
}
ASSERT_STREQ(buf, TEST_XATTR_VALUE);
}
TEST_F(xattr_socket, update_user_xattr)
{
char buf[256];
ssize_t ret;
ret = setxattr(self->socket_path, TEST_XATTR_NAME,
TEST_XATTR_VALUE, strlen(TEST_XATTR_VALUE), 0);
ASSERT_EQ(ret, 0);
ret = setxattr(self->socket_path, TEST_XATTR_NAME,
TEST_XATTR_VALUE2, strlen(TEST_XATTR_VALUE2), 0);
ASSERT_EQ(ret, 0);
memset(buf, 0, sizeof(buf));
ret = getxattr(self->socket_path, TEST_XATTR_NAME, buf, sizeof(buf));
ASSERT_EQ(ret, (ssize_t)strlen(TEST_XATTR_VALUE2));
ASSERT_STREQ(buf, TEST_XATTR_VALUE2);
}
TEST_F(xattr_socket, xattr_create_flag)
{
int ret;
ret = setxattr(self->socket_path, TEST_XATTR_NAME,
TEST_XATTR_VALUE, strlen(TEST_XATTR_VALUE), 0);
ASSERT_EQ(ret, 0);
ret = setxattr(self->socket_path, TEST_XATTR_NAME,
TEST_XATTR_VALUE2, strlen(TEST_XATTR_VALUE2), XATTR_CREATE);
ASSERT_EQ(ret, -1);
ASSERT_EQ(errno, EEXIST);
Annotation
- Immediate include surface: `errno.h`, `limits.h`, `stdio.h`, `stdlib.h`, `string.h`, `sys/socket.h`, `sys/stat.h`, `sys/types.h`.
- Detected declarations: `function filesystem`, `function ASSERT_EQ`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.