diff mbox series

[v1] Fix dio_append/aiodio_append tests

Message ID 20240130103319.22763-1-andrea.cervesato@suse.de
State Superseded
Headers show
Series [v1] Fix dio_append/aiodio_append tests | expand

Commit Message

Andrea Cervesato Jan. 30, 2024, 10:33 a.m. UTC
From: Andrea Cervesato <andrea.cervesato@suse.com>

Ensure that dio_append and aiodio_append will end all children if
parent asked for it. The way we have to do it, is to ensure that
*run_child variable is checked before opening the file to read.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 testcases/kernel/io/ltp-aiodio/common.h     | 12 ++++++++++--
 testcases/kernel/io/ltp-aiodio/dio_append.c |  4 ++--
 2 files changed, 12 insertions(+), 4 deletions(-)

Comments

Andrea Cervesato Jan. 30, 2024, 10:35 a.m. UTC | #1
Hi,

On 1/30/24 11:33, Andrea Cervesato wrote:
> From: Andrea Cervesato <andrea.cervesato@suse.com>
>
> Ensure that dio_append and aiodio_append will end all children if
> parent asked for it. The way we have to do it, is to ensure that
> *run_child variable is checked before opening the file to read.
If you can please mention that append has been increased by 10000 in 
dio_append, once patch is merged.
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
>   testcases/kernel/io/ltp-aiodio/common.h     | 12 ++++++++++--
>   testcases/kernel/io/ltp-aiodio/dio_append.c |  4 ++--
>   2 files changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/testcases/kernel/io/ltp-aiodio/common.h b/testcases/kernel/io/ltp-aiodio/common.h
> index 200bbe18e..9a2d27166 100644
> --- a/testcases/kernel/io/ltp-aiodio/common.h
> +++ b/testcases/kernel/io/ltp-aiodio/common.h
> @@ -62,8 +62,12 @@ static inline void io_read(const char *filename, int filesize, volatile int *run
>   	int i;
>   	int r;
>   
> -	while ((fd = open(filename, O_RDONLY, 0666)) < 0)
> +	while ((fd = open(filename, O_RDONLY, 0666)) < 0) {
> +		if (!*run_child)
> +			return;
> +
>   		usleep(100);
> +	}
>   
>   	tst_res(TINFO, "child %i reading file", getpid());
>   
> @@ -102,8 +106,12 @@ static inline void io_read_eof(const char *filename, volatile int *run_child)
>   	int fd;
>   	int r;
>   
> -	while ((fd = open(filename, O_RDONLY, 0666)) < 0)
> +	while ((fd = open(filename, O_RDONLY, 0666)) < 0) {
> +		if (!*run_child)
> +			return;
> +
>   		usleep(100);
> +	}
>   
>   	tst_res(TINFO, "child %i reading file", getpid());
>   
> diff --git a/testcases/kernel/io/ltp-aiodio/dio_append.c b/testcases/kernel/io/ltp-aiodio/dio_append.c
> index 057ae73d9..bd48a8252 100644
> --- a/testcases/kernel/io/ltp-aiodio/dio_append.c
> +++ b/testcases/kernel/io/ltp-aiodio/dio_append.c
> @@ -33,7 +33,7 @@ static void setup(void)
>   {
>   	numchildren = 16;
>   	writesize = 64 * 1024;
> -	appends = 1000;
> +	appends = 10000;
>   
>   	if (tst_parse_int(str_numchildren, &numchildren, 1, INT_MAX))
>   		tst_brk(TBROK, "Invalid number of children '%s'", str_numchildren);
> @@ -97,7 +97,7 @@ static struct tst_test test = {
>   	.options = (struct tst_option[]) {
>   		{"n:", &str_numchildren, "Number of processes (default 16)"},
>   		{"w:", &str_writesize, "Write size for each append (default 64K)"},
> -		{"c:", &str_appends, "Number of appends (default 1000)"},
> +		{"c:", &str_appends, "Number of appends (default 10000)"},
>   		{}
>   	},
>   	.skip_filesystems = (const char *[]) {

Thanks,

Andrea
Cyril Hrubis Jan. 30, 2024, 12:09 p.m. UTC | #2
Hi!
> diff --git a/testcases/kernel/io/ltp-aiodio/dio_append.c b/testcases/kernel/io/ltp-aiodio/dio_append.c
> index 057ae73d9..bd48a8252 100644
> --- a/testcases/kernel/io/ltp-aiodio/dio_append.c
> +++ b/testcases/kernel/io/ltp-aiodio/dio_append.c
> @@ -33,7 +33,7 @@ static void setup(void)
>  {
>  	numchildren = 16;
>  	writesize = 64 * 1024;
> -	appends = 1000;
> +	appends = 10000;

Since we are increasing this we should probably check the free space as
well, so we should add something as:

	if (!tst_fs_has_free(".", appends, writesize))
		tst_brk(TCONF, "Not enough space to run the test");

Or even better put a function:

void tst_assert_free_space(const char *path, unsigned int size, unsigned int mult)

into the test library and this function would tst_brk(TCONF, ) if there
is not enough space and tst_res(TWARN, ) if the free space is let's say
only 10% more than the test would need to run. And we can use that in
all of these tests.

>  	if (tst_parse_int(str_numchildren, &numchildren, 1, INT_MAX))
>  		tst_brk(TBROK, "Invalid number of children '%s'", str_numchildren);
> @@ -97,7 +97,7 @@ static struct tst_test test = {
>  	.options = (struct tst_option[]) {
>  		{"n:", &str_numchildren, "Number of processes (default 16)"},
>  		{"w:", &str_writesize, "Write size for each append (default 64K)"},
> -		{"c:", &str_appends, "Number of appends (default 1000)"},
> +		{"c:", &str_appends, "Number of appends (default 10000)"},
>  		{}
>  	},
>  	.skip_filesystems = (const char *[]) {
> -- 
> 2.35.3
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp
Cyril Hrubis Jan. 30, 2024, 12:18 p.m. UTC | #3
Hi!
> >  	numchildren = 16;
> >  	writesize = 64 * 1024;
> > -	appends = 1000;
> > +	appends = 10000;
> 
> Since we are increasing this we should probably check the free space as
> well, so we should add something as:
> 
> 	if (!tst_fs_has_free(".", appends, writesize))
> 		tst_brk(TCONF, "Not enough space to run the test");
> 
> Or even better put a function:
> 
> void tst_assert_free_space(const char *path, unsigned int size, unsigned int mult)
> 
> into the test library and this function would tst_brk(TCONF, ) if there
> is not enough space and tst_res(TWARN, ) if the free space is let's say
> only 10% more than the test would need to run. And we can use that in
> all of these tests.

Also this can be done in a follow up patch. I guess that the cleanest
option would be to split the patch into two, one that fixes the race
condition, that one should go in ASAP. And second that raises the
appended file size followed by a patch to check for a free space.
diff mbox series

Patch

diff --git a/testcases/kernel/io/ltp-aiodio/common.h b/testcases/kernel/io/ltp-aiodio/common.h
index 200bbe18e..9a2d27166 100644
--- a/testcases/kernel/io/ltp-aiodio/common.h
+++ b/testcases/kernel/io/ltp-aiodio/common.h
@@ -62,8 +62,12 @@  static inline void io_read(const char *filename, int filesize, volatile int *run
 	int i;
 	int r;
 
-	while ((fd = open(filename, O_RDONLY, 0666)) < 0)
+	while ((fd = open(filename, O_RDONLY, 0666)) < 0) {
+		if (!*run_child)
+			return;
+
 		usleep(100);
+	}
 
 	tst_res(TINFO, "child %i reading file", getpid());
 
@@ -102,8 +106,12 @@  static inline void io_read_eof(const char *filename, volatile int *run_child)
 	int fd;
 	int r;
 
-	while ((fd = open(filename, O_RDONLY, 0666)) < 0)
+	while ((fd = open(filename, O_RDONLY, 0666)) < 0) {
+		if (!*run_child)
+			return;
+
 		usleep(100);
+	}
 
 	tst_res(TINFO, "child %i reading file", getpid());
 
diff --git a/testcases/kernel/io/ltp-aiodio/dio_append.c b/testcases/kernel/io/ltp-aiodio/dio_append.c
index 057ae73d9..bd48a8252 100644
--- a/testcases/kernel/io/ltp-aiodio/dio_append.c
+++ b/testcases/kernel/io/ltp-aiodio/dio_append.c
@@ -33,7 +33,7 @@  static void setup(void)
 {
 	numchildren = 16;
 	writesize = 64 * 1024;
-	appends = 1000;
+	appends = 10000;
 
 	if (tst_parse_int(str_numchildren, &numchildren, 1, INT_MAX))
 		tst_brk(TBROK, "Invalid number of children '%s'", str_numchildren);
@@ -97,7 +97,7 @@  static struct tst_test test = {
 	.options = (struct tst_option[]) {
 		{"n:", &str_numchildren, "Number of processes (default 16)"},
 		{"w:", &str_writesize, "Write size for each append (default 64K)"},
-		{"c:", &str_appends, "Number of appends (default 1000)"},
+		{"c:", &str_appends, "Number of appends (default 10000)"},
 		{}
 	},
 	.skip_filesystems = (const char *[]) {