X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ffailtest%2Ftest%2Frun-write.c;h=6a712fec53a631ca64f34a96504751ba0af133f8;hp=5425517030a5d77f1db0b22926c30956d54bf183;hb=56023cca5f66a40646a1e807c3d10af6e5913623;hpb=f0002cb9e4f6f403a25ad50252c06694439900f0 diff --git a/ccan/failtest/test/run-write.c b/ccan/failtest/test/run-write.c index 54255170..6a712fec 100644 --- a/ccan/failtest/test/run-write.c +++ b/ccan/failtest/test/run-write.c @@ -1,32 +1,40 @@ +/* Include the C files directly. */ +#include #include #include #include #include #include #include -/* Include the C files directly. */ -#include -int main(void) +int main(int argc, char *argv[]) { int fd; char *p; char buf[] = "Hello world!"; plan_tests(5); + failtest_init(argc, argv); - fd = open("run-write-scratchpad", O_RDWR|O_CREAT, 0600); - write(fd, buf, strlen(buf)); + fd = failtest_open("run-write-scratchpad", __FILE__, __LINE__, + O_RDWR|O_CREAT, 0600); + /* Child will fail, ignore. */ + if (fd < 0) + failtest_exit(0); + if (write(fd, buf, strlen(buf)) != strlen(buf)) + abort(); ok1(lseek(fd, 0, SEEK_CUR) == strlen(buf)); - p = failtest_malloc(100, "run-write.c", 1); + p = failtest_malloc(100, __FILE__, __LINE__); if (!p) { /* We are the child. Do a heap of writes. */ unsigned int i; for (i = 0; i < strlen(buf)+1; i++) - if (failtest_write(fd, "x", 1, "run-write.c", 1) == 1) + if (failtest_write(fd, "x", 1, __FILE__, __LINE__) + == 1) break; + failtest_close(fd, __FILE__, __LINE__); failtest_exit(0); } @@ -37,6 +45,7 @@ int main(void) lseek(fd, 0, SEEK_SET); ok1(read(fd, buf, strlen(buf)) == strlen("Hello world!")); ok1(strcmp(buf, "Hello world!") == 0); + failtest_close(fd, __FILE__, __LINE__); return exit_status(); }