[asan][test] Fix tests or mark XFAIL for MinGW target
authorAlvin Wong <alvin@alvinhc.com>
Tue, 28 Mar 2023 09:03:10 +0000 (17:03 +0800)
committerAlvin Wong <alvin@alvinhc.com>
Sat, 1 Apr 2023 17:06:15 +0000 (01:06 +0800)
After this change, `check-asan-dynamic` should pass on x86_64 MinGW
target, using the llvm-mingw toolchain.

The following is a list of issues fixed:

* `asan_str_test.cpp`: Exclude unintercepted functions on MinGW.
* `asan_test.cpp`: Work around regex limitation of gtest on Windows,
  which only affects MinGW target because `long double` has different
  size to `double`.
* `TestCases/Windows/report_after_syminitialize.cpp`: Added  build
  command specifically for MinGW.
* Other tests: Mark XFAIL for various reasons. Some of them need
  further investigation.

Differential Revision: https://reviews.llvm.org/D147059

20 files changed:
compiler-rt/lib/asan/tests/asan_str_test.cpp
compiler-rt/lib/asan/tests/asan_test.cpp
compiler-rt/lib/sanitizer_common/tests/sanitizer_test_utils.h
compiler-rt/test/asan/TestCases/Windows/coverage-basic.cpp
compiler-rt/test/asan/TestCases/Windows/report_after_syminitialize.cpp
compiler-rt/test/asan/TestCases/atexit_stats.cpp
compiler-rt/test/asan/TestCases/atoll_strict.c
compiler-rt/test/asan/TestCases/frexpl_interceptor.cpp
compiler-rt/test/asan/TestCases/global-location.cpp
compiler-rt/test/asan/TestCases/heavy_uar_test.cpp
compiler-rt/test/asan/TestCases/init-order-atexit.cpp
compiler-rt/test/asan/TestCases/printf-2.c
compiler-rt/test/asan/TestCases/printf-3.c
compiler-rt/test/asan/TestCases/printf-5.c
compiler-rt/test/asan/TestCases/strcasestr-1.c
compiler-rt/test/asan/TestCases/strcasestr-2.c
compiler-rt/test/asan/TestCases/strcasestr_strict.c
compiler-rt/test/asan/TestCases/strncasecmp_strict.c
compiler-rt/test/asan/TestCases/strtoll_strict.c
compiler-rt/test/asan/TestCases/time_interceptor.cpp

index 1bf6c35..8b1c1dc 100644 (file)
@@ -110,8 +110,16 @@ TEST(AddressSanitizer, WcsLenTest) {
 }
 #endif
 
+// This test fails on MinGW-w64 because it still ships a static copy of strnlen
+// despite it being available from UCRT.
+#if defined(__MINGW32__)
+#  define MAYBE_StrNLenOOBTest DISABLED_StrNLenOOBTest
+#else
+#  define MAYBE_StrNLenOOBTest StrNLenOOBTest
+#endif
+
 #if SANITIZER_TEST_HAS_STRNLEN
-TEST(AddressSanitizer, StrNLenOOBTest) {
+TEST(AddressSanitizer, MAYBE_StrNLenOOBTest) {
   size_t size = Ident(123);
   char *str = MallocAndMemsetString(size);
   // Normal strnlen calls.
@@ -132,10 +140,10 @@ TEST(AddressSanitizer, StrNLenOOBTest) {
 
 // This test fails with the WinASan dynamic runtime because we fail to intercept
 // strdup.
-#if defined(_MSC_VER) && defined(_DLL)
-#define MAYBE_StrDupOOBTest DISABLED_StrDupOOBTest
+#if (defined(_MSC_VER) && defined(_DLL)) || defined(__MINGW32__)
+#  define MAYBE_StrDupOOBTest DISABLED_StrDupOOBTest
 #else
-#define MAYBE_StrDupOOBTest StrDupOOBTest
+#  define MAYBE_StrDupOOBTest StrDupOOBTest
 #endif
 
 TEST(AddressSanitizer, MAYBE_StrDupOOBTest) {
index 40b335d..827c2ae 100644 (file)
@@ -203,8 +203,16 @@ TEST(AddressSanitizer, UAF_char) {
 TEST(AddressSanitizer, UAF_long_double) {
   if (sizeof(long double) == sizeof(double)) return;
   long double *p = Ident(new long double[10]);
+#if defined(_WIN32)
+  // https://google.github.io/googletest/advanced.html#regular-expression-syntax
+  // GoogleTest's regular expression engine on Windows does not support `[]`
+  // brackets.
+  EXPECT_DEATH(Ident(p)[12] = 0, "WRITE of size 10");
+  EXPECT_DEATH(Ident(p)[0] = Ident(p)[12], "READ of size 10");
+#else
   EXPECT_DEATH(Ident(p)[12] = 0, "WRITE of size 1[026]");
   EXPECT_DEATH(Ident(p)[0] = Ident(p)[12], "READ of size 1[026]");
+#endif
   delete [] Ident(p);
 }
 
index 016ce9e..5fd94a0 100644 (file)
@@ -127,8 +127,8 @@ static inline uint32_t my_rand() {
 # define SANITIZER_TEST_HAS_PRINTF_L 0
 #endif
 
-#if !defined(_MSC_VER)
-# define SANITIZER_TEST_HAS_STRNDUP 1
+#if !defined(_WIN32)
+#  define SANITIZER_TEST_HAS_STRNDUP 1
 #else
 # define SANITIZER_TEST_HAS_STRNDUP 0
 #endif
index 163247e..96262ca 100644 (file)
@@ -4,6 +4,10 @@
 // RUN: %env_asan_opts=coverage=1 %run ./test.exe
 //
 // RUN: %sancov print *.sancov | FileCheck %s
+
+// FIXME: Investigate failure on MinGW.
+// XFAIL: target={{.*-windows-gnu}}
+
 #include <stdio.h>
 
 void foo() { fputs("FOO", stderr); }
index 8169663..45bb6f3 100644 (file)
@@ -1,4 +1,14 @@
-// RUN: %clangxx_asan -O0 %s -o %t
+// This test works on both MSVC and MinGW targets, but they require different
+// build commands. By default we use DWARF debug info on MinGW and dbghelp does
+// not support it, so we need to specify extra flags to get the compiler to
+// generate PDB debug info.
+
+// The first build command is intended for MSVC target, which fails on MinGW.
+// The second build command contains the flags required to get PDB debug info
+// on a MinGW build, which fails on MSVC.
+
+// RUN: %clangxx_asan -O0 %s -o %t \
+// RUN: || %clangxx_asan -gcodeview -gcolumn-info -Wl,--pdb= -O0 %s -o %t -ldbghelp
 // RUN: %env_asan_opts=external_symbolizer_path=non-existent\\\\asdf not %run %t 2>&1 | FileCheck %s
 
 #include <windows.h>
index c8d97da..1774385 100644 (file)
@@ -6,6 +6,9 @@
 // https://code.google.com/p/address-sanitizer/issues/detail?id=263
 // UNSUPPORTED: android
 
+// FIXME: Investigate failure on MinGW.
+// XFAIL: target={{.*-windows-gnu}}
+
 #include <stdlib.h>
 #if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__)
 #include <malloc.h>
index f0cf0c6..431ec6b 100644 (file)
@@ -11,7 +11,7 @@
 // RUN: %env_asan_opts=strict_string_checks=true not %run %t test3 2>&1 | FileCheck %s --check-prefix=CHECK3
 
 // FIXME: Needs Windows interceptor.
-// XFAIL: target={{.*windows-msvc.*}}
+// XFAIL: target={{.*windows-(msvc.*|gnu)}}
 
 #include <assert.h>
 #include <stdlib.h>
index 46bb6a2..721eecc 100644 (file)
@@ -2,6 +2,10 @@
 
 // Test the frexpl() interceptor.
 
+// FIXME: MinGW-w64 implements `frexpl()` as a static import, so the dynamic
+// interceptor seems to not work.
+// XFAIL: target={{.*-windows-gnu}}
+
 #include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
index b0e996a..7aa6941 100644 (file)
@@ -7,6 +7,9 @@
 // COFF doesn't support debuginfo for globals. For the non-debuginfo tests, see global-location-nodebug.cpp.
 // XFAIL: target={{.*windows-msvc.*}}
 
+// FIXME: Investigate failure on MinGW
+// XFAIL: target={{.*-windows-gnu}}
+
 // atos doesn't show source line numbers for global variables.
 // UNSUPPORTED: darwin
 
index f1bd0f0..718f9b9 100644 (file)
@@ -4,6 +4,10 @@
 // RUN: %clangxx_asan -O2 %s -o %t -fsanitize-address-use-after-return=always && not %run %t 2>&1 | FileCheck %s
 // XFAIL: target={{.*windows-msvc.*}}
 
+// FIXME: Investigate failure on MinGW. MinGW ASAN produces a different report:
+//        stack-overflow on address
+// XFAIL: target={{.*-windows-gnu}}
+
 // FIXME: Fix this test under GCC.
 // REQUIRES: Clang
 
index 57bddd4..6877076 100644 (file)
@@ -7,6 +7,9 @@
 // RUN: %clangxx_asan -O0 %s %p/Helpers/init-order-atexit-extra.cpp -o %t
 // RUN: %env_asan_opts=strict_init_order=true not %run %t 2>&1 | FileCheck %s
 
+// FIXME: Investigate failure on MinGW
+// XFAIL: target={{.*-windows-gnu}}
+
 #include <stdio.h>
 #include <stdlib.h>
 
index 7fcf430..3ea263d 100644 (file)
@@ -6,7 +6,7 @@
 // RUN: %env_asan_opts=replace_str=0:intercept_strlen=0:replace_intrin=0 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
 
 // FIXME: printf is not intercepted on Windows yet.
-// XFAIL: target={{.*windows-msvc.*}}
+// XFAIL: target={{.*windows-(msvc.*|gnu)}}
 
 #include <stdio.h>
 #include <stdlib.h>
index 805210c..a8ce02e 100644 (file)
@@ -4,7 +4,7 @@
 // RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
 
 // FIXME: printf is not intercepted on Windows yet.
-// XFAIL: target={{.*windows-msvc.*}}
+// XFAIL: target={{.*windows-(msvc.*|gnu)}}
 
 // New Bionic rejects %n
 // https://android.googlesource.com/platform/bionic/+/41398d03b7e8e0dfb951660ae713e682e9fc0336
index 564de39..eef5223 100644 (file)
@@ -5,7 +5,7 @@
 // RUN: %env_asan_opts=replace_intrin=0 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
 
 // FIXME: printf is not intercepted on Windows yet.
-// XFAIL: target={{.*windows-msvc.*}}
+// XFAIL: target={{.*windows-(msvc.*|gnu)}}
 
 #include <stdio.h>
 #include <string.h>
index 8be4b75..9fa4a2b 100644 (file)
@@ -6,7 +6,7 @@
 // RUN: %env_asan_opts=intercept_strstr=false:replace_str=false %run %t 2>&1
 
 // There's no interceptor for strcasestr on Windows
-// XFAIL: target={{.*windows-msvc.*}}
+// XFAIL: target={{.*windows-(msvc.*|gnu)}}
 
 #define _GNU_SOURCE
 #include <assert.h>
index eabe402..920d11e 100644 (file)
@@ -6,7 +6,7 @@
 // RUN: %env_asan_opts=intercept_strstr=false:replace_str=false:intercept_strlen=false %run %t 2>&1
 
 // There's no interceptor for strcasestr on Windows
-// XFAIL: target={{.*windows-msvc.*}}
+// XFAIL: target={{.*windows-(msvc.*|gnu)}}
 
 #define _GNU_SOURCE
 #include <assert.h>
index a6d1087..16efae7 100644 (file)
@@ -4,7 +4,7 @@
 // RUN: %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s
 
 // There's no interceptor for strcasestr on Windows
-// XFAIL: target={{.*windows-msvc.*}}
+// XFAIL: target={{.*windows-(msvc.*|gnu)}}
 
 #define _GNU_SOURCE
 #include <assert.h>
index 24261be..a0bd338 100644 (file)
@@ -14,7 +14,7 @@
 // RUN: %env_asan_opts=strict_string_checks=false %run %t i 2>&1
 // RUN: %env_asan_opts=strict_string_checks=true not %run %t i 2>&1 | FileCheck %s
 
-// XFAIL: target={{.*windows-msvc.*}}
+// XFAIL: target={{.*windows-(msvc.*|gnu)}}
 
 #include <assert.h>
 #include <stdlib.h>
index 88e6651..097412e 100644 (file)
@@ -24,7 +24,7 @@
 
 // FIXME: Enable strtoll interceptor.
 // REQUIRES: shadow-scale-3
-// XFAIL: target={{.*windows-msvc.*}}
+// XFAIL: target={{.*windows-(msvc.*|gnu)}}
 
 #include <assert.h>
 #include <stdlib.h>
index 47acdd5..0c5e3fe 100644 (file)
@@ -2,8 +2,8 @@
 
 // Test the time() interceptor.
 
-// There's no interceptor for time() on Windows yet.
-// XFAIL: target={{.*windows-msvc.*}}
+// FIXME: There's no interceptor for time() on Windows yet.
+// XFAIL: target={{.*windows-(msvc.*|gnu)}}
 
 #include <stdio.h>
 #include <stdlib.h>