tools/testing/selftests/filesystems/xattr/xattr_socket_types_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/filesystems/xattr/xattr_socket_types_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/filesystems/xattr/xattr_socket_types_test.c- Extension
.c- Size
- 4180 bytes
- Lines
- 178
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
errno.hstddef.hstdio.hstdlib.hstring.hsys/socket.hsys/types.hsys/un.hsys/xattr.hlinux/netlink.hunistd.h../../kselftest_harness.h
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2026 Christian Brauner <brauner@kernel.org>
/*
* Test user.* xattrs on various socket families.
*
* All socket types use sockfs for their inodes, so user.* xattrs should
* work on any socket regardless of address family. This tests AF_INET,
* AF_INET6, AF_NETLINK, AF_PACKET, and abstract namespace AF_UNIX sockets.
*/
#define _GNU_SOURCE
#include <errno.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/un.h>
#include <sys/xattr.h>
#include <linux/netlink.h>
#include <unistd.h>
#include "../../kselftest_harness.h"
#define TEST_XATTR_NAME "user.testattr"
#define TEST_XATTR_VALUE "testvalue"
FIXTURE(xattr_socket_types)
{
int sockfd;
};
FIXTURE_VARIANT(xattr_socket_types)
{
int family;
int type;
int protocol;
};
FIXTURE_VARIANT_ADD(xattr_socket_types, inet) {
.family = AF_INET,
.type = SOCK_STREAM,
.protocol = 0,
};
FIXTURE_VARIANT_ADD(xattr_socket_types, inet6) {
.family = AF_INET6,
.type = SOCK_STREAM,
.protocol = 0,
};
FIXTURE_VARIANT_ADD(xattr_socket_types, netlink) {
.family = AF_NETLINK,
.type = SOCK_RAW,
.protocol = NETLINK_USERSOCK,
};
FIXTURE_VARIANT_ADD(xattr_socket_types, packet) {
.family = AF_PACKET,
.type = SOCK_DGRAM,
.protocol = 0,
};
FIXTURE_SETUP(xattr_socket_types)
{
self->sockfd = socket(variant->family, variant->type,
variant->protocol);
if (self->sockfd < 0 &&
(errno == EAFNOSUPPORT || errno == EPERM || errno == EACCES))
SKIP(return, "socket(%d, %d, %d) not available: %s",
variant->family, variant->type, variant->protocol,
strerror(errno));
ASSERT_GE(self->sockfd, 0) {
TH_LOG("Failed to create socket(%d, %d, %d): %s",
variant->family, variant->type, variant->protocol,
strerror(errno));
}
}
FIXTURE_TEARDOWN(xattr_socket_types)
{
if (self->sockfd >= 0)
close(self->sockfd);
}
TEST_F(xattr_socket_types, set_get_list_remove)
{
char buf[256], list[4096], *ptr;
ssize_t ret;
Annotation
- Immediate include surface: `errno.h`, `stddef.h`, `stdio.h`, `stdlib.h`, `string.h`, `sys/socket.h`, `sys/types.h`, `sys/un.h`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
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.