Project

General

Profile

Bug #758 ยป fbt_demo001.sh.txt

Roland Mainz, 2011-03-01 02:37 PM

 
1

    
2
export PATH='/usr/xpg6/bin:/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:/usr/sbin'
3

    
4
#
5
# prechecks
6
#
7

    
8
print '# Prechecks...'
9

    
10
if [[ $(/usr/bin/ppriv $$) != ~(X).*(dtrace_proc)&(dtrace_user).* && "$LOGNAME" != 'root' ]] ; then
11
	print -u2 "User has no dtrace privs"
12
	exit 1
13
fi
14

    
15

    
16
#
17
# run test
18
#
19

    
20
print '# Run tests'
21
# dtrace script to capture |ioctl()| output of a child
22
# process
23
typeset dtrace_script='
24
#pragma D option flowindent
25

    
26
syscall::ioctl:entry
27
/curpsinfo->pr_ppid==MAGICPPID && execname == "rksh"/
28
{
29
        self->traceme = 1;
30
        printf("fd: %d", arg0);
31
}
32

    
33
syscall::ioctl:return
34
/self->traceme == 1/
35
{
36
        self->traceme = 0;
37
}
38

    
39
fbt:::
40
/self->traceme == 1/
41
{
42
}
43
'
44

    
45
# modify script to include our pid as ppid
46
dtrace_script="${dtrace_script//MAGICPPID/$$}"
47

    
48
/usr/sbin/dtrace -s '/dev/stdin' <<<"$dtrace_script" >'xxx' 2>&1 &
49
integer dt_pid=$!
50

    
51

    
52
# spin-wait until dtrace becomes ready
53
while [[ ! -f 'xxx' || "$( < 'xxx' )" != ~(E)dtrace:\ script.+matched.+probes ]] ; do
54
	sleep 1
55
	printf '.'
56
done
57
printf '\n'
58

    
59
# grrr... dtrace claims to be ready before all probes are active
60
# (and after a long search it seems that sleeping here is the only "solution")
61
sleep 30
62

    
63

    
64
# run test application
65
rksh -c 'tty ; true'
66

    
67

    
68
# grrrr... give dtrace some time to log output
69
# (don't ask how we can programatically figure
70
# out when dtrace is done logging - ENOSUCHWAY)
71
sleep 15
72

    
73
# quit dtrace
74
kill ${dt_pid} 
75
wait ${dt_pid}
76

    
77
printf 'log output:\n-- snip --\n'
78
cat 'xxx'
79
printf -- '-- snip --\n'
80

    
81
typeset out="$( <'xxx' )"
82

    
83
print '# Processing results...'
84

    
85
# check if we met our test's goals:
86
# (we define some simple patterns here as demo...)
87
typeset -a test_goals=(
88
	'*ttcompatwput*'
89
	'*WR*'
90
	'*chicken*'
91
	'*ldterm*'
92
)
93

    
94
integer i
95
for (( i=0 ; i < ${#test_goals[@]} ; i++ )) ; do
96
	tg="${test_goals[i]}"
97

    
98
	if [[ "$out" == ${tg} ]] ; then
99
		printf '# test goal  %s met.\n' "$tg"
100
	else
101
		printf '# FAIL: goal %s NOT met.\n' "$tg"
102
	fi
103
done
104

    
105

    
106
#
107
# cleanup
108
#
109

    
110
rm 'xxx'
111

    
112
# EOF.
    (1-1/1)