print-threads.exp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # Copyright (C) 1996-2022 Free Software Foundation, Inc.
  2. # This program is free software; you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation; either version 3 of the License, or
  5. # (at your option) any later version.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. # This file was written by Daniel Jacobowitz <drow@mvista.com>
  15. # (parts based on pthreads.exp by Fred Fish (fnf@cygnus.com).
  16. #
  17. # It tests miscellaneous actions with multiple threads, including
  18. # handling for thread exit.
  19. standard_testfile
  20. # regexp for "horizontal" text (i.e. doesn't include newline or
  21. # carriage return)
  22. set horiz "\[^\n\r\]*"
  23. if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable debug] != "" } {
  24. return -1
  25. }
  26. # Now we can proceed with the real testing.
  27. clean_restart ${binfile}
  28. gdb_test_no_output "set print sevenbit-strings"
  29. #gdb_test_no_output "set print address off"
  30. gdb_test_no_output "set width 0"
  31. # We'll need this when we send_gdb a ^C to GDB. Need to do it before we
  32. # run the program and gdb starts saving and restoring tty states.
  33. gdb_test "shell stty intr '^C'" ".*"
  34. proc test_all_threads { name kill } {
  35. global gdb_prompt inferior_exited_re
  36. with_test_prefix $name {
  37. set i 0
  38. set j 0
  39. gdb_test_multiple "continue" "all threads ran once" {
  40. -re "Breakpoint \[0-9\]+, thread_function \\(arg=.*\\) at .*print-threads.c:\[0-9\]+.*$gdb_prompt" {
  41. set i [expr $i + 1]
  42. pass "hit thread_function breakpoint, $i"
  43. send_gdb "continue\n"
  44. exp_continue
  45. }
  46. -re "Breakpoint \[0-9\]+, .* kill \\(.*\\) .*$gdb_prompt" {
  47. set j [expr $j + 1]
  48. if { $kill == 1 } {
  49. pass "hit kill breakpoint, $j"
  50. } else {
  51. fail "hit kill breakpoint, $j (unexpected)"
  52. }
  53. send_gdb "continue\n"
  54. exp_continue
  55. }
  56. -re "$inferior_exited_re normally.\[\r\n\]+$gdb_prompt" {
  57. pass "program exited normally"
  58. if {$i == 5} {
  59. pass "all threads ran once"
  60. } else {
  61. fail "all threads ran once (total $i threads ran)"
  62. }
  63. }
  64. -re " received signal SIGTRAP.*(Thread \[-0-9a-fx\]* \\(zombie\\)|0x00000000 in ).*$gdb_prompt $" {
  65. if { $kill == 1 } {
  66. kfail "gdb/1265" "Running threads (zombie thread)"
  67. } else {
  68. fail "running threads (unknown output)"
  69. }
  70. }
  71. }
  72. }
  73. }
  74. # Record the old timeout, we need to extend it for slower tests.
  75. set oldtimeout $timeout
  76. runto_main
  77. gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\."
  78. gdb_test_no_output "set var slow = 0"
  79. test_all_threads "fast" 0
  80. runto_main
  81. gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\." "break thread_function (2)"
  82. gdb_test_no_output "set var slow = 1"
  83. # Extend the timeout for slower tests.
  84. set timeout [expr $oldtimeout + 120]
  85. test_all_threads "slow" 0
  86. set timeout $oldtimeout
  87. runto_main
  88. gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\." "break thread_function (3)"
  89. gdb_test_no_output "set var slow = 1" "set var slow = 1 (2)"
  90. gdb_breakpoint "kill"
  91. # Extend the timeout for slower tests.
  92. set timeout [expr $oldtimeout + 120]
  93. test_all_threads "slow with kill breakpoint" 1
  94. set timeout $oldtimeout
  95. return 0