Message ID | 20220201093954.1660-1-andrea.cervesato@suse.de |
---|---|
State | Superseded |
Headers | show |
Series | [v2] Check for maximum available pids in dio_sparse.c | expand |
Hi! > Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.de> > --- > In v2 setup message for children has been moved from TCONF to TINFO. > And other small fixes. Please send the small fixes in a separate patch. > testcases/kernel/io/ltp-aiodio/dio_sparse.c | 26 +++++++++++++++++---- > 1 file changed, 21 insertions(+), 5 deletions(-) > > diff --git a/testcases/kernel/io/ltp-aiodio/dio_sparse.c b/testcases/kernel/io/ltp-aiodio/dio_sparse.c > index 0039daa8d..1da1ae37f 100644 > --- a/testcases/kernel/io/ltp-aiodio/dio_sparse.c > +++ b/testcases/kernel/io/ltp-aiodio/dio_sparse.c > @@ -54,14 +54,29 @@ static void dio_sparse(int fd, int align, long long fs, int ws, long long off) > w = SAFE_WRITE(0, fd, bufptr, ws); > i += w; > } > + > + free(bufptr); > } > > static void setup(void) > { > struct stat sb; > + int max_pids; > + > + if (tst_parse_int(str_numchildren, &numchildren, 1, INT_MAX)) { > + tst_brk(TBROK, "Invalid number of children '%s'", > + str_numchildren); > + } > > - if (tst_parse_int(str_numchildren, &numchildren, 1, INT_MAX)) > - tst_brk(TBROK, "Invalid number of children '%s'", str_numchildren); > + max_pids = tst_get_free_pids(); > + if (numchildren > max_pids) { > + numchildren = max_pids; > + > + tst_res(TINFO, > + "Number of children reduced to %d due to system " > + "limitations", > + numchildren); > + } Can we put this piece of code into a some common place and use it in all the I/O tests? I guess that we can as well add a function parse_numchildren() into common.h that would call tst_parse_int() and then apply the limits and use that in all the tests...
diff --git a/testcases/kernel/io/ltp-aiodio/dio_sparse.c b/testcases/kernel/io/ltp-aiodio/dio_sparse.c index 0039daa8d..1da1ae37f 100644 --- a/testcases/kernel/io/ltp-aiodio/dio_sparse.c +++ b/testcases/kernel/io/ltp-aiodio/dio_sparse.c @@ -54,14 +54,29 @@ static void dio_sparse(int fd, int align, long long fs, int ws, long long off) w = SAFE_WRITE(0, fd, bufptr, ws); i += w; } + + free(bufptr); } static void setup(void) { struct stat sb; + int max_pids; + + if (tst_parse_int(str_numchildren, &numchildren, 1, INT_MAX)) { + tst_brk(TBROK, "Invalid number of children '%s'", + str_numchildren); + } - if (tst_parse_int(str_numchildren, &numchildren, 1, INT_MAX)) - tst_brk(TBROK, "Invalid number of children '%s'", str_numchildren); + max_pids = tst_get_free_pids(); + if (numchildren > max_pids) { + numchildren = max_pids; + + tst_res(TINFO, + "Number of children reduced to %d due to system " + "limitations", + numchildren); + } if (tst_parse_filesize(str_writesize, &writesize, 1, LLONG_MAX)) tst_brk(TBROK, "Invalid write blocks size '%s'", str_writesize); @@ -75,7 +90,8 @@ static void setup(void) SAFE_STAT(".", &sb); alignment = sb.st_blksize; - run_child = SAFE_MMAP(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); + run_child = SAFE_MMAP(NULL, sizeof(int), PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANONYMOUS, -1, 0); tst_res(TINFO, "Dirtying free blocks"); dirty_freeblocks(100 * 1024 * 1024); @@ -91,7 +107,7 @@ static void cleanup(void) static void run(void) { - char *filename = "dio_sparse"; + char *filename = "file.bin"; int status; int fd; int i; @@ -129,7 +145,7 @@ static struct tst_test test = { {"w:", &str_writesize, "Size of writing blocks (default 1K)"}, {"s:", &str_filesize, "Size of file (default 100M)"}, {"o:", &str_offset, "File offset (default 0)"}, - {} + {}, }, .skip_filesystems = (const char *[]) { "tmpfs",
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.de> --- In v2 setup message for children has been moved from TCONF to TINFO. And other small fixes. testcases/kernel/io/ltp-aiodio/dio_sparse.c | 26 +++++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-)