tests: robustify pc.test

* tests/pc.c (main): Unmap larger memory region.
Dump process map for debug purposes.
* tests/pc.test: Update regexps to take CLD_DUMPED child process
into account.
This commit is contained in:
Дмитрий Левин 2015-02-23 22:37:40 +00:00
parent e3e64a144b
commit 1c5feadf75
2 changed files with 18 additions and 8 deletions

View File

@ -1,17 +1,19 @@
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <sys/sendfile.h>
int main(void)
{
const unsigned long size = sysconf(_SC_PAGESIZE);
const unsigned long mask = ~(size - 1);
/* write instruction pointer length to the log */
if (write(-1, NULL, 2 * sizeof(void *)) >= 0)
return 77;
/* just a noticeable line in the log */
if (munmap(&munmap, 0) >= 0)
if (munmap(&main, 0) >= 0)
return 77;
int pid = fork();
@ -19,9 +21,12 @@ int main(void)
return 77;
if (!pid) {
munmap((void *) ((unsigned long) &munmap & mask), size);
const unsigned long mask = ~(size - 1);
const unsigned long addr = (unsigned long) &main;
/* SIGSEGV is expected */
munmap((void *) (((unsigned long) &munmap & mask) + size), size);
(void) munmap((void *) ((addr & mask) - size * 2), size * 4);
(void) munmap((void *) ((addr & mask) - size * 2), size * 4);
return 77;
}
@ -31,5 +36,10 @@ int main(void)
WTERMSIG(status) != SIGSEGV)
return 77;
/* dump process map for debug purposes */
close(0);
if (!open("/proc/self/maps", O_RDONLY))
(void) sendfile(1, 0, NULL, size);
return 0;
}

View File

@ -19,27 +19,27 @@ $STRACE $args > "$OUT" 2> "$LOG" || {
len="$(sed -n 's/^\[[[:xdigit:]]\+\] write(-1, NULL, \([[:digit:]]\{1,2\}\))[[:space:]]\+= -1 .*/\1/p' "$LOG")" &&
[ -n "$len" ] &&
pid="$(sed -n 's/^\[[[:xdigit:]]\{'"$len"'\}\] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_KILLED, si_pid=\([[:digit:]]\+\), .*/\1/p' "$LOG")" &&
pid="$(sed -n 's/^\[[[:xdigit:]]\{'"$len"'\}\] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_\(KILLED\|DUMPED\), si_pid=\([[:digit:]]\+\), .*/\2/p' "$LOG")" &&
[ -n "$pid" ] &&
ip="$(sed -n 's/^\[pid \+'"$pid"'\] \[\([[:xdigit:]]\{'"$len"'\}\)] --- SIGSEGV {.*} ---$/\1/p' "$LOG")" &&
[ -n "$ip" ] &&
addr="$(echo "$ip" |sed 's/^0\+//')" &&
[ -n "$addr" ] || {
cat "$LOG"
cat "$OUT" "$LOG"
fail_ "$STRACE $args output mismatch"
}
grep_log()
{
LC_ALL=C grep -x -e "$*" < "$LOG" > /dev/null || {
cat "$LOG"
cat "$OUT" "$LOG"
fail_ "$STRACE $args output mismatch"
}
}
grep_log '\[[[:xdigit:]]\{'"$len"'\}\] munmap(0x[[:xdigit:]]\+, 0)[[:space:]]\+= -1 .*'
grep_log '\[pid \+'"$pid"'\] \['"$ip"'\] --- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x'"$addr"'} ---'
grep_log '\[pid \+'"$pid"'\] \[?\{'"$len"'\}\] +++ killed by SIGSEGV +++'
grep_log '\[pid \+'"$pid"'\] \[?\{'"$len"'\}\] +++ killed by SIGSEGV\( (core dumped)\)\? +++'
grep_log '\[?\{'"$len"'\}\] +++ exited with 0 +++'
rm -f "$OUT"