Skip to content

Commit

Permalink
nfslock01: Allow to pass parameters
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
pevik committed Apr 24, 2023
1 parent b154f71 commit afd8cf6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 28 deletions.
37 changes: 21 additions & 16 deletions testcases/network/nfs/nfslock01/nfs_flock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down
8 changes: 3 additions & 5 deletions testcases/network/nfs/nfslock01/nfs_flock_dgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
20 changes: 13 additions & 7 deletions testcases/network/nfs/nfslock01/nfslock01.sh
Original file line number Diff line number Diff line change
@@ -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
#
Expand All @@ -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'"
}

Expand All @@ -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"
Expand Down

0 comments on commit afd8cf6

Please sign in to comment.