From: Rusty Russell Date: Sat, 15 Nov 2008 10:39:38 +0000 (+1030) Subject: Remove compile warnings of tests under Ubuntu (return value ignored) X-Git-Url: https://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=33dfc0abb7a9d2c422246be5f8def438b63a0bb2;ds=sidebyside Remove compile warnings of tests under Ubuntu (return value ignored) --- diff --git a/ccan/alloc/test/run-testsize.c b/ccan/alloc/test/run-testsize.c index bb063c24..9071cb6d 100644 --- a/ccan/alloc/test/run-testsize.c +++ b/ccan/alloc/test/run-testsize.c @@ -3,6 +3,7 @@ #include "alloc/alloc.c" #include #include +#include #define POOL_ORD 16 #define POOL_SIZE (1 << POOL_ORD) @@ -34,7 +35,8 @@ int main(int argc, char *argv[]) plan_tests(5); /* FIXME: Needs to be page aligned for now. */ - posix_memalign(&mem, 1 << POOL_ORD, POOL_SIZE); + if (posix_memalign(&mem, 1 << POOL_ORD, POOL_SIZE) != 0) + errx(1, "Failed allocating aligned memory"); alloc_init(mem, POOL_SIZE); diff --git a/ccan/alloc/test/run.c b/ccan/alloc/test/run.c index bf8ab479..8247122e 100644 --- a/ccan/alloc/test/run.c +++ b/ccan/alloc/test/run.c @@ -2,6 +2,7 @@ #include "tap/tap.h" #include "alloc/alloc.c" #include +#include #define POOL_ORD 16 #define POOL_SIZE (1 << POOL_ORD) @@ -52,7 +53,8 @@ int main(int argc, char *argv[]) plan_tests(178); /* FIXME: Needs to be page aligned for now. */ - posix_memalign(&mem, 1 << POOL_ORD, POOL_SIZE); + if (posix_memalign(&mem, 1 << POOL_ORD, POOL_SIZE) != 0) + errx(1, "Failed allocating aligned memory"); /* Small pool, all allocs fail, even 0-length. */ alloc_init(mem, 0); diff --git a/ccan/tap/test/run.c b/ccan/tap/test/run.c index 2f718cc2..26957fb5 100644 --- a/ccan/tap/test/run.c +++ b/ccan/tap/test/run.c @@ -16,6 +16,20 @@ /* We dup stderr to here. */ static int stderrfd; +/* write_all inlined here to avoid circular dependency. */ +static void write_all(int fd, const void *data, size_t size) +{ + while (size) { + ssize_t done; + + done = write(fd, data, size); + if (done <= 0) + _exit(1); + data += done; + size -= done; + } +} + /* Simple replacement for err() */ static void failmsg(const char *fmt, ...) { @@ -27,9 +41,9 @@ static void failmsg(const char *fmt, ...) vsprintf(buf, fmt, ap); va_end(ap); - write(stderrfd, "# ", 2); - write(stderrfd, buf, strlen(buf)); - write(stderrfd, "\n", 1); + write_all(stderrfd, "# ", 2); + write_all(stderrfd, buf, strlen(buf)); + write_all(stderrfd, "\n", 1); _exit(1); } @@ -113,6 +127,7 @@ int main(int argc, char *argv[]) expect(p[0], "# Looks like you failed 2 tests of 9.\n"); #endif - write(stdoutfd, "ok 1 - All passed\n", strlen("ok 1 - All passed\n")); + write_all(stdoutfd, "ok 1 - All passed\n", + strlen("ok 1 - All passed\n")); _exit(0); }