From: Rasmus Villemoes Date: Wed, 8 May 2024 13:32:26 +0000 (+0200) Subject: tests: add --fcntl testing to flock X-Git-Tag: v2.42-start~352^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0c359281d8c9a4a82305c0b5952e208de697643b;p=thirdparty%2Futil-linux.git tests: add --fcntl testing to flock All the existing tests are also done with --fcntl in effect, and then we add one more test, namely that a flock(2) lock can be be obtained even while a fcntl(2) lock is held - not that anyone should ever need that, but it does show that the lock types are completely independent. --- diff --git a/tests/expected/misc/flock b/tests/expected/misc/flock index 913e35ef9..3db255882 100644 --- a/tests/expected/misc/flock +++ b/tests/expected/misc/flock @@ -2,3 +2,7 @@ API: flock(2) Locking Unlocking Unlocked +API: fcntl(2) +Locking +Unlocking +Unlocked diff --git a/tests/expected/misc/flock-fcntl b/tests/expected/misc/flock-fcntl new file mode 100644 index 000000000..913e35ef9 --- /dev/null +++ b/tests/expected/misc/flock-fcntl @@ -0,0 +1,4 @@ +API: flock(2) +Locking +Unlocking +Unlocked diff --git a/tests/expected/misc/flock-fcntl-exclusive b/tests/expected/misc/flock-fcntl-exclusive new file mode 100644 index 000000000..35821117c --- /dev/null +++ b/tests/expected/misc/flock-fcntl-exclusive @@ -0,0 +1 @@ +Success diff --git a/tests/expected/misc/flock-fcntl-fd b/tests/expected/misc/flock-fcntl-fd new file mode 100644 index 000000000..35821117c --- /dev/null +++ b/tests/expected/misc/flock-fcntl-fd @@ -0,0 +1 @@ +Success diff --git a/tests/expected/misc/flock-fcntl-no-fork b/tests/expected/misc/flock-fcntl-no-fork new file mode 100644 index 000000000..35821117c --- /dev/null +++ b/tests/expected/misc/flock-fcntl-no-fork @@ -0,0 +1 @@ +Success diff --git a/tests/expected/misc/flock-fcntl-non-block b/tests/expected/misc/flock-fcntl-non-block new file mode 100644 index 000000000..35821117c --- /dev/null +++ b/tests/expected/misc/flock-fcntl-non-block @@ -0,0 +1 @@ +Success diff --git a/tests/expected/misc/flock-fcntl-shared b/tests/expected/misc/flock-fcntl-shared new file mode 100644 index 000000000..011f3259c --- /dev/null +++ b/tests/expected/misc/flock-fcntl-shared @@ -0,0 +1,2 @@ +Have shared lock +Success diff --git a/tests/expected/misc/flock-fcntl-time-check b/tests/expected/misc/flock-fcntl-time-check new file mode 100644 index 000000000..2e9ba477f --- /dev/null +++ b/tests/expected/misc/flock-fcntl-time-check @@ -0,0 +1 @@ +success diff --git a/tests/expected/misc/flock-fcntl-timeout b/tests/expected/misc/flock-fcntl-timeout new file mode 100644 index 000000000..b4cd5a4cf --- /dev/null +++ b/tests/expected/misc/flock-fcntl-timeout @@ -0,0 +1,2 @@ +After timeout. +Success diff --git a/tests/expected/misc/flock-fcntl-vs-flock b/tests/expected/misc/flock-fcntl-vs-flock new file mode 100644 index 000000000..dd52ff55e --- /dev/null +++ b/tests/expected/misc/flock-fcntl-vs-flock @@ -0,0 +1,2 @@ +flock vs fcntl +Success diff --git a/tests/ts/misc/flock b/tests/ts/misc/flock index 974e1ba08..70fc69cf5 100755 --- a/tests/ts/misc/flock +++ b/tests/ts/misc/flock @@ -41,11 +41,14 @@ function do_lock { fi } -for api in flock ; do +for api in flock fcntl ; do case $api in (flock) subtest_prefix="" api_arg="" ;; + (fcntl) + subtest_prefix="fcntl-" + api_arg="--fcntl" ;; esac # general lock @@ -104,6 +107,12 @@ for api in flock ; do [ -f 4 ] && ts_log "fd file should not exist" ts_finalize_subtest + # fcntl locks are independent of flock locks, so we should be able to get an exclusive flock lock. + if [ "$api" = "fcntl" ] ; then + ts_init_subtest "fcntl-vs-flock" + do_lock "--nonblock --exclusive" 0 "flock vs fcntl" + ts_finalize_subtest + fi ts_init_subtest "${subtest_prefix}timeout" do_lock "${api_arg} --timeout 5 --conflict-exit-code 5" 0 "After timeout."