tools/testing/selftests/mm/hugetlb-read-hwpoison.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/mm/hugetlb-read-hwpoison.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/mm/hugetlb-read-hwpoison.c- Extension
.c- Size
- 7749 bytes
- Lines
- 323
- 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
stdlib.hstdio.hstring.hlinux/magic.hsys/mman.hsys/statfs.herrno.hstdbool.hkselftest.h
Detected Declarations
enum test_statusfunction setup_filemapfunction verify_chunkfunction seek_read_hugepage_filemapfunction read_hugepage_filemapfunction test_hugetlb_readfunction test_hugetlb_read_hwpoisonfunction create_hugetlbfs_filefunction main
Annotated Snippet
if (buf[i] != val) {
printf(PREFIX ERROR_PREFIX "check fail: buf[%lu] = %u != %u\n",
i, buf[i], val);
return false;
}
}
return true;
}
static bool seek_read_hugepage_filemap(int fd, size_t len, size_t wr_chunk_size,
off_t offset, size_t expected)
{
char buf[MAX_WRITE_READ_CHUNK_SIZE];
ssize_t ret_count = 0;
ssize_t total_ret_count = 0;
char val = offset / wr_chunk_size + offset % wr_chunk_size;
printf(PREFIX PREFIX "init val=%u with offset=0x%lx\n", val, offset);
printf(PREFIX PREFIX "expect to read 0x%lx bytes of data in total\n",
expected);
if (lseek(fd, offset, SEEK_SET) < 0) {
perror(PREFIX ERROR_PREFIX "seek failed");
return false;
}
while (offset + total_ret_count < len) {
ret_count = read(fd, buf, wr_chunk_size);
if (ret_count == 0) {
printf(PREFIX PREFIX "read reach end of the file\n");
break;
} else if (ret_count < 0) {
perror(PREFIX ERROR_PREFIX "read failed");
break;
}
++val;
if (!verify_chunk(buf, ret_count, val))
return false;
total_ret_count += ret_count;
}
printf(PREFIX PREFIX "actually read 0x%lx bytes of data in total\n",
total_ret_count);
return total_ret_count == expected;
}
static bool read_hugepage_filemap(int fd, size_t len,
size_t wr_chunk_size, size_t expected)
{
char buf[MAX_WRITE_READ_CHUNK_SIZE];
ssize_t ret_count = 0;
ssize_t total_ret_count = 0;
char val = 0;
printf(PREFIX PREFIX "expect to read 0x%lx bytes of data in total\n",
expected);
while (total_ret_count < len) {
ret_count = read(fd, buf, wr_chunk_size);
if (ret_count == 0) {
printf(PREFIX PREFIX "read reach end of the file\n");
break;
} else if (ret_count < 0) {
perror(PREFIX ERROR_PREFIX "read failed");
break;
}
++val;
if (!verify_chunk(buf, ret_count, val))
return false;
total_ret_count += ret_count;
}
printf(PREFIX PREFIX "actually read 0x%lx bytes of data in total\n",
total_ret_count);
return total_ret_count == expected;
}
static enum test_status
test_hugetlb_read(int fd, size_t len, size_t wr_chunk_size)
{
enum test_status status = TEST_SKIPPED;
char *filemap = NULL;
if (ftruncate(fd, len) < 0) {
perror(PREFIX ERROR_PREFIX "ftruncate failed");
return status;
}
filemap = mmap(NULL, len, PROT_READ | PROT_WRITE,
Annotation
- Immediate include surface: `stdlib.h`, `stdio.h`, `string.h`, `linux/magic.h`, `sys/mman.h`, `sys/statfs.h`, `errno.h`, `stdbool.h`.
- Detected declarations: `enum test_status`, `function setup_filemap`, `function verify_chunk`, `function seek_read_hugepage_filemap`, `function read_hugepage_filemap`, `function test_hugetlb_read`, `function test_hugetlb_read_hwpoison`, `function create_hugetlbfs_file`, `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.