]> git.ozlabs.org Git - ccan/blob - ccan/failtest/test/run-failpath.c
failtest: new module.
[ccan] / ccan / failtest / test / run-failpath.c
1 #include <stdlib.h>
2 #include <setjmp.h>
3 #include <stdio.h>
4 #include <stdarg.h>
5 #include <ccan/tap/tap.h>
6 #include <ccan/failtest/failtest.c>
7
8 int main(void)
9 {
10         int fds[2], fd;
11         void *p;
12
13         plan_tests(14);
14
15         failpath = "mceopwrMCEOPWR";
16
17         ok1((p = failtest_malloc(10, "run-failpath.c", 1)) != NULL);
18         ok1(failtest_calloc(10, 5, "run-failpath.c", 1) != NULL);
19         ok1((p = failtest_realloc(p, 100, "run-failpath.c", 1)) != NULL);
20         ok1((fd = failtest_open("failpath-scratch", O_RDWR|O_CREAT,
21                                 "run-failpath.c", 1, 0600)) >= 0);
22         ok1(failtest_pipe(fds, "run-failpath.c", 1) == 0);
23         ok1(failtest_write(fd, "xxxx", 4, "run-failpath.c", 1) == 4);
24         lseek(fd, 0, SEEK_SET);
25         ok1(failtest_read(fd, p, 5, "run-failpath.c", 1) == 4);
26
27         /* Now we're into the failures. */
28         ok1(failtest_malloc(10, "run-failpath.c", 1) == NULL);
29         ok1(failtest_calloc(10, 5, "run-failpath.c", 1) == NULL);
30         ok1(failtest_realloc(p, 100, "run-failpath.c", 1) == NULL);
31         ok1(failtest_open("failpath-scratch", O_RDWR|O_CREAT,
32                           "run-failpath.c", 1, 0600) == -1);
33         ok1(failtest_pipe(fds, "run-failpath.c", 1) == -1);
34         ok1(failtest_write(fd, "xxxx", 4, "run-failpath.c", 1) == -1);
35         lseek(fd, 0, SEEK_SET);
36         ok1(failtest_read(fd, p, 5, "run-failpath.c", 1) == -1);
37         return exit_status();
38 }