OILS / test / signal-state.sh View on Github | oils.pub

78 lines, 41 significant
1#!/usr/bin/env bash
2#
3# Test kernel state: which signals caught, ignored, etc.
4#
5# Usage:
6# test/signal-state.sh <function name>
7
8do_child() {
9 echo
10 echo 'BACKGROUND CHILD'
11 $sh -c 'script=$1; sleep 0.5 & { sleep 0.2; $script report $!; }' -- $0
12
13 # TODO: I think we need a foreground child too. It can just be a C program that
14 # prints its own PID, and then waits for a byte on stdin before it exits?
15}
16
17compare-shells() {
18 local do_child=${1:-}
19 local do_trap=${2:-}
20
21 local osh_cpp=_bin/cxx-dbg/osh
22 ninja $osh_cpp
23
24 local -a shells=(bash dash mksh zsh bin/osh $osh_cpp)
25
26 # Hm non-interactive shells have consistency.
27 # SIGCHLD and SIGINT are caught in bash, dash, zsh, mksh. mksh catches
28 # several more.
29
30 for sh in ${shells[@]}; do
31 echo
32 echo "---- $sh ----"
33 echo
34
35 #echo "Parent PID $$"
36 #grep '^SigIgn:' "/proc/$$/status"
37 #trap
38
39 $sh test/signal-report.sh report "$do_trap"
40
41 if test -n "$do_child"; then
42 do_child $sh
43 fi
44 done
45}
46
47old() {
48 echo
49 echo
50
51 # -i messes things up
52 return
53
54 for sh in ${shells[@]}; do
55 echo
56 echo "---- $sh -i ----"
57 echo
58
59 # NOTE: If we don't set --rcfile, somehow this parent shell gets
60 # [2]+ Stopped devtools/sigparse.sh compare-shells
61 # Seems related to spec test flakiness.
62
63 local more_flags=''
64 case $sh in
65 bash|bin/osh)
66 more_flags='--rcfile /dev/null'
67 ;;
68 esac
69
70 $sh $more_flags -i -c 'script=$1; $script report $$' -- $0
71
72 if test -n "$do_child"; then
73 do-child $sh
74 fi
75 done
76}
77
78"$@"