public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 0/2] Create common.h utilities for aiodio testsuite
@ 2021-11-30 12:10 Andrea Cervesato via ltp
  2021-11-30 12:10 ` [LTP] [PATCH 1/2] Add common.h utilities for aiodio tests Andrea Cervesato via ltp
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andrea Cervesato via ltp @ 2021-11-30 12:10 UTC (permalink / raw)
  To: ltp

aiodio testsuite has multiple copy/paste inside the source code. For
this reason, common.h has been created for all aiodio tests.
dio_truncate is the first test based on LTP API and now it's using it.

Andrea Cervesato (2):
  Add common.h utilities for aiodio tests
  Use common.h in dio_truncate test

 testcases/kernel/io/ltp-aiodio/common.h       | 54 +++++++++++++++++++
 testcases/kernel/io/ltp-aiodio/dio_truncate.c | 48 ++---------------
 2 files changed, 58 insertions(+), 44 deletions(-)
 create mode 100644 testcases/kernel/io/ltp-aiodio/common.h

-- 
2.34.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [LTP] [PATCH 1/2] Add common.h utilities for aiodio tests
  2021-11-30 12:10 [LTP] [PATCH 0/2] Create common.h utilities for aiodio testsuite Andrea Cervesato via ltp
@ 2021-11-30 12:10 ` Andrea Cervesato via ltp
  2021-11-30 12:10 ` [LTP] [PATCH 2/2] Use common.h in dio_truncate test Andrea Cervesato via ltp
  2021-11-30 14:48 ` [LTP] [PATCH 0/2] Create common.h utilities for aiodio testsuite Cyril Hrubis
  2 siblings, 0 replies; 4+ messages in thread
From: Andrea Cervesato via ltp @ 2021-11-30 12:10 UTC (permalink / raw)
  To: ltp

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 testcases/kernel/io/ltp-aiodio/common.h | 54 +++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 testcases/kernel/io/ltp-aiodio/common.h

diff --git a/testcases/kernel/io/ltp-aiodio/common.h b/testcases/kernel/io/ltp-aiodio/common.h
new file mode 100644
index 000000000..fefeed2cf
--- /dev/null
+++ b/testcases/kernel/io/ltp-aiodio/common.h
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+#ifndef AIODIO_COMMON_H__
+#define AIODIO_COMMON_H__
+
+#include <stdlib.h>
+#include "tst_test.h"
+
+static inline char *check_zero(char *buf, int size)
+{
+	char *p;
+
+	p = buf;
+
+	while (size > 0) {
+		if (*buf != 0) {
+			tst_res(TINFO,
+				"non zero buffer at buf[%lu] => 0x%02x,%02x,%02x,%02x",
+				buf - p, (unsigned int)buf[0],
+				size > 1 ? (unsigned int)buf[1] : 0,
+				size > 2 ? (unsigned int)buf[2] : 0,
+				size > 3 ? (unsigned int)buf[3] : 0);
+			tst_res(TINFO, "buf %p, p %p", buf, p);
+			return buf;
+		}
+		buf++;
+		size--;
+	}
+
+	return 0;
+}
+
+static inline void io_append(const char *path, char pattern, int flags, size_t bs, size_t bcount)
+{
+	int fd;
+	size_t i;
+	char *bufptr;
+
+	bufptr = SAFE_MEMALIGN(getpagesize(), bs);
+	memset(bufptr, pattern, bs);
+
+	fd = SAFE_OPEN(path, flags, 0666);
+
+	for (i = 0; i < bcount; i++)
+		SAFE_WRITE(1, fd, bufptr, bs);
+
+	free(bufptr);
+	SAFE_CLOSE(fd);
+}
+
+#endif /* AIODIO_COMMON_H__ */
-- 
2.34.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [LTP] [PATCH 2/2] Use common.h in dio_truncate test
  2021-11-30 12:10 [LTP] [PATCH 0/2] Create common.h utilities for aiodio testsuite Andrea Cervesato via ltp
  2021-11-30 12:10 ` [LTP] [PATCH 1/2] Add common.h utilities for aiodio tests Andrea Cervesato via ltp
@ 2021-11-30 12:10 ` Andrea Cervesato via ltp
  2021-11-30 14:48 ` [LTP] [PATCH 0/2] Create common.h utilities for aiodio testsuite Cyril Hrubis
  2 siblings, 0 replies; 4+ messages in thread
From: Andrea Cervesato via ltp @ 2021-11-30 12:10 UTC (permalink / raw)
  To: ltp

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 testcases/kernel/io/ltp-aiodio/dio_truncate.c | 48 ++-----------------
 1 file changed, 4 insertions(+), 44 deletions(-)

diff --git a/testcases/kernel/io/ltp-aiodio/dio_truncate.c b/testcases/kernel/io/ltp-aiodio/dio_truncate.c
index 68c10ac7a..2eebf2891 100644
--- a/testcases/kernel/io/ltp-aiodio/dio_truncate.c
+++ b/testcases/kernel/io/ltp-aiodio/dio_truncate.c
@@ -31,36 +31,13 @@
 #include <sys/types.h>
 #include <fcntl.h>
 #include "tst_test.h"
+#include "common.h"
 
 #define NUM_CHILDREN 16
 #define FILE_SIZE (64 * 1024)
 
 static int *run_child;
 
-static char *check_zero(char *buf, int size)
-{
-	char *p;
-
-	p = buf;
-
-	while (size > 0) {
-		if (*buf != 0) {
-			tst_res(TINFO,
-				"non zero buffer at buf[%lu] => 0x%02x,%02x,%02x,%02x",
-				buf - p, (unsigned int)buf[0],
-				size > 1 ? (unsigned int)buf[1] : 0,
-				size > 2 ? (unsigned int)buf[2] : 0,
-				size > 3 ? (unsigned int)buf[3] : 0);
-			tst_res(TINFO, "buf %p, p %p", buf, p);
-			return buf;
-		}
-		buf++;
-		size--;
-	}
-
-	return 0;
-}
-
 static void dio_read(const char *filename, size_t bs)
 {
 	int fd;
@@ -98,24 +75,6 @@ static void dio_read(const char *filename, size_t bs)
 	SAFE_CLOSE(fd);
 }
 
-static void dio_append(const char *path, char pattern, size_t bs, size_t bcount)
-{
-	int fd;
-	size_t i;
-	char *bufptr;
-
-	bufptr = SAFE_MEMALIGN(getpagesize(), bs);
-	memset(bufptr, pattern, bs);
-
-	fd = SAFE_OPEN(path, O_CREAT | O_WRONLY | O_DIRECT, 0666);
-
-	for (i = 0; i < bcount; i++)
-		SAFE_WRITE(1, fd, bufptr, bs);
-
-	free(bufptr);
-	SAFE_CLOSE(fd);
-}
-
 static void setup(void)
 {
 	run_child = SAFE_MMAP(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
@@ -131,6 +90,7 @@ static void run(void)
 	char *filename = "file";
 	int filesize = FILE_SIZE;
 	int num_children = NUM_CHILDREN;
+	int wflags = O_DIRECT | O_WRONLY | O_CREAT;
 	int status;
 	int i;
 	int fail = 0;
@@ -147,9 +107,9 @@ static void run(void)
 	tst_res(TINFO, "parent writes/truncates the file");
 
 	for (i = 0; i < 100; i++) {
-		dio_append(filename, 0, filesize, 100);
+		io_append(filename, 0, wflags, filesize, 100);
 		SAFE_TRUNCATE(filename, 0);
-		dio_append("junkfile", 0xaa, filesize, 100);
+		io_append("junkfile", 0xaa, wflags, filesize, 100);
 		SAFE_TRUNCATE("junkfile", 0);
 
 		if (SAFE_WAITPID(-1, &status, WNOHANG)) {
-- 
2.34.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH 0/2] Create common.h utilities for aiodio testsuite
  2021-11-30 12:10 [LTP] [PATCH 0/2] Create common.h utilities for aiodio testsuite Andrea Cervesato via ltp
  2021-11-30 12:10 ` [LTP] [PATCH 1/2] Add common.h utilities for aiodio tests Andrea Cervesato via ltp
  2021-11-30 12:10 ` [LTP] [PATCH 2/2] Use common.h in dio_truncate test Andrea Cervesato via ltp
@ 2021-11-30 14:48 ` Cyril Hrubis
  2 siblings, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2021-11-30 14:48 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi!
Pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-11-30 14:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-30 12:10 [LTP] [PATCH 0/2] Create common.h utilities for aiodio testsuite Andrea Cervesato via ltp
2021-11-30 12:10 ` [LTP] [PATCH 1/2] Add common.h utilities for aiodio tests Andrea Cervesato via ltp
2021-11-30 12:10 ` [LTP] [PATCH 2/2] Use common.h in dio_truncate test Andrea Cervesato via ltp
2021-11-30 14:48 ` [LTP] [PATCH 0/2] Create common.h utilities for aiodio testsuite Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox