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