tools/testing/selftests/bpf/prog_tests/stream.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/stream.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/stream.c- Extension
.c- Size
- 3006 bytes
- Lines
- 109
- 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
test_progs.hsys/mman.hstream.skel.hstream_fail.skel.h
Detected Declarations
function test_stream_failurefunction test_stream_successfunction test_stream_syscallfunction test_addressfunction test_stream_arena_fault_address
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */
#include <test_progs.h>
#include <sys/mman.h>
#include "stream.skel.h"
#include "stream_fail.skel.h"
void test_stream_failure(void)
{
RUN_TESTS(stream_fail);
}
void test_stream_success(void)
{
RUN_TESTS(stream);
return;
}
void test_stream_syscall(void)
{
LIBBPF_OPTS(bpf_test_run_opts, opts);
LIBBPF_OPTS(bpf_prog_stream_read_opts, ropts);
struct stream *skel;
int ret, prog_fd;
char buf[64];
skel = stream__open_and_load();
if (!ASSERT_OK_PTR(skel, "stream__open_and_load"))
return;
prog_fd = bpf_program__fd(skel->progs.stream_syscall);
ret = bpf_prog_test_run_opts(prog_fd, &opts);
ASSERT_OK(ret, "ret");
ASSERT_OK(opts.retval, "retval");
ASSERT_LT(bpf_prog_stream_read(0, BPF_STREAM_STDOUT, buf, sizeof(buf), &ropts), 0, "error");
ret = -errno;
ASSERT_EQ(ret, -EINVAL, "bad prog_fd");
ASSERT_LT(bpf_prog_stream_read(prog_fd, 0, buf, sizeof(buf), &ropts), 0, "error");
ret = -errno;
ASSERT_EQ(ret, -ENOENT, "bad stream id");
ASSERT_LT(bpf_prog_stream_read(prog_fd, BPF_STREAM_STDOUT, NULL, sizeof(buf), NULL), 0, "error");
ret = -errno;
ASSERT_EQ(ret, -EFAULT, "bad stream buf");
ret = bpf_prog_stream_read(prog_fd, BPF_STREAM_STDOUT, buf, 2, NULL);
ASSERT_EQ(ret, 2, "bytes");
ret = bpf_prog_stream_read(prog_fd, BPF_STREAM_STDOUT, buf, 2, NULL);
ASSERT_EQ(ret, 1, "bytes");
ret = bpf_prog_stream_read(prog_fd, BPF_STREAM_STDOUT, buf, 1, &ropts);
ASSERT_EQ(ret, 0, "no bytes stdout");
ret = bpf_prog_stream_read(prog_fd, BPF_STREAM_STDERR, buf, 1, &ropts);
ASSERT_EQ(ret, 0, "no bytes stderr");
stream__destroy(skel);
}
static void test_address(struct bpf_program *prog, unsigned long *fault_addr_p)
{
LIBBPF_OPTS(bpf_test_run_opts, opts);
LIBBPF_OPTS(bpf_prog_stream_read_opts, ropts);
int ret, prog_fd;
char fault_addr[64];
char buf[1024];
prog_fd = bpf_program__fd(prog);
ret = bpf_prog_test_run_opts(prog_fd, &opts);
ASSERT_OK(ret, "ret");
ASSERT_OK(opts.retval, "retval");
sprintf(fault_addr, "0x%lx", *fault_addr_p);
ret = bpf_prog_stream_read(prog_fd, BPF_STREAM_STDERR, buf, sizeof(buf), &ropts);
ASSERT_GT(ret, 0, "stream read");
ASSERT_LE(ret, 1023, "len for buf");
buf[ret] = '\0';
if (!ASSERT_HAS_SUBSTR(buf, fault_addr, "fault_addr")) {
fprintf(stderr, "Output from stream:\n%s\n", buf);
fprintf(stderr, "Fault Addr: %s\n", fault_addr);
}
}
void test_stream_arena_fault_address(void)
{
struct stream *skel;
Annotation
- Immediate include surface: `test_progs.h`, `sys/mman.h`, `stream.skel.h`, `stream_fail.skel.h`.
- Detected declarations: `function test_stream_failure`, `function test_stream_success`, `function test_stream_syscall`, `function test_address`, `function test_stream_arena_fault_address`.
- 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.