From patchwork Tue Oct 4 18:20:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 1686064 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=213.254.12.146; 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=LhaYAhiX; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (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 4MhmHj2mcGz1ypH for ; Wed, 5 Oct 2022 05:21:37 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id F2EE43CADF2 for ; Tue, 4 Oct 2022 20:21:34 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [217.194.8.4]) (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 509DA3CA7E7 for ; Tue, 4 Oct 2022 20:21:19 +0200 (CEST) Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) (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-4.smtp.seeweb.it (Postfix) with ESMTPS id E75F3100061E for ; Tue, 4 Oct 2022 20:21:17 +0200 (CEST) Received: by mail-pg1-x549.google.com with SMTP id x23-20020a634857000000b0043c700f6441so9360515pgk.21 for ; Tue, 04 Oct 2022 11:21:17 -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=LhaYAhiXe1GT2C+rCUw52gFMNHW0sdE+W2W6B0ttedfOjWBJffUnqJiBnJDnmxFPdI 8R+qm50J2FIPIaYwpa26wJ7ewP1MA2ksgcvCDYkjfg/WjCsa/T0+drOTRPz7+Qf3DGFp c/BBZ2RscV+MAU/W24N7F6uNSNmDIiv6R6mQ0S+YjWIKj4vRPk8wUyqgg7nZUQWLqsaf oub2mVXgsOr1/oT+NkTs+a8Jw9ILkyq/xzzK3HJIMuCKeWNgliU/Ui4Ykp4A5kea9Blr x0ZgXf2MX4VvGcttXQJDYFDu3qK+e/2xWzI2mPLCBmIE2Lm40tBDfn2T9+w4zJ1NGGry DljA== 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=eG0RZmaMMmb/SjM9XzQUmpT+6PvCRZDUiR4JMkRsoZDHxmvmjW0CU6d/bcEgr25V8D NoFnDd9nxgR4lNCrPsyWP7Gkke3CMmuwa8mSnCU+9tajffUSblPOei/uMWhCirTX74j2 LKSA4+fSiwOchzZxphh95jzyIORKtI1GGkzqvzkmtqR4VBK+s8YLHDjAdcyTo/8hpOo1 m9MvGGhGVW09rcbS8QhiuOJUwZM/OhkmCq9N1qBPoxZQ4YPWJp3OuGypAtHursVpeaMw MniNCUQHUWthrEVviDONW90tIV/mirs9tK/nof5iIBE95QtJVFaBow3OedyhebaJDKXM 9oQA== X-Gm-Message-State: ACrzQf0KhD3XHU6xlptEBnZbA6c/JEejYAHAtrDENQ8frPqkleqftq2B SoGt/rUXGc+nIvP0q6aHgQHU9+fChUm3GZZPaybu+ZMTsuk0KOU9sKnjZ2+JI/H6OXaoNDnY7HH uGqHMBRy5wOFizlA812Gnt/GwsyCZSzRSx/Gm8RruT05/N7d6UJAyiIsp X-Google-Smtp-Source: AMsMyM5L+DfL3Y+uXCiAVpA7iStjrNWkT8U+aqL7Sf2/ZtzTOaISHxSgwipI4z5F6TCyfmuC0+eQhKBAoqM= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a17:902:db0a:b0:178:2636:b6de with SMTP id m10-20020a170902db0a00b001782636b6demr28527960plx.58.1664907676117; Tue, 04 Oct 2022 11:21:16 -0700 (PDT) Date: Tue, 4 Oct 2022 18:20:32 +0000 In-Reply-To: <20221004182040.1859774-1-edliaw@google.com> Mime-Version: 1.0 References: <20221004182040.1859774-1-edliaw@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221004182040.1859774-2-edliaw@google.com> To: ltp@lists.linux.it X-Virus-Scanned: clamav-milter 0.102.4 at in-4.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-4.smtp.seeweb.it Subject: [LTP] [PATCH v3 1/9] 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 Tue Oct 4 18:20:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 1686065 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=213.254.12.146; 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=i6J4U+EZ; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (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 4MhmHx6Jf0z1ypH for ; Wed, 5 Oct 2022 05:21:49 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E026D3CAC63 for ; Tue, 4 Oct 2022 20:21:47 +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)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 403123CAD76 for ; Tue, 4 Oct 2022 20:21:20 +0200 (CEST) Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) (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 5D2831A010F7 for ; Tue, 4 Oct 2022 20:21:19 +0200 (CEST) Received: by mail-pl1-x649.google.com with SMTP id m3-20020a170902bb8300b0017f7e7e4385so205501pls.20 for ; Tue, 04 Oct 2022 11:21:19 -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=GROnVb91ObSkQjtl2A8OjrHhW6Lh57XNN2m+6ey3+q8=; b=i6J4U+EZaMoxOsDl5t/jsfCl0eV+Hf/ev/Vn8FSTm5yYMg8wf8aMHmaJrtPsh1ZuYr DIN6r9cDUosTEKm9ORWu0NSQ1TmLRoTxbNg75tQEaq69xWyIZUNuPBRYcbHgTQCloSrY z4d1ZSM5nBj39xvgCVy+m7wru7bFtjJ/FJMBrZOzyC8UpK69lCDlwBV2B2+xrB0VVK0z YscM4FpAEfL7gulRujuWfpyZ/gd03Uz5U9YaRzERI6m2dUnLdgpnu8nIhy8NZ1yWOZeS 1L9qX4wVcI9pcoAbGcmM5aA1I3qPrgRXYzrsd4EuXshP9N4ToP4pWpxmvs/xBRXqdF/d nwIw== 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=GROnVb91ObSkQjtl2A8OjrHhW6Lh57XNN2m+6ey3+q8=; b=unFbzaj+ZOXcYQVhZEcPHN7X5mBxUyCxkb0DVAhu/YsouUuPVX+lAxXhegEQPoGDWT 1XPXlDzGs1faiBbi4rSzbYShOznTdqYbxSDP9H9x0kGeZNo8CwBvGUlBnV8xR6niTUl2 pzahKAQunkmGG3Kt6v1bRifr664M/anhYYdpW5ID29wbu/dHn13g6kyyMqM51wnNBZY/ /8qvXhlk+tR8vt8scSW04Tx7hwaN6N7PY1+ydKtbxCP4Uw9RB6+tJCJipNTEWoxN28sN 6WS8VsiENWoxcbQuk7QiIYWnKCoXYmpkWVbsiTy6hXSLOv3IDMmYrYQZ25i5/h070BWI TQFw== X-Gm-Message-State: ACrzQf1yUB0KxnY0oFpEaJXTxWgs9JnTtsQhu6z8H1iOPfRtXBCi1Fzo ueRBELyagR+9mNmIR73wLYk53Zt7wW9LceR6xlkPmVCnG7dayVT0LxugYOHQLhJmiH3caHVIaqo HSZVYUKs7ZWIqOOhpqnE24uSmf9hCO6TxcaMxE56l6sQ3LmwlVmBK7CJz X-Google-Smtp-Source: AMsMyM6nCq3ehp7gHiS/AksenKph0f7tWwj9HD407qmEk/3/A356rX98D6QwokQQekche9GVD35k7SlMeQY= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a63:5b16:0:b0:439:ac9b:34b5 with SMTP id p22-20020a635b16000000b00439ac9b34b5mr24260973pgb.144.1664907677616; Tue, 04 Oct 2022 11:21:17 -0700 (PDT) Date: Tue, 4 Oct 2022 18:20:33 +0000 In-Reply-To: <20221004182040.1859774-1-edliaw@google.com> Mime-Version: 1.0 References: <20221004182040.1859774-1-edliaw@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221004182040.1859774-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 v3 2/9] mmapstress01: apply make check suggestions 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 | 87 ++++++++----------- 1 file changed, 38 insertions(+), 49 deletions(-) diff --git a/testcases/kernel/mem/mmapstress/mmapstress01.c b/testcases/kernel/mem/mmapstress/mmapstress01.c index 41f94a52a..20574314b 100644 --- a/testcases/kernel/mem/mmapstress/mmapstress01.c +++ b/testcases/kernel/mem/mmapstress/mmapstress01.c @@ -86,46 +86,36 @@ #endif #define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) -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 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]"; + "-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 int finished; +static int leavefile; -static float alarmtime = 0; -static unsigned int nprocs = 0; +static float alarmtime; +static unsigned int nprocs; -static pid_t *pidarray = NULL; +static pid_t *pidarray; static int wait_stat; static int check_for_sanity; -static unsigned char *buf = NULL; - +static unsigned char *buf; -static int debug = 0; +static int debug; #ifdef LARGE_FILE static off64_t filesize = FILESIZE; -static off64_t sparseoffset = 0; +static off64_t sparseoffset; #else /* LARGE_FILE */ static off_t filesize = FILESIZE; -static off_t sparseoffset = 0; +static off_t sparseoffset; #endif /* LARGE_FILE */ -static unsigned int randloops = 0; -static unsigned int dosync = 0; -static unsigned int do_offset = 0; -static unsigned int pattern = 0; +static unsigned int randloops; +static unsigned int dosync; +static unsigned int do_offset; +static unsigned int pattern; int main(int argc, char *argv[]) { @@ -148,9 +138,8 @@ int main(int argc, char *argv[]) #endif /* LARGE_FILE */ progname = *argv; - if (argc < 2) { + if (argc < 2) tst_brk(TBROK, "usage: %s %s", progname, usage); - } while ((c = getopt(argc, argv, "S:omdlrf:p:t:")) != -1) { switch (c) { @@ -192,7 +181,7 @@ int main(int argc, char *argv[]) #endif /* LARGE_FILE */ if (sparseoffset % pagesize != 0) tst_brk(TBROK, - "sparseoffset must be pagesize multiple"); + "sparseoffset must be pagesize multiple"); break; default: tst_brk(TBROK, "usage: %s %s", progname, usage); @@ -208,15 +197,15 @@ int main(int argc, char *argv[]) if (debug) { #ifdef LARGE_FILE - tst_res(TINFO, "creating file <%s> with %Ld bytes, pattern %d", - TEST_FILE, filesize, pattern); + tst_res(TINFO, "creating file <%s> with %lld 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); + TEST_FILE, filesize, pattern); #endif /* LARGE_FILE */ if (alarmtime) tst_res(TINFO, "running for %f minutes", - alarmtime / 60); + alarmtime / 60); else tst_res(TINFO, "running with no time limit"); } @@ -280,7 +269,7 @@ int main(int argc, char *argv[]) tst_res(TINFO, "write error"); else tst_res(TINFO, "write: wrote %d of %d bytes", - c, write_cnt); + c, write_cnt); (void)close(fd); (void)unlink(TEST_FILE); tst_brk(TFAIL, "write error"); @@ -329,13 +318,13 @@ int main(int argc, char *argv[]) if (!WIFEXITED(wait_stat) || WEXITSTATUS(wait_stat) != 0) tst_brk(TFAIL, "child exit with err ", - wait_stat); + wait_stat); for (i = 0; i < nprocs; i++) if (pid == pidarray[i]) break; if (i == nprocs) tst_brk(TFAIL, "unknown child pid %d, ", - pid, wait_stat); + pid, wait_stat); if ((pid = fork()) == -1) { pidarray[i] = 0; @@ -449,6 +438,7 @@ void child_mapper(char *file, unsigned int procno, unsigned int nprocs) if (do_offset) { int pageoffset = lrand48() % mappages; int byteoffset = pageoffset * pagesize; + offset += byteoffset; mapsize -= byteoffset; mappages -= pageoffset; @@ -457,14 +447,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, filesize, (long)mapsize, + 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, (off64_t)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, (off_t)offset)) == (caddr_t) - 1) #endif /* LARGE_FILE */ tst_brk(TFAIL, "mmap error"); @@ -486,9 +476,9 @@ void child_mapper(char *file, unsigned int procno, unsigned int nprocs) if (*((unsigned char *)(paddr + i)) != ((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); + " at pg %d off %d, exp ", procno, + *((unsigned char *)(paddr + i)), + randpage, i, (procno + pattern) & 0xff); /* * Now write it. @@ -503,7 +493,7 @@ void child_mapper(char *file, unsigned int procno, unsigned int nprocs) randpage = lrand48() % mappages; paddr = maddr + (randpage * pagesize); /* page address */ if (msync(paddr, (mappages - randpage) * pagesize, - MS_SYNC) == -1) + MS_SYNC) == -1) tst_brk(TFAIL, "msync failed"); } if (munmap(maddr, mapsize) == -1) @@ -566,7 +556,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); + (i * pagesize) + cnt, (long)mapsize); close(fd); return 0; } @@ -577,13 +567,13 @@ 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]); + expbuf[j], readbuf[j]); #ifdef LARGE_FILE tst_res(TINFO, ", pg %d off %d, " - "(fsize %Ld)", i, j, statbuf.st_size); + "(fsize %lld)", i, j, statbuf.st_size); #else /* LARGE_FILE */ tst_res(TINFO, ", pg %d off %d, " - "(fsize %ld)", i, j, statbuf.st_size); + "(fsize %ld)", i, j, statbuf.st_size); #endif /* LARGE_FILE */ close(fd); return 0; @@ -598,7 +588,6 @@ int fileokay(char *file, unsigned char *expbuf) void finish(int sig LTP_ATTRIBUTE_UNUSED) { finished++; - return; } unsigned int initrand(void) @@ -617,8 +606,8 @@ unsigned int initrand(void) seed = rand(); srand((unsigned int)time(NULL)); seed = (seed ^ rand()) % 100000; - srand48((long int)seed); - return (seed); + srand48((long)seed); + return seed; } static struct tst_test test = { From patchwork Tue Oct 4 18:20:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 1686066 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=FrghoM1g; 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 4MhmJD5tFfz1ypH for ; Wed, 5 Oct 2022 05:22:04 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 323443CAE01 for ; Tue, 4 Oct 2022 20:22:01 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [217.194.8.5]) (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 BF4123CADED for ; Tue, 4 Oct 2022 20:21:21 +0200 (CEST) Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) (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-5.smtp.seeweb.it (Postfix) with ESMTPS id E449D60102D for ; Tue, 4 Oct 2022 20:21:20 +0200 (CEST) Received: by mail-pg1-x54a.google.com with SMTP id k16-20020a635a50000000b0042986056df6so9195329pgm.2 for ; Tue, 04 Oct 2022 11:21:20 -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=TpAq1FJgLzCpDNuNMLe27DIFR8s55ID621h0FFV8EhY=; b=FrghoM1gGCGzzGicmev+q5FxM0jT/Gz+aspr7s9NzQWXmNUwQHcRQRPXG5tuQL1ePK zAmo14rfb4af7wqXWXko4Ao0majUngz4qLjYBXoMtuBmPY1nh5sGAOfkXxzZ5LQvACIb yQ9WO6071V2BpkRpIcxfMo0Rs5dX63FqEDcEkEF9tqNPj6lM/20cF/SWZp8pgyLSVIUV y1O7caBJBHe138Ne23Ab6xp1/JPz5mT2Vj12QlqSfETYIj00YTb/E14FSIDYdijghle3 Svel7WK+TGm56ose8YESjAZ90n+jJMux9fVw4jmsmu0tp0vtXCiz/uUkBEK3kAtsJwJi G58w== 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=TpAq1FJgLzCpDNuNMLe27DIFR8s55ID621h0FFV8EhY=; b=OOTbrG9l7NGNmHB/zNZQqXvfopOQorSOeP73QdIBl8bEcFnCWjZHG+0jBTt8nPKWMq dek+zZwFDYuskcMwnkOpJjgmRxnOOnFUTQLEZLQIBZD1m2H3Yp0Lw7adHH7D/dQsMLYb 776Qe9Ryqn4U9Hr9luehKoUwsbzLDXrLhPp+48KelXAuuE/Rg1UJk6twPiMjXPC40ecU O6HNYL/E+ap/cgpNI92p56fqIN3O1l0eizQ7WRA+zts1vdD/v/yTVfEzHz71w9sFXIde dVmpmYGdQr/iUAYYh8PKmGbzLZtuwxN7v/Z1SSm0sT70+bS2a8Jm10cD3Wq0GzLdNn2O qPtA== X-Gm-Message-State: ACrzQf05eqcrN9KxGsri59azzV2NFmNoNH5rwnngZSoDTtnCi9Ma/MO+ s6JWoXMtFJ54+r4f9E7KPYVYTDZzQn3xChoPT8DxGRL//NqizeTnAxJvWhAw5z4VxFfFS7Yzi+2 lEw3SfWlI2hnMmw/5rQGpXIr/g/+/X6QP7Ndh1udKjhEEC+9ih6tp/M6c X-Google-Smtp-Source: AMsMyM7sR6O3nK7ZWjisKOAJHeaPS1Vd5rqOTN7WjFcRcV38XdlcaX7Jnkai4//KV+8OMaYNycgYOFKAE8I= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:aa7:88d0:0:b0:542:d98d:bf1f with SMTP id k16-20020aa788d0000000b00542d98dbf1fmr28689357pff.78.1664907679369; Tue, 04 Oct 2022 11:21:19 -0700 (PDT) Date: Tue, 4 Oct 2022 18:20:34 +0000 In-Reply-To: <20221004182040.1859774-1-edliaw@google.com> Mime-Version: 1.0 References: <20221004182040.1859774-1-edliaw@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221004182040.1859774-4-edliaw@google.com> To: ltp@lists.linux.it X-Virus-Scanned: clamav-milter 0.102.4 at in-5.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-5.smtp.seeweb.it Subject: [LTP] [PATCH v3 3/9] 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, 90 insertions(+), 105 deletions(-) diff --git a/testcases/kernel/mem/mmapstress/mmapstress01.c b/testcases/kernel/mem/mmapstress/mmapstress01.c index 20574314b..33213a0f0 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 */ @@ -86,49 +86,103 @@ #endif #define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) -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; -static int leavefile; + +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; -static unsigned int nprocs; +static int nprocs; +static long long filesize = FILESIZE; +static long long sparseoffset; +static unsigned int pattern; static pid_t *pidarray; static int wait_stat; static int check_for_sanity; static unsigned char *buf; -static int debug; +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"); + #ifdef LARGE_FILE -static off64_t filesize = FILESIZE; -static off64_t sparseoffset; -#else /* LARGE_FILE */ -static off_t filesize = FILESIZE; -static off_t sparseoffset; -#endif /* LARGE_FILE */ -static unsigned int randloops; -static unsigned int dosync; -static unsigned int do_offset; -static unsigned int pattern; + 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 @@ -137,81 +191,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 %lld 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. @@ -289,7 +271,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: @@ -330,7 +312,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; @@ -447,14 +429,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"); @@ -486,7 +468,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! */ @@ -569,11 +551,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 %lld)", i, j, statbuf.st_size); + tst_res(TINFO, ", pg %d off %d, (fsize %lld)", + 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; @@ -612,5 +594,8 @@ unsigned int initrand(void) static struct tst_test test = { .needs_tmpdir = 1, + .test_all = run, + .setup = setup, + .options = options, .cleanup = cleanup, }; From patchwork Tue Oct 4 18:20:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 1686067 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=213.254.12.146; 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=BFvT5TPJ; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (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 4MhmJR1Lrpz1ypH for ; Wed, 5 Oct 2022 05:22:15 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B7D803CAC63 for ; Tue, 4 Oct 2022 20:22:12 +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 [IPv6:2001:4b78:1:20::6]) (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 CCC853CAA6E for ; Tue, 4 Oct 2022 20:21:24 +0200 (CEST) Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) (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 24F731400F4F for ; Tue, 4 Oct 2022 20:21:23 +0200 (CEST) Received: by mail-pg1-x549.google.com with SMTP id p24-20020a63f458000000b0043cd718c49dso9315363pgk.15 for ; Tue, 04 Oct 2022 11:21:23 -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=NUXp1GUoKzZ6pS2psJ+v0XBDnpOwJ+u8Hnl0KOX3f38=; b=BFvT5TPJhgr5t/Gjq9c3P3Z2ydaxHEnjsWP3+ASnYZC7aQn+mxD7D0pQIckBYAc47G V5NCE1ecOJpcbCmI0hNy1Zz20SZPQdWWhxHa8GL8kYh1xxGCq+hqmRgfJN2Slxdtv4Dt 9u06unMtd7/YwWgNgAoYuE26JZGRe1ndSg6QV82xJ0s28FXNPj4u0ZJPGhGch4FjVfvA 0WGMI0B8EF9hKjKHqf0FcT3SmEBjCDFk1/64q+S6LG8Vi9LaUTzL8BJEQjT6AaWrdwu8 K0177UkIpaP6/stQRGSTRlpe8b66ejzB5JuDqx8Mfql8sMm3HQ+4UQV8UYi628DxO3NP pIDA== 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=NUXp1GUoKzZ6pS2psJ+v0XBDnpOwJ+u8Hnl0KOX3f38=; b=174ftFLiHks6X0Y7GIwnLLIB08Vg6ud7/eTkhhKFRG3aCgoqY6SUf57oUXJVo/IYMx 9tQKWXsP4Di3Lp+g0paPF9tsBWXqyl9CvK71vNFToSmKliboqYxkGy6ZwttRtPLJEr7c KV8mPGbiQXIdAczOS7M7OfR57bYT58E/Ohr5uozGWCn0vltvtt67DUsFXfXq509rUaed OUQ7+1CVmKB4LqpFZqSAT1A8/VXTavxqLPyk1m6xsFnSKsO0IWnuCG++APYSAmIYOxPD ku4lwnJ9+4/493NyuAxGBkLEcuYpxU/cvoUYT18LZJO3zhxgsBEnIaMpeomttWhs7x6e yAOw== X-Gm-Message-State: ACrzQf2hvxz7ysQqjH0eIofxOi+oPJvJSUIhAkBzko09EJXhA6+s0E9q gSUHJtGrViLJN6a88r97fN/b7hgV6/IJtbzYmNct3fEWdEy8WYY6trF9HitTySddHg0MvTAnxwI O8qUehxQazJNE3dbRJYuPOIPjU8RfQstwSN3tLWWPfAzMk5NGHlgGwx8J X-Google-Smtp-Source: AMsMyM6IkB6TAL6lw6V5vZBHaOYDZooc9wpAkJwvoL1cuqeoCjZPn2h4pYjCOJim1aIcOMjlX6GnHeBLdzc= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a17:90a:cd06:b0:203:ae0e:6a21 with SMTP id d6-20020a17090acd0600b00203ae0e6a21mr370445pju.0.1664907680966; Tue, 04 Oct 2022 11:21:20 -0700 (PDT) Date: Tue, 4 Oct 2022 18:20:35 +0000 In-Reply-To: <20221004182040.1859774-1-edliaw@google.com> Mime-Version: 1.0 References: <20221004182040.1859774-1-edliaw@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221004182040.1859774-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 v3 4/9] 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 | 70 +++---------------- 2 files changed, 10 insertions(+), 62 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 33213a0f0..3f7f617c6 100644 --- a/testcases/kernel/mem/mmapstress/mmapstress01.c +++ b/testcases/kernel/mem/mmapstress/mmapstress01.c @@ -139,14 +139,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)) @@ -185,11 +185,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; @@ -216,13 +212,8 @@ 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 */ + if ((fd = open(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, 0664)) == -1) tst_brk(TFAIL, "open error"); - } if ((buf = malloc(pagesize)) == NULL || (pidarray = malloc(nprocs * sizeof(pid_t))) == NULL) { @@ -237,13 +228,8 @@ 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 */ + if (lseek(fd, (off_t)sparseoffset, SEEK_SET) < 0) 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) { @@ -374,15 +360,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; @@ -397,19 +377,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) @@ -431,13 +403,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); @@ -488,11 +455,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); @@ -501,25 +464,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) @@ -548,15 +499,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 %lld)", - 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 Tue Oct 4 18:20:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 1686068 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=kNW2GbCi; 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 4MhmJf3SnCz1ypH for ; Wed, 5 Oct 2022 05:22:26 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 098D33CAE07 for ; Tue, 4 Oct 2022 20:22:23 +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)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 1E8313CACDD for ; Tue, 4 Oct 2022 20:21:25 +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 68C97600634 for ; Tue, 4 Oct 2022 20:21:24 +0200 (CEST) Received: by mail-pl1-x64a.google.com with SMTP id n1-20020a170902f60100b00179c0a5c51fso10627674plg.7 for ; Tue, 04 Oct 2022 11:21:24 -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=jgmDPCtFYVOuyTlEfR95+wakysEHxyQ9usC/FXUG/jo=; b=kNW2GbCibxN/BeaxqzIOzvjA3AWmaa6FCEXtZm1efnaMtzNzQxEzv9jL0b3/348gpR TNekwsS8FG9PYiDWe/63/NhKMCEMi1ybtVxEolmjc4vxhd3vVYQTZk3rQxiInPiHGD9L 8lUiJ1v82DaUp9Kxii/SUhG0XbcddJvoKI9XTO+lL+NFS3fdj1lXjPP8Xs+Ba1I6k1KZ 06E/zZcsmg0ab9q9ilJkTW7ijzcRUEKJMA3MQ2N2fUM5nTdsgwctAReY7vg7wiw2JuX7 H2/al1PVu3oN1/1weZTIQmHeLpZ2wRn9BaGvboe9XP6y+dEwHXeRRUocCwUihSGazpQ5 eLZw== 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=jgmDPCtFYVOuyTlEfR95+wakysEHxyQ9usC/FXUG/jo=; b=Z6fQ5wU/Ax4fFafxnCTd8dphgm3a+WhxQ3ut38EsRvbwRvMdZ6QAwvnlZsnTVmGvWT aX5mR3RBZ/FfSq9jJC2hdcJuaK/NztvarE6Mff45/JRiLEHHjdE+8BJ/x7V8uy58RqIx tzgdRROO74usJMgstF4w294OR9wSplbdOaUVxa0UN3I/uVXoVtjlEMdcqofOEAWHJ78F ZdH5eW2w/SEI8AE/Idxl8ZLMlon0ITLug/rsJR35YYEY7ZiqlmueMrGk6Qyt9MDABUgV wvj9IOItrKDfP1UWxvSdsrqhHbM/gDeO3fAzMw7Ee1WGXkHkfxGdLpbRLN3UeoEvs5Ls zCkA== X-Gm-Message-State: ACrzQf2ulMZ+F8oWCEsCFXLPERAGVkrL4po4UkoCFL9Jj7O4IhiyUFdu x9NTyXnHlXJZYi0ke3wnmkGBBuf5GF36Y62SrIE8BQlVsqVPXD/EcVtAcemiCnARVqqNikng10k kv3ut3D8ZqxEUzv06AK5AnjQ/5ar355CJxYo9w4zz3i7PjbL9aq1eIm4g X-Google-Smtp-Source: AMsMyM7WE4CKtrN4PPyDUWhR+ExfCrzuO0SxxZeGF6cDcVF5DLrWx21b5+W3chIugOwOfQbJ6Xx+Jo0NxDQ= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a05:6a00:1626:b0:561:5c63:7291 with SMTP id e6-20020a056a00162600b005615c637291mr12083318pfc.29.1664907682887; Tue, 04 Oct 2022 11:21:22 -0700 (PDT) Date: Tue, 4 Oct 2022 18:20:36 +0000 In-Reply-To: <20221004182040.1859774-1-edliaw@google.com> Mime-Version: 1.0 References: <20221004182040.1859774-1-edliaw@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221004182040.1859774-6-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 v3 5/9] 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 | 91 +++++++------------ 1 file changed, 33 insertions(+), 58 deletions(-) diff --git a/testcases/kernel/mem/mmapstress/mmapstress01.c b/testcases/kernel/mem/mmapstress/mmapstress01.c index 3f7f617c6..165db2b81 100644 --- a/testcases/kernel/mem/mmapstress/mmapstress01.c +++ b/testcases/kernel/mem/mmapstress/mmapstress01.c @@ -186,6 +186,7 @@ static void run(void) int write_cnt; unsigned char data; off_t bytes_left; + sigset_t set_mask; seed = initrand(); pattern = seed & 0xff; @@ -197,28 +198,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; @@ -228,23 +220,12 @@ 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) { - 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(TEST_FILE); - tst_brk(TFAIL, "write error"); - } + c = SAFE_WRITE(1, fd, buf, write_cnt); } - - (void)close(fd); + SAFE_CLOSE(fd); /* * Fork off mmap children. @@ -269,14 +250,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) { /* @@ -312,8 +295,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); } /* @@ -321,8 +303,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"); @@ -343,7 +326,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 { @@ -377,12 +360,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"); @@ -403,11 +384,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. @@ -445,8 +425,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); } @@ -464,14 +443,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"); @@ -490,7 +465,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; } } @@ -503,12 +478,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; } From patchwork Tue Oct 4 18:20:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 1686069 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=i6Zo20LO; 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 4MhmJv1hmqz1ypH for ; Wed, 5 Oct 2022 05:22:39 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 732503CA47E for ; Tue, 4 Oct 2022 20:22:36 +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 [IPv6:2001:4b78:1:20::7]) (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 DAFFA3CAE05 for ; Tue, 4 Oct 2022 20:21:26 +0200 (CEST) Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) (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 06CEA200DC2 for ; Tue, 4 Oct 2022 20:21:26 +0200 (CEST) Received: by mail-pl1-x649.google.com with SMTP id c12-20020a170903234c00b0017f695bf8f0so3225032plh.6 for ; Tue, 04 Oct 2022 11:21:25 -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=ua6Op1leeBLDsamZR7vS7csPM92hqpSo1BZRkldJMqA=; b=i6Zo20LO6j7aDIDLWddNPdEEuUnczPjXWpzTwrvy2IoT2fUcAhB5mhIbkTrWM9l0YT BTe5IUn15mj3JLOMxxxgpehqkpwsM6wTb7gZx1wLKkQTppf2YlN0NGdUM+Y/Z6yvRPMq +ui8HrnF/U1ALKhVg5HeKq+jgNUaxZb4Ev7e/1rrmJ0VSEix3xG3p+f5revgGwgIDEkx OfdC3sQLeiZrEmP0cOdP0PB49hWG+Y2BdgkFm57gb29BEIphb79qp7SOKZrxKJmWbiwX sCCNIZ6OJZGzfzw1YWXLP+SdLYUEZ95bonO+xAIeWO50zLa69Z/YRW5mWdIMHNeDB/U6 33AQ== 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=ua6Op1leeBLDsamZR7vS7csPM92hqpSo1BZRkldJMqA=; b=oE4Wn7Ah9TB0Qx1RoxOEqGa8bV9CzpjEZX4GP3UyrO2oV3dBk74Odh5xypPho2IQUa ms/m85B/bYAxxkjChnB+T01Ys3SnasTJSdpmFn7QAXkgkFU1mvpxY3p1UwQQGPBulTIm aWdRoMlucKADv2ntH9xsPYuM47uw5cnpMMbzJkemf3AZZjb+1Ql2UyEqPyq6wu171Xsh Silq6iQzHFwSoY0xoCMMqwBgfOpwsbRFjm99o2tRqfGH+aKxehqNE+AU3hlXaJclBn5Y wwcO9TldGpDzHsdbKCugCMapOJpW67wTIQS+Z6z5ioMEakf25zfAmxEtptxmp+vQYwpf BWEA== X-Gm-Message-State: ACrzQf0bOLTqU0trXG0+gpt3so8mJmXWfX+D7zSOekA91vyJoZwmKOFX NQ5MzKz1ONoJCswX3iV18Ud1b6ILgWzWXu7pP1Aa4KT33EbgQs4LKTVOSOlXwCo7b2uXztaVGPS qxGkUw8JfK6v3hxMQgoPioTvSICzBQ3ypjzQbXVlu1rynLXc5D2WelKkK X-Google-Smtp-Source: AMsMyM72noztDXSefe91AnL7jOOaz8XYRCdaZp9VQgqmKmRmyyqyhQt6+shGEt/MJK2Bpjw4hdyt5CNY/qc= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a05:6a00:1747:b0:55c:b475:5f74 with SMTP id j7-20020a056a00174700b0055cb4755f74mr22179046pfc.68.1664907684511; Tue, 04 Oct 2022 11:21:24 -0700 (PDT) Date: Tue, 4 Oct 2022 18:20:37 +0000 In-Reply-To: <20221004182040.1859774-1-edliaw@google.com> Mime-Version: 1.0 References: <20221004182040.1859774-1-edliaw@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221004182040.1859774-7-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 v3 6/9] mmapstress01: refactor cleanup and drop leavefile option 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 | 84 ++++++------------- 1 file changed, 25 insertions(+), 59 deletions(-) diff --git a/testcases/kernel/mem/mmapstress/mmapstress01.c b/testcases/kernel/mem/mmapstress/mmapstress01.c index 165db2b81..7e8226700 100644 --- a/testcases/kernel/mem/mmapstress/mmapstress01.c +++ b/testcases/kernel/mem/mmapstress/mmapstress01.c @@ -89,11 +89,9 @@ 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; +static void fileokay(char *file, unsigned char *expbuf); static char *debug; -static char *leavefile; static char *do_sync; static char *do_offset; static char *randloops; @@ -102,21 +100,17 @@ static char *opt_nprocs; static char *opt_sparseoffset; static char *opt_alarmtime; +static int fd; static float alarmtime; static int nprocs; static long long filesize = FILESIZE; static long long sparseoffset; static unsigned int pattern; - -static pid_t *pidarray; -static int wait_stat; -static int check_for_sanity; -static unsigned char *buf; +static int finished; 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)"}, @@ -175,7 +169,6 @@ static void setup(void) static void run(void) { - int fd; int c; int procno; pid_t pid; @@ -187,6 +180,9 @@ static void run(void) unsigned char data; off_t bytes_left; sigset_t set_mask; + pid_t *pidarray = NULL; + int wait_stat; + unsigned char *buf; seed = initrand(); pattern = seed & 0xff; @@ -298,40 +294,22 @@ static void run(void) SAFE_SIGPROCMASK(SIG_UNBLOCK, &set_mask, NULL); } - /* - * Finished! Check the file for sanity, then kill all - * the children and done!. - */ - 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"); + + /* + * Finished! Check the file for sanity. + */ + fileokay(TEST_FILE, buf); + tst_res(TPASS, "file has expected data"); } 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 (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 { - tst_res(TINFO, "file data okay"); - if (!leavefile) - SAFE_UNLINK(TEST_FILE); - tst_res(TPASS, "test passed"); - } - } else { - tst_res(TINFO, " leaving file <%s>", TEST_FILE); - } + if (fd > 0) + SAFE_CLOSE(fd); } /* @@ -341,7 +319,7 @@ static void cleanup(void) * determined based on nprocs & procno). After a specific number of * iterations, it exits. */ -void child_mapper(char *file, unsigned int procno, unsigned int nprocs) +static void child_mapper(char *file, unsigned int procno, unsigned int nprocs) { struct stat statbuf; off_t filesize; @@ -349,7 +327,6 @@ void child_mapper(char *file, unsigned int procno, unsigned int nprocs) size_t validsize; size_t mapsize; char *maddr = NULL, *paddr; - int fd; size_t pagesize = sysconf(_SC_PAGE_SIZE); unsigned int randpage; unsigned int seed; @@ -432,14 +409,13 @@ void child_mapper(char *file, unsigned int procno, unsigned int nprocs) /* * Make sure file has all the correct data. */ -int fileokay(char *file, unsigned char *expbuf) +static void fileokay(char *file, unsigned char *expbuf) { struct stat statbuf; size_t mapsize; unsigned int mappages; unsigned int pagesize = sysconf(_SC_PAGE_SIZE); unsigned char readbuf[pagesize]; - int fd; int cnt; unsigned int i, j; @@ -455,45 +431,35 @@ int fileokay(char *file, unsigned char *expbuf) mappages = roundup(mapsize, pagesize) / pagesize; for (i = 0; i < mappages; i++) { - cnt = read(fd, readbuf, pagesize); - if (cnt == -1) { - tst_brk(TFAIL, "read error"); - } else if ((unsigned int)cnt != pagesize) { + cnt = SAFE_READ(0, fd, readbuf, pagesize); + if ((unsigned int)cnt != pagesize) { /* * Okay if at last page in file... */ - if ((i * pagesize) + cnt != mapsize) { - tst_res(TINFO, "read %d of %ld bytes", + if ((i * pagesize) + cnt != mapsize) + tst_brk(TFAIL, "missing data: read %d of %ld bytes", (i * pagesize) + cnt, (long)mapsize); - SAFE_CLOSE(fd); - return 0; - } } /* * Compare read bytes of data. */ for (j = 0; j < (unsigned int)cnt; j++) { - if (expbuf[j] != readbuf[j]) { - tst_res(TINFO, + if (expbuf[j] != readbuf[j]) + tst_brk(TFAIL, "read bad data: exp %c got %c, pg %d off %d, (fsize %lld)", expbuf[j], readbuf[j], i, j, (long long)statbuf.st_size); - SAFE_CLOSE(fd); - return 0; - } } } SAFE_CLOSE(fd); - - return 1; } -void finish(int sig LTP_ATTRIBUTE_UNUSED) +static void finish(int sig LTP_ATTRIBUTE_UNUSED) { finished++; } -unsigned int initrand(void) +static unsigned int initrand(void) { unsigned int seed; @@ -514,9 +480,9 @@ unsigned int initrand(void) } static struct tst_test test = { - .needs_tmpdir = 1, .test_all = run, .setup = setup, .options = options, .cleanup = cleanup, + .needs_tmpdir = 1, }; From patchwork Tue Oct 4 18:20:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 1686070 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=213.254.12.146; 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=Pxe1OUG1; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (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 4MhmK557htz1ypH for ; Wed, 5 Oct 2022 05:22:49 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id BF9673CADED for ; Tue, 4 Oct 2022 20:22:47 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [IPv6:2001:4b78:1:20::5]) (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 618B13CADFD for ; Tue, 4 Oct 2022 20:21:28 +0200 (CEST) Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) (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-5.smtp.seeweb.it (Postfix) with ESMTPS id DB0C46009F3 for ; Tue, 4 Oct 2022 20:21:27 +0200 (CEST) Received: by mail-pg1-x54a.google.com with SMTP id j63-20020a638042000000b00454d34199fcso1779413pgd.0 for ; Tue, 04 Oct 2022 11:21:27 -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=rEC7fZaVwbKLTCVK2ZmrGhGtlDjKS8MDTV9IgJAn7LY=; b=Pxe1OUG1dQdQNWeEhgCZD0tuHtuMcM5uV1AitYssy4vHFNqePoMJWL9U+qvjMIEVGx Xr+5nhBp9AjQyb53gEhnH47J7Ws/h2oS7U/y2LfMfYwamlaVPItcQKgZ/YlJ0lB1HTmi 41ITKzeYqun99hpBR4vnRg84w0bkLLsgIgdE8Z6i3TFHTqJ00zHtLiBiz3rcZ0hdpPS+ rd8mioaSKbHuyeXFEhpyzyGZnmTlDFNgV1Bz7JMZQbAlSplXfgZqK5R81WcCKOWjpC78 PFOvGRzoNJG1hUVpNREbQN/vTTAQxCZikNubguxdK//MTjLap5ltP4W3i0WGQmP1VFm0 ur+w== 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=rEC7fZaVwbKLTCVK2ZmrGhGtlDjKS8MDTV9IgJAn7LY=; b=MwO3qZgupz6S7RVBTI7f9lwOF2emmgRjB4eHwLmejMCmotkDHbcPcSJ0gHFMv7jBNG T2PrUVA01u/eZVF0fHdFZmcctnEVaBaMtj1130E5mDH+wDWQB/AzEZXJsrPe9uO1zazW yuyKJBcUGamqVtrrt1Ozh1K9DLqmMXQQSY8u3IeTIi3/jIH0gYI+kJkwgEDZ4A7bj/e4 We7po8Sl2alIEa1KbTkheFCb9ngDYJpqN5kvsUie0o0NyaqNlO557Ad8FOJKTW+Xdplm om52Mqj6Q4hlay/mYWvXlNB8xEPumlNj+DeGObxBGZNJ5MBdOLFKYMegFqGgXph/u2Qk lAcg== X-Gm-Message-State: ACrzQf3fPkiCd1dz8gk72Lvt+8YrcqnM4DidiFYtBrgFhyMIsFf+2P3s Es6TT+6MeDln6Pp4bXdGpDCWDiL12XXLXgqc6vB3dwBv/aflqk6alApCrneFuo3ANM5uLW1Qcj2 XJvZlQsMRjrZD4vqM/F09neuVAdWuNC7O40oUZDu+M+7UuQwyCttbtc1Z X-Google-Smtp-Source: AMsMyM6kdLIxDGzBOI/yOG239svMz8zE8AmfpupBMxS4wYe5orYHqawBDHFiKHF3xVsdUu5hCBd/s/bk3wE= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a17:903:181:b0:178:703f:689f with SMTP id z1-20020a170903018100b00178703f689fmr27701666plg.129.1664907686348; Tue, 04 Oct 2022 11:21:26 -0700 (PDT) Date: Tue, 4 Oct 2022 18:20:38 +0000 In-Reply-To: <20221004182040.1859774-1-edliaw@google.com> Mime-Version: 1.0 References: <20221004182040.1859774-1-edliaw@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221004182040.1859774-8-edliaw@google.com> To: ltp@lists.linux.it X-Virus-Scanned: clamav-milter 0.102.4 at in-5.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-5.smtp.seeweb.it Subject: [LTP] [PATCH v3 7/9] mmapstress01: use SAFE_FORK 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 --- testcases/kernel/mem/mmapstress/mmapstress01.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/testcases/kernel/mem/mmapstress/mmapstress01.c b/testcases/kernel/mem/mmapstress/mmapstress01.c index 7e8226700..99ab0d64e 100644 --- a/testcases/kernel/mem/mmapstress/mmapstress01.c +++ b/testcases/kernel/mem/mmapstress/mmapstress01.c @@ -227,12 +227,7 @@ static void run(void) * Fork off mmap children. */ for (procno = 0; procno < nprocs; procno++) { - switch (pid = fork()) { - - case -1: - tst_brk(TFAIL, "fork error"); - break; - + switch (pid = SAFE_FORK()) { case 0: child_mapper(TEST_FILE, (unsigned int)procno, (unsigned int)nprocs); exit(0); @@ -273,10 +268,8 @@ static void run(void) tst_brk(TFAIL, "unknown child pid %d, ", pid, wait_stat); - if ((pid = fork()) == -1) { - pidarray[i] = 0; - tst_brk(TFAIL, "fork error"); - } else if (pid == 0) { /* child */ + pid = SAFE_FORK(); + if (pid == 0) { /* child */ child_mapper(TEST_FILE, (unsigned int)i, (unsigned int)nprocs); exit(0); } else { @@ -485,4 +478,5 @@ static struct tst_test test = { .options = options, .cleanup = cleanup, .needs_tmpdir = 1, + .forks_child = 1, }; From patchwork Tue Oct 4 18:20:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 1686071 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=ZXfHOjut; 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 4MhmKK0bQBz1ypH for ; Wed, 5 Oct 2022 05:23:01 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 6E86F3CAD32 for ; Tue, 4 Oct 2022 20:22:58 +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 [IPv6:2001:4b78:1:20::3]) (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 0200B3CAE01 for ; Tue, 4 Oct 2022 20:21:30 +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 8915D1A01100 for ; Tue, 4 Oct 2022 20:21:29 +0200 (CEST) Received: by mail-pf1-x44a.google.com with SMTP id h1-20020a62b401000000b0056161cd284fso4340092pfn.16 for ; Tue, 04 Oct 2022 11:21:29 -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=sQ3K3r5hjqhLaUUz3ZNbDvyjCO2m/Rb68WINFoRE5mw=; b=ZXfHOjutvMkQ1xFkEPQMP6AsIVtgBTNIug/UXQWUfm3m7cJWgqoQQrLhZUuwfzfaiz i2iNzAgkPA/TF9xMKJbdjoFJNKdOL4NYUm4uEb2yOi9vwPw3ob44EJsOts6EUCrKFX3Y mAHKnftVlJtYsq8itVzRT7BQZdOrDxtNizJg8XrEMfAl/M6zfXUA5v1G8QQ0w4r6KTrg MYD+VUrqE+JSDlvcVKgnpXzdOvtP2smh+X6SJ96Ui4UtCncZJ9sMR3cfJjuMQpvjzzcp 3OR4AyQ08tizQFvw78XXs1KYlNmXEBAUHRlMVMEosP1Jv7GcpfyvY+R02KA2M3fZLzOG CK2g== 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=sQ3K3r5hjqhLaUUz3ZNbDvyjCO2m/Rb68WINFoRE5mw=; b=mlXFlFXr+TqiCFwa79w6nAta8676U9v7I1wFUKbpmLjK1C1vJM/EUCTFxuSdOTG6Ks X6VjCc4CL5olgxc4AhoRDLe5FGFKPpRM18rFchNReW0Hf/cjO51bfYegbQFy6IOWkhMq jQS39ZOk3JSbcil2ZVV3Z2GawWSRC83Qin7MtXvp/B+EhIZTDoxIKtHn9w61fxIjOi2/ V/ttutw/4bOiCtpPfOd46whmLaDGOU0jHcqlEveYAV9+pDoLyOyH7Zeku0w5FPi/OnHT hMB7dzdRpFcttgZ4+MUVO2GYpDGnPl1FhEqOkybv/9cl8Twz43B7zyISWN1ZMxKLI9mB wA+Q== X-Gm-Message-State: ACrzQf1wi3snabUT2T4jIvux9ZMpDDlXM9j6ZZ6bu5cW8HM/e4f9ZpKR Mr7nSxbDP1tFR+tyBdna9MG4zhj2zyFcg3HGOKEzUowlyMUD6FLh5tW9vMI033XbatB0CCcWEwY JpunaZHRFxUub4AUpW20FHjLkdSoNFps9F5kcKjiBv8bkeDDWlRKjG0V0 X-Google-Smtp-Source: AMsMyM4/5HBzgPBw8azTkKcSoquIvr3upoid+j6G9plcVnLzX5E5kyQNHXuPzr/aQl+o2aLzUl3ZFU6hMis= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a17:902:768c:b0:17a:ec9:51da with SMTP id m12-20020a170902768c00b0017a0ec951damr28568136pll.159.1664907687892; Tue, 04 Oct 2022 11:21:27 -0700 (PDT) Date: Tue, 4 Oct 2022 18:20:39 +0000 In-Reply-To: <20221004182040.1859774-1-edliaw@google.com> Mime-Version: 1.0 References: <20221004182040.1859774-1-edliaw@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221004182040.1859774-9-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 v3 8/9] mmapstress01: update license 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 | 25 ++++--------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/testcases/kernel/mem/mmapstress/mmapstress01.c b/testcases/kernel/mem/mmapstress/mmapstress01.c index 99ab0d64e..9eced3526 100644 --- a/testcases/kernel/mem/mmapstress/mmapstress01.c +++ b/testcases/kernel/mem/mmapstress/mmapstress01.c @@ -1,25 +1,10 @@ -/* IBM Corporation */ -/* 01/02/2003 Port to LTP avenkat@us.ibm.com */ -/* 06/30/2001 Port to Linux nsharoff@us.ibm.com */ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * 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, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (c) International Business Machines Corp., 2003 + * 01/02/2003 Port to LTP avenkat@us.ibm.com + * 06/30/2001 Port to Linux nsharoff@us.ibm.com + * 10/03/2022 Refactor to LTP framework edliaw@google.com */ - /* * This test stresses mmaps, without dealing with fragments or anything! * It forks a specified number of children, From patchwork Tue Oct 4 18:20:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Liaw X-Patchwork-Id: 1686072 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=gyiAxkA+; 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 4MhmKW6W47z1ypH for ; Wed, 5 Oct 2022 05:23:11 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 4907B3CAD32 for ; Tue, 4 Oct 2022 20:23:09 +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 [IPv6:2001:4b78:1:20::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 picard.linux.it (Postfix) with ESMTPS id 360903CABEA for ; Tue, 4 Oct 2022 20:21:31 +0200 (CEST) Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) (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 BF04A600634 for ; Tue, 4 Oct 2022 20:21:30 +0200 (CEST) Received: by mail-pg1-x549.google.com with SMTP id y62-20020a638a41000000b0044a5d5be5b8so5313547pgd.13 for ; Tue, 04 Oct 2022 11:21:30 -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=/nbqv4N9ztmyb2Ewjmw6DU/CJhin4caMIprlYkwVWzg=; b=gyiAxkA+9uE6l+sEugf4YBq1afe+SYh2mVT9x2r8A/dMRg4jYuxCSPrBqgLa+iPhY5 teiN6fKH/POgdBtNJPiJ8KP4ac9qsoxKicfWzqvYvDIwS5RbnNSRFUi8yMdJm1JuUeLa mnkfFx1kVRkYNeuEYlkYcG+LhKnUseibqUI05yUZD4Ykj9I9EOxTSI41eoE6iBqyVGyq JqLrps0EO0706P62Ofh8jbvIPPBPrRTY7LgPucrILBUfs48uRnoPI5M+ocNPB/Nch/jE NxdiHjgc0WXQAwPJMnleXveY70WYFSmzwBGSVDsajKIgdqEB/rCFCWfaqzP2B5tdGVHr YmTQ== 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=/nbqv4N9ztmyb2Ewjmw6DU/CJhin4caMIprlYkwVWzg=; b=N+E81WQ8UWHm7N9DFcnnvZMhZG9JzYGp7d5sk6hXTW8KgxXIolmRk30nnzAwwgTXIO e9tepNYjllBHIHq9MJ56oFetcOCjO/+7v+AtXYZcMHGFMJi87zOpnbvvuepzHOW6c0dE plmlh4WyYFFw3mBA6hNjWy2fjxVrLpQv1FJNFGmIpLH1/fvNlerOnagCYydLZ6d2REj1 JX0l9Eoi0Ncwn/vSXpn13QcXixdllKSoJeHfGaJqbtC5Vif5nWVNxz+fuZXpZ/hXXZrx gQ0Z2AxcylDe9oVvjSnjbP/ZPJKy3tBIwJg2NFfLeVJStch/0CHNd/DOC1CwupsOrGzb Mxow== X-Gm-Message-State: ACrzQf1rNZzm65x7wbK5cLngMOdpR+m4ieQjth3l4MBSMci3FHMrSwya uboNV5cKuaFU+xK7LIsv/dtrVauwNZ8O28cXM6V9lmz7TwiGwF1uP1PbZbHxfkgWQGc06+Rlbgr TeJjcDX+lTlo+A6oohPv86IZQxUkevV/E9IHzD+hgxDvnNbmgalecD1iV X-Google-Smtp-Source: AMsMyM7j0AMF4zMldwWsc9bvPI00Fgq+kiJ/4WDH941QjJ4tAdxi/EsPvOeRYS8hITG+TlZpjFVS8704b8c= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a05:6a00:3392:b0:547:f861:1fad with SMTP id cm18-20020a056a00339200b00547f8611fadmr28999262pfb.16.1664907689245; Tue, 04 Oct 2022 11:21:29 -0700 (PDT) Date: Tue, 4 Oct 2022 18:20:40 +0000 In-Reply-To: <20221004182040.1859774-1-edliaw@google.com> Mime-Version: 1.0 References: <20221004182040.1859774-1-edliaw@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221004182040.1859774-10-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 v3 9/9] mmapstress01: reorder vars and functions 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 | 286 +++++++++--------- 1 file changed, 143 insertions(+), 143 deletions(-) diff --git a/testcases/kernel/mem/mmapstress/mmapstress01.c b/testcases/kernel/mem/mmapstress/mmapstress01.c index 9eced3526..f68193706 100644 --- a/testcases/kernel/mem/mmapstress/mmapstress01.c +++ b/testcases/kernel/mem/mmapstress/mmapstress01.c @@ -72,26 +72,27 @@ #define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) static unsigned int initrand(void); -static void finish(int sig); static void child_mapper(char *file, unsigned int procno, unsigned int nprocs); static void fileokay(char *file, unsigned char *expbuf); +static void sighandler(int sig); static char *debug; static char *do_sync; static char *do_offset; -static char *randloops; +static char *opt_alarmtime; static char *opt_filesize; static char *opt_nprocs; static char *opt_sparseoffset; -static char *opt_alarmtime; +static char *randloops; static int fd; -static float alarmtime; +static int finished; static int nprocs; +static float alarmtime; static long long filesize = FILESIZE; static long long sparseoffset; +static size_t pagesize; static unsigned int pattern; -static int finished; static struct tst_option options[] = { {"d", &debug, "Enable debug output"}, @@ -152,138 +153,6 @@ static void setup(void) alarmtime *= 60; } -static void run(void) -{ - int c; - int procno; - pid_t pid; - unsigned int seed; - int pagesize = sysconf(_SC_PAGE_SIZE); - struct sigaction sa; - int i; - int write_cnt; - unsigned char data; - off_t bytes_left; - sigset_t set_mask; - pid_t *pidarray = NULL; - int wait_stat; - unsigned char *buf; - - seed = initrand(); - pattern = seed & 0xff; - - /* - * Plan for death by signal. User may have specified - * a time limit, in which set an alarm and catch SIGALRM. - * Also catch and cleanup with SIGINT. - */ - sa.sa_handler = finish; - sa.sa_flags = 0; - SAFE_SIGEMPTYSET(&sa.sa_mask); - SAFE_SIGACTION(SIGINT, &sa, 0); - SAFE_SIGACTION(SIGQUIT, &sa, 0); - SAFE_SIGACTION(SIGTERM, &sa, 0); - - if (alarmtime) { - SAFE_SIGACTION(SIGALRM, &sa, 0); - (void)alarm(alarmtime); - } - fd = SAFE_OPEN(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, 0664); - - buf = SAFE_MALLOC(pagesize); - pidarray = SAFE_MALLOC(nprocs * sizeof(pid_t)); - - for (i = 0; i < nprocs; i++) - *(pidarray + i) = 0; - - for (i = 0, data = 0; i < pagesize; i++) { - *(buf + i) = (data + pattern) & 0xff; - if (++data == nprocs) - data = 0; - } - SAFE_LSEEK(fd, (off_t)sparseoffset, SEEK_SET); - for (bytes_left = filesize; bytes_left; bytes_left -= c) { - write_cnt = MIN(pagesize, (int)bytes_left); - c = SAFE_WRITE(1, fd, buf, write_cnt); - } - SAFE_CLOSE(fd); - - /* - * Fork off mmap children. - */ - for (procno = 0; procno < nprocs; procno++) { - switch (pid = SAFE_FORK()) { - case 0: - child_mapper(TEST_FILE, (unsigned int)procno, (unsigned int)nprocs); - exit(0); - - default: - pidarray[procno] = pid; - } - } - - /* - * 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. - */ - - SAFE_SIGPROCMASK(SIG_BLOCK, &set_mask, NULL); - - if (pid != -1) { - /* - * Check exit status, then refork with the - * appropriate procno. - */ - if (!WIFEXITED(wait_stat) - || 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) - tst_brk(TFAIL, "unknown child pid %d, ", - pid, wait_stat); - - pid = SAFE_FORK(); - if (pid == 0) { /* child */ - child_mapper(TEST_FILE, (unsigned int)i, (unsigned int)nprocs); - exit(0); - } else { - pidarray[i] = pid; - } - } else { - /* - * wait returned an error. If EINTR, then - * normal finish, else it's an unexpected - * error... - */ - if (errno != EINTR || !finished) - tst_brk(TFAIL, "unexpected wait error"); - } - SAFE_SIGPROCMASK(SIG_UNBLOCK, &set_mask, NULL); - } - - SAFE_SIGEMPTYSET(&set_mask); - SAFE_SIGADDSET(&set_mask, SIGALRM); - SAFE_SIGPROCMASK(SIG_BLOCK, &set_mask, NULL); - (void)alarm(0); - - /* - * Finished! Check the file for sanity. - */ - fileokay(TEST_FILE, buf); - tst_res(TPASS, "file has expected data"); -} - static void cleanup(void) { if (fd > 0) @@ -305,7 +174,6 @@ static void child_mapper(char *file, unsigned int procno, unsigned int nprocs) size_t validsize; size_t mapsize; char *maddr = NULL, *paddr; - size_t pagesize = sysconf(_SC_PAGE_SIZE); unsigned int randpage; unsigned int seed; unsigned int loopcnt; @@ -389,13 +257,13 @@ static void child_mapper(char *file, unsigned int procno, unsigned int nprocs) */ static void fileokay(char *file, unsigned char *expbuf) { - struct stat statbuf; + int cnt; size_t mapsize; - unsigned int mappages; - unsigned int pagesize = sysconf(_SC_PAGE_SIZE); + struct stat statbuf; unsigned char readbuf[pagesize]; - int cnt; unsigned int i, j; + unsigned int mappages; + unsigned int pagesize = sysconf(_SC_PAGE_SIZE); fd = SAFE_OPEN(file, O_RDONLY); @@ -432,7 +300,7 @@ static void fileokay(char *file, unsigned char *expbuf) SAFE_CLOSE(fd); } -static void finish(int sig LTP_ATTRIBUTE_UNUSED) +static void sighandler(int sig LTP_ATTRIBUTE_UNUSED) { finished++; } @@ -457,6 +325,138 @@ static unsigned int initrand(void) return seed; } +static void run(void) +{ + int c; + int i; + int procno; + int wait_stat; + off_t bytes_left; + pid_t pid; + pid_t *pidarray = NULL; + sigset_t set_mask; + size_t write_cnt; + struct sigaction sa; + unsigned char data; + unsigned char *buf; + unsigned int seed; + + pagesize = sysconf(_SC_PAGE_SIZE); + seed = initrand(); + pattern = seed & 0xff; + + /* + * Plan for death by signal. User may have specified + * a time limit, in which set an alarm and catch SIGALRM. + * Also catch and cleanup with SIGINT. + */ + sa.sa_handler = sighandler; + sa.sa_flags = 0; + SAFE_SIGEMPTYSET(&sa.sa_mask); + SAFE_SIGACTION(SIGINT, &sa, 0); + SAFE_SIGACTION(SIGQUIT, &sa, 0); + SAFE_SIGACTION(SIGTERM, &sa, 0); + + if (alarmtime) { + SAFE_SIGACTION(SIGALRM, &sa, 0); + (void)alarm(alarmtime); + } + fd = SAFE_OPEN(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, 0664); + + buf = SAFE_MALLOC(pagesize); + pidarray = SAFE_MALLOC(nprocs * sizeof(pid_t)); + + for (i = 0; i < nprocs; i++) + *(pidarray + i) = 0; + + for (i = 0, data = 0; i < (int)pagesize; i++) { + *(buf + i) = (data + pattern) & 0xff; + if (++data == nprocs) + data = 0; + } + SAFE_LSEEK(fd, (off_t)sparseoffset, SEEK_SET); + for (bytes_left = filesize; bytes_left; bytes_left -= c) { + write_cnt = MIN((long long)pagesize, (long long)bytes_left); + c = SAFE_WRITE(1, fd, buf, write_cnt); + } + SAFE_CLOSE(fd); + + /* + * Fork off mmap children. + */ + for (procno = 0; procno < nprocs; procno++) { + switch (pid = SAFE_FORK()) { + case 0: + child_mapper(TEST_FILE, (unsigned int)procno, (unsigned int)nprocs); + exit(0); + + default: + pidarray[procno] = pid; + } + } + + /* + * 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. + */ + + SAFE_SIGPROCMASK(SIG_BLOCK, &set_mask, NULL); + + if (pid != -1) { + /* + * Check exit status, then refork with the + * appropriate procno. + */ + if (!WIFEXITED(wait_stat) + || 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) + tst_brk(TFAIL, "unknown child pid %d, ", + pid, wait_stat); + + pid = SAFE_FORK(); + if (pid == 0) { /* child */ + child_mapper(TEST_FILE, (unsigned int)i, (unsigned int)nprocs); + exit(0); + } else { + pidarray[i] = pid; + } + } else { + /* + * wait returned an error. If EINTR, then + * normal finish, else it's an unexpected + * error... + */ + if (errno != EINTR || !finished) + tst_brk(TFAIL, "unexpected wait error"); + } + SAFE_SIGPROCMASK(SIG_UNBLOCK, &set_mask, NULL); + } + + SAFE_SIGEMPTYSET(&set_mask); + SAFE_SIGADDSET(&set_mask, SIGALRM); + SAFE_SIGPROCMASK(SIG_BLOCK, &set_mask, NULL); + (void)alarm(0); + + /* + * Finished! Check the file for sanity. + */ + fileokay(TEST_FILE, buf); + tst_res(TPASS, "file has expected data"); +} + static struct tst_test test = { .test_all = run, .setup = setup,