From 11af31c336a4791a981c602b99dc52e2af5fa09b Mon Sep 17 00:00:00 2001 From: David Gibson Date: Mon, 15 Feb 2016 22:49:54 +1100 Subject: [PATCH] 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 --- ccan/altstack/test/run.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/ccan/altstack/test/run.c b/ccan/altstack/test/run.c index 389ecb91..12cc460d 100644 --- a/ccan/altstack/test/run.c +++ b/ccan/altstack/test/run.c @@ -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, -- 2.39.2