[LTP] [PATCH v2 24/30] ltp-aiodio/dio_sparse, aiodio_sparse: Convert to runtime.
Cyril Hrubis
chrubis@suse.cz
Tue May 3 19:47:12 CEST 2022
Change the code so that the test runtime is capped at the maximal
runtime allowed for the test.
For this to work we also have to:
- check the run_child in the io_read() in the inner loop otherwise the
test will timeout while waiting for the children to finish
- run the AIO writer in a separate process and kill it when we are out
of runtime in the aiodio_sparse
CC: Andrea Cervesato <andrea.cervesato@suse.de>
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
.../kernel/io/ltp-aiodio/aiodio_sparse.c | 26 ++++++++++++++++---
testcases/kernel/io/ltp-aiodio/common.h | 6 ++++-
testcases/kernel/io/ltp-aiodio/dio_sparse.c | 6 ++++-
3 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/testcases/kernel/io/ltp-aiodio/aiodio_sparse.c b/testcases/kernel/io/ltp-aiodio/aiodio_sparse.c
index 2aa5662bb..d3c27646c 100644
--- a/testcases/kernel/io/ltp-aiodio/aiodio_sparse.c
+++ b/testcases/kernel/io/ltp-aiodio/aiodio_sparse.c
@@ -189,7 +189,7 @@ static void run(void)
{
char *filename = "file.bin";
int status;
- int i;
+ int i, pid;
*run_child = 1;
@@ -200,9 +200,27 @@ static void run(void)
}
}
- tst_res(TINFO, "Parent create a sparse file");
+ pid = SAFE_FORK();
+ if (!pid) {
+ aiodio_sparse(filename, alignment, writesize, filesize, numaio);
+ return;
+ }
+
+ tst_res(TINFO, "Child %i creates a sparse file", pid);
+
+ for (;;) {
+ if (SAFE_WAITPID(pid, NULL, WNOHANG))
+ break;
- aiodio_sparse(filename, alignment, writesize, filesize, numaio);
+ sleep(1);
+
+ if (!tst_remaining_runtime()) {
+ tst_res(TINFO, "Test out of runtime, exitting");
+ kill(pid, SIGKILL);
+ SAFE_WAITPID(pid, NULL, 0);
+ break;
+ }
+ }
if (SAFE_WAITPID(-1, &status, WNOHANG))
tst_res(TFAIL, "Non zero bytes read");
@@ -229,7 +247,7 @@ static struct tst_test test = {
"tmpfs",
NULL
},
- .timeout = 1800,
+ .max_iteration_runtime = 1800,
};
#else
TST_TEST_TCONF("test requires libaio and its development packages");
diff --git a/testcases/kernel/io/ltp-aiodio/common.h b/testcases/kernel/io/ltp-aiodio/common.h
index c27c3a0ad..0a242b91e 100644
--- a/testcases/kernel/io/ltp-aiodio/common.h
+++ b/testcases/kernel/io/ltp-aiodio/common.h
@@ -63,7 +63,7 @@ static inline void io_read(const char *filename, int filesize, volatile int *run
tst_res(TINFO, "child %i reading file", getpid());
- while (*run_child) {
+ for (;;) {
off_t offset = 0;
char *bufoff;
@@ -80,9 +80,13 @@ static inline void io_read(const char *filename, int filesize, volatile int *run
}
offset += r;
}
+
+ if (!*run_child)
+ goto exit;
}
}
+exit:
SAFE_CLOSE(fd);
}
diff --git a/testcases/kernel/io/ltp-aiodio/dio_sparse.c b/testcases/kernel/io/ltp-aiodio/dio_sparse.c
index 0039daa8d..dac034158 100644
--- a/testcases/kernel/io/ltp-aiodio/dio_sparse.c
+++ b/testcases/kernel/io/ltp-aiodio/dio_sparse.c
@@ -51,6 +51,10 @@ static void dio_sparse(int fd, int align, long long fs, int ws, long long off)
SAFE_LSEEK(fd, off, SEEK_SET);
for (i = off; i < fs;) {
+ if (!tst_remaining_runtime()) {
+ tst_res(TINFO, "Test runtime is over, exitting");
+ return;
+ }
w = SAFE_WRITE(0, fd, bufptr, ws);
i += w;
}
@@ -135,5 +139,5 @@ static struct tst_test test = {
"tmpfs",
NULL
},
- .timeout = 1800,
+ .max_iteration_runtime = 1800,
};
--
2.35.1
More information about the ltp
mailing list