Debian Codegraph @

tests/preload_tsan.sh

raw
1 #!/usr/bin/env bash
2 #
3 # Licensed to the Apache Software Foundation (ASF) under one
4 # or more contributor license agreements. See the NOTICE file
5 # distributed with this work for additional information
6 # regarding copyright ownership. The ASF licenses this file
7 # to you under the Apache License, Version 2.0 (the
8 # "License"); you may not use this file except in compliance
9 # with the License. You may obtain a copy of the License at
10 #
11 # http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing,
14 # software distributed under the License is distributed on an
15 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 # KIND, either express or implied. See the License for the
17 # specific language governing permissions and limitations
18 # under the License.
19 #
20
21 if test $# -lt 2; then
22 echo <<EOF
23 usage: $0 LIB EXE [args ...]
24 Get the libtsan linked to LIB and preload it to run `EXE args ...`
25 EOF
26 fi
27
28 LIB=$1; shift
29 EXE=$2
30
31 # Preload the tsan library linked to LIB. Note we need to
32 # check the actual linkage, there may be multiple tsan lib
33 # versions installed and we must use the same one.
34
35 libtsan=$(ldd "$LIB" | awk "/(tsan.*\\.so[.0-9]*)/ { print \$3 }")
36 LD_PRELOAD="$libtsan:$LD_PRELOAD"
37 export LD_PRELOAD
38
39 exec "$@"