binutils-gdb/gdb/testsuite/boards/simavr.exp

125 lines
3.7 KiB
Plaintext
Raw Normal View History

# Copyright 2020-2021 Free Software Foundation, Inc.
gdb/testsuite: add simavr.exp board This patch adds a board file for against a simavr target (so, for the AVR architecture). simavr, when started with option -g, runs a GDB stub on port 1234. In the current latest release (1.6), the port is hardcoded to 1234. But in master, there is the option to choose another port. So while the board file hardcodes the port today, in the future it should be possible to let the user choose a port, or automatically select a free port. It is easy enough to run, make sure you have avr-gcc/avr-g++ and simavr installed, and as usual just run: make check RUNTESTFLAGS="--target_board=simavr" The following environment variables influence the behavior of the board file: - SIMAVR_MCU: type of chip to simulate - SIMAVR_PATH: path to simavr binary (useful if you build your own simavr or for some reason it is not simply called `simavr`. As expected, there are a lot of failures. Many tests use some features not supported by such a target, and I suppose there are real GDB bugs too. But a lot also passes (including tests that actually run stuff), so this board file should still help to validate changes to the AVR architecture support. These are the results I got of running tests gdb.base/*.exp: # of expected passes 20926 # of unexpected failures 2257 # of expected failures 14 # of unknown successes 1 # of known failures 13 # of unresolved testcases 592 # of untested testcases 156 # of unsupported tests 30 # of paths in test names 3 # of duplicate test names 56 gdb/testsuite/ChangeLog: * boards/simavr.exp: New file. Change-Id: Ib7fa8c4e2e90b08b104bb9b552df37779de3bc21
2020-05-25 23:55:21 +08:00
# 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/>.
# Let the user override the path to the simavr binary with the SIMAVR_PATH
# environment variable.
if { [info exists ::env(SIMAVR_PATH)] } {
set simavr_path $::env(SIMAVR_PATH)
} else {
set simavr_path simavr
}
# Let the user override the simulated AVR chip with the SIMAVR_PATH environment
# variable.
#
# The value passed here must be supported by avr-gcc (see the -mmcu flag in the
# `AVR Options` section of the gcc(1) man page) and by simavr (see output of
# `simavr --list-cores`).
if { [info exists ::env(SIMAVR_MCU)] } {
set simavr_mcu $::env(SIMAVR_MCU)
} else {
set simavr_mcu atmega2560
}
set simavr_last_load_file ""
set simavr_spawn_id ""
set_board_info compiler avr-gcc
set_board_info c++compiler avr-g++
set_board_info cflags "-mmcu=${simavr_mcu}"
set_board_info ldflags "-mmcu=${simavr_mcu}"
set_board_info use_gdb_stub 1
set_board_info gdb_protocol "remote"
set_board_info gdb,do_reload_on_run 1
set_board_info noargs 1
set_board_info gdb,noinferiorio 1
set_board_info gdb,nofileio 1
set_board_info gdb,noresults 1
set_board_info gdb,nosignals 1
proc gdb_load { file } {
global simavr_last_load_file
global simavr_spawn_id
global simavr_mcu
global simavr_path
global gdb_prompt
if { $file == "" } {
set file $simavr_last_load_file
} else {
set simavr_last_load_file $file
}
gdb_file_cmd $file
# Close any previous simavr instance.
if { $simavr_spawn_id != "" } {
gdb/testsuite: better handle failures in simavr board, reap simavr process This patch makes a few adjustments to the simavr.exp to handle tests that error out more gracefully. I put all the changes in the same patch because right now it's in a very bad shape, so it's very painful to do small incremental adjustements. I found that with these changes, it becomes reasonably stable. For example, the gdb.base/step-over-syscall.exp test is a bit buggy (stuff for another patch...), in that it calls gdb_load (through clean_restart) with a file that doesn't exist. The gdb_load implementation in simavr.exp gets called with a file that doesn't exist, and simavr (expectedly) fails to start. When this happens, we currently leave the $simavr_spawn_id variable set. However, because the simavr process has terminated, its spawn id is closed. When the next test tries to close the previous connection to simavr, it fails to, and this error is thrown: ERROR: close: spawn id exp86 not open while executing "close -i $simavr_spawn_id" (procedure "gdb_load" line 18) invoked from within In other words, any test ran after step-over-syscall.exp will have simavr.exp's gdb_load fail on it. This patch tries to make sure that simavr.exp's gdb_load only leaves simavr_spawn_id set if everything went fine. If we couldn't start simavr, don't see the expected output, or fail to connect to it, we close the spawn id (if needed) and unset simavr_spawn_id. As an additional precaution, I added a catch around the "close the previous connection" code. Ideally, this shouldn't be necessary, but I bet there are other similar scenarios where we might try to close an already close spawn id. So I think displaying a warning is better than messing up all following tests. Also, the board never wait'ed for the simavr process, resulting in tons of zombie simavr processes hanging around. This patch adds some calls to "wait" whenever we close the connection (or realize it is already closed), which seems to fix the problem. Finally I switched a `gdb_expect` to bare `expect`, where we wait for the "listening" message from simavr. I found it necessary because gdb_expect (through remote_expect) adds a `-i <gdb spawn id> -timeout 10`. So if for some reason the GDB process has crashed in the mean time, this expect will unexpectedly error out with a `spawn id <gdb spawn id> not open`. Therefore, change `gdb_expect` to `expect` so that we only deal with simavr's spawn id here. Here are the results on TESTS="gdb.base/*.exp" before: # of expected passes 4816 # of unexpected failures 4433 # of known failures 2 # of unresolved testcases 300 # of untested testcases 143 # of unsupported tests 7 # of paths in test names 2 # of duplicate test names 10 and after: # of expected passes 21957 # of unexpected failures 1564 # of expected failures 8 # of unknown successes 1 # of known failures 31 # of unresolved testcases 532 # of untested testcases 153 # of unsupported tests 28 # of paths in test names 2 # of duplicate test names 32 I tested using simavr's current master (7c254e2081b5). gdb/testsuite/ChangeLog: * boards/simavr.exp (gdb_load): Catch errors when closing previous connection. Close connection, wait for process and unset simavr_spawn_id on failure. Change-Id: I695fc765e1c22e1d1dc0b08e0f5141244986b868
2020-06-29 22:19:43 +08:00
verbose -log "simavr: closing previous spawn id $simavr_spawn_id"
if [catch { close -i $simavr_spawn_id } != 0] {
warning "simavr: failed to close connection to previous simavr instance"
}
wait -i $simavr_spawn_id
gdb/testsuite: add simavr.exp board This patch adds a board file for against a simavr target (so, for the AVR architecture). simavr, when started with option -g, runs a GDB stub on port 1234. In the current latest release (1.6), the port is hardcoded to 1234. But in master, there is the option to choose another port. So while the board file hardcodes the port today, in the future it should be possible to let the user choose a port, or automatically select a free port. It is easy enough to run, make sure you have avr-gcc/avr-g++ and simavr installed, and as usual just run: make check RUNTESTFLAGS="--target_board=simavr" The following environment variables influence the behavior of the board file: - SIMAVR_MCU: type of chip to simulate - SIMAVR_PATH: path to simavr binary (useful if you build your own simavr or for some reason it is not simply called `simavr`. As expected, there are a lot of failures. Many tests use some features not supported by such a target, and I suppose there are real GDB bugs too. But a lot also passes (including tests that actually run stuff), so this board file should still help to validate changes to the AVR architecture support. These are the results I got of running tests gdb.base/*.exp: # of expected passes 20926 # of unexpected failures 2257 # of expected failures 14 # of unknown successes 1 # of known failures 13 # of unresolved testcases 592 # of untested testcases 156 # of unsupported tests 30 # of paths in test names 3 # of duplicate test names 56 gdb/testsuite/ChangeLog: * boards/simavr.exp: New file. Change-Id: Ib7fa8c4e2e90b08b104bb9b552df37779de3bc21
2020-05-25 23:55:21 +08:00
set simavr_spawn_id ""
}
# Run simavr.
set cmd "spawn -noecho ${simavr_path} --mcu ${simavr_mcu} -g $file"
verbose -log "Spawning simavr: $cmd"
eval $cmd
set simavr_spawn_id $spawn_id
gdb/testsuite: better handle failures in simavr board, reap simavr process This patch makes a few adjustments to the simavr.exp to handle tests that error out more gracefully. I put all the changes in the same patch because right now it's in a very bad shape, so it's very painful to do small incremental adjustements. I found that with these changes, it becomes reasonably stable. For example, the gdb.base/step-over-syscall.exp test is a bit buggy (stuff for another patch...), in that it calls gdb_load (through clean_restart) with a file that doesn't exist. The gdb_load implementation in simavr.exp gets called with a file that doesn't exist, and simavr (expectedly) fails to start. When this happens, we currently leave the $simavr_spawn_id variable set. However, because the simavr process has terminated, its spawn id is closed. When the next test tries to close the previous connection to simavr, it fails to, and this error is thrown: ERROR: close: spawn id exp86 not open while executing "close -i $simavr_spawn_id" (procedure "gdb_load" line 18) invoked from within In other words, any test ran after step-over-syscall.exp will have simavr.exp's gdb_load fail on it. This patch tries to make sure that simavr.exp's gdb_load only leaves simavr_spawn_id set if everything went fine. If we couldn't start simavr, don't see the expected output, or fail to connect to it, we close the spawn id (if needed) and unset simavr_spawn_id. As an additional precaution, I added a catch around the "close the previous connection" code. Ideally, this shouldn't be necessary, but I bet there are other similar scenarios where we might try to close an already close spawn id. So I think displaying a warning is better than messing up all following tests. Also, the board never wait'ed for the simavr process, resulting in tons of zombie simavr processes hanging around. This patch adds some calls to "wait" whenever we close the connection (or realize it is already closed), which seems to fix the problem. Finally I switched a `gdb_expect` to bare `expect`, where we wait for the "listening" message from simavr. I found it necessary because gdb_expect (through remote_expect) adds a `-i <gdb spawn id> -timeout 10`. So if for some reason the GDB process has crashed in the mean time, this expect will unexpectedly error out with a `spawn id <gdb spawn id> not open`. Therefore, change `gdb_expect` to `expect` so that we only deal with simavr's spawn id here. Here are the results on TESTS="gdb.base/*.exp" before: # of expected passes 4816 # of unexpected failures 4433 # of known failures 2 # of unresolved testcases 300 # of untested testcases 143 # of unsupported tests 7 # of paths in test names 2 # of duplicate test names 10 and after: # of expected passes 21957 # of unexpected failures 1564 # of expected failures 8 # of unknown successes 1 # of known failures 31 # of unresolved testcases 532 # of untested testcases 153 # of unsupported tests 28 # of paths in test names 2 # of duplicate test names 32 I tested using simavr's current master (7c254e2081b5). gdb/testsuite/ChangeLog: * boards/simavr.exp (gdb_load): Catch errors when closing previous connection. Close connection, wait for process and unset simavr_spawn_id on failure. Change-Id: I695fc765e1c22e1d1dc0b08e0f5141244986b868
2020-06-29 22:19:43 +08:00
verbose -log "simavr: simavr spawned with spawn id $simavr_spawn_id, pid [exp_pid $simavr_spawn_id]"
# Wait for "listening on port" message of simavr.
expect {
gdb/testsuite: add simavr.exp board This patch adds a board file for against a simavr target (so, for the AVR architecture). simavr, when started with option -g, runs a GDB stub on port 1234. In the current latest release (1.6), the port is hardcoded to 1234. But in master, there is the option to choose another port. So while the board file hardcodes the port today, in the future it should be possible to let the user choose a port, or automatically select a free port. It is easy enough to run, make sure you have avr-gcc/avr-g++ and simavr installed, and as usual just run: make check RUNTESTFLAGS="--target_board=simavr" The following environment variables influence the behavior of the board file: - SIMAVR_MCU: type of chip to simulate - SIMAVR_PATH: path to simavr binary (useful if you build your own simavr or for some reason it is not simply called `simavr`. As expected, there are a lot of failures. Many tests use some features not supported by such a target, and I suppose there are real GDB bugs too. But a lot also passes (including tests that actually run stuff), so this board file should still help to validate changes to the AVR architecture support. These are the results I got of running tests gdb.base/*.exp: # of expected passes 20926 # of unexpected failures 2257 # of expected failures 14 # of unknown successes 1 # of known failures 13 # of unresolved testcases 592 # of untested testcases 156 # of unsupported tests 30 # of paths in test names 3 # of duplicate test names 56 gdb/testsuite/ChangeLog: * boards/simavr.exp: New file. Change-Id: Ib7fa8c4e2e90b08b104bb9b552df37779de3bc21
2020-05-25 23:55:21 +08:00
-i $simavr_spawn_id -re ".*avr_gdb_init listening on port 1234" {}
gdb/testsuite: better handle failures in simavr board, reap simavr process This patch makes a few adjustments to the simavr.exp to handle tests that error out more gracefully. I put all the changes in the same patch because right now it's in a very bad shape, so it's very painful to do small incremental adjustements. I found that with these changes, it becomes reasonably stable. For example, the gdb.base/step-over-syscall.exp test is a bit buggy (stuff for another patch...), in that it calls gdb_load (through clean_restart) with a file that doesn't exist. The gdb_load implementation in simavr.exp gets called with a file that doesn't exist, and simavr (expectedly) fails to start. When this happens, we currently leave the $simavr_spawn_id variable set. However, because the simavr process has terminated, its spawn id is closed. When the next test tries to close the previous connection to simavr, it fails to, and this error is thrown: ERROR: close: spawn id exp86 not open while executing "close -i $simavr_spawn_id" (procedure "gdb_load" line 18) invoked from within In other words, any test ran after step-over-syscall.exp will have simavr.exp's gdb_load fail on it. This patch tries to make sure that simavr.exp's gdb_load only leaves simavr_spawn_id set if everything went fine. If we couldn't start simavr, don't see the expected output, or fail to connect to it, we close the spawn id (if needed) and unset simavr_spawn_id. As an additional precaution, I added a catch around the "close the previous connection" code. Ideally, this shouldn't be necessary, but I bet there are other similar scenarios where we might try to close an already close spawn id. So I think displaying a warning is better than messing up all following tests. Also, the board never wait'ed for the simavr process, resulting in tons of zombie simavr processes hanging around. This patch adds some calls to "wait" whenever we close the connection (or realize it is already closed), which seems to fix the problem. Finally I switched a `gdb_expect` to bare `expect`, where we wait for the "listening" message from simavr. I found it necessary because gdb_expect (through remote_expect) adds a `-i <gdb spawn id> -timeout 10`. So if for some reason the GDB process has crashed in the mean time, this expect will unexpectedly error out with a `spawn id <gdb spawn id> not open`. Therefore, change `gdb_expect` to `expect` so that we only deal with simavr's spawn id here. Here are the results on TESTS="gdb.base/*.exp" before: # of expected passes 4816 # of unexpected failures 4433 # of known failures 2 # of unresolved testcases 300 # of untested testcases 143 # of unsupported tests 7 # of paths in test names 2 # of duplicate test names 10 and after: # of expected passes 21957 # of unexpected failures 1564 # of expected failures 8 # of unknown successes 1 # of known failures 31 # of unresolved testcases 532 # of untested testcases 153 # of unsupported tests 28 # of paths in test names 2 # of duplicate test names 32 I tested using simavr's current master (7c254e2081b5). gdb/testsuite/ChangeLog: * boards/simavr.exp (gdb_load): Catch errors when closing previous connection. Close connection, wait for process and unset simavr_spawn_id on failure. Change-Id: I695fc765e1c22e1d1dc0b08e0f5141244986b868
2020-06-29 22:19:43 +08:00
timeout {
verbose -log "simavr: timeout, closing simavr spawn id"
close -i $simavr_spawn_id
verbose -log "simavr: timeout, waiting for simavr process exit"
wait -i $simavr_spawn_id
set simavr_spawn_id ""
error "unable to start simavr: timeout"
}
eof {
verbose -log "simavr: eof, waiting for simavr process exit"
wait -i $simavr_spawn_id
set simavr_spawn_id ""
error "unable to start simavr: eof"
}
gdb/testsuite: add simavr.exp board This patch adds a board file for against a simavr target (so, for the AVR architecture). simavr, when started with option -g, runs a GDB stub on port 1234. In the current latest release (1.6), the port is hardcoded to 1234. But in master, there is the option to choose another port. So while the board file hardcodes the port today, in the future it should be possible to let the user choose a port, or automatically select a free port. It is easy enough to run, make sure you have avr-gcc/avr-g++ and simavr installed, and as usual just run: make check RUNTESTFLAGS="--target_board=simavr" The following environment variables influence the behavior of the board file: - SIMAVR_MCU: type of chip to simulate - SIMAVR_PATH: path to simavr binary (useful if you build your own simavr or for some reason it is not simply called `simavr`. As expected, there are a lot of failures. Many tests use some features not supported by such a target, and I suppose there are real GDB bugs too. But a lot also passes (including tests that actually run stuff), so this board file should still help to validate changes to the AVR architecture support. These are the results I got of running tests gdb.base/*.exp: # of expected passes 20926 # of unexpected failures 2257 # of expected failures 14 # of unknown successes 1 # of known failures 13 # of unresolved testcases 592 # of untested testcases 156 # of unsupported tests 30 # of paths in test names 3 # of duplicate test names 56 gdb/testsuite/ChangeLog: * boards/simavr.exp: New file. Change-Id: Ib7fa8c4e2e90b08b104bb9b552df37779de3bc21
2020-05-25 23:55:21 +08:00
}
# Connect to simavr.
send_gdb "target remote :1234\n"
gdb_expect {
-re ".*Remote debugging using :1234.*\[\r\n\]+$gdb_prompt $" {}
gdb/testsuite: better handle failures in simavr board, reap simavr process This patch makes a few adjustments to the simavr.exp to handle tests that error out more gracefully. I put all the changes in the same patch because right now it's in a very bad shape, so it's very painful to do small incremental adjustements. I found that with these changes, it becomes reasonably stable. For example, the gdb.base/step-over-syscall.exp test is a bit buggy (stuff for another patch...), in that it calls gdb_load (through clean_restart) with a file that doesn't exist. The gdb_load implementation in simavr.exp gets called with a file that doesn't exist, and simavr (expectedly) fails to start. When this happens, we currently leave the $simavr_spawn_id variable set. However, because the simavr process has terminated, its spawn id is closed. When the next test tries to close the previous connection to simavr, it fails to, and this error is thrown: ERROR: close: spawn id exp86 not open while executing "close -i $simavr_spawn_id" (procedure "gdb_load" line 18) invoked from within In other words, any test ran after step-over-syscall.exp will have simavr.exp's gdb_load fail on it. This patch tries to make sure that simavr.exp's gdb_load only leaves simavr_spawn_id set if everything went fine. If we couldn't start simavr, don't see the expected output, or fail to connect to it, we close the spawn id (if needed) and unset simavr_spawn_id. As an additional precaution, I added a catch around the "close the previous connection" code. Ideally, this shouldn't be necessary, but I bet there are other similar scenarios where we might try to close an already close spawn id. So I think displaying a warning is better than messing up all following tests. Also, the board never wait'ed for the simavr process, resulting in tons of zombie simavr processes hanging around. This patch adds some calls to "wait" whenever we close the connection (or realize it is already closed), which seems to fix the problem. Finally I switched a `gdb_expect` to bare `expect`, where we wait for the "listening" message from simavr. I found it necessary because gdb_expect (through remote_expect) adds a `-i <gdb spawn id> -timeout 10`. So if for some reason the GDB process has crashed in the mean time, this expect will unexpectedly error out with a `spawn id <gdb spawn id> not open`. Therefore, change `gdb_expect` to `expect` so that we only deal with simavr's spawn id here. Here are the results on TESTS="gdb.base/*.exp" before: # of expected passes 4816 # of unexpected failures 4433 # of known failures 2 # of unresolved testcases 300 # of untested testcases 143 # of unsupported tests 7 # of paths in test names 2 # of duplicate test names 10 and after: # of expected passes 21957 # of unexpected failures 1564 # of expected failures 8 # of unknown successes 1 # of known failures 31 # of unresolved testcases 532 # of untested testcases 153 # of unsupported tests 28 # of paths in test names 2 # of duplicate test names 32 I tested using simavr's current master (7c254e2081b5). gdb/testsuite/ChangeLog: * boards/simavr.exp (gdb_load): Catch errors when closing previous connection. Close connection, wait for process and unset simavr_spawn_id on failure. Change-Id: I695fc765e1c22e1d1dc0b08e0f5141244986b868
2020-06-29 22:19:43 +08:00
timeout {
verbose -log "simavr: unable to connect to simavr, closing simavr spawn id"
close -i $simavr_spawn_id
verbose -log "simavr: unable to connect to simavr, waiting for simavr process exit"
wait -i $simavr_spawn_id
set simavr_spawn_id ""
error "unable to connect to simavr stub"
}
gdb/testsuite: add simavr.exp board This patch adds a board file for against a simavr target (so, for the AVR architecture). simavr, when started with option -g, runs a GDB stub on port 1234. In the current latest release (1.6), the port is hardcoded to 1234. But in master, there is the option to choose another port. So while the board file hardcodes the port today, in the future it should be possible to let the user choose a port, or automatically select a free port. It is easy enough to run, make sure you have avr-gcc/avr-g++ and simavr installed, and as usual just run: make check RUNTESTFLAGS="--target_board=simavr" The following environment variables influence the behavior of the board file: - SIMAVR_MCU: type of chip to simulate - SIMAVR_PATH: path to simavr binary (useful if you build your own simavr or for some reason it is not simply called `simavr`. As expected, there are a lot of failures. Many tests use some features not supported by such a target, and I suppose there are real GDB bugs too. But a lot also passes (including tests that actually run stuff), so this board file should still help to validate changes to the AVR architecture support. These are the results I got of running tests gdb.base/*.exp: # of expected passes 20926 # of unexpected failures 2257 # of expected failures 14 # of unknown successes 1 # of known failures 13 # of unresolved testcases 592 # of untested testcases 156 # of unsupported tests 30 # of paths in test names 3 # of duplicate test names 56 gdb/testsuite/ChangeLog: * boards/simavr.exp: New file. Change-Id: Ib7fa8c4e2e90b08b104bb9b552df37779de3bc21
2020-05-25 23:55:21 +08:00
}
return 0
}