Module Name:    src
Committed By:   joerg
Date:           Thu Jun  6 17:40:09 UTC 2013

Modified Files:
        src/tests/lib/libexecinfo: t_backtrace.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libexecinfo/t_backtrace.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libexecinfo/t_backtrace.c
diff -u src/tests/lib/libexecinfo/t_backtrace.c:1.5 src/tests/lib/libexecinfo/t_backtrace.c:1.6
--- src/tests/lib/libexecinfo/t_backtrace.c:1.5	Sat Jun  2 14:52:28 2012
+++ src/tests/lib/libexecinfo/t_backtrace.c	Thu Jun  6 17:40:09 2013
@@ -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);
 }

Reply via email to