Fixed multi-archness of the `demo' script.
[libobjid.git] / demo
1 #! /bin/sh
2 # $Id$
3
4
5 GDB=$PWD/gdb.`uname -i`
6
7 DIR=$PWD
8 TEST=tst-core.`uname -i`
9 STORAGE=$PWD/demo.d
10 LIB=libobjid.so.`uname -i`
11
12 function check
13 {
14   if ! $*
15   then
16     echo >&2 "Failed: $*"
17     exit 1
18   fi
19 }
20
21 check test -f ./demo
22 check test ! -e $STORAGE
23
24 if test -f $LIB
25 then
26   rm -f ./libobjid.so
27   cp -p $LIB ./libobjid.so
28   cp -p $LIB.debug ./libobjid.so.debug
29 fi
30 if ! test -f $GDB
31 then
32   GDB=gdb
33 fi
34
35 check ulimit -c unlimited
36 [ -f Makefile ] && check make libobjid.so $TEST
37
38 check mkdir $STORAGE
39
40 # Move to an empty directory to better test by losing any absolute references.
41 EMPTY=$STORAGE/empty
42 check mkdir $EMPTY
43 cd $EMPTY
44
45 STORAGE2=$STORAGE/`hostname -s`
46 check mkdir $STORAGE2
47 libs="$(ldd $DIR/$TEST $DIR/libobjid.so | sed -n 's/^\t\(.* => \)\?\([^ ]*\).*$/\2/p' | sort -u)"
48 for obj in $DIR/$TEST $DIR/libobjid.so $libs
49 do
50         if test -L $obj
51         then
52                 link=$(readlink $obj)
53                 ln -s $link $STORAGE2/`basename $obj`
54                 obj=`dirname $obj`/$link
55         fi
56         check cp -p $obj $STORAGE2/`basename $obj`
57         # It may not be present.
58         cp -p /usr/lib/debug/$obj.debug $STORAGE2/`basename $obj`.debug
59 done
60
61 # Provide relative pathname to lose the reference to the original.
62 check ln -s $DIR/libobjid.so
63 check ln -s $DIR/$TEST
64 LD_PRELOAD=./libobjid.so ./$TEST &
65 pid=$!
66 wait
67 rm -f ./libobjid.so
68 rm -f ./$TEST
69 CORE=$PWD/core.$pid
70 ls -l $CORE
71
72 strace -s200 -o x -q $GDB --objectdirectory=$STORAGE2 --core=$CORE
73
74 check rm -f $CORE
75 check rm -rf $STORAGE
76
77 echo $0 done