Skip to content

Commit 7169bbb

Browse files
committed
add test utility process_tree()
needed for valgrind to work with simulated keystrokes
1 parent 57ee9ef commit 7169bbb

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test/tools/libtest.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,39 @@ filter_file_ok()
243243
esac
244244
}
245245

246+
process_tree()
247+
{
248+
pid="${1:-0}"; shift
249+
pid="$(expr "$pid")"
250+
test "$pid" -gt 0 || return
251+
252+
depth="${1:-0}"
253+
maxdepth=20
254+
255+
printf '%s\n' "$pid"
256+
257+
depth="$((depth + 1))"
258+
test "$depth" -ge "$maxdepth" && return
259+
260+
last_pid=-1
261+
while [ "$pid" != "$last_pid" ]; do
262+
last_pid="$pid"
263+
proc_tmp="$(tempfile_name 'process_tree')"
264+
ps -e -o ppid=,pid= | grep "^[ 0]*$pid[^0-9]" > "$proc_tmp" || continue
265+
while read -r child_proc; do
266+
test -z "$child_proc" && continue
267+
ORIG_IFS="$IFS"; IFS=' '
268+
set -- $child_proc
269+
IFS="$ORIG_IFS"
270+
test "$#" -ne 2 && continue
271+
test "$pid" = "$2" && continue
272+
pid="$2"
273+
( process_tree "$pid" "$depth" )
274+
done < "$proc_tmp"
275+
rm -f -- "$proc_tmp"
276+
done
277+
}
278+
246279
#
247280
# Parse TEST_OPTS
248281
#

0 commit comments

Comments
 (0)