[PATCH] sigall.exp and friends: centralize signals list.

Pedro Alves
2012-07-19T14:35:56Z

I was doing a fix to gdb.reverse/sigall-precsave.exp that requires
adding code that does something once for each signal the tested
program generates. I thought that putting the signals list into a tcl
list and add another walk over the list would be better than following
the trend of adding a bunch of similar calls in a sequence, once per
each signal. This patch just does the refactoring to add a list and
use it, without changing anything else.

Tested x86_64 Fedora 17, and applied.

2012-07-19 Pedro Alves <palves@redhat.com>

* gdb.base/sigall.exp (signals): New list.
<top level>: Loop over signals in the $signals list instead of
calling a test function once per signal.
* gdb.reverse/sigall-precsave.exp (signals): New list.
<top level>: Loop over signals in the $signals list instead of
calling a test function once per signal.
* gdb.reverse/sigall-reverse.exp (signals): New list.
<top level>: Loop over signals in the $signals list instead of
calling a test function once per signal.
---
gdb/testsuite/gdb.base/sigall.exp | 164 +++++++------
gdb/testsuite/gdb.reverse/sigall-precsave.exp | 316 ++++++++-----------------
gdb/testsuite/gdb.reverse/sigall-reverse.exp | 317 ++++++++-----------------
3 files changed, 293 insertions(+), 504 deletions(-)

diff --git a/gdb/testsuite/gdb.base/sigall.exp b/gdb/testsuite/gdb.base/sigall.exp
index 1f2bab7..7963504 100644
--- a/gdb/testsuite/gdb.base/sigall.exp
+++ b/gdb/testsuite/gdb.base/sigall.exp
@@ -31,10 +31,6 @@ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {deb
return -1
}

-# Make the first signal SIGABRT because it is always supported.
-set sig_supported 1
-set thissig "ABRT"
-
proc test_one_sig {nextsig} {
global sig_supported
global gdb_prompt
@@ -104,77 +100,97 @@ proc test_one_sig {nextsig} {

gdb_load $binfile

+# The list of signals that the program generates, in the order they
+# are generated.
+set signals {
+ ABRT
+ HUP
+ QUIT
+ ILL
+ EMT
+ FPE
+ BUS
+ SEGV
+ SYS
+ PIPE
+ ALRM
+ URG
+ TSTP
+ CONT
+ CHLD
+ TTIN
+ TTOU
+ IO
+ XCPU
+ XFSZ
+ VTALRM
+ PROF
+ WINCH
+ LOST
+ USR1
+ USR2
+ PWR
+ POLL
+ WIND
+ PHONE
+ WAITING
+ LWP
+ DANGER
+ GRANT
+ RETRACT
+ MSG
+ SOUND
+ SAK
+ PRIO
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ TERM
+}
+
+# Make the first signal SIGABRT because it is always supported.
+set sig_supported 1
+set thissig "ABRT"
+
runto gen_ABRT
-test_one_sig HUP
-test_one_sig QUIT
-test_one_sig ILL
-test_one_sig EMT
-test_one_sig FPE
-test_one_sig BUS
-test_one_sig SEGV
-test_one_sig SYS
-test_one_sig PIPE
-test_one_sig ALRM
-test_one_sig URG
-test_one_sig TSTP
-test_one_sig CONT
-test_one_sig CHLD
-test_one_sig TTIN
-test_one_sig TTOU
-test_one_sig IO
-test_one_sig XCPU
-test_one_sig XFSZ
-test_one_sig VTALRM
-test_one_sig PROF
-test_one_sig WINCH
-test_one_sig LOST
-test_one_sig USR1
-test_one_sig USR2
-test_one_sig PWR
-test_one_sig POLL
-test_one_sig WIND
-test_one_sig PHONE
-test_one_sig WAITING
-test_one_sig LWP
-test_one_sig DANGER
-test_one_sig GRANT
-test_one_sig RETRACT
-test_one_sig MSG
-test_one_sig SOUND
-test_one_sig SAK
-test_one_sig PRIO
-test_one_sig 33
-test_one_sig 34
-test_one_sig 35
-test_one_sig 36
-test_one_sig 37
-test_one_sig 38
-test_one_sig 39
-test_one_sig 40
-test_one_sig 41
-test_one_sig 42
-test_one_sig 43
-test_one_sig 44
-test_one_sig 45
-test_one_sig 46
-test_one_sig 47
-test_one_sig 48
-test_one_sig 49
-test_one_sig 50
-test_one_sig 51
-test_one_sig 52
-test_one_sig 53
-test_one_sig 54
-test_one_sig 55
-test_one_sig 56
-test_one_sig 57
-test_one_sig 58
-test_one_sig 59
-test_one_sig 60
-test_one_sig 61
-test_one_sig 62
-test_one_sig 63
-test_one_sig TERM
+
+for {set i 0;} {$i < [llength $signals]} {incr i;} {
+ # Skip the first.
+ if { $i == 0 } {
+ continue
+ }
+
+ set sig [lindex $signals $i]
+ test_one_sig $sig
+}

# The last signal (SIGTERM) gets handled slightly differently because
# we are not setting up for another test.
diff --git a/gdb/testsuite/gdb.reverse/sigall-precsave.exp b/gdb/testsuite/gdb.reverse/sigall-precsave.exp
index 465e3cc..e2dabf9 100644
--- a/gdb/testsuite/gdb.reverse/sigall-precsave.exp
+++ b/gdb/testsuite/gdb.reverse/sigall-precsave.exp
@@ -34,10 +34,6 @@ if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} {
return -1
}

-# Make the first signal SIGABRT because it is always supported.
-set sig_supported 1
-set thissig "ABRT"
-
proc test_one_sig {nextsig} {
global sig_supported
global gdb_prompt
@@ -182,6 +178,82 @@ gdb_test "break $breakloc" \
# Signal handlers must be disabled
gdb_test "handle all nostop noprint"

+# The list of signals that the program generates, in the order they
+# are generated.
+set signals {
+ ABRT
+ HUP
+ QUIT
+ ILL
+ EMT
+ FPE
+ BUS
+ SEGV
+ SYS
+ PIPE
+ ALRM
+ URG
+ TSTP
+ CONT
+ CHLD
+ TTIN
+ TTOU
+ IO
+ XCPU
+ XFSZ
+ VTALRM
+ PROF
+ WINCH
+ LOST
+ USR1
+ USR2
+ PWR
+ POLL
+ WIND
+ PHONE
+ WAITING
+ LWP
+ DANGER
+ GRANT
+ RETRACT
+ MSG
+ SOUND
+ SAK
+ PRIO
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ TERM
+}
+
gdb_test "continue" "Breakpoint .* end of main .*" "run to end of main"

gdb_test "record save $precsave" \
@@ -198,77 +270,20 @@ gdb_test "record restore $precsave" \
# Signal handlers must be re-enabled
gdb_test "handle all stop print"

+# Make the first signal SIGABRT because it is always supported.
+set sig_supported 1
+set thissig "ABRT"
+
# test signal handling
-test_one_sig HUP
-test_one_sig QUIT
-test_one_sig ILL
-test_one_sig EMT
-test_one_sig FPE
-test_one_sig BUS
-test_one_sig SEGV
-test_one_sig SYS
-test_one_sig PIPE
-test_one_sig ALRM
-test_one_sig URG
-test_one_sig TSTP
-test_one_sig CONT
-test_one_sig CHLD
-test_one_sig TTIN
-test_one_sig TTOU
-test_one_sig IO
-test_one_sig XCPU
-test_one_sig XFSZ
-test_one_sig VTALRM
-test_one_sig PROF
-test_one_sig WINCH
-test_one_sig LOST
-test_one_sig USR1
-test_one_sig USR2
-test_one_sig PWR
-test_one_sig POLL
-test_one_sig WIND
-test_one_sig PHONE
-test_one_sig WAITING
-test_one_sig LWP
-test_one_sig DANGER
-test_one_sig GRANT
-test_one_sig RETRACT
-test_one_sig MSG
-test_one_sig SOUND
-test_one_sig SAK
-test_one_sig PRIO
-test_one_sig 33
-test_one_sig 34
-test_one_sig 35
-test_one_sig 36
-test_one_sig 37
-test_one_sig 38
-test_one_sig 39
-test_one_sig 40
-test_one_sig 41
-test_one_sig 42
-test_one_sig 43
-test_one_sig 44
-test_one_sig 45
-test_one_sig 46
-test_one_sig 47
-test_one_sig 48
-test_one_sig 49
-test_one_sig 50
-test_one_sig 51
-test_one_sig 52
-test_one_sig 53
-test_one_sig 54
-test_one_sig 55
-test_one_sig 56
-test_one_sig 57
-test_one_sig 58
-test_one_sig 59
-test_one_sig 60
-test_one_sig 61
-test_one_sig 62
-test_one_sig 63
-test_one_sig TERM
+for {set i 0;} {$i < [llength $signals]} {incr i;} {
+ # Skip the first.
+ if { $i == 0 } {
+ continue
+ }
+
+ set sig [lindex $signals $i]
+ test_one_sig $sig
+}

# The last signal (SIGTERM) gets handled slightly differently because
# we are not setting up for another test.
@@ -282,149 +297,20 @@ gdb_test "continue" "Breakpoint.*handle_TERM.*" "send signal TERM"

gdb_test "continue" " end of main .*" "continue to sigall exit"

-test_one_sig_reverse TERM
-test_one_sig_reverse 63
-test_one_sig_reverse 62
-test_one_sig_reverse 61
-test_one_sig_reverse 60
-test_one_sig_reverse 59
-test_one_sig_reverse 58
-test_one_sig_reverse 57
-test_one_sig_reverse 56
-test_one_sig_reverse 55
-test_one_sig_reverse 54
-test_one_sig_reverse 53
-test_one_sig_reverse 52
-test_one_sig_reverse 51
-test_one_sig_reverse 50
-test_one_sig_reverse 49
-test_one_sig_reverse 48
-test_one_sig_reverse 47
-test_one_sig_reverse 46
-test_one_sig_reverse 45
-test_one_sig_reverse 44
-test_one_sig_reverse 43
-test_one_sig_reverse 42
-test_one_sig_reverse 41
-test_one_sig_reverse 40
-test_one_sig_reverse 39
-test_one_sig_reverse 38
-test_one_sig_reverse 37
-test_one_sig_reverse 36
-test_one_sig_reverse 35
-test_one_sig_reverse 34
-test_one_sig_reverse 33
-test_one_sig_reverse PRIO
-test_one_sig_reverse SAK
-test_one_sig_reverse SOUND
-test_one_sig_reverse MSG
-test_one_sig_reverse RETRACT
-test_one_sig_reverse GRANT
-test_one_sig_reverse DANGER
-test_one_sig_reverse LWP
-test_one_sig_reverse WAITING
-test_one_sig_reverse PHONE
-test_one_sig_reverse WIND
-test_one_sig_reverse POLL
-test_one_sig_reverse PWR
-test_one_sig_reverse USR2
-test_one_sig_reverse USR1
-test_one_sig_reverse LOST
-test_one_sig_reverse WINCH
-test_one_sig_reverse PROF
-test_one_sig_reverse VTALRM
-test_one_sig_reverse XFSZ
-test_one_sig_reverse XCPU
-test_one_sig_reverse IO
-test_one_sig_reverse TTOU
-test_one_sig_reverse TTIN
-test_one_sig_reverse CHLD
-test_one_sig_reverse CONT
-test_one_sig_reverse TSTP
-test_one_sig_reverse URG
-test_one_sig_reverse ALRM
-test_one_sig_reverse PIPE
-test_one_sig_reverse SYS
-test_one_sig_reverse SEGV
-test_one_sig_reverse BUS
-test_one_sig_reverse FPE
-test_one_sig_reverse EMT
-test_one_sig_reverse ILL
-test_one_sig_reverse QUIT
-test_one_sig_reverse HUP
-test_one_sig_reverse ABRT
+foreach sig [lreverse $signals] {
+ test_one_sig_reverse $sig
+}

# Make the first signal SIGABRT because it is always supported.
set sig_supported 1
set thissig "ABRT"

-test_one_sig HUP
-test_one_sig QUIT
-test_one_sig ILL
-test_one_sig EMT
-test_one_sig FPE
-test_one_sig BUS
-test_one_sig SEGV
-test_one_sig SYS
-test_one_sig PIPE
-test_one_sig ALRM
-test_one_sig URG
-test_one_sig TSTP
-test_one_sig CONT
-test_one_sig CHLD
-test_one_sig TTIN
-test_one_sig TTOU
-test_one_sig IO
-test_one_sig XCPU
-test_one_sig XFSZ
-test_one_sig VTALRM
-test_one_sig PROF
-test_one_sig WINCH
-test_one_sig LOST
-test_one_sig USR1
-test_one_sig USR2
-test_one_sig PWR
-test_one_sig POLL
-test_one_sig WIND
-test_one_sig PHONE
-test_one_sig WAITING
-test_one_sig LWP
-test_one_sig DANGER
-test_one_sig GRANT
-test_one_sig RETRACT
-test_one_sig MSG
-test_one_sig SOUND
-test_one_sig SAK
-test_one_sig PRIO
-test_one_sig 33
-test_one_sig 34
-test_one_sig 35
-test_one_sig 36
-test_one_sig 37
-test_one_sig 38
-test_one_sig 39
-test_one_sig 40
-test_one_sig 41
-test_one_sig 42
-test_one_sig 43
-test_one_sig 44
-test_one_sig 45
-test_one_sig 46
-test_one_sig 47
-test_one_sig 48
-test_one_sig 49
-test_one_sig 50
-test_one_sig 51
-test_one_sig 52
-test_one_sig 53
-test_one_sig 54
-test_one_sig 55
-test_one_sig 56
-test_one_sig 57
-test_one_sig 58
-test_one_sig 59
-test_one_sig 60
-test_one_sig 61
-test_one_sig 62
-test_one_sig 63
-test_one_sig TERM
+for {set i 0;} {$i < [llength $signals]} {incr i;} {
+ # Skip the first.
+ if { $i == 0 } {
+ continue
+ }
+
+ set sig [lindex $signals $i]
+ test_one_sig $sig
+}
diff --git a/gdb/testsuite/gdb.reverse/sigall-reverse.exp b/gdb/testsuite/gdb.reverse/sigall-reverse.exp
index 598e5d4..f5bbe1e 100644
--- a/gdb/testsuite/gdb.reverse/sigall-reverse.exp
+++ b/gdb/testsuite/gdb.reverse/sigall-reverse.exp
@@ -33,10 +33,6 @@ if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} {
return -1
}

-# Make the first signal SIGABRT because it is always supported.
-set sig_supported 1
-set thissig "ABRT"
-
proc test_one_sig {nextsig} {
global sig_supported
global gdb_prompt
@@ -171,76 +167,96 @@ if [supports_process_record] {
gdb_test_no_output "record" "Turn on process record"
}

-test_one_sig HUP
-test_one_sig QUIT
-test_one_sig ILL
-test_one_sig EMT
-test_one_sig FPE
-test_one_sig BUS
-test_one_sig SEGV
-test_one_sig SYS
-test_one_sig PIPE
-test_one_sig ALRM
-test_one_sig URG
-test_one_sig TSTP
-test_one_sig CONT
-test_one_sig CHLD
-test_one_sig TTIN
-test_one_sig TTOU
-test_one_sig IO
-test_one_sig XCPU
-test_one_sig XFSZ
-test_one_sig VTALRM
-test_one_sig PROF
-test_one_sig WINCH
-test_one_sig LOST
-test_one_sig USR1
-test_one_sig USR2
-test_one_sig PWR
-test_one_sig POLL
-test_one_sig WIND
-test_one_sig PHONE
-test_one_sig WAITING
-test_one_sig LWP
-test_one_sig DANGER
-test_one_sig GRANT
-test_one_sig RETRACT
-test_one_sig MSG
-test_one_sig SOUND
-test_one_sig SAK
-test_one_sig PRIO
-test_one_sig 33
-test_one_sig 34
-test_one_sig 35
-test_one_sig 36
-test_one_sig 37
-test_one_sig 38
-test_one_sig 39
-test_one_sig 40
-test_one_sig 41
-test_one_sig 42
-test_one_sig 43
-test_one_sig 44
-test_one_sig 45
-test_one_sig 46
-test_one_sig 47
-test_one_sig 48
-test_one_sig 49
-test_one_sig 50
-test_one_sig 51
-test_one_sig 52
-test_one_sig 53
-test_one_sig 54
-test_one_sig 55
-test_one_sig 56
-test_one_sig 57
-test_one_sig 58
-test_one_sig 59
-test_one_sig 60
-test_one_sig 61
-test_one_sig 62
-test_one_sig 63
-test_one_sig TERM
+# The list of signals that the program generates, in the order they
+# are generated.
+set signals {
+ ABRT
+ HUP
+ QUIT
+ ILL
+ EMT
+ FPE
+ BUS
+ SEGV
+ SYS
+ PIPE
+ ALRM
+ URG
+ TSTP
+ CONT
+ CHLD
+ TTIN
+ TTOU
+ IO
+ XCPU
+ XFSZ
+ VTALRM
+ PROF
+ WINCH
+ LOST
+ USR1
+ USR2
+ PWR
+ POLL
+ WIND
+ PHONE
+ WAITING
+ LWP
+ DANGER
+ GRANT
+ RETRACT
+ MSG
+ SOUND
+ SAK
+ PRIO
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ TERM
+}
+
+# Make the first signal SIGABRT because it is always supported.
+set sig_supported 1
+set thissig "ABRT"
+
+# test signal handling
+for {set i 0;} {$i < [llength $signals]} {incr i;} {
+ # Skip the first.
+ if { $i == 0 } {
+ continue
+ }
+
+ set sig [lindex $signals $i]
+ test_one_sig $sig
+}

# The last signal (SIGTERM) gets handled slightly differently because
# we are not setting up for another test.
@@ -256,149 +272,20 @@ gdb_test "continue" "\[process \[0-9\]+ .*" "continue to sigal exit" \
"The next instruction is syscall exit_group.* program...y. or n. " \
"yes"

-test_one_sig_reverse TERM
-test_one_sig_reverse 63
-test_one_sig_reverse 62
-test_one_sig_reverse 61
-test_one_sig_reverse 60
-test_one_sig_reverse 59
-test_one_sig_reverse 58
-test_one_sig_reverse 57
-test_one_sig_reverse 56
-test_one_sig_reverse 55
-test_one_sig_reverse 54
-test_one_sig_reverse 53
-test_one_sig_reverse 52
-test_one_sig_reverse 51
-test_one_sig_reverse 50
-test_one_sig_reverse 49
-test_one_sig_reverse 48
-test_one_sig_reverse 47
-test_one_sig_reverse 46
-test_one_sig_reverse 45
-test_one_sig_reverse 44
-test_one_sig_reverse 43
-test_one_sig_reverse 42
-test_one_sig_reverse 41
-test_one_sig_reverse 40
-test_one_sig_reverse 39
-test_one_sig_reverse 38
-test_one_sig_reverse 37
-test_one_sig_reverse 36
-test_one_sig_reverse 35
-test_one_sig_reverse 34
-test_one_sig_reverse 33
-test_one_sig_reverse PRIO
-test_one_sig_reverse SAK
-test_one_sig_reverse SOUND
-test_one_sig_reverse MSG
-test_one_sig_reverse RETRACT
-test_one_sig_reverse GRANT
-test_one_sig_reverse DANGER
-test_one_sig_reverse LWP
-test_one_sig_reverse WAITING
-test_one_sig_reverse PHONE
-test_one_sig_reverse WIND
-test_one_sig_reverse POLL
-test_one_sig_reverse PWR
-test_one_sig_reverse USR2
-test_one_sig_reverse USR1
-test_one_sig_reverse LOST
-test_one_sig_reverse WINCH
-test_one_sig_reverse PROF
-test_one_sig_reverse VTALRM
-test_one_sig_reverse XFSZ
-test_one_sig_reverse XCPU
-test_one_sig_reverse IO
-test_one_sig_reverse TTOU
-test_one_sig_reverse TTIN
-test_one_sig_reverse CHLD
-test_one_sig_reverse CONT
-test_one_sig_reverse TSTP
-test_one_sig_reverse URG
-test_one_sig_reverse ALRM
-test_one_sig_reverse PIPE
-test_one_sig_reverse SYS
-test_one_sig_reverse SEGV
-test_one_sig_reverse BUS
-test_one_sig_reverse FPE
-test_one_sig_reverse EMT
-test_one_sig_reverse ILL
-test_one_sig_reverse QUIT
-test_one_sig_reverse HUP
-test_one_sig_reverse ABRT
+foreach sig [lreverse $signals] {
+ test_one_sig_reverse $sig
+}

# Make the first signal SIGABRT because it is always supported.
set sig_supported 1
set thissig "ABRT"

-test_one_sig HUP
-test_one_sig QUIT
-test_one_sig ILL
-test_one_sig EMT
-test_one_sig FPE
-test_one_sig BUS
-test_one_sig SEGV
-test_one_sig SYS
-test_one_sig PIPE
-test_one_sig ALRM
-test_one_sig URG
-test_one_sig TSTP
-test_one_sig CONT
-test_one_sig CHLD
-test_one_sig TTIN
-test_one_sig TTOU
-test_one_sig IO
-test_one_sig XCPU
-test_one_sig XFSZ
-test_one_sig VTALRM
-test_one_sig PROF
-test_one_sig WINCH
-test_one_sig LOST
-test_one_sig USR1
-test_one_sig USR2
-test_one_sig PWR
-test_one_sig POLL
-test_one_sig WIND
-test_one_sig PHONE
-test_one_sig WAITING
-test_one_sig LWP
-test_one_sig DANGER
-test_one_sig GRANT
-test_one_sig RETRACT
-test_one_sig MSG
-test_one_sig SOUND
-test_one_sig SAK
-test_one_sig PRIO
-test_one_sig 33
-test_one_sig 34
-test_one_sig 35
-test_one_sig 36
-test_one_sig 37
-test_one_sig 38
-test_one_sig 39
-test_one_sig 40
-test_one_sig 41
-test_one_sig 42
-test_one_sig 43
-test_one_sig 44
-test_one_sig 45
-test_one_sig 46
-test_one_sig 47
-test_one_sig 48
-test_one_sig 49
-test_one_sig 50
-test_one_sig 51
-test_one_sig 52
-test_one_sig 53
-test_one_sig 54
-test_one_sig 55
-test_one_sig 56
-test_one_sig 57
-test_one_sig 58
-test_one_sig 59
-test_one_sig 60
-test_one_sig 61
-test_one_sig 62
-test_one_sig 63
-test_one_sig TERM
+for {set i 0;} {$i < [llength $signals]} {incr i;} {
+ # Skip the first.
+ if { $i == 0 } {
+ continue
+ }
+
+ set sig [lindex $signals $i]
+ test_one_sig $sig
+}