[LTP] [PATCH 1/1] nfslock01: Allow to pass parameters

Petr Vorel pvorel@suse.cz
Fri Apr 28 18:32:19 CEST 2023


Parameter for chars in line and number of lines can be made lower to
make debugging faster.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Changes v1->v2:
Rebased

 testcases/network/nfs/nfslock01/nfs_flock.c   | 37 +++++++++++--------
 .../network/nfs/nfslock01/nfs_flock_dgen.c    |  8 ++--
 testcases/network/nfs/nfslock01/nfslock01.sh  | 20 ++++++----
 3 files changed, 37 insertions(+), 28 deletions(-)

diff --git a/testcases/network/nfs/nfslock01/nfs_flock.c b/testcases/network/nfs/nfslock01/nfs_flock.c
index d13c9766c..62e4c1a4a 100644
--- a/testcases/network/nfs/nfslock01/nfs_flock.c
+++ b/testcases/network/nfs/nfslock01/nfs_flock.c
@@ -20,17 +20,15 @@
 #include <stdlib.h>
 #include <unistd.h>
 
-#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 <mac num> <file name>\n", argv[0]);
+	if (argc != 5) {
+		fprintf(stderr, "Usage: %s <mac num> <file name> <nchars> <nlines>\n",
+				argv[0]);
 		exit(2);
 	}
 
@@ -41,48 +39,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++) {
+	for (i = 0; i < nlines; i++) {
 		if (mac == 1) {	/* Set the offset to even lines */
 			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 */
 			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 bef5219fc..995c3800b 100644
--- a/testcases/network/nfs/nfslock01/nfs_flock_dgen.c
+++ b/testcases/network/nfs/nfslock01/nfs_flock_dgen.c
@@ -22,17 +22,15 @@ int main(int argc, char **argv)
 	FILE *fp;
 
 	if (argc != 5) {
-		printf
-		    ("usage: <nfs_flock_dgen> <file> <char/line> <lines> <ctype>\n");
+		printf("usage: <nfs_flock_dgen> <file> <char/line> <lines> <ctype>\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 fbcc3c00f..34eeb74a1 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"
-- 
2.40.0



More information about the ltp mailing list