annotate libcxx/docs/TestingLibcxx.rst @ 220:42394fc6a535

Added tag llvm12 for changeset 0572611fdcc8
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 15 Jun 2021 19:13:43 +0900
parents 0572611fdcc8
children 2e18cbf3894f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 ==============
anatofuz
parents:
diff changeset
2 Testing libc++
anatofuz
parents:
diff changeset
3 ==============
anatofuz
parents:
diff changeset
4
anatofuz
parents:
diff changeset
5 .. contents::
anatofuz
parents:
diff changeset
6 :local:
anatofuz
parents:
diff changeset
7
anatofuz
parents:
diff changeset
8 Getting Started
anatofuz
parents:
diff changeset
9 ===============
anatofuz
parents:
diff changeset
10
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
11 libc++ uses LIT to configure and run its tests.
150
anatofuz
parents:
diff changeset
12
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
13 The primary way to run the libc++ tests is by using ``make check-cxx``.
150
anatofuz
parents:
diff changeset
14
anatofuz
parents:
diff changeset
15 However since libc++ can be used in any number of possible
anatofuz
parents:
diff changeset
16 configurations it is important to customize the way LIT builds and runs
anatofuz
parents:
diff changeset
17 the tests. This guide provides information on how to use LIT directly to
anatofuz
parents:
diff changeset
18 test libc++.
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20 Please see the `Lit Command Guide`_ for more information about LIT.
anatofuz
parents:
diff changeset
21
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
22 .. _LIT Command Guide: https://llvm.org/docs/CommandGuide/lit.html
150
anatofuz
parents:
diff changeset
23
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
24 Usage
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
25 -----
150
anatofuz
parents:
diff changeset
26
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
27 After building libc++, you can run parts of the libc++ test suite by simply
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
28 running ``llvm-lit`` on a specified test or directory. If you're unsure
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
29 whether the required libraries have been built, you can use the
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
30 `check-cxx-deps` target. For example:
150
anatofuz
parents:
diff changeset
31
anatofuz
parents:
diff changeset
32 .. code-block:: bash
anatofuz
parents:
diff changeset
33
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
34 $ cd <monorepo-root>
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
35 $ make -C <build> check-cxx-deps # If you want to make sure the targets get rebuilt
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
36 $ <build>/bin/llvm-lit -sv libcxx/test/std/re # Run all of the std::regex tests
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
37 $ <build>/bin/llvm-lit -sv libcxx/test/std/depr/depr.c.headers/stdlib_h.pass.cpp # Run a single test
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
38 $ <build>/bin/llvm-lit -sv libcxx/test/std/atomics libcxx/test/std/threads # Test std::thread and std::atomic
150
anatofuz
parents:
diff changeset
39
anatofuz
parents:
diff changeset
40 Sometimes you'll want to change the way LIT is running the tests. Custom options
anatofuz
parents:
diff changeset
41 can be specified using the `--param=<name>=<val>` flag. The most common option
anatofuz
parents:
diff changeset
42 you'll want to change is the standard dialect (ie -std=c++XX). By default the
anatofuz
parents:
diff changeset
43 test suite will select the newest C++ dialect supported by the compiler and use
anatofuz
parents:
diff changeset
44 that. However if you want to manually specify the option like so:
anatofuz
parents:
diff changeset
45
anatofuz
parents:
diff changeset
46 .. code-block:: bash
anatofuz
parents:
diff changeset
47
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
48 $ <build>/bin/llvm-lit -sv libcxx/test/std/containers # Run the tests with the newest -std
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
49 $ <build>/bin/llvm-lit -sv libcxx/test/std/containers --param=std=c++03 # Run the tests in C++03
150
anatofuz
parents:
diff changeset
50
anatofuz
parents:
diff changeset
51 Occasionally you'll want to add extra compile or link flags when testing.
anatofuz
parents:
diff changeset
52 You can do this as follows:
anatofuz
parents:
diff changeset
53
anatofuz
parents:
diff changeset
54 .. code-block:: bash
anatofuz
parents:
diff changeset
55
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
56 $ <build>/bin/llvm-lit -sv libcxx/test --param=compile_flags='-Wcustom-warning'
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
57 $ <build>/bin/llvm-lit -sv libcxx/test --param=link_flags='-L/custom/library/path'
150
anatofuz
parents:
diff changeset
58
anatofuz
parents:
diff changeset
59 Some other common examples include:
anatofuz
parents:
diff changeset
60
anatofuz
parents:
diff changeset
61 .. code-block:: bash
anatofuz
parents:
diff changeset
62
anatofuz
parents:
diff changeset
63 # Specify a custom compiler.
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
64 $ <build>/bin/llvm-lit -sv libcxx/test/std --param=cxx_under_test=/opt/bin/g++
150
anatofuz
parents:
diff changeset
65
anatofuz
parents:
diff changeset
66 # Enable warnings in the test suite
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
67 $ <build>/bin/llvm-lit -sv libcxx/test --param=enable_warnings=true
150
anatofuz
parents:
diff changeset
68
anatofuz
parents:
diff changeset
69 # Use UBSAN when running the tests.
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
70 $ <build>/bin/llvm-lit -sv libcxx/test --param=use_sanitizer=Undefined
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
71
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
72 Using a custom site configuration
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
73 ---------------------------------
150
anatofuz
parents:
diff changeset
74
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
75 By default, the libc++ test suite will use a site configuration that matches
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
76 the current CMake configuration. It does so by generating a ``lit.site.cfg``
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
77 file in the build directory from the ``libcxx/test/lit.site.cfg.in`` template,
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
78 and pointing ``llvm-lit`` (which is a wrapper around ``llvm/utils/lit/lit.py``)
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
79 to that file. So when you're running ``<build>/bin/llvm-lit``, the generated
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
80 ``lit.site.cfg`` file is always loaded first, followed by the actual config in
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
81 ``libcxx/test/lit.cfg``. However, it is sometimes desirable to use a custom
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
82 site configuration. To do that, you can use ``--param=libcxx_site_config`` or
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
83 the ``LIBCXX_SITE_CONFIG`` environment variable to point to the right site
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
84 configuration file. However, you must stop using ``llvm-lit``, or else the
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
85 generated ``lit.site.cfg`` will still be preferred:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
86
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
87 .. code-block:: bash
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
88
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
89 $ LIBCXX_SITE_CONFIG=path/to/your/site/configuration llvm/utils/lit/lit.py -sv ...
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
90
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
91 $ llvm/utils/lit/lit.py -sv ... --param=libcxx_site_config=path/to/your/site/configuration
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
92
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
93 In both of these cases, your custom site configuration should set up the
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
94 ``config`` object in a way that is compatible with what libc++'s ``config.py``
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
95 module expects.
150
anatofuz
parents:
diff changeset
96
anatofuz
parents:
diff changeset
97 LIT Options
anatofuz
parents:
diff changeset
98 ===========
anatofuz
parents:
diff changeset
99
anatofuz
parents:
diff changeset
100 :program:`lit` [*options*...] [*filenames*...]
anatofuz
parents:
diff changeset
101
anatofuz
parents:
diff changeset
102 Command Line Options
anatofuz
parents:
diff changeset
103 --------------------
anatofuz
parents:
diff changeset
104
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
105 To use these options you pass them on the LIT command line as ``--param NAME``
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
106 or ``--param NAME=VALUE``. Some options have default values specified during
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
107 CMake's configuration. Passing the option on the command line will override the
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
108 default.
150
anatofuz
parents:
diff changeset
109
anatofuz
parents:
diff changeset
110 .. program:: lit
anatofuz
parents:
diff changeset
111
anatofuz
parents:
diff changeset
112 .. option:: cxx_under_test=<path/to/compiler>
anatofuz
parents:
diff changeset
113
anatofuz
parents:
diff changeset
114 Specify the compiler used to build the tests.
anatofuz
parents:
diff changeset
115
anatofuz
parents:
diff changeset
116 .. option:: cxx_stdlib_under_test=<stdlib name>
anatofuz
parents:
diff changeset
117
anatofuz
parents:
diff changeset
118 **Values**: libc++, libstdc++
anatofuz
parents:
diff changeset
119
anatofuz
parents:
diff changeset
120 Specify the C++ standard library being tested. Unless otherwise specified
anatofuz
parents:
diff changeset
121 libc++ is used. This option is intended to allow running the libc++ test
anatofuz
parents:
diff changeset
122 suite against other standard library implementations.
anatofuz
parents:
diff changeset
123
anatofuz
parents:
diff changeset
124 .. option:: std=<standard version>
anatofuz
parents:
diff changeset
125
anatofuz
parents:
diff changeset
126 **Values**: c++98, c++03, c++11, c++14, c++17, c++2a
anatofuz
parents:
diff changeset
127
anatofuz
parents:
diff changeset
128 Change the standard version used when building the tests.
anatofuz
parents:
diff changeset
129
anatofuz
parents:
diff changeset
130 .. option:: libcxx_site_config=<path/to/lit.site.cfg>
anatofuz
parents:
diff changeset
131
anatofuz
parents:
diff changeset
132 Specify the site configuration to use when running the tests. This option
anatofuz
parents:
diff changeset
133 overrides the environment variable LIBCXX_SITE_CONFIG.
anatofuz
parents:
diff changeset
134
anatofuz
parents:
diff changeset
135 .. option:: cxx_headers=<path/to/headers>
anatofuz
parents:
diff changeset
136
anatofuz
parents:
diff changeset
137 Specify the c++ standard library headers that are tested. By default the
anatofuz
parents:
diff changeset
138 headers in the source tree are used.
anatofuz
parents:
diff changeset
139
anatofuz
parents:
diff changeset
140 .. option:: cxx_library_root=<path/to/lib/>
anatofuz
parents:
diff changeset
141
anatofuz
parents:
diff changeset
142 Specify the directory of the libc++ library to be tested. By default the
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
143 library folder of the build directory is used.
150
anatofuz
parents:
diff changeset
144
anatofuz
parents:
diff changeset
145
anatofuz
parents:
diff changeset
146 .. option:: cxx_runtime_root=<path/to/lib/>
anatofuz
parents:
diff changeset
147
anatofuz
parents:
diff changeset
148 Specify the directory of the libc++ library to use at runtime. This directory
anatofuz
parents:
diff changeset
149 is not added to the linkers search path. This can be used to compile tests
anatofuz
parents:
diff changeset
150 against one version of libc++ and run them using another. The default value
anatofuz
parents:
diff changeset
151 for this option is `cxx_library_root`.
anatofuz
parents:
diff changeset
152
anatofuz
parents:
diff changeset
153 .. option:: use_system_cxx_lib=<bool>
anatofuz
parents:
diff changeset
154
anatofuz
parents:
diff changeset
155 **Default**: False
anatofuz
parents:
diff changeset
156
anatofuz
parents:
diff changeset
157 Enable or disable testing against the installed version of libc++ library.
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
158 This impacts whether the ``with_system_cxx_lib`` Lit feature is defined or
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
159 not. The ``cxx_library_root`` and ``cxx_runtime_root`` parameters should
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
160 still be used to specify the path of the library to link to and run against,
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
161 respectively.
150
anatofuz
parents:
diff changeset
162
anatofuz
parents:
diff changeset
163 .. option:: use_lit_shell=<bool>
anatofuz
parents:
diff changeset
164
anatofuz
parents:
diff changeset
165 Enable or disable the use of LIT's internal shell in ShTests. If the
anatofuz
parents:
diff changeset
166 environment variable LIT_USE_INTERNAL_SHELL is present then that is used as
anatofuz
parents:
diff changeset
167 the default value. Otherwise the default value is True on Windows and False
anatofuz
parents:
diff changeset
168 on every other platform.
anatofuz
parents:
diff changeset
169
anatofuz
parents:
diff changeset
170 .. option:: compile_flags="<list-of-args>"
anatofuz
parents:
diff changeset
171
anatofuz
parents:
diff changeset
172 Specify additional compile flags as a space delimited string.
anatofuz
parents:
diff changeset
173 Note: This options should not be used to change the standard version used.
anatofuz
parents:
diff changeset
174
anatofuz
parents:
diff changeset
175 .. option:: link_flags="<list-of-args>"
anatofuz
parents:
diff changeset
176
anatofuz
parents:
diff changeset
177 Specify additional link flags as a space delimited string.
anatofuz
parents:
diff changeset
178
anatofuz
parents:
diff changeset
179 .. option:: debug_level=<level>
anatofuz
parents:
diff changeset
180
anatofuz
parents:
diff changeset
181 **Values**: 0, 1
anatofuz
parents:
diff changeset
182
anatofuz
parents:
diff changeset
183 Enable the use of debug mode. Level 0 enables assertions and level 1 enables
anatofuz
parents:
diff changeset
184 assertions and debugging of iterator misuse.
anatofuz
parents:
diff changeset
185
anatofuz
parents:
diff changeset
186 .. option:: use_sanitizer=<sanitizer name>
anatofuz
parents:
diff changeset
187
anatofuz
parents:
diff changeset
188 **Values**: Memory, MemoryWithOrigins, Address, Undefined
anatofuz
parents:
diff changeset
189
anatofuz
parents:
diff changeset
190 Run the tests using the given sanitizer. If LLVM_USE_SANITIZER was given when
anatofuz
parents:
diff changeset
191 building libc++ then that sanitizer will be used by default.
anatofuz
parents:
diff changeset
192
anatofuz
parents:
diff changeset
193 .. option:: llvm_unwinder
anatofuz
parents:
diff changeset
194
anatofuz
parents:
diff changeset
195 Enable the use of LLVM unwinder instead of libgcc.
anatofuz
parents:
diff changeset
196
anatofuz
parents:
diff changeset
197 .. option:: builtins_library
anatofuz
parents:
diff changeset
198
anatofuz
parents:
diff changeset
199 Path to the builtins library to use instead of libgcc.
anatofuz
parents:
diff changeset
200
anatofuz
parents:
diff changeset
201
anatofuz
parents:
diff changeset
202 Environment Variables
anatofuz
parents:
diff changeset
203 ---------------------
anatofuz
parents:
diff changeset
204
anatofuz
parents:
diff changeset
205 .. envvar:: LIBCXX_SITE_CONFIG=<path/to/lit.site.cfg>
anatofuz
parents:
diff changeset
206
anatofuz
parents:
diff changeset
207 Specify the site configuration to use when running the tests.
anatofuz
parents:
diff changeset
208 Also see `libcxx_site_config`.
anatofuz
parents:
diff changeset
209
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
210 Writing Tests
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
211 -------------
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
212
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
213 When writing tests for the libc++ test suite, you should follow a few guidelines.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
214 This will ensure that your tests can run on a wide variety of hardware and under
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
215 a wide variety of configurations. We have several unusual configurations such as
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
216 building the tests on one host but running them on a different host, which add a
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
217 few requirements to the test suite. Here's some stuff you should know:
150
anatofuz
parents:
diff changeset
218
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
219 - All tests are run in a temporary directory that is unique to that test and
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
220 cleaned up after the test is done.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
221 - When a test needs data files as inputs, these data files can be saved in the
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
222 repository (when reasonable) and referrenced by the test as
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
223 ``// FILE_DEPENDENCIES: <path-to-dependencies>``. Copies of these files or
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
224 directories will be made available to the test in the temporary directory
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
225 where it is run.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
226 - You should never hardcode a path from the build-host in a test, because that
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
227 path will not necessarily be available on the host where the tests are run.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
228 - You should try to reduce the runtime dependencies of each test to the minimum.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
229 For example, requiring Python to run a test is bad, since Python is not
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
230 necessarily available on all devices we may want to run the tests on (even
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
231 though supporting Python is probably trivial for the build-host).
150
anatofuz
parents:
diff changeset
232
anatofuz
parents:
diff changeset
233 Benchmarks
anatofuz
parents:
diff changeset
234 ==========
anatofuz
parents:
diff changeset
235
anatofuz
parents:
diff changeset
236 Libc++ contains benchmark tests separately from the test of the test suite.
anatofuz
parents:
diff changeset
237 The benchmarks are written using the `Google Benchmark`_ library, a copy of which
anatofuz
parents:
diff changeset
238 is stored in the libc++ repository.
anatofuz
parents:
diff changeset
239
anatofuz
parents:
diff changeset
240 For more information about using the Google Benchmark library see the
anatofuz
parents:
diff changeset
241 `official documentation <https://github.com/google/benchmark>`_.
anatofuz
parents:
diff changeset
242
anatofuz
parents:
diff changeset
243 .. _`Google Benchmark`: https://github.com/google/benchmark
anatofuz
parents:
diff changeset
244
anatofuz
parents:
diff changeset
245 Building Benchmarks
anatofuz
parents:
diff changeset
246 -------------------
anatofuz
parents:
diff changeset
247
anatofuz
parents:
diff changeset
248 The benchmark tests are not built by default. The benchmarks can be built using
anatofuz
parents:
diff changeset
249 the ``cxx-benchmarks`` target.
anatofuz
parents:
diff changeset
250
anatofuz
parents:
diff changeset
251 An example build would look like:
anatofuz
parents:
diff changeset
252
anatofuz
parents:
diff changeset
253 .. code-block:: bash
anatofuz
parents:
diff changeset
254
anatofuz
parents:
diff changeset
255 $ cd build
anatofuz
parents:
diff changeset
256 $ cmake [options] <path to libcxx sources>
anatofuz
parents:
diff changeset
257 $ make cxx-benchmarks
anatofuz
parents:
diff changeset
258
anatofuz
parents:
diff changeset
259 This will build all of the benchmarks under ``<libcxx-src>/benchmarks`` to be
anatofuz
parents:
diff changeset
260 built against the just-built libc++. The compiled tests are output into
anatofuz
parents:
diff changeset
261 ``build/benchmarks``.
anatofuz
parents:
diff changeset
262
anatofuz
parents:
diff changeset
263 The benchmarks can also be built against the platforms native standard library
anatofuz
parents:
diff changeset
264 using the ``-DLIBCXX_BUILD_BENCHMARKS_NATIVE_STDLIB=ON`` CMake option. This
anatofuz
parents:
diff changeset
265 is useful for comparing the performance of libc++ to other standard libraries.
anatofuz
parents:
diff changeset
266 The compiled benchmarks are named ``<test>.libcxx.out`` if they test libc++ and
anatofuz
parents:
diff changeset
267 ``<test>.native.out`` otherwise.
anatofuz
parents:
diff changeset
268
anatofuz
parents:
diff changeset
269 Also See:
anatofuz
parents:
diff changeset
270
anatofuz
parents:
diff changeset
271 * :ref:`Building Libc++ <build instructions>`
anatofuz
parents:
diff changeset
272 * :ref:`CMake Options`
anatofuz
parents:
diff changeset
273
anatofuz
parents:
diff changeset
274 Running Benchmarks
anatofuz
parents:
diff changeset
275 ------------------
anatofuz
parents:
diff changeset
276
anatofuz
parents:
diff changeset
277 The benchmarks must be run manually by the user. Currently there is no way
anatofuz
parents:
diff changeset
278 to run them as part of the build.
anatofuz
parents:
diff changeset
279
anatofuz
parents:
diff changeset
280 For example:
anatofuz
parents:
diff changeset
281
anatofuz
parents:
diff changeset
282 .. code-block:: bash
anatofuz
parents:
diff changeset
283
anatofuz
parents:
diff changeset
284 $ cd build/benchmarks
anatofuz
parents:
diff changeset
285 $ make cxx-benchmarks
anatofuz
parents:
diff changeset
286 $ ./algorithms.libcxx.out # Runs all the benchmarks
anatofuz
parents:
diff changeset
287 $ ./algorithms.libcxx.out --benchmark_filter=BM_Sort.* # Only runs the sort benchmarks
anatofuz
parents:
diff changeset
288
anatofuz
parents:
diff changeset
289 For more information about running benchmarks see `Google Benchmark`_.