[libcxx-commits] [libcxx] 7ad8e19 - [libc++] Move the GDB pretty printer tests to the DSL

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Nov 16 13:17:04 PST 2020


Author: Louis Dionne
Date: 2020-11-16T16:16:39-05:00
New Revision: 7ad8e19958b271b9369e6b9d8d76f2f9f1beeb90

URL: https://github.com/llvm/llvm-project/commit/7ad8e19958b271b9369e6b9d8d76f2f9f1beeb90
DIFF: https://github.com/llvm/llvm-project/commit/7ad8e19958b271b9369e6b9d8d76f2f9f1beeb90.diff

LOG: [libc++] Move the GDB pretty printer tests to the DSL

Also, enable them whenever we detect that gdb is available. Previously,
these tests would basically never run because they relied on a CMake
configuration option that defaulted to OFF.

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

Added: 
    libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
    libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp

Modified: 
    libcxx/CMakeLists.txt
    libcxx/test/CMakeLists.txt
    libcxx/test/configs/legacy.cfg.in
    libcxx/utils/libcxx/test/config.py
    libcxx/utils/libcxx/test/dsl.py
    libcxx/utils/libcxx/test/features.py

Removed: 
    libcxx/test/pretty_printers/gdb_pretty_printer_test.py
    libcxx/test/pretty_printers/gdb_pretty_printer_test.sh.cpp


################################################################################
diff  --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 8e0864c21db5..840bc5d97a51 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -128,7 +128,6 @@ option(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS
    to provide compile-time errors when using features unavailable on some version of
    the shared library they shipped should turn this on and see `include/__availability`
    for more details." OFF)
-option(LIBCXX_TEST_GDB_PRETTY_PRINTERS "Test gdb pretty printers." OFF)
 set(LIBCXX_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/configs/legacy.cfg.in" CACHE STRING
     "The Lit testing configuration to use when running the tests.")
 set(LIBCXX_TEST_PARAMS "" CACHE STRING

diff  --git a/libcxx/test/CMakeLists.txt b/libcxx/test/CMakeLists.txt
index 4d9f2e5f0017..e9a886964d80 100644
--- a/libcxx/test/CMakeLists.txt
+++ b/libcxx/test/CMakeLists.txt
@@ -91,18 +91,6 @@ if (NOT DEFINED LIBCXX_TEST_DEPS)
   message(FATAL_ERROR "Expected LIBCXX_TEST_DEPS to be defined")
 endif()
 
-# Turn this on by default when the pretty printers are python3
-# compatible.
-if(LIBCXX_TEST_GDB_PRETTY_PRINTERS)
-  find_program(LIBCXX_GDB gdb)
-  if (LIBCXX_GDB)
-    set(LIBCXX_GDB "${LIBCXX_GDB}")
-    message(STATUS "gdb found: ${LIBCXX_GDB}")
-  else()
-    message(STATUS "gdb not found. Disabling dependent tests.")
-  endif()
-endif()
-
 if (LIBCXX_INCLUDE_TESTS)
   include(AddLLVM) # for configure_lit_site_cfg and add_lit_target
 

diff  --git a/libcxx/test/configs/legacy.cfg.in b/libcxx/test/configs/legacy.cfg.in
index f0a4e8a73e09..c8c6855140c0 100644
--- a/libcxx/test/configs/legacy.cfg.in
+++ b/libcxx/test/configs/legacy.cfg.in
@@ -38,7 +38,6 @@ config.libcxxabi_shared         = @LIBCXX_LINK_TESTS_WITH_SHARED_LIBCXXABI@
 config.cxx_ext_threads          = @LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY@
 config.pstl_src_root            = "@ParallelSTL_SOURCE_DIR@" if @LIBCXX_ENABLE_PARALLEL_ALGORITHMS@ else None
 config.pstl_obj_root            = "@ParallelSTL_BINARY_DIR@" if @LIBCXX_ENABLE_PARALLEL_ALGORITHMS@ else None
-config.libcxx_gdb               = "@LIBCXX_GDB@"
 
 # Code signing
 config.llvm_codesign_identity   = "@LLVM_CODESIGNING_IDENTITY@"

diff  --git a/libcxx/test/pretty_printers/gdb_pretty_printer_test.py b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
similarity index 100%
rename from libcxx/test/pretty_printers/gdb_pretty_printer_test.py
rename to libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py

diff  --git a/libcxx/test/pretty_printers/gdb_pretty_printer_test.sh.cpp b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
similarity index 97%
rename from libcxx/test/pretty_printers/gdb_pretty_printer_test.sh.cpp
rename to libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
index 540db56478e4..fed6a1618483 100644
--- a/libcxx/test/pretty_printers/gdb_pretty_printer_test.sh.cpp
+++ b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
@@ -6,11 +6,14 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
-// REQUIRES: libcxx_gdb
-//
+
+// REQUIRES: host-has-gdb
+// UNSUPPORTED: libcpp-has-no-localization
+// UNSUPPORTED: c++03
+
 // RUN: %{cxx} %{flags} %s -o %t.exe %{compile_flags} -g %{link_flags}
 // Ensure locale-independence for unicode tests.
-// RUN: %{libcxx_gdb} -nx -batch -iex "set autoload off" -ex "source %S/../../utils/gdb/libcxx/printers.py" -ex "python register_libcxx_printer_loader()" -ex "source %S/gdb_pretty_printer_test.py" %t.exe
+// RUN: %{gdb} -nx -batch -iex "set autoload off" -ex "source %S/../../../utils/gdb/libcxx/printers.py" -ex "python register_libcxx_printer_loader()" -ex "source %S/gdb_pretty_printer_test.py" %t.exe
 
 #include <bitset>
 #include <deque>
@@ -60,15 +63,15 @@
 #else
 #define OPT_NONE __attribute__((optnone))
 #endif
-void StopForDebugger(void *value, void *check) OPT_NONE;
-void StopForDebugger(void *value, void *check)  {}
+void StopForDebugger(void *, void *) OPT_NONE;
+void StopForDebugger(void *, void *)  {}
 
 
 // Prevents the compiler optimizing away the parameter in the caller function.
 template <typename Type>
-void MarkAsLive(Type &&t) OPT_NONE;
+void MarkAsLive(Type &&) OPT_NONE;
 template <typename Type>
-void MarkAsLive(Type &&t) {}
+void MarkAsLive(Type &&) {}
 
 // In all of the Compare(Expression)PrettyPrintTo(Regex/Chars) functions below,
 // the python script sets a breakpoint just before the call to StopForDebugger,
@@ -643,7 +646,7 @@ void streampos_test() {
       test1, "std::fpos with stream offset:5 with state: {count:0 value:0}");
 }
 
-int main(int argc, char* argv[]) {
+int main(int, char**) {
   framework_self_test();
 
   string_test();

diff  --git a/libcxx/utils/libcxx/test/config.py b/libcxx/utils/libcxx/test/config.py
index ca0385a16977..a10d4392c170 100644
--- a/libcxx/utils/libcxx/test/config.py
+++ b/libcxx/utils/libcxx/test/config.py
@@ -247,11 +247,6 @@ def configure_features(self):
                 # using this feature. (Also see llvm.org/PR32730)
                 self.config.available_features.add('LIBCXX-WINDOWS-FIXME')
 
-        libcxx_gdb = self.get_lit_conf('libcxx_gdb')
-        if libcxx_gdb and 'NOTFOUND' not in libcxx_gdb:
-            self.config.available_features.add('libcxx_gdb')
-            self.cxx.libcxx_gdb = libcxx_gdb
-
         target_triple = getattr(self.config, 'target_triple', None)
         if target_triple:
             if re.match(r'^x86_64.*-apple', target_triple):
@@ -599,8 +594,6 @@ def configure_substitutions(self):
             '--env {}'.format(env_vars)
         ]
         sub.append(('%{exec}', '{} {} -- '.format(self.executor, ' '.join(exec_args))))
-        if self.get_lit_conf('libcxx_gdb'):
-            sub.append(('%{libcxx_gdb}', self.get_lit_conf('libcxx_gdb')))
 
     def configure_triple(self):
         # Get or infer the target triple.

diff  --git a/libcxx/utils/libcxx/test/dsl.py b/libcxx/utils/libcxx/test/dsl.py
index 93722a14685a..012d13aa2d77 100644
--- a/libcxx/utils/libcxx/test/dsl.py
+++ b/libcxx/utils/libcxx/test/dsl.py
@@ -350,6 +350,26 @@ def pretty(self, config, litParams):
     return 'add {} to %{{compile_flags}}'.format(self._getFlag(config))
 
 
+class AddSubstitution(ConfigAction):
+  """
+  This action adds the given substitution to the Lit configuration.
+
+  The substitution can be a string or a callable, in which case it is called
+  with the configuration to produce the actual substitution (as a string).
+  """
+  def __init__(self, key, substitution):
+    self._key = key
+    self._getSub = lambda config: substitution(config) if callable(substitution) else substitution
+
+  def applyTo(self, config):
+    key = self._key
+    sub = self._getSub(config)
+    config.substitutions.append((key, sub))
+
+  def pretty(self, config, litParams):
+    return 'add substitution {} = {}'.format(self._key, self._getSub(config))
+
+
 class Feature(object):
   """
   Represents a Lit available feature that is enabled whenever it is supported.

diff  --git a/libcxx/utils/libcxx/test/features.py b/libcxx/utils/libcxx/test/features.py
index 51f9296c31f8..f78db66f49ad 100644
--- a/libcxx/utils/libcxx/test/features.py
+++ b/libcxx/utils/libcxx/test/features.py
@@ -8,6 +8,7 @@
 
 from libcxx.test.dsl import *
 import re
+import shutil
 import sys
 
 _isClang      = lambda cfg: '__clang__' in compilerMacros(cfg) and '__apple_build_version__' not in compilerMacros(cfg)
@@ -131,6 +132,15 @@
 ]
 
 
+# Detect whether GDB is on the system, and if so add a substitution to access it.
+DEFAULT_FEATURES += [
+  Feature(name='host-has-gdb',
+    when=lambda cfg: shutil.which('gdb') is not None,
+    actions=[AddSubstitution('%{gdb}', lambda cfg: shutil.which('gdb'))]
+  )
+]
+
+
 # When vendor-specific availability annotations are enabled, add Lit features
 # with various forms of the target triple to make it easier to write XFAIL or
 # UNSUPPORTED markup for tests that are known to fail on a particular triple.


        


More information about the libcxx-commits mailing list