Re: [PATCH 2/2] selftests/nolibc: Add a very basic test for fallocate()

From: Thomas Weißschuh

Date: Wed Apr 15 2026 - 12:02:03 EST


On 2026-04-15 23:32:25+0900, Daniel Palmer wrote:
> Create a tmp file, fallocate() to make it a bit bigger, check the
> size is what was expected.
>
> Signed-off-by: Daniel Palmer <daniel@xxxxxxxxx>
> ---
> tools/testing/selftests/nolibc/nolibc-test.c | 33 ++++++++++++++++++++
> 1 file changed, 33 insertions(+)
>
> diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> index d3c4facb54c0..066f436561e7 100644
> --- a/tools/testing/selftests/nolibc/nolibc-test.c
> +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> @@ -896,6 +896,38 @@ int test_getpagesize(void)
> return !c;
> }
>
> +int test_fallocate(void)
> +{
> + struct stat st;
> + int fd, r;
> +
> + /* Create a new tmp file */
> + fd = open("/tmp", O_TMPFILE | O_RDWR, 0644);
> + if (fd == -1)
> + return -1;
> +
> + /* Expand it to 42 bytes */
> + r = fallocate(fd, 0, 0, 42);
> + if (r)
> + goto close_tmpfile;
> +
> + /* Get the new stat */
> + r = fstat(fd, &st);
> + if (r)
> + goto close_tmpfile;
> +
> + /* It should be 42 bytes long */
> + if (st.st_size != 42) {
> + r = -1;
> + goto close_tmpfile;
> + }

This should also check that full 64-bit values are passed through.

> +
> +close_tmpfile:
> + close(fd);
> +
> + return r;
> +}

(...)