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