]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
testsuite: Use color=never for more sanitizer tests
authorJoseph Myers <josmyers@redhat.com>
Wed, 11 Feb 2026 23:53:41 +0000 (23:53 +0000)
committerJoseph Myers <josmyers@redhat.com>
Wed, 11 Feb 2026 23:53:41 +0000 (23:53 +0000)
The sanitizer tests have logic to set ASAN_OPTIONS and UBSAN_OPTIONS
to color=never to avoid problems checking against output patterns, in
test configurations where the output is otherwise coloured by default.

This does not however cover all sanitizer tests with issues in such
configurations.  There is no corresponding logic to set TSAN_OPTIONS
for tsan tests, and environment variable settings in
dg-set-target-env-var override the globally set color=never.

Add logic to set TSAN_OPTIONS similarly (following the UBSAN_OPTIONS
logic, that saves and restores any previous setting or lack thereof,
rather than the ASAN_OPTIONS logic, that just sets ASAN_OPTIONS in the
environment so that it remains set for all the rest of the possibly
unrelated tests included in the same runtest execution).  Also add
color=never to dg-set-target-env-var in two such tests where I've seen
coloured output causing failures (but not for other tests where I
haven't seen the default producing such fallures).

Tested for x86_64-pc-linux-gnu, and with a cross to aarch64-linux
(together with other testsuite fixes) in a configuration where I
previously saw failures related to colour output from sanitizer tests.

* lib/tsan-dg.exp (orig_tsan_options_saved, orig_tsan_options):
New global variables.
(tsan_init): Save TSAN_OPTIONS and set it to color=never.
(tsan_finish): Restore TSAN_OPTIONS.
* c-c++-common/asan/pr64820.c: Include color=never in
ASAN_OPTIONS.
* c-c++-common/asan/use-after-return-1.c: Likewise.

gcc/testsuite/c-c++-common/asan/pr64820.c
gcc/testsuite/c-c++-common/asan/use-after-return-1.c
gcc/testsuite/lib/tsan-dg.exp

index a00debf358833ef8de1f2b6ba9d50a2d68c86296..b675ef21b275c8f791a8fe979d5f23bab431bb0c 100644 (file)
@@ -1,7 +1,7 @@
 /* { dg-do run } */
 /* { dg-require-effective-target fstack_protector } */
 /* { dg-options "-fstack-protector-strong" } */
-/* { dg-set-target-env-var ASAN_OPTIONS "detect_stack_use_after_return=1" } */
+/* { dg-set-target-env-var ASAN_OPTIONS "color=never detect_stack_use_after_return=1" } */
 /* { dg-shouldfail "asan" } */
 
 __attribute__((noinline))
index e1bb18a574319b3ecde14af53eb1d2730608ba88..557a687e0e32f45d084fbd6d3926a082987c00bb 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do run } */
-/* { dg-set-target-env-var ASAN_OPTIONS "detect_stack_use_after_return=1" } */
+/* { dg-set-target-env-var ASAN_OPTIONS "color=never detect_stack_use_after_return=1" } */
 /* { dg-shouldfail "asan" } */
 
 #include <stdio.h>
index 916c8737807e15158611afd7c9f5452e33c2cec6..6379d18e6b5468e507f7c4bda39cbbf2fc4f9610 100644 (file)
@@ -81,6 +81,9 @@ proc tsan_link_flags { paths } {
     return "$flags"
 }
 
+set orig_tsan_options_saved 0
+set orig_tsan_options 0
+
 #
 # tsan_init -- called at the start of each subdir of tests
 #
@@ -93,6 +96,17 @@ proc tsan_init { args } {
     global tsan_saved_ALWAYS_CXXFLAGS
     global dg-do-what-default
     global tsan_saved_dg-do-what-default
+    global orig_tsan_options_saved
+    global orig_tsan_options
+
+    if { $orig_tsan_options_saved == 0 } {
+       # Save the original environment.
+       if [info exists env(TSAN_OPTIONS)] {
+           set orig_tsan_options "$env(TSAN_OPTIONS)"
+           set orig_tsan_options_saved 1
+       }
+    }
+    setenv TSAN_OPTIONS color=never
 
     set link_flags ""
     if ![is_remote host] {
@@ -134,6 +148,14 @@ proc tsan_finish { args } {
     global tsan_saved_dg-do-what-default
     global tsan_saved_library_path
     global ld_library_path
+    global orig_tsan_options_saved
+    global orig_tsan_options
+
+    if { $orig_tsan_options_saved } {
+       setenv TSAN_OPTIONS "$orig_tsan_options"
+    } elseif [info exists env(TSAN_OPTIONS)] {
+       unsetenv TSAN_OPTIONS
+    }
 
     if [info exists tsan_saved_ALWAYS_CXXFLAGS ] {
        set ALWAYS_CXXFLAGS $tsan_saved_ALWAYS_CXXFLAGS