tools/testing/selftests/net/socket.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/socket.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/net/socket.c- Extension
.c- Size
- 1943 bytes
- Lines
- 96
- 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
stdio.herrno.hunistd.hstring.hsys/types.hsys/socket.hnetinet/in.hkselftest.h
Detected Declarations
struct socket_testcasefunction run_testsfunction main
Annotated Snippet
struct socket_testcase {
int domain;
int type;
int protocol;
/* 0 = valid file descriptor
* -foo = error foo
*/
int expect;
/* If non-zero, accept EAFNOSUPPORT to handle the case
* of the protocol not being configured into the kernel.
*/
int nosupport_ok;
};
static struct socket_testcase tests[] = {
{ AF_MAX, 0, 0, -EAFNOSUPPORT, 0 },
{ AF_INET, SOCK_STREAM, IPPROTO_TCP, 0, 1 },
{ AF_INET, SOCK_DGRAM, IPPROTO_TCP, -EPROTONOSUPPORT, 1 },
{ AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0, 1 },
{ AF_INET, SOCK_STREAM, IPPROTO_UDP, -EPROTONOSUPPORT, 1 },
};
#define ERR_STRING_SZ 64
static int run_tests(void)
{
char err_string1[ERR_STRING_SZ];
char err_string2[ERR_STRING_SZ];
const char *msg1, *msg2;
int i, err;
err = 0;
for (i = 0; i < ARRAY_SIZE(tests); i++) {
struct socket_testcase *s = &tests[i];
int fd;
fd = socket(s->domain, s->type, s->protocol);
if (fd < 0) {
if (s->nosupport_ok &&
errno == EAFNOSUPPORT)
continue;
if (s->expect < 0 &&
errno == -s->expect)
continue;
msg1 = strerror_r(-s->expect, err_string1, ERR_STRING_SZ);
msg2 = strerror_r(errno, err_string2, ERR_STRING_SZ);
fprintf(stderr, "socket(%d, %d, %d) expected "
"err (%s) got (%s)\n",
s->domain, s->type, s->protocol,
msg1, msg2);
err = -1;
break;
} else {
close(fd);
if (s->expect < 0) {
msg1 = strerror_r(errno, err_string1, ERR_STRING_SZ);
fprintf(stderr, "socket(%d, %d, %d) expected "
"success got err (%s)\n",
s->domain, s->type, s->protocol,
msg1);
err = -1;
break;
}
}
}
return err;
}
int main(void)
{
int err = run_tests();
return err;
}
Annotation
- Immediate include surface: `stdio.h`, `errno.h`, `unistd.h`, `string.h`, `sys/types.h`, `sys/socket.h`, `netinet/in.h`, `kselftest.h`.
- Detected declarations: `struct socket_testcase`, `function run_tests`, `function main`.
- 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.