2014-07-29 Ed Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / gcc / testsuite / lib / tsan-dg.exp
blobf313123aaaa4a55fb479cf3df67b7137d12e3b10
1 # Copyright (C) 2013-2014 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with GCC; see the file COPYING3. If not see
15 # <http://www.gnu.org/licenses/>.
17 # Return 1 if compilation with -fsanitize=thread is error-free for trivial
18 # code, 0 otherwise.
20 proc check_effective_target_fthread_sanitizer {} {
21 return [check_no_compiler_messages faddress_sanitizer object {
22 void foo (void) { }
23 } "-fPIE -pie -fsanitize=thread"]
27 # tsan_link_flags -- compute library path and flags to find libtsan.
28 # (originally from g++.exp)
31 proc tsan_link_flags { paths } {
32 global srcdir
33 global ld_library_path
34 global shlib_ext
36 set gccpath ${paths}
37 set flags ""
39 set shlib_ext [get_shlib_extension]
41 if { $gccpath != "" } {
42 if { [file exists "${gccpath}/libsanitizer/tsan/.libs/libtsan.a"]
43 || [file exists "${gccpath}/libsanitizer/tsan/.libs/libtsan.${shlib_ext}"] } {
44 append flags " -B${gccpath}/libsanitizer/tsan/ "
45 append flags " -L${gccpath}/libsanitizer/tsan/.libs "
46 append ld_library_path ":${gccpath}/libsanitizer/tsan/.libs"
48 } else {
49 global tool_root_dir
51 set libtsan [lookfor_file ${tool_root_dir} libtsan]
52 if { $libtsan != "" } {
53 append flags "-L${libtsan} "
54 append ld_library_path ":${libtsan}"
58 set_ld_library_path_env_vars
60 return "$flags"
64 # tsan_init -- called at the start of each subdir of tests
67 proc tsan_init { args } {
68 global TEST_ALWAYS_FLAGS
69 global ALWAYS_CXXFLAGS
70 global TOOL_OPTIONS
71 global tsan_saved_TEST_ALWAYS_FLAGS
72 global dg-do-what-default
73 global tsan_saved_dg-do-what-default
75 set link_flags ""
76 if ![is_remote host] {
77 if [info exists TOOL_OPTIONS] {
78 set link_flags "[tsan_link_flags [get_multilibs ${TOOL_OPTIONS}]]"
79 } else {
80 set link_flags "[tsan_link_flags [get_multilibs]]"
84 if [info exists dg-do-what-default] {
85 set tsan_saved_dg-do-what-default ${dg-do-what-default}
87 if [info exists TEST_ALWAYS_FLAGS] {
88 set tsan_saved_TEST_ALWAYS_FLAGS $TEST_ALWAYS_FLAGS
90 if [info exists ALWAYS_CXXFLAGS] {
91 set ALWAYS_CXXFLAGS [concat "{ldflags=$link_flags}" $ALWAYS_CXXFLAGS]
92 set ALWAYS_CXXFLAGS [concat "{additional_flags=-fPIE -pie -fsanitize=thread -g}" $ALWAYS_CXXFLAGS]
93 } else {
94 if [info exists TEST_ALWAYS_FLAGS] {
95 set TEST_ALWAYS_FLAGS "$link_flags -fPIE -pie -fsanitize=thread -g $TEST_ALWAYS_FLAGS"
96 } else {
97 set TEST_ALWAYS_FLAGS "$link_flags -fPIE -pie -fsanitize=thread -g"
100 if { $link_flags != "" } {
101 global individual_timeout
103 # Lower timeout value in case test does not terminate properly.
104 set individual_timeout 20
105 if [check_runtime_nocache tsan_works {
106 int main () { return 0; }
107 } "-fPIE -pie -fsanitize=thread -g"] {
108 set dg-do-what-default run
109 } else {
110 set dg-do-what-default compile
112 unset individual_timeout
113 return 1
115 return 0
119 # tsan_finish -- called at the end of each subdir of tests
122 proc tsan_finish { args } {
123 global TEST_ALWAYS_FLAGS
124 global tsan_saved_TEST_ALWAYS_FLAGS
125 global dg-do-what-default
126 global tsan_saved_dg-do-what-default
128 if [info exists tsan_saved_TEST_ALWAYS_FLAGS] {
129 set TEST_ALWAYS_FLAGS $tsan_saved_TEST_ALWAYS_FLAGS
130 } else {
131 unset TEST_ALWAYS_FLAGS
133 if [info exists tsan_saved_dg-do-what-default] {
134 set dg-do-what-default ${tsan_saved_dg-do-what-default}
135 } else {
136 unset dg-do-what-default