5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
23 # Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
26 #ident "%Z%%M% %I% %E% SMI"
28 export PATH
=/usr
/bin
:/usr
/sbin
:/usr
/ccs
/bin
34 if [[ $isa = sparc
]]; then
36 elif [[ $isa = i386
]]; then
42 if [[ -n "$SRCTOP" ]]; then
43 sysroot
=$SRCTOP/proto
/root_
$isa
44 elif [[ -n "$ROOT" ]]; then
54 simchan=com.sun:fm:fmd$$
73 nm -ghp $1 2>/dev/null | while read addr type name; do
74 [[ $type != T ]] && continue
76 _fmd_init) cp $1 $2/usr/lib/fm/fmd/plugins; return ;;
77 fmd_fmri_nvl2str) cp $1 $2/usr/lib/fm/fmd/schemes; return ;;
78 topo_load) cp $1 $2/usr/lib/fm/topo/plugins; return ;;
81 die "\nunknown .so type -- $1"
86 mkdir -p $2/usr/lib/fm/topo/maps
87 cp $1 $2/usr/lib/fm/topo/maps;
88 for platdir in $2/usr/platform/*/lib/fm/topo/maps; do
89 rm -f $platdir/* 2>/dev/null
95 for cmd in fmadm fmdump fmstat; do
102 if [[ $1 -gt 128 ]]; then
103 sig=$(kill -l $(($1 - 128)))
104 die "fmd terminated from signal $sig (see $simroot)"
105 elif [[ $1 -ne 0 ]]; then
106 die "fmd terminated with status $1 (see $simroot)"
112 echo "fmsim: [ Press return to $* ] \c"
114 stty -echo -isig min 1 time 0
121 echo "fmsim: $*" >& 2
122 $opt_w && wait_prompt exit
123 [[ -n "$simpid" ]] && exit 1 || exit 2
126 while [[ $# -gt 0 ]]; do
127 OPTIND=1; while getopts ':d
:D
:ehio
:st
:vVwx
' c; do
134 truss_args="-s $OPTARG -c"
138 dump_args="$dump_args -$c"
144 fmd_args="$fmd_args -o $OPTARG"
151 die "option requires an argument
-- $OPTARG"
154 die "illegal option
-- $OPTARG"
158 let OPTIND="$OPTIND - 1"; shift $OPTIND
160 if [[ $# -gt 0 ]]; then
170 for file in $files; do
171 [[ -r $file ]] || die "input
file is missing or not readable
-- $file"
174 if $opt_h || [[ -z "$files" && $opt_i = false ]]; then
175 echo "Usage
: fmsim
[-ehisvVwx] [-d dir
] [-D a.d
] [-o opt
=val
]" \
176 "[-t args
] [file ...
]"
178 echo "\t-d set the simulation root directory to the given location
"
179 echo "\t-D start fmd
(1M
) using dtrace
(1M
) and specified D
script"
180 echo "\t-e display error log content instead of fault log content
"
181 echo "\t-h display usage information
for fmsim and
exit"
182 echo "\t-i set interactive mode
: do not stop after sending events
"
183 echo "\t-o set fmd
(1M
) option to specified value during simulation
"
184 echo "\t-s set up simulation world but
do not actually run simulation
"
185 echo "\t-t start fmd
(1M
) using truss
(1) and specified arguments
"
186 echo "\t-v set verbose mode
: display additional event detail
"
187 echo "\t-V set very verbose mode
: display complete event contents
"
188 echo "\t-w wait for a keypress after simulation completes
"
189 echo "\t-x delete simulation world
if simulation is successful
"
194 echo "fmsim
: creating simulation world
$simroot ... \c
"
195 [[ -d $simroot ]] || mkdir -p $simroot || exit 1
196 cd $simroot || exit 1
199 echo "fmsim
: populating
/var ... \c
"
200 mkdir -p -m 0755 var/fm/fmd
201 mkdir -p -m 0700 var/fm/fmd/ckpt
202 mkdir -p -m 0700 var/fm/fmd/rsrc
203 mkdir -p -m 0700 var/fm/fmd/xprt
206 echo "fmsim
: populating
/usr
/lib
/fm from
$sysroot ... \c
"
207 (cd $sysroot && find usr/lib/fm -depth -print | cpio -pdmu $simroot)
209 for platdir in $sysroot/usr/platform/*/lib/fm; do
210 [[ -d $platdir ]] && platdir=${platdir#$sysroot} || continue
211 echo "fmsim
: populating
$platdir from
$sysroot ... \c
"
212 (cd $sysroot && find ${platdir#/} -depth -print | cpio -pdmu $simroot)
215 echo "fmsim
: populating
/usr
/lib
/locale
/$LANG from
$sysroot ... \c
"
216 (cd $sysroot && find usr/lib/locale/$LANG -depth -print | cpio -pdmu $simroot)
218 echo "fmsim
: populating
/usr
/sbin from
$sysroot ... \c
"
219 (cd $sysroot && list_cmds | cpio -pdmu $simroot)
221 echo "fmsim
: adding customizations
:\c
"
224 for file in $files; do
225 base=$(basename $file)
227 *.cmd) die "\neversholt
command file not yet supported
-- $file" ;;
228 fmd.conf) cp $file $simroot/etc/fm/fmd ;;
229 *.conf) cp $file $simroot/usr/lib/fm/fmd/plugins ;;
230 *.dict) cp $file $simroot/usr/lib/fm/dict ;;
231 *.eft) cp $file $simroot/usr/lib/fm/eft ;;
232 *.esc) die "\neversholt
source file not yet supported
-- $file" ;;
233 *.inj) inj_args="$inj_args $file" ;;
234 *.log) inj_args="$inj_args $file" ;;
235 *log) inj_args="$inj_args $file" ;;
236 *.mo) cp $file $simroot/usr/lib/locale/$LANG/LC_MESSAGES ;;
237 *.so) cp_so $file $simroot ;;
238 *.topo) die "\n .topo files not supported
-- $file" ;;
239 *.xml) cp_topo $file $simroot ;;
240 *) die "\nunknown
file type or suffix
-- $file" ;;
245 cd $simroot || exit 1
248 echo "fmsim
: generating
script ... \c
"
249 cat >$simscript <<EOS
252 # Copyright 2005 Sun Microsystems, Inc. All rights reserved.
253 # Use is subject to license terms.
255 #ident "@
(#)fmsim.ksh 1.5 06/10/11 SMI"
258 # fmsim(1M) script generated for $simroot $(date)
261 export LD_LIBRARY_PATH
=$simroot/usr
/lib
:$simroot/usr
/lib
/fm
262 export LD_LIBRARY_PATH_64
=$simroot/usr
/lib
/64:$simroot/usr
/lib
/fm
/$isa64
264 export _THREAD_ERROR_DETECTION
=2
266 exec $truss_cmd $truss_args $quote.
/usr
/lib
/fm
/fmd
/fmd
-R $simroot $eol
267 -o fg=true
-o clock=simulated
$eol
268 -o rpc.adm.prog
=0 -o rpc.adm.path
=$simroot/rpc
$eol
269 -o sysevent-transport
:device
=/dev
/null
$eol
270 -o sysevent-transport
:channel
=$simchan $fmd_args$quote
274 chmod 0555 $simscript
278 echo "fmsim: simulation is saved in $simroot"
282 export LD_LIBRARY_PATH
=$simroot/usr
/lib
:$simroot/usr
/lib
/fm
283 export LD_LIBRARY_PATH_64
=$simroot/usr
/lib
/64:$simroot/usr
/lib
/fm
/$isa64
285 echo "fmsim: simulation $$ running fmd(1M)\c"
286 .
/usr
/lib
/fm
/fmd
/fmd
-V | cut
-d: -f2
294 while [[ ! -s $simroot/rpc
]]; do
295 [[ $i -ge 30 ]] && kill -9 $simpid >/dev
/null
2>&1
296 kill -0 $simpid >/dev
/null
2>&1 ||
break
301 kill -0 $simpid >/dev
/null
2>&1 ||
{
306 echo "fmsim: rpc adm requests can rendezvous at" $
(<$simroot/rpc
)
307 echo "fmsim: injectors should use channel $simchan"
308 echo "fmsim: debuggers should attach to PID $simpid"
310 for arg
in $inj_args; do
311 echo "fmsim: injecting events from $arg ... \c"
312 $simroot/usr
/lib
/fm
/fmd
/fminject
-q -c $simchan $arg ||
{
313 echo "fmsim: fminject failed for $arg: aborting simulation" >& 2
314 kill $simpid >/dev
/null
2>&1
319 if [[ $opt_i = false
]]; then
320 echo "fmsim: injecting event to advance to end-of-time ... \c"
321 echo 'endhrtime;' |
$simroot/usr
/lib
/fm
/fmd
/fminject
-q -c $simchan -
328 if [[ -f $simroot/var
/fm
/fmd
/errlog
]]; then
329 echo; $simroot/usr
/sbin
/fmdump
-R $simroot $dump_args; echo
333 $opt_w && wait_prompt
exit
334 $opt_x && rm -rf $simroot