X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ffailtest%2Ftest%2Frun-failpath.c;fp=ccan%2Ffailtest%2Ftest%2Frun-failpath.c;h=c5aca9ef88f6ceb97609855db820cfcf30106834;hb=f0002cb9e4f6f403a25ad50252c06694439900f0;hp=0000000000000000000000000000000000000000;hpb=fece6c238afd41bd3ffba1287afa598863d7165e;p=ccan diff --git a/ccan/failtest/test/run-failpath.c b/ccan/failtest/test/run-failpath.c new file mode 100644 index 00000000..c5aca9ef --- /dev/null +++ b/ccan/failtest/test/run-failpath.c @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include +#include + +int main(void) +{ + int fds[2], fd; + void *p; + + plan_tests(14); + + failpath = "mceopwrMCEOPWR"; + + ok1((p = failtest_malloc(10, "run-failpath.c", 1)) != NULL); + ok1(failtest_calloc(10, 5, "run-failpath.c", 1) != NULL); + ok1((p = failtest_realloc(p, 100, "run-failpath.c", 1)) != NULL); + ok1((fd = failtest_open("failpath-scratch", O_RDWR|O_CREAT, + "run-failpath.c", 1, 0600)) >= 0); + ok1(failtest_pipe(fds, "run-failpath.c", 1) == 0); + ok1(failtest_write(fd, "xxxx", 4, "run-failpath.c", 1) == 4); + lseek(fd, 0, SEEK_SET); + ok1(failtest_read(fd, p, 5, "run-failpath.c", 1) == 4); + + /* Now we're into the failures. */ + ok1(failtest_malloc(10, "run-failpath.c", 1) == NULL); + ok1(failtest_calloc(10, 5, "run-failpath.c", 1) == NULL); + ok1(failtest_realloc(p, 100, "run-failpath.c", 1) == NULL); + ok1(failtest_open("failpath-scratch", O_RDWR|O_CREAT, + "run-failpath.c", 1, 0600) == -1); + ok1(failtest_pipe(fds, "run-failpath.c", 1) == -1); + ok1(failtest_write(fd, "xxxx", 4, "run-failpath.c", 1) == -1); + lseek(fd, 0, SEEK_SET); + ok1(failtest_read(fd, p, 5, "run-failpath.c", 1) == -1); + return exit_status(); +}