curl/tests/unit
Stefan Eissing 671158242d
connections: introduce http/3 happy eyeballs
New cfilter HTTP-CONNECT for h3/h2/http1.1 eyeballing.
- filter is installed when `--http3` in the tool is used (or
  the equivalent CURLOPT_ done in the library)
- starts a QUIC/HTTP/3 connect right away. Should that not
  succeed after 100ms (subject to change), a parallel attempt
  is started for HTTP/2 and HTTP/1.1 via TCP
- both attempts are subject to IPv6/IPv4 eyeballing, same
  as happens for other connections
- tie timeout to the ip-version HAPPY_EYEBALLS_TIMEOUT
- use a `soft` timeout at half the value. When the soft timeout
  expires, the HTTPS-CONNECT filter checks if the QUIC filter
  has received any data from the server. If not, it will start
  the HTTP/2 attempt.

HTTP/3(ngtcp2) improvements.
- setting call_data in all cfilter calls similar to http/2 and vtls filters
  for use in callback where no stream data is available.
- returning CURLE_PARTIAL_FILE for prematurely terminated transfers
- enabling pytest test_05 for h3
- shifting functionality to "connect" UDP sockets from ngtcp2
  implementation into the udp socket cfilter. Because unconnected
  UDP sockets are weird. For example they error when adding to a
  pollset.

HTTP/3(quiche) improvements.
- fixed upload bug in quiche implementation, now passes 251 and pytest
- error codes on stream RESET
- improved debug logs
- handling of DRAIN during connect
- limiting pending event queue

HTTP/2 cfilter improvements.
- use LOG_CF macros for dynamic logging in debug build
- fix CURLcode on RST streams to be CURLE_PARTIAL_FILE
- enable pytest test_05 for h2
- fix upload pytests and improve parallel transfer performance.

GOAWAY handling for ngtcp2/quiche
- during connect, when the remote server refuses to accept new connections
  and closes immediately (so the local conn goes into DRAIN phase), the
  connection is torn down and a another attempt is made after a short grace
  period.
  This is the behaviour observed with nghttpx when we tell it to  shut
  down gracefully. Tested in pytest test_03_02.

TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
  copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
  and connection related things based on the negotiated protocol (or lack thereof).

- new tests/tests-httpd/scorecard.py for testing h3/h2 protocol implementation.
  Invoke:
    python3 tests/tests-httpd/scorecard.py --help
  for usage.

Improvements on gathering connect statistics and socket access.
- new CF_CTRL_CONN_REPORT_STATS cfilter control for having cfilters
  report connection statistics. This is triggered when the connection
  has completely connected.
- new void Curl_pgrsTimeWas(..) method to report a timer update with
  a timestamp of when it happend. This allows for updating timers
  "later", e.g. a connect statistic after full connectivity has been
  reached.
- in case of HTTP eyeballing, the previous changes will update
  statistics only from the filter chain that "won" the eyeballing.
- new cfilter query CF_QUERY_SOCKET for retrieving the socket used
  by a filter chain.
  Added methods Curl_conn_cf_get_socket() and Curl_conn_get_socket()
  for convenient use of this query.
- Change VTLS backend to query their sub-filters for the socket when
  checks during the handshake are made.

HTTP/3 documentation on how https eyeballing works.

TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
  copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
  and connection related things based on the negotiated protocol (or lack thereof).

Scorecard with Caddy.
- configure can be run with `--with-test-caddy=path` to specify which caddy to use for testing
- tests/tests-httpd/scorecard.py now measures download speeds with caddy

pytest improvements
- adding Makfile to clean gen dir
- adding nghttpx rundir creation on start
- checking httpd version 2.4.55 for test_05 cases where it is needed. Skipping with message if too old.
- catch exception when checking for caddy existance on system.

Closes #10349
2023-02-02 09:57:34 +01:00
..
.gitignore copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
CMakeLists.txt copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
curlcheck.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
Makefile.am copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
Makefile.inc connect: fix strategy testing for attempts, timeouts and happy-eyeball 2023-01-31 11:28:14 +01:00
README.md copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1300.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1302.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1303.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1304.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1305.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1307.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1308.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1309.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1323.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1330.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1394.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1395.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1396.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1397.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1398.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1399.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1600.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1601.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1602.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1603.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1604.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1605.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1606.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1607.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1608.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1609.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1610.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1611.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1612.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1614.c noproxy: support for space-separated names is deprecated 2023-01-04 09:15:37 +01:00
unit1620.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1621.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1650.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1651.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1652.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1653.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1654.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1655.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1660.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit1661.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
unit2600.c connections: introduce http/3 happy eyeballs 2023-02-02 09:57:34 +01:00
unit3200.c copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00

Unit tests

The goal is to add tests for all functions in libcurl. If functions are too big and complicated, we should split them into smaller and testable ones.

Build Unit Tests

./configure --enable-debug is required for the unit tests to build. To enable unit tests, there will be a separate static libcurl built that will be used exclusively for linking unit test programs. Just build everything as normal, and then you can run the unit test cases as well.

Run Unit Tests

Unit tests are run as part of the regular test suite. If you have built everything to run unit tests, to can do 'make test' at the root level. Or you can cd tests and make and then invoke individual unit tests with ./runtests.pl NNNN where NNNN is the specific test number.

Debug Unit Tests

If a specific test fails you will get told. The test case then has output left in the log/ subdirectory, but most importantly you can re-run the test again using gdb by doing ./runtests.pl -g NNNN. That is, add a -g to make it start up gdb and run the same case using that.

Write Unit Tests

We put tests that focus on an area or a specific function into a single C source file. The source file should be named unitNNNN.c where NNNN is a previously unused number.

Add your test to tests/unit/Makefile.inc (if it is a unit test). Add your test data file name to tests/data/Makefile.inc

You also need a separate file called tests/data/testNNNN (using the same number) that describes your test case. See the test1300 file for inspiration and the tests/FILEFORMAT.md documentation.

For the actual C file, here's a simple example:


    #include "curlcheck.h"

    #include "a libcurl header.h" /* from the lib dir */

    static CURLcode unit_setup( void )
    {
      /* whatever you want done first */
      return CURLE_OK;
    }

    static void unit_stop( void )
    {
      /* done before shutting down and exiting */
    }

    UNITTEST_START

      /* here you start doing things and checking that the results are good */

      fail_unless( size == 0 , "initial size should be zero" );
      fail_if( head == NULL , "head should not be initiated to NULL" );

      /* you end the test code like this: */

    UNITTEST_STOP