From bc83b4eaea0ab9b1a132f7717369685f5a37182e Mon Sep 17 00:00:00 2001 From: Petr Vorel Date: Mon, 24 Apr 2023 20:04:07 +0200 Subject: [PATCH] nfslock01: Allow to pass parameters Parameter for chars in line and number of lines can be made lower to make debugging faster. Signed-off-by: Petr Vorel --- testcases/network/nfs/nfslock01/nfs_flock.c | 43 +++++++++++-------- .../network/nfs/nfslock01/nfs_flock_dgen.c | 8 ++-- testcases/network/nfs/nfslock01/nfslock01.sh | 20 ++++++--- 3 files changed, 40 insertions(+), 31 deletions(-) diff --git a/testcases/network/nfs/nfslock01/nfs_flock.c b/testcases/network/nfs/nfslock01/nfs_flock.c index fe345780e4a..07b725fec94 100644 --- a/testcases/network/nfs/nfslock01/nfs_flock.c +++ b/testcases/network/nfs/nfslock01/nfs_flock.c @@ -4,7 +4,7 @@ * * Program for testing file locking. The original data file consists of * characters from 'A' to 'Z'. The data file after running this program - * would consist of lines with 1's in even lines and 0's in odd lines. + * would consist of nlines with 1's in even lines and 0's in odd lines. */ #include "nfs_flock.h" @@ -13,17 +13,15 @@ #include #include -#define BYTES 64 -#define LINES 16384 - int main(int argc, char **argv) { - int i, fd, mac; + int i, fd, mac, nchars, nlines; int offset = 0; char buf[BUFSIZ]; - if (argc != 3) { - fprintf(stderr, "Usage: %s \n", argv[0]); + if (argc != 5) { + fprintf(stderr, "Usage: %s \n", + argv[0]); exit(2); } @@ -34,48 +32,55 @@ int main(int argc, char **argv) } mac = atoi(argv[1]); + nchars = atoi(argv[3]); + nlines = atoi(argv[4]); + + if (nchars > BUFSIZ) { + printf("Exceeded the maximum limit of the buffer (%d)\n", BUFSIZ); + exit(3); + } /* * Replace a line of characters by 1's if it is process one - * else with 0's. Number of charcters in any line are BYTES-1, + * else with 0's. Number of charcters in any line are nchars-1, * the last character being a newline character. */ - for (i = 0; i < BYTES - 1; i++) { + for (i = 0; i < nchars - 1; i++) { if (mac == 1) buf[i] = '1'; else buf[i] = '0'; } - buf[BYTES - 1] = '\n'; + buf[nchars - 1] = '\n'; - for (i = 0; i < LINES; i++) { - if (mac == 1) { /* Set the offset to even lines */ + for (i = 0; i < nlines; i++) { + if (mac == 1) { /* Set the offset to even nlines */ if ((i % 2) == 0) { if (i == 0) offset = 0; else - offset += 2 * BYTES; + offset += 2 * nchars; } else continue; - } else { /* Set the offset to odd lines */ + } else { /* Set the offset to odd nlines */ if ((i % 2) == 1) { if (i == 1) - offset = BYTES; + offset = nchars; else - offset += 2 * BYTES; + offset += 2 * nchars; } else continue; } - if (writeb_lock(fd, offset, SEEK_SET, BYTES) < 0) + if (writeb_lock(fd, offset, SEEK_SET, nchars) < 0) printf("failed in writeb_lock, Errno = %d", errno); lseek(fd, offset, SEEK_SET); /* write to the test file */ - write(fd, buf, BYTES); + write(fd, buf, nchars); - if (unb_lock(fd, offset, SEEK_SET, BYTES) < 0) + if (unb_lock(fd, offset, SEEK_SET, nchars) < 0) printf("failed in unb_lock, Errno = %d", errno); } exit(0); diff --git a/testcases/network/nfs/nfslock01/nfs_flock_dgen.c b/testcases/network/nfs/nfslock01/nfs_flock_dgen.c index 129121d9e1f..4334e911d9c 100644 --- a/testcases/network/nfs/nfslock01/nfs_flock_dgen.c +++ b/testcases/network/nfs/nfslock01/nfs_flock_dgen.c @@ -16,17 +16,15 @@ int main(int argc, char **argv) FILE *fp; if (argc != 5) { - printf - ("usage: \n"); + printf("usage: \n"); exit(2); } fp = fopen(argv[1], "w"); - nchars = atoi(argv[2]); + nchars = atoi(argv[2]) - 1; if (nchars > BUFSIZ) { - printf("Exceeded the maximum limit of the buffer (%d)\n", - BUFSIZ); + printf("Exceeded the maximum limit of the buffer (%d)\n", BUFSIZ); exit(3); } nlines = atoi(argv[3]); diff --git a/testcases/network/nfs/nfslock01/nfslock01.sh b/testcases/network/nfs/nfslock01/nfslock01.sh index fbcc3c00f7c..34eeb74a1e9 100755 --- a/testcases/network/nfs/nfslock01/nfslock01.sh +++ b/testcases/network/nfs/nfslock01/nfslock01.sh @@ -1,6 +1,6 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0-or-later -# Copyright (c) Linux Test Project, 2002-2022 +# Copyright (c) Linux Test Project, 2002-2023 # Copyright (c) 2016-2018 Oracle and/or its affiliates. All Rights Reserved. # Copyright (c) International Business Machines Corp., 2001 # @@ -13,18 +13,24 @@ TST_SETUP="do_setup" TST_TESTFUNC="do_test" +NCHARS=${NCHARS:-64} +NLINES=${NLINES:-16384} + do_setup() { + local exp_size + nfs_setup tst_res TINFO "creating test files" - ROD nfs_flock_dgen flock_data 63 16384 0 - ROD nfs_flock_dgen flock_odata 63 16384 1 + ROD nfs_flock_dgen flock_data $NCHARS $NLINES 0 + ROD nfs_flock_dgen flock_odata $NCHARS $NLINES 1 - [ "$(wc -c flock_data | awk '{print $1}')" -ne 1048576 ] && \ + exp_size=$(( NCHARS * NLINES )) + [ "$(wc -c flock_data | awk '{print $1}')" -ne $exp_size ] && \ tst_brk TBROK "could not create 'flock_data'" - [ "$(wc -c flock_odata | awk '{print $1}')" -ne 1048576 ] && \ + [ "$(wc -c flock_odata | awk '{print $1}')" -ne $exp_size ] && \ tst_brk TBROK "could not create 'flock_odata'" } @@ -36,9 +42,9 @@ do_test() tst_res TINFO "locking 'flock_idata' file and writing data" - nfs_flock 0 flock_idata & + nfs_flock 0 flock_idata $NCHARS $NLINES & local pids=$! - nfs_flock 1 flock_idata & + nfs_flock 1 flock_idata $NCHARS $NLINES & pids="$pids $!" tst_res TINFO "waiting for pids: $pids"