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>
6461e84d8SAmol Deshpande#ifndef WIN32
750aadb33SDmitri Tikhonov#include <sys/time.h>
8461e84d8SAmol Deshpande#endif
9461e84d8SAmol Deshpande#include <sys/queue.h>
1050aadb33SDmitri Tikhonov
11461e84d8SAmol Deshpande#include "lsquic.h"
1250aadb33SDmitri Tikhonov#include "lsquic_types.h"
1350aadb33SDmitri Tikhonov#include "lsquic_parse.h"
14bfc7bfd8SDmitri Tikhonov#include "lsquic_packet_common.h"
1550aadb33SDmitri Tikhonov#include "lsquic_packet_in.h"
1650aadb33SDmitri Tikhonov
1750aadb33SDmitri Tikhonovstruct test {
1850aadb33SDmitri Tikhonov    const char     *name;
1950aadb33SDmitri Tikhonov    int             lineno;
2050aadb33SDmitri Tikhonov    const struct parse_funcs *
2150aadb33SDmitri Tikhonov                    pf;
2250aadb33SDmitri Tikhonov    const unsigned char
2350aadb33SDmitri Tikhonov                    buf[0x100];    /* Large enough for our needs */
2450aadb33SDmitri Tikhonov    size_t          buf_sz;        /* # of stream frame bytes in `buf' */
2550aadb33SDmitri Tikhonov    size_t          rem_packet_sz; /* # of bytes remaining in the packet,
2650aadb33SDmitri Tikhonov                                    * starting at the beginning of the
2750aadb33SDmitri Tikhonov                                    * stream frame.
2850aadb33SDmitri Tikhonov                                    */
2950aadb33SDmitri Tikhonov    stream_frame_t  frame;         /* Expected values */
3050aadb33SDmitri Tikhonov    int             should_succeed;
3150aadb33SDmitri Tikhonov};
3250aadb33SDmitri Tikhonov
3350aadb33SDmitri Tikhonovstatic void
3450aadb33SDmitri Tikhonovrun_test (const struct test *test)
3550aadb33SDmitri Tikhonov{
3650aadb33SDmitri Tikhonov    stream_frame_t frame;
3750aadb33SDmitri Tikhonov    memset(&frame, 0x7A, sizeof(frame));
3850aadb33SDmitri Tikhonov
3950aadb33SDmitri Tikhonov    int len = test->pf->pf_parse_stream_frame(test->buf, test->rem_packet_sz, &frame);
4050aadb33SDmitri Tikhonov
4150aadb33SDmitri Tikhonov    if (test->should_succeed) {
4250aadb33SDmitri Tikhonov        /* Check parser operation */
4350aadb33SDmitri Tikhonov        assert(("Parsed correct number of bytes", (size_t) len == test->buf_sz + test->frame.data_frame.df_size));
4450aadb33SDmitri Tikhonov        assert(("Stream ID is correct", frame.stream_id == test->frame.stream_id));
4550aadb33SDmitri Tikhonov        assert(("Data length is correct", frame.data_frame.df_size == test->frame.data_frame.df_size));
4650aadb33SDmitri Tikhonov        assert(("Offset is correct", frame.data_frame.df_offset == test->frame.data_frame.df_offset));
4750aadb33SDmitri Tikhonov        assert(("FIN is correct", frame.data_frame.df_fin == test->frame.data_frame.df_fin));
4850aadb33SDmitri Tikhonov
4950aadb33SDmitri Tikhonov        /* Check that initialization of other fields occurred correctly: */
5050aadb33SDmitri Tikhonov        assert(0 == frame.packet_in);
5150aadb33SDmitri Tikhonov        assert(0 == frame.data_frame.df_read_off);
5250aadb33SDmitri Tikhonov    }
5350aadb33SDmitri Tikhonov    else
5450aadb33SDmitri Tikhonov    {
5550aadb33SDmitri Tikhonov        assert(("This test should fail", len < 0));
5650aadb33SDmitri Tikhonov    }
5750aadb33SDmitri Tikhonov}
5850aadb33SDmitri Tikhonov
5950aadb33SDmitri Tikhonov
6050aadb33SDmitri Tikhonovint
6150aadb33SDmitri Tikhonovmain (void)
6250aadb33SDmitri Tikhonov{
63f07b3eaeSTyler Young
646ff1e9b8SGeorge Wang    const struct test tests[] = {
65f07b3eaeSTyler Young
666ff1e9b8SGeorge Wang        /*
676ff1e9b8SGeorge Wang         * Big-endian tests
686ff1e9b8SGeorge Wang         */
696ff1e9b8SGeorge Wang        {   "Balls to the wall: every possible bit is set",
706ff1e9b8SGeorge Wang            __LINE__,
716ff1e9b8SGeorge Wang            select_pf_by_ver(LSQVER_043),
726ff1e9b8SGeorge Wang          /*  1      f      d      ooo    ss            1fdoooss */
736ff1e9b8SGeorge Wang          /*  TYPE   FIN    DLEN   OLEN   SLEN  */
746ff1e9b8SGeorge Wang            { 0x80 | 0x40 | 0x20 | 0x1C | 0x3,
756ff1e9b8SGeorge Wang              0x00, 0x00, 0x02, 0x10,                           /* Stream ID */
766ff1e9b8SGeorge Wang              0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01,   /* Offset */
776ff1e9b8SGeorge Wang              0x01, 0xC4,                                       /* Data length */
786ff1e9b8SGeorge Wang            },
796ff1e9b8SGeorge Wang              1           + 2    + 8    + 4,
806ff1e9b8SGeorge Wang            0x200,
816ff1e9b8SGeorge Wang            {   .data_frame.df_offset      = 0x0807060504030201UL,
826ff1e9b8SGeorge Wang                .stream_id   = 0x210,
836ff1e9b8SGeorge Wang                .data_frame.df_size = 0x1C4,
846ff1e9b8SGeorge Wang                .data_frame.df_fin         = 1,
856ff1e9b8SGeorge Wang            },
866ff1e9b8SGeorge Wang            1,
876ff1e9b8SGeorge Wang        },
88f07b3eaeSTyler Young
896ff1e9b8SGeorge Wang        {   "Balls to the wall #2: every possible bit is set, except FIN",
906ff1e9b8SGeorge Wang            __LINE__,
916ff1e9b8SGeorge Wang            select_pf_by_ver(LSQVER_043),
926ff1e9b8SGeorge Wang          /*  1      f      d      ooo    ss            1fdoooss */
936ff1e9b8SGeorge Wang          /*  TYPE   FIN    DLEN   OLEN   SLEN  */
946ff1e9b8SGeorge Wang            { 0x80 | 0x00 | 0x20 | 0x1C | 0x3,
956ff1e9b8SGeorge Wang              0x00, 0x00, 0x02, 0x10,                           /* Stream ID */
966ff1e9b8SGeorge Wang              0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01,   /* Offset */
976ff1e9b8SGeorge Wang              0x01, 0xC4,                                       /* Data length */
986ff1e9b8SGeorge Wang            },
996ff1e9b8SGeorge Wang              1           + 2    + 8    + 4,
1006ff1e9b8SGeorge Wang            0x200,
1016ff1e9b8SGeorge Wang            {   .data_frame.df_offset      = 0x0807060504030201UL,
1026ff1e9b8SGeorge Wang                .stream_id   = 0x210,
1036ff1e9b8SGeorge Wang                .data_frame.df_size = 0x1C4,
1046ff1e9b8SGeorge Wang                .data_frame.df_fin         = 0,
1056ff1e9b8SGeorge Wang            },
1066ff1e9b8SGeorge Wang            1,
1076ff1e9b8SGeorge Wang        },
108f07b3eaeSTyler Young
1096ff1e9b8SGeorge Wang        {   "Data length is zero",
1106ff1e9b8SGeorge Wang            __LINE__,
1116ff1e9b8SGeorge Wang            select_pf_by_ver(LSQVER_043),
1126ff1e9b8SGeorge Wang          /*  1      f      d      ooo    ss            1fdoooss */
1136ff1e9b8SGeorge Wang          /*  TYPE   FIN    DLEN   OLEN   SLEN  */
1146ff1e9b8SGeorge Wang            { 0x80 | 0x40 | 0x00 | 0x1C | 0x3,
1156ff1e9b8SGeorge Wang              0x00, 0x00, 0x02, 0x10,                           /* Stream ID */
1166ff1e9b8SGeorge Wang              0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01,   /* Offset */
1176ff1e9b8SGeorge Wang              0xC4, 0x01,                                       /* Data length: note this does not matter */
1186ff1e9b8SGeorge Wang            },
1196ff1e9b8SGeorge Wang              1           + 0    + 8    + 4,
1206ff1e9b8SGeorge Wang            0x200,
1216ff1e9b8SGeorge Wang            {   .data_frame.df_offset      = 0x0807060504030201UL,
1226ff1e9b8SGeorge Wang                .stream_id   = 0x210,
1236ff1e9b8SGeorge Wang                .data_frame.df_size = 0x200 - (1 + 8 + 4),
1246ff1e9b8SGeorge Wang                .data_frame.df_fin         = 1,
1256ff1e9b8SGeorge Wang            },
1266ff1e9b8SGeorge Wang            1,
1276ff1e9b8SGeorge Wang        },
128f07b3eaeSTyler Young
1296ff1e9b8SGeorge Wang        {   "Stream ID length is 1",
1306ff1e9b8SGeorge Wang            __LINE__,
1316ff1e9b8SGeorge Wang            select_pf_by_ver(LSQVER_043),
1326ff1e9b8SGeorge Wang          /*  1      f      d      ooo    ss            1fdoooss */
1336ff1e9b8SGeorge Wang          /*  TYPE   FIN    DLEN   OLEN   SLEN  */
1346ff1e9b8SGeorge Wang            { 0x80 | 0x40 | 0x20 | 0x1C | 0x0,
1356ff1e9b8SGeorge Wang              0xF0,                                             /* Stream ID */
1366ff1e9b8SGeorge Wang              0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01,   /* Offset */
1376ff1e9b8SGeorge Wang              0x01, 0xC4,                                       /* Data length */
1386ff1e9b8SGeorge Wang            },
1396ff1e9b8SGeorge Wang              1           + 2    + 8    + 1,
1406ff1e9b8SGeorge Wang            0x200,
1416ff1e9b8SGeorge Wang            {   .data_frame.df_offset      = 0x0807060504030201UL,
1426ff1e9b8SGeorge Wang                .stream_id   = 0xF0,
1436ff1e9b8SGeorge Wang                .data_frame.df_size = 0x1C4,
1446ff1e9b8SGeorge Wang                .data_frame.df_fin         = 1,
1456ff1e9b8SGeorge Wang            },
1466ff1e9b8SGeorge Wang            1,
1476ff1e9b8SGeorge Wang        },
148f07b3eaeSTyler Young
1496ff1e9b8SGeorge Wang        {   "All bits are zero save offset length",
1506ff1e9b8SGeorge Wang            __LINE__,
1516ff1e9b8SGeorge Wang            select_pf_by_ver(LSQVER_043),
1526ff1e9b8SGeorge Wang          /*  1      f      d      ooo    ss            1fdoooss */
1536ff1e9b8SGeorge Wang          /*  TYPE   FIN    DLEN   OLEN   SLEN  */
1546ff1e9b8SGeorge Wang            { 0x80 | 0x00 | 0x00 | 0x04 | 0x0,
1556ff1e9b8SGeorge Wang              0xF0,                                             /* Stream ID */
1566ff1e9b8SGeorge Wang              0x02, 0x55, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,   /* Offset */
1576ff1e9b8SGeorge Wang              0xC4, 0x01,                                       /* Data length */
1586ff1e9b8SGeorge Wang            },
1596ff1e9b8SGeorge Wang              1           + 0    + 2    + 1,
1606ff1e9b8SGeorge Wang            0x200,
1616ff1e9b8SGeorge Wang            {   .data_frame.df_offset      = 0x255,
1626ff1e9b8SGeorge Wang                .stream_id   = 0xF0,
1636ff1e9b8SGeorge Wang                .data_frame.df_size = 0x200 - 4,
1646ff1e9b8SGeorge Wang                .data_frame.df_fin         = 0,
1656ff1e9b8SGeorge Wang            },
1666ff1e9b8SGeorge Wang            1,
1676ff1e9b8SGeorge Wang        },
168f07b3eaeSTyler Young
1696ff1e9b8SGeorge Wang        {   "Sanity check: either FIN must be set or data length is not zero #1",
1706ff1e9b8SGeorge Wang            __LINE__,
1716ff1e9b8SGeorge Wang            select_pf_by_ver(LSQVER_043),
1726ff1e9b8SGeorge Wang          /*  1      f      d      ooo    ss            1fdoooss */
1736ff1e9b8SGeorge Wang          /*  TYPE   FIN    DLEN   OLEN   SLEN  */
1746ff1e9b8SGeorge Wang            { 0x80 | 0x00 | 0x00 | 0x04 | 0x0,
1756ff1e9b8SGeorge Wang              0xF0,                                             /* Stream ID */
1766ff1e9b8SGeorge Wang              0x02, 0x55,                                       /* Offset */
1776ff1e9b8SGeorge Wang            },
1786ff1e9b8SGeorge Wang              1           + 0    + 2    + 1,
1796ff1e9b8SGeorge Wang              4,    /* Same as buffer size: in the absense of explicit data
1806ff1e9b8SGeorge Wang                     * length in the header, this would mean that data
1816ff1e9b8SGeorge Wang                     * length is zero.
1826ff1e9b8SGeorge Wang                     */
1836ff1e9b8SGeorge Wang            {   .data_frame.df_offset      = 0x255,
1846ff1e9b8SGeorge Wang                .stream_id   = 0xF0,
1856ff1e9b8SGeorge Wang                .data_frame.df_size = 0x200 - 4,
1866ff1e9b8SGeorge Wang                .data_frame.df_fin         = 0,
1876ff1e9b8SGeorge Wang            },
1886ff1e9b8SGeorge Wang            0,
1896ff1e9b8SGeorge Wang        },
190f07b3eaeSTyler Young
1916ff1e9b8SGeorge Wang        {   "Sanity check: either FIN must be set or data length is not zero #2",
1926ff1e9b8SGeorge Wang            __LINE__,
1936ff1e9b8SGeorge Wang            select_pf_by_ver(LSQVER_043),
1946ff1e9b8SGeorge Wang          /*  1      f      d      ooo    ss            1fdoooss */
1956ff1e9b8SGeorge Wang          /*  TYPE   FIN    DLEN   OLEN   SLEN  */
1966ff1e9b8SGeorge Wang            { 0x80 | 0x00 | 0x20 | 0x04 | 0x0,
1976ff1e9b8SGeorge Wang              0xF0,                                             /* Stream ID */
1986ff1e9b8SGeorge Wang              0x02, 0x55,                                       /* Offset */
1996ff1e9b8SGeorge Wang              0x00, 0x00,
2006ff1e9b8SGeorge Wang            },
2016ff1e9b8SGeorge Wang              1           + 2    + 2    + 1,
2026ff1e9b8SGeorge Wang              200,
2036ff1e9b8SGeorge Wang            {   .data_frame.df_offset      = 0x255,
2046ff1e9b8SGeorge Wang                .stream_id   = 0xF0,
2056ff1e9b8SGeorge Wang                .data_frame.df_size = 0x200 - 4,
2066ff1e9b8SGeorge Wang                .data_frame.df_fin         = 0,
2076ff1e9b8SGeorge Wang            },
2086ff1e9b8SGeorge Wang            0,
2096ff1e9b8SGeorge Wang        },
210f07b3eaeSTyler Young
2116ff1e9b8SGeorge Wang        {   "Sanity check: either FIN must be set or data length is not zero #3",
2126ff1e9b8SGeorge Wang            __LINE__,
2136ff1e9b8SGeorge Wang            select_pf_by_ver(LSQVER_043),
2146ff1e9b8SGeorge Wang          /*  1      f      d      ooo    ss            1fdoooss */
2156ff1e9b8SGeorge Wang          /*  TYPE   FIN    DLEN   OLEN   SLEN  */
2166ff1e9b8SGeorge Wang            { 0x80 | 0x40 | 0x20 | 0x04 | 0x0,
2176ff1e9b8SGeorge Wang              0xF0,                                             /* Stream ID */
2186ff1e9b8SGeorge Wang              0x02, 0x55,                                       /* Offset */
2196ff1e9b8SGeorge Wang              0x00, 0x00,
2206ff1e9b8SGeorge Wang            },
2216ff1e9b8SGeorge Wang              1           + 2    + 2    + 1,
2226ff1e9b8SGeorge Wang              200,
2236ff1e9b8SGeorge Wang            {   .data_frame.df_offset      = 0x255,
2246ff1e9b8SGeorge Wang                .stream_id   = 0xF0,
2256ff1e9b8SGeorge Wang                .data_frame.df_size = 0x0,
2266ff1e9b8SGeorge Wang                .data_frame.df_fin         = 1,
2276ff1e9b8SGeorge Wang            },
2286ff1e9b8SGeorge Wang            1,
2296ff1e9b8SGeorge Wang        },
230f07b3eaeSTyler Young
2316ff1e9b8SGeorge Wang        {   "Check data bounds #1",
2326ff1e9b8SGeorge Wang            __LINE__,
2336ff1e9b8SGeorge Wang            select_pf_by_ver(LSQVER_043),
2346ff1e9b8SGeorge Wang          /*  1      f      d      ooo    ss            1fdoooss */
2356ff1e9b8SGeorge Wang          /*  TYPE   FIN    DLEN   OLEN   SLEN  */
2366ff1e9b8SGeorge Wang            { 0x80 | 0x00 | 0x20 | 0x04 | 0x0,
2376ff1e9b8SGeorge Wang              0xF0,                                             /* Stream ID */
2386ff1e9b8SGeorge Wang              0x02, 0x55,                                       /* Offset */
2396ff1e9b8SGeorge Wang              0x01, 0xFA,                                       /* Data length */
2406ff1e9b8SGeorge Wang            },
2416ff1e9b8SGeorge Wang              1           + 2    + 2    + 1,
2426ff1e9b8SGeorge Wang              0x200,
2436ff1e9b8SGeorge Wang            {   .data_frame.df_offset      = 0x255,
2446ff1e9b8SGeorge Wang                .stream_id   = 0xF0,
2456ff1e9b8SGeorge Wang                .data_frame.df_size = 0x1FA,
2466ff1e9b8SGeorge Wang                .data_frame.df_fin         = 0,
2476ff1e9b8SGeorge Wang            },
2486ff1e9b8SGeorge Wang            1,
2496ff1e9b8SGeorge Wang        },
250f07b3eaeSTyler Young
2516ff1e9b8SGeorge Wang        {   "Check data bounds #2",
2526ff1e9b8SGeorge Wang            __LINE__,
2536ff1e9b8SGeorge Wang            select_pf_by_ver(LSQVER_043),
2546ff1e9b8SGeorge Wang          /*  1      f      d      ooo    ss            1fdoooss */
2556ff1e9b8SGeorge Wang          /*  TYPE   FIN    DLEN   OLEN   SLEN  */
2566ff1e9b8SGeorge Wang            { 0x80 | 0x00 | 0x20 | 0x04 | 0x0,
2576ff1e9b8SGeorge Wang              0xF0,                                             /* Stream ID */
2586ff1e9b8SGeorge Wang              0x02, 0x55,                                       /* Offset */
2596ff1e9b8SGeorge Wang              0x01, 0xFB,    /* <---   One byte too many */
2606ff1e9b8SGeorge Wang            },
2616ff1e9b8SGeorge Wang              1           + 2    + 2    + 1,
2626ff1e9b8SGeorge Wang              0x200,
2636ff1e9b8SGeorge Wang            {   .data_frame.df_offset      = 0x255,
2646ff1e9b8SGeorge Wang                .stream_id   = 0xF0,
2656ff1e9b8SGeorge Wang                .data_frame.df_size = 0x1FA,
2666ff1e9b8SGeorge Wang                .data_frame.df_fin         = 0,
2676ff1e9b8SGeorge Wang            },
2686ff1e9b8SGeorge Wang            0,
2696ff1e9b8SGeorge Wang        },
270f07b3eaeSTyler Young
2716ff1e9b8SGeorge Wang        /*
2726ff1e9b8SGeorge Wang         * IETF QUIC Internet-Draft 14 Tests.
2736ff1e9b8SGeorge Wang         */
274f07b3eaeSTyler Young
2756ff1e9b8SGeorge Wang        {   "Balls to the wall: every possible bit is set",
2766ff1e9b8SGeorge Wang            __LINE__,
2776ff1e9b8SGeorge Wang            select_pf_by_ver(LSQVER_ID27),
2786ff1e9b8SGeorge Wang          /*  TYPE   OFF    DLEN   FIN   */
2796ff1e9b8SGeorge Wang            { 0x10 | 1<<2 | 1<<1 | 1<<0,
2806ff1e9b8SGeorge Wang              0x41, 0x23,                                       /* Stream ID */
2816ff1e9b8SGeorge Wang              0x08,                                             /* Offset */
2826ff1e9b8SGeorge Wang              0x41, 0xC4,                                       /* Data length */
2836ff1e9b8SGeorge Wang            },
2846ff1e9b8SGeorge Wang              1           + 2    + 1    + 2,
2856ff1e9b8SGeorge Wang            0x200,
2866ff1e9b8SGeorge Wang            {   .data_frame.df_offset       = 0x08,
2876ff1e9b8SGeorge Wang                .stream_id                  = 0x123,
2886ff1e9b8SGeorge Wang                .data_frame.df_size         = 0x1C4,
2896ff1e9b8SGeorge Wang                .data_frame.df_fin          = 1,
2906ff1e9b8SGeorge Wang            },
2916ff1e9b8SGeorge Wang            1,
2926ff1e9b8SGeorge Wang        },
293f07b3eaeSTyler Young
2946ff1e9b8SGeorge Wang        {   "Balls to the wall #2: every possible bit is set except FIN",
2956ff1e9b8SGeorge Wang            __LINE__,
2966ff1e9b8SGeorge Wang            select_pf_by_ver(LSQVER_ID27),
2976ff1e9b8SGeorge Wang          /*  TYPE   OFF    DLEN   FIN   */
2986ff1e9b8SGeorge Wang            { 0x10 | 1<<2 | 1<<1 | 0<<0,
2996ff1e9b8SGeorge Wang              0x81, 0x23, 0x00, 0xE4,                           /* Stream ID */
3006ff1e9b8SGeorge Wang              0xF0, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD,   /* Offset */
3016ff1e9b8SGeorge Wang              0x41, 0xC4,                                       /* Data length */
3026ff1e9b8SGeorge Wang            },
3036ff1e9b8SGeorge Wang              1           + 4    + 8    + 2,
3046ff1e9b8SGeorge Wang            0x200,
3056ff1e9b8SGeorge Wang            {   .data_frame.df_offset       = 0x301234567890ABCDull,
3066ff1e9b8SGeorge Wang                .stream_id                  = 0x12300E4,
3076ff1e9b8SGeorge Wang                .data_frame.df_size         = 0x1C4,
3086ff1e9b8SGeorge Wang                .data_frame.df_fin          = 0,
3096ff1e9b8SGeorge Wang            },
3106ff1e9b8SGeorge Wang            1,
3116ff1e9b8SGeorge Wang        },
312f07b3eaeSTyler Young
3136ff1e9b8SGeorge Wang        {   "Data length is zero",
3146ff1e9b8SGeorge Wang            __LINE__,
3156ff1e9b8SGeorge Wang            select_pf_by_ver(LSQVER_ID27),
3166ff1e9b8SGeorge Wang          /*  TYPE   OFF    DLEN   FIN   */
3176ff1e9b8SGeorge Wang            { 0x10 | 1<<2 | 0<<1 | 0<<0,
3186ff1e9b8SGeorge Wang              0x81, 0x23, 0x00, 0xE4,                           /* Stream ID */
3196ff1e9b8SGeorge Wang              0xF0, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD,   /* Offset */
3206ff1e9b8SGeorge Wang            },
3216ff1e9b8SGeorge Wang              1           + 4    + 8    + 0,
3226ff1e9b8SGeorge Wang            0x200,
3236ff1e9b8SGeorge Wang            {   .data_frame.df_offset       = 0x301234567890ABCDull,
3246ff1e9b8SGeorge Wang                .stream_id                  = 0x12300E4,
3256ff1e9b8SGeorge Wang                .data_frame.df_size         = 0x200 - 1 - 4 - 8,
3266ff1e9b8SGeorge Wang                .data_frame.df_fin          = 0,
3276ff1e9b8SGeorge Wang            },
3286ff1e9b8SGeorge Wang            1,
3296ff1e9b8SGeorge Wang        },
330f07b3eaeSTyler Young
3316ff1e9b8SGeorge Wang        {   "Sanity check: what happens when data length is zero #1",
3326ff1e9b8SGeorge Wang            __LINE__,
3336ff1e9b8SGeorge Wang            select_pf_by_ver(LSQVER_ID27),
3346ff1e9b8SGeorge Wang          /*  TYPE   OFF    DLEN   FIN   */
3356ff1e9b8SGeorge Wang            { 0x10 | 1<<2 | 1<<1 | 0<<0,
3366ff1e9b8SGeorge Wang              0x81, 0x23, 0x00, 0xE4,                           /* Stream ID */
3376ff1e9b8SGeorge Wang              0xF0, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD,   /* Offset */
3386ff1e9b8SGeorge Wang              0x40, 0x00,                                       /* Data length */
3396ff1e9b8SGeorge Wang            },
3406ff1e9b8SGeorge Wang              1           + 4    + 8    + 2,
3416ff1e9b8SGeorge Wang            0x200,
3426ff1e9b8SGeorge Wang            {   .data_frame.df_offset       = 0x301234567890ABCDull,
3436ff1e9b8SGeorge Wang                .stream_id                  = 0x12300E4,
3446ff1e9b8SGeorge Wang                .data_frame.df_size         = 0,
3456ff1e9b8SGeorge Wang                .data_frame.df_fin          = 0,
3466ff1e9b8SGeorge Wang            },
3476ff1e9b8SGeorge Wang            1,
3486ff1e9b8SGeorge Wang        },
349f07b3eaeSTyler Young
3506ff1e9b8SGeorge Wang        {   "Sanity check: what happens when data length is zero #2",
3516ff1e9b8SGeorge Wang            __LINE__,
3526ff1e9b8SGeorge Wang            select_pf_by_ver(LSQVER_ID27),
3536ff1e9b8SGeorge Wang          /*  TYPE   OFF    DLEN   FIN   */
3546ff1e9b8SGeorge Wang            { 0x10 | 1<<2 | 1<<1 | 0<<0,
3556ff1e9b8SGeorge Wang              0x81, 0x23, 0x00, 0xE4,                           /* Stream ID */
3566ff1e9b8SGeorge Wang              0x00,                                             /* Offset */
3576ff1e9b8SGeorge Wang              0x40, 0x00,                                       /* Data length */
3586ff1e9b8SGeorge Wang            },
3596ff1e9b8SGeorge Wang              1           + 4    + 1    + 2,
3606ff1e9b8SGeorge Wang            0x200,
3616ff1e9b8SGeorge Wang            {   .data_frame.df_offset       = 0,
3626ff1e9b8SGeorge Wang                .stream_id                  = 0x12300E4,
3636ff1e9b8SGeorge Wang                .data_frame.df_size         = 0,
3646ff1e9b8SGeorge Wang                .data_frame.df_fin          = 0,
3656ff1e9b8SGeorge Wang            },
3666ff1e9b8SGeorge Wang            1,
3676ff1e9b8SGeorge Wang        },
368f07b3eaeSTyler Young
3696ff1e9b8SGeorge Wang        {   "Sanity check: what happens when data length is zero #3",
3706ff1e9b8SGeorge Wang            __LINE__,
3716ff1e9b8SGeorge Wang            select_pf_by_ver(LSQVER_ID27),
3726ff1e9b8SGeorge Wang          /*  TYPE   OFF    DLEN   FIN   */
3736ff1e9b8SGeorge Wang            { 0x10 | 0<<2 | 1<<1 | 0<<0,
3746ff1e9b8SGeorge Wang              0x81, 0x23, 0x00, 0xE4,                           /* Stream ID */
3756ff1e9b8SGeorge Wang              0x40, 0x00,                                       /* Data length */
3766ff1e9b8SGeorge Wang            },
3776ff1e9b8SGeorge Wang              1           + 4    + 0    + 2,
3786ff1e9b8SGeorge Wang            0x200,
3796ff1e9b8SGeorge Wang            {   .data_frame.df_offset       = 0,
3806ff1e9b8SGeorge Wang                .stream_id                  = 0x12300E4,
3816ff1e9b8SGeorge Wang                .data_frame.df_size         = 0,
3826ff1e9b8SGeorge Wang                .data_frame.df_fin          = 0,
3836ff1e9b8SGeorge Wang            },
3846ff1e9b8SGeorge Wang            1,
3856ff1e9b8SGeorge Wang        },
386f07b3eaeSTyler Young
3876ff1e9b8SGeorge Wang        {   "Sanity check: what happens when data length is zero #3",
3886ff1e9b8SGeorge Wang            __LINE__,
3896ff1e9b8SGeorge Wang            select_pf_by_ver(LSQVER_ID27),
3906ff1e9b8SGeorge Wang          /*  TYPE   OFF    DLEN   FIN   */
3916ff1e9b8SGeorge Wang            { 0x10 | 1<<2 | 1<<1 | 1<<0,
3926ff1e9b8SGeorge Wang              0x81, 0x23, 0x00, 0xE4,                           /* Stream ID */
3936ff1e9b8SGeorge Wang              0x12,                                             /* Offset */
3946ff1e9b8SGeorge Wang              0x00,                                             /* Data length */
3956ff1e9b8SGeorge Wang            },
3966ff1e9b8SGeorge Wang              1           + 4    + 1    + 1,
3976ff1e9b8SGeorge Wang            0x200,
3986ff1e9b8SGeorge Wang            {   .data_frame.df_offset       = 0x12,
3996ff1e9b8SGeorge Wang                .stream_id                  = 0x12300E4,
4006ff1e9b8SGeorge Wang                .data_frame.df_size         = 0,
4016ff1e9b8SGeorge Wang                .data_frame.df_fin          = 1,
4026ff1e9b8SGeorge Wang            },
4036ff1e9b8SGeorge Wang            1,
4046ff1e9b8SGeorge Wang        },
405f07b3eaeSTyler Young
4066ff1e9b8SGeorge Wang        {   "Check data bounds #1",
4076ff1e9b8SGeorge Wang            __LINE__,
4086ff1e9b8SGeorge Wang            select_pf_by_ver(LSQVER_ID27),
4096ff1e9b8SGeorge Wang          /*  TYPE   OFF    DLEN   FIN   */
4106ff1e9b8SGeorge Wang            { 0x10 | 1<<2 | 1<<1 | 1<<0,
4116ff1e9b8SGeorge Wang              0x81, 0x23, 0x00, 0xE4,                           /* Stream ID */
4126ff1e9b8SGeorge Wang              0x12,                                             /* Offset */
4136ff1e9b8SGeorge Wang              0x41, 0xF8,                                       /* Data length */
4146ff1e9b8SGeorge Wang            },
4156ff1e9b8SGeorge Wang              1           + 4    + 1    + 2,
4166ff1e9b8SGeorge Wang            0x200,
4176ff1e9b8SGeorge Wang            {   .data_frame.df_offset       = 0x12,
4186ff1e9b8SGeorge Wang                .stream_id                  = 0x12300E4,
4196ff1e9b8SGeorge Wang                .data_frame.df_size         = 0x200 - 1 - 4 - 1 - 2,
4206ff1e9b8SGeorge Wang                .data_frame.df_fin          = 1,
4216ff1e9b8SGeorge Wang            },
4226ff1e9b8SGeorge Wang            1,
4236ff1e9b8SGeorge Wang        },
424f07b3eaeSTyler Young
4256ff1e9b8SGeorge Wang        {   "Check data bounds #2",
4266ff1e9b8SGeorge Wang            __LINE__,
4276ff1e9b8SGeorge Wang            select_pf_by_ver(LSQVER_ID27),
4286ff1e9b8SGeorge Wang          /*  TYPE   OFF    DLEN   FIN   */
4296ff1e9b8SGeorge Wang            { 0x10 | 1<<2 | 1<<1 | 1<<0,
4306ff1e9b8SGeorge Wang              0x81, 0x23, 0x00, 0xE4,                           /* Stream ID */
4316ff1e9b8SGeorge Wang              0x12,                                             /* Offset */
4326ff1e9b8SGeorge Wang              0x41, 0xF9,                                       /* Data length */
4336ff1e9b8SGeorge Wang            },
4346ff1e9b8SGeorge Wang              1           + 4    + 1    + 2,
4356ff1e9b8SGeorge Wang            0x200,
4366ff1e9b8SGeorge Wang            {   .data_frame.df_offset       = 0x12,
4376ff1e9b8SGeorge Wang                .stream_id                  = 0x12300E4,
4386ff1e9b8SGeorge Wang                .data_frame.df_size         = 0x200 - 1 - 4 - 1 - 2,
4396ff1e9b8SGeorge Wang                .data_frame.df_fin          = 1,
4406ff1e9b8SGeorge Wang            },
4416ff1e9b8SGeorge Wang            0,
4426ff1e9b8SGeorge Wang        },
443f07b3eaeSTyler Young
4446ff1e9b8SGeorge Wang    };
445f07b3eaeSTyler Young
44650aadb33SDmitri Tikhonov    unsigned i;
44750aadb33SDmitri Tikhonov    for (i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
44850aadb33SDmitri Tikhonov        run_test(&tests[i]);
44950aadb33SDmitri Tikhonov    return 0;
45050aadb33SDmitri Tikhonov}
451