From patchwork Fri Sep 30 17:59:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 1684978 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=Hj/gUNqx; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MfJ114ymkz1yql for ; Sat, 1 Oct 2022 04:00:21 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 781373CAAAC for ; Fri, 30 Sep 2022 20:00:18 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 0D1513CA950 for ; Fri, 30 Sep 2022 20:00:12 +0200 (CEST) Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id ACFFE602265 for ; Fri, 30 Sep 2022 20:00:10 +0200 (CEST) Received: by mail-pl1-x64a.google.com with SMTP id l2-20020a170902f68200b00177ee7e673eso3683047plg.2 for ; Fri, 30 Sep 2022 11:00:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date; bh=C8cDnASKRJ672FF3lOKNTiiJ4uZDcLifNtvhc+f4O4M=; b=Hj/gUNqxRSlPDL29gYz+IdHPjs3Lbyq6kHtTlgjFg8AagjnDwB4ae9e7tNbvKfgjTH kHXAzUbnK23CQ+I/CiFSH72QCXMSy3cKvzELfwXCsWs5x2V6pi5pe+2gyfwvA5iAls0t jqysePR3ub066ZUj1fHNduitr9vVvq84Bi7gJ0SMea3aZGRmOCabxHWnBE3FHJt6Vmb+ BJ8TwkUmBkDaM4GEh/l3vlVrarP24qfzRkHryjhylm3p9FnRYuvY3/WhcGWem5F+C4yn Bo3pZC6Eryl6rM1Hro/TIDfkUidiLtXNU2CQwGhuyHI+Pd4yoaC1ZeMRMHp/BodgkxBl WTrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=C8cDnASKRJ672FF3lOKNTiiJ4uZDcLifNtvhc+f4O4M=; b=Zay3L6qnPqf/jYyhfkXItQQ8rc7i2Qf2q7YrGeXnAZoazfvoDWCg0Ak1Tq0EeARyK9 7NMAsvYZH/+M9SXsjd9lGTsZFLWFkU1kprldaGTxYDpu+abgohOps7d2uV5k9ls9Tgrj fLWky4Cxz8vsOlbvxfAjUCJk2MS942KIPUBfHt0xNprvK7e4v9EmJ35usURnDyQyzso/ pqZskd5kk/GUEYhKv8zIlZG4/H94yCcEbofA0s2PhNAqbqv0cxEAMRuPsFdy+zgM01/J i9DJgh9IWb1N8/LAV+7NCDBmAJ+0D4KyaOk+LnUtVmNe5p6raNbsZoGAsZ8dai5JDstC pKOw== X-Gm-Message-State: ACrzQf0IxKqCsAqcw15BOwq/BsHv9u2UGC3pI9TXryJxaMlGMbOTKcls 9ev8vAWflyRpQ+nFPRwaADcrGoM6m1pklPrTgPh2b01VP3NL3jMdBrvVRogppN2h800wMl4hICp SiuDvkM8xbL5yR/agDQ2zQHAi8cmRZeZKY7hQoy12j1iMT6O03J62Xxe+ X-Google-Smtp-Source: AMsMyM5okX30m+/EFB4xhYggO8DFUBuMUpxu5YG9G7eXN4k++0YXNxywKRyBzHllmA++JhPCxd4FhnYWC8w= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a17:90b:3b4b:b0:203:3265:d314 with SMTP id ot11-20020a17090b3b4b00b002033265d314mr23543842pjb.196.1664560808908; Fri, 30 Sep 2022 11:00:08 -0700 (PDT) Date: Fri, 30 Sep 2022 17:59:56 +0000 In-Reply-To: <20220930175959.3955586-1-edliaw@google.com> Mime-Version: 1.0 References: <20220930175959.3955586-1-edliaw@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20220930175959.3955586-2-edliaw@google.com> To: ltp@lists.linux.it X-Virus-Scanned: clamav-milter 0.102.4 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-7.4 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v2 1/4] mmapstress01: refactor to tst_test framework X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Edward Liaw via ltp From: Edward Liaw Reply-To: Edward Liaw Cc: kernel-team@android.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Edward Liaw --- .../kernel/mem/mmapstress/mmapstress01.c | 485 +++++++----------- 1 file changed, 187 insertions(+), 298 deletions(-) diff --git a/testcases/kernel/mem/mmapstress/mmapstress01.c b/testcases/kernel/mem/mmapstress/mmapstress01.c index f425c223d..41f94a52a 100644 --- a/testcases/kernel/mem/mmapstress/mmapstress01.c +++ b/testcases/kernel/mem/mmapstress/mmapstress01.c @@ -20,32 +20,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#define _GNU_SOURCE 1 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -/***** LTP Port *****/ -#include "test.h" -#define FAILED 0 -#define PASSED 1 - -int local_flag = PASSED; -char *TCID = "mmapstress01"; //tmnoextend -FILE *temp; -int TST_TOTAL = 1; - -int anyfail(); -void ok_exit(); -/***** ** ** *****/ - /* * This test stresses mmaps, without dealing with fragments or anything! * It forks a specified number of children, @@ -88,8 +62,24 @@ void ok_exit(); * Compile with -DLARGE_FILE to enable file sizes > 2 GB. */ +#define _GNU_SOURCE 1 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define TST_NO_DEFAULT_MAIN +#include "tst_test.h" + #define MAXLOOPS 500 /* max pages for map children to write */ #define FILESIZE 4096 /* initial filesize set up by parent */ +#define TEST_FILE "mmapstress01.out" #ifdef roundup #undef roundup @@ -100,36 +90,42 @@ extern time_t time(time_t *); extern char *ctime(const time_t *); extern void *malloc(size_t); extern long lrand48(void); -extern void srand(unsigned); +extern void srand(unsigned int); extern void srand48(long); extern int rand(void); extern int atoi(const char *); -char *usage = +static char *usage = "-p nprocs [-t minutes -f filesize -S sparseoffset -r -o -m -l -d]"; -typedef unsigned char uchar_t; -#define SIZE_MAX UINT_MAX +static unsigned int initrand(void); +static void finish(int sig); +static void child_mapper(char *file, unsigned int procno, unsigned int nprocs); +static int fileokay(char *file, unsigned char *expbuf); +static int finished = 0; +static int leavefile = 0; + +static float alarmtime = 0; +static unsigned int nprocs = 0; + +static pid_t *pidarray = NULL; +static int wait_stat; +static int check_for_sanity; +static unsigned char *buf = NULL; -unsigned int initrand(void); -void finish(int sig); -void child_mapper(char *file, unsigned procno, unsigned nprocs); -int fileokay(char *file, uchar_t * expbuf); -int finished = 0; -int leavefile = 0; -int debug = 0; +static int debug = 0; #ifdef LARGE_FILE -off64_t filesize = FILESIZE; -off64_t sparseoffset = 0; +static off64_t filesize = FILESIZE; +static off64_t sparseoffset = 0; #else /* LARGE_FILE */ -off_t filesize = FILESIZE; -off_t sparseoffset = 0; +static off_t filesize = FILESIZE; +static off_t sparseoffset = 0; #endif /* LARGE_FILE */ -unsigned randloops = 0; -unsigned dosync = 0; -unsigned do_offset = 0; -unsigned pattern = 0; +static unsigned int randloops = 0; +static unsigned int dosync = 0; +static unsigned int do_offset = 0; +static unsigned int pattern = 0; int main(int argc, char *argv[]) { @@ -137,32 +133,23 @@ int main(int argc, char *argv[]) int fd; int c; extern char *optarg; - unsigned nprocs = 0; - unsigned procno; - pid_t *pidarray = NULL; + unsigned int procno; pid_t pid; - uchar_t *buf = NULL; unsigned int seed; int pagesize = sysconf(_SC_PAGE_SIZE); - float alarmtime = 0; struct sigaction sa; - unsigned i; + unsigned int i; int write_cnt; - uchar_t data; - int no_prob = 0; - int wait_stat; - time_t t; + unsigned char data; #ifdef LARGE_FILE off64_t bytes_left; #else /* LARGE_FILE */ off_t bytes_left; #endif /* LARGE_FILE */ - const char *filename = "mmapstress01.out"; progname = *argv; - tst_tmpdir(); if (argc < 2) { - tst_brkm(TBROK, NULL, "usage: %s %s", progname, usage); + tst_brk(TBROK, "usage: %s %s", progname, usage); } while ((c = getopt(argc, argv, "S:omdlrf:p:t:")) != -1) { @@ -185,11 +172,8 @@ int main(int argc, char *argv[]) #else /* LARGE_FILE */ filesize = atoi(optarg); #endif /* LARGE_FILE */ - if (filesize < 0) { - (void)fprintf(stderr, "error: negative " - "filesize\n"); - anyfail(); - } + if (filesize < 0) + tst_brk(TBROK, "error: negative filesize"); break; case 'r': randloops = 1; @@ -206,46 +190,39 @@ int main(int argc, char *argv[]) #else /* LARGE_FILE */ sparseoffset = atoi(optarg); #endif /* LARGE_FILE */ - if (sparseoffset % pagesize != 0) { - fprintf(stderr, - "sparseoffset must be pagesize multiple\n"); - anyfail(); - } + if (sparseoffset % pagesize != 0) + tst_brk(TBROK, + "sparseoffset must be pagesize multiple"); break; default: - (void)fprintf(stderr, "usage: %s %s\n", progname, - usage); - tst_exit(); + tst_brk(TBROK, "usage: %s %s", progname, usage); } } /* nprocs is >= 0 since it's unsigned */ - if (nprocs > 255) { - (void)fprintf(stderr, "invalid nprocs %d - (range 0-255)\n", - nprocs); - anyfail(); - } - - (void)time(&t); + if (nprocs > 255) + tst_brk(TBROK, "invalid nprocs %d - (range 0-255)", nprocs); seed = initrand(); pattern = seed & 0xff; if (debug) { #ifdef LARGE_FILE - (void)printf("creating file <%s> with %Ld bytes, pattern %d\n", - filename, filesize, pattern); + tst_res(TINFO, "creating file <%s> with %Ld bytes, pattern %d", + TEST_FILE, filesize, pattern); #else /* LARGE_FILE */ - (void)printf("creating file <%s> with %ld bytes, pattern %d\n", - filename, filesize, pattern); + tst_res(TINFO, "creating file <%s> with %ld bytes, pattern %d", + TEST_FILE, filesize, pattern); #endif /* LARGE_FILE */ if (alarmtime) - (void)printf("running for %f minutes\n", - alarmtime / 60); + tst_res(TINFO, "running for %f minutes", + alarmtime / 60); else - (void)printf("running with no time limit\n"); + tst_res(TINFO, "running with no time limit"); } + tst_reinit(); + /* * Plan for death by signal. User may have specified * a time limit, in which set an alarm and catch SIGALRM. @@ -253,44 +230,32 @@ int main(int argc, char *argv[]) */ sa.sa_handler = finish; sa.sa_flags = 0; - if (sigemptyset(&sa.sa_mask)) { - perror("sigemptyset error"); - goto cleanup; - } + if (sigemptyset(&sa.sa_mask)) + tst_brk(TFAIL, "sigemptyset error"); - if (sigaction(SIGINT, &sa, 0) == -1) { - perror("sigaction error SIGINT"); - goto cleanup; - } - if (sigaction(SIGQUIT, &sa, 0) == -1) { - perror("sigaction error SIGQUIT"); - goto cleanup; - } - if (sigaction(SIGTERM, &sa, 0) == -1) { - perror("sigaction error SIGTERM"); - goto cleanup; - } + if (sigaction(SIGINT, &sa, 0) == -1) + tst_brk(TFAIL, "sigaction error SIGINT"); + if (sigaction(SIGQUIT, &sa, 0) == -1) + tst_brk(TFAIL, "sigaction error SIGQUIT"); + if (sigaction(SIGTERM, &sa, 0) == -1) + tst_brk(TFAIL, "sigaction error SIGTERM"); if (alarmtime) { - if (sigaction(SIGALRM, &sa, 0) == -1) { - perror("sigaction error"); - goto cleanup; - } + if (sigaction(SIGALRM, &sa, 0) == -1) + tst_brk(TFAIL, "sigaction error"); (void)alarm(alarmtime); } #ifdef LARGE_FILE - if ((fd = open64(filename, O_CREAT | O_TRUNC | O_RDWR, 0664)) == -1) { + if ((fd = open64(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, 0664)) == -1) { #else /* LARGE_FILE */ - if ((fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, 0664)) == -1) { + if ((fd = open(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, 0664)) == -1) { #endif /* LARGE_FILE */ - perror("open error"); - anyfail(); + tst_brk(TFAIL, "open error"); } if ((buf = malloc(pagesize)) == NULL || (pidarray = malloc(nprocs * sizeof(pid_t))) == NULL) { - perror("malloc error"); - anyfail(); + tst_brk(TFAIL, "malloc error"); } for (i = 0; i < nprocs; i++) @@ -302,25 +267,23 @@ int main(int argc, char *argv[]) data = 0; } #ifdef LARGE_FILE - if (lseek64(fd, sparseoffset, SEEK_SET) < 0) { + if (lseek64(fd, (off64_t)sparseoffset, SEEK_SET) < 0) { #else /* LARGE_FILE */ - if (lseek(fd, sparseoffset, SEEK_SET) < 0) { + if (lseek(fd, (off_t)sparseoffset, SEEK_SET) < 0) { #endif /* LARGE_FILE */ - perror("lseek"); - anyfail(); + tst_brk(TFAIL, "lseek"); } for (bytes_left = filesize; bytes_left; bytes_left -= c) { write_cnt = MIN(pagesize, (int)bytes_left); if ((c = write(fd, buf, write_cnt)) != write_cnt) { - if (c == -1) { - perror("write error"); - } else { - (void)fprintf(stderr, "write: wrote %d of %d " - "bytes\n", c, write_cnt); - } + if (c == -1) + tst_res(TINFO, "write error"); + else + tst_res(TINFO, "write: wrote %d of %d bytes", + c, write_cnt); (void)close(fd); - (void)unlink(filename); - anyfail(); + (void)unlink(TEST_FILE); + tst_brk(TFAIL, "write error"); } } @@ -333,11 +296,11 @@ int main(int argc, char *argv[]) switch (pid = fork()) { case -1: - perror("fork error"); - goto cleanup; + tst_brk(TFAIL, "fork error"); + break; case 0: - child_mapper(filename, procno, nprocs); + child_mapper(TEST_FILE, procno, nprocs); exit(0); default: @@ -355,10 +318,8 @@ int main(int argc, char *argv[]) * Block signals while processing child exit. */ - if (sighold(SIGALRM) || sighold(SIGINT)) { - perror("sighold error"); - goto cleanup; - } + if (sighold(SIGALRM) || sighold(SIGINT)) + tst_brk(TFAIL, "sighold error"); if (pid != -1) { /* @@ -366,44 +327,36 @@ int main(int argc, char *argv[]) * appropriate procno. */ if (!WIFEXITED(wait_stat) - || WEXITSTATUS(wait_stat) != 0) { - (void)fprintf(stderr, "child exit with err " - "\n", wait_stat); - goto cleanup; - } + || WEXITSTATUS(wait_stat) != 0) + tst_brk(TFAIL, "child exit with err ", + wait_stat); for (i = 0; i < nprocs; i++) if (pid == pidarray[i]) break; - if (i == nprocs) { - (void)fprintf(stderr, "unknown child pid %d, " - "\n", pid, wait_stat); - goto cleanup; - } + if (i == nprocs) + tst_brk(TFAIL, "unknown child pid %d, ", + pid, wait_stat); if ((pid = fork()) == -1) { - perror("fork error"); pidarray[i] = 0; - goto cleanup; + tst_brk(TFAIL, "fork error"); } else if (pid == 0) { /* child */ - child_mapper(filename, i, nprocs); + child_mapper(TEST_FILE, i, nprocs); exit(0); - } else + } else { pidarray[i] = pid; + } } else { /* * wait returned an error. If EINTR, then * normal finish, else it's an unexpected * error... */ - if (errno != EINTR || !finished) { - perror("unexpected wait error"); - goto cleanup; - } - } - if (sigrelse(SIGALRM) || sigrelse(SIGINT)) { - perror("sigrelse error"); - goto cleanup; + if (errno != EINTR || !finished) + tst_brk(TFAIL, "unexpected wait error"); } + if (sigrelse(SIGALRM) || sigrelse(SIGINT)) + tst_brk(TFAIL, "sigrelse error"); } /* @@ -411,40 +364,34 @@ int main(int argc, char *argv[]) * the children and done!. */ - if (sighold(SIGALRM)) { - perror("sighold error"); - goto cleanup; - } + if (sighold(SIGALRM)) + tst_brk(TFAIL, "sighold error"); (void)alarm(0); - no_prob = 1; + check_for_sanity = 1; + tst_res(TPASS, "finished, cleaning up"); +} -cleanup: - for (i = 0; i < nprocs; i++) +static void cleanup(void) +{ + for (int i = 0; i < nprocs; i++) (void)kill(pidarray[i], SIGKILL); while (wait(&wait_stat) != -1 || errno != ECHILD) continue; - if (no_prob) { /* only check file if no errors */ - if (!fileokay(filename, buf)) { - (void)fprintf(stderr, "file data incorrect!\n"); - (void)printf(" leaving file <%s>\n", filename); - /***** LTP Port *****/ - local_flag = FAILED; - anyfail(); - /***** ** *****/ + if (check_for_sanity) { /* only check file if no errors */ + if (!fileokay(TEST_FILE, buf)) { + tst_res(TINFO, " leaving file <%s>", TEST_FILE); + tst_brk(TFAIL, "file data incorrect"); } else { - (void)printf("file data okay\n"); + tst_res(TINFO, "file data okay"); if (!leavefile) - (void)unlink(filename); + (void)unlink(TEST_FILE); + tst_res(TPASS, "test passed"); } - } else - (void)printf(" leaving file <%s>\n", filename); - - (void)time(&t); - //(void)printf("%s: Finished %s", argv[0], ctime(&t)); LTP Port - ok_exit(); - tst_exit(); + } else { + tst_res(TINFO, " leaving file <%s>", TEST_FILE); + } } /* @@ -454,7 +401,7 @@ cleanup: * determined based on nprocs & procno). After a specific number of * iterations, it exits. */ -void child_mapper(char *file, unsigned procno, unsigned nprocs) +void child_mapper(char *file, unsigned int procno, unsigned int nprocs) { #ifdef LARGE_FILE struct stat64 statbuf; @@ -470,38 +417,32 @@ void child_mapper(char *file, unsigned procno, unsigned nprocs) char *maddr = NULL, *paddr; int fd; size_t pagesize = sysconf(_SC_PAGE_SIZE); - unsigned randpage; + unsigned int randpage; unsigned int seed; - unsigned loopcnt; - unsigned nloops; - unsigned mappages; - unsigned i; + unsigned int loopcnt; + unsigned int nloops; + unsigned int mappages; + unsigned int i; seed = initrand(); /* initialize random seed */ #ifdef LARGE_FILE - if (stat64(file, &statbuf) == -1) { + if (stat64(file, &statbuf) == -1) #else /* LARGE_FILE */ - if (stat(file, &statbuf) == -1) { + if (stat(file, &statbuf) == -1) #endif /* LARGE_FILE */ - perror("stat error"); - anyfail(); - } + tst_brk(TFAIL, "stat error"); filesize = statbuf.st_size; #ifdef LARGE_FILE - if ((fd = open64(file, O_RDWR)) == -1) { + if ((fd = open64(file, O_RDWR)) == -1) #else /* LARGE_FILE */ - if ((fd = open(file, O_RDWR)) == -1) { + if ((fd = open(file, O_RDWR)) == -1) #endif /* LARGE_FILE */ - perror("open error"); - anyfail(); - } + tst_brk(TFAIL, "open error"); - if (statbuf.st_size - sparseoffset > SIZE_MAX) { - fprintf(stderr, "size_t overflow when setting up map\n"); - anyfail(); - } + if (statbuf.st_size - sparseoffset > UINT_MAX) + tst_brk(TFAIL, "size_t overflow when setting up map"); mapsize = (size_t) (statbuf.st_size - sparseoffset); mappages = roundup(mapsize, pagesize) / pagesize; offset = sparseoffset; @@ -514,29 +455,18 @@ void child_mapper(char *file, unsigned procno, unsigned nprocs) } nloops = (randloops) ? (lrand48() % MAXLOOPS) : MAXLOOPS; - if (debug) { -#ifdef LARGE_FILE - (void)printf("child %d (pid %ld): seed %d, fsize %Ld, " - "mapsize %d, off %Ld, loop %d\n", - procno, getpid(), seed, filesize, mapsize, - offset / pagesize, nloops); -#else /* LARGE_FILE */ - (void)printf("child %d (pid %d): seed %d, fsize %ld, " - "mapsize %ld, off %ld, loop %d\n", - procno, getpid(), seed, filesize, (long)mapsize, - offset / pagesize, nloops); -#endif /* LARGE_FILE */ - } + if (debug) + tst_res(TINFO, "child %d (pid %d): seed %d, fsize %lld, mapsize %ld, off %lld, loop %d", + procno, getpid(), seed, filesize, (long)mapsize, + offset / pagesize, nloops); #ifdef LARGE_FILE if ((maddr = mmap64(0, mapsize, PROT_READ | PROT_WRITE, MAP_SHARED, - fd, offset)) == (caddr_t) - 1) { + fd, (off64_t)offset)) == (caddr_t) - 1) #else /* LARGE_FILE */ if ((maddr = mmap(0, mapsize, PROT_READ | PROT_WRITE, MAP_SHARED, - fd, offset)) == (caddr_t) - 1) { + fd, (off_t)offset)) == (caddr_t) - 1) #endif /* LARGE_FILE */ - perror("mmap error"); - anyfail(); - } + tst_brk(TFAIL, "mmap error"); (void)close(fd); @@ -554,15 +484,11 @@ void child_mapper(char *file, unsigned procno, unsigned nprocs) for (i = procno; i < validsize; i += nprocs) { if (*((unsigned char *)(paddr + i)) - != ((procno + pattern) & 0xff)) { - (void)fprintf(stderr, "child %d: invalid data " - "", procno, - *((unsigned char *)(paddr + i))); - (void)fprintf(stderr, " at pg %d off %d, exp " - "\n", randpage, i, - (procno + pattern) & 0xff); - anyfail(); - } + != ((procno + pattern) & 0xff)) + tst_brk(TFAIL, "child %d: invalid data \n" + " at pg %d off %d, exp ", procno, + *((unsigned char *)(paddr + i)), + randpage, i, (procno + pattern) & 0xff); /* * Now write it. @@ -577,22 +503,18 @@ void child_mapper(char *file, unsigned procno, unsigned nprocs) randpage = lrand48() % mappages; paddr = maddr + (randpage * pagesize); /* page address */ if (msync(paddr, (mappages - randpage) * pagesize, - MS_SYNC) == -1) { - anyfail(); - } - } - if (munmap(maddr, mapsize) == -1) { - perror("munmap failed"); - local_flag = FAILED; - anyfail(); + MS_SYNC) == -1) + tst_brk(TFAIL, "msync failed"); } + if (munmap(maddr, mapsize) == -1) + tst_brk(TFAIL, "munmap failed"); exit(0); } /* * Make sure file has all the correct data. */ -int fileokay(char *file, uchar_t * expbuf) +int fileokay(char *file, unsigned char *expbuf) { #ifdef LARGE_FILE struct stat64 statbuf; @@ -600,50 +522,36 @@ int fileokay(char *file, uchar_t * expbuf) struct stat statbuf; #endif /* LARGE_FILE */ size_t mapsize; - unsigned mappages; - unsigned pagesize = sysconf(_SC_PAGE_SIZE); - uchar_t readbuf[pagesize]; + unsigned int mappages; + unsigned int pagesize = sysconf(_SC_PAGE_SIZE); + unsigned char readbuf[pagesize]; int fd; int cnt; - unsigned i, j; + unsigned int i, j; #ifdef LARGE_FILE - if ((fd = open64(file, O_RDONLY)) == -1) { + if ((fd = open64(file, O_RDONLY)) == -1) #else /* LARGE_FILE */ - if ((fd = open(file, O_RDONLY)) == -1) { + if ((fd = open(file, O_RDONLY)) == -1) #endif /* LARGE_FILE */ - perror("open error"); - /***** LTP Port *****/ - local_flag = FAILED; - anyfail(); - /***** ** *****/ - return 0; - } + tst_brk(TFAIL, "open error"); + #ifdef LARGE_FILE - if (fstat64(fd, &statbuf) == -1) { + if (fstat64(fd, &statbuf) == -1) #else /* LARGE_FILE */ - if (fstat(fd, &statbuf) == -1) { + if (fstat(fd, &statbuf) == -1) #endif /* LARGE_FILE */ - perror("stat error"); - /***** LTP Port *****/ - local_flag = FAILED; - anyfail(); - /***** ** *****/ - return 0; - } + tst_brk(TFAIL, "stat error"); + #ifdef LARGE_FILE - if (lseek64(fd, sparseoffset, SEEK_SET) < 0) { + if (lseek64(fd, sparseoffset, SEEK_SET) < 0) #else /* LARGE_FILE */ - if (lseek(fd, sparseoffset, SEEK_SET) < 0) { + if (lseek(fd, sparseoffset, SEEK_SET) < 0) #endif /* LARGE_FILE */ - perror("lseek"); - anyfail(); - } + tst_brk(TFAIL, "lseek"); - if (statbuf.st_size - sparseoffset > SIZE_MAX) { - fprintf(stderr, "size_t overflow when setting up map\n"); - anyfail(); - } + if (statbuf.st_size - sparseoffset > UINT_MAX) + tst_brk(TFAIL, "size_t overflow when setting up map"); mapsize = (size_t) (statbuf.st_size - sparseoffset); mappages = roundup(mapsize, pagesize) / pagesize; @@ -651,20 +559,14 @@ int fileokay(char *file, uchar_t * expbuf) for (i = 0; i < mappages; i++) { cnt = read(fd, readbuf, pagesize); if (cnt == -1) { - perror("read error"); - /***** LTP Port *****/ - local_flag = FAILED; - anyfail(); - /***** ** *****/ - return 0; - } else if (cnt != pagesize) { + tst_brk(TFAIL, "read error"); + } else if ((unsigned int)cnt != pagesize) { /* * Okay if at last page in file... */ if ((i * pagesize) + cnt != mapsize) { - (void)fprintf(stderr, "read %d of %ld bytes\n", - (i * pagesize) + cnt, - (long)mapsize); + tst_res(TINFO, "read %d of %ld bytes", + (i * pagesize) + cnt, (long)mapsize); close(fd); return 0; } @@ -672,19 +574,16 @@ int fileokay(char *file, uchar_t * expbuf) /* * Compare read bytes of data. */ - for (j = 0; j < cnt; j++) { + for (j = 0; j < (unsigned int)cnt; j++) { if (expbuf[j] != readbuf[j]) { - (void)fprintf(stderr, - "read bad data: exp %c got %c)", - expbuf[j], readbuf[j]); + tst_res(TINFO, "read bad data: exp %c got %c)", + expbuf[j], readbuf[j]); #ifdef LARGE_FILE - (void)fprintf(stderr, ", pg %d off %d, " - "(fsize %Ld)\n", i, j, - statbuf.st_size); + tst_res(TINFO, ", pg %d off %d, " + "(fsize %Ld)", i, j, statbuf.st_size); #else /* LARGE_FILE */ - (void)fprintf(stderr, ", pg %d off %d, " - "(fsize %ld)\n", i, j, - statbuf.st_size); + tst_res(TINFO, ", pg %d off %d, " + "(fsize %ld)", i, j, statbuf.st_size); #endif /* LARGE_FILE */ close(fd); return 0; @@ -696,7 +595,7 @@ int fileokay(char *file, uchar_t * expbuf) return 1; } - /*ARGSUSED*/ void finish(int sig) +void finish(int sig LTP_ATTRIBUTE_UNUSED) { finished++; return; @@ -722,17 +621,7 @@ unsigned int initrand(void) return (seed); } -/***** LTP Port *****/ -void ok_exit(void) -{ - tst_resm(TPASS, "Test passed"); - tst_rmdir(); - tst_exit(); -} - -int anyfail(void) -{ - tst_brkm(TFAIL, tst_rmdir, "Test failed"); -} - -/***** ** ** *****/ +static struct tst_test test = { + .needs_tmpdir = 1, + .cleanup = cleanup, +}; From patchwork Fri Sep 30 17:59:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 1684979 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=JK2XYcrH; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MfJ1G6KSCz1yql for ; Sat, 1 Oct 2022 04:00:34 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E6D9E3CA924 for ; Fri, 30 Sep 2022 20:00:31 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [217.194.8.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id DFCDA3CA990 for ; Fri, 30 Sep 2022 20:00:15 +0200 (CEST) Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id C7B741A01747 for ; Fri, 30 Sep 2022 20:00:13 +0200 (CEST) Received: by mail-pf1-x44a.google.com with SMTP id j11-20020a056a00234b00b005415b511595so3176064pfj.12 for ; Fri, 30 Sep 2022 11:00:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date; bh=HJi+7ouVXW2bAcRDdb8WxGOvC1/03RBY0WicBLQ3bBE=; b=JK2XYcrHM//A/uY+o6LgCs/AA13SxrkE9bbrektxSetUeCUXyrF21VdLNu0dPZ1fsy LnMQkyoMPiBNOajR+SU9o/6Q+hEJK3RU298/t7MVrKGyr2JEGKuw5NE80ufcOYrdmRZw xIvv6CTFifvMzDivfuB87K9aPgUS9Jbsrb7jNv9hGl96S8+yqCDmnEYz8RAa/3nN6D2o tR9Z6he16oHaiNoLjX1UeDRnEor+IBrFR4KH15g4usz4DiRg+oeuwona84VT+rftWetU Q3fHnPpvE8HRhmtxTHdG8Ey/VkGfZWHf4EwjOfWTFmXtxg5QhQs9pnLo+sYIXdFEaKDZ Q0iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=HJi+7ouVXW2bAcRDdb8WxGOvC1/03RBY0WicBLQ3bBE=; b=M5/7BCelYnPHxSqXcMGq+6oTUbCnjlG1Y85sF7hxzfPOVwqCQXvSN9HFYvYxlGRL1o 0iCiMo0rqIw0Ep3+W+NKrT9DhUvp1motVVUVTeiLVEpK5o9hIUli7PfY1FumOgd5iGLJ XV6J7zd4a1zNYCM79MF7Fli1lbmsLgnafad5WOznmTSdrUCe2nF1BEOXjT9cbfrFnxNu Zi6FntmZXMjVHR6fMJdExUKnf0z6YkCDIIkTdqHOLcCJ0BmCYNUY9/I+93cQ6FlcdMQJ 5Ae2IUGJ5j7lUgSyKfTOcCVN4EnJEO+V48KOu0bxChIH+Qp28o35Lh89bp9Ynwwh1T/P DxHQ== X-Gm-Message-State: ACrzQf1PPqoR3c7WAYdI2aP37Fxh4tKxljuc4cW/6xJO/Vn/ndHVcjJp odgjK1c690fh0LD2bpcRCGtHKcZdMrAZHmGHLd+lU85Eaq2nnnVV22edDX2S5m8ioMeQxTvhXgI wNbdZN2hl//AVOFliQXoFECAN65ReB4Hoblrug24kTJNEELEuIO3u51ir X-Google-Smtp-Source: AMsMyM7v0SPak+XXSnPa3mAyxuKj+nQAHnrFFaNCyLM1wUChBbUK0p3m0uE6/OvGEpOvsckRzv6T8xGV+Do= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a17:902:7894:b0:178:bb0b:5740 with SMTP id q20-20020a170902789400b00178bb0b5740mr10530267pll.65.1664560810733; Fri, 30 Sep 2022 11:00:10 -0700 (PDT) Date: Fri, 30 Sep 2022 17:59:57 +0000 In-Reply-To: <20220930175959.3955586-1-edliaw@google.com> Mime-Version: 1.0 References: <20220930175959.3955586-1-edliaw@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20220930175959.3955586-3-edliaw@google.com> To: ltp@lists.linux.it X-Virus-Scanned: clamav-milter 0.102.4 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-7.4 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH v2 2/4] mmapstress01: refactor options X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Edward Liaw via ltp From: Edward Liaw Reply-To: Edward Liaw Cc: kernel-team@android.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Edward Liaw --- .../kernel/mem/mmapstress/mmapstress01.c | 195 ++++++++---------- 1 file changed, 88 insertions(+), 107 deletions(-) diff --git a/testcases/kernel/mem/mmapstress/mmapstress01.c b/testcases/kernel/mem/mmapstress/mmapstress01.c index 41f94a52a..90cb285d6 100644 --- a/testcases/kernel/mem/mmapstress/mmapstress01.c +++ b/testcases/kernel/mem/mmapstress/mmapstress01.c @@ -74,7 +74,7 @@ #include #include #include -#define TST_NO_DEFAULT_MAIN +#include #include "tst_test.h" #define MAXLOOPS 500 /* max pages for map children to write */ @@ -93,52 +93,103 @@ extern long lrand48(void); extern void srand(unsigned int); extern void srand48(long); extern int rand(void); -extern int atoi(const char *); - -static char *usage = - "-p nprocs [-t minutes -f filesize -S sparseoffset -r -o -m -l -d]"; static unsigned int initrand(void); static void finish(int sig); static void child_mapper(char *file, unsigned int procno, unsigned int nprocs); static int fileokay(char *file, unsigned char *expbuf); static int finished = 0; -static int leavefile = 0; + +static char *debug; +static char *leavefile; +static char *do_sync; +static char *do_offset; +static char *randloops; +static char *opt_filesize; +static char *opt_nprocs; +static char *opt_sparseoffset; +static char *opt_alarmtime; static float alarmtime = 0; -static unsigned int nprocs = 0; +static int nprocs = 0; +static long long filesize = FILESIZE; +static long long sparseoffset = 0; +static unsigned int pattern = 0; static pid_t *pidarray = NULL; static int wait_stat; static int check_for_sanity; static unsigned char *buf = NULL; +static struct tst_option options[] = { + {"d", &debug, "Enable debug output"}, + {"f:", &opt_filesize, "Initial filesize (default 4096)"}, + {"l", &leavefile, "Don't remove the output file on program exit"}, + {"m", &do_sync, "Do random msync/fsyncs as well"}, + {"o", &do_offset, "Randomize the offset of file to map"}, + {"p:", &opt_nprocs, "Number of mapping children to create (required)"}, + {"r", &randloops, + "Randomize number of pages map children check (random % MAXLOOPS), " + "otherwise each child checks MAXLOOPS pages"}, + {"S:", &opt_sparseoffset, + "When non-zero, causes the sparse area to be left before the data, " + "so that the actual initial filesize is sparseoffset + filesize " + "(default 0)"}, + {"t:", &opt_alarmtime, "Number of minutes to run (default 0)"}, +}; + +static void setup(void) +{ + int pagesize = sysconf(_SC_PAGE_SIZE); + + if (!opt_nprocs) + tst_brk(TBROK, + "missing number of mapping children, specify with -p nprocs"); -static int debug = 0; #ifdef LARGE_FILE -static off64_t filesize = FILESIZE; -static off64_t sparseoffset = 0; -#else /* LARGE_FILE */ -static off_t filesize = FILESIZE; -static off_t sparseoffset = 0; -#endif /* LARGE_FILE */ -static unsigned int randloops = 0; -static unsigned int dosync = 0; -static unsigned int do_offset = 0; -static unsigned int pattern = 0; + if (tst_parse_filesize(opt_filesize, &filesize, 0, LONG_MAX)) +#else + if (tst_parse_filesize(opt_filesize, &filesize, 0, INT_MAX)) +#endif + tst_brk(TBROK, "invalid initial filesize '%s'", opt_filesize); + +#ifdef LARGE_FILE + if (tst_parse_filesize(opt_sparseoffset, &sparseoffset, LONG_MIN, LONG_MAX)) +#else + if (tst_parse_filesize(opt_sparseoffset, &sparseoffset, INT_MIN, INT_MAX)) +#endif + tst_brk(TBROK, "invalid sparse offset '%s'", opt_sparseoffset); + if (sparseoffset % pagesize != 0) + tst_brk(TBROK, "sparseoffset must be pagesize multiple"); -int main(int argc, char *argv[]) + if (tst_parse_int(opt_nprocs, &nprocs, 0, 255)) + tst_brk(TBROK, "invalid number of mapping children '%s'", + opt_nprocs); + + if (tst_parse_float(opt_alarmtime, &alarmtime, 0, FLT_MAX / 60)) + tst_brk(TBROK, "invalid minutes to run '%s'", opt_alarmtime); + + if (debug) { + tst_res(TINFO, "creating file <%s> with %lld bytes, pattern %d", + TEST_FILE, filesize, pattern); + if (alarmtime) + tst_res(TINFO, "running for %f minutes", alarmtime); + else + tst_res(TINFO, "running with no time limit"); + } + alarmtime *= 60; +} + +static void run(void) { - char *progname; int fd; int c; - extern char *optarg; - unsigned int procno; + int procno; pid_t pid; unsigned int seed; int pagesize = sysconf(_SC_PAGE_SIZE); struct sigaction sa; - unsigned int i; + int i; int write_cnt; unsigned char data; #ifdef LARGE_FILE @@ -147,82 +198,9 @@ int main(int argc, char *argv[]) off_t bytes_left; #endif /* LARGE_FILE */ - progname = *argv; - if (argc < 2) { - tst_brk(TBROK, "usage: %s %s", progname, usage); - } - - while ((c = getopt(argc, argv, "S:omdlrf:p:t:")) != -1) { - switch (c) { - case 'd': - debug = 1; - break; - case 't': - alarmtime = atof(optarg) * 60; - break; - case 'p': - nprocs = atoi(optarg); - break; - case 'l': - leavefile = 1; - break; - case 'f': -#ifdef LARGE_FILE - filesize = atoll(optarg); -#else /* LARGE_FILE */ - filesize = atoi(optarg); -#endif /* LARGE_FILE */ - if (filesize < 0) - tst_brk(TBROK, "error: negative filesize"); - break; - case 'r': - randloops = 1; - break; - case 'm': - dosync = 1; - break; - case 'o': - do_offset = 1; - break; - case 'S': -#ifdef LARGE_FILE - sparseoffset = atoll(optarg); -#else /* LARGE_FILE */ - sparseoffset = atoi(optarg); -#endif /* LARGE_FILE */ - if (sparseoffset % pagesize != 0) - tst_brk(TBROK, - "sparseoffset must be pagesize multiple"); - break; - default: - tst_brk(TBROK, "usage: %s %s", progname, usage); - } - } - - /* nprocs is >= 0 since it's unsigned */ - if (nprocs > 255) - tst_brk(TBROK, "invalid nprocs %d - (range 0-255)", nprocs); - seed = initrand(); pattern = seed & 0xff; - if (debug) { -#ifdef LARGE_FILE - tst_res(TINFO, "creating file <%s> with %Ld bytes, pattern %d", - TEST_FILE, filesize, pattern); -#else /* LARGE_FILE */ - tst_res(TINFO, "creating file <%s> with %ld bytes, pattern %d", - TEST_FILE, filesize, pattern); -#endif /* LARGE_FILE */ - if (alarmtime) - tst_res(TINFO, "running for %f minutes", - alarmtime / 60); - else - tst_res(TINFO, "running with no time limit"); - } - - tst_reinit(); - /* * Plan for death by signal. User may have specified * a time limit, in which set an alarm and catch SIGALRM. @@ -300,7 +278,7 @@ int main(int argc, char *argv[]) break; case 0: - child_mapper(TEST_FILE, procno, nprocs); + child_mapper(TEST_FILE, (unsigned int)procno, (unsigned int)nprocs); exit(0); default: @@ -341,7 +319,7 @@ int main(int argc, char *argv[]) pidarray[i] = 0; tst_brk(TFAIL, "fork error"); } else if (pid == 0) { /* child */ - child_mapper(TEST_FILE, i, nprocs); + child_mapper(TEST_FILE, (unsigned int)i, (unsigned int)nprocs); exit(0); } else { pidarray[i] = pid; @@ -457,14 +435,14 @@ void child_mapper(char *file, unsigned int procno, unsigned int nprocs) if (debug) tst_res(TINFO, "child %d (pid %d): seed %d, fsize %lld, mapsize %ld, off %lld, loop %d", - procno, getpid(), seed, filesize, (long)mapsize, - offset / pagesize, nloops); + procno, getpid(), seed, (long long)filesize, + (long)mapsize, (long long)offset / pagesize, nloops); #ifdef LARGE_FILE if ((maddr = mmap64(0, mapsize, PROT_READ | PROT_WRITE, MAP_SHARED, - fd, (off64_t)offset)) == (caddr_t) - 1) + fd, offset)) == (caddr_t) - 1) #else /* LARGE_FILE */ if ((maddr = mmap(0, mapsize, PROT_READ | PROT_WRITE, MAP_SHARED, - fd, (off_t)offset)) == (caddr_t) - 1) + fd, offset)) == (caddr_t) - 1) #endif /* LARGE_FILE */ tst_brk(TFAIL, "mmap error"); @@ -496,7 +474,7 @@ void child_mapper(char *file, unsigned int procno, unsigned int nprocs) *(paddr + i) = (procno + pattern) & 0xff; } } - if (dosync) { + if (do_sync) { /* * Exercise msync() as well! */ @@ -579,11 +557,11 @@ int fileokay(char *file, unsigned char *expbuf) tst_res(TINFO, "read bad data: exp %c got %c)", expbuf[j], readbuf[j]); #ifdef LARGE_FILE - tst_res(TINFO, ", pg %d off %d, " - "(fsize %Ld)", i, j, statbuf.st_size); + tst_res(TINFO, ", pg %d off %d, (fsize %Ld)", + i, j, statbuf.st_size); #else /* LARGE_FILE */ - tst_res(TINFO, ", pg %d off %d, " - "(fsize %ld)", i, j, statbuf.st_size); + tst_res(TINFO, ", pg %d off %d, (fsize %ld)", + i, j, statbuf.st_size); #endif /* LARGE_FILE */ close(fd); return 0; @@ -623,5 +601,8 @@ unsigned int initrand(void) static struct tst_test test = { .needs_tmpdir = 1, + .test_all = run, + .setup = setup, + .options = options, .cleanup = cleanup, }; From patchwork Fri Sep 30 17:59:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 1684980 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=dL3PdP7P; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MfJ1T3VRdz1yql for ; Sat, 1 Oct 2022 04:00:45 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 9BAA93CA968 for ; Fri, 30 Sep 2022 20:00:42 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [217.194.8.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 941613CAA78 for ; Fri, 30 Sep 2022 20:00:16 +0200 (CEST) Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 490DA20115D for ; Fri, 30 Sep 2022 20:00:14 +0200 (CEST) Received: by mail-pj1-x104a.google.com with SMTP id hk15-20020a17090b224f00b00205fa3483bdso5057857pjb.8 for ; Fri, 30 Sep 2022 11:00:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date; bh=z3xOG2z4wiuhhrM2NmLfl6jflzYQeqnglOSK0uDgGeA=; b=dL3PdP7PvONTZwtGD7xs0J3Teo6Q/7FTuTMXH6vB+s19okdLtq41f9ErZ7m2HXzO3/ 9QkATjb5T+plbKYwu8cn6/4fyLjY0xBSHlBJoMEwUu5+LCnjs9lGAXL5ffDvxng998Of 8pXL7GOvKHtdte9vNG/4b04chWgJmzW/UvygMZjxIuQZ3fmdU2jwxphgqPZybiahawH8 fmTwx3a+akPDoCBkaeqqIMb9uFZDh1FW3Ciu6Rl8rLISFqxrdthBnNLgqxJ7n/5Yp56k +V8vq0E+DvqYty1uyZW6ykyTieQaaxMnb/CkQNhsqD65rbv1lRO5Wmu2dXLaVBD6iqTA geuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=z3xOG2z4wiuhhrM2NmLfl6jflzYQeqnglOSK0uDgGeA=; b=7A+kZcvrjfdFAtGnap+NeF1Iy1DzBbAFgBBBb4pt2Kwibf2ZaPGEGV7rKqF7ByRgYa wELL09V+F/ORUT7JI256Oz8BJY7NGx4gwF7q+DEe7s8J2j7iZCdCm8vIv38H8tybYAJ4 JPdzsPjkGmiXoBYBceb5KMssHiZhb7kAMYEL1n0K50kH2y/WX1ZS8TIiQ83alwlxmn3h 9VB1Da95iQxJivsj3m4a6oywsWT5nILdOqzZeVLAka16QX7l70/eajfDm4bd9Ixabi8t OvjcI8m+0S2uP6q4BOh5hux9R+l7TtkSgL0wirQzrrjVNhLUCco75m+43L3tmIwSdA87 P8ug== X-Gm-Message-State: ACrzQf3qZlf7zxM2W1sBq9VEtTmF4GIzpk8dZnZV1Mb0HwZV7Qcuq3By t5oEvJsZZb8AIJZG532rIFWzDlrYu9NE1C3veiVNHYZXSL2ch7U/JdKKTAV5H/98S1HnDKgIjUA vo7+wvVknMj85j6CFvrKtt2bjvoA2dr5kdR6tfoY6+AdEIIeAWDjC5icz X-Google-Smtp-Source: AMsMyM7eYze/ddJ8q6dBuR6fy/3QlDcV/wwqK1xgNcmtQpoFHHiJIVDLEaKZyKK7kH8iUU5No4znq02lEJE= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a17:90b:3808:b0:202:c5ba:d71b with SMTP id mq8-20020a17090b380800b00202c5bad71bmr23279072pjb.18.1664560812654; Fri, 30 Sep 2022 11:00:12 -0700 (PDT) Date: Fri, 30 Sep 2022 17:59:58 +0000 In-Reply-To: <20220930175959.3955586-1-edliaw@google.com> Mime-Version: 1.0 References: <20220930175959.3955586-1-edliaw@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20220930175959.3955586-4-edliaw@google.com> To: ltp@lists.linux.it X-Virus-Scanned: clamav-milter 0.102.4 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-7.4 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v2 3/4] mmapstress01: use FILE_OFFSET_BITS=64 X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Edward Liaw via ltp From: Edward Liaw Reply-To: Edward Liaw Cc: kernel-team@android.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Build tests with FILE_OFFSET_BITS=64 instead of doing LARGE_FILE checks to switch between 32 and 64 bit types and syscalls. Signed-off-by: Edward Liaw --- testcases/kernel/mem/mmapstress/Makefile | 2 + .../kernel/mem/mmapstress/mmapstress01.c | 64 ++----------------- 2 files changed, 8 insertions(+), 58 deletions(-) diff --git a/testcases/kernel/mem/mmapstress/Makefile b/testcases/kernel/mem/mmapstress/Makefile index 744f099d8..b30bd34b8 100644 --- a/testcases/kernel/mem/mmapstress/Makefile +++ b/testcases/kernel/mem/mmapstress/Makefile @@ -5,3 +5,5 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk include $(top_srcdir)/include/mk/generic_leaf_target.mk + +mmapstress01: CFLAGS += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE diff --git a/testcases/kernel/mem/mmapstress/mmapstress01.c b/testcases/kernel/mem/mmapstress/mmapstress01.c index 90cb285d6..0f5071a20 100644 --- a/testcases/kernel/mem/mmapstress/mmapstress01.c +++ b/testcases/kernel/mem/mmapstress/mmapstress01.c @@ -146,14 +146,14 @@ static void setup(void) tst_brk(TBROK, "missing number of mapping children, specify with -p nprocs"); -#ifdef LARGE_FILE +#if _FILE_OFFSET_BITS == 64 if (tst_parse_filesize(opt_filesize, &filesize, 0, LONG_MAX)) #else if (tst_parse_filesize(opt_filesize, &filesize, 0, INT_MAX)) #endif tst_brk(TBROK, "invalid initial filesize '%s'", opt_filesize); -#ifdef LARGE_FILE +#if _FILE_OFFSET_BITS == 64 if (tst_parse_filesize(opt_sparseoffset, &sparseoffset, LONG_MIN, LONG_MAX)) #else if (tst_parse_filesize(opt_sparseoffset, &sparseoffset, INT_MIN, INT_MAX)) @@ -192,11 +192,7 @@ static void run(void) int i; int write_cnt; unsigned char data; -#ifdef LARGE_FILE - off64_t bytes_left; -#else /* LARGE_FILE */ off_t bytes_left; -#endif /* LARGE_FILE */ seed = initrand(); pattern = seed & 0xff; @@ -223,11 +219,7 @@ static void run(void) tst_brk(TFAIL, "sigaction error"); (void)alarm(alarmtime); } -#ifdef LARGE_FILE - if ((fd = open64(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, 0664)) == -1) { -#else /* LARGE_FILE */ if ((fd = open(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, 0664)) == -1) { -#endif /* LARGE_FILE */ tst_brk(TFAIL, "open error"); } @@ -244,11 +236,7 @@ static void run(void) if (++data == nprocs) data = 0; } -#ifdef LARGE_FILE - if (lseek64(fd, (off64_t)sparseoffset, SEEK_SET) < 0) { -#else /* LARGE_FILE */ if (lseek(fd, (off_t)sparseoffset, SEEK_SET) < 0) { -#endif /* LARGE_FILE */ tst_brk(TFAIL, "lseek"); } for (bytes_left = filesize; bytes_left; bytes_left -= c) { @@ -381,15 +369,9 @@ static void cleanup(void) */ void child_mapper(char *file, unsigned int procno, unsigned int nprocs) { -#ifdef LARGE_FILE - struct stat64 statbuf; - off64_t filesize; - off64_t offset; -#else /* LARGE_FILE */ struct stat statbuf; off_t filesize; off_t offset; -#endif /* LARGE_FILE */ size_t validsize; size_t mapsize; char *maddr = NULL, *paddr; @@ -404,19 +386,11 @@ void child_mapper(char *file, unsigned int procno, unsigned int nprocs) seed = initrand(); /* initialize random seed */ -#ifdef LARGE_FILE - if (stat64(file, &statbuf) == -1) -#else /* LARGE_FILE */ if (stat(file, &statbuf) == -1) -#endif /* LARGE_FILE */ tst_brk(TFAIL, "stat error"); filesize = statbuf.st_size; -#ifdef LARGE_FILE - if ((fd = open64(file, O_RDWR)) == -1) -#else /* LARGE_FILE */ if ((fd = open(file, O_RDWR)) == -1) -#endif /* LARGE_FILE */ tst_brk(TFAIL, "open error"); if (statbuf.st_size - sparseoffset > UINT_MAX) @@ -437,13 +411,8 @@ void child_mapper(char *file, unsigned int procno, unsigned int nprocs) tst_res(TINFO, "child %d (pid %d): seed %d, fsize %lld, mapsize %ld, off %lld, loop %d", procno, getpid(), seed, (long long)filesize, (long)mapsize, (long long)offset / pagesize, nloops); -#ifdef LARGE_FILE - if ((maddr = mmap64(0, mapsize, PROT_READ | PROT_WRITE, MAP_SHARED, - fd, offset)) == (caddr_t) - 1) -#else /* LARGE_FILE */ if ((maddr = mmap(0, mapsize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset)) == (caddr_t) - 1) -#endif /* LARGE_FILE */ tst_brk(TFAIL, "mmap error"); (void)close(fd); @@ -494,11 +463,7 @@ void child_mapper(char *file, unsigned int procno, unsigned int nprocs) */ int fileokay(char *file, unsigned char *expbuf) { -#ifdef LARGE_FILE - struct stat64 statbuf; -#else /* LARGE_FILE */ struct stat statbuf; -#endif /* LARGE_FILE */ size_t mapsize; unsigned int mappages; unsigned int pagesize = sysconf(_SC_PAGE_SIZE); @@ -507,25 +472,13 @@ int fileokay(char *file, unsigned char *expbuf) int cnt; unsigned int i, j; -#ifdef LARGE_FILE - if ((fd = open64(file, O_RDONLY)) == -1) -#else /* LARGE_FILE */ if ((fd = open(file, O_RDONLY)) == -1) -#endif /* LARGE_FILE */ tst_brk(TFAIL, "open error"); -#ifdef LARGE_FILE - if (fstat64(fd, &statbuf) == -1) -#else /* LARGE_FILE */ if (fstat(fd, &statbuf) == -1) -#endif /* LARGE_FILE */ tst_brk(TFAIL, "stat error"); -#ifdef LARGE_FILE - if (lseek64(fd, sparseoffset, SEEK_SET) < 0) -#else /* LARGE_FILE */ if (lseek(fd, sparseoffset, SEEK_SET) < 0) -#endif /* LARGE_FILE */ tst_brk(TFAIL, "lseek"); if (statbuf.st_size - sparseoffset > UINT_MAX) @@ -554,15 +507,10 @@ int fileokay(char *file, unsigned char *expbuf) */ for (j = 0; j < (unsigned int)cnt; j++) { if (expbuf[j] != readbuf[j]) { - tst_res(TINFO, "read bad data: exp %c got %c)", - expbuf[j], readbuf[j]); -#ifdef LARGE_FILE - tst_res(TINFO, ", pg %d off %d, (fsize %Ld)", - i, j, statbuf.st_size); -#else /* LARGE_FILE */ - tst_res(TINFO, ", pg %d off %d, (fsize %ld)", - i, j, statbuf.st_size); -#endif /* LARGE_FILE */ + tst_res(TINFO, + "read bad data: exp %c got %c, pg %d off %d, (fsize %lld)", + expbuf[j], readbuf[j], i, j, + (long long)statbuf.st_size); close(fd); return 0; } From patchwork Fri Sep 30 17:59:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 1684981 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=hi+d6qHZ; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MfJ1f5M7Nz1yql for ; Sat, 1 Oct 2022 04:00:54 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 1D0523CAA78 for ; Fri, 30 Sep 2022 20:00:52 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id C47033CAAE9 for ; Fri, 30 Sep 2022 20:00:16 +0200 (CEST) Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id F17DA140075D for ; Fri, 30 Sep 2022 20:00:15 +0200 (CEST) Received: by mail-pl1-x64a.google.com with SMTP id k2-20020a170902c40200b001782bd6c416so3710119plk.20 for ; Fri, 30 Sep 2022 11:00:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date; bh=il8dMVGdybulSzwK0RPt+bs7nkLT8s4scRqbMcDfoCA=; b=hi+d6qHZbqkc0BwojT2PILsO3uahyH/f2UiT00yp0tvXibnEHPRAbbTZov8sDccz4r oNRCsnbWu7YhTS9qwLNZVdOX+rmhi0IP7kJPwdjg6+o6R2n9pfChsIhn7sozuCVNQ8PI LNPekJxY2qykZS6nLixJkT6h6adnhT3Q2OC0Oi1vZnmaHT98oSREdn1mP/1SAaGa55O4 vh75b7wWd1n8zmueNxzpT1outyhcb7SgWnrmVz5FjTIvb4N0nSSC45SqF6ZOjZRJv/4W YStwz83PMrVcuG/qsandiW1swZ5xCefACdTOC24SpVCfrivOHAVHYDBYSvrGpfTD2dq3 5/EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=il8dMVGdybulSzwK0RPt+bs7nkLT8s4scRqbMcDfoCA=; b=GC6ftkYCT39vR2/6bhfJv454UNgZOxZOP6weJK99D8cWFEdrGm/Bs5Q1GbyJJ/B93Z iI6JynwuQp+p19PMq195EdXN2c0bjmVT0BNiQq3cYX4zwNKUgTuoz9AqTlx2rxwxWMEK 6roxmtM4HgkPI30B93NespXTxduLgOO+6c6I6zCTMG+LpC49P+p8eFPUbGt48bI2EiHw SnIfAQiL9RBjKcosGFUNdQYIuN6Q1DEBD1Et6Dymdn4TSz8fteDJf24a3AYtsiBFzieJ oKONS9rMN1lq42isn4bchQICvxVGHCadJRy5aHPSX67lr5IdgrfjGNzIqGgFeoCRnHq1 842g== X-Gm-Message-State: ACrzQf18Gbye3L5D7UKZS+IRTJjOfP6Dl6AnEZgJ90gakPq9JfY9KeYm 2nE8vSPlweHsJt1sse8dvCu9K0KNcZchx/ZLowP5FchRdBzEfVVyklo34pBHW1wHfgOBvxpbItz agiLKJyOhcNCBp7Axmk03tvaDIMxHx5nsq1MLbG3//LY64XeYVhKs2MIp X-Google-Smtp-Source: AMsMyM7F0rgnpDsV3P54j80EAQr7O6068ek8mhXc63WQ5gy8JCC/QsKW+bPxe+Hbckl7HRJJrmtpz5zcN9A= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a62:1c8f:0:b0:537:2284:bd00 with SMTP id c137-20020a621c8f000000b005372284bd00mr10078222pfc.78.1664560814442; Fri, 30 Sep 2022 11:00:14 -0700 (PDT) Date: Fri, 30 Sep 2022 17:59:59 +0000 In-Reply-To: <20220930175959.3955586-1-edliaw@google.com> Mime-Version: 1.0 References: <20220930175959.3955586-1-edliaw@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20220930175959.3955586-5-edliaw@google.com> To: ltp@lists.linux.it X-Virus-Scanned: clamav-milter 0.102.4 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-7.4 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH v2 4/4] mmapstress01: use safe macros X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Edward Liaw via ltp From: Edward Liaw Reply-To: Edward Liaw Cc: kernel-team@android.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Edward Liaw --- .../kernel/mem/mmapstress/mmapstress01.c | 85 ++++++++----------- 1 file changed, 34 insertions(+), 51 deletions(-) diff --git a/testcases/kernel/mem/mmapstress/mmapstress01.c b/testcases/kernel/mem/mmapstress/mmapstress01.c index 0f5071a20..955d6ac3f 100644 --- a/testcases/kernel/mem/mmapstress/mmapstress01.c +++ b/testcases/kernel/mem/mmapstress/mmapstress01.c @@ -193,6 +193,7 @@ static void run(void) int write_cnt; unsigned char data; off_t bytes_left; + sigset_t set_mask; seed = initrand(); pattern = seed & 0xff; @@ -204,29 +205,19 @@ static void run(void) */ sa.sa_handler = finish; sa.sa_flags = 0; - if (sigemptyset(&sa.sa_mask)) - tst_brk(TFAIL, "sigemptyset error"); - - if (sigaction(SIGINT, &sa, 0) == -1) - tst_brk(TFAIL, "sigaction error SIGINT"); - if (sigaction(SIGQUIT, &sa, 0) == -1) - tst_brk(TFAIL, "sigaction error SIGQUIT"); - if (sigaction(SIGTERM, &sa, 0) == -1) - tst_brk(TFAIL, "sigaction error SIGTERM"); + SAFE_SIGEMPTYSET(&sa.sa_mask); + SAFE_SIGACTION(SIGINT, &sa, 0); + SAFE_SIGACTION(SIGQUIT, &sa, 0); + SAFE_SIGACTION(SIGTERM, &sa, 0); if (alarmtime) { - if (sigaction(SIGALRM, &sa, 0) == -1) - tst_brk(TFAIL, "sigaction error"); + SAFE_SIGACTION(SIGALRM, &sa, 0); (void)alarm(alarmtime); } - if ((fd = open(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, 0664)) == -1) { - tst_brk(TFAIL, "open error"); - } + fd = SAFE_OPEN(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, 0664); - if ((buf = malloc(pagesize)) == NULL - || (pidarray = malloc(nprocs * sizeof(pid_t))) == NULL) { - tst_brk(TFAIL, "malloc error"); - } + buf = SAFE_MALLOC(pagesize); + pidarray = SAFE_MALLOC(nprocs * sizeof(pid_t)); for (i = 0; i < nprocs; i++) *(pidarray + i) = 0; @@ -236,9 +227,7 @@ static void run(void) if (++data == nprocs) data = 0; } - if (lseek(fd, (off_t)sparseoffset, SEEK_SET) < 0) { - tst_brk(TFAIL, "lseek"); - } + SAFE_LSEEK(fd, (off_t)sparseoffset, SEEK_SET); for (bytes_left = filesize; bytes_left; bytes_left -= c) { write_cnt = MIN(pagesize, (int)bytes_left); if ((c = write(fd, buf, write_cnt)) != write_cnt) { @@ -247,13 +236,13 @@ static void run(void) else tst_res(TINFO, "write: wrote %d of %d bytes", c, write_cnt); - (void)close(fd); - (void)unlink(TEST_FILE); + SAFE_CLOSE(fd); + SAFE_UNLINK(TEST_FILE); tst_brk(TFAIL, "write error"); } } - (void)close(fd); + SAFE_CLOSE(fd); /* * Fork off mmap children. @@ -278,14 +267,16 @@ static void run(void) * Now wait for children and refork them as needed. */ + SAFE_SIGEMPTYSET(&set_mask); + SAFE_SIGADDSET(&set_mask, SIGALRM); + SAFE_SIGADDSET(&set_mask, SIGINT); while (!finished) { pid = wait(&wait_stat); /* * Block signals while processing child exit. */ - if (sighold(SIGALRM) || sighold(SIGINT)) - tst_brk(TFAIL, "sighold error"); + SAFE_SIGPROCMASK(SIG_BLOCK, &set_mask, NULL); if (pid != -1) { /* @@ -321,8 +312,7 @@ static void run(void) if (errno != EINTR || !finished) tst_brk(TFAIL, "unexpected wait error"); } - if (sigrelse(SIGALRM) || sigrelse(SIGINT)) - tst_brk(TFAIL, "sigrelse error"); + SAFE_SIGPROCMASK(SIG_UNBLOCK, &set_mask, NULL); } /* @@ -330,8 +320,9 @@ static void run(void) * the children and done!. */ - if (sighold(SIGALRM)) - tst_brk(TFAIL, "sighold error"); + SAFE_SIGEMPTYSET(&set_mask); + SAFE_SIGADDSET(&set_mask, SIGALRM); + SAFE_SIGPROCMASK(SIG_BLOCK, &set_mask, NULL); (void)alarm(0); check_for_sanity = 1; tst_res(TPASS, "finished, cleaning up"); @@ -352,7 +343,7 @@ static void cleanup(void) } else { tst_res(TINFO, "file data okay"); if (!leavefile) - (void)unlink(TEST_FILE); + SAFE_UNLINK(TEST_FILE); tst_res(TPASS, "test passed"); } } else { @@ -386,12 +377,10 @@ void child_mapper(char *file, unsigned int procno, unsigned int nprocs) seed = initrand(); /* initialize random seed */ - if (stat(file, &statbuf) == -1) - tst_brk(TFAIL, "stat error"); + SAFE_STAT(file, &statbuf); filesize = statbuf.st_size; - if ((fd = open(file, O_RDWR)) == -1) - tst_brk(TFAIL, "open error"); + fd = SAFE_OPEN(file, O_RDWR); if (statbuf.st_size - sparseoffset > UINT_MAX) tst_brk(TFAIL, "size_t overflow when setting up map"); @@ -411,11 +400,10 @@ void child_mapper(char *file, unsigned int procno, unsigned int nprocs) tst_res(TINFO, "child %d (pid %d): seed %d, fsize %lld, mapsize %ld, off %lld, loop %d", procno, getpid(), seed, (long long)filesize, (long)mapsize, (long long)offset / pagesize, nloops); - if ((maddr = mmap(0, mapsize, PROT_READ | PROT_WRITE, MAP_SHARED, - fd, offset)) == (caddr_t) - 1) - tst_brk(TFAIL, "mmap error"); - (void)close(fd); + maddr = SAFE_MMAP(0, mapsize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, + offset); + SAFE_CLOSE(fd); /* * Now loop read/writing random pages. @@ -453,8 +441,7 @@ void child_mapper(char *file, unsigned int procno, unsigned int nprocs) MS_SYNC) == -1) tst_brk(TFAIL, "msync failed"); } - if (munmap(maddr, mapsize) == -1) - tst_brk(TFAIL, "munmap failed"); + SAFE_MUNMAP(maddr, mapsize); exit(0); } @@ -472,14 +459,10 @@ int fileokay(char *file, unsigned char *expbuf) int cnt; unsigned int i, j; - if ((fd = open(file, O_RDONLY)) == -1) - tst_brk(TFAIL, "open error"); - - if (fstat(fd, &statbuf) == -1) - tst_brk(TFAIL, "stat error"); + fd = SAFE_OPEN(file, O_RDONLY); - if (lseek(fd, sparseoffset, SEEK_SET) < 0) - tst_brk(TFAIL, "lseek"); + SAFE_FSTAT(fd, &statbuf); + SAFE_LSEEK(fd, sparseoffset, SEEK_SET); if (statbuf.st_size - sparseoffset > UINT_MAX) tst_brk(TFAIL, "size_t overflow when setting up map"); @@ -498,7 +481,7 @@ int fileokay(char *file, unsigned char *expbuf) if ((i * pagesize) + cnt != mapsize) { tst_res(TINFO, "read %d of %ld bytes", (i * pagesize) + cnt, (long)mapsize); - close(fd); + SAFE_CLOSE(fd); return 0; } } @@ -511,12 +494,12 @@ int fileokay(char *file, unsigned char *expbuf) "read bad data: exp %c got %c, pg %d off %d, (fsize %lld)", expbuf[j], readbuf[j], i, j, (long long)statbuf.st_size); - close(fd); + SAFE_CLOSE(fd); return 0; } } } - close(fd); + SAFE_CLOSE(fd); return 1; }