wafsamba: fix pidl dependencies to rebuild on pidl changes
[Samba.git] / ctdb / tests / cunit / run_proc_001.sh
blobac0c0da6ca435b553af2efcc5059d270ea6eeda5
1 #!/bin/sh
3 . "${TEST_SCRIPTS_DIR}/unit.sh"
5 # Invalid path
6 ok <<EOF
7 Process exited with error $(errcode ENOENT)
8 EOF
9 unit_test run_proc_test 0 -1 /a/b/c
11 # Non-executable path
12 prog=$(TMPDIR="$TEST_VAR_DIR" mktemp)
13 cat > "$prog" <<EOF
14 echo hello
15 EOF
17 ok <<EOF
18 Process exited with error $(errcode EACCES)
19 EOF
20 unit_test run_proc_test 0 -1 "$prog"
22 # Executable path
23 chmod +x "$prog"
25 ok <<EOF
26 Process exited with error $(errcode ENOEXEC)
27 EOF
28 unit_test run_proc_test 0 -1 "$prog"
30 # Capture output
31 cat > "$prog" <<EOF
32 #!/bin/sh
33 echo hello
34 EOF
36 ok <<EOF
37 Process exited with status 0
38 Output = (hello
40 EOF
41 unit_test run_proc_test 0 -1 "$prog"
43 # Specify timeout
44 ok <<EOF
45 Process exited with status 0
46 Output = (hello
48 EOF
49 unit_test run_proc_test 5 -1 "$prog"
51 # Redirected output
52 output=$(TMPDIR="$TEST_VAR_DIR" mktemp)
53 cat > "$prog" <<EOF
54 #!/bin/sh
55 exec >"$output" 2>&1
56 echo hello
57 EOF
59 ok <<EOF
60 Process exited with status 0
61 EOF
62 unit_test run_proc_test 0 -1 "$prog"
64 ok <<EOF
65 hello
66 EOF
67 unit_test cat "$output"
69 # Exit with error
70 cat > "$prog" <<EOF
71 #!/bin/sh
72 exit 1
73 EOF
75 ok <<EOF
76 Process exited with status 1
77 EOF
78 unit_test run_proc_test 0 -1 "$prog"
80 # Exit with signal
81 cat > "$prog" <<EOF
82 #!/bin/sh
83 kill \$$
84 EOF
86 ok <<EOF
87 Process exited with signal 15
88 EOF
89 unit_test run_proc_test 0 -1 "$prog"
91 # Exit with timeout
92 cat > "$prog" <<EOF
93 #!/bin/sh
94 echo "Sleeping for 5 seconds"
95 sleep 5
96 EOF
98 result_filter ()
100 _pid="[0-9][0-9]*"
101 sed -e "s|= ${_pid}|= PID|"
104 ok <<EOF
105 Process exited with error $(errcode ETIMEDOUT)
106 Child = PID
107 Output = (Sleeping for 5 seconds
110 unit_test run_proc_test 1 -1 "$prog"
112 # No zombie processes
113 pidfile=$(TMPDIR="$TEST_VAR_DIR" mktemp)
115 cat > "$prog" <<EOF
116 #!/bin/sh
117 echo \$$ > "$pidfile"
118 sleep 10
121 ok <<EOF
122 Process exited with error $(errcode ETIMEDOUT)
123 Child = PID
125 unit_test run_proc_test 1 -1 "$prog"
127 result_filter ()
129 _header=" *PID *TTY *TIME *CMD"
130 _header2=" *PID *TT *STAT *TIME *COMMAND"
131 sed -e "s|^${_header}|HEADER|" -e "s|^${_header2}|HEADER|"
134 pid=$(cat "$pidfile")
135 required_result 1 <<EOF
136 HEADER
138 unit_test ps -p "$pid"
140 # Redirect stdin
141 cat > "$prog" <<EOF
142 #!/bin/sh
143 cat -
146 cat > "$output" <<EOF
147 this is sample input
150 ok <<EOF
151 Process exited with status 0
152 Output = (this is sample input
155 (unit_test run_proc_test 0 4 "$prog") 4<"$output"
157 rm -f "$pidfile"
158 rm -f "$output"
159 rm -f "$prog"