TestingLibcxx.rst 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. ==============
  2. Testing libc++
  3. ==============
  4. .. contents::
  5. :local:
  6. Getting Started
  7. ===============
  8. libc++ uses LIT to configure and run its tests. The primary way to run the
  9. libc++ tests is by using make check-libcxx. However since libc++ can be used
  10. in any number of possible configurations it is important to customize the way
  11. LIT builds and runs the tests. This guide provides information on how to use
  12. LIT directly to test libc++.
  13. Please see the `Lit Command Guide`_ for more information about LIT.
  14. .. _LIT Command Guide: http://llvm.org/docs/CommandGuide/lit.html
  15. Setting up the Environment
  16. --------------------------
  17. After building libc++ you must setup your environment to test libc++ using
  18. LIT.
  19. #. Create a shortcut to the actual lit executable so that you can invoke it
  20. easily from the command line.
  21. .. code-block:: bash
  22. $ alias lit='python path/to/llvm/utils/lit/lit.py'
  23. #. Tell LIT where to find your build configuration.
  24. .. code-block:: bash
  25. $ export LIBCXX_SITE_CONFIG=path/to/build-libcxx/test/lit.site.cfg
  26. Example Usage
  27. -------------
  28. Once you have your environment set up and you have built libc++ you can run
  29. parts of the libc++ test suite by simply running `lit` on a specified test or
  30. directory. For example:
  31. .. code-block:: bash
  32. $ cd path/to/src/libcxx
  33. $ lit -sv test/std/re # Run all of the std::regex tests
  34. $ lit -sv test/std/depr/depr.c.headers/stdlib_h.pass.cpp # Run a single test
  35. $ lit -sv test/std/atomics test/std/threads # Test std::thread and std::atomic
  36. Sometimes you'll want to change the way LIT is running the tests. Custom options
  37. can be specified using the `--param=<name>=<val>` flag. The most common option
  38. you'll want to change is the standard dialect (ie -std=c++XX). By default the
  39. test suite will select the newest C++ dialect supported by the compiler and use
  40. that. However if you want to manually specify the option like so:
  41. .. code-block:: bash
  42. $ lit -sv test/std/containers # Run the tests with the newest -std
  43. $ lit -sv --param=std=c++03 test/std/containers # Run the tests in C++03
  44. Occasionally you'll want to add extra compile or link flags when testing.
  45. You can do this as follows:
  46. .. code-block:: bash
  47. $ lit -sv --param=compile_flags='-Wcustom-warning'
  48. $ lit -sv --param=link_flags='-L/custom/library/path'
  49. Some other common examples include:
  50. .. code-block:: bash
  51. # Specify a custom compiler.
  52. $ lit -sv --param=cxx_under_test=/opt/bin/g++ test/std
  53. # Enable warnings in the test suite
  54. $ lit -sv --param=enable_warnings=true test/std
  55. # Use UBSAN when running the tests.
  56. $ lit -sv --param=use_sanitizer=Undefined
  57. LIT Options
  58. ===========
  59. :program:`lit` [*options*...] [*filenames*...]
  60. Command Line Options
  61. --------------------
  62. To use these options you pass them on the LIT command line as --param NAME or
  63. --param NAME=VALUE. Some options have default values specified during CMake's
  64. configuration. Passing the option on the command line will override the default.
  65. .. program:: lit
  66. .. option:: --cxx_under_test=<path/to/compiler>
  67. Specify the compiler used to build the tests.
  68. .. option:: std=<standard version>
  69. **Values**: c++98, c++03, c++11, c++14, c++1z
  70. Change the standard version used when building the tests.
  71. .. option:: --libcxx_site_config=<path/to/lit.site.cfg>
  72. Specify the site configuration to use when running the tests. This option
  73. overrides the enviroment variable LIBCXX_SITE_CONFIG.
  74. .. option:: --libcxx_headers=<path/to/headers>
  75. Specify the libc++ headers that are tested. By default the headers in the
  76. source tree are used.
  77. .. option:: --cxx_library_root=<path/to/lib/>
  78. Specify the directory of the libc++ library to be tested. By default the
  79. library folder of the build directory is used. This option cannot be used
  80. when use_system_lib is provided.
  81. .. option:: --cxx_runtime_root=<path/to/lib/>
  82. Specify the directory of the libc++ library to use at runtime. This directory
  83. is not added to the linkers search path. This can be used to compile tests
  84. against one version of libc++ and run them using another. The default value
  85. for this option is `cxx_library_root`. This option cannot be used
  86. when use_system_lib is provided.
  87. .. option:: --use_system_lib=<bool>
  88. **Default**: False
  89. Enable or disable testing against the installed version of libc++ library.
  90. Note: This does not use the installed headers.
  91. .. option:: --use_lit_shell=<bool>
  92. Enable or disable the use of LIT's internal shell in ShTests. If the
  93. environment variable LIT_USE_INTERNAL_SHELL is present then that is used as
  94. the default value. Otherwise the default value is True on Windows and False
  95. on every other platform.
  96. .. option:: --no_default_flags=<bool>
  97. **Default**: False
  98. Disable all default compile and link flags from being added. When this
  99. option is used only flags specified using the compile_flags and link_flags
  100. will be used.
  101. .. option:: --compile_flags="<list-of-args>"
  102. Specify additional compile flags as a space delimited string.
  103. Note: This options should not be used to change the standard version used.
  104. .. option:: --link_flags="<list-of-args>"
  105. Specify additional link flags as a space delimited string.
  106. .. option:: --debug_level=<level>
  107. **Values**: 0, 1
  108. Enable the use of debug mode. Level 0 enables assertions and level 1 enables
  109. assertions and debugging of iterator misuse.
  110. .. option:: use_sanitizer=<sanitizer name>
  111. **Values**: Memory, MemoryWithOrigins, Address, Undefined
  112. Run the tests using the given sanitizer. If LLVM_USE_SANITIZER was given when
  113. building libc++ then that sanitizer will be used by default.
  114. .. option:: color_diagnostics
  115. Enable the use of colorized compile diagnostics. If the color_diagnostics
  116. option is specified or the environment variable LIBCXX_COLOR_DIAGNOSTICS is
  117. present then color diagnostics will be enabled.
  118. Environment Variables
  119. ---------------------
  120. .. envvar:: LIBCXX_SITE_CONFIG=<path/to/lit.site.cfg>
  121. Specify the site configuration to use when running the tests.
  122. Also see :option:`libcxx_site_config`.
  123. .. envvar:: LIBCXX_COLOR_DIAGNOSTICS
  124. If ``LIBCXX_COLOR_DIAGNOSTICS`` is defined then the test suite will attempt
  125. to use color diagnostic outputs from the compiler.
  126. Also see :option:`color_diagnostics`.
  127. Benchmarks
  128. ==========
  129. Libc++ contains benchmark tests separately from the test of the test suite.
  130. The benchmarks are written using the `Google Benchmark`_ library, a copy of which
  131. is stored in the libc++ repository.
  132. For more information about using the Google Benchmark library see the
  133. `official documentation <https://github.com/google/benchmark>`_.
  134. .. _`Google Benchmark`: https://github.com/google/benchmark
  135. Building Benchmarks
  136. -------------------
  137. The benchmark tests are not enabled by default. To build the benchmarks
  138. libc++ must be configured using the CMake option ``-DLIBCXX_INCLUDE_BENCHMARKS=ON``.
  139. Then the benchmarks can be built using the ``libcxx-benchmarks`` target.
  140. An example build would look like:
  141. .. code-block:: bash
  142. $ cd build
  143. $ cmake [options] -DLIBCXX_INCLUDE_BENCHMARKS=ON <path to libcxx sources>
  144. $ make libcxx-benchmarks
  145. This will build all of the benchmarks under ``<libcxx-src>/benchmarks`` to be
  146. built against the just-built libc++. The compiled tests are output into
  147. ``build/benchmarks``.
  148. The benchmarks can also be built against the platforms native standard library
  149. using the ``-DLIBCXX_BUILD_BENCHMARKS_NATIVE_STDLIB=ON`` CMake option. This
  150. is useful for comparing the performance of libc++ to other standard libraries.
  151. The compiled benchmarks are named ``<test>.libcxx.out`` if they test libc++ and
  152. ``<test>.native.out`` otherwise.
  153. Also See:
  154. * :ref:`Building Libc++ <build instructions>`
  155. * :ref:`CMake Options`
  156. Running Benchmarks
  157. ------------------
  158. The benchmarks must be run manually by the user. Currently there is no way
  159. to run them as part of the build.
  160. For example:
  161. .. code-block:: bash
  162. $ cd build/benchmarks
  163. $ make libcxx-benchmarks
  164. $ ./algorithms.libcxx.out # Runs all the benchmarks
  165. $ ./algorithms.libcxx.out --benchmark_filter=BM_Sort.* # Only runs the sort benchmarks
  166. For more information about running benchmarks see `Google Benchmark`_.