Browse Source

Remove compile warnings of tests under Ubuntu (return value ignored)

Rusty Russell 17 years ago
parent
commit
33dfc0abb7
3 changed files with 25 additions and 6 deletions
  1. 3 1
      ccan/alloc/test/run-testsize.c
  2. 3 1
      ccan/alloc/test/run.c
  3. 19 4
      ccan/tap/test/run.c

+ 3 - 1
ccan/alloc/test/run-testsize.c

@@ -3,6 +3,7 @@
 #include "alloc/alloc.c"
 #include <stdlib.h>
 #include <stdbool.h>
+#include <err.h>
 
 #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);
 

+ 3 - 1
ccan/alloc/test/run.c

@@ -2,6 +2,7 @@
 #include "tap/tap.h"
 #include "alloc/alloc.c"
 #include <stdlib.h>
+#include <err.h>
 
 #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);

+ 19 - 4
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);
 }