6 #include <ccan/tap/tap.h>
7 /* Include the C files directly. */
8 #include <ccan/failtest/failtest.c>
12 /* We don't want to fork and fail; we're just testing lock recording. */
13 static bool dont_fail(struct failtest_call *history, unsigned num)
18 static bool place_lock(int fd, char lockarr[], unsigned pos, unsigned size,
23 /* Update record keeping. */
25 memset(lockarr+pos, 1, size);
26 else if (type == F_WRLCK)
27 memset(lockarr+pos, 2, size);
29 memset(lockarr+pos, 0, size);
31 fl.l_whence = SEEK_SET;
35 return failtest_fcntl(fd, "run-locking.c", 1, F_SETLK, &fl) == 0;
38 static char lock_lookup(int fd, unsigned pos)
44 for (i = 0; i < lock_num; i++) {
50 if (pos >= l->start && pos <= l->end) {
53 else if (l->type == F_RDLCK)
62 static bool test(int fd,
63 unsigned p1, unsigned s1,
64 unsigned p2, unsigned s2,
65 unsigned p3, unsigned s3)
70 memset(lockarr, 0, sizeof(lockarr));
72 if (!place_lock(fd, lockarr, p1, s1, F_WRLCK))
75 if (!place_lock(fd, lockarr, p2, s2, F_RDLCK))
78 if (!place_lock(fd, lockarr, p3, s3, F_UNLCK))
81 for (i = 0; i < SIZE; i++) {
82 if (lock_lookup(fd, i) != lockarr[i])
86 /* Reset lock info. */
98 failtest_hook = dont_fail;
100 fd = open("run-locking-scratch", O_RDWR|O_CREAT, 0600);
101 /* GETFL and SETFL wrappers should pass through. */
102 flags = fcntl(fd, F_GETFL);
103 ok1(failtest_fcntl(fd, "run-locking.c", 1, F_GETFL) == flags);
105 ok1(failtest_fcntl(fd, "run-locking.c", 1, F_SETFL, flags) == 0);
106 ok1(failtest_fcntl(fd, "run-locking.c", 1, F_GETFL) == flags);
108 for (isize = 1; isize < 4; isize++) {
110 for (ipos = 0; ipos + isize < SIZE; ipos++) {
112 for (jsize = 1; jsize < 4; jsize++) {
114 for (jpos = 0; jpos + jsize < SIZE; jpos++) {
116 for (ksize = 1; ksize < 4; ksize++) {
132 return exit_status();