export PATH='/usr/xpg6/bin:/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:/usr/sbin' # # prechecks # print '# Prechecks...' if [[ $(/usr/bin/ppriv $$) != ~(X).*(dtrace_proc)&(dtrace_user).* && "$LOGNAME" != 'root' ]] ; then print -u2 "User has no dtrace privs" exit 1 fi # # run test # print '# Run tests' # dtrace script to capture |ioctl()| output of a child # process typeset dtrace_script=' #pragma D option flowindent syscall::ioctl:entry /curpsinfo->pr_ppid==MAGICPPID && execname == "rksh"/ { self->traceme = 1; printf("fd: %d", arg0); } syscall::ioctl:return /self->traceme == 1/ { self->traceme = 0; } fbt::: /self->traceme == 1/ { } ' # modify script to include our pid as ppid dtrace_script="${dtrace_script//MAGICPPID/$$}" /usr/sbin/dtrace -s '/dev/stdin' <<<"$dtrace_script" >'xxx' 2>&1 & integer dt_pid=$! # spin-wait until dtrace becomes ready while [[ ! -f 'xxx' || "$( < 'xxx' )" != ~(E)dtrace:\ script.+matched.+probes ]] ; do sleep 1 printf '.' done printf '\n' # grrr... dtrace claims to be ready before all probes are active # (and after a long search it seems that sleeping here is the only "solution") sleep 30 # run test application rksh -c 'tty ; true' # grrrr... give dtrace some time to log output # (don't ask how we can programatically figure # out when dtrace is done logging - ENOSUCHWAY) sleep 15 # quit dtrace kill ${dt_pid} wait ${dt_pid} printf 'log output:\n-- snip --\n' cat 'xxx' printf -- '-- snip --\n' typeset out="$( <'xxx' )" print '# Processing results...' # check if we met our test's goals: # (we define some simple patterns here as demo...) typeset -a test_goals=( '*ttcompatwput*' '*WR*' '*chicken*' '*ldterm*' ) integer i for (( i=0 ; i < ${#test_goals[@]} ; i++ )) ; do tg="${test_goals[i]}" if [[ "$out" == ${tg} ]] ; then printf '# test goal %s met.\n' "$tg" else printf '# FAIL: goal %s NOT met.\n' "$tg" fi done # # cleanup # rm 'xxx' # EOF.