On Fri, Nov 14, 2025, Nikita Kalyazin wrote:
> +static void test_write_supported(int fd, size_t total_size)
> +{
> +     size_t page_size = getpagesize();
> +     void *buf = NULL;
> +     int ret;
> +
> +     ret = posix_memalign(&buf, page_size, total_size);
> +     TEST_ASSERT_EQ(ret, 0);
> +
> +     ret = pwrite(fd, buf, page_size, total_size);
> +     TEST_ASSERT(ret == -1, "writing past the file size on a guest_mem fd 
> should fail");
> +     TEST_ASSERT_EQ(errno, EINVAL);
> +
> +     ret = pwrite(fd, buf, 1, 0);
> +     TEST_ASSERT(ret == -1, "writing an unaligned count a guest_mem fd 
> should fail");
> +     TEST_ASSERT_EQ(errno, EINVAL);
> +
> +     ret = pwrite(fd, buf, page_size, 1);
> +     TEST_ASSERT(ret == -1, "writing to an unaligned offset a guest_mem fd 
> should fail");
> +     TEST_ASSERT_EQ(errno, EINVAL);
> +
> +     ret = pwrite(fd, buf, page_size, 0);
> +     TEST_ASSERT(ret == page_size, "write on a guest_mem fd should succeed");

This write should actually verify a given pattern is written, not just that the
write() returned success.  There should also be testcases for writes that fail,
e.g. on the first page and also on the nth page.

In a perfect world, there would also be testcases for partial writes, but I'm 
not
entirely sure how to make that happen, e.g. I'm not sure if an munmap() can pull
the rug out from under __copy_from_iter().  If we go with the -EFAULT behavior,
the test can map two pages, then use a separate helper thread to munmap() the 
pages
after a delay.  Then in the pwrite() thread, verify all bytes are written on 
success?
I'm not sure that's interesting enought to warrant the development cost and 
effort
though, e.g. it doesn't seem wildly different than the deterministic "entire 
page
failed" case.

Reply via email to