Linux Test Project
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 2/2] nfslock01: Allow to pass parameters
Date: Mon, 24 Apr 2023 20:46:58 +0200	[thread overview]
Message-ID: <20230424184658.2858634-2-pvorel@suse.cz> (raw)
In-Reply-To: <20230424184658.2858634-1-pvorel@suse.cz>

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>
---
 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 fe345780e..a00a43ceb 100644
--- a/testcases/network/nfs/nfslock01/nfs_flock.c
+++ b/testcases/network/nfs/nfslock01/nfs_flock.c
@@ -13,17 +13,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);
 	}
 
@@ -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++) {
+	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 129121d9e..4334e911d 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: <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


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2023-04-24 18:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-24 18:46 [LTP] [PATCH v2 1/2] nfslock01: Add GPL-2.0-or-later license, copyright Petr Vorel
2023-04-24 18:46 ` Petr Vorel [this message]
2023-04-25 12:17 ` Petr Vorel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230424184658.2858634-2-pvorel@suse.cz \
    --to=pvorel@suse.cz \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox