Make back trace more robust. At least on i386, one of the intermediate

functions in ATF is not replaced by tail recursion elimination, so
mark it as optional.
This commit is contained in:
joerg 2013-06-06 17:40:09 +00:00
parent d5fe81af2a
commit 44c2dc6e5d

View File

@ -1,4 +1,4 @@
/* $NetBSD: t_backtrace.c,v 1.5 2012/06/02 14:52:28 njoly Exp $ */
/* $NetBSD: t_backtrace.c,v 1.6 2013/06/06 17:40:09 joerg Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_backtrace.c,v 1.5 2012/06/02 14:52:28 njoly Exp $");
__RCSID("$NetBSD: t_backtrace.c,v 1.6 2013/06/06 17:40:09 joerg Exp $");
#include <atf-c.h>
#include <atf-c/config.h>
@ -45,13 +45,23 @@ static void __attribute__((__noinline__))
myfunc3(size_t ncalls)
{
static const char *top[] = { "myfunc", "atfu_backtrace_fmt_basic_body",
"atf_tc_run", "atf_tp_main", "main", "___start" };
size_t j, nptrs;
"atf_tc_run", "atf_tp_run", "atf_tp_main", "main", "___start" };
static bool optional_frame[] = { false, false, false, true, false, false, false };
size_t j, nptrs, min_frames, max_frames;
void *buffer[ncalls + 10];
char **strings;
__CTASSERT(__arraycount(top) == __arraycount(optional_frame));
min_frames = 0;
max_frames = 0;
for (j = 0; j < __arraycount(optional_frame); ++j) {
if (!optional_frame[j])
++min_frames;
++max_frames;
}
nptrs = backtrace(buffer, __arraycount(buffer));
ATF_REQUIRE_EQ(nptrs, ncalls + 8);
ATF_REQUIRE(nptrs >= ncalls + 2 + min_frames);
ATF_REQUIRE(nptrs <= ncalls + 2 + max_frames);
strings = backtrace_symbols_fmt(buffer, nptrs, "%n");
@ -62,8 +72,13 @@ myfunc3(size_t ncalls)
for (j = 2; j < ncalls + 2; j++)
ATF_CHECK_STREQ(strings[j], "myfunc1");
for (size_t i = 0; j < nptrs; i++, j++)
for (size_t i = 0; j < nptrs; i++, j++) {
if (optional_frame[i] && strcmp(strings[j], top[i])) {
--i;
continue;
}
ATF_CHECK_STREQ(strings[j], top[i]);
}
free(strings);
}