tools/perf/tests/api-io.c
Source file repositories/reference/linux-study-clean/tools/perf/tests/api-io.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/tests/api-io.c- Extension
.c- Size
- 6307 bytes
- Lines
- 344
- 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
sys/types.hsys/stat.hfcntl.hlimits.hstdio.hstdlib.hstring.hunistd.hdebug.htests.hapi/io.hlinux/kernel.hlinux/zalloc.h
Detected Declarations
function make_test_filefunction setup_testfunction cleanup_testfunction do_test_get_charfunction test_get_charfunction do_test_get_hexfunction test_get_hexfunction do_test_get_decfunction test_get_decfunction test_get_linefunction test__api_io
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "debug.h"
#include "tests.h"
#include <api/io.h>
#include <linux/kernel.h>
#include <linux/zalloc.h>
#define TEMPL "/tmp/perf-test-XXXXXX"
#define EXPECT_EQUAL(val, expected) \
do { \
if (val != expected) { \
pr_debug("%s:%d: %d != %d\n", \
__FILE__, __LINE__, val, expected); \
ret = -1; \
} \
} while (0)
#define EXPECT_EQUAL64(val, expected) \
do { \
if (val != expected) { \
pr_debug("%s:%d: %lld != %lld\n", \
__FILE__, __LINE__, val, expected); \
ret = -1; \
} \
} while (0)
static int make_test_file(char path[PATH_MAX], const char *contents)
{
ssize_t contents_len = strlen(contents);
int fd;
strcpy(path, TEMPL);
fd = mkstemp(path);
if (fd < 0) {
pr_debug("mkstemp failed");
return -1;
}
if (write(fd, contents, contents_len) < contents_len) {
pr_debug("short write");
close(fd);
unlink(path);
return -1;
}
close(fd);
return 0;
}
static int setup_test(char path[PATH_MAX], const char *contents,
size_t buf_size, struct io *io)
{
if (make_test_file(path, contents))
return -1;
io->fd = open(path, O_RDONLY);
if (io->fd < 0) {
pr_debug("Failed to open '%s'\n", path);
unlink(path);
return -1;
}
io->buf = malloc(buf_size);
if (io->buf == NULL) {
pr_debug("Failed to allocate memory");
close(io->fd);
unlink(path);
return -1;
}
io__init(io, io->fd, io->buf, buf_size);
return 0;
}
static void cleanup_test(char path[PATH_MAX], struct io *io)
{
zfree(&io->buf);
close(io->fd);
unlink(path);
}
static int do_test_get_char(const char *test_string, size_t buf_size)
{
char path[PATH_MAX];
Annotation
- Immediate include surface: `sys/types.h`, `sys/stat.h`, `fcntl.h`, `limits.h`, `stdio.h`, `stdlib.h`, `string.h`, `unistd.h`.
- Detected declarations: `function make_test_file`, `function setup_test`, `function cleanup_test`, `function do_test_get_char`, `function test_get_char`, `function do_test_get_hex`, `function test_get_hex`, `function do_test_get_dec`, `function test_get_dec`, `function test_get_line`.
- 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.