1 /* Include the C files directly. */
2 #include <ccan/failtest/failtest.c>
8 #include <ccan/tap/tap.h>
13 char buf[] = "Hello world!";
17 failtest_init(0, NULL);
21 fd = failtest_open("run-open-scratchpad", "run-open.c", 1,
22 O_RDWR|O_CREAT, 0600);
24 /* We are the child: write error code for parent to check. */
26 if (write(pfd[1], &err, sizeof(err)) != sizeof(err))
30 /* Check it is read-write. */
31 ok1(write(fd, buf, strlen(buf)) == strlen(buf));
32 lseek(fd, SEEK_SET, 0);
33 ok1(read(fd, buf, strlen("Hello world!")) == strlen("Hello world!"));
34 ok1(strcmp(buf, "Hello world!") == 0);
36 /* Check name and perms. */
37 ok1(stat("run-open-scratchpad", &st) == 0);
38 ok1(st.st_size == strlen(buf));
39 ok1(S_ISREG(st.st_mode));
40 ok1((st.st_mode & 0777) == 0600);
42 /* Check child got correct errno. */
43 ok1(read(pfd[0], &err, sizeof(err)) == sizeof(err));
47 failtest_close(fd, "run-open.c", 1);
54 fd = failtest_open("run-open-scratchpad", "run-open.c", 1, O_RDONLY);
56 /* We are the child: write error code for parent to check. */
58 if (write(pfd[1], &err, sizeof(err)) != sizeof(err))
62 /* Check it is read-only. */
63 ok1(write(fd, buf, strlen(buf)) == -1);
64 ok1(read(fd, buf, strlen("Hello world!")) == strlen("Hello world!"));
65 ok1(strcmp(buf, "Hello world!") == 0);
67 failtest_close(fd, "run-open.c", 1);