Skip to contentSkip to conversation

Add io_read_eof in common.h utilities

PATCH In review Andrea Cervesato via ltp 3 participants 3 messages Dec 13, 2021 – Dec 15, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Add io_read_eof in common.h utilities

---
 testcases/kernel/io/ltp-aiodio/common.h | 30 +++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
testcases/kernel/io/ltp-aiodio/common.h +30 -0
index c9fd0bbaa..c27c3a0ad 100644
@@ -86,6 +86,36 @@ 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;
+		char *bufoff;
+
+		offset = 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 %p", offset + bufoff);
+				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
Signature · 5 lines
2.34.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi,

...

testcases/kernel/io/ltp-aiodio/common.h static inline void io_read(const char *filename, int filesize, volatile int *run · line 95

Quoted 7 lines
testcases/kernel/io/ltp-aiodio/common.h +7 -0
+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)

Just for a record [1] this open should be checked for errno == EINVAL in case of /tmp/ being tmpfs.

Kind regards,
Petr

[1] https://lore.kernel.org/ltp/YbjIqypOcAYAnLbl@pevik/T/#t

Review

Quoted 2 lines
(quoted diff) +2 -0
+		usleep(100);
+

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp