6 #include <ccan/tap/tap.h>
7 /* Include the C files directly. */
8 #include <ccan/failtest/failtest.c>
13 char buf[] = "Hello world!";
19 fd = failtest_open("run-open-scratchpad", "run-open.c", 1,
20 O_RDWR|O_CREAT, 0600);
22 /* We are the child: write error code for parent to check. */
24 write(pfd[1], &err, sizeof(err));
27 /* Check it is read-write. */
28 ok1(write(fd, buf, strlen(buf)) == strlen(buf));
29 lseek(fd, SEEK_SET, 0);
30 ok1(read(fd, buf, strlen("Hello world!")) == strlen("Hello world!"));
31 ok1(strcmp(buf, "Hello world!") == 0);
33 /* Check name and perms. */
34 ok1(stat("run-open-scratchpad", &st) == 0);
35 ok1(st.st_size == strlen(buf));
36 ok1(S_ISREG(st.st_mode));
37 ok1((st.st_mode & 0777) == 0600);
39 /* Check child got correct errno. */
40 ok1(read(pfd[0], &err, sizeof(err)) == sizeof(err));
44 failtest_close(fd, "run-open.c", 1);
50 fd = failtest_open("run-open-scratchpad", "run-open.c", 1, O_RDONLY);
52 /* We are the child: write error code for parent to check. */
54 write(pfd[1], &err, sizeof(err));
57 /* Check it is read-only. */
58 ok1(write(fd, buf, strlen(buf)) == -1);
59 ok1(read(fd, buf, strlen("Hello world!")) == strlen("Hello world!"));
60 ok1(strcmp(buf, "Hello world!") == 0);
62 failtest_close(fd, "run-open.c", 1);