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.

Dependency Surface

Detected Declarations

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

Implementation Notes