TEST_ASSERT(read(fd, buf, sizeof(buf)) < 0, "read on a guest_mem fd should fail");
TEST_ASSERT(write(fd, buf, sizeof(buf)) < 0, "write on a guest_mem fd should fail");
TEST_ASSERT(pread(fd, buf, sizeof(buf), 0) < 0, "pread on a guest_mem fd should fail");
TEST_ASSERT(pwrite(fd, buf, sizeof(buf), 0) < 0, "pwrite on a guest_mem fd should fail");
}
staticvoid test_file_size(int fd, size_t page_size, size_t total_size)
{ struct stat sb; int ret;
ret = fstat(fd, &sb);
TEST_ASSERT(!ret, "fstat should succeed");
TEST_ASSERT_EQ(sb.st_size, total_size);
TEST_ASSERT_EQ(sb.st_blksize, page_size);
}
staticvoid test_fallocate(int fd, size_t page_size, size_t total_size)
{ int ret;
ret = fallocate(fd, FALLOC_FL_KEEP_SIZE, 0, total_size);
TEST_ASSERT(!ret, "fallocate with aligned offset and size should succeed");
ret = fallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE,
page_size - 1, page_size);
TEST_ASSERT(ret, "fallocate with unaligned offset should fail");
ret = fallocate(fd, FALLOC_FL_KEEP_SIZE, total_size, page_size);
TEST_ASSERT(ret, "fallocate beginning at total_size should fail");
ret = fallocate(fd, FALLOC_FL_KEEP_SIZE, total_size + page_size, page_size);
TEST_ASSERT(ret, "fallocate beginning after total_size should fail");
ret = fallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE,
total_size, page_size);
TEST_ASSERT(!ret, "fallocate(PUNCH_HOLE) at total_size should succeed");
ret = fallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE,
total_size + page_size, page_size);
TEST_ASSERT(!ret, "fallocate(PUNCH_HOLE) after total_size should succeed");
ret = fallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE,
page_size, page_size - 1);
TEST_ASSERT(ret, "fallocate with unaligned size should fail");
ret = fallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE,
page_size, page_size);
TEST_ASSERT(!ret, "fallocate(PUNCH_HOLE) with aligned offset and size should succeed");
ret = fallocate(fd, FALLOC_FL_KEEP_SIZE, page_size, page_size);
TEST_ASSERT(!ret, "fallocate to restore punched hole should succeed");
}
ret = fstat(fd1, &st1);
TEST_ASSERT(ret != -1, "memfd fstat should succeed");
TEST_ASSERT(st1.st_size == 4096, "memfd st_size should match requested size");
ret = fstat(fd2, &st2);
TEST_ASSERT(ret != -1, "memfd fstat should succeed");
TEST_ASSERT(st2.st_size == 8192, "second memfd st_size should match requested size");
ret = fstat(fd1, &st1);
TEST_ASSERT(ret != -1, "memfd fstat should succeed");
TEST_ASSERT(st1.st_size == 4096, "first memfd st_size should still match requested size");
TEST_ASSERT(st1.st_ino != st2.st_ino, "different memfd should have different inode numbers");
close(fd2);
close(fd1);
}
int main(int argc, char *argv[])
{
size_t page_size;
size_t total_size; int fd; struct kvm_vm *vm;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.