From: Rusty Russell Date: Tue, 4 Oct 2011 01:39:45 +0000 (+1030) Subject: foreach: make test more accurate, fix for 64-bit gcc 4.4.3 X-Git-Url: https://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=83bba283bd7c94f083ea19df78e1e921b30d97b6;ds=sidebyside foreach: make test more accurate, fix for 64-bit gcc 4.4.3 gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3 on x86_64 uses a different stack offset for the second call to test_ptr_recursion(), meaning it sees new iterators. Put it inside a loop to reduce the chance of that happening. --- diff --git a/ccan/foreach/test/run-nested.c b/ccan/foreach/test/run-nested.c index b54fbbe0..17fa2f16 100644 --- a/ccan/foreach/test/run-nested.c +++ b/ccan/foreach/test/run-nested.c @@ -47,7 +47,7 @@ int main(void) int i, j, sum; const char *istr, *jstr; - plan_tests(12); + plan_tests(16); sum = 0; foreach_int(i, 0, 1, 2, 3, 4) @@ -68,12 +68,6 @@ int main(void) ok1(sum == 100); ok1(count_iters() <= 2); - sum = test_int_recursion(0); - diag("sum = %i\n", sum); - diag("iters = %i\n", count_iters()); - ok1(sum == 160); - ok1(count_iters() <= 2 + 5); /* 5 is max depth of recursion. */ - sum = 0; foreach_ptr(istr, "0", "1", "2", "3", "4") foreach_ptr(jstr, "0", "1", "2", "3", "4") @@ -81,7 +75,7 @@ int main(void) diag("sum = %i\n", sum); diag("iters = %i\n", count_iters()); ok1(sum == 100); - ok1(count_iters() <= 2 + 5 + 2); + ok1(count_iters() <= 2 + 2); /* Same again... reusing iterators. */ sum = 0; @@ -91,13 +85,22 @@ int main(void) diag("sum = %i\n", sum); diag("iters = %i\n", count_iters()); ok1(sum == 100); - ok1(count_iters() <= 2 + 5 + 2); + ok1(count_iters() <= 2 + 2); - sum = test_ptr_recursion("0"); - diag("sum = %i\n", sum); - diag("iters = %i\n", count_iters()); - ok1(sum == 160); - ok1(count_iters() <= 2 + 5 + 2); + /* Do this twice, second time shouldn't increase iterators. */ + for (i = 0; i < 2; i++) { + sum = test_int_recursion(0); + diag("sum = %i\n", sum); + diag("iters = %i\n", count_iters()); + ok1(sum == 160); + ok1(count_iters() <= 2 + 2 + 5); /* 5 is max depth of recursion. */ + + sum = test_ptr_recursion("0"); + diag("sum = %i\n", sum); + diag("iters = %i\n", count_iters()); + ok1(sum == 160); + ok1(count_iters() <= 2 + 2 + 5); + } return exit_status(); }