1#!/bin/sh 2# 3# Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.org> 4# 5# Permission to use, copy, modify, and distribute this software for any 6# purpose with or without fee is hereby granted, provided that the above 7# copyright notice and this permission notice appear in all copies. 8# 9# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 17test_ps() 18{ 19 ps_args=$1 20 expected=$2 21 result=`ps -p $pid $ps_args | tail -n +2` 22 if [ "$result" != "$expected" ]; then 23 echo "$ps_vars ps $ps_args" 24 echo "expected: >$expected<" 25 echo "result: >$result<" 26 exit 1; 27 fi 28} 29 30# path shorter than 40 bytes (hopefully) 31./shortsleep & 32pid=$! 33dirname=`readlink -fn . | cut -c -40` 34padded=`printf '%-40s' $dirname` 35 36test_ps "-o cwd,command" "$padded ./shortsleep" 37test_ps "-wwo cwd,command" "$padded ./shortsleep" 38test_ps "-o cwd" "$dirname" 39test_ps "-wwo cwd" "$dirname" 40test_ps "-wwo command,cwd" "./shortsleep $dirname" 41 42kill $pid 43 44# path longer than 40 bytes 45rm -rf ridiculously_long_directory_name_component 46mkdir ridiculously_long_directory_name_component 47cd ridiculously_long_directory_name_component 48 49../shortsleep & 50pid=$! 51dirname=`readlink -fn . | cut -c -40` 52 53test_ps "-o cwd,command" "$dirname ../shortsleep" 54test_ps "-wwo cwd,command" "$dirname ../shortsleep" 55test_ps "-o cwd" "$dirname" 56test_ps "-wwo cwd" "$dirname" 57test_ps "-wwo command,cwd" "../shortsleep $dirname" 58 59kill $pid 60cd .. 61rm -rf ridiculously_long_directory_name_component 62 63exit 0 64