1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0-or-later 3# Copyright (c) Linux Test Project, 2002-2023 4# Copyright (c) 2016-2018 Oracle and/or its affiliates. All Rights Reserved. 5# Copyright (c) International Business Machines Corp., 2001 6# 7# PURPOSE: 8# Two processes open FLOCK_IDATA file simultaneously 9# each one locks odd and even lines of the file simultaneously 10# and fill them with '0's and '1's. After they find eof, the 11# datafiles are compared. 12 13TST_SETUP="do_setup" 14TST_TESTFUNC="do_test" 15 16NCHARS=${NCHARS:-64} 17NLINES=${NLINES:-16384} 18 19generate_file() 20{ 21 local file="$1" 22 local nchars="$2" 23 local nlines="$3" 24 local val="$4" 25 local exp_size="$((nchars*nlines))" 26 local size 27 28 ROD nfs_flock_dgen $file $nchars $nlines $val 29 30 size="$(wc -c $file | awk '{print $1}')" 31 if [ $size -ne $exp_size ]; then 32 tst_brk TBROK "could not create '$file' (size: $size, expected: $exp_size)" 33 fi 34} 35 36do_setup() 37{ 38 if ! tst_is_int $NCHARS || [ $NCHARS -lt 1 ]; then 39 tst_res TBROK "NCHARS must be > 0" 40 fi 41 42 if ! tst_is_int $NLINES || [ $NLINES -lt 1 ]; then 43 tst_res TBROK "NLINES must be > 0" 44 fi 45 46 nfs_setup 47 48 tst_res TINFO "creating test files (chars: $NCHARS, lines: $NLINES)" 49 50 generate_file flock_data $NCHARS $NLINES 0 51 generate_file flock_odata $NCHARS $NLINES 1 52} 53 54do_test() 55{ 56 tst_res TINFO "Testing locking" 57 58 ROD cp flock_data flock_idata 59 60 tst_res TINFO "locking 'flock_idata' file and writing data" 61 62 nfs_flock 0 flock_idata $NCHARS $NLINES & 63 local pids=$! 64 nfs_flock 1 flock_idata $NCHARS $NLINES & 65 pids="$pids $!" 66 67 tst_res TINFO "waiting for pids: $pids" 68 for p in $pids; do 69 wait $p 70 if [ $? -ne 0 ]; then 71 tst_res TFAIL "nfs_lock process failed" 72 return 73 else 74 tst_res TINFO "$p completed" 75 fi 76 done 77 78 diff flock_odata flock_idata 79 if [ $? -ne 0 ]; then 80 tst_res TFAIL "content is different" 81 else 82 tst_res TPASS "content is the same" 83 fi 84} 85 86. nfs_lib.sh 87tst_run 88