]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
TESTS: quic: add unit-tests for QUIC TX part
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 4 Sep 2025 12:53:03 +0000 (14:53 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 8 Sep 2025 12:49:03 +0000 (14:49 +0200)
Define a new "quic_tx" unit-test which is used to test QUIC TX module.
For the moment, a single test is performed on qc_do_build_pkt(). It
checks that PADDING is correctly added for HP sampling in case of a
small packet.

src/quic_tx.c
tests/unit/quic/quic.sh

index 4c6d64518fb62ff65daf9a32d48d4ba3a7d6a451..7a2da7eed8fd4a40435bb800f9a7171924163b95 100644 (file)
@@ -2231,6 +2231,65 @@ static struct quic_tx_packet *qc_build_pkt(unsigned char **pos,
        TRACE_DEVEL("leaving on error", QUIC_EV_CONN_TXPKT, qc);
        return NULL;
 }
+
+int quic_tx_unittest(int argc, char **argv)
+{
+       struct quic_conn qc;
+       struct quic_cc_path path;
+       struct quic_pktns pktns;
+       struct quic_enc_level qel;
+       struct quic_tx_packet pkt;
+
+       unsigned char area[1024];
+       unsigned char *end = area + 1024;
+
+       unsigned char *buf_pn;
+       size_t pn_len;
+
+       struct list frms = LIST_HEAD_INIT(frms);
+       struct quic_frame frm;
+
+       /* Minimal quic_conn init and linked elements to be able to use
+        * qc_do_build_pkt() safely.
+        */
+       qc.dcid.len = 8;
+       qc.scid.len = 8;
+
+       qc.path = &path;
+       path.prep_in_flight = 0;
+       path.cwnd = 16384;
+
+       qel.pktns = &pktns;
+       pktns.rx.largest_acked_pn = 0;
+       pktns.tx.pto_probe = 0;
+       pktns.flags = 0;
+
+       /* short header packet */
+       pkt.type = QUIC_PACKET_TYPE_SHORT;
+       LIST_INIT(&pkt.frms);
+
+       /* payload frames content */
+       frm.type = QUIC_FT_MAX_STREAMS_BIDI;
+       frm.max_streams_bidi.max_streams = 4;
+       LIST_APPEND(&frms, &frm.list);
+
+       /* Built a small packet with a single MAX_STREAMS frame. Padding must
+        * be added so that PN decoding can be performed by the peer.
+        */
+       qc_do_build_pkt(area, end, 0, &pkt, 0, &pn_len, &buf_pn,
+                       0, 0, 0, 1,
+                       &qel, &qc, NULL, &frms);
+
+       /* Ensure padding has been added to packet.
+        * packet length = 1 (short hdlen) + 8 (DCID len) + 1 (PN len) + 3 (payload)
+        * payload       = 2 (MAX_STREAMS frm) + 1 (PADDING)
+        */
+       BUG_ON(pkt.len != 13 || pn_len  != 1);
+
+       return 0;
+}
+REGISTER_UNITTEST("quic_tx", quic_tx_unittest);
+
 /*
  * Local variables:
  *  c-indent-level: 8
index ecea5d550f5ea778f712b95b1ab137b5ec9b5c75..e9f05c6883e06cebe367bb52ad521a371e97dd98 100755 (executable)
@@ -6,6 +6,7 @@ check() {
 
 run() {
        ${HAPROXY_PROGRAM} -U quic_enc
+       ${HAPROXY_PROGRAM} -U quic_tx
 }
 
 case "$1" in