6 #include <ccan/tap/tap.h>
7 /* Include the C files directly. */
8 #include <ccan/failtest/failtest.c>
13 char buf[] = "Hello world!";
20 fd = failtest_open("run-open-scratchpad", "run-open.c", 1,
21 O_RDWR|O_CREAT, 0600);
23 /* We are the child: write error code for parent to check. */
25 if (write(pfd[1], &err, sizeof(err)) != sizeof(err))
29 /* Check it is read-write. */
30 ok1(write(fd, buf, strlen(buf)) == strlen(buf));
31 lseek(fd, SEEK_SET, 0);
32 ok1(read(fd, buf, strlen("Hello world!")) == strlen("Hello world!"));
33 ok1(strcmp(buf, "Hello world!") == 0);
35 /* Check name and perms. */
36 ok1(stat("run-open-scratchpad", &st) == 0);
37 ok1(st.st_size == strlen(buf));
38 ok1(S_ISREG(st.st_mode));
39 ok1((st.st_mode & 0777) == 0600);
41 /* Check child got correct errno. */
42 ok1(read(pfd[0], &err, sizeof(err)) == sizeof(err));
46 failtest_close(fd, "run-open.c", 1);
53 fd = failtest_open("run-open-scratchpad", "run-open.c", 1, O_RDONLY);
55 /* We are the child: write error code for parent to check. */
57 if (write(pfd[1], &err, sizeof(err)) != sizeof(err))
61 /* Check it is read-only. */
62 ok1(write(fd, buf, strlen(buf)) == -1);
63 ok1(read(fd, buf, strlen("Hello world!")) == strlen("Hello world!"));
64 ok1(strcmp(buf, "Hello world!") == 0);
66 failtest_close(fd, "run-open.c", 1);