From owner-svn-src-stable-10@freebsd.org Mon Jan 4 07:02:49 2016 Return-Path: Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D174AA5FB5F; Mon, 4 Jan 2016 07:02:49 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A89971830; Mon, 4 Jan 2016 07:02:49 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u0472m74082306; Mon, 4 Jan 2016 07:02:48 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u0472mKv082304; Mon, 4 Jan 2016 07:02:48 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201601040702.u0472mKv082304@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Garrett Cooper Date: Mon, 4 Jan 2016 07:02:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r293140 - stable/10/tests/sys/aio X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Jan 2016 07:02:49 -0000 Author: ngie Date: Mon Jan 4 07:02:48 2016 New Revision: 293140 URL: https://svnweb.freebsd.org/changeset/base/293140 Log: MFC r292816,r292818,r292819: r292816: Place cancel and error under #ifdef DEBUG to mute -Wunused-but-set-variable warnings reported by gcc 4.9 Remove some trailing whitespace as well Tested with and without -DDEBUG r292818: Fix style(9) a bit and ensure that error from initializing kqueue(2) is sane - Push the kqueue(2) initialization down so the errno will correspond with the failure instead of potentially being stomped on by functions called by `PLAIN_REQUIRE_KERNEL_MODULE` - Delete trailing whitespace - Add spaces between braces for conditional and control blocks (for/if) - Use err/errx instead of perror+printf+exit/printf+exit. - Remove braces for single-line conditionals Tested with and without -DDEBUG r292819: - Fix an improperly sized buffer for `pathname` [1] - Fix a -Wunused-but-set-variable warning [2] Modified: stable/10/tests/sys/aio/aio_kqueue_test.c stable/10/tests/sys/aio/lio_kqueue_test.c Directory Properties: stable/10/ (props changed) Modified: stable/10/tests/sys/aio/aio_kqueue_test.c ============================================================================== --- stable/10/tests/sys/aio/aio_kqueue_test.c Mon Jan 4 06:58:39 2016 (r293139) +++ stable/10/tests/sys/aio/aio_kqueue_test.c Mon Jan 4 07:02:48 2016 (r293140) @@ -62,7 +62,10 @@ main (int argc, char *argv[]) struct kevent ke, kq_returned; struct timespec ts; char buffer[32768]; - int cancel, error, failed = 0, fd, kq, pending, result, run; +#ifdef DEBUG + int cancel, error; +#endif + int failed = 0, fd, kq, pending, result, run; int tmp_file = 0; unsigned i, j; @@ -96,19 +99,19 @@ main (int argc, char *argv[]) if (iocb[i] == NULL) err(1, "calloc"); } - - pending = 0; + + pending = 0; for (i = 0; i < nitems(iocb); i++) { pending++; iocb[i]->aio_nbytes = sizeof(buffer); iocb[i]->aio_buf = buffer; iocb[i]->aio_fildes = fd; iocb[i]->aio_offset = iocb[i]->aio_nbytes * i * run; - + iocb[i]->aio_sigevent.sigev_notify_kqueue = kq; iocb[i]->aio_sigevent.sigev_value.sival_ptr = iocb[i]; iocb[i]->aio_sigevent.sigev_notify = SIGEV_KEVENT; - + result = aio_write(iocb[i]); if (result != 0) { perror("aio_write"); @@ -133,7 +136,9 @@ main (int argc, char *argv[]) } } } +#ifdef DEBUG cancel = nitems(iocb) - pending; +#endif i = 0; while (pending) { @@ -144,34 +149,36 @@ main (int argc, char *argv[]) bzero(&kq_returned, sizeof(ke)); ts.tv_sec = 0; ts.tv_nsec = 1; - result = kevent(kq, NULL, 0, + result = kevent(kq, NULL, 0, &kq_returned, 1, &ts); +#ifdef DEBUG error = errno; +#endif if (result < 0) perror("kevent error: "); kq_iocb = kq_returned.udata; #ifdef DEBUG printf("kevent %d %d errno %d return.ident %p " - "return.data %p return.udata %p %p\n", - i, result, error, - kq_returned.ident, kq_returned.data, - kq_returned.udata, + "return.data %p return.udata %p %p\n", + i, result, error, + kq_returned.ident, kq_returned.data, + kq_returned.udata, kq_iocb); #endif - + if (kq_iocb) break; #ifdef DEBUG printf("Try again left %d out of %d %d\n", pending, nitems(iocb), cancel); #endif - } - + } + for (j = 0; j < nitems(iocb) && iocb[j] != kq_iocb; j++) ; #ifdef DEBUG printf("kq_iocb %p\n", kq_iocb); - + printf("Error Result for %d is %d pending %d\n", j, result, pending); #endif @@ -192,7 +199,7 @@ main (int argc, char *argv[]) iocb[j] = NULL; pending--; i++; - } + } for (i = 0; i < nitems(iocb); i++) free(iocb[i]); Modified: stable/10/tests/sys/aio/lio_kqueue_test.c ============================================================================== --- stable/10/tests/sys/aio/lio_kqueue_test.c Mon Jan 4 06:58:39 2016 (r293139) +++ stable/10/tests/sys/aio/lio_kqueue_test.c Mon Jan 4 07:02:48 2016 (r293140) @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -57,26 +58,26 @@ #define MAX_RUNS 300 int -main(int argc, char *argv[]){ +main(int argc, char *argv[]) +{ int fd; struct aiocb *iocb[MAX_IOCBS]; - struct aiocb **lio[LIO_MAX], **lio_element, **kq_lio; + struct aiocb **lio[LIO_MAX], **kq_lio; int i, result, run, error, j, k; char buffer[32768]; - int kq = kqueue(); + int kq; struct kevent ke, kq_returned; struct timespec ts; struct sigevent sig; time_t time1, time2; - char *file, pathname[sizeof(PATH_TEMPLATE)-1]; + char *file, pathname[sizeof(PATH_TEMPLATE)]; int tmp_file = 0, failed = 0; PLAIN_REQUIRE_KERNEL_MODULE("aio", 0); - if (kq < 0) { - perror("No kqeueue\n"); - exit(1); - } + kq = kqueue(); + if (kq < 0) + err(1, "kqeueue(2) failed"); if (argc == 1) { strcpy(pathname, PATH_TEMPLATE); @@ -87,34 +88,29 @@ main(int argc, char *argv[]){ file = argv[1]; fd = open(file, O_RDWR|O_CREAT, 0666); } - if (fd < 0){ - fprintf(stderr, "Can't open %s\n", argv[1]); - perror(""); - exit(1); - } + if (fd < 0) + err(1, "can't open %s", argv[1]); #ifdef DEBUG printf("Hello kq %d fd %d\n", kq, fd); #endif - for (run = 0; run < MAX_RUNS; run++){ + for (run = 0; run < MAX_RUNS; run++) { #ifdef DEBUG printf("Run %d\n", run); #endif for (j = 0; j < LIO_MAX; j++) { - lio[j] = (struct aiocb **) + lio[j] = malloc(sizeof(struct aiocb *) * MAX_IOCBS/LIO_MAX); - for(i = 0; i < MAX_IOCBS / LIO_MAX; i++) { + 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)); - bzero(iocb[k], sizeof(struct aiocb)); + lio[j][i] = iocb[k] = + calloc(1, sizeof(struct aiocb)); iocb[k]->aio_nbytes = sizeof(buffer); iocb[k]->aio_buf = buffer; iocb[k]->aio_fildes = fd; - iocb[k]->aio_offset - = iocb[k]->aio_nbytes * k * (run + 1); + iocb[k]->aio_offset + = iocb[k]->aio_nbytes * k * (run + 1); #ifdef DEBUG printf("hello iocb[k] %d\n", @@ -131,27 +127,26 @@ main(int argc, char *argv[]){ error = errno; time(&time2); #ifdef DEBUG - printf("Time %d %d %d result -> %d\n", + printf("Time %d %d %d result -> %d\n", time1, time2, time2-time1, result); #endif if (result != 0) { errno = error; - perror("list_listio"); - printf("FAIL: Result %d iteration %d\n",result, j); - exit(1); + err(1, "FAIL: Result %d iteration %d\n", + result, j); } #ifdef DEBUG printf("write %d is at %p\n", j, lio[j]); #endif } - for(i = 0; i < LIO_MAX; i++) { - for(j = LIO_MAX - 1; j >=0; j--) { + for (i = 0; i < LIO_MAX; i++) { + for (j = LIO_MAX - 1; j >=0; j--) { if (lio[j]) break; } - for(;;) { + for (;;) { bzero(&ke, sizeof(ke)); bzero(&kq_returned, sizeof(ke)); ts.tv_sec = 0; @@ -159,9 +154,9 @@ main(int argc, char *argv[]){ #ifdef DEBUG printf("FOO lio %d -> %p\n", j, lio[j]); #endif - EV_SET(&ke, (uintptr_t)lio[j], + EV_SET(&ke, (uintptr_t)lio[j], EVFILT_LIO, EV_ONESHOT, 0, 0, iocb[j]); - result = kevent(kq, NULL, 0, + result = kevent(kq, NULL, 0, &kq_returned, 1, &ts); error = errno; if (result < 0) { @@ -170,14 +165,14 @@ main(int argc, char *argv[]){ kq_lio = kq_returned.udata; #ifdef DEBUG printf("kevent %d %d errno %d return.ident %p " - "return.data %p return.udata %p %p\n", - i, result, error, - kq_returned.ident, kq_returned.data, - kq_returned.udata, + "return.data %p return.udata %p %p\n", + i, result, error, + kq_returned.ident, kq_returned.data, + kq_returned.udata, lio[j]); #endif - if(kq_lio) + if (kq_lio) break; #ifdef DEBUG printf("Try again\n"); @@ -189,25 +184,21 @@ main(int argc, char *argv[]){ #endif for (j = 0; j < LIO_MAX; j++) { - if (lio[j] == kq_lio) { + if (lio[j] == kq_lio) break; - } - } - if (j == LIO_MAX) { - printf("FAIL:\n"); - exit(1); } + if (j == LIO_MAX) + errx(1, "FAIL: "); #ifdef DEBUG printf("Error Result for %d is %d\n", j, result); #endif if (result < 0) { printf("FAIL: run %d, operation %d result %d \n", run, LIO_MAX - i -1, result); - failed = 1; - } else { + failed++; + } else printf("PASS: run %d, operation %d result %d \n", run, LIO_MAX - i -1, result); - } - for(k = 0; k < MAX_IOCBS / 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); @@ -224,9 +215,8 @@ main(int argc, char *argv[]){ printf("\n"); #endif - for(k = 0; k < MAX_IOCBS / LIO_MAX; k++) { + for (k = 0; k < MAX_IOCBS / LIO_MAX; k++) free(lio[j][k]); - } free(lio[j]); lio[j] = NULL; } @@ -235,15 +225,12 @@ main(int argc, char *argv[]){ printf("Done\n"); #endif - if (tmp_file) { + if (tmp_file) unlink(pathname); - } - if (failed) { - printf("FAIL: Atleast one\n"); - exit(1); - } else { - printf("PASS: All\n"); - exit(0); - } + if (failed) + errx(1, "FAIL: %d testcases failed", failed); + else + errx(0, "PASS: All\n"); + }