Skip to content

Commit c7cfe51

Browse files
committed
lkl: tests: add lklfuse_lock_conflict test
This tests that two lklfuse instances using the same lock file result in a lock conflict (exit status 2) for the instance started last. Signed-off-by: David Disseldorp <ddiss@suse.de>
1 parent 5a7149c commit c7cfe51

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

tools/lkl/tests/lklfuse.sh

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ cleanup()
1818
rmdir $dir
1919
}
2020

21-
2221
# $1 - disk image
2322
# $2 - fstype
2423
function prepfs()
@@ -33,9 +32,10 @@ function prepfs()
3332
# $1 - disk image
3433
# $2 - mount point
3534
# $3 - filesystem type
35+
# $4 - lock file
3636
lklfuse_mount()
3737
{
38-
${script_dir}/../lklfuse $1 $2 -o type=$3
38+
${script_dir}/../lklfuse $1 $2 -o type=$3,lock=$4
3939
}
4040

4141
# $1 - mount point
@@ -74,6 +74,21 @@ lklfuse_stressng()
7474
--sync-file-bytes 10m
7575
}
7676

77+
# $1 - disk image
78+
# $2 - filesystem type
79+
# $3 - lock file
80+
lklfuse_lock_conflict()
81+
{
82+
local ret=$TEST_FAILURE unused_mnt=`mktemp -d`
83+
84+
set +e
85+
# assume lklfuse already running with same lock file, causing lock conflict
86+
${script_dir}/../lklfuse -f $1 $unused_mnt -o type=$2,lock=$3
87+
[ $? -eq 2 ] && ret=$TEST_SUCCESS
88+
rmdir "$unused_mnt"
89+
return $ret
90+
}
91+
7792
if [ "$1" = "-t" ]; then
7893
shift
7994
fstype=$1
@@ -102,18 +117,19 @@ if [ -z $(which mkfs.$fstype) ]; then
102117
exit 0
103118
fi
104119

105-
106120
file=`mktemp`
107121
dir=`mktemp -d`
122+
lock_file="$file"
108123

109124
trap cleanup EXIT
110125

111-
lkl_test_plan 4 "lklfuse $fstype"
126+
lkl_test_plan 5 "lklfuse $fstype"
112127

113128
lkl_test_run 1 prepfs $file $fstype
114-
lkl_test_run 2 lklfuse_mount $file $dir $fstype
129+
lkl_test_run 2 lklfuse_mount $file $dir $fstype $lock_file
115130
lkl_test_run 3 lklfuse_basic $dir
116131
# stress-ng returns 2 with no apparent failures so skip it for now
117132
#lkl_test_run 4 lklfuse_stressng $dir $fstype
133+
lkl_test_run 4 lklfuse_lock_conflict $file $fstype $lock_file
118134
trap : EXIT
119-
lkl_test_run 4 cleanup
135+
lkl_test_run 5 cleanup

0 commit comments

Comments
 (0)