]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: add --fcntl testing to flock
authorRasmus Villemoes <rasmus.villemoes@prevas.dk>
Wed, 8 May 2024 13:32:26 +0000 (15:32 +0200)
committerRasmus Villemoes <rasmus.villemoes@prevas.dk>
Wed, 8 May 2024 13:48:41 +0000 (15:48 +0200)
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.

tests/expected/misc/flock
tests/expected/misc/flock-fcntl [new file with mode: 0644]
tests/expected/misc/flock-fcntl-exclusive [new file with mode: 0644]
tests/expected/misc/flock-fcntl-fd [new file with mode: 0644]
tests/expected/misc/flock-fcntl-no-fork [new file with mode: 0644]
tests/expected/misc/flock-fcntl-non-block [new file with mode: 0644]
tests/expected/misc/flock-fcntl-shared [new file with mode: 0644]
tests/expected/misc/flock-fcntl-time-check [new file with mode: 0644]
tests/expected/misc/flock-fcntl-timeout [new file with mode: 0644]
tests/expected/misc/flock-fcntl-vs-flock [new file with mode: 0644]
tests/ts/misc/flock

index 913e35ef9d7295b4c78e0c3543eeec859ff4b3c2..3db2558821c40b56888673b6a299869438989d33 100644 (file)
@@ -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 (file)
index 0000000..913e35e
--- /dev/null
@@ -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 (file)
index 0000000..3582111
--- /dev/null
@@ -0,0 +1 @@
+Success
diff --git a/tests/expected/misc/flock-fcntl-fd b/tests/expected/misc/flock-fcntl-fd
new file mode 100644 (file)
index 0000000..3582111
--- /dev/null
@@ -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 (file)
index 0000000..3582111
--- /dev/null
@@ -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 (file)
index 0000000..3582111
--- /dev/null
@@ -0,0 +1 @@
+Success
diff --git a/tests/expected/misc/flock-fcntl-shared b/tests/expected/misc/flock-fcntl-shared
new file mode 100644 (file)
index 0000000..011f325
--- /dev/null
@@ -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 (file)
index 0000000..2e9ba47
--- /dev/null
@@ -0,0 +1 @@
+success
diff --git a/tests/expected/misc/flock-fcntl-timeout b/tests/expected/misc/flock-fcntl-timeout
new file mode 100644 (file)
index 0000000..b4cd5a4
--- /dev/null
@@ -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 (file)
index 0000000..dd52ff5
--- /dev/null
@@ -0,0 +1,2 @@
+flock vs fcntl
+Success
index 974e1ba089f261c4c93ff3f6ad2b66a1304e451c..70fc69cf5606649b0caef395e6895d5176097b86 100755 (executable)
@@ -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."