1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Manual tests
|
4 | #
|
5 | # Usage:
|
6 | # test/manual.sh <function name>
|
7 |
|
8 | : ${LIB_OSH=stdlib/osh}
|
9 | source $LIB_OSH/bash-strict.sh
|
10 | source $LIB_OSH/task-five.sh
|
11 |
|
12 | readonly OSHRC=_tmp/manual-oshrc
|
13 |
|
14 | setup() {
|
15 | cat >$OSHRC <<EOF
|
16 | OILS_COMP_UI=nice
|
17 | EOF
|
18 | }
|
19 |
|
20 | test-osh() {
|
21 | # Test it manually
|
22 | bin/osh --rcfile $OSHRC
|
23 | }
|
24 |
|
25 | test-ysh() {
|
26 | # same OSHRC? Should it respect ENV.OILS_COMP_UI?
|
27 | bin/ysh --rcfile $OSHRC
|
28 | }
|
29 |
|
30 | no-home-dir() {
|
31 | ### Trying to tickle code path hit via oily-pine
|
32 |
|
33 | local sh=${1:-bash}
|
34 | # env -i gets rid of $HOME
|
35 | # unshare allows us to fake /etc/passwd
|
36 | env -i -- unshare --user --mount --map-root-user bash -c '
|
37 | sh=$1
|
38 |
|
39 | #set -x
|
40 |
|
41 | cmd="wc -l /etc/passwd; echo home \$HOME; echo tilde ~"
|
42 |
|
43 | whoami
|
44 | $sh -c "$cmd"
|
45 | echo
|
46 |
|
47 | #mount --bind /dev/null /etc/passwd
|
48 | echo "bob:x:1001:1001:Bob:/tmp:/bin/bash" > /tmp/passwd
|
49 | mount --bind /tmp/passwd /etc/passwd
|
50 |
|
51 | echo "bob:x:1001:h" > /tmp/group
|
52 | mount --bind /tmp/group /etc/group
|
53 |
|
54 | getent passwd bob
|
55 | su - bob
|
56 | #sudo -u bob bash
|
57 |
|
58 | #wc -l /etc/passwd
|
59 | #cat /etc/passwd
|
60 |
|
61 | #su -s $sh "#1001" -c "$cmd"
|
62 | #su -s $sh bob -c "$cmd"
|
63 |
|
64 | #setuidgid 1000 $sh -c "$cmd"
|
65 |
|
66 | #setpriv --reuid=1001 --regid=1001 --clear-groups -- $sh -c "$cmd"
|
67 | #sudo -u "#1001" $sh -c "$cmd"
|
68 | ' dummy0 $sh
|
69 | }
|
70 |
|
71 | # MANUAL TEST
|
72 | # - external sleep can be killed with TERM, but it's unaffacted
|
73 |
|
74 | start-sleep() {
|
75 | local osh=${1:-} # start with bin/osh or _bin/cxx-asan/osh
|
76 | local do_trap=${2:-}
|
77 |
|
78 | local traps='
|
79 | trap "echo GOT-INT" INT
|
80 | trap "echo GOT-WINCH" WINCH
|
81 | trap "sleep 0.3" USR1
|
82 | '
|
83 |
|
84 | local code='sleep 100 & last_pid=$!; echo "pid $last_pid"; test/signal-state.sh report $last_pid; wait; echo "sleep done"'
|
85 |
|
86 | if test -n "$osh"; then
|
87 | code="builtin $code"
|
88 | if test -n "$do_trap"; then
|
89 | code="$traps $code"
|
90 | fi
|
91 | set -x
|
92 | $osh -c "$code"
|
93 | else
|
94 | sh -c "$code"
|
95 | fi
|
96 | }
|
97 |
|
98 | read-t-sleep() {
|
99 | echo "PID = $$"
|
100 |
|
101 | local do_trap=${1:-}
|
102 |
|
103 | if test -n "$do_trap"; then
|
104 | # bash does run signal handlers immediately
|
105 | # I can see int multiple times
|
106 | set -x
|
107 | trap 'echo GOT-INT' INT
|
108 | trap 'echo GOT-WINCH' WINCH
|
109 |
|
110 | # Test out remaining time logic. It still sleeps for 5 seconds total.
|
111 | trap 'sleep 0.3' USR1
|
112 | fi
|
113 | # note:
|
114 | # - untrapped SIGINT/Ctrl-C interrupts it
|
115 | # - trapped SIGINT does not!
|
116 |
|
117 | # sleep
|
118 | read -t 5.0
|
119 | }
|
120 |
|
121 | task-five "$@"
|