1a74702c6SGeorge Wang/* Copyright (c) 2017 - 2022 LiteSpeed Technologies Inc.  See LICENSE. */
250aadb33SDmitri Tikhonov#include <assert.h>
350aadb33SDmitri Tikhonov#include <stdio.h>
450aadb33SDmitri Tikhonov#include <stdlib.h>
550aadb33SDmitri Tikhonov#include <string.h>
650aadb33SDmitri Tikhonov#include <sys/queue.h>
7461e84d8SAmol Deshpande#ifndef WIN32
850aadb33SDmitri Tikhonov#include <sys/time.h>
9461e84d8SAmol Deshpande#endif
1050aadb33SDmitri Tikhonov
11461e84d8SAmol Deshpande#include "lsquic.h"
1250aadb33SDmitri Tikhonov#include "lsquic_types.h"
1350aadb33SDmitri Tikhonov#include "lsquic_parse.h"
1450aadb33SDmitri Tikhonov#include "lsquic_sfcw.h"
155392f7a3SLiteSpeed Tech#include "lsquic_varint.h"
165392f7a3SLiteSpeed Tech#include "lsquic_hq.h"
175392f7a3SLiteSpeed Tech#include "lsquic_hash.h"
1850aadb33SDmitri Tikhonov#include "lsquic_stream.h"
1950aadb33SDmitri Tikhonov
2050aadb33SDmitri Tikhonovstruct test {
2150aadb33SDmitri Tikhonov    int             lineno;
2250aadb33SDmitri Tikhonov    const struct parse_funcs *
2350aadb33SDmitri Tikhonov                    pf;
2450aadb33SDmitri Tikhonov    /* Inputs.  These are returned by lsquic_stream_tosend_fin(),
2550aadb33SDmitri Tikhonov     * lsquic_stream_tosend_read(), and lsquic_stream_tosend_offset().
2650aadb33SDmitri Tikhonov     */
2750aadb33SDmitri Tikhonov    int             fin[2];         /* There may be two calls to lsquic_stream_tosend_fin() */
2850aadb33SDmitri Tikhonov    uint64_t        offset;
2950aadb33SDmitri Tikhonov    uint32_t        stream_id;
3050aadb33SDmitri Tikhonov    size_t          avail;          /* Space to write stream frame to */
3150aadb33SDmitri Tikhonov    size_t          min_sz;         /* Minimum size needed to generate stream frame.  Any
3250aadb33SDmitri Tikhonov                                     * sizes smaller than this should fail.
3350aadb33SDmitri Tikhonov                                     */
3450aadb33SDmitri Tikhonov    size_t          data_sz;
3550aadb33SDmitri Tikhonov    char            data[0x100];
3650aadb33SDmitri Tikhonov
3750aadb33SDmitri Tikhonov    /* Output.  This is how we expect the resulting frame to look.
3850aadb33SDmitri Tikhonov     */
3950aadb33SDmitri Tikhonov    int             len;            /* Return value of gen_stream_frame() */
4050aadb33SDmitri Tikhonov    char            out[0x100];
4150aadb33SDmitri Tikhonov};
4250aadb33SDmitri Tikhonov
4350aadb33SDmitri Tikhonov
4450aadb33SDmitri Tikhonovstatic struct test_ctx {
4550aadb33SDmitri Tikhonov    const struct test *test;
4650aadb33SDmitri Tikhonov    int                next_fin;
4750aadb33SDmitri Tikhonov    lsquic_stream_t    stream;
4850aadb33SDmitri Tikhonov} test_ctx;
4950aadb33SDmitri Tikhonov
5050aadb33SDmitri Tikhonov
5150aadb33SDmitri Tikhonovstatic int
5250aadb33SDmitri Tikhonovstream_tosend_fin (void *stream)
5350aadb33SDmitri Tikhonov{
54461e84d8SAmol Deshpande    struct test_ctx *test_ctx2 = stream;
55461e84d8SAmol Deshpande    return test_ctx2->test->fin[ test_ctx2->next_fin++ ];
5650aadb33SDmitri Tikhonov}
5750aadb33SDmitri Tikhonov
5850aadb33SDmitri Tikhonov
5950aadb33SDmitri Tikhonovstatic size_t
6050aadb33SDmitri Tikhonovstream_tosend_read (void *stream, void *buf, size_t len, int *reached_fin)
6150aadb33SDmitri Tikhonov{
62461e84d8SAmol Deshpande    struct test_ctx *test_ctx2 = stream;
63461e84d8SAmol Deshpande    if (test_ctx2->test->data_sz < len)
64461e84d8SAmol Deshpande        len = test_ctx2->test->data_sz;
65461e84d8SAmol Deshpande    memcpy(buf, test_ctx2->test->data, len);
6650aadb33SDmitri Tikhonov    *reached_fin = stream_tosend_fin(stream);
6750aadb33SDmitri Tikhonov    return len;
6850aadb33SDmitri Tikhonov}
6950aadb33SDmitri Tikhonov
7050aadb33SDmitri Tikhonov
7150aadb33SDmitri Tikhonovstatic size_t
7250aadb33SDmitri Tikhonovstream_tosend_size (void *stream)
7350aadb33SDmitri Tikhonov{
74461e84d8SAmol Deshpande    struct test_ctx *test_ctx2 = stream;
75461e84d8SAmol Deshpande    return test_ctx2->test->data_sz;
7650aadb33SDmitri Tikhonov}
7750aadb33SDmitri Tikhonov
7850aadb33SDmitri Tikhonov
7950aadb33SDmitri Tikhonovstatic void
8050aadb33SDmitri Tikhonovreset_ctx (const struct test *test)
8150aadb33SDmitri Tikhonov{
8250aadb33SDmitri Tikhonov    test_ctx.test      = test;
8350aadb33SDmitri Tikhonov    test_ctx.next_fin  = 0;
8450aadb33SDmitri Tikhonov    test_ctx.stream.id = test->stream_id;
8550aadb33SDmitri Tikhonov}
8650aadb33SDmitri Tikhonov
8750aadb33SDmitri Tikhonov
8850aadb33SDmitri Tikhonovstatic void
89f07b3eaeSTyler Youngrun_test (const struct test *const test)
9050aadb33SDmitri Tikhonov{
9150aadb33SDmitri Tikhonov
9250aadb33SDmitri Tikhonov    unsigned char out[0x100];
9350aadb33SDmitri Tikhonov    int len;
9450aadb33SDmitri Tikhonov    size_t min;
9550aadb33SDmitri Tikhonov
9650aadb33SDmitri Tikhonov    if (test->len > 0)
9750aadb33SDmitri Tikhonov    {
9850aadb33SDmitri Tikhonov        /* Test that all sizes under specified min fail to produce a frame */
9950aadb33SDmitri Tikhonov        for (min = 0; min < test->min_sz; ++min)
10050aadb33SDmitri Tikhonov        {
10150aadb33SDmitri Tikhonov            reset_ctx(test);
102bfc7bfd8SDmitri Tikhonov            len = test->pf->pf_gen_stream_frame(out, min, test->stream_id,
103bfc7bfd8SDmitri Tikhonov                        test_ctx.test->offset, stream_tosend_fin(&test_ctx),
104bfc7bfd8SDmitri Tikhonov                        stream_tosend_size(&test_ctx), stream_tosend_read, &test_ctx);
10514e3680dSDmitri Tikhonov            assert(len < 0);
10650aadb33SDmitri Tikhonov        }
10750aadb33SDmitri Tikhonov
10850aadb33SDmitri Tikhonov        /* Test that it succeeds now: */
10950aadb33SDmitri Tikhonov        reset_ctx(test);
110bfc7bfd8SDmitri Tikhonov        len = test->pf->pf_gen_stream_frame(out, min, test->stream_id,
111bfc7bfd8SDmitri Tikhonov                        test_ctx.test->offset, stream_tosend_fin(&test_ctx),
112bfc7bfd8SDmitri Tikhonov                        stream_tosend_size(&test_ctx), stream_tosend_read, &test_ctx);
11350aadb33SDmitri Tikhonov        assert(len == (int) min);
11450aadb33SDmitri Tikhonov    }
11550aadb33SDmitri Tikhonov
11650aadb33SDmitri Tikhonov    reset_ctx(test);
117bfc7bfd8SDmitri Tikhonov    len = test->pf->pf_gen_stream_frame(out, test->avail, test->stream_id,
118bfc7bfd8SDmitri Tikhonov                    test_ctx.test->offset, stream_tosend_fin(&test_ctx),
119bfc7bfd8SDmitri Tikhonov                    stream_tosend_size(&test_ctx), stream_tosend_read, &test_ctx);
12050aadb33SDmitri Tikhonov
12150aadb33SDmitri Tikhonov    if (test->len > 0) {
12250aadb33SDmitri Tikhonov        /* Check parser operation */
12350aadb33SDmitri Tikhonov        assert(test->len == len);
12450aadb33SDmitri Tikhonov        assert(("Generated frame is correct", 0 == memcmp(test->out, out, test->len)));
12550aadb33SDmitri Tikhonov    }
12650aadb33SDmitri Tikhonov    else
12750aadb33SDmitri Tikhonov    {
12850aadb33SDmitri Tikhonov        assert(("This test should fail", len < 0));
12950aadb33SDmitri Tikhonov    }
13050aadb33SDmitri Tikhonov}
13150aadb33SDmitri Tikhonov
13250aadb33SDmitri Tikhonov
13350aadb33SDmitri Tikhonovint
13450aadb33SDmitri Tikhonovmain (void)
13550aadb33SDmitri Tikhonov{
136f07b3eaeSTyler Young    const struct test tests[] = {
1376ff1e9b8SGeorge Wang        /*
1386ff1e9b8SGeorge Wang         * Big-endian:
1396ff1e9b8SGeorge Wang         */
1406ff1e9b8SGeorge Wang        {   .lineno     = __LINE__,
1416ff1e9b8SGeorge Wang            .pf         = select_pf_by_ver(LSQVER_043),
1426ff1e9b8SGeorge Wang            .fin        = { 0, 1, },
1436ff1e9b8SGeorge Wang            .offset     = 0x0807060504030201UL,
1446ff1e9b8SGeorge Wang            .stream_id  = 0x210,
1456ff1e9b8SGeorge Wang            .data_sz    = 10,
1466ff1e9b8SGeorge Wang            .data       = "0123456789",
1476ff1e9b8SGeorge Wang            .avail      = 0x100,
1486ff1e9b8SGeorge Wang            .out        =
1496ff1e9b8SGeorge Wang          /*  1      f      d      ooo    ss            1fdoooss */
1506ff1e9b8SGeorge Wang          /*  TYPE   FIN    DLEN   OLEN   SLEN  */
1516ff1e9b8SGeorge Wang            { 0x80 | 0x40 | 0x20 | 0x1C | 0x01,
1526ff1e9b8SGeorge Wang              0x02, 0x10,                                       /* Stream ID */
1536ff1e9b8SGeorge Wang              0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01,   /* Offset */
1546ff1e9b8SGeorge Wang              0x00, 0x0A,                                       /* Data length */
1556ff1e9b8SGeorge Wang              '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
1566ff1e9b8SGeorge Wang            },
1576ff1e9b8SGeorge Wang            .len        = 1 + 2 + 8 + 2 + 10,
1586ff1e9b8SGeorge Wang            .min_sz     = 1 + 2 + 8 + 0 + 1,
1596ff1e9b8SGeorge Wang        },
1606ff1e9b8SGeorge Wang
1616ff1e9b8SGeorge Wang        {   .lineno     = __LINE__,
1626ff1e9b8SGeorge Wang            .pf         = select_pf_by_ver(LSQVER_043),
1636ff1e9b8SGeorge Wang            .fin        = { 0, 0, },
1646ff1e9b8SGeorge Wang            .offset     = 0x0807060504030201UL,
1656ff1e9b8SGeorge Wang            .stream_id  = 0x210,
1666ff1e9b8SGeorge Wang            .data_sz    = 10,
1676ff1e9b8SGeorge Wang            .data       = "0123456789",
1686ff1e9b8SGeorge Wang            .avail      = 0x100,
1696ff1e9b8SGeorge Wang            .out        =
1706ff1e9b8SGeorge Wang          /*  1      f      d      ooo    ss            1fdoooss */
1716ff1e9b8SGeorge Wang          /*  TYPE   FIN    DLEN   OLEN   SLEN  */
1726ff1e9b8SGeorge Wang            { 0x80 | 0x00 | 0x20 | 0x1C | 0x01,
1736ff1e9b8SGeorge Wang              0x02, 0x10,                                       /* Stream ID */
1746ff1e9b8SGeorge Wang              0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01,   /* Offset */
1756ff1e9b8SGeorge Wang              0x00, 0x0A,                                       /* Data length */
1766ff1e9b8SGeorge Wang              '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
1776ff1e9b8SGeorge Wang            },
1786ff1e9b8SGeorge Wang            .len        = 1 + 2 + 8 + 2 + 10,
1796ff1e9b8SGeorge Wang            .min_sz     = 1 + 2 + 8 + 0 + 1,
1806ff1e9b8SGeorge Wang        },
1816ff1e9b8SGeorge Wang
1826ff1e9b8SGeorge Wang        {   .lineno     = __LINE__,
1836ff1e9b8SGeorge Wang            .pf         = select_pf_by_ver(LSQVER_043),
1846ff1e9b8SGeorge Wang            .fin        = { 1, 0, },
1856ff1e9b8SGeorge Wang            .offset     = 0x0807060504030201UL,
1866ff1e9b8SGeorge Wang            .stream_id  = 0x210,
1876ff1e9b8SGeorge Wang            .data_sz    = 10,
1886ff1e9b8SGeorge Wang            .data       = "0123456789",
1896ff1e9b8SGeorge Wang            .avail      = 0x100,
1906ff1e9b8SGeorge Wang            .out        =
1916ff1e9b8SGeorge Wang          /*  1      f      d      ooo    ss            1fdoooss */
1926ff1e9b8SGeorge Wang          /*  TYPE   FIN    DLEN   OLEN   SLEN  */
1936ff1e9b8SGeorge Wang            { 0x80 | 0x40 | 0x20 | 0x1C | 0x01,
1946ff1e9b8SGeorge Wang              0x02, 0x10,                                       /* Stream ID */
1956ff1e9b8SGeorge Wang              0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01,   /* Offset */
1966ff1e9b8SGeorge Wang              0x00, 0x00,                                       /* Data length */
1976ff1e9b8SGeorge Wang              '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
1986ff1e9b8SGeorge Wang            },
1996ff1e9b8SGeorge Wang            .len        = 1 + 2 + 8 + 2,
2006ff1e9b8SGeorge Wang            .min_sz     = 1 + 2 + 8 + 2,
2016ff1e9b8SGeorge Wang        },
2026ff1e9b8SGeorge Wang
2036ff1e9b8SGeorge Wang        {   .lineno     = __LINE__,
2046ff1e9b8SGeorge Wang            .pf         = select_pf_by_ver(LSQVER_043),
2056ff1e9b8SGeorge Wang            .fin        = { 1, 0, },
2066ff1e9b8SGeorge Wang            .offset     = 0x0807060504030201UL,
2076ff1e9b8SGeorge Wang            .stream_id  = 0x21,
2086ff1e9b8SGeorge Wang            .data_sz    = 10,
2096ff1e9b8SGeorge Wang            .data       = "0123456789",
2106ff1e9b8SGeorge Wang            .avail      = 0x100,
2116ff1e9b8SGeorge Wang            .out        =
2126ff1e9b8SGeorge Wang          /*  1      f      d      ooo    ss            1fdoooss */
2136ff1e9b8SGeorge Wang          /*  TYPE   FIN    DLEN   OLEN   SLEN  */
2146ff1e9b8SGeorge Wang            { 0x80 | 0x40 | 0x20 | 0x1C | 0x00,
2156ff1e9b8SGeorge Wang              0x21,                                             /* Stream ID */
2166ff1e9b8SGeorge Wang              0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01,   /* Offset */
2176ff1e9b8SGeorge Wang              0x00, 0x00,                                       /* Data length */
2186ff1e9b8SGeorge Wang              '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
2196ff1e9b8SGeorge Wang            },
2206ff1e9b8SGeorge Wang            .len        = 1 + 1 + 8 + 2,
2216ff1e9b8SGeorge Wang            .min_sz     = 1 + 1 + 8 + 2,
2226ff1e9b8SGeorge Wang        },
2236ff1e9b8SGeorge Wang
2246ff1e9b8SGeorge Wang        {   .lineno     = __LINE__,
2256ff1e9b8SGeorge Wang            .pf         = select_pf_by_ver(LSQVER_043),
2266ff1e9b8SGeorge Wang            .fin        = { 0, 0, },
2276ff1e9b8SGeorge Wang            .offset     = 0x77,
2286ff1e9b8SGeorge Wang            .stream_id  = 0x210,
2296ff1e9b8SGeorge Wang            .data_sz    = 10,
2306ff1e9b8SGeorge Wang            .data       = "0123456789",
2316ff1e9b8SGeorge Wang            .avail      = 0x100,
2326ff1e9b8SGeorge Wang            .out        =
2336ff1e9b8SGeorge Wang          /*  1      f      d      ooo    ss            1fdoooss */
2346ff1e9b8SGeorge Wang          /*  TYPE   FIN    DLEN   OLEN   SLEN  */
2356ff1e9b8SGeorge Wang            { 0x80 | 0x00 | 0x20 | 0x04 | 0x01,
2366ff1e9b8SGeorge Wang              0x02, 0x10,                                       /* Stream ID */
2376ff1e9b8SGeorge Wang              0x00, 0x77,                                       /* Offset */
2386ff1e9b8SGeorge Wang              0x00, 0x0A,                                       /* Data length */
2396ff1e9b8SGeorge Wang              '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
2406ff1e9b8SGeorge Wang            },
2416ff1e9b8SGeorge Wang            .len        = 1 + 2 + 2 + 2 + 10,
2426ff1e9b8SGeorge Wang            .min_sz     = 1 + 2 + 2 + 0 + 1,
2436ff1e9b8SGeorge Wang        },
2446ff1e9b8SGeorge Wang
2456ff1e9b8SGeorge Wang        {   .lineno     = __LINE__,
2466ff1e9b8SGeorge Wang            .pf         = select_pf_by_ver(LSQVER_043),
2476ff1e9b8SGeorge Wang            .fin        = { 0, 0, },
2486ff1e9b8SGeorge Wang            .offset     = 0x0,
2496ff1e9b8SGeorge Wang            .stream_id  = 0x210,
2506ff1e9b8SGeorge Wang            .data_sz    = 10,
2516ff1e9b8SGeorge Wang            .data       = "0123456789",
2526ff1e9b8SGeorge Wang            .avail      = 0x100,
2536ff1e9b8SGeorge Wang            .out        =
2546ff1e9b8SGeorge Wang          /*  1      f      d      ooo    ss            1fdoooss */
2556ff1e9b8SGeorge Wang          /*  TYPE   FIN    DLEN   OLEN   SLEN  */
2566ff1e9b8SGeorge Wang            { 0x80 | 0x00 | 0x20 | 0x00 | 0x01,
2576ff1e9b8SGeorge Wang              0x02, 0x10,                                       /* Stream ID */
2586ff1e9b8SGeorge Wang                                                                /* Offset */
2596ff1e9b8SGeorge Wang              0x00, 0x0A,                                       /* Data length */
2606ff1e9b8SGeorge Wang              '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
2616ff1e9b8SGeorge Wang            },
2626ff1e9b8SGeorge Wang            .len        = 1 + 2 + 0 + 2 + 10,
2636ff1e9b8SGeorge Wang            .min_sz     = 1 + 2 + 0 + 0 + 1,
2646ff1e9b8SGeorge Wang        },
2656ff1e9b8SGeorge Wang
2666ff1e9b8SGeorge Wang        {   .lineno     = __LINE__,
2676ff1e9b8SGeorge Wang            .pf         = select_pf_by_ver(LSQVER_043),
2686ff1e9b8SGeorge Wang            .fin        = { 0, 1, },
2696ff1e9b8SGeorge Wang            .offset     = 0x0,
2706ff1e9b8SGeorge Wang            .stream_id  = 0x210,
2716ff1e9b8SGeorge Wang            .data_sz    = 1,
2726ff1e9b8SGeorge Wang            .data       = "0123456789",
2736ff1e9b8SGeorge Wang            .avail      = 0x100,
2746ff1e9b8SGeorge Wang            .out        =
2756ff1e9b8SGeorge Wang          /*  1      f      d      ooo    ss            1fdoooss */
2766ff1e9b8SGeorge Wang          /*  TYPE   FIN    DLEN   OLEN   SLEN  */
2776ff1e9b8SGeorge Wang            { 0x80 | 0x40 | 0x20 | 0x00 | 0x01,
2786ff1e9b8SGeorge Wang              0x02, 0x10,                                       /* Stream ID */
2796ff1e9b8SGeorge Wang                                                                /* Offset */
2806ff1e9b8SGeorge Wang              0x00, 0x01,                                       /* Data length */
2816ff1e9b8SGeorge Wang              '0',
2826ff1e9b8SGeorge Wang            },
2836ff1e9b8SGeorge Wang            .len        = 1 + 2 + 0 + 2 + 1,
2846ff1e9b8SGeorge Wang            .min_sz     = 1 + 2 + 0 + 0 + 1,
2856ff1e9b8SGeorge Wang        },
2866ff1e9b8SGeorge Wang
2876ff1e9b8SGeorge Wang        {   .lineno     = __LINE__,
2886ff1e9b8SGeorge Wang            .pf         = select_pf_by_ver(LSQVER_043),
2896ff1e9b8SGeorge Wang            .fin        = { 0, 0, },
2906ff1e9b8SGeorge Wang            .offset     = 0xFFFFFF,
2916ff1e9b8SGeorge Wang            .stream_id  = 0x210,
2926ff1e9b8SGeorge Wang            .data_sz    = 10,
2936ff1e9b8SGeorge Wang            .data       = "0123456789",
2946ff1e9b8SGeorge Wang            .avail      = 0x100,
2956ff1e9b8SGeorge Wang            .out        =
2966ff1e9b8SGeorge Wang          /*  1      f      d      ooo    ss            1fdoooss */
2976ff1e9b8SGeorge Wang          /*  TYPE   FIN    DLEN   OLEN   SLEN  */
2986ff1e9b8SGeorge Wang            { 0x80 | 0x00 | 0x20 | 0x08 | 0x01,
2996ff1e9b8SGeorge Wang              0x02, 0x10,                                       /* Stream ID */
3006ff1e9b8SGeorge Wang              0xFF, 0xFF, 0xFF,                                 /* Offset */
3016ff1e9b8SGeorge Wang              0x00, 0x0A,                                       /* Data length */
3026ff1e9b8SGeorge Wang              '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
3036ff1e9b8SGeorge Wang            },
3046ff1e9b8SGeorge Wang            .len        = 1 + 2 + 3 + 2 + 10,
3056ff1e9b8SGeorge Wang            .min_sz     = 1 + 2 + 3 + 0 + 1,
3066ff1e9b8SGeorge Wang        },
3076ff1e9b8SGeorge Wang
3086ff1e9b8SGeorge Wang        {   .lineno     = __LINE__,
3096ff1e9b8SGeorge Wang            .pf         = select_pf_by_ver(LSQVER_043),
3106ff1e9b8SGeorge Wang            .fin        = { 0, 0, },
3116ff1e9b8SGeorge Wang            .offset     = 0xFFFFFF + 1,
3126ff1e9b8SGeorge Wang            .stream_id  = 0x210,
3136ff1e9b8SGeorge Wang            .data_sz    = 10,
3146ff1e9b8SGeorge Wang            .data       = "0123456789",
3156ff1e9b8SGeorge Wang            .avail      = 0x100,
3166ff1e9b8SGeorge Wang            .out        =
3176ff1e9b8SGeorge Wang          /*  1      f      d      ooo    ss            1fdoooss */
3186ff1e9b8SGeorge Wang          /*  TYPE   FIN    DLEN   OLEN   SLEN  */
3196ff1e9b8SGeorge Wang            { 0x80 | 0x00 | 0x20 | 0x0C | 0x01,
3206ff1e9b8SGeorge Wang              0x02, 0x10,                                       /* Stream ID */
3216ff1e9b8SGeorge Wang              0x01, 0x00, 0x00, 0x00,                           /* Offset */
3226ff1e9b8SGeorge Wang              0x00, 0x0A,                                       /* Data length */
3236ff1e9b8SGeorge Wang              '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
3246ff1e9b8SGeorge Wang            },
3256ff1e9b8SGeorge Wang            .len        = 1 + 2 + 4 + 2 + 10,
3266ff1e9b8SGeorge Wang            .min_sz     = 1 + 2 + 4 + 0 + 1,
3276ff1e9b8SGeorge Wang        },
3286ff1e9b8SGeorge Wang
3296ff1e9b8SGeorge Wang        {   .lineno     = __LINE__,
3306ff1e9b8SGeorge Wang            .pf         = select_pf_by_ver(LSQVER_043),
3316ff1e9b8SGeorge Wang            .fin        = { 0, 0, },
3326ff1e9b8SGeorge Wang            .offset     = 0xFFFFFF + 1,
3336ff1e9b8SGeorge Wang            .stream_id  = 0x210,
3346ff1e9b8SGeorge Wang            .data_sz    = 10,
3356ff1e9b8SGeorge Wang            .data       = "0123456789",
3366ff1e9b8SGeorge Wang            .avail      = 10,
3376ff1e9b8SGeorge Wang            .out        =
3386ff1e9b8SGeorge Wang          /*  1      f      d      ooo    ss            1fdoooss */
3396ff1e9b8SGeorge Wang          /*  TYPE   FIN    DLEN   OLEN   SLEN  */
3406ff1e9b8SGeorge Wang            { 0x80 | 0x00 | 0x00 | 0x0C | 0x01,
3416ff1e9b8SGeorge Wang              0x02, 0x10,                                       /* Stream ID */
3426ff1e9b8SGeorge Wang              0x01, 0x00, 0x00, 0x00,                           /* Offset */
3436ff1e9b8SGeorge Wang              '0', '1', '2',
3446ff1e9b8SGeorge Wang            },
3456ff1e9b8SGeorge Wang            .len        = 1 + 2 + 4 + 0 + 3,
3466ff1e9b8SGeorge Wang            .min_sz     = 1 + 2 + 4 + 0 + 1,
3476ff1e9b8SGeorge Wang        },
3486ff1e9b8SGeorge Wang
3496ff1e9b8SGeorge Wang        {   .lineno     = __LINE__,
3506ff1e9b8SGeorge Wang            .pf         = select_pf_by_ver(LSQVER_043),
3516ff1e9b8SGeorge Wang            .fin        = { 1, 0, },
3526ff1e9b8SGeorge Wang            .offset     = 0xB4,
3536ff1e9b8SGeorge Wang            .stream_id  = 0x01,
3546ff1e9b8SGeorge Wang            .data_sz    = 0,
3556ff1e9b8SGeorge Wang            .data       = "0123456789",
3566ff1e9b8SGeorge Wang            .avail      = 0x100,
3576ff1e9b8SGeorge Wang            .out        =
3586ff1e9b8SGeorge Wang          /*  1      f      d      ooo    ss            1fdoooss */
3596ff1e9b8SGeorge Wang          /*  TYPE   FIN    DLEN   OLEN   SLEN  */
3606ff1e9b8SGeorge Wang            { 0x80 | 0x40 | 0x20 | 0x04 | 0x00,
3616ff1e9b8SGeorge Wang              0x01,                                             /* Stream ID */
3626ff1e9b8SGeorge Wang              0x00, 0xB4,                                       /* Offset */
3636ff1e9b8SGeorge Wang              0x00, 0x00,                                       /* Data length */
3646ff1e9b8SGeorge Wang            },
3656ff1e9b8SGeorge Wang            .len        = 6,
3666ff1e9b8SGeorge Wang            .min_sz     = 6,
3676ff1e9b8SGeorge Wang        },
3686ff1e9b8SGeorge Wang
3696ff1e9b8SGeorge Wang        /*
3706ff1e9b8SGeorge Wang         * IETF QUIC Internet-Draft 17:
3716ff1e9b8SGeorge Wang         */
3726ff1e9b8SGeorge Wang
3736ff1e9b8SGeorge Wang        {   .lineno     = __LINE__,
3746ff1e9b8SGeorge Wang            .pf         = select_pf_by_ver(LSQVER_ID27),
3756ff1e9b8SGeorge Wang            .fin        = { 0, 1, },
3766ff1e9b8SGeorge Wang            .offset     = 0x0807060504030201UL,
3776ff1e9b8SGeorge Wang            .stream_id  = 0x210,
3786ff1e9b8SGeorge Wang            .data_sz    = 10,
3796ff1e9b8SGeorge Wang            .data       = "0123456789",
3806ff1e9b8SGeorge Wang            .avail      = 0x100,
3816ff1e9b8SGeorge Wang            .out        =
3826ff1e9b8SGeorge Wang          /*  TYPE   OFF    DLEN   FIN  */
3836ff1e9b8SGeorge Wang            { 0x08 | 1<<2 | 1<<1 | 1<<0,
3846ff1e9b8SGeorge Wang              0x42, 0x10,                                       /* Stream ID */
3856ff1e9b8SGeorge Wang              0xC8, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01,   /* Offset */
3866ff1e9b8SGeorge Wang              0x0A,                                             /* Data length */
3876ff1e9b8SGeorge Wang              '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
3886ff1e9b8SGeorge Wang            },
3896ff1e9b8SGeorge Wang            .len        = 1 + 2 + 8 + 1 + 10,
3906ff1e9b8SGeorge Wang            .min_sz     = 1 + 2 + 8 + 0 + 1,
3916ff1e9b8SGeorge Wang        },
3926ff1e9b8SGeorge Wang
3936ff1e9b8SGeorge Wang        {   .lineno     = __LINE__,
3946ff1e9b8SGeorge Wang            .pf         = select_pf_by_ver(LSQVER_ID27),
3956ff1e9b8SGeorge Wang            .fin        = { 0, 0, },
3966ff1e9b8SGeorge Wang            .offset     = 0,
3976ff1e9b8SGeorge Wang            .stream_id  = 0x210,
3986ff1e9b8SGeorge Wang            .data_sz    = 10,
3996ff1e9b8SGeorge Wang            .data       = "0123456789",
4006ff1e9b8SGeorge Wang            .avail      = 0x100,
4016ff1e9b8SGeorge Wang            .out        =
4026ff1e9b8SGeorge Wang          /*  TYPE   OFF    DLEN   FIN  */
4036ff1e9b8SGeorge Wang            { 0x08 | 0<<2 | 1<<1 | 0<<0,
4046ff1e9b8SGeorge Wang              0x42, 0x10,                                       /* Stream ID */
4056ff1e9b8SGeorge Wang              0x0A,                                             /* Data length */
4066ff1e9b8SGeorge Wang              '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
4076ff1e9b8SGeorge Wang            },
4086ff1e9b8SGeorge Wang            .len        = 1 + 2 + 0 + 1 + 10,
4096ff1e9b8SGeorge Wang            .min_sz     = 1 + 2 + 0 + 0 + 1,
4106ff1e9b8SGeorge Wang        },
4116ff1e9b8SGeorge Wang
4126ff1e9b8SGeorge Wang        {   .lineno     = __LINE__,
4136ff1e9b8SGeorge Wang            .pf         = select_pf_by_ver(LSQVER_ID27),
4146ff1e9b8SGeorge Wang            .fin        = { 0, 0, },
4156ff1e9b8SGeorge Wang            .offset     = 0,
4166ff1e9b8SGeorge Wang            .stream_id  = 0x21,
4176ff1e9b8SGeorge Wang            .data_sz    = 10,
4186ff1e9b8SGeorge Wang            .data       = "0123456789",
4196ff1e9b8SGeorge Wang            .avail      = 12,
4206ff1e9b8SGeorge Wang            .out        =
4216ff1e9b8SGeorge Wang          /*  TYPE   OFF    DLEN   FIN  */
4226ff1e9b8SGeorge Wang            { 0x08 | 0<<2 | 0<<1 | 0<<0,
4236ff1e9b8SGeorge Wang              0x21,                                             /* Stream ID */
4246ff1e9b8SGeorge Wang              '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
4256ff1e9b8SGeorge Wang            },
4266ff1e9b8SGeorge Wang            .len        = 1 + 1 + 0 + 0 + 10,
4276ff1e9b8SGeorge Wang            .min_sz     = 1 + 1 + 0 + 0 + 1,
4286ff1e9b8SGeorge Wang        },
4296ff1e9b8SGeorge Wang
4306ff1e9b8SGeorge Wang        {   .lineno     = __LINE__,
4316ff1e9b8SGeorge Wang            .pf         = select_pf_by_ver(LSQVER_ID27),
4326ff1e9b8SGeorge Wang            .fin        = { 0, 0, },
4336ff1e9b8SGeorge Wang            .offset     = 0x0807060504030201UL,
4346ff1e9b8SGeorge Wang            .stream_id  = 0x210,
4356ff1e9b8SGeorge Wang            .data_sz    = 10,
4366ff1e9b8SGeorge Wang            .data       = "0123456789",
4376ff1e9b8SGeorge Wang            .avail      = 0x100,
4386ff1e9b8SGeorge Wang            .out        =
4396ff1e9b8SGeorge Wang          /*  TYPE   OFF    DLEN   FIN  */
4406ff1e9b8SGeorge Wang            { 0x08 | 1<<2 | 1<<1 | 0<<0,
4416ff1e9b8SGeorge Wang              0x42, 0x10,                                       /* Stream ID */
4426ff1e9b8SGeorge Wang              0xC8, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01,   /* Offset */
4436ff1e9b8SGeorge Wang              0x0A,                                             /* Data length */
4446ff1e9b8SGeorge Wang              '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
4456ff1e9b8SGeorge Wang            },
4466ff1e9b8SGeorge Wang            .len        = 1 + 2 + 8 + 1 + 10,
4476ff1e9b8SGeorge Wang            .min_sz     = 1 + 2 + 8 + 0 + 1,
4486ff1e9b8SGeorge Wang        },
4496ff1e9b8SGeorge Wang
4506ff1e9b8SGeorge Wang        {   .lineno     = __LINE__,
4516ff1e9b8SGeorge Wang            .pf         = select_pf_by_ver(LSQVER_ID27),
4526ff1e9b8SGeorge Wang            .fin        = { 1, 0, },
4536ff1e9b8SGeorge Wang            .offset     = 0x0807060504030201UL,
4546ff1e9b8SGeorge Wang            .stream_id  = 0x210,
4556ff1e9b8SGeorge Wang            .data_sz    = 0,
4566ff1e9b8SGeorge Wang            .data       = "0123456789",
4576ff1e9b8SGeorge Wang            .avail      = 11,
4586ff1e9b8SGeorge Wang            .out        =
4596ff1e9b8SGeorge Wang          /*  TYPE   OFF    DLEN   FIN  */
4606ff1e9b8SGeorge Wang            { 0x08 | 1<<2 | 0<<1 | 1<<0,
4616ff1e9b8SGeorge Wang              0x42, 0x10,                                       /* Stream ID */
4626ff1e9b8SGeorge Wang              0xC8, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01,   /* Offset */
4636ff1e9b8SGeorge Wang            },
4646ff1e9b8SGeorge Wang            .len        = 1 + 2 + 8,
4656ff1e9b8SGeorge Wang            .min_sz     = 1 + 2 + 8,
4666ff1e9b8SGeorge Wang        },
4676ff1e9b8SGeorge Wang
4686ff1e9b8SGeorge Wang        {   .lineno     = __LINE__,
4696ff1e9b8SGeorge Wang            .pf         = select_pf_by_ver(LSQVER_ID27),
4706ff1e9b8SGeorge Wang            .fin        = { 1, 0, },
4716ff1e9b8SGeorge Wang            .offset     = 0x0807060504030201UL,
4726ff1e9b8SGeorge Wang            .stream_id  = 0x210,
4736ff1e9b8SGeorge Wang            .data_sz    = 0,
4746ff1e9b8SGeorge Wang            .data       = "0123456789",
4756ff1e9b8SGeorge Wang            .avail      = 0x100,
4766ff1e9b8SGeorge Wang            .out        =
4776ff1e9b8SGeorge Wang          /*  TYPE   OFF    DLEN   FIN  */
4786ff1e9b8SGeorge Wang            { 0x08 | 1<<2 | 1<<1 | 1<<0,
4796ff1e9b8SGeorge Wang              0x42, 0x10,                                       /* Stream ID */
4806ff1e9b8SGeorge Wang              0xC8, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01,   /* Offset */
4816ff1e9b8SGeorge Wang              0x00,                                             /* Data length */
4826ff1e9b8SGeorge Wang            },
4836ff1e9b8SGeorge Wang            .len        = 1 + 2 + 8 + 1,
4846ff1e9b8SGeorge Wang            .min_sz     = 1 + 2 + 8,
4856ff1e9b8SGeorge Wang        },
4866ff1e9b8SGeorge Wang
4876ff1e9b8SGeorge Wang    };
488f07b3eaeSTyler Young
48950aadb33SDmitri Tikhonov    unsigned i;
49050aadb33SDmitri Tikhonov    for (i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
491f07b3eaeSTyler Young        run_test(&tests[i]);
49250aadb33SDmitri Tikhonov    return 0;
49350aadb33SDmitri Tikhonov}
494