798b39d3e2cd849eb3addd49373748f036019709
[platform/upstream/coreclr.git] / Documentation / building / testing-with-corefx.md
1 Testing with CoreFX
2 ===================
3
4 You can use CoreFX tests to validate your changes to CoreCLR. There are two basic options:
5
6 1. Build the CoreFX product and tests against a build of CoreCLR, or
7 2. Use a snapshot of the CoreFX test build with a build of CoreCLR.
8
9 Both mechanisms are exposed to certain types of breaking changes which can cause test failures.
10 However, we have a test exclusion mechanism for option #2, with exclusions specified in the
11 CoreCLR tree, not the CoreFX tree. This can make it possible to exclude tests that fail for
12 transient breaking change reasons, as well as for more long-lasting reasons.
13
14 Mechanism #2 is used to run CoreFX tests in the CI against every CoreCLR pull request.
15
16 # Building CoreFX against CoreCLR
17
18 In general, refer to the
19 [CoreFX Developer Guide](https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/developer-guide.md)
20 for information about CoreFX build scripts.
21
22 Normally when you build CoreFX it is built against a "last known good" version of CoreCLR. 
23 To run CoreFX tests against a current, "live", version of CoreCLR (for example, a CoreCLR
24 you have built yourself), including with an updated System.Private.CoreLib.dll,
25 [use these instructions](https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/developer-guide.md#testing-with-private-coreclr-bits).
26
27 ## Replace runtime between building CoreFX product and tests
28
29 A variation on the above is to build CoreFX normally, then overwrite the "last known good" CoreCLR
30 it used with your build of CoreCLR.
31
32 Do the following:
33
34 1. Build the CoreCLR you wish to test under `<coreclr_root>`.
35 2. Build the CoreFX repo (using `build.[cmd|sh]`) under `<corefx_root>`, but don't build tests yet.
36 3. Copy the contents of the CoreCLR binary root you wish to test into the CoreFX runtime
37 folder created in step #2.
38
39 For example:
40
41 `copy <coreclr_root>\bin\Product\Windows_NT.<arch>.<build_type>\* <corefx_root>\artifacts\bin\testhost\netcoreapp-Windows_NT-<build_type>-<arch>\shared\Microsoft.NETCore.App\9.9.9`
42
43 -or-  
44
45 `cp <coreclr_root>/bin/Product/<os>.<arch>.<build_type>/* <corefx_root>/artifacts/bin/testhost/netcoreapp-<os>-<build_type>-<arch>/shared/Microsoft.NETCore.App/9.9.9`
46   
47 4. Build and run the CoreFX tests using `build.[cmd|sh] -test` as described in the Developer Guide.
48
49 ### CI Script
50
51 [run-corefx-tests.py](https://github.com/dotnet/coreclr/blob/master/tests/scripts/run-corefx-tests.py)
52 will clone dotnet/corefx and run steps 2-4 above automatically. It is primarily intended
53 to be run by the dotnet/coreclr CI system, but it might provide a useful reference or
54 shortcut for individuals running the tests locally.
55
56 # Using the built CoreCLR test host
57
58 Here is an alternative method to the one described above. You can test your changes with
59 an existing CoreFX build or CoreCLR's cached CoreFX test build assemblies.
60
61 The "test host" is a dotnet CLI layout that includes both the CoreCLR and the CoreFX you want to test.
62
63 ## Locally-built CoreFX 
64
65 First, build CoreCLR (building the tests is not required) and CoreFX (including the tests),
66 as described above:
67
68 1. Build the CoreCLR you wish to test under `<coreclr_root>`.
69 2. Build the CoreFX repo under `<corefx_root>`.
70 3. Build the CoreFX tests using `build.[cmd|sh] -test`.
71
72 Once these are built, execute the following commands to test your local CoreCLR changes
73 with the built CoreFX changes.
74
75 1. From `<coreclr_root>` run:
76
77 For Windows:
78 ```
79 build-test.cmd <arch> <build_type> buildtesthostonly
80 ```
81
82 For Linux:
83 ```
84 build-test.sh <arch> <build_type> generatetesthostonly
85 ```
86
87 to generate the test host.
88
89 2. Navigate to `<corefx_root>\bin\tests\` and then into the directory for the test
90 you would like to run.
91
92 3. Run:
93
94 For Windows:
95 ```cmd
96 <coreclr_root>\bin\<os>.<arch>.<build_type>\testhost\dotnet.exe .\xunit.console.netcore.exe <testname>.dll
97 ```
98
99 For Linux:
100 ```sh
101 <coreclr_root>/bin/<os>.<arch>.<build_type>/testhost/dotnet ./xunit.console.netcore.exe <testname>.dll
102 ```
103
104 followed by any extra command-line arguments for xunit.
105
106 For example to run .NET Core Windows tests from System.Collections.Tests with an x64 Release build of CoreCLR:
107
108 For Windows:
109 ```
110 cd C:\corefx\artifacts\bin\tests\System.Collections.Tests
111 C:\coreclr\bin\tests\Windows_NT.x64.Release\testhost\dotnet.exe .\xunit.console.netcore.exe .\System.Collections.Tests.dll -notrait category=nonnetcoretests -notrait category=nonwindowstests
112 ```
113
114 For Linux:
115 ```
116 cd ~/corefx/bin/tests/System.Collections.Tests
117 ~/coreclr/artifacts/bin/tests/Linux.x64.Release/testhost/dotnet ./xunit.console.netcore.exe ./System.Collections.Tests.dll -notrait category=nonnetcoretests -notrait category=nonlinuxtests
118 ```
119
120 ## Running against a cached copy of the CoreFX tests
121
122 CoreCLR has an alternative way to run CoreFX tests, built for CI jobs.
123
124 To run tests against pre-built binaries you can execute the following from the CoreCLR repo root:
125
126 For Windows:
127
128 1. `.\build.cmd <arch> <build_type> skiptests`
129 2. `.\build-test.cmd <arch> <build_type> buildtesthostonly` -- this generates the test host
130 3. `.\tests\runtest.cmd <arch> <build_type> corefxtests|corefxtestsall` -- this runs the CoreFX tests
131
132 For Linux and macOS:
133
134 1. `./build.sh <arch> <build_type> skiptests`
135 2. `./build-test.sh <arch> <build_type> generatetesthostonly`
136 3. `./tests/runtest.sh --corefxtests|--corefxtestsall --testHostDir=<path_to_testhost> --coreclr-src=<path_to_coreclr_root>`
137
138 where:
139 + `<path_to_testhost>` - path to the CoreCLR test host built in step 2.
140 + `<path_to_coreclr_root>` - path to root of CoreCLR clone. Required to build the TestFileSetup tool for CoreFX testing.
141
142 The set of tests run are based on the `corefxtests` or `corefxtestsall` arguments, as follows:
143 + CoreFXTests - runs all tests defined in the dotnet/coreclr repo in `tests\CoreFX\CoreFX.issues.json`, or the test list specified with the optional argument `CoreFXTestList`.
144 + CoreFXTestsAll - runs all tests available, ignoring exclusions. The full list of tests is found at the URL in the dotnet/coreclr repo at `.\tests\CoreFX`: one of `CoreFXTestListURL.txt`, `CoreFXTestListURL_Linux.txt`, or `CoreFXTestListURL_OSX.txt`, based on platform.
145
146 ## Helix Testing
147
148 To use Helix-built binaries, substitute the URL in `.\tests\CoreFX\CoreFXTestListURL.txt`
149 with one acquired from a Helix test run and run the commands above.
150
151 ## Workflow
152
153 The CoreFX tests CI jobs run against cached test binaries in blob storage. This means that
154 tests might need to be disabled until the test binaries are refreshed as breaking changes
155 are merged in both CoreCLR and CoreFX. If you suspect a test is not failing because of a
156 functional regression, but rather because it's stale you can add it to the
157 [test exclusion file](https://github.com/dotnet/coreclr/blob/master/tests/CoreFX/CoreFX.issues.json).
158
159 ## Test List Format
160
161 The tests defined in CoreFX.issues.json or the test list specified with the argument
162 `CoreFXTestList` should conform to the following format.
163 ```js
164 [   // array of assemblies
165     {   // one per assembly
166         "name": "<Fully Qualified Assembly Name>", //e.g. System.Collections.Concurrent.Tests
167         "enabled": true|false, // Defines whether a test assembly should be run. If set to false any tests with the same name will not be run even if corefxtestsall is specified
168         "exclusions": {
169             "namespaces": // Can be null
170             [
171                 {
172                     "name": "System.Collections.Concurrent.Tests", // All test methods under this namespace will be skipped
173                     "reason": "<Reason for exclusion>" // This should be a link to the GitHub issue describing the problem
174                 }
175             ]
176             "classes": // Can be null
177             [
178                 {
179                     "name": "System.Collections.Concurrent.Tests.ConcurrentDictionaryTests", // All test methods in this class will be skipped
180                     "reason": "<Reason for exclusion>"
181                 }
182             ]
183             "methods": // Can be null
184             [
185                 {
186                     "name": "System.Collections.Concurrent.Tests.ConcurrentDictionaryTests.TestAddNullValue_IDictionary_ReferenceType_null",
187                     "reason": "<Reason for exclusion>"
188                 },
189                 {
190                     "name": "System.Collections.Concurrent.Tests.ConcurrentDictionaryTests.TestAddNullValue_IDictionary_ValueType_null_add",
191                     "reason": "<Reason for exclusion>"
192                 }
193             ]
194         }
195     },
196     { // next assembly
197         ...
198     }
199 ]
200 ```
201