build-sys: Enable testing of sigqueue

The referenced commits enavled both pkill and kill to send an integer to
the killed or signalled process. The test_process now will report on the
integer if sent and the testsuite changes take advantage of this
new feature.

Another process make/destroy set had to be made as using spawn
instead of exec changes both the SID and TTY for the underlying
process, making other tests fail.

References:
 commit 7d55409b82
 commit 2b804a532a
This commit is contained in:
Craig Small 2020-04-28 19:40:07 +10:00
parent 7d55409b82
commit 4090fa711b
4 changed files with 90 additions and 29 deletions

View File

@ -38,19 +38,37 @@ static void usage(void)
void void
signal_handler(int signum) signal_handler(int signum, siginfo_t *siginfo, void *ucontext)
{ {
char *signame = NULL;
switch(signum) { switch(signum) {
case SIGUSR1: case SIGUSR1:
printf("SIG SIGUSR1\n"); signame = strdup("SIGUSR1");
break; break;
case SIGUSR2: case SIGUSR2:
printf("SIG SIGUSR2\n"); signame = strdup("SIGUSR2");
break; break;
default: default:
printf("SIG unknown\n"); printf("SIG unknown\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (signame == NULL) {
printf("SIG malloc error\n");
exit(EXIT_FAILURE);
}
switch (siginfo->si_code) {
case SI_USER:
printf("SIG %s\n", signame);
break;
case SI_QUEUE:
printf("SIG %s value=%d\n", signame, siginfo->si_int);
break;
default:
printf("Unknown si_code %d\n", siginfo->si_code);
exit(EXIT_FAILURE);
}
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -74,9 +92,9 @@ int main(int argc, char *argv[])
} }
/* Setup signal handling */ /* Setup signal handling */
signal_action.sa_handler = signal_handler; signal_action.sa_sigaction = signal_handler;
sigemptyset (&signal_action.sa_mask); sigemptyset (&signal_action.sa_mask);
signal_action.sa_flags = 0; signal_action.sa_flags = SA_SIGINFO;
sigaction(SIGUSR1, &signal_action, NULL); sigaction(SIGUSR1, &signal_action, NULL);
sigaction(SIGUSR2, &signal_action, NULL); sigaction(SIGUSR2, &signal_action, NULL);

View File

@ -52,6 +52,17 @@ proc expect_pass { testname reg } {
} }
} }
proc expect_pipeproc_pass { testname reg } {
global pipeproc_spawnid
expect {
-i $pipeproc_spawnid
-re "$reg" { pass "$testname" }
default { fail "$testname" }
timeout { fail "$testname (timeout)" }
}
}
proc expect_blank { testname } { proc expect_blank { testname } {
expect { expect {
-re "\\w" { fail "$testname" } -re "\\w" { fail "$testname" }
@ -60,6 +71,14 @@ proc expect_blank { testname } {
} }
} }
proc expect_blank_continue { testname } {
expect {
-re "\\w" { fail "$testname" }
eof { }
timeout { pass "$testname (timeout)" }
}
}
proc expect_table { test match_header match_items match_footer } { proc expect_table { test match_header match_items match_footer } {
expect { expect {
-re "$match_header" { -re "$match_header" {
@ -117,6 +136,15 @@ proc expect_table_dsc { test match_header match_item } {
#} #}
} }
proc make_pipeproc { } {
global pipeproc_pid pipeproc_spawnid topdir
set testproc_realpath "${topdir}/lib/test_process"
set pipeproc_pid [ spawn $testproc_realpath ]
set pipeproc_spawnid $spawn_id
}
proc make_testproc { } { proc make_testproc { } {
global testproc_path testproc_comm testproc_arg_str testproc1_pid testproc2_pid topdir global testproc_path testproc_comm testproc_arg_str testproc1_pid testproc2_pid topdir
@ -157,6 +185,11 @@ proc kill_testproc { } {
file delete $testproc_path file delete $testproc_path
} }
proc kill_pipeproc { } {
global pipeproc_pid
kill_process $pipeproc_pid
}
proc get_tty {} { proc get_tty {} {
if { [catch { set raw_tty [ exec tty ] } msg]} { if { [catch { set raw_tty [ exec tty ] } msg]} {
warning "No TTY found" warning "No TTY found"

View File

@ -45,26 +45,21 @@ set test "kill convert signal number to name with space"
spawn $kill -l 1 spawn $kill -l 1
expect_pass "$test" "^HUP\\s*" expect_pass "$test" "^HUP\\s*"
#set test "kill numbered process" make_pipeproc
#make_testproc
#if { [ file isdirectory "/proc/$testproc1_pid" ] && [ file isdirectory "/proc/$testproc2_pid" ] } { set test "kill with SIGUSR1"
#} else { spawn $kill -USR1 $pipeproc_pid
# perror "Could not start test processes" expect_blank_continue "$test"
#} expect_pipeproc_pass "$test" "SIG SIGUSR1"
#exec $kill -KILL $testproc1_pid
#wait set test "kill with long SIGUSR2"
#if { [ file exists "/proc/$testproc1_pid" ] } { spawn $kill -s SIGUSR2 $pipeproc_pid
# exec kill $testproc2_pid expect_blank_continue "$test"
# fail "$test (proc 1 exists)" expect_pipeproc_pass "$test" "SIG SIGUSR2"
#} else {
# exec $kill -KILL $testproc2_pid set test "kill with queued int"
# wait spawn $kill -USR1 -q 42 $pipeproc_pid
# if { [ file exists "/proc/$testproc2_pid" ] } { expect_blank_continue "$test"
# exec kill $testproc2_pid expect_pipeproc_pass "$test" "SIG SIGUSR1 value=42"
# fail "$test (proc 2 exists)"
# } else { kill_pipeproc
# pass "$test"
# }
#}
## Cleanup
#exec rm $testproc_path

View File

@ -18,7 +18,6 @@ expect_pass "$test" "^\(lt-\)\?pkill: no matching criteria specified\\s*"
make_testproc make_testproc
set testproc_len [ string length $testproc_comm ] set testproc_len [ string length $testproc_comm ]
set testproc_trim [ string range $testproc_comm 0 [ expr { $testproc_len - 2 } ] ] set testproc_trim [ string range $testproc_comm 0 [ expr { $testproc_len - 2 } ] ]
set testproc1_sid [ exec $ps --no-headers -o sid $testproc1_pid ]
set test "pkill find both test pids" set test "pkill find both test pids"
spawn $pkill -0 -e $testproc_comm spawn $pkill -0 -e $testproc_comm
@ -30,3 +29,19 @@ expect_pass "$test" "^$testproc_comm killed \\(pid $testproc1_pid\\)\\s+$testpro
# Cleanup # Cleanup
kill_testproc kill_testproc
make_pipeproc
set test "pkill with SIGUSR1"
spawn $pkill -USR1 -e $testproc_comm
expect_pipeproc_pass "$test" "SIG SIGUSR1"
set test "pkill with SIGUSR2"
spawn $pkill -USR2 -e $testproc_comm
expect_pipeproc_pass "$test" "SIG SIGUSR2"
set test "pkill with queued int"
spawn $pkill -USR1 -e -q 42 $testproc_comm
expect_pipeproc_pass "$test" "SIG SIGUSR1 value=42"
kill_pipeproc