[LTP] [PATCH v1] Add io_read_eof in common.h utilities
Andrea Cervesato
andrea.cervesato@suse.com
Mon Dec 13 11:58:41 CET 2021
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
testcases/kernel/io/ltp-aiodio/common.h | 31 +++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/testcases/kernel/io/ltp-aiodio/common.h b/testcases/kernel/io/ltp-aiodio/common.h
index c9fd0bbaa..304613496 100644
--- a/testcases/kernel/io/ltp-aiodio/common.h
+++ b/testcases/kernel/io/ltp-aiodio/common.h
@@ -86,6 +86,37 @@ static inline void io_read(const char *filename, int filesize, volatile int *run
SAFE_CLOSE(fd);
}
+static inline void io_read_eof(const char *filename, volatile int *run_child)
+{
+ char buff[4096];
+ int fd;
+ int r;
+
+ while ((fd = open(filename, O_RDONLY, 0666)) < 0)
+ usleep(100);
+
+ tst_res(TINFO, "child %i reading file", getpid());
+
+ while (*run_child) {
+ off_t offset = 0;
+ char *bufoff;
+
+ SAFE_LSEEK(fd, SEEK_END, 0);
+
+ r = SAFE_READ(0, fd, buff, sizeof(buff));
+ if (r > 0) {
+ bufoff = check_zero(buff, r);
+ if (bufoff) {
+ tst_res(TINFO, "non-zero read at offset %zu",
+ offset + (bufoff - buff));
+ break;
+ }
+ }
+ }
+
+ SAFE_CLOSE(fd);
+}
+
/*
* This code tries to create dirty free blocks on
* the HDD so there is a chance that blocks to be allocated
--
2.34.1
More information about the ltp
mailing list