use license macro in the spec file
[platform/upstream/libwebsockets.git] / README.test-apps.md
1 Testing server with a browser
2 -----------------------------
3
4 If you run [libwebsockets-test-server](test-server/test-server.c) and point your browser
5 (eg, Chrome) to
6
7   http://127.0.0.1:7681
8
9 It will fetch a script in the form of `test.html`, and then run the
10 script in there on the browser to open a websocket connection.
11 Incrementing numbers should appear in the browser display.
12
13 By default the test server logs to both stderr and syslog, you can control
14 what is logged using `-d <log level>`, see later.
15
16
17 Running test server as a Daemon
18 -------------------------------
19
20 You can use the -D option on the test server to have it fork into the
21 background and return immediately.  In this daemonized mode all stderr is
22 disabled and logging goes only to syslog, eg, `/var/log/messages` or similar.
23
24 The server maintains a lockfile at `/tmp/.lwsts-lock` that contains the pid
25 of the master process, and deletes this file when the master process
26 terminates.
27
28 To stop the daemon, do
29
30 ```bash
31 $ kill `cat /tmp/.lwsts-lock`
32 ```
33
34 If it finds a stale lock (the pid mentioned in the file does not exist
35 any more) it will delete the lock and create a new one during startup.
36
37 If the lock is valid, the daemon will exit with a note on stderr that
38 it was already running.
39
40
41 Using SSL on the server side
42 ----------------------------
43
44 To test it using SSL/WSS, just run the test server with
45
46 ```bash
47 $ libwebsockets-test-server --ssl
48 ```
49
50 and use the URL
51
52   https://127.0.0.1:7681
53
54 The connection will be entirely encrypted using some generated
55 certificates that your browser will not accept, since they are
56 not signed by any real Certificate Authority.  Just accept the
57 certificates in the browser and the connection will proceed
58 in first https and then websocket wss, acting exactly the
59 same.
60
61 [test-server.c](test-server/test-server.c) is all that is needed to use libwebsockets for
62 serving both the script html over http and websockets.
63
64
65 Testing websocket client support
66 --------------------------------
67
68 If you run the test server as described above, you can also
69 connect to it using the test client as well as a browser.
70
71 ```bash
72 $ libwebsockets-test-client localhost
73 ```
74
75 will by default connect to the test server on localhost:7681
76 and print the dumb increment number from the server at the
77 same time as drawing random circles in the mirror protocol;
78 if you connect to the test server using a browser at the
79 same time you will be able to see the circles being drawn.
80
81 The test client supports SSL too, use
82
83 ```bash
84 $ libwebsockets-test-client localhost --ssl -s
85 ```
86
87 the -s tells it to accept the default selfsigned cert from the server,
88 otherwise it will strictly fail the connection if there is no CA cert to
89 validate the server's certificate.
90
91
92 Testing simple echo
93 -------------------
94
95 You can test against `echo.websockets.org` as a sanity test like
96 this (the client connects to port `80` by default):
97
98 ```bash
99 $ libwebsockets-test-echo --client echo.websocket.org
100 ```
101
102 This echo test is of limited use though because it doesn't
103 negotiate any protocol.  You can run the same test app as a
104 local server, by default on localhost:7681
105
106 ```bash
107 $ libwebsockets-test-echo
108 ```
109
110 and do the echo test against the local echo server
111
112 ```bash
113 $ libwebsockets-test-echo --client localhost --port 7681
114 ```
115
116 If you add the `--ssl` switch to both the client and server, you can also test
117 with an encrypted link.
118
119
120 Testing SSL on the client side
121 ------------------------------
122
123 To test SSL/WSS client action, just run the client test with
124
125 ```bash
126 $ libwebsockets-test-client localhost --ssl
127 ```
128
129 By default the client test applet is set to accept selfsigned
130 certificates used by the test server, this is indicated by the
131 `use_ssl` var being set to `2`.  Set it to `1` to reject any server
132 certificate that it doesn't have a trusted CA cert for.
133
134
135 Using the websocket ping utility
136 --------------------------------
137
138 libwebsockets-test-ping connects as a client to a remote
139 websocket server using 04 protocol and pings it like the
140 normal unix ping utility.
141
142 ```bash
143 $ libwebsockets-test-ping localhost
144 handshake OK for protocol lws-mirror-protocol
145 Websocket PING localhost.localdomain (127.0.0.1) 64 bytes of data.
146 64 bytes from localhost: req=1 time=0.1ms
147 64 bytes from localhost: req=2 time=0.1ms
148 64 bytes from localhost: req=3 time=0.1ms
149 64 bytes from localhost: req=4 time=0.2ms
150 64 bytes from localhost: req=5 time=0.1ms
151 64 bytes from localhost: req=6 time=0.2ms
152 64 bytes from localhost: req=7 time=0.2ms
153 64 bytes from localhost: req=8 time=0.1ms
154 ^C
155 --- localhost.localdomain websocket ping statistics ---
156 8 packets transmitted, 8 received, 0% packet loss, time 7458ms
157 rtt min/avg/max = 0.110/0.185/0.218 ms
158 $
159 ```
160
161 By default it sends 64 byte payload packets using the 04
162 PING packet opcode type.  You can change the payload size
163 using the `-s=` flag, up to a maximum of 125 mandated by the
164 04 standard.
165
166 Using the lws-mirror protocol that is provided by the test
167 server, libwebsockets-test-ping can also use larger payload
168 sizes up to 4096 is BINARY packets; lws-mirror will copy
169 them back to the client and they appear as a PONG.  Use the
170 `-m` flag to select this operation.
171
172 The default interval between pings is 1s, you can use the -i=
173 flag to set this, including fractions like `-i=0.01` for 10ms
174 interval.
175
176 Before you can even use the PING opcode that is part of the
177 standard, you must complete a handshake with a specified
178 protocol.  By default lws-mirror-protocol is used which is
179 supported by the test server.  But if you are using it on
180 another server, you can specify the protcol to handshake with
181 by `--protocol=protocolname`
182
183
184 Fraggle test app
185 ----------------
186
187 By default it runs in server mode
188
189 ```bash
190 $ libwebsockets-test-fraggle
191 libwebsockets test fraggle
192 (C) Copyright 2010-2011 Andy Green <andy@warmcat.com> licensed under LGPL2.1
193  Compiled with SSL support, not using it
194  Listening on port 7681
195 server sees client connect
196 accepted v06 connection
197 Spamming 360 random fragments
198 Spamming session over, len = 371913. sum = 0x2D3C0AE
199 Spamming 895 random fragments
200 Spamming session over, len = 875970. sum = 0x6A74DA1
201 ...
202 ```
203
204 You need to run a second session in client mode, you have to
205 give the `-c` switch and the server address at least:
206
207 ```bash
208 $ libwebsockets-test-fraggle -c localhost
209 libwebsockets test fraggle
210 (C) Copyright 2010-2011 Andy Green <andy@warmcat.com> licensed under LGPL2.1
211  Client mode
212 Connecting to localhost:7681
213 denied deflate-stream extension
214 handshake OK for protocol fraggle-protocol
215 client connects to server
216 EOM received 371913 correctly from 360 fragments
217 EOM received 875970 correctly from 895 fragments
218 EOM received 247140 correctly from 258 fragments
219 EOM received 695451 correctly from 692 fragments
220 ...
221 ```
222
223 The fraggle test sends a random number up to 1024 fragmented websocket frames
224 each of a random size between 1 and 2001 bytes in a single message, then sends
225 a checksum and starts sending a new randomly sized and fragmented message.
226
227 The fraggle test client receives the same message fragments and computes the
228 same checksum using websocket framing to see when the message has ended.  It
229 then accepts the server checksum message and compares that to its checksum.
230
231
232 proxy support
233 -------------
234
235 The http_proxy environment variable is respected by the client
236 connection code for both `ws://` and `wss://`.  It doesn't support
237 authentication.
238
239 You use it like this
240
241 ```bash
242 $ export http_proxy=myproxy.com:3128
243 $ libwebsockets-test-client someserver.com
244 ```
245
246
247 debug logging
248 -------------
249
250 By default logging of severity "notice", "warn" or "err" is enabled to stderr.
251
252 Again by default other logging is compiled in but disabled from printing.
253
254 If you want to eliminate the debug logging below notice  in severity, use the
255 `--disable-debug` configure option to have it removed from the code by the
256 preprocesser.
257
258 If you want to see more detailed debug logs, you can control a bitfield to
259 select which logs types may print using the `lws_set_log_level()` api, in the
260 test apps you can use `-d <number>` to control this.  The types of logging
261 available are (OR together the numbers to select multiple)
262
263  - 1   ERR
264  - 2   WARN
265  - 4   NOTICE
266  - 8   INFO
267  - 16  DEBUG
268  - 32  PARSER
269  - 64  HEADER
270  - 128 EXTENSION
271  - 256 CLIENT
272  - 512 LATENCY
273
274
275 Websocket version supported
276 ---------------------------
277
278 The final IETF standard is supported for both client and server, protocol
279 version 13.
280
281
282 Latency Tracking
283 ----------------
284
285 Since libwebsockets runs using `poll()` and a single threaded approach, any
286 unexpected latency coming from system calls would be bad news.  There's now
287 a latency tracking scheme that can be built in with `--with-latency` at
288 configure-time, logging the time taken for system calls to complete and if
289 the whole action did complete that time or was deferred.
290
291 You can see the detailed data by enabling logging level 512 (eg, `-d 519` on
292 the test server to see that and the usual logs), however even without that
293 the "worst" latency is kept and reported to the logs with NOTICE severity
294 when the context is destroyed.
295
296 Some care is needed interpreting them, if the action completed the first figure
297 (in us) is the time taken for the whole action, which may have retried through
298 the poll loop many times and will depend on network roundtrip times.  High
299 figures here don't indicate a problem.  The figure in us reported after "lat"
300 in the logging is the time taken by this particular attempt.  High figures
301 here may indicate a problem, or if you system is loaded with another app at
302 that time, such as the browser, it may simply indicate the OS gave preferential
303 treatment to the other app during that call.
304
305
306 Autobahn Test Suite
307 -------------------
308
309 Lws can be tested against the autobahn websocket fuzzer.
310
311 1) pip install autobahntestsuite
312
313 2) wstest -m fuzzingserver
314
315 3) Run tests like this
316
317 libwebsockets-test-echo --client localhost --port 9001 -u "/runCase?case=20&agent=libwebsockets" -v -d 65535 -n 1
318
319 (this runs test 20)
320
321 4) In a browser, go here
322
323 http://localhost:8080/test_browser.html
324
325 fill in "libwebsockets" in "User Agent Identifier" and press "Update Reports (Manual)"
326
327 5) In a browser go to the directory you ran wstest in (eg, /projects/libwebsockets)
328
329 file:///projects/libwebsockets/reports/clients/index.html
330
331 to see the results
332
333
334 Autobahn Test Notes
335 -------------------
336
337 1) Autobahn tests the user code + lws implementation.  So to get the same
338 results, you need to follow test-echo.c in terms of user implmentation.
339
340 2) Some of the tests make no sense for Libwebsockets to support and we fail them.
341
342  - Tests 2.10 + 2.11: sends multiple pings on one connection.  Lws policy is to
343 only allow one active ping in flight on each connection, the rest are dropped.
344 The autobahn test itself admits this is not part of the standard, just someone's
345 random opinion about how they think a ws server should act.  So we will fail
346 this by design and it is no problem about RFC6455 compliance.
347
348  
349