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

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