Skip to content

Commit a5edbf3

Browse files
authored
Merge pull request #10758 from gottesmm/convert_testingrst_to_markdown
2 parents 0b0d221 + 2289e5c commit a5edbf3

File tree

1 file changed

+33
-84
lines changed

1 file changed

+33
-84
lines changed

docs/Testing.rst renamed to docs/Testing.md

Lines changed: 33 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
1-
:orphan:
21

3-
.. @raise litre.TestsAreMissing
4-
5-
=============
6-
Testing Swift
7-
=============
2+
# Testing Swift
83

94
This document describes how we test the Swift compiler, the Swift runtime, and
105
the Swift standard library.
116

12-
Testing approaches
13-
==================
7+
## Testing approaches
148

159
We use multiple approaches to test the Swift toolchain.
1610

1711
* LLVM lit-based testsuites for the compiler, runtime and the standard library.
18-
1912
* Unit tests for sub-tools.
20-
2113
* A selection of open source projects written in Swift.
2214

23-
The LLVM lit-based testsuite
24-
============================
15+
## The LLVM lit-based testsuite
2516

2617
**Purpose**: primary testsuites for the Swift toolchain.
2718

@@ -32,27 +23,21 @@ The LLVM lit-based testsuite
3223
* Engineers and contributors are expected to run tests from these testsuites
3324
locally before committing. (Usually on a single platform, and not necessarily
3425
all tests.)
35-
3626
* Buildbots run all tests, on all supported platforms.
3727

38-
Testsuite subsets
39-
-----------------
28+
### Testsuite subsets
4029

4130
The testsuite is split into four subsets:
4231

4332
* Primary testsuite, located under ``swift/test``.
44-
4533
* Validation testsuite, located under ``swift/validation-test``.
46-
4734
* Unit tests, located under ``swift/unittests``.
48-
4935
* Long tests, which are marked with ``REQUIRES: long_test``.
5036

51-
Unlike other tests, every long test should also include either
52-
``REQUIRES: nonexecutable_test`` or ``REQUIRES: executable_test``.
37+
Unlike other tests, every long test should also include either
38+
``REQUIRES: nonexecutable_test`` or ``REQUIRES: executable_test``.
5339

54-
Running the LLVM lit-based testsuite
55-
------------------------------------
40+
### Running the LLVM lit-based testsuite
5641

5742
It is recommended that you run the Swift test suites via ``utils/build-script``.
5843
For day-to-day work on the Swift compiler, using ``utils/build-script --test``
@@ -68,66 +53,45 @@ technically possible to execute the tests directly via CMake. For example, if yo
6853
built Swift products at the directory ``build/Ninja-ReleaseAssert/swift-macosx-x86_64``,
6954
you may run the entire test suite directly using the following command:
7055

71-
.. code-block:: bash
72-
56+
```
7357
cmake --build build/Ninja-ReleaseAssert/swift-macosx-x86_64 -- check-swift-macosx-x86_64
58+
```
7459

7560
Note that ``check-swift`` is suffixed with a target operating system and architecture.
7661
Besides ``check-swift``, other targets are also available. Here's the full list:
7762

78-
* ``check-swift``
79-
80-
Runs tests from the ``${SWIFT_SOURCE_ROOT}/test`` directory.
81-
82-
* ``check-swift-only_validation``
83-
84-
Runs tests from the ``${SWIFT_SOURCE_ROOT}/validation-test`` directory.
85-
86-
* ``check-swift-validation``
87-
88-
Runs the primary and validation tests, without the long tests.
89-
90-
* ``check-swift-only_long``
91-
92-
Runs long tests only.
93-
94-
* ``check-swift-all``
95-
96-
Runs all tests (primary, validation, and long).
97-
98-
* ``SwiftUnitTests``
99-
100-
Builds all unit tests. Executables are located under
63+
* ``check-swift``: Runs tests from the ``${SWIFT_SOURCE_ROOT}/test`` directory.
64+
* ``check-swift-only_validation``: Runs tests from the ``${SWIFT_SOURCE_ROOT}/validation-test`` directory.
65+
* ``check-swift-validation``: Runs the primary and validation tests, without the long tests.
66+
* ``check-swift-only_long``: Runs long tests only.
67+
* ``check-swift-all``: Runs all tests (primary, validation, and long).
68+
* ``SwiftUnitTests``: Builds all unit tests. Executables are located under
10169
``${SWIFT_BUILD_ROOT}/unittests`` and must be run individually.
10270

10371
For every target above, there are variants for different optimizations:
10472

10573
* the target itself (e.g., ``check-swift``) -- runs all tests from the primary
10674
testsuite. The execution tests are run in ``-Onone`` mode.
107-
10875
* the target with ``-optimize`` suffix (e.g., ``check-swift-optimize``) -- runs
10976
execution tests in ``-O`` mode. This target will only run tests marked as
11077
``executable_test``.
111-
11278
* the target with ``-optimize-unchecked`` suffix (e.g.,
11379
``check-swift-optimize-unchecked``) -- runs execution tests in
11480
``-Ounchecked`` mode. This target will only run tests marked as
11581
``executable_test``.
116-
11782
* the target with ``-executable`` suffix (e.g.,
11883
``check-swift-executable-iphoneos-arm64``) -- runs tests marked with
11984
``executable_test`` in ``-Onone`` mode.
120-
12185
* the target with ``-non-executable`` suffix (e.g.,
12286
``check-swift-non-executable-iphoneos-arm64``) -- runs tests not marked with
12387
``executable_test`` in ``-Onone`` mode.
12488

12589
If more control is required (e.g. to manually run certain tests), you can invoke
12690
LLVM's lit.py script directly. For example:
12791

128-
.. code-block:: bash
129-
92+
```
13093
% ${LLVM_SOURCE_ROOT}/utils/lit/lit.py -sv ${SWIFT_BUILD_ROOT}/test-iphonesimulator-i386/Parse/
94+
```
13195

13296
This runs the tests in the test/Parse/ directory targeting the 32-bit iOS
13397
Simulator. The ``-sv`` options give you a nice progress bar and only show you
@@ -141,60 +105,45 @@ source 'test/' directory.) There is a more verbose form that specifies the
141105
testing configuration explicitly, which then allows you to test files
142106
regardless of location.
143107

144-
.. code-block:: bash
145-
108+
```
146109
% ${LLVM_SOURCE_ROOT}/utils/lit/lit.py -sv --param swift_site_config=${SWIFT_BUILD_ROOT}/test-iphonesimulator-i386/lit.site.cfg ${SWIFT_SOURCE_ROOT}/test/Parse/
110+
```
147111

148112
For more complicated configuration, copy the invocation from one of the build
149113
targets mentioned above and modify it as necessary. lit.py also has several
150114
useful features, like timing tests and providing a timeout. Check these features
151115
out with ``lit.py -h``. We document some of the more useful ones below:
152116

153-
Extra lit.py invocation options
154-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
117+
#### Extra lit.py invocation options
155118

156119
* ``-s`` reduces the amount of output that lit shows.
157-
158120
* ``-v`` causes a test's commandline and output to be printed if the test fails.
159-
160121
* ``-a`` causes a test's commandline and output to always be printed.
161-
162122
* ``--filter=<pattern>`` causes only tests with paths matching the given regular
163123
expression to be run.
164-
165124
* ``-i`` causes tests that have a newer modification date and failing tests to
166125
be run first. This is implemented by updating the mtimes of the tests.
167-
168126
* ``--no-execute`` causes a dry run to be performed. *NOTE* This means that all
169127
tests are assumed to PASS.
170-
171128
* ``--time-tests`` will cause elapsed wall time to be tracked for each test.
172-
173129
* ``--timeout=<MAXINDIVIDUALTESTTIME>`` sets a maximum time that can be spent
174130
running a single test (in seconds). 0 (the default means no time limit.
175-
176131
* ``--max-failures=<MAXFAILURES>`` stops execution after ``MAXFAILURES`` number
177132
of failures.
178-
179133
* ``--param gmalloc`` will run all tests under Guard Malloc (macOS only). See
180134
``man libgmalloc`` for more information.
181-
182135
* ``--param swift-version=<MAJOR>`` overrides the default Swift language
183136
version used by swift/swiftc and swift-ide-test.
184-
185137
* ``--param interpret`` is an experimental option for running execution tests
186138
using Swift's interpreter rather than compiling them first. Note that this
187139
does not affect all substitutions.
188-
189140
* ``--param swift_test_mode=<MODE>`` drives the various suffix variations
190141
mentioned above. Again, it's best to get the invocation from the existing
191142
build system targets and modify it rather than constructing it yourself.
192143

193-
Writing tests
194-
-------------
144+
### Writing tests
195145

196-
General guidelines
197-
^^^^^^^^^^^^^^^^^^
146+
#### General guidelines
198147

199148
When adding a new testcase, try to find an existing test file focused on the
200149
same topic rather than starting a new test file. There is a fixed runtime cost
@@ -225,7 +174,6 @@ details of the standard library (unless doing so is point of the test).
225174
Platform-dependent details include:
226175

227176
* ``Int`` (use integer types with explicit types instead).
228-
229177
* Layout of ``String``, ``Array``, ``Dictionary``, ``Set``. These differ
230178
between platforms that have Objective-C interop and those that don't.
231179

@@ -239,8 +187,7 @@ standard library that only has a very basic set of APIs.
239187
If you write an executable test please add ``REQUIRES: executable_test`` to the
240188
test.
241189

242-
Substitutions in lit tests
243-
^^^^^^^^^^^^^^^^^^^^^^^^^^
190+
#### Substitutions in lit tests
244191

245192
Substitutions that start with ``%target`` configure the compiler for building
246193
code for the target that is not the build machine:
@@ -427,6 +374,7 @@ Other substitutions:
427374
When writing a test where output (or IR, SIL) depends on the bitness of the
428375
target CPU, use this pattern::
429376

377+
```
430378
// RUN: %target-swift-frontend ... | %FileCheck --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize %s
431379
432380
// CHECK: common line
@@ -439,10 +387,12 @@ target CPU, use this pattern::
439387
// CHECK: define @foo() {
440388
// CHECK-32: integer_literal $Builtin.Int32, 0
441389
// CHECK-64: integer_literal $Builtin.Int64, 0
390+
```
442391

443392
When writing a test where output (or IR, SIL) depends on the target CPU itself,
444393
use this pattern::
445394

395+
```
446396
// RUN: %target-swift-frontend ... | %FileCheck --check-prefix=CHECK --check-prefix=CHECK-%target-cpu %s
447397
448398
// CHECK: common line
@@ -452,9 +402,9 @@ use this pattern::
452402
// CHECK-arm64: only for arm64
453403
// CHECK-powerpc64: only for powerpc64
454404
// CHECK-powerpc64le: only for powerpc64le
405+
```
455406

456-
Features for ``REQUIRES`` and ``XFAIL``
457-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
407+
#### Features for ``REQUIRES`` and ``XFAIL``
458408

459409
FIXME: full list.
460410

@@ -476,25 +426,23 @@ FIXME: full list.
476426
* ``XFAIL: linux``: tests that need to be adapted for Linux, for example parts
477427
that depend on Objective-C interop need to be split out.
478428

479-
Feature ``REQUIRES: executable_test``
480-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
429+
#### Feature ``REQUIRES: executable_test``
481430

482431
This feature marks an executable test. The test harness makes this feature
483432
generally available. It can be used to restrict the set of tests to run.
484433

485-
StdlibUnittest
486-
^^^^^^^^^^^^^^
434+
#### StdlibUnittest
487435

488436
Tests accept command line parameters, run StdlibUnittest-based test binary
489437
with ``--help`` for more information.
490438

491-
Testing memory management in execution tests
492-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
439+
#### Testing memory management in execution tests
493440

494441
In execution tests, memory management testing should be performed
495442
using local variables enclosed in a closure passed to the standard
496443
library ``autoreleasepool`` function. For example::
497444

445+
```
498446
// A counter that's decremented by Canary's deinitializer.
499447
var CanaryCount = 0
500448
@@ -510,6 +458,7 @@ library ``autoreleasepool`` function. For example::
510458
let canary = Canary()
511459
}
512460
assert(CanaryCount == 1, "canary was not released")
461+
```
513462

514463
Memory management tests should be performed in a local scope because Swift does
515464
not guarantee the destruction of global variables. Code that needs to

0 commit comments

Comments
 (0)