Browse Source

altstack: Clarify checking macros

The chkfail() and chkok() macros in altstack's test program are pretty
difficult to read.  More importantly, though, they do all their tests with
one big ok1().  That means if the test fails, you get no indication which
of the checks was actually wrong, making debugging harder.

This reworks the macros into a more verbose form that's easier to read,
and splits them into multiple ok1() tests to make failures more explicit.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson 10 years ago
parent
commit
11af31c336
1 changed files with 24 additions and 4 deletions
  1. 24 4
      ccan/altstack/test/run.c

+ 24 - 4
ccan/altstack/test/run.c

@@ -57,14 +57,34 @@ static void *wrap(void *i)
 	return wrap;
 	return wrap;
 }
 }
 
 
+#define chkfail(x, y, z, c1, c2)					\
+	do {								\
+		call1 = 0;						\
+		call2 = 0;						\
+		errno = 0;						\
+		ok1((fail = x) && (y));					\
+		ok1(errno == (z));					\
+		ok1(call1 == (c1));					\
+		ok1(call2 == (c2));					\
+	} while (0);
+
+#define chkok(y, z, c1, c2)						\
+	do {								\
+		call1 = 0;						\
+		call2 = 0;						\
+		errno = 0;						\
+		fail = 0;						\
+		ok1((y));						\
+		ok1(errno == (z));					\
+		ok1(call1 == (c1));					\
+		ok1(call2 == (c2));					\
+	} while (0)
+
 int main(void)
 int main(void)
 {
 {
 	long pgsz = sysconf(_SC_PAGESIZE);
 	long pgsz = sysconf(_SC_PAGESIZE);
 
 
-	plan_tests(17);
-
-#define chkfail(x, y, z, c1, c2) (call1 = 0, call2 = 0, errno = 0, ok1((fail = x) && (y) && errno == (z) && call1 == (c1) && call2 == (c2)));
-#define   chkok(   y, z, c1, c2) (call1 = 0, call2 = 0, errno = 0, fail = 0,     ok1((y) && errno == (z) && call1 == (c1) && call2 == (c2)));
+	plan_tests(50);
 
 
 	chkfail(getrlimit_,	altstack(8*MiB, wrap, 0, 0) == -1, e(getrlimit_),
 	chkfail(getrlimit_,	altstack(8*MiB, wrap, 0, 0) == -1, e(getrlimit_),
 		0,
 		0,