@@ -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_runtime = 1800,
};
#else
TST_TEST_TCONF("test requires libaio and its development packages");
@@ -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);
}
@@ -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_runtime = 1800,
};
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(-)