README.md
1# The curl Test Suite
2
3# Running
4
5## Requires to run
6
7 - perl (and a unix-style shell)
8 - python (and a unix-style shell, for SMB and TELNET tests)
9 - python-impacket (for SMB tests)
10 - diff (when a test fails, a diff is shown)
11 - stunnel (for HTTPS and FTPS tests)
12 - OpenSSH or SunSSH (for SCP, SFTP and SOCKS4/5 tests)
13 - nghttpx (for HTTP/2 tests)
14 - nroff (for --manual tests)
15
16### Installation of python-impacket
17
18 The Python-based test servers support both recent Python 2 and 3.
19 You can figure out your default Python interpreter with python -V
20
21 Please install python-impacket in the correct Python environment.
22 You can use pip or your OS' package manager to install 'impacket'.
23
24 On Debian/Ubuntu the package names are:
25
26 - Python 2: 'python-impacket'
27 - Python 3: 'python3-impacket'
28
29 On FreeBSD the package names are:
30
31 - Python 2: 'py27-impacket'
32 - Python 3: 'py37-impacket'
33
34 On any system where pip is available:
35
36 - Python 2: 'pip2 install impacket'
37 - Python 3: 'pip3 install impacket'
38
39 You may also need to manually install the Python package 'six'
40 as that may be a missing requirement for impacket on Python 3.
41
42### Port numbers used by test servers
43
44 All test servers run on "random" port numbers. All tests should be written
45 to use suitable variables instead of fixed port numbers so that test cases
46 continue to work independent on what port numbers the test servers actually
47 use.
48
49 See [FILEFORMAT](FILEFORMAT.md) for the port number variables.
50
51### Test servers
52
53 The test suite runs simple FTP, POP3, IMAP, SMTP, HTTP and TFTP stand-alone
54 servers on the ports listed above to which it makes requests. For SSL tests,
55 it runs stunnel to handle encryption to the regular servers. For SSH, it
56 runs a standard OpenSSH server. For SOCKS4/5 tests SSH is used to perform
57 the SOCKS functionality and requires a SSH client and server.
58
59 The base port number (8990), which all the individual port numbers are
60 indexed from, can be set explicitly using runtests.pl' -b option to allow
61 running more than one instance of the test suite simultaneously on one
62 machine, or just move the servers in case you have local services on any of
63 those ports.
64
65 The HTTP server supports listening on a Unix domain socket, the default
66 location is 'http.sock'.
67
68### Run
69
70 `./configure && make && make test`. This builds the test suite support code
71 and invokes the 'runtests.pl' perl script to run all the tests. Edit the top
72 variables of that script in case you have some specific needs, or run the
73 script manually (after the support code has been built).
74
75 The script breaks on the first test that doesn't do OK. Use `-a` to prevent
76 the script from aborting on the first error. Run the script with `-v` for
77 more verbose output. Use `-d` to run the test servers with debug output
78 enabled as well. Specifying `-k` keeps all the log files generated by the
79 test intact.
80
81 Use `-s` for shorter output, or pass test numbers to run specific tests only
82 (like `./runtests.pl 3 4` to test 3 and 4 only). It also supports test case
83 ranges with 'to', as in `./runtests.pl 3 to 9` which runs the seven tests
84 from 3 to 9. Any test numbers starting with ! are disabled, as are any test
85 numbers found in the files `data/DISABLED` or `data/DISABLED.local` (one per
86 line). The latter is meant for local temporary disables and will be ignored
87 by git.
88
89 When `-s` is not present, each successful test will display on one line the
90 test number and description and on the next line a set of flags, the test
91 result, current test sequence, total number of tests to be run and an
92 estimated amount of time to complete the test run. The flags consist of
93 these letters describing what is checked in this test:
94
95 s stdout
96 d data
97 u upload
98 p protocol
99 o output
100 e exit code
101 m memory
102 v valgrind
103
104### Shell startup scripts
105
106 Tests which use the ssh test server, SCP/SFTP/SOCKS tests, might be badly
107 influenced by the output of system wide or user specific shell startup
108 scripts, .bashrc, .profile, /etc/csh.cshrc, .login, /etc/bashrc, etc. which
109 output text messages or escape sequences on user login. When these shell
110 startup messages or escape sequences are output they might corrupt the
111 expected stream of data which flows to the sftp-server or from the ssh
112 client which can result in bad test behaviour or even prevent the test
113 server from running.
114
115 If the test suite ssh or sftp server fails to start up and logs the message
116 'Received message too long' then you are certainly suffering the unwanted
117 output of a shell startup script. Locate, cleanup or adjust the shell
118 script.
119
120### Memory test
121
122 The test script will check that all allocated memory is freed properly IF
123 curl has been built with the `CURLDEBUG` define set. The script will
124 automatically detect if that is the case, and it will use the
125 'memanalyze.pl' script to analyze the memory debugging output.
126
127 Also, if you run tests on a machine where valgrind is found, the script will
128 use valgrind to run the test with (unless you use `-n`) to further verify
129 correctness.
130
131 runtests.pl's `-t` option will enable torture testing mode, which runs each
132 test many times and makes each different memory allocation fail on each
133 successive run. This tests the out of memory error handling code to ensure
134 that memory leaks do not occur even in those situations. It can help to
135 compile curl with `CPPFLAGS=-DMEMDEBUG_LOG_SYNC` when using this option, to
136 ensure that the memory log file is properly written even if curl crashes.
137
138### Debug
139
140 If a test case fails, you can conveniently get the script to invoke the
141 debugger (gdb) for you with the server running and the exact same command
142 line parameters that failed. Just invoke `runtests.pl <test number> -g` and
143 then just type 'run' in the debugger to perform the command through the
144 debugger.
145
146### Logs
147
148 All logs are generated in the log/ subdirectory (it is emptied first in the
149 runtests.pl script). They remain in there after a test run.
150
151### Test input files
152
153 All test cases are put in the `data/` subdirectory. Each test is stored in
154 the file named according to the test number.
155
156 See [FILEFORMAT.md](FILEFORMAT.md) for a description of the test case file
157 format.
158
159### Code coverage
160
161 gcc provides a tool that can determine the code coverage figures for the
162 test suite. To use it, configure curl with `CFLAGS='-fprofile-arcs
163 -ftest-coverage -g -O0`. Make sure you run the normal and torture tests to
164 get more full coverage, i.e. do:
165
166 make test
167 make test-torture
168
169 The graphical tool ggcov can be used to browse the source and create
170 coverage reports on *NIX hosts:
171
172 ggcov -r lib src
173
174 The text mode tool gcov may also be used, but it doesn't handle object files
175 in more than one directory very well.
176
177### Remote testing
178
179 The runtests.pl script provides some hooks to allow curl to be tested on a
180 machine where perl can not be run. The test framework in this case runs on
181 a workstation where perl is available, while curl itself is run on a remote
182 system using ssh or some other remote execution method. See the comments at
183 the beginning of runtests.pl for details.
184
185## Test case numbering
186
187 Test cases used to be numbered by category ranges, but the ranges filled
188 up. Subsets of tests can now be selected by passing keywords to the
189 runtests.pl script via the make `TFLAGS` variable.
190
191 New tests are added by finding a free number in `tests/data/Makefile.inc`.
192
193## Write tests
194
195 Here's a quick description on writing test cases. We basically have three
196 kinds of tests: the ones that test the curl tool, the ones that build small
197 applications and test libcurl directly and the unit tests that test
198 individual (possibly internal) functions.
199
200### test data
201
202 Each test has a master file that controls all the test data. What to read,
203 what the protocol exchange should look like, what exit code to expect and
204 what command line arguments to use etc.
205
206 These files are `tests/data/test[num]` where `[num]` is just a unique
207 identifier described above, and the XML-like file format of them is
208 described in the separate [FILEFORMAT.md](FILEFORMAT.md) document.
209
210### curl tests
211
212 A test case that runs the curl tool and verifies that it gets the correct
213 data, it sends the correct data, it uses the correct protocol primitives
214 etc.
215
216### libcurl tests
217
218 The libcurl tests are identical to the curl ones, except that they use a
219 specific and dedicated custom-built program to run instead of "curl". This
220 tool is built from source code placed in `tests/libtest` and if you want to
221 make a new libcurl test that is where you add your code.
222
223### unit tests
224
225 Unit tests are placed in `tests/unit`. There's a tests/unit/README
226 describing the specific set of checks and macros that may be used when
227 writing tests that verify behaviors of specific individual functions.
228
229 The unit tests depend on curl being built with debug enabled.
230