Blame SOURCES/gdb-6.5-ia64-libunwind-leak-test.patch

a8223e
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
a8223e
From: Fedora GDB patches <invalid@email.com>
a8223e
Date: Fri, 27 Oct 2017 21:07:50 +0200
a8223e
Subject: gdb-6.5-ia64-libunwind-leak-test.patch
a8223e
a8223e
;; Test ia64 memory leaks of the code using libunwind.
a8223e
;;=fedoratest
a8223e
a8223e
diff --git a/gdb/testsuite/gdb.base/unwind-leak.c b/gdb/testsuite/gdb.base/unwind-leak.c
a8223e
new file mode 100644
a8223e
--- /dev/null
a8223e
+++ b/gdb/testsuite/gdb.base/unwind-leak.c
a8223e
@@ -0,0 +1,29 @@
a8223e
+/* This testcase is part of GDB, the GNU debugger.
a8223e
+
a8223e
+   Copyright 2007 Free Software Foundation, Inc.
a8223e
+
a8223e
+   This program is free software; you can redistribute it and/or modify
a8223e
+   it under the terms of the GNU General Public License as published by
a8223e
+   the Free Software Foundation; either version 2 of the License, or
a8223e
+   (at your option) any later version.
a8223e
+
a8223e
+   This program is distributed in the hope that it will be useful,
a8223e
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
a8223e
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
a8223e
+   GNU General Public License for more details.
a8223e
+
a8223e
+   You should have received a copy of the GNU General Public License
a8223e
+   along with this program; if not, write to the Free Software
a8223e
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
a8223e
+
a8223e
+   Please email any bugs, comments, and/or additions to this file to:
a8223e
+   bug-gdb@prep.ai.mit.edu  */
a8223e
+
a8223e
+#include <unistd.h>
a8223e
+
a8223e
+int main()
a8223e
+{
a8223e
+  for (;;)
a8223e
+    alarm (0);
a8223e
+  return 0;
a8223e
+}
a8223e
diff --git a/gdb/testsuite/gdb.base/unwind-leak.exp b/gdb/testsuite/gdb.base/unwind-leak.exp
a8223e
new file mode 100644
a8223e
--- /dev/null
a8223e
+++ b/gdb/testsuite/gdb.base/unwind-leak.exp
a8223e
@@ -0,0 +1,88 @@
a8223e
+# Copyright 2007 Free Software Foundation, Inc.
a8223e
+
a8223e
+# This program is free software; you can redistribute it and/or modify
a8223e
+# it under the terms of the GNU General Public License as published by
a8223e
+# the Free Software Foundation; either version 2 of the License, or
a8223e
+# (at your option) any later version.
a8223e
+#
a8223e
+# This program is distributed in the hope that it will be useful,
a8223e
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
a8223e
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
a8223e
+# GNU General Public License for more details.
a8223e
+#
a8223e
+# You should have received a copy of the GNU General Public License
a8223e
+# along with this program; if not, write to the Free Software
a8223e
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
a8223e
+
a8223e
+if {[use_gdb_stub]} {
a8223e
+    untested "skipping test because of use_gdb_stub"
a8223e
+    return -1
a8223e
+}
a8223e
+
a8223e
+set testfile unwind-leak
a8223e
+set srcfile ${testfile}.c
a8223e
+set shfile [standard_output_file ${testfile}-gdb.sh]
a8223e
+set binfile [standard_output_file ${testfile}]
a8223e
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
a8223e
+    untested "Couldn't compile test program"
a8223e
+    return -1
a8223e
+}
a8223e
+
a8223e
+# Get things started.
a8223e
+
a8223e
+gdb_exit
a8223e
+gdb_start
a8223e
+gdb_reinitialize_dir $srcdir/$subdir
a8223e
+gdb_load ${binfile}
a8223e
+
a8223e
+set pid [exp_pid -i [board_info host fileid]]
a8223e
+
a8223e
+# For C programs, "start" should stop in main().
a8223e
+
a8223e
+gdb_test "start" \
a8223e
+         "main \\(\\) at .*$srcfile.*" \
a8223e
+         "start"
a8223e
+
a8223e
+set loc [gdb_get_line_number "alarm"]
a8223e
+gdb_breakpoint $loc
a8223e
+
a8223e
+proc memory_get {} {
a8223e
+    global pid
a8223e
+    set fd [open "/proc/$pid/statm"]
a8223e
+    gets $fd line
a8223e
+    close $fd
a8223e
+    # number of pages of data/stack
a8223e
+    scan $line "%*d%*d%*d%*d%*d%d" drs
a8223e
+    return $drs
a8223e
+}
a8223e
+
a8223e
+set cycles 100
a8223e
+# For 100 cycles it was 1308: from = 363 KB, to = 1671 KB
a8223e
+set permit_kb 100
a8223e
+verbose -log "cycles = $cycles, permit_kb = $permit_kb"
a8223e
+
a8223e
+set fail 0
a8223e
+set test "breakpoint stop/continue cycles"
a8223e
+for {set i $cycles} {$i > 0} {set i [expr {$i - 1}]} {
a8223e
+    gdb_test_multiple "continue" $test {
a8223e
+	-re "Breakpoint 2, main .*alarm .*.*${gdb_prompt} $" {
a8223e
+	}
a8223e
+	-re "Segmentation fault" {
a8223e
+	    fail $test
a8223e
+	    set i 0
a8223e
+	    set fail 1
a8223e
+	}
a8223e
+    }
a8223e
+    if ![info exists from] {
a8223e
+	set from [memory_get]
a8223e
+    }
a8223e
+}
a8223e
+set to [memory_get]
a8223e
+if {!$fail} {
a8223e
+    verbose -log "from = $from KB, to = $to KB"
a8223e
+    if {$from > 0 && $to > 10 && $to < $from + $permit_kb} {
a8223e
+	pass $test
a8223e
+    } else {
a8223e
+	fail $test
a8223e
+    }
a8223e
+}