TEST-SUITE.md (13052B)
1 <!-- 2 Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 4 SPDX-License-Identifier: curl 5 --> 6 7 # The curl Test Suite 8 9 # Running 10 11 See the "Requires to run" section for prerequisites. 12 13 In the root of the curl repository: 14 15 ./configure && make && make test 16 17 To run a specific set of tests (e.g. 303 and 410): 18 19 make test TFLAGS="303 410" 20 21 To run the tests faster, pass the -j (parallelism) flag: 22 23 make test TFLAGS="-j10" 24 25 "make test" builds the test suite support code and invokes the 'runtests.pl' 26 perl script to run all the tests. The value of `TFLAGS` is passed 27 directly to 'runtests.pl'. 28 29 When you run tests via make, the flags `-a` and `-s` are passed, meaning 30 to continue running tests even after one fails, and to emit short output. 31 32 If you would like to not use those flags, you can run 'runtests.pl' directly. 33 You must `chdir` into the tests directory, then you can run it like so: 34 35 ./runtests.pl 303 410 36 37 You must have run `make test` at least once first to build the support code. 38 39 To see what flags are available for runtests.pl, and what output it emits, run: 40 41 man ./tests/runtests.1 42 43 After a test fails, examine the tests/log directory for stdout, stderr, and 44 output from the servers used in the test. 45 46 ## Requires to run 47 48 - `perl` (and a Unix-style shell) 49 - `python` (and a Unix-style shell, for SMB and TELNET tests) 50 - `python-impacket` (for SMB tests) 51 - `diff` (when a test fails, a diff is shown) 52 - `stunnel` (for HTTPS and FTPS tests) 53 - `openssl` (the command line tool, for generating test server certificates) 54 - `openssh` or `SunSSH` (for SCP and SFTP tests) 55 - `nghttpx` (for HTTP/2 and HTTP/3 tests) 56 - An available `en_US.UTF-8` locale 57 58 ### Installation of impacket 59 60 The Python-based test servers support Python 3. 61 62 Please install python-impacket in the correct Python environment. 63 You can use pip or your OS' package manager to install 'impacket'. 64 65 On Debian/Ubuntu the package name is 'python3-impacket' 66 67 On FreeBSD the package name is 'py311-impacket' 68 69 On any system where pip is available: 'python3 -m pip install impacket' 70 71 You may also need to manually install the Python package 'six' 72 as that may be a missing requirement for impacket. 73 74 ## Event-based 75 76 If curl is built with `Debug` enabled (see below), then the `runtests.pl` 77 script offers a `-e` option (or `--test-event`) that makes it perform 78 *event-based*. Such tests invokes the curl tool with `--test-event`, a 79 debug-only option made for this purpose. 80 81 Performing event-based means that the curl tool uses the 82 `curl_multi_socket_action()` API call to drive the transfer(s), instead of 83 the otherwise "normal" functions it would use. This allows us to test drive 84 the socket_action API. Transfers done this way should work exactly the same 85 as with the non-event based API. 86 87 To be able to use `--test-event` together with `--parallel`, curl requires 88 *libuv* to be present and enabled in the build: `configure --enable-libuv` 89 90 ## Duplicated handles 91 92 If curl is built with `Debug` enabled (see below), then the `runtests.pl` 93 script offers a `--test-duphandle` option. When enabled, curl always 94 duplicates the easy handle and does its transfers using the new one instead 95 of the original. This is done entirely for testing purpose to verify that 96 everything works exactly the same when this is done; confirming that the 97 `curl_easy_duphandle()` function duplicates everything that it should. 98 99 ### Port numbers used by test servers 100 101 All test servers run on "random" port numbers. All tests must be written to 102 use the suitable variables instead of fixed port numbers so that test cases 103 continue to work independently of what port numbers the test servers 104 actually use. 105 106 See [`FILEFORMAT`](FILEFORMAT.md) for the port number variables. 107 108 ### Test servers 109 110 The test suite runs stand-alone servers on random ports to which it makes 111 requests. For SSL tests, it runs stunnel to handle encryption to the regular 112 servers. For SSH, it runs a standard OpenSSH server. 113 114 The listen port numbers for the test servers are picked randomly to allow 115 users to run multiple test cases concurrently and to not collide with other 116 existing services that might listen to ports on the machine. 117 118 The HTTP server supports listening on a Unix domain socket, the default 119 location is 'http.sock'. 120 121 For HTTP/2 and HTTP/3 testing an installed `nghttpx` is used. HTTP/3 tests 122 check if nghttpx supports the protocol. To override the nghttpx used, set 123 the environment variable `NGHTTPX`. The default can also be changed by 124 specifying `--with-test-nghttpx=<path>` as argument to `configure`. 125 126 ### DNS server 127 128 There is a test DNS server to allow tests to resolve hostnames to verify 129 those code paths. This server is started like all the other servers within 130 the `<servers>` section. 131 132 To make a curl build actually use the test DNS server requires a debug 133 build. When such a test runs, the environment variable `CURL_DNS_SERVER` is 134 set to identify the IP address and port number of the DNS server to use. 135 136 - curl built to use c-ares for resolving automatically asks that server for 137 host information 138 139 - curl built to use `getaddrinfo()` for resolving *and* is built with c-ares 140 1.26.0 or later, gets a special work-around. In such builds, when the 141 environment variable is set, curl instead invokes a getaddrinfo wrapper 142 that emulates the function and acknowledges the DNS server environment 143 variable. This way, the getaddrinfo-using code paths in curl are verified, 144 and yet the custom responses from the test DNS server are used. 145 146 curl that is built to support a custom DNS server in a test gets the 147 `override-dns` feature set. 148 149 When curl ask for HTTPS-RR, c-ares is always used and in debug builds such 150 asks respects the dns server environment variable as well. 151 152 The test DNS server only has a few limited responses. When asked for 153 154 - type `A` response, it returns the address `127.0.0.1` three times 155 - type `AAAA` response, it returns the address `::1` three times 156 - other types, it returns a blank response without answers 157 158 ### Shell startup scripts 159 160 Tests which use the ssh test server, SCP/SFTP tests, might be badly 161 influenced by the output of system wide or user specific shell startup 162 scripts, .bashrc, .profile, /etc/csh.cshrc, .login, /etc/bashrc, etc. which 163 output text messages or escape sequences on user login. When these shell 164 startup messages or escape sequences are output they might corrupt the 165 expected stream of data which flows to the sftp-server or from the ssh 166 client which can result in bad test behavior or even prevent the test server 167 from running. 168 169 If the test suite ssh or sftp server fails to start up and logs the message 170 'Received message too long' then you are certainly suffering the unwanted 171 output of a shell startup script. Locate, cleanup or adjust the shell 172 script. 173 174 ### Memory test 175 176 The test script checks that all allocated memory is freed properly IF curl 177 has been built with the `CURLDEBUG` define set. The script automatically 178 detects if that is the case, and it uses the `memanalyze.pl` script to 179 analyze the memory debugging output. 180 181 Also, if you run tests on a machine where valgrind is found, the script uses 182 valgrind to run the test with (unless you use `-n`) to further verify 183 correctness. 184 185 The `runtests.pl` `-t` option enables torture testing mode. It runs each 186 test many times and makes each different memory allocation fail on each 187 successive run. This tests the out of memory error handling code to ensure 188 that memory leaks do not occur even in those situations. It can help to 189 compile curl with `CPPFLAGS=-DMEMDEBUG_LOG_SYNC` when using this option, to 190 ensure that the memory log file is properly written even if curl crashes. 191 192 ### Debug 193 194 If a test case fails, you can conveniently get the script to invoke the 195 debugger (gdb) for you with the server running and the same command line 196 parameters that failed. Just invoke `runtests.pl <test number> -g` and then 197 just type 'run' in the debugger to perform the command through the debugger. 198 199 ### Logs 200 201 All logs are generated in the log/ subdirectory (it is emptied first in the 202 runtests.pl script). They remain in there after a test run. 203 204 ### Log Verbosity 205 206 A curl build with `--enable-debug` offers more verbose output in the logs. 207 This applies not only for test cases, but also when running it standalone 208 with `curl -v`. While a curl debug built is 209 ***not suitable for production***, it is often helpful in tracking down 210 problems. 211 212 Sometimes, one needs detailed logging of operations, but does not want 213 to drown in output. The newly introduced *connection filters* allows one to 214 dynamically increase log verbosity for a particular *filter type*. Example: 215 216 CURL_DEBUG=ssl curl -v https://curl.se 217 218 makes the `ssl` connection filter log more details. One may do that for 219 every filter type and also use a combination of names, separated by `,` or 220 space. 221 222 CURL_DEBUG=ssl,http/2 curl -v https://curl.se 223 224 The order of filter type names is not relevant. Names used here are 225 case insensitive. Note that these names are implementation internals and 226 subject to change. 227 228 Some, likely stable names are `tcp`, `ssl`, `http/2`. For a current list, 229 one may search the sources for `struct Curl_cftype` definitions and find 230 the names there. Also, some filters are only available with certain build 231 options, of course. 232 233 ### Test input files 234 235 All test cases are put in the `data/` subdirectory. Each test is stored in 236 the file named according to the test number. 237 238 See [`FILEFORMAT`](FILEFORMAT.md) for a description of the test case file 239 format. 240 241 ### Code coverage 242 243 gcc provides a tool that can determine the code coverage figures for the 244 test suite. To use it, configure curl with `CFLAGS='-fprofile-arcs 245 -ftest-coverage -g -O0'`. Make sure you run the normal and torture tests to 246 get more full coverage, i.e. do: 247 248 make test 249 make test-torture 250 251 The graphical tool `ggcov` can be used to browse the source and create 252 coverage reports on \*nix hosts: 253 254 ggcov -r lib src 255 256 The text mode tool `gcov` may also be used, but it does not handle object 257 files in more than one directory correctly. 258 259 ### Remote testing 260 261 The runtests.pl script provides some hooks to allow curl to be tested on a 262 machine where perl can not be run. The test framework in this case runs on 263 a workstation where perl is available, while curl itself is run on a remote 264 system using ssh or some other remote execution method. See the comments at 265 the beginning of runtests.pl for details. 266 267 ## Test case numbering 268 269 Test cases used to be numbered by category ranges, but the ranges filled 270 up. Subsets of tests can now be selected by passing keywords to the 271 runtests.pl script via the make `TFLAGS` variable. 272 273 New tests are added by finding a free number in `tests/data/Makefile.am`. 274 275 ## Write tests 276 277 Here's a quick description on writing test cases. We basically have three 278 kinds of tests: the ones that test the curl tool, the ones that build small 279 applications and test libcurl directly and the unit tests that test 280 individual (possibly internal) functions. 281 282 ### test data 283 284 Each test has a master file that controls all the test data. What to read, 285 what the protocol exchange should look like, what exit code to expect and 286 what command line arguments to use etc. 287 288 These files are `tests/data/test[num]` where `[num]` is just a unique 289 identifier described above, and the XML-like file format of them is 290 described in the separate [`FILEFORMAT`](FILEFORMAT.md) document. 291 292 ### curl tests 293 294 A test case that runs the curl tool and verifies that it gets the correct 295 data, it sends the correct data, it uses the correct protocol primitives 296 etc. 297 298 ### libcurl tests 299 300 The libcurl tests are identical to the curl ones, except that they use a 301 specific and dedicated custom-built program to run instead of "curl". This 302 tool is built from source code placed in `tests/libtest` and if you want to 303 make a new libcurl test that is where you add your code. 304 305 ### unit tests 306 307 Unit tests are placed in `tests/unit`. There is a tests/unit/README 308 describing the specific set of checks and macros that may be used when 309 writing tests that verify behaviors of specific individual functions. 310 311 The unit tests depend on curl being built with debug enabled. 312 313 ### test bundles 314 315 Individual tests are bundled into single executables, one for libtests, one 316 for unit tests and one for servers. The executables' first argument is 317 the name of libtest, unit test or server respectively. 318 In these executables, the build process automatically renames the entry point 319 to a unique symbol. `test` becomes `test_<tool>`, e.g. `test_lib1598` or 320 `test_unit1305`. For servers `main` becomes `main_sws` for the `sws` server, 321 and so on. Other common symbols may also be suffixed the same way.