]> git.ozlabs.org Git - ccan/commitdiff
altstack: Clarify checking macros
authorDavid Gibson <david@gibson.dropbear.id.au>
Mon, 15 Feb 2016 11:49:54 +0000 (22:49 +1100)
committerDavid Gibson <david@gibson.dropbear.id.au>
Mon, 15 Feb 2016 11:49:54 +0000 (22:49 +1100)
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>
ccan/altstack/test/run.c

index 389ecb916b2f9d5089ab8fefa1e1ae951ee4c322..12cc460d8dd264647e11a7d4e0dacc4cf1b60a3d 100644 (file)
@@ -57,14 +57,34 @@ static void *wrap(void *i)
        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)
 {
        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_),
                0,