test_streamparse.c revision 06b2a236
106b2a236SDmitri Tikhonov/* Copyright (c) 2017 - 2021 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 const struct test tests[] = { 3450aadb33SDmitri Tikhonov 3550aadb33SDmitri Tikhonov /* 365392f7a3SLiteSpeed Tech * Big-endian tests 3750aadb33SDmitri Tikhonov */ 3850aadb33SDmitri Tikhonov { "Balls to the wall: every possible bit is set", 3950aadb33SDmitri Tikhonov __LINE__, 40fb96f4ddSDmitri Tikhonov select_pf_by_ver(LSQVER_043), 4150aadb33SDmitri Tikhonov /* 1 f d ooo ss 1fdoooss */ 4250aadb33SDmitri Tikhonov /* TYPE FIN DLEN OLEN SLEN */ 4350aadb33SDmitri Tikhonov { 0x80 | 0x40 | 0x20 | 0x1C | 0x3, 445392f7a3SLiteSpeed Tech 0x00, 0x00, 0x02, 0x10, /* Stream ID */ 455392f7a3SLiteSpeed Tech 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, /* Offset */ 465392f7a3SLiteSpeed Tech 0x01, 0xC4, /* Data length */ 4750aadb33SDmitri Tikhonov }, 4850aadb33SDmitri Tikhonov 1 + 2 + 8 + 4, 4950aadb33SDmitri Tikhonov 0x200, 5050aadb33SDmitri Tikhonov { .data_frame.df_offset = 0x0807060504030201UL, 5150aadb33SDmitri Tikhonov .stream_id = 0x210, 5250aadb33SDmitri Tikhonov .data_frame.df_size = 0x1C4, 5350aadb33SDmitri Tikhonov .data_frame.df_fin = 1, 5450aadb33SDmitri Tikhonov }, 5550aadb33SDmitri Tikhonov 1, 5650aadb33SDmitri Tikhonov }, 5750aadb33SDmitri Tikhonov 5850aadb33SDmitri Tikhonov { "Balls to the wall #2: every possible bit is set, except FIN", 5950aadb33SDmitri Tikhonov __LINE__, 60fb96f4ddSDmitri Tikhonov select_pf_by_ver(LSQVER_043), 6150aadb33SDmitri Tikhonov /* 1 f d ooo ss 1fdoooss */ 6250aadb33SDmitri Tikhonov /* TYPE FIN DLEN OLEN SLEN */ 6350aadb33SDmitri Tikhonov { 0x80 | 0x00 | 0x20 | 0x1C | 0x3, 645392f7a3SLiteSpeed Tech 0x00, 0x00, 0x02, 0x10, /* Stream ID */ 655392f7a3SLiteSpeed Tech 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, /* Offset */ 665392f7a3SLiteSpeed Tech 0x01, 0xC4, /* Data length */ 6750aadb33SDmitri Tikhonov }, 6850aadb33SDmitri Tikhonov 1 + 2 + 8 + 4, 6950aadb33SDmitri Tikhonov 0x200, 7050aadb33SDmitri Tikhonov { .data_frame.df_offset = 0x0807060504030201UL, 7150aadb33SDmitri Tikhonov .stream_id = 0x210, 7250aadb33SDmitri Tikhonov .data_frame.df_size = 0x1C4, 7350aadb33SDmitri Tikhonov .data_frame.df_fin = 0, 7450aadb33SDmitri Tikhonov }, 7550aadb33SDmitri Tikhonov 1, 7650aadb33SDmitri Tikhonov }, 7750aadb33SDmitri Tikhonov 7850aadb33SDmitri Tikhonov { "Data length is zero", 7950aadb33SDmitri Tikhonov __LINE__, 80fb96f4ddSDmitri Tikhonov select_pf_by_ver(LSQVER_043), 8150aadb33SDmitri Tikhonov /* 1 f d ooo ss 1fdoooss */ 8250aadb33SDmitri Tikhonov /* TYPE FIN DLEN OLEN SLEN */ 8350aadb33SDmitri Tikhonov { 0x80 | 0x40 | 0x00 | 0x1C | 0x3, 845392f7a3SLiteSpeed Tech 0x00, 0x00, 0x02, 0x10, /* Stream ID */ 855392f7a3SLiteSpeed Tech 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, /* Offset */ 865392f7a3SLiteSpeed Tech 0xC4, 0x01, /* Data length: note this does not matter */ 8750aadb33SDmitri Tikhonov }, 8850aadb33SDmitri Tikhonov 1 + 0 + 8 + 4, 8950aadb33SDmitri Tikhonov 0x200, 9050aadb33SDmitri Tikhonov { .data_frame.df_offset = 0x0807060504030201UL, 9150aadb33SDmitri Tikhonov .stream_id = 0x210, 9250aadb33SDmitri Tikhonov .data_frame.df_size = 0x200 - (1 + 8 + 4), 9350aadb33SDmitri Tikhonov .data_frame.df_fin = 1, 9450aadb33SDmitri Tikhonov }, 9550aadb33SDmitri Tikhonov 1, 9650aadb33SDmitri Tikhonov }, 9750aadb33SDmitri Tikhonov 9850aadb33SDmitri Tikhonov { "Stream ID length is 1", 9950aadb33SDmitri Tikhonov __LINE__, 100fb96f4ddSDmitri Tikhonov select_pf_by_ver(LSQVER_043), 10150aadb33SDmitri Tikhonov /* 1 f d ooo ss 1fdoooss */ 10250aadb33SDmitri Tikhonov /* TYPE FIN DLEN OLEN SLEN */ 10350aadb33SDmitri Tikhonov { 0x80 | 0x40 | 0x20 | 0x1C | 0x0, 10450aadb33SDmitri Tikhonov 0xF0, /* Stream ID */ 1055392f7a3SLiteSpeed Tech 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, /* Offset */ 1065392f7a3SLiteSpeed Tech 0x01, 0xC4, /* Data length */ 10750aadb33SDmitri Tikhonov }, 10850aadb33SDmitri Tikhonov 1 + 2 + 8 + 1, 10950aadb33SDmitri Tikhonov 0x200, 11050aadb33SDmitri Tikhonov { .data_frame.df_offset = 0x0807060504030201UL, 11150aadb33SDmitri Tikhonov .stream_id = 0xF0, 11250aadb33SDmitri Tikhonov .data_frame.df_size = 0x1C4, 11350aadb33SDmitri Tikhonov .data_frame.df_fin = 1, 11450aadb33SDmitri Tikhonov }, 11550aadb33SDmitri Tikhonov 1, 11650aadb33SDmitri Tikhonov }, 11750aadb33SDmitri Tikhonov 11850aadb33SDmitri Tikhonov { "All bits are zero save offset length", 11950aadb33SDmitri Tikhonov __LINE__, 120fb96f4ddSDmitri Tikhonov select_pf_by_ver(LSQVER_043), 12150aadb33SDmitri Tikhonov /* 1 f d ooo ss 1fdoooss */ 12250aadb33SDmitri Tikhonov /* TYPE FIN DLEN OLEN SLEN */ 12350aadb33SDmitri Tikhonov { 0x80 | 0x00 | 0x00 | 0x04 | 0x0, 12450aadb33SDmitri Tikhonov 0xF0, /* Stream ID */ 1255392f7a3SLiteSpeed Tech 0x02, 0x55, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, /* Offset */ 12650aadb33SDmitri Tikhonov 0xC4, 0x01, /* Data length */ 12750aadb33SDmitri Tikhonov }, 12850aadb33SDmitri Tikhonov 1 + 0 + 2 + 1, 12950aadb33SDmitri Tikhonov 0x200, 13050aadb33SDmitri Tikhonov { .data_frame.df_offset = 0x255, 13150aadb33SDmitri Tikhonov .stream_id = 0xF0, 13250aadb33SDmitri Tikhonov .data_frame.df_size = 0x200 - 4, 13350aadb33SDmitri Tikhonov .data_frame.df_fin = 0, 13450aadb33SDmitri Tikhonov }, 13550aadb33SDmitri Tikhonov 1, 13650aadb33SDmitri Tikhonov }, 13750aadb33SDmitri Tikhonov 13850aadb33SDmitri Tikhonov { "Sanity check: either FIN must be set or data length is not zero #1", 13950aadb33SDmitri Tikhonov __LINE__, 140fb96f4ddSDmitri Tikhonov select_pf_by_ver(LSQVER_043), 14150aadb33SDmitri Tikhonov /* 1 f d ooo ss 1fdoooss */ 14250aadb33SDmitri Tikhonov /* TYPE FIN DLEN OLEN SLEN */ 14350aadb33SDmitri Tikhonov { 0x80 | 0x00 | 0x00 | 0x04 | 0x0, 14450aadb33SDmitri Tikhonov 0xF0, /* Stream ID */ 1455392f7a3SLiteSpeed Tech 0x02, 0x55, /* Offset */ 14650aadb33SDmitri Tikhonov }, 14750aadb33SDmitri Tikhonov 1 + 0 + 2 + 1, 14850aadb33SDmitri Tikhonov 4, /* Same as buffer size: in the absense of explicit data 14950aadb33SDmitri Tikhonov * length in the header, this would mean that data 15050aadb33SDmitri Tikhonov * length is zero. 15150aadb33SDmitri Tikhonov */ 15250aadb33SDmitri Tikhonov { .data_frame.df_offset = 0x255, 15350aadb33SDmitri Tikhonov .stream_id = 0xF0, 15450aadb33SDmitri Tikhonov .data_frame.df_size = 0x200 - 4, 15550aadb33SDmitri Tikhonov .data_frame.df_fin = 0, 15650aadb33SDmitri Tikhonov }, 15750aadb33SDmitri Tikhonov 0, 15850aadb33SDmitri Tikhonov }, 15950aadb33SDmitri Tikhonov 16050aadb33SDmitri Tikhonov { "Sanity check: either FIN must be set or data length is not zero #2", 16150aadb33SDmitri Tikhonov __LINE__, 162fb96f4ddSDmitri Tikhonov select_pf_by_ver(LSQVER_043), 16350aadb33SDmitri Tikhonov /* 1 f d ooo ss 1fdoooss */ 16450aadb33SDmitri Tikhonov /* TYPE FIN DLEN OLEN SLEN */ 16550aadb33SDmitri Tikhonov { 0x80 | 0x00 | 0x20 | 0x04 | 0x0, 16650aadb33SDmitri Tikhonov 0xF0, /* Stream ID */ 1675392f7a3SLiteSpeed Tech 0x02, 0x55, /* Offset */ 16850aadb33SDmitri Tikhonov 0x00, 0x00, 16950aadb33SDmitri Tikhonov }, 17050aadb33SDmitri Tikhonov 1 + 2 + 2 + 1, 17150aadb33SDmitri Tikhonov 200, 17250aadb33SDmitri Tikhonov { .data_frame.df_offset = 0x255, 17350aadb33SDmitri Tikhonov .stream_id = 0xF0, 17450aadb33SDmitri Tikhonov .data_frame.df_size = 0x200 - 4, 17550aadb33SDmitri Tikhonov .data_frame.df_fin = 0, 17650aadb33SDmitri Tikhonov }, 17750aadb33SDmitri Tikhonov 0, 17850aadb33SDmitri Tikhonov }, 17950aadb33SDmitri Tikhonov 18050aadb33SDmitri Tikhonov { "Sanity check: either FIN must be set or data length is not zero #3", 18150aadb33SDmitri Tikhonov __LINE__, 182fb96f4ddSDmitri Tikhonov select_pf_by_ver(LSQVER_043), 18350aadb33SDmitri Tikhonov /* 1 f d ooo ss 1fdoooss */ 18450aadb33SDmitri Tikhonov /* TYPE FIN DLEN OLEN SLEN */ 18550aadb33SDmitri Tikhonov { 0x80 | 0x40 | 0x20 | 0x04 | 0x0, 18650aadb33SDmitri Tikhonov 0xF0, /* Stream ID */ 1875392f7a3SLiteSpeed Tech 0x02, 0x55, /* Offset */ 18850aadb33SDmitri Tikhonov 0x00, 0x00, 18950aadb33SDmitri Tikhonov }, 19050aadb33SDmitri Tikhonov 1 + 2 + 2 + 1, 19150aadb33SDmitri Tikhonov 200, 19250aadb33SDmitri Tikhonov { .data_frame.df_offset = 0x255, 19350aadb33SDmitri Tikhonov .stream_id = 0xF0, 19450aadb33SDmitri Tikhonov .data_frame.df_size = 0x0, 19550aadb33SDmitri Tikhonov .data_frame.df_fin = 1, 19650aadb33SDmitri Tikhonov }, 19750aadb33SDmitri Tikhonov 1, 19850aadb33SDmitri Tikhonov }, 19950aadb33SDmitri Tikhonov 20050aadb33SDmitri Tikhonov { "Check data bounds #1", 20150aadb33SDmitri Tikhonov __LINE__, 202fb96f4ddSDmitri Tikhonov select_pf_by_ver(LSQVER_043), 20350aadb33SDmitri Tikhonov /* 1 f d ooo ss 1fdoooss */ 20450aadb33SDmitri Tikhonov /* TYPE FIN DLEN OLEN SLEN */ 20550aadb33SDmitri Tikhonov { 0x80 | 0x00 | 0x20 | 0x04 | 0x0, 20650aadb33SDmitri Tikhonov 0xF0, /* Stream ID */ 2075392f7a3SLiteSpeed Tech 0x02, 0x55, /* Offset */ 2085392f7a3SLiteSpeed Tech 0x01, 0xFA, /* Data length */ 20950aadb33SDmitri Tikhonov }, 21050aadb33SDmitri Tikhonov 1 + 2 + 2 + 1, 21150aadb33SDmitri Tikhonov 0x200, 21250aadb33SDmitri Tikhonov { .data_frame.df_offset = 0x255, 21350aadb33SDmitri Tikhonov .stream_id = 0xF0, 21450aadb33SDmitri Tikhonov .data_frame.df_size = 0x1FA, 21550aadb33SDmitri Tikhonov .data_frame.df_fin = 0, 21650aadb33SDmitri Tikhonov }, 21750aadb33SDmitri Tikhonov 1, 21850aadb33SDmitri Tikhonov }, 21950aadb33SDmitri Tikhonov 22050aadb33SDmitri Tikhonov { "Check data bounds #2", 22150aadb33SDmitri Tikhonov __LINE__, 222fb96f4ddSDmitri Tikhonov select_pf_by_ver(LSQVER_043), 22350aadb33SDmitri Tikhonov /* 1 f d ooo ss 1fdoooss */ 22450aadb33SDmitri Tikhonov /* TYPE FIN DLEN OLEN SLEN */ 22550aadb33SDmitri Tikhonov { 0x80 | 0x00 | 0x20 | 0x04 | 0x0, 22650aadb33SDmitri Tikhonov 0xF0, /* Stream ID */ 2275392f7a3SLiteSpeed Tech 0x02, 0x55, /* Offset */ 2285392f7a3SLiteSpeed Tech 0x01, 0xFB, /* <--- One byte too many */ 22950aadb33SDmitri Tikhonov }, 23050aadb33SDmitri Tikhonov 1 + 2 + 2 + 1, 23150aadb33SDmitri Tikhonov 0x200, 23250aadb33SDmitri Tikhonov { .data_frame.df_offset = 0x255, 23350aadb33SDmitri Tikhonov .stream_id = 0xF0, 23450aadb33SDmitri Tikhonov .data_frame.df_size = 0x1FA, 23550aadb33SDmitri Tikhonov .data_frame.df_fin = 0, 23650aadb33SDmitri Tikhonov }, 23750aadb33SDmitri Tikhonov 0, 23850aadb33SDmitri Tikhonov }, 23950aadb33SDmitri Tikhonov 24050aadb33SDmitri Tikhonov /* 2415392f7a3SLiteSpeed Tech * IETF QUIC Internet-Draft 14 Tests. 24250aadb33SDmitri Tikhonov */ 2435392f7a3SLiteSpeed Tech 24450aadb33SDmitri Tikhonov { "Balls to the wall: every possible bit is set", 24550aadb33SDmitri Tikhonov __LINE__, 246fb73393fSDmitri Tikhonov select_pf_by_ver(LSQVER_ID27), 2475392f7a3SLiteSpeed Tech /* TYPE OFF DLEN FIN */ 2485392f7a3SLiteSpeed Tech { 0x10 | 1<<2 | 1<<1 | 1<<0, 2495392f7a3SLiteSpeed Tech 0x41, 0x23, /* Stream ID */ 2505392f7a3SLiteSpeed Tech 0x08, /* Offset */ 2515392f7a3SLiteSpeed Tech 0x41, 0xC4, /* Data length */ 2525392f7a3SLiteSpeed Tech }, 2535392f7a3SLiteSpeed Tech 1 + 2 + 1 + 2, 25450aadb33SDmitri Tikhonov 0x200, 2555392f7a3SLiteSpeed Tech { .data_frame.df_offset = 0x08, 2565392f7a3SLiteSpeed Tech .stream_id = 0x123, 2575392f7a3SLiteSpeed Tech .data_frame.df_size = 0x1C4, 2585392f7a3SLiteSpeed Tech .data_frame.df_fin = 1, 25950aadb33SDmitri Tikhonov }, 26050aadb33SDmitri Tikhonov 1, 26150aadb33SDmitri Tikhonov }, 26250aadb33SDmitri Tikhonov 2635392f7a3SLiteSpeed Tech { "Balls to the wall #2: every possible bit is set except FIN", 26450aadb33SDmitri Tikhonov __LINE__, 265fb73393fSDmitri Tikhonov select_pf_by_ver(LSQVER_ID27), 2665392f7a3SLiteSpeed Tech /* TYPE OFF DLEN FIN */ 2675392f7a3SLiteSpeed Tech { 0x10 | 1<<2 | 1<<1 | 0<<0, 2685392f7a3SLiteSpeed Tech 0x81, 0x23, 0x00, 0xE4, /* Stream ID */ 2695392f7a3SLiteSpeed Tech 0xF0, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, /* Offset */ 2705392f7a3SLiteSpeed Tech 0x41, 0xC4, /* Data length */ 2715392f7a3SLiteSpeed Tech }, 2725392f7a3SLiteSpeed Tech 1 + 4 + 8 + 2, 27350aadb33SDmitri Tikhonov 0x200, 2745392f7a3SLiteSpeed Tech { .data_frame.df_offset = 0x301234567890ABCDull, 2755392f7a3SLiteSpeed Tech .stream_id = 0x12300E4, 2765392f7a3SLiteSpeed Tech .data_frame.df_size = 0x1C4, 2775392f7a3SLiteSpeed Tech .data_frame.df_fin = 0, 27850aadb33SDmitri Tikhonov }, 27950aadb33SDmitri Tikhonov 1, 28050aadb33SDmitri Tikhonov }, 28150aadb33SDmitri Tikhonov 28250aadb33SDmitri Tikhonov { "Data length is zero", 28350aadb33SDmitri Tikhonov __LINE__, 284fb73393fSDmitri Tikhonov select_pf_by_ver(LSQVER_ID27), 2855392f7a3SLiteSpeed Tech /* TYPE OFF DLEN FIN */ 2865392f7a3SLiteSpeed Tech { 0x10 | 1<<2 | 0<<1 | 0<<0, 2875392f7a3SLiteSpeed Tech 0x81, 0x23, 0x00, 0xE4, /* Stream ID */ 2885392f7a3SLiteSpeed Tech 0xF0, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, /* Offset */ 28950aadb33SDmitri Tikhonov }, 2905392f7a3SLiteSpeed Tech 1 + 4 + 8 + 0, 29150aadb33SDmitri Tikhonov 0x200, 2925392f7a3SLiteSpeed Tech { .data_frame.df_offset = 0x301234567890ABCDull, 2935392f7a3SLiteSpeed Tech .stream_id = 0x12300E4, 2945392f7a3SLiteSpeed Tech .data_frame.df_size = 0x200 - 1 - 4 - 8, 2955392f7a3SLiteSpeed Tech .data_frame.df_fin = 0, 29650aadb33SDmitri Tikhonov }, 29750aadb33SDmitri Tikhonov 1, 29850aadb33SDmitri Tikhonov }, 29950aadb33SDmitri Tikhonov 3005392f7a3SLiteSpeed Tech { "Sanity check: what happens when data length is zero #1", 30150aadb33SDmitri Tikhonov __LINE__, 302fb73393fSDmitri Tikhonov select_pf_by_ver(LSQVER_ID27), 3035392f7a3SLiteSpeed Tech /* TYPE OFF DLEN FIN */ 3045392f7a3SLiteSpeed Tech { 0x10 | 1<<2 | 1<<1 | 0<<0, 3055392f7a3SLiteSpeed Tech 0x81, 0x23, 0x00, 0xE4, /* Stream ID */ 3065392f7a3SLiteSpeed Tech 0xF0, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, /* Offset */ 3075392f7a3SLiteSpeed Tech 0x40, 0x00, /* Data length */ 3085392f7a3SLiteSpeed Tech }, 3095392f7a3SLiteSpeed Tech 1 + 4 + 8 + 2, 31050aadb33SDmitri Tikhonov 0x200, 3115392f7a3SLiteSpeed Tech { .data_frame.df_offset = 0x301234567890ABCDull, 3125392f7a3SLiteSpeed Tech .stream_id = 0x12300E4, 3135392f7a3SLiteSpeed Tech .data_frame.df_size = 0, 3145392f7a3SLiteSpeed Tech .data_frame.df_fin = 0, 31550aadb33SDmitri Tikhonov }, 31650aadb33SDmitri Tikhonov 1, 31750aadb33SDmitri Tikhonov }, 31850aadb33SDmitri Tikhonov 3195392f7a3SLiteSpeed Tech { "Sanity check: what happens when data length is zero #2", 32050aadb33SDmitri Tikhonov __LINE__, 321fb73393fSDmitri Tikhonov select_pf_by_ver(LSQVER_ID27), 3225392f7a3SLiteSpeed Tech /* TYPE OFF DLEN FIN */ 3235392f7a3SLiteSpeed Tech { 0x10 | 1<<2 | 1<<1 | 0<<0, 3245392f7a3SLiteSpeed Tech 0x81, 0x23, 0x00, 0xE4, /* Stream ID */ 3255392f7a3SLiteSpeed Tech 0x00, /* Offset */ 3265392f7a3SLiteSpeed Tech 0x40, 0x00, /* Data length */ 3275392f7a3SLiteSpeed Tech }, 3285392f7a3SLiteSpeed Tech 1 + 4 + 1 + 2, 32950aadb33SDmitri Tikhonov 0x200, 3305392f7a3SLiteSpeed Tech { .data_frame.df_offset = 0, 3315392f7a3SLiteSpeed Tech .stream_id = 0x12300E4, 3325392f7a3SLiteSpeed Tech .data_frame.df_size = 0, 3335392f7a3SLiteSpeed Tech .data_frame.df_fin = 0, 33450aadb33SDmitri Tikhonov }, 33550aadb33SDmitri Tikhonov 1, 33650aadb33SDmitri Tikhonov }, 33750aadb33SDmitri Tikhonov 3385392f7a3SLiteSpeed Tech { "Sanity check: what happens when data length is zero #3", 33950aadb33SDmitri Tikhonov __LINE__, 340fb73393fSDmitri Tikhonov select_pf_by_ver(LSQVER_ID27), 3415392f7a3SLiteSpeed Tech /* TYPE OFF DLEN FIN */ 3425392f7a3SLiteSpeed Tech { 0x10 | 0<<2 | 1<<1 | 0<<0, 3435392f7a3SLiteSpeed Tech 0x81, 0x23, 0x00, 0xE4, /* Stream ID */ 3445392f7a3SLiteSpeed Tech 0x40, 0x00, /* Data length */ 34550aadb33SDmitri Tikhonov }, 3465392f7a3SLiteSpeed Tech 1 + 4 + 0 + 2, 3475392f7a3SLiteSpeed Tech 0x200, 3485392f7a3SLiteSpeed Tech { .data_frame.df_offset = 0, 3495392f7a3SLiteSpeed Tech .stream_id = 0x12300E4, 3505392f7a3SLiteSpeed Tech .data_frame.df_size = 0, 3515392f7a3SLiteSpeed Tech .data_frame.df_fin = 0, 35250aadb33SDmitri Tikhonov }, 3535392f7a3SLiteSpeed Tech 1, 35450aadb33SDmitri Tikhonov }, 35550aadb33SDmitri Tikhonov 3565392f7a3SLiteSpeed Tech { "Sanity check: what happens when data length is zero #3", 35750aadb33SDmitri Tikhonov __LINE__, 358fb73393fSDmitri Tikhonov select_pf_by_ver(LSQVER_ID27), 3595392f7a3SLiteSpeed Tech /* TYPE OFF DLEN FIN */ 3605392f7a3SLiteSpeed Tech { 0x10 | 1<<2 | 1<<1 | 1<<0, 3615392f7a3SLiteSpeed Tech 0x81, 0x23, 0x00, 0xE4, /* Stream ID */ 3625392f7a3SLiteSpeed Tech 0x12, /* Offset */ 3635392f7a3SLiteSpeed Tech 0x00, /* Data length */ 3645392f7a3SLiteSpeed Tech }, 3655392f7a3SLiteSpeed Tech 1 + 4 + 1 + 1, 3665392f7a3SLiteSpeed Tech 0x200, 3675392f7a3SLiteSpeed Tech { .data_frame.df_offset = 0x12, 3685392f7a3SLiteSpeed Tech .stream_id = 0x12300E4, 3695392f7a3SLiteSpeed Tech .data_frame.df_size = 0, 3705392f7a3SLiteSpeed Tech .data_frame.df_fin = 1, 37150aadb33SDmitri Tikhonov }, 37250aadb33SDmitri Tikhonov 1, 37350aadb33SDmitri Tikhonov }, 37450aadb33SDmitri Tikhonov 37550aadb33SDmitri Tikhonov { "Check data bounds #1", 37650aadb33SDmitri Tikhonov __LINE__, 377fb73393fSDmitri Tikhonov select_pf_by_ver(LSQVER_ID27), 3785392f7a3SLiteSpeed Tech /* TYPE OFF DLEN FIN */ 3795392f7a3SLiteSpeed Tech { 0x10 | 1<<2 | 1<<1 | 1<<0, 3805392f7a3SLiteSpeed Tech 0x81, 0x23, 0x00, 0xE4, /* Stream ID */ 3815392f7a3SLiteSpeed Tech 0x12, /* Offset */ 3825392f7a3SLiteSpeed Tech 0x41, 0xF8, /* Data length */ 3835392f7a3SLiteSpeed Tech }, 3845392f7a3SLiteSpeed Tech 1 + 4 + 1 + 2, 3855392f7a3SLiteSpeed Tech 0x200, 3865392f7a3SLiteSpeed Tech { .data_frame.df_offset = 0x12, 3875392f7a3SLiteSpeed Tech .stream_id = 0x12300E4, 3885392f7a3SLiteSpeed Tech .data_frame.df_size = 0x200 - 1 - 4 - 1 - 2, 3895392f7a3SLiteSpeed Tech .data_frame.df_fin = 1, 39050aadb33SDmitri Tikhonov }, 39150aadb33SDmitri Tikhonov 1, 39250aadb33SDmitri Tikhonov }, 39350aadb33SDmitri Tikhonov 39450aadb33SDmitri Tikhonov { "Check data bounds #2", 39550aadb33SDmitri Tikhonov __LINE__, 396fb73393fSDmitri Tikhonov select_pf_by_ver(LSQVER_ID27), 3975392f7a3SLiteSpeed Tech /* TYPE OFF DLEN FIN */ 3985392f7a3SLiteSpeed Tech { 0x10 | 1<<2 | 1<<1 | 1<<0, 3995392f7a3SLiteSpeed Tech 0x81, 0x23, 0x00, 0xE4, /* Stream ID */ 4005392f7a3SLiteSpeed Tech 0x12, /* Offset */ 4015392f7a3SLiteSpeed Tech 0x41, 0xF9, /* Data length */ 4025392f7a3SLiteSpeed Tech }, 4035392f7a3SLiteSpeed Tech 1 + 4 + 1 + 2, 4045392f7a3SLiteSpeed Tech 0x200, 4055392f7a3SLiteSpeed Tech { .data_frame.df_offset = 0x12, 4065392f7a3SLiteSpeed Tech .stream_id = 0x12300E4, 4075392f7a3SLiteSpeed Tech .data_frame.df_size = 0x200 - 1 - 4 - 1 - 2, 4085392f7a3SLiteSpeed Tech .data_frame.df_fin = 1, 40950aadb33SDmitri Tikhonov }, 41050aadb33SDmitri Tikhonov 0, 41150aadb33SDmitri Tikhonov }, 41250aadb33SDmitri Tikhonov 41350aadb33SDmitri Tikhonov}; 41450aadb33SDmitri Tikhonov 41550aadb33SDmitri Tikhonov 41650aadb33SDmitri Tikhonovstatic void 41750aadb33SDmitri Tikhonovrun_test (const struct test *test) 41850aadb33SDmitri Tikhonov{ 41950aadb33SDmitri Tikhonov stream_frame_t frame; 42050aadb33SDmitri Tikhonov memset(&frame, 0x7A, sizeof(frame)); 42150aadb33SDmitri Tikhonov 42250aadb33SDmitri Tikhonov int len = test->pf->pf_parse_stream_frame(test->buf, test->rem_packet_sz, &frame); 42350aadb33SDmitri Tikhonov 42450aadb33SDmitri Tikhonov if (test->should_succeed) { 42550aadb33SDmitri Tikhonov /* Check parser operation */ 42650aadb33SDmitri Tikhonov assert(("Parsed correct number of bytes", (size_t) len == test->buf_sz + test->frame.data_frame.df_size)); 42750aadb33SDmitri Tikhonov assert(("Stream ID is correct", frame.stream_id == test->frame.stream_id)); 42850aadb33SDmitri Tikhonov assert(("Data length is correct", frame.data_frame.df_size == test->frame.data_frame.df_size)); 42950aadb33SDmitri Tikhonov assert(("Offset is correct", frame.data_frame.df_offset == test->frame.data_frame.df_offset)); 43050aadb33SDmitri Tikhonov assert(("FIN is correct", frame.data_frame.df_fin == test->frame.data_frame.df_fin)); 43150aadb33SDmitri Tikhonov 43250aadb33SDmitri Tikhonov /* Check that initialization of other fields occurred correctly: */ 43350aadb33SDmitri Tikhonov assert(0 == frame.packet_in); 43450aadb33SDmitri Tikhonov assert(0 == frame.data_frame.df_read_off); 43550aadb33SDmitri Tikhonov } 43650aadb33SDmitri Tikhonov else 43750aadb33SDmitri Tikhonov { 43850aadb33SDmitri Tikhonov assert(("This test should fail", len < 0)); 43950aadb33SDmitri Tikhonov } 44050aadb33SDmitri Tikhonov} 44150aadb33SDmitri Tikhonov 44250aadb33SDmitri Tikhonov 44350aadb33SDmitri Tikhonovint 44450aadb33SDmitri Tikhonovmain (void) 44550aadb33SDmitri Tikhonov{ 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