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 enum failtest_result dont_fail(struct failtest_call *history,
16 return FAIL_DONT_FAIL;
19 static bool place_lock(int fd, char lockarr[], unsigned pos, unsigned size,
24 /* Update record keeping. */
26 memset(lockarr+pos, 1, size);
27 else if (type == F_WRLCK)
28 memset(lockarr+pos, 2, size);
30 memset(lockarr+pos, 0, size);
32 fl.l_whence = SEEK_SET;
36 return failtest_fcntl(fd, "run-locking.c", 1, F_SETLK, &fl) == 0;
39 static char lock_lookup(int fd, unsigned pos)
45 for (i = 0; i < lock_num; i++) {
51 if (pos >= l->start && pos <= l->end) {
54 else if (l->type == F_RDLCK)
63 static bool test(int fd,
64 unsigned p1, unsigned s1,
65 unsigned p2, unsigned s2,
66 unsigned p3, unsigned s3)
71 memset(lockarr, 0, sizeof(lockarr));
73 if (!place_lock(fd, lockarr, p1, s1, F_WRLCK))
76 if (!place_lock(fd, lockarr, p2, s2, F_RDLCK))
79 if (!place_lock(fd, lockarr, p3, s3, F_UNLCK))
82 for (i = 0; i < SIZE; i++) {
83 if (lock_lookup(fd, i) != lockarr[i])
87 /* Reset lock info. */
99 failtest_hook = dont_fail;
101 fd = open("run-locking-scratch", O_RDWR|O_CREAT, 0600);
102 /* GETFL and SETFL wrappers should pass through. */
103 flags = fcntl(fd, F_GETFL);
104 ok1(failtest_fcntl(fd, "run-locking.c", 1, F_GETFL) == flags);
106 ok1(failtest_fcntl(fd, "run-locking.c", 1, F_SETFL, flags) == 0);
107 ok1(failtest_fcntl(fd, "run-locking.c", 1, F_GETFL) == flags);
109 for (isize = 1; isize < 4; isize++) {
111 for (ipos = 0; ipos + isize < SIZE; ipos++) {
113 for (jsize = 1; jsize < 4; jsize++) {
115 for (jpos = 0; jpos + jsize < SIZE; jpos++) {
117 for (ksize = 1; ksize < 4; ksize++) {
133 return exit_status();