TestingLibcxx.rst 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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:: libcxx_library=<path/to/libc++.so>
  78. Specify the libc++ library that is tested. By default the library in the
  79. build directory is used. This option cannot be used when use_system_lib is
  80. provided.
  81. .. option:: use_system_lib=<bool>
  82. **Default**: False
  83. Enable or disable testing against the installed version of libc++ library.
  84. Note: This does not use the installed headers.
  85. .. option:: use_lit_shell=<bool>
  86. Enable or disable the use of LIT's internal shell in ShTests. If the
  87. environment variable LIT_USE_INTERNAL_SHELL is present then that is used as
  88. the default value. Otherwise the default value is True on Windows and False
  89. on every other platform.
  90. .. option:: no_default_flags=<bool>
  91. **Default**: False
  92. Disable all default compile and link flags from being added. When this
  93. option is used only flags specified using the compile_flags and link_flags
  94. will be used.
  95. .. option:: compile_flags="<list-of-args>"
  96. Specify additional compile flags as a space delimited string.
  97. Note: This options should not be used to change the standard version used.
  98. .. option:: link_flags="<list-of-args>"
  99. Specify additional link flags as a space delimited string.
  100. .. option:: debug_level=<level>
  101. **Values**: 0, 1
  102. Enable the use of debug mode. Level 0 enables assertions and level 1 enables
  103. assertions and debugging of iterator misuse.
  104. .. option:: use_sanitizer=<sanitizer name>
  105. **Values**: Memory, MemoryWithOrigins, Address, Undefined
  106. Run the tests using the given sanitizer. If LLVM_USE_SANITIZER was given when
  107. building libc++ then that sanitizer will be used by default.
  108. .. option:: color_diagnostics
  109. Enable the use of colorized compile diagnostics. If the color_diagnostics
  110. option is specified or the environment variable LIBCXX_COLOR_DIAGNOSTICS is
  111. present then color diagnostics will be enabled.
  112. Environment Variables
  113. ---------------------
  114. .. envvar:: LIBCXX_SITE_CONFIG=<path/to/lit.site.cfg>
  115. Specify the site configuration to use when running the tests.
  116. Also see :option:`libcxx_site_config`.
  117. .. envvar:: LIBCXX_COLOR_DIAGNOSTICS
  118. If ``LIBCXX_COLOR_DIAGNOSTICS`` is defined then the test suite will attempt
  119. to use color diagnostic outputs from the compiler.
  120. Also see :option:`color_diagnostics`.