# This proc restarts GDB, runs the inferior with the desired
# amount of memory, then checks how much memory is necessary
# to run the gcore command. It will return -1 if the gcore
-# command fails, 0 otherwise.
-proc run_test {megs} {
+# command fails, otherwise the amount of memory used by GDB
+# to generate that gcore. MAX_MEM is the maximum amount of
+# memory GDB is allowed to use, in megabytes.
+proc run_test {megs max_mem} {
with_test_prefix "$megs Mb" {
clean_restart $::testfile
set diff_k [expr $mem_after - $mem_before]
set diff [expr $diff_k/1024]
verbose -log "The gcore command used $diff Mb ($diff_k Kb)"
- # The original plan was to compare to a multiple of MEGS
- # but since the requirements don't seem to go up as the
- # inferior allocated more memory, we instead just hardcode
- # 2 megs, since sometimes 1 is used.
- gdb_assert {$diff < 2} "gdb did not use too much memory"
+ gdb_assert {$diff <= $max_mem} "gdb did not use too much memory"
gdb_test_no_output "set spin=0" "Allow program to exit"
}
- return 0
+ return $diff
}
# If we couldn't create the first corefile, there's no point
-# in running the second part of the test.
-if {[run_test 4] != 0} {
+# in running the second part of the test. The maximum amount
+# of memory allowed is the same as the memory used by the
+# inferior.
+set mem_limit [run_test 4 4]
+if {$mem_limit < 0} {
return
}
# Surprisingly enough, the larger inferior doesn't seem to use
# any extra memory, it usually uses less memory. Which is good,
# it means our memory requirements aren't growing with the inferior.
-run_test 64
+# This test ensures that it remains true that a larger inferior will
+# not grow the memory requirements.
+run_test 64 $mem_limit