summaryrefslogtreecommitdiff
path: root/regress/sys
diff options
context:
space:
mode:
authoranton <anton@cvs.openbsd.org>2018-10-21 15:19:26 +0000
committeranton <anton@cvs.openbsd.org>2018-10-21 15:19:26 +0000
commit152c7638bc39a6b45575a6a166c8e23f335a579c (patch)
treeac4f286abc08ac321178de6c17cd219bfe8b05c5 /regress/sys
parent05e97ea280b065b17e190c48ab1311f4c4a645ed (diff)
Add flock insertion tests covering all possible forms of byte range overlap.
Diffstat (limited to 'regress/sys')
-rw-r--r--regress/sys/kern/flock/Makefile4
-rw-r--r--regress/sys/kern/flock/flock.c292
2 files changed, 294 insertions, 2 deletions
diff --git a/regress/sys/kern/flock/Makefile b/regress/sys/kern/flock/Makefile
index 0f4fbc6a090..9e427a55e9d 100644
--- a/regress/sys/kern/flock/Makefile
+++ b/regress/sys/kern/flock/Makefile
@@ -1,10 +1,10 @@
-# $OpenBSD: Makefile,v 1.4 2018/10/16 16:54:18 anton Exp $
+# $OpenBSD: Makefile,v 1.5 2018/10/21 15:19:25 anton Exp $
PROG= flock
WARNINGS= yes
-TESTS!=jot 16 1
+TESTS!=jot 22 1
# XXX known failures (talk to art)
REGRESS_SKIP_TARGETS = t-5 t-6
diff --git a/regress/sys/kern/flock/flock.c b/regress/sys/kern/flock/flock.c
index 6617adb07b3..7b85bb320f0 100644
--- a/regress/sys/kern/flock/flock.c
+++ b/regress/sys/kern/flock/flock.c
@@ -1449,6 +1449,292 @@ test16(int fd, __unused int argc, const __unused char **argv)
SUCCEED;
}
+/*
+ * Test 17 - lf_findoverlap() case 0
+ *
+ * No overlap.
+ */
+static int
+test17(int fd, __unused int argc, const __unused char **argv)
+{
+ struct flock fl;
+ int nfd, res;
+
+ /* First lock. */
+ {
+ nfd = dup(fd);
+ FAIL(nfd == -1);
+
+ fl.l_start = 0;
+ fl.l_len = 100;
+ fl.l_pid = 0;
+ fl.l_type = F_RDLCK;
+ fl.l_whence = 0;
+ res = fcntl(fd, F_SETLK, &fl);
+ FAIL(res != 0);
+
+ close(nfd);
+ }
+
+ /* Insert at end. */
+ {
+ nfd = dup(fd);
+ FAIL(nfd == -1);
+
+ fl.l_start = 100;
+ fl.l_len = 100;
+ fl.l_pid = 0;
+ fl.l_type = F_RDLCK;
+ fl.l_whence = 0;
+ res = fcntl(fd, F_SETLK, &fl);
+ FAIL(res != 0);
+
+ fl.l_start = 200;
+ fl.l_len = 100;
+ fl.l_pid = 0;
+ fl.l_type = F_RDLCK;
+ fl.l_whence = 0;
+ res = fcntl(fd, F_SETLK, &fl);
+ FAIL(res != 0);
+
+ close(nfd);
+ }
+
+ /* Insert before overlap. */
+ {
+ nfd = dup(fd);
+ FAIL(nfd == -1);
+
+ fl.l_start = 300;
+ fl.l_len = 100;
+ fl.l_pid = 0;
+ fl.l_type = F_RDLCK;
+ fl.l_whence = 0;
+ res = fcntl(fd, F_SETLK, &fl);
+ FAIL(res != 0);
+
+ fl.l_start = 500;
+ fl.l_len = 100;
+ fl.l_pid = 0;
+ fl.l_type = F_RDLCK;
+ fl.l_whence = 0;
+ res = fcntl(fd, F_SETLK, &fl);
+ FAIL(res != 0);
+
+ fl.l_start = 400;
+ fl.l_len = 100;
+ fl.l_pid = 0;
+ fl.l_type = F_RDLCK;
+ fl.l_whence = 0;
+ res = fcntl(fd, F_SETLK, &fl);
+ FAIL(res != 0);
+
+ close(nfd);
+ }
+
+ SUCCEED;
+}
+
+/*
+ * Test 18 - lf_findoverlap() case 1
+ *
+ * Overlap and lock are equal.
+ */
+static int
+test18(int fd, __unused int argc, const __unused char **argv)
+{
+ struct flock fl;
+ int res;
+
+ fl.l_start = 0;
+ fl.l_len = 100;
+ fl.l_pid = 0;
+ fl.l_type = F_RDLCK;
+ fl.l_whence = 0;
+ res = fcntl(fd, F_SETLK, &fl);
+ FAIL(res != 0);
+ res = fcntl(fd, F_SETLK, &fl);
+ FAIL(res != 0);
+
+ SUCCEED;
+}
+
+/*
+ * Test 19 - lf_findoverlap() case 2
+ *
+ * Overlap contains lock.
+ */
+static int
+test19(int fd, __unused int argc, const __unused char **argv)
+{
+ struct flock fl;
+ int nfd, res;
+
+ /* Same type. */
+ {
+ nfd = dup(fd);
+ FAIL(nfd == -1);
+
+ fl.l_start = 0;
+ fl.l_len = 100;
+ fl.l_pid = 0;
+ fl.l_type = F_RDLCK;
+ fl.l_whence = 0;
+ res = fcntl(fd, F_SETLK, &fl);
+ FAIL(res != 0);
+
+ fl.l_start = 0;
+ fl.l_len = 50;
+ fl.l_pid = 0;
+ fl.l_type = F_RDLCK;
+ fl.l_whence = 0;
+ res = fcntl(fd, F_SETLK, &fl);
+ FAIL(res != 0);
+
+ close(nfd);
+ }
+
+ /* Different type, same start offset. */
+ {
+ nfd = dup(fd);
+ FAIL(nfd == -1);
+
+ fl.l_start = 100;
+ fl.l_len = 100;
+ fl.l_pid = 0;
+ fl.l_type = F_RDLCK;
+ fl.l_whence = 0;
+ res = fcntl(fd, F_SETLK, &fl);
+ FAIL(res != 0);
+
+ fl.l_start = 100;
+ fl.l_len = 50;
+ fl.l_pid = 0;
+ fl.l_type = F_WRLCK;
+ fl.l_whence = 0;
+ res = fcntl(fd, F_SETLK, &fl);
+ FAIL(res != 0);
+
+ close(nfd);
+ }
+
+ /* Split fallback. */
+ {
+ nfd = dup(fd);
+ FAIL(nfd == -1);
+
+ fl.l_start = 100;
+ fl.l_len = 100;
+ fl.l_pid = 0;
+ fl.l_type = F_RDLCK;
+ fl.l_whence = 0;
+ res = fcntl(fd, F_SETLK, &fl);
+ FAIL(res != 0);
+
+ fl.l_start = 110;
+ fl.l_len = 50;
+ fl.l_pid = 0;
+ fl.l_type = F_WRLCK;
+ fl.l_whence = 0;
+ res = fcntl(fd, F_SETLK, &fl);
+ FAIL(res != 0);
+
+ close(nfd);
+ }
+
+ SUCCEED;
+}
+
+/*
+ * Test 20 - lf_findoverlap() case 3
+ *
+ * Lock contains overlap.
+ */
+static int
+test20(int fd, __unused int argc, const __unused char **argv)
+{
+ struct flock fl;
+ int res;
+
+ fl.l_start = 0;
+ fl.l_len = 100;
+ fl.l_pid = 0;
+ fl.l_type = F_WRLCK;
+ fl.l_whence = 0;
+ res = fcntl(fd, F_SETLK, &fl);
+ FAIL(res != 0);
+
+ fl.l_start = 0;
+ fl.l_len = 200;
+ fl.l_pid = 0;
+ fl.l_type = F_WRLCK;
+ fl.l_whence = 0;
+ res = fcntl(fd, F_SETLK, &fl);
+ FAIL(res != 0);
+
+ SUCCEED;
+}
+
+/*
+ * Test 21 - lf_findoverlap() case 4
+ *
+ * Overlap starts before lock.
+ */
+static int
+test21(int fd, __unused int argc, const __unused char **argv)
+{
+ struct flock fl;
+ int res;
+
+ fl.l_start = 0;
+ fl.l_len = 100;
+ fl.l_pid = 0;
+ fl.l_type = F_WRLCK;
+ fl.l_whence = 0;
+ res = fcntl(fd, F_SETLK, &fl);
+ FAIL(res != 0);
+
+ fl.l_start = 50;
+ fl.l_len = 100;
+ fl.l_pid = 0;
+ fl.l_type = F_WRLCK;
+ fl.l_whence = 0;
+ res = fcntl(fd, F_SETLK, &fl);
+ FAIL(res != 0);
+
+ SUCCEED;
+}
+
+/*
+ * Test 22 - lf_findoverlap() case 5
+ *
+ * Overlap ends after lock.
+ */
+static int
+test22(int fd, __unused int argc, const __unused char **argv)
+{
+ struct flock fl;
+ int res;
+
+ fl.l_start = 10;
+ fl.l_len = 100;
+ fl.l_pid = 0;
+ fl.l_type = F_WRLCK;
+ fl.l_whence = 0;
+ res = fcntl(fd, F_SETLK, &fl);
+ FAIL(res != 0);
+
+ fl.l_start = 0;
+ fl.l_len = 50;
+ fl.l_pid = 0;
+ fl.l_type = F_WRLCK;
+ fl.l_whence = 0;
+ res = fcntl(fd, F_SETLK, &fl);
+ FAIL(res != 0);
+
+ SUCCEED;
+}
+
struct test {
int (*testfn)(int, int, const char **); /* function to perform the test */
int num; /* test number */
@@ -1472,6 +1758,12 @@ struct test tests[] = {
{ test14, 14, 0 },
{ test15, 15, 1 },
{ test16, 16, 0 },
+ { test17, 17, 0 },
+ { test18, 18, 0 },
+ { test19, 19, 0 },
+ { test20, 20, 0 },
+ { test21, 21, 0 },
+ { test22, 22, 0 },
};
int test_count = sizeof(tests) / sizeof(tests[0]);