[LTP] [PATCH v2] syscalls/write06: Add new test

Petr Vorel pvorel@suse.cz
Mon Dec 20 10:53:30 CET 2021


Hi Dai,

> Like pwrite04.c, test the write() system call with O_APPEND.

...
> +++ b/testcases/kernel/syscalls/write/write06.c
> @@ -0,0 +1,95 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
> + * Author: Dai Shili <daisl.fnst@fujitsu.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * Test the write() system call with O_APPEND.
> + *
> + * The full description of O_APPEND is in open(2) man-pages:
> + * O_APPEND
> + *        The file is opened in append mode.  Before each write(2), the
nit: FYI this formatting will be lost in our metadata.
(To see the output, you can run make metadata/ and check docparse/metadata.html
or docparse/metadata.pdf.)

...
> +static void verify_write(void)
> +{
> +	off_t off;
> +	struct stat statbuf;
> +
> +	fd = SAFE_OPEN(DATA_FILE, O_RDWR | O_CREAT | O_TRUNC);
> +	SAFE_WRITE(1, fd, write_buf[0], K2);
> +	SAFE_CLOSE(fd);
> +
> +	fd = SAFE_OPEN(DATA_FILE, O_RDWR | O_APPEND);

Quite often I get EACCES when running the test. It's strange that not always.

$ ./write06
tst_buffers.c:55: TINFO: Test is using guarded buffers
tst_test.c:1423: TINFO: Timeout per run is 0h 05m 00s
write06.c:45: TBROK: open(write06_file,1026,4162714000) failed: EACCES (13)

IMHO this depends on umask (0022) in my case.
Obviously specifying permissions as it's in pwrite04.c fixes the problem:


@@ -38,7 +38,7 @@ static void verify_write(void)
 	off_t off;
 	struct stat statbuf;
 
-	fd = SAFE_OPEN(DATA_FILE, O_RDWR | O_CREAT | O_TRUNC);
+	fd = SAFE_OPEN(DATA_FILE, O_RDWR | O_CREAT | O_TRUNC, 0666);
 	SAFE_WRITE(1, fd, write_buf[0], K2);
 	SAFE_CLOSE(fd);

(pwrite04.c specifies permission in both SAFE_OPEN(), but it's obviously enough
to put it just in the first one, which uses O_CREAT).

Also Cyril noted using permissions in review of v1 patch:
https://lore.kernel.org/ltp/Ya9my0FdHXLqvkJr@yuki/

Otherwise LGTM.
Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr


More information about the ltp mailing list