test_stop_waiting_gquic_be.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 950aadb33SDmitri Tikhonov 1050aadb33SDmitri Tikhonov#include "lsquic.h" 1150aadb33SDmitri Tikhonov#include "lsquic_types.h" 1250aadb33SDmitri Tikhonov#include "lsquic_parse.h" 1350aadb33SDmitri Tikhonov 14fb96f4ddSDmitri Tikhonovstatic const struct parse_funcs *const pf = select_pf_by_ver(LSQVER_043); 1550aadb33SDmitri Tikhonov 1650aadb33SDmitri Tikhonov 1750aadb33SDmitri Tikhonovstruct parse_test { 1850aadb33SDmitri Tikhonov /* Input: */ 1950aadb33SDmitri Tikhonov unsigned char buf[0x10]; 2050aadb33SDmitri Tikhonov size_t buf_len; 2150aadb33SDmitri Tikhonov lsquic_packno_t cur_packno; 22c7d81ce1SDmitri Tikhonov enum packno_bits 2350aadb33SDmitri Tikhonov bits; 2450aadb33SDmitri Tikhonov /* Expected values: */ 2550aadb33SDmitri Tikhonov int retval; 2650aadb33SDmitri Tikhonov lsquic_packno_t least_unacked; 2750aadb33SDmitri Tikhonov}; 2850aadb33SDmitri Tikhonov 2950aadb33SDmitri Tikhonovstatic const struct parse_test parse_tests[] = { 3050aadb33SDmitri Tikhonov { 3150aadb33SDmitri Tikhonov .buf = { 0x06, 0x34, 0x12, 0x45, 0x67, 0x89, 0xAB, }, 3250aadb33SDmitri Tikhonov .buf_len = 3, 3350aadb33SDmitri Tikhonov .least_unacked = 0x1111, 3450aadb33SDmitri Tikhonov .cur_packno = 0x4523, 35c7d81ce1SDmitri Tikhonov .bits = GQUIC_PACKNO_LEN_2, 3650aadb33SDmitri Tikhonov .retval = 3, 3750aadb33SDmitri Tikhonov }, 3850aadb33SDmitri Tikhonov 3950aadb33SDmitri Tikhonov { 4050aadb33SDmitri Tikhonov .buf = { 0x06, 0x12, 0x34, 0x45, 0x67, 0x89, 0xAB, }, 4150aadb33SDmitri Tikhonov .buf_len = 2, 4250aadb33SDmitri Tikhonov .least_unacked = 0x1111, 4350aadb33SDmitri Tikhonov .cur_packno = 0x4523, 44c7d81ce1SDmitri Tikhonov .bits = GQUIC_PACKNO_LEN_2, 4550aadb33SDmitri Tikhonov .retval = -1, 4650aadb33SDmitri Tikhonov }, 4750aadb33SDmitri Tikhonov 4850aadb33SDmitri Tikhonov { 4950aadb33SDmitri Tikhonov .buf = { 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, }, 5050aadb33SDmitri Tikhonov .buf_len = 7, 5150aadb33SDmitri Tikhonov .least_unacked = 0x1122324252627282, 5250aadb33SDmitri Tikhonov .cur_packno = 0x1122334455667788, 53c7d81ce1SDmitri Tikhonov .bits = GQUIC_PACKNO_LEN_6, 5450aadb33SDmitri Tikhonov .retval = 7, 5550aadb33SDmitri Tikhonov }, 5650aadb33SDmitri Tikhonov 5750aadb33SDmitri Tikhonov { .buf = { 0 }, } 5850aadb33SDmitri Tikhonov}; 5950aadb33SDmitri Tikhonov 6050aadb33SDmitri Tikhonov 6150aadb33SDmitri Tikhonovstatic void 6250aadb33SDmitri Tikhonovrun_parse_tests (void) 6350aadb33SDmitri Tikhonov{ 6450aadb33SDmitri Tikhonov const struct parse_test *test; 6550aadb33SDmitri Tikhonov for (test = parse_tests; test->buf[0]; ++test) 6650aadb33SDmitri Tikhonov { 6750aadb33SDmitri Tikhonov lsquic_packno_t least; 6850aadb33SDmitri Tikhonov memset(&least, 0x33, sizeof(least)); 6950aadb33SDmitri Tikhonov int sz = pf->pf_parse_stop_waiting_frame(test->buf, test->buf_len, 7050aadb33SDmitri Tikhonov test->cur_packno, test->bits, &least); 7150aadb33SDmitri Tikhonov assert(("return value is correct", sz == test->retval)); 7250aadb33SDmitri Tikhonov if (test->retval > 0) 7350aadb33SDmitri Tikhonov assert(("least ACKed value is correct", least == test->least_unacked)); 7450aadb33SDmitri Tikhonov } 7550aadb33SDmitri Tikhonov} 7650aadb33SDmitri Tikhonov 7750aadb33SDmitri Tikhonov 7850aadb33SDmitri Tikhonovstatic void 7950aadb33SDmitri Tikhonovrun_gen_tests (void) 8050aadb33SDmitri Tikhonov{ 8150aadb33SDmitri Tikhonov const struct parse_test *test; 8250aadb33SDmitri Tikhonov for (test = parse_tests; test->buf[0]; ++test) 8350aadb33SDmitri Tikhonov { 8450aadb33SDmitri Tikhonov unsigned char buf[0x100]; 8550aadb33SDmitri Tikhonov int sz = pf->pf_gen_stop_waiting_frame(buf, test->buf_len, 8650aadb33SDmitri Tikhonov test->cur_packno, test->bits, test->least_unacked); 8750aadb33SDmitri Tikhonov assert(("return value is correct", sz == test->retval)); 8850aadb33SDmitri Tikhonov if (test->retval > 0) 8950aadb33SDmitri Tikhonov assert(("generated frame is correct", 0 == memcmp(test->buf, buf, sz))); 9050aadb33SDmitri Tikhonov } 9150aadb33SDmitri Tikhonov} 9250aadb33SDmitri Tikhonov 9350aadb33SDmitri Tikhonov 9450aadb33SDmitri Tikhonovint 9550aadb33SDmitri Tikhonovmain (void) 9650aadb33SDmitri Tikhonov{ 9750aadb33SDmitri Tikhonov run_parse_tests(); 9850aadb33SDmitri Tikhonov run_gen_tests(); 9950aadb33SDmitri Tikhonov return 0; 10050aadb33SDmitri Tikhonov} 101