|
| 1 | +# Copyright 2014 Free Software Foundation, Inc. |
| 2 | + |
| 3 | +# This program is free software; you can redistribute it and/or modify |
| 4 | +# it under the terms of the GNU General Public License as published by |
| 5 | +# the Free Software Foundation; either version 3 of the License, or |
| 6 | +# (at your option) any later version. |
| 7 | +# |
| 8 | +# This program is distributed in the hope that it will be useful, |
| 9 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | +# GNU General Public License for more details. |
| 12 | +# |
| 13 | +# You should have received a copy of the GNU General Public License |
| 14 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | + |
| 16 | +set testfile py-gdb-rhbz1007614-memleak-infpy_read_memory |
| 17 | +set srcfile ${testfile}.c |
| 18 | +set binfile [standard_output_file ${testfile}] |
| 19 | + |
| 20 | +if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } { |
| 21 | + return -1 |
| 22 | +} |
| 23 | + |
| 24 | +if { [skip_python_tests] } { continue } |
| 25 | + |
| 26 | +set pid_of_gdb [exp_pid -i [board_info host fileid]] |
| 27 | + |
| 28 | +proc memory_v_pages_get {} { |
| 29 | + global pid_of_gdb |
| 30 | + set fd [open "/proc/$pid_of_gdb/statm"] |
| 31 | + gets $fd line |
| 32 | + close $fd |
| 33 | + # number of pages of virtual memory |
| 34 | + scan $line "%d" drs |
| 35 | + return $drs |
| 36 | +} |
| 37 | + |
| 38 | +if { ![runto_main] } { |
| 39 | + untested $testfile.exp |
| 40 | + return -1 |
| 41 | +} |
| 42 | + |
| 43 | +set remote_python_file [remote_download host ${srcdir}/${subdir}/${testfile}.py] |
| 44 | + |
| 45 | +gdb_test "source ${remote_python_file}" "" |
| 46 | + |
| 47 | +gdb_test "hello-world" "" |
| 48 | + |
| 49 | +set kbytes_before [memory_v_pages_get] |
| 50 | +verbose -log "kbytes_before = $kbytes_before" |
| 51 | + |
| 52 | +gdb_test "hello-world" "" |
| 53 | + |
| 54 | +set kbytes_after [memory_v_pages_get] |
| 55 | +verbose -log "kbytes_after = $kbytes_after" |
| 56 | + |
| 57 | +set kbytes_diff [expr $kbytes_after - $kbytes_before] |
| 58 | +verbose -log "kbytes_diff = $kbytes_diff" |
| 59 | + |
| 60 | +# The value "1000" was calculated by running a few GDB sessions with this |
| 61 | +# testcase, and seeing how much (in average) the memory consumption |
| 62 | +# increased after the "hello-world" command issued above. The average |
| 63 | +# was around 500 bytes, so I chose 1000 as a high estimate. |
| 64 | +if { $kbytes_diff > 1000 } { |
| 65 | + fail "there is a memory leak on GDB (RHBZ 1007614)" |
| 66 | +} else { |
| 67 | + pass "there is not a memory leak on GDB (RHBZ 1007614)" |
| 68 | +} |
0 commit comments