1 | # check if stdout is a terminal...
|
---|
2 | if test -t 1; then
|
---|
3 |
|
---|
4 | # see if it supports colors...
|
---|
5 | ncolors=$(tput colors)
|
---|
6 |
|
---|
7 | if test -n "$ncolors" && test $ncolors -ge 8; then
|
---|
8 | bold="$(tput bold)"
|
---|
9 | underline="$(tput smul)"
|
---|
10 | standout="$(tput smso)"
|
---|
11 | normal="$(tput sgr0)"
|
---|
12 | black="$(tput setaf 0)"
|
---|
13 | red="$(tput setaf 1)"
|
---|
14 | green="$(tput setaf 2)"
|
---|
15 | yellow="$(tput setaf 3)"
|
---|
16 | blue="$(tput setaf 4)"
|
---|
17 | magenta="$(tput setaf 5)"
|
---|
18 | cyan="$(tput setaf 6)"
|
---|
19 | white="$(tput setaf 7)"
|
---|
20 | fi
|
---|
21 | fi
|
---|
22 |
|
---|
23 | function error
|
---|
24 | {
|
---|
25 | >&2 echo "${red}$1${normal}"
|
---|
26 | }
|
---|
27 |
|
---|
28 | # helper function to get the runpath (-Wl,-rpath in gcc)
|
---|
29 | function getrunpath()
|
---|
30 | {
|
---|
31 | local elfout=$(readelf -d $1 | grep -E "RPATH|RUNPATH")
|
---|
32 | regex='\[/([[:alpha:][:digit:]@/_.-]+)\]'
|
---|
33 | if [[ $elfout =~ $regex ]]; then
|
---|
34 | local myRPath=${BASH_REMATCH[1]}
|
---|
35 | else
|
---|
36 | error "Could not find RUNPATH for test $2"
|
---|
37 | fi
|
---|
38 | echo "$myRPath"
|
---|
39 | }
|
---|
40 |
|
---|
41 | # helper function to list the dependencies of each executable
|
---|
42 | function getdeps()
|
---|
43 | {
|
---|
44 | local deps=$(ldd $1)
|
---|
45 | retlcldeps=()
|
---|
46 | retsysdeps=()
|
---|
47 | while IFS= read -r line; do
|
---|
48 | regex1='(libcfa[[:alpha:][:digit:].]+)'
|
---|
49 | regex2='/([[:alpha:][:digit:]@/_.-]+)'
|
---|
50 | regex3='linux-vdso.so.1|linux-gate.so.1'
|
---|
51 | if [[ $line =~ $regex1 ]]; then
|
---|
52 | retlcldeps+=(${BASH_REMATCH[1]})
|
---|
53 | elif [[ $line =~ $regex2 ]]; then
|
---|
54 | retsysdeps+=(${BASH_REMATCH[1]})
|
---|
55 | elif [[ $line =~ $regex3 ]]; then
|
---|
56 | # echo "ignoring '$line}': intrinsic"
|
---|
57 | :
|
---|
58 | else
|
---|
59 | error "Could not find dependency '$line' for test $2"
|
---|
60 | fi
|
---|
61 | done <<< "$deps"
|
---|
62 | }
|
---|
63 |
|
---|
64 | # make a symlink, with better errors
|
---|
65 | function makelink()
|
---|
66 | {
|
---|
67 | local source=$1
|
---|
68 | local target=$2
|
---|
69 | if [ ! -f $source ]; then
|
---|
70 | error "Source of link $source does not exist"
|
---|
71 | fi
|
---|
72 |
|
---|
73 | if [ ! -e $target ] && [ ! -L $target ]; then
|
---|
74 | ln -s $source $target
|
---|
75 | return
|
---|
76 | fi
|
---|
77 |
|
---|
78 | if [ ! -L $target ]; then
|
---|
79 | error "Cannot create link $target for $source, existing regular file"
|
---|
80 | else
|
---|
81 | want=$(readlink -f $source)
|
---|
82 | have=$(readlink -f $target)
|
---|
83 | if [ $want == $have ]; then
|
---|
84 | return
|
---|
85 | fi
|
---|
86 | error "Target link $(basename $target) for $source already exists and has incorrect target $have"
|
---|
87 | fi
|
---|
88 | }
|
---|
89 |
|
---|
90 | # ========================================
|
---|
91 | # make sure this computer is acceptable
|
---|
92 | myarch=$(uname -m)
|
---|
93 | if [ ! -z $arch ] && [ "$myarch" != "$arch" ]; then
|
---|
94 | error "Wrong architecture, is : $myarch, need: $arch"
|
---|
95 | exit 1
|
---|
96 | fi
|
---|
97 |
|
---|
98 | myname=$(uname -n)
|
---|
99 | if [ ! -z $name ] && [ "$myname" != "$name" ]; then
|
---|
100 | >&2 echo "${yellow}Unexpected machine name, is: $myname, expected: $name${normal}"
|
---|
101 | fi
|
---|
102 |
|
---|
103 | # ========================================
|
---|
104 | # make sure we use the right paths
|
---|
105 | srcdir=$(readlink -f $(dirname "$0"))
|
---|
106 | outdir=$(readlink -f $(pwd))
|
---|
107 |
|
---|
108 | rnpaths=()
|
---|
109 | sysdeps=()
|
---|
110 | lcldeps=()
|
---|
111 |
|
---|
112 | # find all the tests
|
---|
113 | programs=($(find $srcdir/tests/crashes -name exe))
|
---|
114 | if [ ${#programs[@]} -eq 0 ]; then
|
---|
115 | error "ERROR no executables found in archive"
|
---|
116 | exit 1
|
---|
117 | fi
|
---|
118 |
|
---|
119 | # ========================================
|
---|
120 | # for each tests
|
---|
121 | echo "generating command files ..."
|
---|
122 | for pgm in "${programs[@]}"
|
---|
123 | do
|
---|
124 | # find the test's name
|
---|
125 | regex='tests/crashes/(short|full-debug|full-nodebug)/([[:alpha:][:digit:]@/_.-]+)/exe'
|
---|
126 | if [[ $pgm =~ $regex ]]; then
|
---|
127 | name=${BASH_REMATCH[2]}
|
---|
128 | else
|
---|
129 | error "Executable '$pgm' has ill-formed path"
|
---|
130 | fi
|
---|
131 |
|
---|
132 | # get a path to the executable
|
---|
133 | exe=$(readlink -f "$pgm")
|
---|
134 |
|
---|
135 | # check the executable exist
|
---|
136 | if [ ! -x $exe ]; then
|
---|
137 | error "Executable for '$name' does not have execute permission"
|
---|
138 | continue
|
---|
139 | fi
|
---|
140 |
|
---|
141 | ldd $exe > /dev/null 2>&1
|
---|
142 | if [ $? -ne 0 ]; then
|
---|
143 | error "Executable for '$name' is not valid for this architecture"
|
---|
144 | continue
|
---|
145 | fi
|
---|
146 |
|
---|
147 | # get the corresponding core file
|
---|
148 | core="$(dirname "$exe")/core"
|
---|
149 | if [ ! -f "$core" ]; then
|
---|
150 | error "No core found for test '$name'"
|
---|
151 | fi
|
---|
152 |
|
---|
153 | # create the command file
|
---|
154 | file="${name//\//.}.com"
|
---|
155 | echo "$file"
|
---|
156 | echo "set solib-absolute-prefix $outdir" > $file
|
---|
157 | echo "file $exe" >> $file
|
---|
158 | echo "core-file $core" >> $file
|
---|
159 |
|
---|
160 | # find the system dependencies
|
---|
161 | getdeps $exe $name
|
---|
162 | sysdeps+=("${retsysdeps[@]}")
|
---|
163 | lcldeps+=("${retlcldeps[@]}")
|
---|
164 |
|
---|
165 | # find it's expected runpath
|
---|
166 | rnpaths+=("$(getrunpath $exe $name)")
|
---|
167 | done <<< "$programs"
|
---|
168 |
|
---|
169 | echo "done"
|
---|
170 |
|
---|
171 | # ========================================
|
---|
172 | # eliminate duplicates from the list of dependencies
|
---|
173 |
|
---|
174 | # get unique elements of array
|
---|
175 | function getuniques()
|
---|
176 | {
|
---|
177 | echo "$*" | tr ' ' '\n' | sort -u | tr '\n' ' '
|
---|
178 | }
|
---|
179 |
|
---|
180 | rnpaths=($(getuniques ${rnpaths[@]}))
|
---|
181 | sysdeps=($(getuniques ${sysdeps[@]}))
|
---|
182 | lcldeps=($(getuniques ${lcldeps[@]}))
|
---|
183 |
|
---|
184 | # ========================================
|
---|
185 | # create symlinks to cforall dependencies
|
---|
186 | echo "setting up local dependencies ..."
|
---|
187 |
|
---|
188 | for rpath in "${rnpaths[@]}"
|
---|
189 | do
|
---|
190 | # find the debug level
|
---|
191 | if [[ $rpath =~ 'nodebug' ]]; then
|
---|
192 | level="-nodebug"
|
---|
193 | elif [[ $rpath =~ 'debug' ]]; then
|
---|
194 | level="-debug"
|
---|
195 | else
|
---|
196 | error "Executable(s) with ill-formed rpath"
|
---|
197 | fi
|
---|
198 |
|
---|
199 | # create the right directory
|
---|
200 | mkdir -p "$outdir/$rpath"
|
---|
201 |
|
---|
202 | # for each dependencies create them
|
---|
203 | # this might create unnecessary pairs, but I don't care
|
---|
204 | for lib in "${lcldeps[@]}"
|
---|
205 | do
|
---|
206 | echo "$lib$level"
|
---|
207 | source=$(find "$srcdir" -name "$lib*" -a -path "*$level*")
|
---|
208 | target="$outdir/$rpath/$lib"
|
---|
209 | makelink $source $target
|
---|
210 | done
|
---|
211 | done
|
---|
212 |
|
---|
213 | echo "done"
|
---|
214 |
|
---|
215 | # ========================================
|
---|
216 | # create symlinks to system dependencies
|
---|
217 | echo "setting up system dependencies ..."
|
---|
218 |
|
---|
219 | for dep in "${sysdeps[@]}"
|
---|
220 | do
|
---|
221 | echo $dep
|
---|
222 | mkdir -p "$outdir/$(dirname $dep)"
|
---|
223 | makelink "/$dep" "$outdir/$dep"
|
---|
224 | done
|
---|
225 |
|
---|
226 | echo "done"
|
---|