Files
binutils-gdb/gdb/testsuite/gdb.python/py-read-memory-leak.exp
Andrew Burgess 93c145c2aa gdb/python: restructure the existing memory leak tests
We currently have two memory leak tests in gdb.python/ and there's a
lot of duplication between these two.

In the next commit I'd like to add yet another memory leak test, which
would mean a third set of scripts which duplicate the existing two.
And three is where I draw the line.

This commit factors out the core of the memory leak tests into a new
module gdb_leak_detector.py, which can then be imported by each
tests's Python file in order to make writing the memory leak tests
easier.

I've also added a helper function to lib/gdb-python.exp which captures
some of the common steps needed in the TCL file in order to run a
memory leak test.

Finally, I use this new infrastructure to rewrite the two existing
memory leak tests.

What I considered, but ultimately didn't do, is merge the two memory
leak tests into a single TCL script.  I did consider this, and for the
existing tests this would be possible, but future tests might require
different enough setup that this might not be possible for all future
tests, and now that we have helper functions in a central location,
the each individual test is actually pretty small now, so leaving them
separate seemed OK.

There should be no change in what is actually being tested after this
commit.

Approved-By: Tom Tromey <tom@tromey.com>
2025-04-22 17:21:58 +01:00

35 lines
1.1 KiB
Plaintext

# Copyright (C) 2024-2025 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This file is part of the GDB testsuite. It checks for memory leaks
# associated with calling gdb.Inferior.read_memory().
load_lib gdb-python.exp
require allow_python_tests
standard_testfile
if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
return -1
}
if ![runto_main] {
return -1
}
gdb_py_run_memory_leak_test ${srcdir}/${subdir}/${testfile}.py \
"buffers returned by read_memory() deallocates correctly"