Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Apr 2015 10:53:07 +0000 (UTC)
From:      Garrett Cooper <ngie@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r282136 - head/tests/sys/aio
Message-ID:  <201504281053.t3SAr7lr004573@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ngie
Date: Tue Apr 28 10:53:06 2015
New Revision: 282136
URL: https://svnweb.freebsd.org/changeset/base/282136

Log:
  - Use ATF_REQUIRE_KERNEL_MDOULE to require aio(4)
  - Don't use /tmp as a basis for temporary files as it's outside of the ATF
    sandbox
  - Don't override MAX macro in sys/param.h
  
  MFC after: 6 days

Modified:
  head/tests/sys/aio/aio_kqueue_test.c
  head/tests/sys/aio/lio_kqueue_test.c

Modified: head/tests/sys/aio/aio_kqueue_test.c
==============================================================================
--- head/tests/sys/aio/aio_kqueue_test.c	Tue Apr 28 10:51:12 2015	(r282135)
+++ head/tests/sys/aio/aio_kqueue_test.c	Tue Apr 28 10:53:06 2015	(r282136)
@@ -46,25 +46,29 @@
 #include <string.h>
 #include <unistd.h>
 
-#define PATH_TEMPLATE   "/tmp/aio.XXXXXXXXXX"
+#include "freebsd_test_suite/macros.h"
 
-#define MAX 128
+#define PATH_TEMPLATE   "aio.XXXXXXXXXX"
+
+#define MAX_IOCBS 128
 #define MAX_RUNS 300
 /* #define DEBUG */
 
 int
 main (int argc, char *argv[])
 {
-	int fd;
-	struct aiocb *iocb[MAX], *kq_iocb;
-	int i, result, run, error, j;
-	char buffer[32768];
-	int kq = kqueue();
+	struct aiocb *iocb[MAX_IOCBS], *kq_iocb;
+	char *file, pathname[sizeof(PATH_TEMPLATE)+1];
 	struct kevent ke, kq_returned;
 	struct timespec ts;
-	int cancel, pending, tmp_file = 0, failed = 0;
-	char *file, pathname[sizeof(PATH_TEMPLATE)+1];
+	char buffer[32768];
+	int cancel, error, failed = 0, fd, kq, pending, result, run;
+	int tmp_file = 0;
+	unsigned i, j;
+
+	PLAIN_REQUIRE_KERNEL_MODULE("aio", 0);
 
+	kq = kqueue();
 	if (kq < 0) {
 		perror("No kqeueue\n");
 		exit(1);
@@ -86,7 +90,7 @@ main (int argc, char *argv[])
 #ifdef DEBUG
 		printf("Run %d\n", run);
 #endif
-		for (i = 0; i < MAX; i++) {
+		for (i = 0; i < nitems(iocb); i++) {
 			iocb[i] = (struct aiocb *)calloc(1,
 			    sizeof(struct aiocb));
 			if (iocb[i] == NULL)
@@ -94,7 +98,7 @@ main (int argc, char *argv[])
 		}
 		
 		pending = 0;	
-		for (i = 0; i < MAX; i++) {
+		for (i = 0; i < nitems(iocb); i++) {
 			pending++;
 			iocb[i]->aio_nbytes = sizeof(buffer);
 			iocb[i]->aio_buf = buffer;
@@ -129,8 +133,8 @@ main (int argc, char *argv[])
 				}
 			}
 		}
-		cancel = MAX - pending;
-		
+		cancel = nitems(iocb) - pending;
+
 		i = 0;
 		while (pending) {
 
@@ -159,11 +163,11 @@ main (int argc, char *argv[])
 					break;
 #ifdef DEBUG
 				printf("Try again left %d out of %d %d\n",
-				    pending, MAX, cancel);
+				    pending, nitems(iocb), cancel);
 #endif
 			}			
 			
-			for (j = 0; j < MAX && iocb[j] != kq_iocb;
+			for (j = 0; j < nitems(iocb) && iocb[j] != kq_iocb;
 			   j++) ;
 #ifdef DEBUG
 			printf("kq_iocb %p\n", kq_iocb);
@@ -190,7 +194,7 @@ main (int argc, char *argv[])
 			i++;
 		}	
 
-		for (i = 0; i < MAX; i++)
+		for (i = 0; i < nitems(iocb); i++)
 			free(iocb[i]);
 
 	}

Modified: head/tests/sys/aio/lio_kqueue_test.c
==============================================================================
--- head/tests/sys/aio/lio_kqueue_test.c	Tue Apr 28 10:51:12 2015	(r282135)
+++ head/tests/sys/aio/lio_kqueue_test.c	Tue Apr 28 10:53:06 2015	(r282136)
@@ -48,16 +48,18 @@
 #include <string.h>
 #include <unistd.h>
 
-#define PATH_TEMPLATE   "/tmp/aio.XXXXXXXXXX"
+#include "freebsd_test_suite/macros.h"
+
+#define PATH_TEMPLATE   "aio.XXXXXXXXXX"
 
 #define LIO_MAX 5
-#define MAX LIO_MAX * 16
+#define MAX_IOCBS LIO_MAX * 16
 #define MAX_RUNS 300
 
 int
 main(int argc, char *argv[]){
 	int fd;
-	struct aiocb *iocb[MAX];
+	struct aiocb *iocb[MAX_IOCBS];
 	struct aiocb **lio[LIO_MAX], **lio_element, **kq_lio;
 	int i, result, run, error, j, k;
 	char buffer[32768];
@@ -69,6 +71,8 @@ main(int argc, char *argv[]){
 	char *file, pathname[sizeof(PATH_TEMPLATE)-1];
 	int tmp_file = 0, failed = 0;
 
+	PLAIN_REQUIRE_KERNEL_MODULE("aio", 0);
+
 	if (kq < 0) {
 		perror("No kqeueue\n");
 		exit(1);
@@ -99,9 +103,9 @@ main(int argc, char *argv[]){
 #endif
 		for (j = 0; j < LIO_MAX; j++) {
 			lio[j] = (struct aiocb **)
-				malloc(sizeof(struct aiocb *) * MAX/LIO_MAX);
-			for(i = 0; i < MAX / LIO_MAX; i++) {
-				k = (MAX / LIO_MAX * j) + i;
+			    malloc(sizeof(struct aiocb *) * MAX_IOCBS/LIO_MAX);
+			for(i = 0; i < MAX_IOCBS / LIO_MAX; i++) {
+				k = (MAX_IOCBS / LIO_MAX * j) + i;
 				lio_element = lio[j];
 				lio[j][i] = iocb[k] = (struct aiocb *)
 					malloc(sizeof(struct aiocb));
@@ -123,7 +127,7 @@ main(int argc, char *argv[]){
 			sig.sigev_notify = SIGEV_KEVENT;
 			time(&time1);
 			result = lio_listio(LIO_NOWAIT, lio[j],
-					    MAX / LIO_MAX, &sig);
+					    MAX_IOCBS / LIO_MAX, &sig);
 			error = errno;
 			time(&time2);
 #ifdef DEBUG
@@ -203,7 +207,7 @@ main(int argc, char *argv[]){
 			} else {
 				printf("PASS: run %d, operation %d result %d \n", run, LIO_MAX - i -1, result);
 			}
-			for(k = 0; k < MAX / LIO_MAX; k++){
+			for(k = 0; k < MAX_IOCBS / LIO_MAX; k++){
 				result = aio_return(kq_lio[k]);
 #ifdef DEBUG
 				printf("Return Resulto for %d %d is %d\n", j, k, result);
@@ -220,7 +224,7 @@ main(int argc, char *argv[]){
 			printf("\n");
 #endif
 
-			for(k = 0; k < MAX / LIO_MAX; k++) {
+			for(k = 0; k < MAX_IOCBS / LIO_MAX; k++) {
 				free(lio[j][k]);
 			}
 			free(lio[j]);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201504281053.t3SAr7lr004573>