All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v2 1/2] aio_tio: fix error diagnosis for byte transfers
@ 2019-01-11  8:53 Matthias Maennich
  2019-01-11  8:53 ` [LTP] [PATCH v2 2/2] aio_tio: determine alignment based on target filesystem Matthias Maennich
                   ` (3 more replies)
  0 siblings, 4 replies; 18+ messages in thread
From: Matthias Maennich @ 2019-01-11  8:53 UTC (permalink / raw)
  To: ltp

In case the expected bytes written during an async io operation did not
match the actually written ones, the wrong error code (res2) had been
reported. Correct that to reflect the error condition (res!=bytes).

Signed-off-by: Matthias Maennich <maennich@google.com>
---
 testcases/kernel/io/aio/aio02/aio_tio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/testcases/kernel/io/aio/aio02/aio_tio.c b/testcases/kernel/io/aio/aio02/aio_tio.c
index 08fb04162..623c81a5e 100644
--- a/testcases/kernel/io/aio/aio02/aio_tio.c
+++ b/testcases/kernel/io/aio/aio02/aio_tio.c
@@ -57,7 +57,7 @@ static void work_done(io_context_t ctx, struct iocb *iocb, long res, long res2)
 
 	if (res != iocb->u.c.nbytes) {
 		fprintf(stderr, "write missed bytes expect %lu got %ld\n",
-			iocb->u.c.nbytes, res2);
+			iocb->u.c.nbytes, res);
 		exit(1);
 	}
 	wait_count--;
-- 
2.20.1.97.g81188d93c3-goog


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

* [LTP] [PATCH v2 2/2] aio_tio: determine alignment based on target filesystem
  2019-01-11  8:53 [LTP] [PATCH v2 1/2] aio_tio: fix error diagnosis for byte transfers Matthias Maennich
@ 2019-01-11  8:53 ` Matthias Maennich
  2019-01-29 18:19   ` Steve Muckle
  2019-02-22 15:33   ` Cyril Hrubis
  2019-02-20 15:20 ` [LTP] [PATCH v3 0/3] aio_tio: fixes and conversion to new lib Matthias Maennich
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 18+ messages in thread
From: Matthias Maennich @ 2019-01-11  8:53 UTC (permalink / raw)
  To: ltp

The alignment for O_DIRECT operations has to match the blocksize of the
underlying filesystem. Determine the alignment from the target file's
file system.

aio_tio test cases 1 and 2 failed (nondeterministic) on aarch64 when run
on a 4096 byte blocksize filesystem and with an alignment of 512 bytes.

Determining the blocksize from the file system and using it for the
alignment resolves the test issue.

Signed-off-by: Matthias Maennich <maennich@google.com>
Reviewed-by: Alessio Balsini <balsini@google.com>
---
 testcases/kernel/io/aio/aio02/aio_tio.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/io/aio/aio02/aio_tio.c b/testcases/kernel/io/aio/aio02/aio_tio.c
index 623c81a5e..db6fa2688 100644
--- a/testcases/kernel/io/aio/aio02/aio_tio.c
+++ b/testcases/kernel/io/aio/aio02/aio_tio.c
@@ -34,6 +34,7 @@
 #include "config.h"
 #include "common.h"
 #include "test.h"
+#include "safe_macros.h"
 #include <string.h>
 #include <errno.h>
 
@@ -42,7 +43,6 @@
 #define AIO_MAXIO 32
 #define AIO_BLKSIZE (64*1024)
 
-static int alignment = 512;
 static int wait_count = 0;
 
 /*
@@ -94,6 +94,8 @@ int io_tio(char *pathname, int flag, int n, int operation)
 	void *bufptr = NULL;
 	off_t offset = 0;
 	struct timespec timeout;
+	struct stat fi_stat;
+	size_t alignment;
 
 	io_context_t myctx;
 	struct iocb iocb_array[AIO_MAXIO];
@@ -105,6 +107,10 @@ int io_tio(char *pathname, int flag, int n, int operation)
 		return -1;
 	}
 
+	/* determine the alignment from the blksize of the underlying fs */
+	SAFE_FSTAT(NULL, fd, &fi_stat);
+	alignment = fi_stat.st_blksize;
+
 	res = io_queue_init(n, &myctx);
 	//printf (" res = %d \n", res);
 
-- 
2.20.1.97.g81188d93c3-goog


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

* [LTP] [PATCH v2 2/2] aio_tio: determine alignment based on target filesystem
  2019-01-11  8:53 ` [LTP] [PATCH v2 2/2] aio_tio: determine alignment based on target filesystem Matthias Maennich
@ 2019-01-29 18:19   ` Steve Muckle
  2019-02-22 15:33   ` Cyril Hrubis
  1 sibling, 0 replies; 18+ messages in thread
From: Steve Muckle @ 2019-01-29 18:19 UTC (permalink / raw)
  To: ltp

Reviewed-by: Steve Muckle <smuckle@google.com>

On 01/11/2019 12:53 AM, Matthias Maennich wrote:
> The alignment for O_DIRECT operations has to match the blocksize of the
> underlying filesystem. Determine the alignment from the target file's
> file system.
> 
> aio_tio test cases 1 and 2 failed (nondeterministic) on aarch64 when run
> on a 4096 byte blocksize filesystem and with an alignment of 512 bytes.
> 
> Determining the blocksize from the file system and using it for the
> alignment resolves the test issue.
> 
> Signed-off-by: Matthias Maennich <maennich@google.com>
> Reviewed-by: Alessio Balsini <balsini@google.com>
> ---
>   testcases/kernel/io/aio/aio02/aio_tio.c | 8 +++++++-
>   1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/testcases/kernel/io/aio/aio02/aio_tio.c b/testcases/kernel/io/aio/aio02/aio_tio.c
> index 623c81a5e..db6fa2688 100644
> --- a/testcases/kernel/io/aio/aio02/aio_tio.c
> +++ b/testcases/kernel/io/aio/aio02/aio_tio.c
> @@ -34,6 +34,7 @@
>   #include "config.h"
>   #include "common.h"
>   #include "test.h"
> +#include "safe_macros.h"
>   #include <string.h>
>   #include <errno.h>
>   
> @@ -42,7 +43,6 @@
>   #define AIO_MAXIO 32
>   #define AIO_BLKSIZE (64*1024)
>   
> -static int alignment = 512;
>   static int wait_count = 0;
>   
>   /*
> @@ -94,6 +94,8 @@ int io_tio(char *pathname, int flag, int n, int operation)
>   	void *bufptr = NULL;
>   	off_t offset = 0;
>   	struct timespec timeout;
> +	struct stat fi_stat;
> +	size_t alignment;
>   
>   	io_context_t myctx;
>   	struct iocb iocb_array[AIO_MAXIO];
> @@ -105,6 +107,10 @@ int io_tio(char *pathname, int flag, int n, int operation)
>   		return -1;
>   	}
>   
> +	/* determine the alignment from the blksize of the underlying fs */
> +	SAFE_FSTAT(NULL, fd, &fi_stat);
> +	alignment = fi_stat.st_blksize;
> +
>   	res = io_queue_init(n, &myctx);
>   	//printf (" res = %d \n", res);
>   
> 


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

* [LTP] [PATCH v3 0/3] aio_tio: fixes and conversion to new lib
  2019-01-11  8:53 [LTP] [PATCH v2 1/2] aio_tio: fix error diagnosis for byte transfers Matthias Maennich
  2019-01-11  8:53 ` [LTP] [PATCH v2 2/2] aio_tio: determine alignment based on target filesystem Matthias Maennich
@ 2019-02-20 15:20 ` Matthias Maennich
  2019-02-20 15:20   ` [LTP] [PATCH v3 1/3] aio_tio: fix error diagnosis for byte transfers Matthias Maennich
                     ` (2 more replies)
  2019-02-22 15:28 ` [LTP] [PATCH v2 1/2] aio_tio: fix error diagnosis for byte transfers Cyril Hrubis
  2019-02-26 17:02 ` [LTP] [PATCH v4 0/3] aio_tio: fixes and conversion to new lib Matthias Maennich
  3 siblings, 3 replies; 18+ messages in thread
From: Matthias Maennich @ 2019-02-20 15:20 UTC (permalink / raw)
  To: ltp

This patch series is a resend of an earlier series for two bug fixes. In
addition, it now contains a patch to migrate the test to the new lib
along with some cleanup.

Cheers,
Matthias

Matthias Maennich (3):
  aio_tio: fix error diagnosis for byte transfers
  aio_tio: determine alignment based on target filesystem
  aio_tio: convert to new lib

 testcases/kernel/io/aio/aio02/Makefile  |  24 +--
 testcases/kernel/io/aio/aio02/aio_tio.c | 207 +++++++++++++-----------
 testcases/kernel/io/aio/aio02/common.h  |  28 ----
 testcases/kernel/io/aio/aio02/main.c    |  37 -----
 4 files changed, 112 insertions(+), 184 deletions(-)
 delete mode 100644 testcases/kernel/io/aio/aio02/common.h
 delete mode 100644 testcases/kernel/io/aio/aio02/main.c

-- 
2.21.0.rc0.258.g878e2cd30e-goog


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

* [LTP] [PATCH v3 1/3] aio_tio: fix error diagnosis for byte transfers
  2019-02-20 15:20 ` [LTP] [PATCH v3 0/3] aio_tio: fixes and conversion to new lib Matthias Maennich
@ 2019-02-20 15:20   ` Matthias Maennich
  2019-02-20 15:20   ` [LTP] [PATCH v3 2/3] aio_tio: determine alignment based on target filesystem Matthias Maennich
  2019-02-20 15:20   ` [LTP] [PATCH v3 3/3] aio_tio: convert to new lib Matthias Maennich
  2 siblings, 0 replies; 18+ messages in thread
From: Matthias Maennich @ 2019-02-20 15:20 UTC (permalink / raw)
  To: ltp

In case the expected bytes written during an async io operation did not
match the actually written ones, the wrong error code (res2) had been
reported. Correct that to reflect the error condition (res!=bytes).

Signed-off-by: Matthias Maennich <maennich@google.com>
---
 testcases/kernel/io/aio/aio02/aio_tio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/testcases/kernel/io/aio/aio02/aio_tio.c b/testcases/kernel/io/aio/aio02/aio_tio.c
index 08fb04162..623c81a5e 100644
--- a/testcases/kernel/io/aio/aio02/aio_tio.c
+++ b/testcases/kernel/io/aio/aio02/aio_tio.c
@@ -57,7 +57,7 @@ static void work_done(io_context_t ctx, struct iocb *iocb, long res, long res2)
 
 	if (res != iocb->u.c.nbytes) {
 		fprintf(stderr, "write missed bytes expect %lu got %ld\n",
-			iocb->u.c.nbytes, res2);
+			iocb->u.c.nbytes, res);
 		exit(1);
 	}
 	wait_count--;
-- 
2.21.0.rc0.258.g878e2cd30e-goog


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

* [LTP] [PATCH v3 2/3] aio_tio: determine alignment based on target filesystem
  2019-02-20 15:20 ` [LTP] [PATCH v3 0/3] aio_tio: fixes and conversion to new lib Matthias Maennich
  2019-02-20 15:20   ` [LTP] [PATCH v3 1/3] aio_tio: fix error diagnosis for byte transfers Matthias Maennich
@ 2019-02-20 15:20   ` Matthias Maennich
  2019-02-20 15:20   ` [LTP] [PATCH v3 3/3] aio_tio: convert to new lib Matthias Maennich
  2 siblings, 0 replies; 18+ messages in thread
From: Matthias Maennich @ 2019-02-20 15:20 UTC (permalink / raw)
  To: ltp

The alignment for O_DIRECT operations has to match the blocksize of the
underlying filesystem. Determine the alignment from the target file's
file system.

aio_tio test cases 1 and 2 failed (nondeterministic) on aarch64 when run
on a 4096 byte blocksize filesystem and with an alignment of 512 bytes.

Determining the blocksize from the file system and using it for the
alignment resolves the test issue.

Signed-off-by: Matthias Maennich <maennich@google.com>
Reviewed-by: Alessio Balsini <balsini@google.com>
Reviewed-by: Steve Muckle <smuckle@google.com>
---
 testcases/kernel/io/aio/aio02/aio_tio.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/io/aio/aio02/aio_tio.c b/testcases/kernel/io/aio/aio02/aio_tio.c
index 623c81a5e..db6fa2688 100644
--- a/testcases/kernel/io/aio/aio02/aio_tio.c
+++ b/testcases/kernel/io/aio/aio02/aio_tio.c
@@ -34,6 +34,7 @@
 #include "config.h"
 #include "common.h"
 #include "test.h"
+#include "safe_macros.h"
 #include <string.h>
 #include <errno.h>
 
@@ -42,7 +43,6 @@
 #define AIO_MAXIO 32
 #define AIO_BLKSIZE (64*1024)
 
-static int alignment = 512;
 static int wait_count = 0;
 
 /*
@@ -94,6 +94,8 @@ int io_tio(char *pathname, int flag, int n, int operation)
 	void *bufptr = NULL;
 	off_t offset = 0;
 	struct timespec timeout;
+	struct stat fi_stat;
+	size_t alignment;
 
 	io_context_t myctx;
 	struct iocb iocb_array[AIO_MAXIO];
@@ -105,6 +107,10 @@ int io_tio(char *pathname, int flag, int n, int operation)
 		return -1;
 	}
 
+	/* determine the alignment from the blksize of the underlying fs */
+	SAFE_FSTAT(NULL, fd, &fi_stat);
+	alignment = fi_stat.st_blksize;
+
 	res = io_queue_init(n, &myctx);
 	//printf (" res = %d \n", res);
 
-- 
2.21.0.rc0.258.g878e2cd30e-goog


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

* [LTP] [PATCH v3 3/3] aio_tio: convert to new lib
  2019-02-20 15:20 ` [LTP] [PATCH v3 0/3] aio_tio: fixes and conversion to new lib Matthias Maennich
  2019-02-20 15:20   ` [LTP] [PATCH v3 1/3] aio_tio: fix error diagnosis for byte transfers Matthias Maennich
  2019-02-20 15:20   ` [LTP] [PATCH v3 2/3] aio_tio: determine alignment based on target filesystem Matthias Maennich
@ 2019-02-20 15:20   ` Matthias Maennich
  2019-02-22 20:40     ` Steve Muckle
  2 siblings, 1 reply; 18+ messages in thread
From: Matthias Maennich @ 2019-02-20 15:20 UTC (permalink / raw)
  To: ltp

Convert to the new test lib and perform various cleanups.
Also refactor the test definition for readability.

Signed-off-by: Matthias Maennich <maennich@google.com>
---
 testcases/kernel/io/aio/aio02/Makefile  |  24 +--
 testcases/kernel/io/aio/aio02/aio_tio.c | 201 +++++++++++++-----------
 testcases/kernel/io/aio/aio02/common.h  |  28 ----
 testcases/kernel/io/aio/aio02/main.c    |  37 -----
 4 files changed, 106 insertions(+), 184 deletions(-)
 delete mode 100644 testcases/kernel/io/aio/aio02/common.h
 delete mode 100644 testcases/kernel/io/aio/aio02/main.c

diff --git a/testcases/kernel/io/aio/aio02/Makefile b/testcases/kernel/io/aio/aio02/Makefile
index a99807c26..629aa9a58 100644
--- a/testcases/kernel/io/aio/aio02/Makefile
+++ b/testcases/kernel/io/aio/aio02/Makefile
@@ -1,36 +1,14 @@
-#
-#    kernel/io/aio/aio2 testcase Makefile.
+// SPDX-License-Identifier: GPL-2.0-or-later
 #
 #    Copyright (C) 2009, Cisco Systems Inc.
 #
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
 
-# Needed for common.h...
 CPPFLAGS		+= -D_GNU_SOURCE
 
 LDLIBS			+= $(AIO_LIBS)
 
-FILTER_OUT_MAKE_TARGETS	:= main
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
-
-$(MAKE_TARGETS): %: %.o main.o
diff --git a/testcases/kernel/io/aio/aio02/aio_tio.c b/testcases/kernel/io/aio/aio02/aio_tio.c
index db6fa2688..a55ff2663 100644
--- a/testcases/kernel/io/aio/aio02/aio_tio.c
+++ b/testcases/kernel/io/aio/aio02/aio_tio.c
@@ -1,64 +1,59 @@
-/*************************************************************************************
-*
-*  Copyright (c) International Business Machines  Corp., 2003
-*
-*  This program is free software;  you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  This program is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-*  the GNU General Public License for more details.
-*
-*  You should have received a copy of the GNU General Public License
-*  along with this program;  if not, write to the Free Software
-*  Foundation,
-*
-*  FILE        : aio_tio
-*  USAGE       : ./aio_tio
-*
-*  DESCRIPTION : This program will test Asynchronous I/O for 2.5 Kernel infrastructure
-*  REQUIREMENTS:
-*                1) libaio-0.3.92 or up for 2.5 kernal
-*                2) glibc 2.1.91 or up
-*  HISTORY     :
-*      11/03/2003 Kai Zhao (ltcd3@cn.ibm.com)
-*
-*  CODE COVERAGE:
-*                 68.3% - fs/aio.c
-*
-************************************************************************************/
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ *  Copyright (c) International Business Machines Corp., 2003
+ *
+ *  AUTHORS
+ *   Kai Zhao (ltcd3@cn.ibm.com)
+ *
+ *  DESCRIPTION : Test Asynchronous I/O for 2.5 Kernel Infrastructure
+ *
+ *  REQUIREMENTS:
+ *   1) libaio-0.3.92 or up for 2.5 kernel
+ *   2) glibc 2.1.91 or up
+ */
 
 #include "config.h"
-#include "common.h"
-#include "test.h"
-#include "safe_macros.h"
-#include <string.h>
+#include "tst_test.h"
 #include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
 #ifdef HAVE_LIBAIO
+#include <libaio.h>
 
 #define AIO_MAXIO 32
 #define AIO_BLKSIZE (64*1024)
 
 static int wait_count = 0;
 
+/*
+ * Fatal error handler
+ */
+void io_error(const char *func, int rc)
+{
+	if (rc == -ENOSYS)
+		tst_brk(TCONF, "AIO not in this kernel\n");
+	else if (rc < 0)
+		tst_brk(TFAIL, "%s: %s\n", func, strerror(-rc));
+	else
+		tst_brk(TFAIL, "%s: error %d\n", func, rc);
+}
+
 /*
  * write work done
  */
 static void work_done(io_context_t ctx, struct iocb *iocb, long res, long res2)
 {
+	(void) ctx;  // silence compiler warning (-Wunused)
 
 	if (res2 != 0) {
 		io_error("aio write", res2);
 	}
 
-	if (res != iocb->u.c.nbytes) {
-		fprintf(stderr, "write missed bytes expect %lu got %ld\n",
+	if (res != (long)iocb->u.c.nbytes) {
+		tst_brk(TFAIL, "write missed bytes expect %lu got %ld\n",
 			iocb->u.c.nbytes, res);
-		exit(1);
 	}
 	wait_count--;
 }
@@ -66,7 +61,7 @@ static void work_done(io_context_t ctx, struct iocb *iocb, long res, long res2)
 /*
  * io_wait_run() - wait for an io_event and then call the callback.
  */
-int io_wait_run(io_context_t ctx, struct timespec *to)
+static int io_wait_run(io_context_t ctx, struct timespec *to)
 {
 	struct io_event events[AIO_MAXIO];
 	struct io_event *ep;
@@ -88,7 +83,7 @@ int io_wait_run(io_context_t ctx, struct timespec *to)
 	return ret;
 }
 
-int io_tio(char *pathname, int flag, int n, int operation)
+static int io_tio(char *pathname, int flag, int n, int operation)
 {
 	int res, fd = 0, i = 0;
 	void *bufptr = NULL;
@@ -101,31 +96,26 @@ int io_tio(char *pathname, int flag, int n, int operation)
 	struct iocb iocb_array[AIO_MAXIO];
 	struct iocb *iocbps[AIO_MAXIO];
 
-	fd = open(pathname, flag, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
-	if (fd <= 0) {
-		printf("open for %s failed: %s\n", pathname, strerror(errno));
-		return -1;
-	}
+	fd = SAFE_OPEN(pathname, flag, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
 
 	/* determine the alignment from the blksize of the underlying fs */
-	SAFE_FSTAT(NULL, fd, &fi_stat);
+	SAFE_FSTAT(fd, &fi_stat);
 	alignment = fi_stat.st_blksize;
 
 	res = io_queue_init(n, &myctx);
-	//printf (" res = %d \n", res);
 
 	for (i = 0; i < AIO_MAXIO; i++) {
 
 		switch (operation) {
 		case IO_CMD_PWRITE:
 			if (posix_memalign(&bufptr, alignment, AIO_BLKSIZE)) {
-				perror(" posix_memalign failed ");
+				tst_brk(TBROK | TERRNO, "posix_memalign failed");
 				return -1;
 			}
 			memset(bufptr, 0, AIO_BLKSIZE);
 
 			io_prep_pwrite(&iocb_array[i], fd, bufptr,
-				       AIO_BLKSIZE, offset);
+					   AIO_BLKSIZE, offset);
 			io_set_callback(&iocb_array[i], work_done);
 			iocbps[i] = &iocb_array[i];
 			offset += AIO_BLKSIZE;
@@ -133,13 +123,13 @@ int io_tio(char *pathname, int flag, int n, int operation)
 			break;
 		case IO_CMD_PREAD:
 			if (posix_memalign(&bufptr, alignment, AIO_BLKSIZE)) {
-				perror(" posix_memalign failed ");
+				tst_brk(TBROK | TERRNO, "posix_memalign failed");
 				return -1;
 			}
 			memset(bufptr, 0, AIO_BLKSIZE);
 
 			io_prep_pread(&iocb_array[i], fd, bufptr,
-				      AIO_BLKSIZE, offset);
+					  AIO_BLKSIZE, offset);
 			io_set_callback(&iocb_array[i], work_done);
 			iocbps[i] = &iocb_array[i];
 			offset += AIO_BLKSIZE;
@@ -148,9 +138,7 @@ int io_tio(char *pathname, int flag, int n, int operation)
 		case IO_CMD_NOOP:
 			break;
 		default:
-			tst_resm(TFAIL,
-				 "Command failed; opcode returned: %d\n",
-				 operation);
+			tst_res(TFAIL, "Command failed; opcode returned: %d\n", operation);
 			return -1;
 			break;
 		}
@@ -164,8 +152,8 @@ int io_tio(char *pathname, int flag, int n, int operation)
 	}
 
 	/*
-	 * We have submitted all the i/o requests. Wait for at least one to complete
-	 * and call the callbacks.
+	 * We have submitted all the i/o requests. Wait for@least one to
+	 * complete and call the callbacks.
 	 */
 	wait_count = AIO_MAXIO;
 
@@ -185,7 +173,7 @@ int io_tio(char *pathname, int flag, int n, int operation)
 		break;
 	}
 
-	close(fd);
+	SAFE_CLOSE(fd);
 
 	for (i = 0; i < AIO_MAXIO; i++) {
 		if (iocb_array[i].u.c.buf != NULL) {
@@ -198,49 +186,70 @@ int io_tio(char *pathname, int flag, int n, int operation)
 	return 0;
 }
 
-int test_main(void)
+static void test_main(void)
 {
-	int status = 0;
-
-	tst_resm(TINFO, "Running test 1\n");
-	status = io_tio("file1",
-			O_TRUNC | O_DIRECT | O_WRONLY | O_CREAT | O_LARGEFILE,
-			AIO_MAXIO, IO_CMD_PWRITE);
-	if (status) {
-		return status;
-	}
+	struct testcase {
+		const char *description;
+		int flags;
+		int operation;
+	} testcases[] = {
+		{ .description =
+		    "WRITE: O_WRONLY | O_TRUNC | O_DIRECT | O_LARGEFILE | O_CREAT",
+		  .flags =  O_WRONLY | O_TRUNC | O_DIRECT | O_LARGEFILE | O_CREAT,
+		  .operation = IO_CMD_PWRITE
+		},
+		{ .description =
+		    "WRITE: O_RDONLY           | O_DIRECT | O_LARGEFILE",
+		  .flags =  O_RDONLY           | O_DIRECT | O_LARGEFILE,
+		  .operation = IO_CMD_PREAD
+		},
+		{ .description =
+		    "WRITE: O_RDWR   | O_TRUNC",
+		  .flags =  O_RDWR   | O_TRUNC,
+		  .operation = IO_CMD_PWRITE
+		},
+		{ .description =
+		    "READ : O_RDWR",
+		  .flags =  O_RDWR,
+		  .operation = IO_CMD_PREAD
+		},
+		{ .description =
+		    "WRITE: O_WRONLY | O_TRUNC",
+		  .flags =  O_WRONLY | O_TRUNC,
+		  .operation = IO_CMD_PWRITE
+		},
+		{ .description =
+		    "READ : O_RDONLY",
+		  .flags =  O_RDONLY,
+		  .operation = IO_CMD_PREAD
+		},
+	};
 
-	tst_resm(TINFO, "Running test 2\n");
-	status = io_tio("file1", O_RDONLY | O_DIRECT | O_LARGEFILE,
-			AIO_MAXIO, IO_CMD_PREAD);
-	if (status) {
-		return status;
-	}
-
-	tst_resm(TINFO, "Running test 3\n");
-	status = io_tio("file1", O_TRUNC | O_RDWR, AIO_MAXIO, IO_CMD_PWRITE);
-	if (status) {
-		return status;
-	}
-
-	tst_resm(TINFO, "Running test 4\n");
-	status = io_tio("file1", O_RDWR, AIO_MAXIO, IO_CMD_PREAD);
-	if (status) {
-		return status;
-	}
+	int status = 0;
 
-	tst_resm(TINFO, "Running test 5\n");
-	status = io_tio("file1", O_TRUNC | O_WRONLY, AIO_MAXIO, IO_CMD_PWRITE);
-	if (status) {
-		return status;
+	for (size_t i = 0; i < ARRAY_SIZE(testcases); ++i) {
+		tst_res(TINFO, "%s", testcases[i].description);
+		status = io_tio("file", testcases[i].flags, AIO_MAXIO,
+				testcases[i].operation);
+		if (status) {
+			tst_res(TFAIL, "%s, status = %d",
+					testcases[i].description, status);
+		} else {
+			tst_res(TPASS, "%s", testcases[i].description);
+		}
 	}
+}
 
-	tst_resm(TINFO, "Running test 6 \n");
-	status = io_tio("file1", O_RDONLY, AIO_MAXIO, IO_CMD_PREAD);
-	if (status) {
-		return status;
-	}
+#else
 
-	return status;
+static void test_main(void)
+{
+	tst_brk(TCONF, "test requires libaio and it's development packages");
 }
+
 #endif
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.test_all = test_main
+};
diff --git a/testcases/kernel/io/aio/aio02/common.h b/testcases/kernel/io/aio/aio02/common.h
deleted file mode 100644
index 4b80761a6..000000000
--- a/testcases/kernel/io/aio/aio02/common.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/param.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <sys/select.h>
-#if HAVE_LIBAIO_H
-#include <libaio.h>
-#endif
-#include <sys/uio.h>
-#include <assert.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-
-/* Fatal error handler */
-static void io_error(const char *func, int rc)
-{
-	if (rc == -ENOSYS)
-		fprintf(stderr, "AIO not in this kernel\n");
-	else if (rc < 0)
-		fprintf(stderr, "%s: %s\n", func, strerror(-rc));
-	else
-		fprintf(stderr, "%s: error %d\n", func, rc);
-
-	exit(1);
-}
diff --git a/testcases/kernel/io/aio/aio02/main.c b/testcases/kernel/io/aio/aio02/main.c
deleted file mode 100644
index 7b157f31b..000000000
--- a/testcases/kernel/io/aio/aio02/main.c
+++ /dev/null
@@ -1,37 +0,0 @@
-#include <stdio.h>
-#include <errno.h>
-#include <assert.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#include "config.h"
-#include "test.h"
-
-#define TEST_NAME "aio_tio"
-
-char *TCID = "aio02/" TEST_NAME;
-int TST_TOTAL = 0;
-
-#ifdef HAVE_LIBAIO
-#include <libaio.h>
-
-int test_main(void);
-
-int main(void)
-{
-	tst_tmpdir();
-
-	test_main();
-
-	tst_rmdir();
-	tst_exit();
-}
-#else
-int main(void)
-{
-	tst_brkm(TCONF, NULL, "test requires libaio and it's development packages");
-}
-#endif
-- 
2.21.0.rc0.258.g878e2cd30e-goog


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

* [LTP] [PATCH v2 1/2] aio_tio: fix error diagnosis for byte transfers
  2019-01-11  8:53 [LTP] [PATCH v2 1/2] aio_tio: fix error diagnosis for byte transfers Matthias Maennich
  2019-01-11  8:53 ` [LTP] [PATCH v2 2/2] aio_tio: determine alignment based on target filesystem Matthias Maennich
  2019-02-20 15:20 ` [LTP] [PATCH v3 0/3] aio_tio: fixes and conversion to new lib Matthias Maennich
@ 2019-02-22 15:28 ` Cyril Hrubis
  2019-02-26 17:02 ` [LTP] [PATCH v4 0/3] aio_tio: fixes and conversion to new lib Matthias Maennich
  3 siblings, 0 replies; 18+ messages in thread
From: Cyril Hrubis @ 2019-02-22 15:28 UTC (permalink / raw)
  To: ltp

Hi!
Pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v2 2/2] aio_tio: determine alignment based on target filesystem
  2019-01-11  8:53 ` [LTP] [PATCH v2 2/2] aio_tio: determine alignment based on target filesystem Matthias Maennich
  2019-01-29 18:19   ` Steve Muckle
@ 2019-02-22 15:33   ` Cyril Hrubis
  2019-02-26 15:37     ` Matthias =?unknown-8bit?q?M=C3=A4nnich?=
  1 sibling, 1 reply; 18+ messages in thread
From: Cyril Hrubis @ 2019-02-22 15:33 UTC (permalink / raw)
  To: ltp

Hi!
> The alignment for O_DIRECT operations has to match the blocksize of the
> underlying filesystem. Determine the alignment from the target file's
> file system.
> 
> aio_tio test cases 1 and 2 failed (nondeterministic) on aarch64 when run
> on a 4096 byte blocksize filesystem and with an alignment of 512 bytes.

Is this really about the filesystem? Citing man open:

       Under Linux 2.4, transfer sizes, and the alignment of the  user  buffer
       and  the file offset must all be multiples of the logical block size of
       the filesystem.  Since Linux 2.6.0, alignment to the logical block size
       of  the underlying storage (typically 512 bytes) suffices.  The logical
       block size can be determined using the ioctl(2) BLKSSZGET operation  or
       from the shell using the command:

       blockdev --getss

So unless you are running ancient 2.4 kernel the aligment restrictions should
be result of the blocksize of the device rather than of the filesystem.

What does the blockdev command return on the particular system?

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v3 3/3] aio_tio: convert to new lib
  2019-02-20 15:20   ` [LTP] [PATCH v3 3/3] aio_tio: convert to new lib Matthias Maennich
@ 2019-02-22 20:40     ` Steve Muckle
  0 siblings, 0 replies; 18+ messages in thread
From: Steve Muckle @ 2019-02-22 20:40 UTC (permalink / raw)
  To: ltp

Hi Matthias,

On 02/20/2019 07:20 AM, 'Matthias Maennich' via kernel-team wrote:
> Convert to the new test lib and perform various cleanups.
> Also refactor the test definition for readability.
> 
> Signed-off-by: Matthias Maennich <maennich@google.com>
> ---
>   testcases/kernel/io/aio/aio02/Makefile  |  24 +--
>   testcases/kernel/io/aio/aio02/aio_tio.c | 201 +++++++++++++-----------
>   testcases/kernel/io/aio/aio02/common.h  |  28 ----
>   testcases/kernel/io/aio/aio02/main.c    |  37 -----

Given that aio02 is just a single file now it'd be a nice cleanup to get 
rid of the extra directory level here and just have

testcases/kernel/io/aio/aio01.c
testcases/kernel/io/aio/aio_tio.c
testcases/kernel/io/aio/Makefile

Not proposing that as part of this patch but rather just possible for 
someone to do in the future.

Also maybe renaming aio_tio.c to aio02.c. The only instance I see in 
runtest/ of aio_tio is as aio02.

>   4 files changed, 106 insertions(+), 184 deletions(-)
>   delete mode 100644 testcases/kernel/io/aio/aio02/common.h
>   delete mode 100644 testcases/kernel/io/aio/aio02/main.c
> 
> diff --git a/testcases/kernel/io/aio/aio02/Makefile b/testcases/kernel/io/aio/aio02/Makefile
> index a99807c26..629aa9a58 100644
> --- a/testcases/kernel/io/aio/aio02/Makefile
> +++ b/testcases/kernel/io/aio/aio02/Makefile
> @@ -1,36 +1,14 @@
> -#
> -#    kernel/io/aio/aio2 testcase Makefile.
> +// SPDX-License-Identifier: GPL-2.0-or-later
>   #
>   #    Copyright (C) 2009, Cisco Systems Inc.
>   #
> -#    This program is free software; you can redistribute it and/or modify
> -#    it under the terms of the GNU General Public License as published by
> -#    the Free Software Foundation; either version 2 of the License, or
> -#    (at your option) any later version.
> -#
> -#    This program is distributed in the hope that it will be useful,
> -#    but WITHOUT ANY WARRANTY; without even the implied warranty of
> -#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> -#    GNU General Public License for more details.
> -#
> -#    You should have received a copy of the GNU General Public License along
> -#    with this program; if not, write to the Free Software Foundation, Inc.,
> -#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> -#
> -# Ngie Cooper, July 2009
> -#
>   
>   top_srcdir		?= ../../../../..
>   
>   include $(top_srcdir)/include/mk/testcases.mk
>   
> -# Needed for common.h...
>   CPPFLAGS		+= -D_GNU_SOURCE
>   
>   LDLIBS			+= $(AIO_LIBS)
>   
> -FILTER_OUT_MAKE_TARGETS	:= main
> -
>   include $(top_srcdir)/include/mk/generic_leaf_target.mk
> -
> -$(MAKE_TARGETS): %: %.o main.o
> diff --git a/testcases/kernel/io/aio/aio02/aio_tio.c b/testcases/kernel/io/aio/aio02/aio_tio.c
> index db6fa2688..a55ff2663 100644
> --- a/testcases/kernel/io/aio/aio02/aio_tio.c
> +++ b/testcases/kernel/io/aio/aio02/aio_tio.c
> @@ -1,64 +1,59 @@
> -/*************************************************************************************
> -*
> -*  Copyright (c) International Business Machines  Corp., 2003
> -*
> -*  This program is free software;  you can redistribute it and/or modify
> -*  it under the terms of the GNU General Public License as published by
> -*  the Free Software Foundation; either version 2 of the License, or
> -*  (at your option) any later version.
> -*
> -*  This program is distributed in the hope that it will be useful,
> -*  but WITHOUT ANY WARRANTY;  without even the implied warranty of
> -*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
> -*  the GNU General Public License for more details.
> -*
> -*  You should have received a copy of the GNU General Public License
> -*  along with this program;  if not, write to the Free Software
> -*  Foundation,
> -*
> -*  FILE        : aio_tio
> -*  USAGE       : ./aio_tio
> -*
> -*  DESCRIPTION : This program will test Asynchronous I/O for 2.5 Kernel infrastructure
> -*  REQUIREMENTS:
> -*                1) libaio-0.3.92 or up for 2.5 kernal
> -*                2) glibc 2.1.91 or up
> -*  HISTORY     :
> -*      11/03/2003 Kai Zhao (ltcd3@cn.ibm.com)
> -*
> -*  CODE COVERAGE:
> -*                 68.3% - fs/aio.c
> -*
> -************************************************************************************/
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + *  Copyright (c) International Business Machines Corp., 2003
> + *
> + *  AUTHORS
> + *   Kai Zhao (ltcd3@cn.ibm.com)
> + *
> + *  DESCRIPTION : Test Asynchronous I/O for 2.5 Kernel Infrastructure
> + *
> + *  REQUIREMENTS:
> + *   1) libaio-0.3.92 or up for 2.5 kernel
> + *   2) glibc 2.1.91 or up
> + */
>   
>   #include "config.h"
> -#include "common.h"
> -#include "test.h"
> -#include "safe_macros.h"
> -#include <string.h>
> +#include "tst_test.h"
>   #include <errno.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
>   
>   #ifdef HAVE_LIBAIO
> +#include <libaio.h>
>   
>   #define AIO_MAXIO 32
>   #define AIO_BLKSIZE (64*1024)
>   
>   static int wait_count = 0;
>   
> +/*
> + * Fatal error handler
> + */
> +void io_error(const char *func, int rc)

can this be static (or better yet, just merge into work_done())

> +{
> +	if (rc == -ENOSYS)
> +		tst_brk(TCONF, "AIO not in this kernel\n");
> +	else if (rc < 0)
> +		tst_brk(TFAIL, "%s: %s\n", func, strerror(-rc));
> +	else
> +		tst_brk(TFAIL, "%s: error %d\n", func, rc);
> +}
> +
>   /*
>    * write work done
>    */
>   static void work_done(io_context_t ctx, struct iocb *iocb, long res, long res2)
>   {
> +	(void) ctx;  // silence compiler warning (-Wunused)
>   
>   	if (res2 != 0) {

can remove the braces here

>   		io_error("aio write", res2);
>   	}
>   
> -	if (res != iocb->u.c.nbytes) {
> -		fprintf(stderr, "write missed bytes expect %lu got %ld\n",
> +	if (res != (long)iocb->u.c.nbytes) {

can remove the braces here

> +		tst_brk(TFAIL, "write missed bytes expect %lu got %ld\n",
>   			iocb->u.c.nbytes, res);
> -		exit(1);
>   	}
>   	wait_count--;
>   }
> @@ -66,7 +61,7 @@ static void work_done(io_context_t ctx, struct iocb *iocb, long res, long res2)
>   /*
>    * io_wait_run() - wait for an io_event and then call the callback.
>    */
> -int io_wait_run(io_context_t ctx, struct timespec *to)
> +static int io_wait_run(io_context_t ctx, struct timespec *to)
>   {
>   	struct io_event events[AIO_MAXIO];
>   	struct io_event *ep;
> @@ -88,7 +83,7 @@ int io_wait_run(io_context_t ctx, struct timespec *to)
>   	return ret;
>   }
>   
> -int io_tio(char *pathname, int flag, int n, int operation)
> +static int io_tio(char *pathname, int flag, int n, int operation)

I noticed this fn is always getting called with n = AIO_MAXIO, is the 
parameter still needed as opposed to just hardcoding that in here

>   {
>   	int res, fd = 0, i = 0;
>   	void *bufptr = NULL;
> @@ -101,31 +96,26 @@ int io_tio(char *pathname, int flag, int n, int operation)
>   	struct iocb iocb_array[AIO_MAXIO];
>   	struct iocb *iocbps[AIO_MAXIO];
>   
> -	fd = open(pathname, flag, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
> -	if (fd <= 0) {
> -		printf("open for %s failed: %s\n", pathname, strerror(errno));
> -		return -1;
> -	}
> +	fd = SAFE_OPEN(pathname, flag, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
>   
>   	/* determine the alignment from the blksize of the underlying fs */
> -	SAFE_FSTAT(NULL, fd, &fi_stat);
> +	SAFE_FSTAT(fd, &fi_stat);
>   	alignment = fi_stat.st_blksize;
>   
>   	res = io_queue_init(n, &myctx);
> -	//printf (" res = %d \n", res);
>   
>   	for (i = 0; i < AIO_MAXIO; i++) {
>   
>   		switch (operation) {
>   		case IO_CMD_PWRITE:
>   			if (posix_memalign(&bufptr, alignment, AIO_BLKSIZE)) {
> -				perror(" posix_memalign failed ");
> +				tst_brk(TBROK | TERRNO, "posix_memalign failed");
>   				return -1;
>   			}
>   			memset(bufptr, 0, AIO_BLKSIZE);
>   
>   			io_prep_pwrite(&iocb_array[i], fd, bufptr,
> -				       AIO_BLKSIZE, offset);
> +					   AIO_BLKSIZE, offset);
>   			io_set_callback(&iocb_array[i], work_done);
>   			iocbps[i] = &iocb_array[i];
>   			offset += AIO_BLKSIZE;
> @@ -133,13 +123,13 @@ int io_tio(char *pathname, int flag, int n, int operation)
>   			break;
>   		case IO_CMD_PREAD:
>   			if (posix_memalign(&bufptr, alignment, AIO_BLKSIZE)) {
> -				perror(" posix_memalign failed ");
> +				tst_brk(TBROK | TERRNO, "posix_memalign failed");
>   				return -1;
>   			}
>   			memset(bufptr, 0, AIO_BLKSIZE);
>   
>   			io_prep_pread(&iocb_array[i], fd, bufptr,
> -				      AIO_BLKSIZE, offset);
> +					  AIO_BLKSIZE, offset);
>   			io_set_callback(&iocb_array[i], work_done);
>   			iocbps[i] = &iocb_array[i];
>   			offset += AIO_BLKSIZE;
> @@ -148,9 +138,7 @@ int io_tio(char *pathname, int flag, int n, int operation)
>   		case IO_CMD_NOOP:
>   			break;
>   		default:
> -			tst_resm(TFAIL,
> -				 "Command failed; opcode returned: %d\n",
> -				 operation);
> +			tst_res(TFAIL, "Command failed; opcode returned: %d\n", operation);
>   			return -1;
>   			break;
>   		}
> @@ -164,8 +152,8 @@ int io_tio(char *pathname, int flag, int n, int operation)
>   	}
>   
>   	/*
> -	 * We have submitted all the i/o requests. Wait for at least one to complete
> -	 * and call the callbacks.
> +	 * We have submitted all the i/o requests. Wait for at least one to
> +	 * complete and call the callbacks.

Is this comment accurate? It looks like we're waiting for all the io 
requests to complete (not at least one)

>   	 */
>   	wait_count = AIO_MAXIO;
>   
> @@ -185,7 +173,7 @@ int io_tio(char *pathname, int flag, int n, int operation)
>   		break;
>   	}
>   
> -	close(fd);
> +	SAFE_CLOSE(fd);
>   
>   	for (i = 0; i < AIO_MAXIO; i++) {
>   		if (iocb_array[i].u.c.buf != NULL) {
> @@ -198,49 +186,70 @@ int io_tio(char *pathname, int flag, int n, int operation)
>   	return 0;
>   }
>   
> -int test_main(void)
> +static void test_main(void)
>   {
> -	int status = 0;
> -
> -	tst_resm(TINFO, "Running test 1\n");
> -	status = io_tio("file1",
> -			O_TRUNC | O_DIRECT | O_WRONLY | O_CREAT | O_LARGEFILE,
> -			AIO_MAXIO, IO_CMD_PWRITE);
> -	if (status) {
> -		return status;
> -	}
> +	struct testcase {
> +		const char *description;
> +		int flags;
> +		int operation;
> +	} testcases[] = {
> +		{ .description =
> +		    "WRITE: O_WRONLY | O_TRUNC | O_DIRECT | O_LARGEFILE | O_CREAT",
> +		  .flags =  O_WRONLY | O_TRUNC | O_DIRECT | O_LARGEFILE | O_CREAT,
> +		  .operation = IO_CMD_PWRITE
> +		},
> +		{ .description =
> +		    "WRITE: O_RDONLY           | O_DIRECT | O_LARGEFILE",
> +		  .flags =  O_RDONLY           | O_DIRECT | O_LARGEFILE,
> +		  .operation = IO_CMD_PREAD
> +		},
> +		{ .description =
> +		    "WRITE: O_RDWR   | O_TRUNC",
> +		  .flags =  O_RDWR   | O_TRUNC,
> +		  .operation = IO_CMD_PWRITE
> +		},
> +		{ .description =
> +		    "READ : O_RDWR",
> +		  .flags =  O_RDWR,
> +		  .operation = IO_CMD_PREAD
> +		},
> +		{ .description =
> +		    "WRITE: O_WRONLY | O_TRUNC",
> +		  .flags =  O_WRONLY | O_TRUNC,
> +		  .operation = IO_CMD_PWRITE
> +		},
> +		{ .description =
> +		    "READ : O_RDONLY",
> +		  .flags =  O_RDONLY,
> +		  .operation = IO_CMD_PREAD
> +		},
> +	};
>   
> -	tst_resm(TINFO, "Running test 2\n");
> -	status = io_tio("file1", O_RDONLY | O_DIRECT | O_LARGEFILE,
> -			AIO_MAXIO, IO_CMD_PREAD);
> -	if (status) {
> -		return status;
> -	}
> -
> -	tst_resm(TINFO, "Running test 3\n");
> -	status = io_tio("file1", O_TRUNC | O_RDWR, AIO_MAXIO, IO_CMD_PWRITE);
> -	if (status) {
> -		return status;
> -	}
> -
> -	tst_resm(TINFO, "Running test 4\n");
> -	status = io_tio("file1", O_RDWR, AIO_MAXIO, IO_CMD_PREAD);
> -	if (status) {
> -		return status;
> -	}
> +	int status = 0;
>   
> -	tst_resm(TINFO, "Running test 5\n");
> -	status = io_tio("file1", O_TRUNC | O_WRONLY, AIO_MAXIO, IO_CMD_PWRITE);
> -	if (status) {
> -		return status;
> +	for (size_t i = 0; i < ARRAY_SIZE(testcases); ++i) {
> +		tst_res(TINFO, "%s", testcases[i].description);
> +		status = io_tio("file", testcases[i].flags, AIO_MAXIO,
> +				testcases[i].operation);
> +		if (status) {
> +			tst_res(TFAIL, "%s, status = %d",
> +					testcases[i].description, status);
> +		} else {
> +			tst_res(TPASS, "%s", testcases[i].description);
> +		}
>   	}

The LTP lib has support for testcases that have multiple subtests like 
this, see for example testcases/kernel/syscalls/access01.c. It'll save 
you having to iterate over the subtests here.

I thought maybe it would also allow running individual subtests directly 
from the command line - that doesn't seem to be supported currently but 
perhaps will in the future.

> +}
>   
> -	tst_resm(TINFO, "Running test 6 \n");
> -	status = io_tio("file1", O_RDONLY, AIO_MAXIO, IO_CMD_PREAD);
> -	if (status) {
> -		return status;
> -	}
> +#else
>   
> -	return status;
> +static void test_main(void)
> +{
> +	tst_brk(TCONF, "test requires libaio and it's development packages");

nit, its instead of it's

>   }
> +
>   #endif
> +
> +static struct tst_test test = {
> +	.needs_tmpdir = 1,
> +	.test_all = test_main
> +};
> diff --git a/testcases/kernel/io/aio/aio02/common.h b/testcases/kernel/io/aio/aio02/common.h
> deleted file mode 100644
> index 4b80761a6..000000000
> --- a/testcases/kernel/io/aio/aio02/common.h
> +++ /dev/null
> @@ -1,28 +0,0 @@
> -#include <sys/types.h>
> -#include <sys/stat.h>
> -#include <fcntl.h>
> -#include <sys/param.h>
> -#include <errno.h>
> -#include <stdlib.h>
> -#include <sys/select.h>
> -#if HAVE_LIBAIO_H
> -#include <libaio.h>
> -#endif
> -#include <sys/uio.h>
> -#include <assert.h>
> -#include <unistd.h>
> -#include <stdio.h>
> -#include <string.h>
> -
> -/* Fatal error handler */
> -static void io_error(const char *func, int rc)
> -{
> -	if (rc == -ENOSYS)
> -		fprintf(stderr, "AIO not in this kernel\n");
> -	else if (rc < 0)
> -		fprintf(stderr, "%s: %s\n", func, strerror(-rc));
> -	else
> -		fprintf(stderr, "%s: error %d\n", func, rc);
> -
> -	exit(1);
> -}
> diff --git a/testcases/kernel/io/aio/aio02/main.c b/testcases/kernel/io/aio/aio02/main.c
> deleted file mode 100644
> index 7b157f31b..000000000
> --- a/testcases/kernel/io/aio/aio02/main.c
> +++ /dev/null
> @@ -1,37 +0,0 @@
> -#include <stdio.h>
> -#include <errno.h>
> -#include <assert.h>
> -#include <stdlib.h>
> -#include <fcntl.h>
> -#include <sys/types.h>
> -#include <sys/stat.h>
> -#include <unistd.h>
> -
> -#include "config.h"
> -#include "test.h"
> -
> -#define TEST_NAME "aio_tio"
> -
> -char *TCID = "aio02/" TEST_NAME;
> -int TST_TOTAL = 0;
> -
> -#ifdef HAVE_LIBAIO
> -#include <libaio.h>
> -
> -int test_main(void);
> -
> -int main(void)
> -{
> -	tst_tmpdir();
> -
> -	test_main();
> -
> -	tst_rmdir();
> -	tst_exit();
> -}
> -#else
> -int main(void)
> -{
> -	tst_brkm(TCONF, NULL, "test requires libaio and it's development packages");
> -}
> -#endif
> 


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

* [LTP] [PATCH v2 2/2] aio_tio: determine alignment based on target filesystem
  2019-02-22 15:33   ` Cyril Hrubis
@ 2019-02-26 15:37     ` Matthias =?unknown-8bit?q?M=C3=A4nnich?=
  0 siblings, 0 replies; 18+ messages in thread
From: Matthias =?unknown-8bit?q?M=C3=A4nnich?= @ 2019-02-26 15:37 UTC (permalink / raw)
  To: ltp

Hi!

On 22/02/2019 15:33, Cyril Hrubis wrote:
>> The alignment for O_DIRECT operations has to match the blocksize of the
>> underlying filesystem. Determine the alignment from the target file's
>> file system.
>>
>> aio_tio test cases 1 and 2 failed (nondeterministic) on aarch64 when run
>> on a 4096 byte blocksize filesystem and with an alignment of 512 bytes.
> 
> Is this really about the filesystem? Citing man open:
> 
>         Under Linux 2.4, transfer sizes, and the alignment of the  user  buffer
>         and  the file offset must all be multiples of the logical block size of
>         the filesystem.  Since Linux 2.6.0, alignment to the logical block size
>         of  the underlying storage (typically 512 bytes) suffices.  The logical
>         block size can be determined using the ioctl(2) BLKSSZGET operation  or
>         from the shell using the command:
> 
>         blockdev --getss
> 
> So unless you are running ancient 2.4 kernel the aligment restrictions should
> be result of the blocksize of the device rather than of the filesystem.

Yes. You are right. The blocksize of the device is what I was referring 
to. Sorry for that.
In particular the test hits the alignment check in fs/direct-io.c 
(do_blockdev_direct_IO) [1], which makes the direct io operation fail in 
my case with EINVAL.

> What does the blockdev command return on the particular system?
4096

I will update the patch to correct comment and commit message.

Thanks,
Matthias

[1] https://elixir.bootlin.com/linux/v4.20/source/fs/direct-io.c#L1199

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

* [LTP] [PATCH v4 0/3] aio_tio: fixes and conversion to new lib
  2019-01-11  8:53 [LTP] [PATCH v2 1/2] aio_tio: fix error diagnosis for byte transfers Matthias Maennich
                   ` (2 preceding siblings ...)
  2019-02-22 15:28 ` [LTP] [PATCH v2 1/2] aio_tio: fix error diagnosis for byte transfers Cyril Hrubis
@ 2019-02-26 17:02 ` Matthias Maennich
  2019-02-26 17:02   ` [LTP] [PATCH v4 1/3] aio_tio: determine alignment based on target block device Matthias Maennich
                     ` (2 more replies)
  3 siblings, 3 replies; 18+ messages in thread
From: Matthias Maennich @ 2019-02-26 17:02 UTC (permalink / raw)
  To: ltp

This patch series fixes aio_tio and migrates the test to the new lib
along with some cleanup.

v3->v4: - address review comments
        - add directory cleanup patch

Matthias Maennich (3):
  aio_tio: determine alignment based on target block device
  aio_tio: convert to new lib
  io/aio: cleanup test directory

 runtest/io                                  |   2 +-
 testcases/kernel/io/aio/.gitignore          |   4 +-
 testcases/kernel/io/aio/Makefile            |  22 +-
 testcases/kernel/io/aio/{aio01 => }/aio01.c |   0
 testcases/kernel/io/aio/aio01/Makefile      |  30 ---
 testcases/kernel/io/aio/aio02.c             | 246 ++++++++++++++++++++
 testcases/kernel/io/aio/aio02/Makefile      |  36 ---
 testcases/kernel/io/aio/aio02/README        |  12 -
 testcases/kernel/io/aio/aio02/aio_tio.c     | 240 -------------------
 testcases/kernel/io/aio/aio02/common.h      |  28 ---
 testcases/kernel/io/aio/aio02/main.c        |  37 ---
 11 files changed, 256 insertions(+), 401 deletions(-)
 rename testcases/kernel/io/aio/{aio01 => }/aio01.c (100%)
 delete mode 100644 testcases/kernel/io/aio/aio01/Makefile
 create mode 100644 testcases/kernel/io/aio/aio02.c
 delete mode 100644 testcases/kernel/io/aio/aio02/Makefile
 delete mode 100644 testcases/kernel/io/aio/aio02/README
 delete mode 100644 testcases/kernel/io/aio/aio02/aio_tio.c
 delete mode 100644 testcases/kernel/io/aio/aio02/common.h
 delete mode 100644 testcases/kernel/io/aio/aio02/main.c

-- 
2.21.0.rc2.261.ga7da99ff1b-goog


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

* [LTP] [PATCH v4 1/3] aio_tio: determine alignment based on target block device
  2019-02-26 17:02 ` [LTP] [PATCH v4 0/3] aio_tio: fixes and conversion to new lib Matthias Maennich
@ 2019-02-26 17:02   ` Matthias Maennich
  2019-02-26 17:02   ` [LTP] [PATCH v4 2/3] aio_tio: convert to new lib Matthias Maennich
  2019-02-26 17:02   ` [LTP] [PATCH v4 3/3] io/aio: cleanup test directory Matthias Maennich
  2 siblings, 0 replies; 18+ messages in thread
From: Matthias Maennich @ 2019-02-26 17:02 UTC (permalink / raw)
  To: ltp

The alignment for O_DIRECT operations has to match the blocksize of the
underlying block device. Determine the alignment from the target file.

aio_tio test cases 1 and 2 failed (nondeterministic) on aarch64 when run
on a 4096 byte blocksize and with an alignment of 512 bytes.

Determining the blocksize from the block device and using it for the
alignment resolves the test issue.

Signed-off-by: Matthias Maennich <maennich@google.com>
Reviewed-by: Alessio Balsini <balsini@google.com>
Reviewed-by: Steve Muckle <smuckle@google.com>
---
 testcases/kernel/io/aio/aio02/aio_tio.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/io/aio/aio02/aio_tio.c b/testcases/kernel/io/aio/aio02/aio_tio.c
index 623c81a5e..ddf71e85b 100644
--- a/testcases/kernel/io/aio/aio02/aio_tio.c
+++ b/testcases/kernel/io/aio/aio02/aio_tio.c
@@ -34,6 +34,7 @@
 #include "config.h"
 #include "common.h"
 #include "test.h"
+#include "safe_macros.h"
 #include <string.h>
 #include <errno.h>
 
@@ -42,7 +43,6 @@
 #define AIO_MAXIO 32
 #define AIO_BLKSIZE (64*1024)
 
-static int alignment = 512;
 static int wait_count = 0;
 
 /*
@@ -94,6 +94,8 @@ int io_tio(char *pathname, int flag, int n, int operation)
 	void *bufptr = NULL;
 	off_t offset = 0;
 	struct timespec timeout;
+	struct stat fi_stat;
+	size_t alignment;
 
 	io_context_t myctx;
 	struct iocb iocb_array[AIO_MAXIO];
@@ -105,6 +107,10 @@ int io_tio(char *pathname, int flag, int n, int operation)
 		return -1;
 	}
 
+	/* determine the alignment from the blksize of the underlying device */
+	SAFE_FSTAT(NULL, fd, &fi_stat);
+	alignment = fi_stat.st_blksize;
+
 	res = io_queue_init(n, &myctx);
 	//printf (" res = %d \n", res);
 
-- 
2.21.0.rc2.261.ga7da99ff1b-goog


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

* [LTP] [PATCH v4 2/3] aio_tio: convert to new lib
  2019-02-26 17:02 ` [LTP] [PATCH v4 0/3] aio_tio: fixes and conversion to new lib Matthias Maennich
  2019-02-26 17:02   ` [LTP] [PATCH v4 1/3] aio_tio: determine alignment based on target block device Matthias Maennich
@ 2019-02-26 17:02   ` Matthias Maennich
  2019-02-26 19:13     ` Steve Muckle
  2019-03-15 11:50     ` Petr Vorel
  2019-02-26 17:02   ` [LTP] [PATCH v4 3/3] io/aio: cleanup test directory Matthias Maennich
  2 siblings, 2 replies; 18+ messages in thread
From: Matthias Maennich @ 2019-02-26 17:02 UTC (permalink / raw)
  To: ltp

Convert to the new test lib and perform various cleanups.
Also refactor the test definition for readability.

Signed-off-by: Matthias Maennich <maennich@google.com>
---
 testcases/kernel/io/aio/aio02/Makefile  |  24 +--
 testcases/kernel/io/aio/aio02/aio_tio.c | 218 ++++++++++++------------
 testcases/kernel/io/aio/aio02/common.h  |  28 ---
 testcases/kernel/io/aio/aio02/main.c    |  37 ----
 4 files changed, 110 insertions(+), 197 deletions(-)
 delete mode 100644 testcases/kernel/io/aio/aio02/common.h
 delete mode 100644 testcases/kernel/io/aio/aio02/main.c

diff --git a/testcases/kernel/io/aio/aio02/Makefile b/testcases/kernel/io/aio/aio02/Makefile
index a99807c26..629aa9a58 100644
--- a/testcases/kernel/io/aio/aio02/Makefile
+++ b/testcases/kernel/io/aio/aio02/Makefile
@@ -1,36 +1,14 @@
-#
-#    kernel/io/aio/aio2 testcase Makefile.
+// SPDX-License-Identifier: GPL-2.0-or-later
 #
 #    Copyright (C) 2009, Cisco Systems Inc.
 #
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
 
-# Needed for common.h...
 CPPFLAGS		+= -D_GNU_SOURCE
 
 LDLIBS			+= $(AIO_LIBS)
 
-FILTER_OUT_MAKE_TARGETS	:= main
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
-
-$(MAKE_TARGETS): %: %.o main.o
diff --git a/testcases/kernel/io/aio/aio02/aio_tio.c b/testcases/kernel/io/aio/aio02/aio_tio.c
index ddf71e85b..be53ace68 100644
--- a/testcases/kernel/io/aio/aio02/aio_tio.c
+++ b/testcases/kernel/io/aio/aio02/aio_tio.c
@@ -1,72 +1,100 @@
-/*************************************************************************************
-*
-*  Copyright (c) International Business Machines  Corp., 2003
-*
-*  This program is free software;  you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  This program is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-*  the GNU General Public License for more details.
-*
-*  You should have received a copy of the GNU General Public License
-*  along with this program;  if not, write to the Free Software
-*  Foundation,
-*
-*  FILE        : aio_tio
-*  USAGE       : ./aio_tio
-*
-*  DESCRIPTION : This program will test Asynchronous I/O for 2.5 Kernel infrastructure
-*  REQUIREMENTS:
-*                1) libaio-0.3.92 or up for 2.5 kernal
-*                2) glibc 2.1.91 or up
-*  HISTORY     :
-*      11/03/2003 Kai Zhao (ltcd3@cn.ibm.com)
-*
-*  CODE COVERAGE:
-*                 68.3% - fs/aio.c
-*
-************************************************************************************/
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ *  Copyright (c) International Business Machines Corp., 2003
+ *
+ *  AUTHORS
+ *   Kai Zhao (ltcd3@cn.ibm.com)
+ *
+ *  DESCRIPTION : Test Asynchronous I/O for 2.5 Kernel Infrastructure
+ *
+ *  REQUIREMENTS:
+ *   1) libaio-0.3.92 or up for 2.5 kernel
+ *   2) glibc 2.1.91 or up
+ */
 
 #include "config.h"
-#include "common.h"
-#include "test.h"
-#include "safe_macros.h"
-#include <string.h>
+#include "tst_test.h"
 #include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
 #ifdef HAVE_LIBAIO
+#include <libaio.h>
 
 #define AIO_MAXIO 32
 #define AIO_BLKSIZE (64*1024)
 
 static int wait_count = 0;
 
+/*
+ * test case definition
+ */
+struct testcase {
+	const char *description;
+	int flags;
+	int operation;
+} testcases[] = {
+	{"WRITE: O_WRONLY | O_TRUNC | O_DIRECT | O_LARGEFILE | O_CREAT",
+	         O_WRONLY | O_TRUNC | O_DIRECT | O_LARGEFILE | O_CREAT,
+	  IO_CMD_PWRITE
+	},
+	{"WRITE: O_RDONLY           | O_DIRECT | O_LARGEFILE",
+	         O_RDONLY           | O_DIRECT | O_LARGEFILE,
+	 IO_CMD_PREAD
+	},
+	{"WRITE: O_RDWR   | O_TRUNC",
+	         O_RDWR   | O_TRUNC,
+	 IO_CMD_PWRITE
+	},
+	{"READ : O_RDWR",
+	         O_RDWR,
+	 IO_CMD_PREAD
+	},
+	{"WRITE: O_WRONLY | O_TRUNC",
+	         O_WRONLY | O_TRUNC,
+	 IO_CMD_PWRITE
+	},
+	{"READ : O_RDONLY",
+	         O_RDONLY,
+	 IO_CMD_PREAD
+	},
+};
+
+/*
+ * Fatal error handler
+ */
+static void io_error(const char *func, int rc)
+{
+	if (rc == -ENOSYS)
+		tst_brk(TCONF, "AIO not in this kernel\n");
+	else if (rc < 0)
+		tst_brk(TFAIL, "%s: %s\n", func, strerror(-rc));
+	else
+		tst_brk(TFAIL, "%s: error %d\n", func, rc);
+}
+
 /*
  * write work done
  */
 static void work_done(io_context_t ctx, struct iocb *iocb, long res, long res2)
 {
+	(void) ctx;  // silence compiler warning (-Wunused)
 
-	if (res2 != 0) {
+	if (res2 != 0)
 		io_error("aio write", res2);
-	}
 
-	if (res != iocb->u.c.nbytes) {
-		fprintf(stderr, "write missed bytes expect %lu got %ld\n",
+	if (res != (long)iocb->u.c.nbytes)
+		tst_brk(TFAIL, "write missed bytes expect %lu got %ld\n",
 			iocb->u.c.nbytes, res);
-		exit(1);
-	}
+
 	wait_count--;
 }
 
 /*
  * io_wait_run() - wait for an io_event and then call the callback.
  */
-int io_wait_run(io_context_t ctx, struct timespec *to)
+static int io_wait_run(io_context_t ctx, struct timespec *to)
 {
 	struct io_event events[AIO_MAXIO];
 	struct io_event *ep;
@@ -88,7 +116,7 @@ int io_wait_run(io_context_t ctx, struct timespec *to)
 	return ret;
 }
 
-int io_tio(char *pathname, int flag, int n, int operation)
+static int io_tio(char *pathname, int flag, int operation)
 {
 	int res, fd = 0, i = 0;
 	void *bufptr = NULL;
@@ -101,31 +129,26 @@ int io_tio(char *pathname, int flag, int n, int operation)
 	struct iocb iocb_array[AIO_MAXIO];
 	struct iocb *iocbps[AIO_MAXIO];
 
-	fd = open(pathname, flag, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
-	if (fd <= 0) {
-		printf("open for %s failed: %s\n", pathname, strerror(errno));
-		return -1;
-	}
+	fd = SAFE_OPEN(pathname, flag, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
 
 	/* determine the alignment from the blksize of the underlying device */
-	SAFE_FSTAT(NULL, fd, &fi_stat);
+	SAFE_FSTAT(fd, &fi_stat);
 	alignment = fi_stat.st_blksize;
 
-	res = io_queue_init(n, &myctx);
-	//printf (" res = %d \n", res);
+	res = io_queue_init(AIO_MAXIO, &myctx);
 
 	for (i = 0; i < AIO_MAXIO; i++) {
 
 		switch (operation) {
 		case IO_CMD_PWRITE:
 			if (posix_memalign(&bufptr, alignment, AIO_BLKSIZE)) {
-				perror(" posix_memalign failed ");
+				tst_brk(TBROK | TERRNO, "posix_memalign failed");
 				return -1;
 			}
 			memset(bufptr, 0, AIO_BLKSIZE);
 
 			io_prep_pwrite(&iocb_array[i], fd, bufptr,
-				       AIO_BLKSIZE, offset);
+					   AIO_BLKSIZE, offset);
 			io_set_callback(&iocb_array[i], work_done);
 			iocbps[i] = &iocb_array[i];
 			offset += AIO_BLKSIZE;
@@ -133,13 +156,13 @@ int io_tio(char *pathname, int flag, int n, int operation)
 			break;
 		case IO_CMD_PREAD:
 			if (posix_memalign(&bufptr, alignment, AIO_BLKSIZE)) {
-				perror(" posix_memalign failed ");
+				tst_brk(TBROK | TERRNO, "posix_memalign failed");
 				return -1;
 			}
 			memset(bufptr, 0, AIO_BLKSIZE);
 
 			io_prep_pread(&iocb_array[i], fd, bufptr,
-				      AIO_BLKSIZE, offset);
+					  AIO_BLKSIZE, offset);
 			io_set_callback(&iocb_array[i], work_done);
 			iocbps[i] = &iocb_array[i];
 			offset += AIO_BLKSIZE;
@@ -148,9 +171,7 @@ int io_tio(char *pathname, int flag, int n, int operation)
 		case IO_CMD_NOOP:
 			break;
 		default:
-			tst_resm(TFAIL,
-				 "Command failed; opcode returned: %d\n",
-				 operation);
+			tst_res(TFAIL, "Command failed; opcode returned: %d\n", operation);
 			return -1;
 			break;
 		}
@@ -159,13 +180,13 @@ int io_tio(char *pathname, int flag, int n, int operation)
 	do {
 		res = io_submit(myctx, AIO_MAXIO, iocbps);
 	} while (res == -EAGAIN);
-	if (res < 0) {
+
+	if (res < 0)
 		io_error("io_submit tio", res);
-	}
 
 	/*
-	 * We have submitted all the i/o requests. Wait for@least one to complete
-	 * and call the callbacks.
+	 * We have submitted all the i/o requests. Wait for them to complete and
+	 * call the callbacks.
 	 */
 	wait_count = AIO_MAXIO;
 
@@ -185,62 +206,41 @@ int io_tio(char *pathname, int flag, int n, int operation)
 		break;
 	}
 
-	close(fd);
+	SAFE_CLOSE(fd);
 
-	for (i = 0; i < AIO_MAXIO; i++) {
-		if (iocb_array[i].u.c.buf != NULL) {
+	for (i = 0; i < AIO_MAXIO; i++)
+		if (iocb_array[i].u.c.buf != NULL)
 			free(iocb_array[i].u.c.buf);
-		}
-	}
 
 	io_queue_release(myctx);
 
 	return 0;
 }
 
-int test_main(void)
+static void test_io(unsigned int n)
 {
-	int status = 0;
-
-	tst_resm(TINFO, "Running test 1\n");
-	status = io_tio("file1",
-			O_TRUNC | O_DIRECT | O_WRONLY | O_CREAT | O_LARGEFILE,
-			AIO_MAXIO, IO_CMD_PWRITE);
-	if (status) {
-		return status;
-	}
-
-	tst_resm(TINFO, "Running test 2\n");
-	status = io_tio("file1", O_RDONLY | O_DIRECT | O_LARGEFILE,
-			AIO_MAXIO, IO_CMD_PREAD);
-	if (status) {
-		return status;
-	}
-
-	tst_resm(TINFO, "Running test 3\n");
-	status = io_tio("file1", O_TRUNC | O_RDWR, AIO_MAXIO, IO_CMD_PWRITE);
-	if (status) {
-		return status;
-	}
-
-	tst_resm(TINFO, "Running test 4\n");
-	status = io_tio("file1", O_RDWR, AIO_MAXIO, IO_CMD_PREAD);
-	if (status) {
-		return status;
-	}
-
-	tst_resm(TINFO, "Running test 5\n");
-	status = io_tio("file1", O_TRUNC | O_WRONLY, AIO_MAXIO, IO_CMD_PWRITE);
-	if (status) {
-		return status;
-	}
+	int status;
+	struct testcase *tc = testcases + n;
+
+	tst_res(TINFO, "%s", tc->description);
+	status = io_tio("file", tc->flags, tc->operation);
+	if (status)
+		tst_res(TFAIL, "%s, status = %d", tc->description, status);
+	else
+		tst_res(TPASS, "%s", tc->description);
+}
 
-	tst_resm(TINFO, "Running test 6 \n");
-	status = io_tio("file1", O_RDONLY, AIO_MAXIO, IO_CMD_PREAD);
-	if (status) {
-		return status;
-	}
+#else
 
-	return status;
+static void test_main(void)
+{
+	tst_brk(TCONF, "test requires libaio and its development packages");
 }
+
 #endif
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.test = test_io,
+	.tcnt = ARRAY_SIZE(testcases),
+};
diff --git a/testcases/kernel/io/aio/aio02/common.h b/testcases/kernel/io/aio/aio02/common.h
deleted file mode 100644
index 4b80761a6..000000000
--- a/testcases/kernel/io/aio/aio02/common.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/param.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <sys/select.h>
-#if HAVE_LIBAIO_H
-#include <libaio.h>
-#endif
-#include <sys/uio.h>
-#include <assert.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-
-/* Fatal error handler */
-static void io_error(const char *func, int rc)
-{
-	if (rc == -ENOSYS)
-		fprintf(stderr, "AIO not in this kernel\n");
-	else if (rc < 0)
-		fprintf(stderr, "%s: %s\n", func, strerror(-rc));
-	else
-		fprintf(stderr, "%s: error %d\n", func, rc);
-
-	exit(1);
-}
diff --git a/testcases/kernel/io/aio/aio02/main.c b/testcases/kernel/io/aio/aio02/main.c
deleted file mode 100644
index 7b157f31b..000000000
--- a/testcases/kernel/io/aio/aio02/main.c
+++ /dev/null
@@ -1,37 +0,0 @@
-#include <stdio.h>
-#include <errno.h>
-#include <assert.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#include "config.h"
-#include "test.h"
-
-#define TEST_NAME "aio_tio"
-
-char *TCID = "aio02/" TEST_NAME;
-int TST_TOTAL = 0;
-
-#ifdef HAVE_LIBAIO
-#include <libaio.h>
-
-int test_main(void);
-
-int main(void)
-{
-	tst_tmpdir();
-
-	test_main();
-
-	tst_rmdir();
-	tst_exit();
-}
-#else
-int main(void)
-{
-	tst_brkm(TCONF, NULL, "test requires libaio and it's development packages");
-}
-#endif
-- 
2.21.0.rc2.261.ga7da99ff1b-goog


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

* [LTP] [PATCH v4 3/3] io/aio: cleanup test directory
  2019-02-26 17:02 ` [LTP] [PATCH v4 0/3] aio_tio: fixes and conversion to new lib Matthias Maennich
  2019-02-26 17:02   ` [LTP] [PATCH v4 1/3] aio_tio: determine alignment based on target block device Matthias Maennich
  2019-02-26 17:02   ` [LTP] [PATCH v4 2/3] aio_tio: convert to new lib Matthias Maennich
@ 2019-02-26 17:02   ` Matthias Maennich
  2019-02-26 19:16     ` Steve Muckle
  2 siblings, 1 reply; 18+ messages in thread
From: Matthias Maennich @ 2019-02-26 17:02 UTC (permalink / raw)
  To: ltp

Now that aio_tio is just a single file test, consolidate the aio tests
within io/aio.

Suggested-by: Steve Muckle <smuckle@google.com>
Signed-off-by: Matthias Maennich <maennich@google.com>
---
 runtest/io                                    |  2 +-
 testcases/kernel/io/aio/.gitignore            |  4 +--
 testcases/kernel/io/aio/Makefile              | 22 +++++---------
 testcases/kernel/io/aio/{aio01 => }/aio01.c   |  0
 testcases/kernel/io/aio/aio01/Makefile        | 30 -------------------
 .../io/aio/{aio02/aio_tio.c => aio02.c}       |  0
 testcases/kernel/io/aio/aio02/Makefile        | 14 ---------
 testcases/kernel/io/aio/aio02/README          | 12 --------
 8 files changed, 10 insertions(+), 74 deletions(-)
 rename testcases/kernel/io/aio/{aio01 => }/aio01.c (100%)
 delete mode 100644 testcases/kernel/io/aio/aio01/Makefile
 rename testcases/kernel/io/aio/{aio02/aio_tio.c => aio02.c} (100%)
 delete mode 100644 testcases/kernel/io/aio/aio02/Makefile
 delete mode 100644 testcases/kernel/io/aio/aio02/README

diff --git a/runtest/io b/runtest/io
index 00032ffde..cd51cce3c 100644
--- a/runtest/io
+++ b/runtest/io
@@ -1,3 +1,3 @@
 #AIO01 & AIO02 tests to be run
 aio01 aio01
-aio02 aio_tio
+aio02 aio02
diff --git a/testcases/kernel/io/aio/.gitignore b/testcases/kernel/io/aio/.gitignore
index 646af5479..81cc7c4fa 100644
--- a/testcases/kernel/io/aio/.gitignore
+++ b/testcases/kernel/io/aio/.gitignore
@@ -1,2 +1,2 @@
-/aio01/aio01
-/aio02/aio_tio
+aio01
+aio02
diff --git a/testcases/kernel/io/aio/Makefile b/testcases/kernel/io/aio/Makefile
index daf81f50e..13ed4a395 100644
--- a/testcases/kernel/io/aio/Makefile
+++ b/testcases/kernel/io/aio/Makefile
@@ -1,22 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 #
 #  Copyright (c) International Business Machines  Corp., 2001
 #
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-#
 
 top_srcdir		?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
-include $(top_srcdir)/include/mk/generic_trunk_target.mk
+
+CPPFLAGS		+= -D_GNU_SOURCE
+
+LDLIBS			+= $(AIO_LIBS)
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/io/aio/aio01/aio01.c b/testcases/kernel/io/aio/aio01.c
similarity index 100%
rename from testcases/kernel/io/aio/aio01/aio01.c
rename to testcases/kernel/io/aio/aio01.c
diff --git a/testcases/kernel/io/aio/aio01/Makefile b/testcases/kernel/io/aio/aio01/Makefile
deleted file mode 100644
index 9a0ad7732..000000000
--- a/testcases/kernel/io/aio/aio01/Makefile
+++ /dev/null
@@ -1,30 +0,0 @@
-#
-#  Copyright (c) International Business Machines  Corp., 2001
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-#
-
-###########################################################################
-# name of file	: Makefile						  #
-# description	: make(1) description file                                #
-###########################################################################
-
-top_srcdir		?= ../../../../..
-
-include $(top_srcdir)/include/mk/testcases.mk
-
-LDLIBS			+= $(AIO_LIBS)
-
-include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/io/aio/aio02/aio_tio.c b/testcases/kernel/io/aio/aio02.c
similarity index 100%
rename from testcases/kernel/io/aio/aio02/aio_tio.c
rename to testcases/kernel/io/aio/aio02.c
diff --git a/testcases/kernel/io/aio/aio02/Makefile b/testcases/kernel/io/aio/aio02/Makefile
deleted file mode 100644
index 629aa9a58..000000000
--- a/testcases/kernel/io/aio/aio02/Makefile
+++ /dev/null
@@ -1,14 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-
-top_srcdir		?= ../../../../..
-
-include $(top_srcdir)/include/mk/testcases.mk
-
-CPPFLAGS		+= -D_GNU_SOURCE
-
-LDLIBS			+= $(AIO_LIBS)
-
-include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/io/aio/aio02/README b/testcases/kernel/io/aio/aio02/README
deleted file mode 100644
index 81ab36e22..000000000
--- a/testcases/kernel/io/aio/aio02/README
+++ /dev/null
@@ -1,12 +0,0 @@
-This program will test Asynchronous I/O support by kernel 2.5 .
-make the program
-	make
-execute the test
-	./aio_tio
-
-
-NOTE:
-	make sure your system are support with libaio-0.3.92 or higher.
-		you can download this form http://www.kernel.org.
-	make sure your system are support with glibc 2.1.91 or higher.
-
-- 
2.21.0.rc2.261.ga7da99ff1b-goog


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

* [LTP] [PATCH v4 2/3] aio_tio: convert to new lib
  2019-02-26 17:02   ` [LTP] [PATCH v4 2/3] aio_tio: convert to new lib Matthias Maennich
@ 2019-02-26 19:13     ` Steve Muckle
  2019-03-15 11:50     ` Petr Vorel
  1 sibling, 0 replies; 18+ messages in thread
From: Steve Muckle @ 2019-02-26 19:13 UTC (permalink / raw)
  To: ltp

On 02/26/2019 09:02 AM, Matthias Maennich wrote:
> Convert to the new test lib and perform various cleanups.
> Also refactor the test definition for readability.
> 
> Signed-off-by: Matthias Maennich <maennich@google.com>
> ---
>   testcases/kernel/io/aio/aio02/Makefile  |  24 +--
>   testcases/kernel/io/aio/aio02/aio_tio.c | 218 ++++++++++++------------
>   testcases/kernel/io/aio/aio02/common.h  |  28 ---
>   testcases/kernel/io/aio/aio02/main.c    |  37 ----
>   4 files changed, 110 insertions(+), 197 deletions(-)
>   delete mode 100644 testcases/kernel/io/aio/aio02/common.h
>   delete mode 100644 testcases/kernel/io/aio/aio02/main.c

Reviewed-by: Steve Muckle <smuckle@google.com>

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

* [LTP] [PATCH v4 3/3] io/aio: cleanup test directory
  2019-02-26 17:02   ` [LTP] [PATCH v4 3/3] io/aio: cleanup test directory Matthias Maennich
@ 2019-02-26 19:16     ` Steve Muckle
  0 siblings, 0 replies; 18+ messages in thread
From: Steve Muckle @ 2019-02-26 19:16 UTC (permalink / raw)
  To: ltp

On 02/26/2019 09:02 AM, Matthias Maennich wrote:
> Now that aio_tio is just a single file test, consolidate the aio tests
> within io/aio.
> 
> Suggested-by: Steve Muckle <smuckle@google.com>
> Signed-off-by: Matthias Maennich <maennich@google.com>
> ---
>   runtest/io                                    |  2 +-
>   testcases/kernel/io/aio/.gitignore            |  4 +--
>   testcases/kernel/io/aio/Makefile              | 22 +++++---------
>   testcases/kernel/io/aio/{aio01 => }/aio01.c   |  0
>   testcases/kernel/io/aio/aio01/Makefile        | 30 -------------------
>   .../io/aio/{aio02/aio_tio.c => aio02.c}       |  0
>   testcases/kernel/io/aio/aio02/Makefile        | 14 ---------
>   testcases/kernel/io/aio/aio02/README          | 12 --------
>   8 files changed, 10 insertions(+), 74 deletions(-)
>   rename testcases/kernel/io/aio/{aio01 => }/aio01.c (100%)
>   delete mode 100644 testcases/kernel/io/aio/aio01/Makefile
>   rename testcases/kernel/io/aio/{aio02/aio_tio.c => aio02.c} (100%)
>   delete mode 100644 testcases/kernel/io/aio/aio02/Makefile
>   delete mode 100644 testcases/kernel/io/aio/aio02/README

Reviewed-by: Steve Muckle <smuckle@google.com>

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

* [LTP] [PATCH v4 2/3] aio_tio: convert to new lib
  2019-02-26 17:02   ` [LTP] [PATCH v4 2/3] aio_tio: convert to new lib Matthias Maennich
  2019-02-26 19:13     ` Steve Muckle
@ 2019-03-15 11:50     ` Petr Vorel
  1 sibling, 0 replies; 18+ messages in thread
From: Petr Vorel @ 2019-03-15 11:50 UTC (permalink / raw)
  To: ltp

Hi Matthias,

> Convert to the new test lib and perform various cleanups.
> Also refactor the test definition for readability.

Thanks for your work, whole patchset pushed, with following fixes and further
cleanup.

Defining struct tst_test after HAVE_LIBAIO guard lead to build failures
on distros without libaio.


Kind regards,
Petr

diff --git testcases/kernel/io/aio/Makefile testcases/kernel/io/aio/Makefile
index 13ed4a395..32cad5215 100644
--- testcases/kernel/io/aio/Makefile
+++ testcases/kernel/io/aio/Makefile
@@ -1,14 +1,11 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-#
-#  Copyright (c) International Business Machines  Corp., 2001
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 
 top_srcdir		?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
 
 CPPFLAGS		+= -D_GNU_SOURCE
-
 LDLIBS			+= $(AIO_LIBS)
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git testcases/kernel/io/aio/aio02.c testcases/kernel/io/aio/aio02.c
index be53ace68..e283afba9 100644
--- testcases/kernel/io/aio/aio02.c
+++ testcases/kernel/io/aio/aio02.c
@@ -1,25 +1,18 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *  Copyright (c) International Business Machines Corp., 2003
+ * Copyright (c) International Business Machines Corp., 2003
+ * Copyright (c) Linux Test Project, 2004-2019
  *
  *  AUTHORS
  *   Kai Zhao (ltcd3@cn.ibm.com)
- *
- *  DESCRIPTION : Test Asynchronous I/O for 2.5 Kernel Infrastructure
- *
- *  REQUIREMENTS:
- *   1) libaio-0.3.92 or up for 2.5 kernel
- *   2) glibc 2.1.91 or up
  */
 
 #include "config.h"
 #include "tst_test.h"
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
 
 #ifdef HAVE_LIBAIO
+#include <errno.h>
+#include <stdlib.h>
 #include <libaio.h>
 
 #define AIO_MAXIO 32
@@ -27,37 +20,31 @@
 
 static int wait_count = 0;
 
-/*
- * test case definition
- */
+#define DESC_FLAGS_OPR(x, y) .desc = (x == IO_CMD_PWRITE ? "WRITE: " #y: "READ : " #y), \
+	.flags = y, .operation = x
+
 struct testcase {
-	const char *description;
+	const char *desc;
 	int flags;
 	int operation;
 } testcases[] = {
-	{"WRITE: O_WRONLY | O_TRUNC | O_DIRECT | O_LARGEFILE | O_CREAT",
-	         O_WRONLY | O_TRUNC | O_DIRECT | O_LARGEFILE | O_CREAT,
-	  IO_CMD_PWRITE
+	{
+		DESC_FLAGS_OPR(IO_CMD_PWRITE, O_WRONLY | O_TRUNC | O_DIRECT | O_LARGEFILE | O_CREAT),
 	},
-	{"WRITE: O_RDONLY           | O_DIRECT | O_LARGEFILE",
-	         O_RDONLY           | O_DIRECT | O_LARGEFILE,
-	 IO_CMD_PREAD
+	{
+		DESC_FLAGS_OPR(IO_CMD_PREAD, O_RDONLY | O_DIRECT | O_LARGEFILE),
 	},
-	{"WRITE: O_RDWR   | O_TRUNC",
-	         O_RDWR   | O_TRUNC,
-	 IO_CMD_PWRITE
+	{
+		DESC_FLAGS_OPR(IO_CMD_PWRITE, O_RDWR | O_TRUNC),
 	},
-	{"READ : O_RDWR",
-	         O_RDWR,
-	 IO_CMD_PREAD
+	{
+		DESC_FLAGS_OPR(IO_CMD_PREAD, O_RDWR),
 	},
-	{"WRITE: O_WRONLY | O_TRUNC",
-	         O_WRONLY | O_TRUNC,
-	 IO_CMD_PWRITE
+	{
+		DESC_FLAGS_OPR(IO_CMD_PWRITE, O_WRONLY | O_TRUNC),
 	},
-	{"READ : O_RDONLY",
-	         O_RDONLY,
-	 IO_CMD_PREAD
+	{
+		DESC_FLAGS_OPR(IO_CMD_PREAD, O_RDONLY),
 	},
 };
 
@@ -167,9 +154,6 @@ static int io_tio(char *pathname, int flag, int operation)
 			iocbps[i] = &iocb_array[i];
 			offset += AIO_BLKSIZE;
 			break;
-		case IO_CMD_POLL:
-		case IO_CMD_NOOP:
-			break;
 		default:
 			tst_res(TFAIL, "Command failed; opcode returned: %d\n", operation);
 			return -1;
@@ -222,25 +206,19 @@ static void test_io(unsigned int n)
 	int status;
 	struct testcase *tc = testcases + n;
 
-	tst_res(TINFO, "%s", tc->description);
 	status = io_tio("file", tc->flags, tc->operation);
 	if (status)
-		tst_res(TFAIL, "%s, status = %d", tc->description, status);
+		tst_res(TFAIL, "%s, status = %d", tc->desc, status);
 	else
-		tst_res(TPASS, "%s", tc->description);
+		tst_res(TPASS, "%s", tc->desc);
 }
 
-#else
-
-static void test_main(void)
-{
-	tst_brk(TCONF, "test requires libaio and its development packages");
-}
-
-#endif
-
 static struct tst_test test = {
 	.needs_tmpdir = 1,
 	.test = test_io,
 	.tcnt = ARRAY_SIZE(testcases),
 };
+
+#else
+TST_TEST_TCONF("test requires libaio and its development packages");
+#endif

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

end of thread, other threads:[~2019-03-15 11:50 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-11  8:53 [LTP] [PATCH v2 1/2] aio_tio: fix error diagnosis for byte transfers Matthias Maennich
2019-01-11  8:53 ` [LTP] [PATCH v2 2/2] aio_tio: determine alignment based on target filesystem Matthias Maennich
2019-01-29 18:19   ` Steve Muckle
2019-02-22 15:33   ` Cyril Hrubis
2019-02-26 15:37     ` Matthias =?unknown-8bit?q?M=C3=A4nnich?=
2019-02-20 15:20 ` [LTP] [PATCH v3 0/3] aio_tio: fixes and conversion to new lib Matthias Maennich
2019-02-20 15:20   ` [LTP] [PATCH v3 1/3] aio_tio: fix error diagnosis for byte transfers Matthias Maennich
2019-02-20 15:20   ` [LTP] [PATCH v3 2/3] aio_tio: determine alignment based on target filesystem Matthias Maennich
2019-02-20 15:20   ` [LTP] [PATCH v3 3/3] aio_tio: convert to new lib Matthias Maennich
2019-02-22 20:40     ` Steve Muckle
2019-02-22 15:28 ` [LTP] [PATCH v2 1/2] aio_tio: fix error diagnosis for byte transfers Cyril Hrubis
2019-02-26 17:02 ` [LTP] [PATCH v4 0/3] aio_tio: fixes and conversion to new lib Matthias Maennich
2019-02-26 17:02   ` [LTP] [PATCH v4 1/3] aio_tio: determine alignment based on target block device Matthias Maennich
2019-02-26 17:02   ` [LTP] [PATCH v4 2/3] aio_tio: convert to new lib Matthias Maennich
2019-02-26 19:13     ` Steve Muckle
2019-03-15 11:50     ` Petr Vorel
2019-02-26 17:02   ` [LTP] [PATCH v4 3/3] io/aio: cleanup test directory Matthias Maennich
2019-02-26 19:16     ` Steve Muckle

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.